I am trying to understand how to write a delay function for a GPIO. For example,
void PortF_Init(void){ volatile unsigned long delay;
SYSCTL_RCGC2_R |= 0x00000020; // 1) activate clock for Port F
delay = SYSCTL_RCGC2_R; // allow time for clock to start
...
}
unsigned long Led;
void Delay(void){unsigned long volatile time;
time = 145448; // 0.1sec
while(time){
time--;
}
}
int main(void){
PortF_Init(); // make PF1 out (PF1 built-in LED)
while(1){
Led = GPIO_PORTF_DATA_R; // read previous
Led = Led^0x02; // toggle red LED, PF1
GPIO_PORTF_DATA_R = Led; // output
Delay();
}
}
For the function Delay, how can i estimate the following? What is the default clock for the GPIO?
time = 145448; // 0.1sec
From the documents and
SYSCTL_RCGC2_R |= 0x00000020; // 1) activate clock for Port F
, it is not clear to me what clock is being used for the GPIO.
Regards,
Leon