-
-
Save ctring/7f12d812fb594eecc493 to your computer and use it in GitHub Desktop.
/* | |
* delay.c - Delay in millisecond and microsecond functions | |
* | |
* Created on: Jul 7, 2014 | |
* Author: Cuong T. Nguyen | |
*/ | |
#include <stdint.h> | |
#include <stdbool.h> | |
#include "driverlib/sysctl.h" | |
void delayMs(uint32_t ui32Ms) { | |
// 1 clock cycle = 1 / SysCtlClockGet() second | |
// 1 SysCtlDelay = 3 clock cycle = 3 / SysCtlClockGet() second | |
// 1 second = SysCtlClockGet() / 3 | |
// 0.001 second = 1 ms = SysCtlClockGet() / 3 / 1000 | |
SysCtlDelay(ui32Ms * (SysCtlClockGet() / 3 / 1000)); | |
} | |
void delayUs(uint32_t ui32Us) { | |
SysCtlDelay(ui32Us * (SysCtlClockGet() / 3 / 1000000)); | |
} | |
It was 7 years ago so I'm not exactly sure where I got that number. A Google search for SysCtlDelay
yields this document (which looks very familiar to me so highly likely I got the number from it). On page 77, it says:
SysCtlDelay() is a loop timer provided in TivaWare. The count parameter is the loop count, not the actual delay in clock cycles. Each loop is 3 CPU cycles
Hi, bro. How do you know 1 SysCtlDelay = 3 clock cycle? It is not mentioned in reference manual.
It is actually mentioned in the SysCtlDelay description in the api manual as the following "This function provides a means of generating a delay by executing a simple 3 instruction cycle
loop a given number of times. It is written in assembly to keep the loop instruction count
consistent across tool chains."
Hi, bro. How do you know 1 SysCtlDelay = 3 clock cycle? It is not mentioned in reference manual.