AnsweredAssumed Answered

How do I pass GPIOx_PTOR and TPMx_SC registers as arguments to a function

Question asked by Miguel Amaro on Oct 4, 2019
Latest reply on Nov 3, 2019 by Miguel Amaro

kl25z  function parameter registers

Hi, I want to have one timer() function that I can call and to control each led with instead of having these three almost identical ones. I figure that I have to pass PTOR and SC to the function but I don't know how to declare registers as arguments... 

while(1){
timerRed (rItrPtr, rDtyCycMrkrPtr, rFlgPtr, 3.0, 0.8);
timerGreen(gItrPtr, gDtyCycMrkrPtr, gFlgPtr, 0.5, 0.2);
timerBlue (bItrPtr, bDtyCycMrkrPtr, bFlgPtr, 4.0, 0.3);
}
}

void timerRed(volatile uint32_t port, int* iterator, int* dtyCycMrkr, int* flag, float seconds, float dutyCycle){
if(*flag){
*iterator *= seconds; *flag = 0; //Timer overflows 650 times a second(Hz)
*dtyCycMrkr = dutyCycle * *iterator;
}
if(TPM0->SC & 0x80){ //Timer must overflow 6 times before changing LED state
if(*iterator == 0 || *iterator == *dtyCycMrkr){ //Time overflows for the 6th time
PTB->PTOR |= 0x40000; //LED state changes
if(*iterator == 0)*iterator = seconds * 650; //Overflow tracker set to 6
}
TPM0->SC |= 0x80; //TOF cleared
*iterator -= 1; //Tracks how number of overflows and decrements by 1
}
}

void timerGreen(volatile int* iterator, int* dtyCycMrkr, int* flag, float seconds, float dutyCycle){
if(*flag){
*iterator *= seconds; *flag = 0; //Timer overflows 650 times a second(Hz)
*dtyCycMrkr = dutyCycle * *iterator;
}
if(TPM1->SC & 0x80){ //Timer must overflow 6 times before changing LED state
if(*iterator == 0 || *iterator == *dtyCycMrkr){ //Time overflows for the 6th
PTB->PTOR |= 0x80000; //LED state changes
if(*iterator == 0)*iterator = seconds * 650; //Overflow tracker set to 6
}
TPM1->SC |= 0x80; //TOF cleared
*iterator -= 1; //Tracks how number of overflows and decrements by1
}
}

void timerBlue(volatile int* iterator, int* dtyCycMrkr, int* flag, float seconds, float dutyCycle){
if(*flag){
*iterator *= seconds; *flag = 0; //Timer overflows 650 times a second(Hz)
*dtyCycMrkr = dutyCycle * *iterator;
}
if(TPM2->SC & 0x80){ //Timer must overflow 6 times before changing LED state
if(*iterator == 0 || *iterator == *dtyCycMrkr){ //Time overflows for the 6th
PTD->PTOR |= 0x2; //LED state changes
if(*iterator == 0)*iterator = seconds * 650; //Overflow tracker set to 6
}
TPM2->SC |= 0x80; //TOF cleared
*iterator -= 1; //Tracks how number of overflows and decrements by1
}
}

Outcomes