Last active
February 15, 2024 11:36
-
-
Save ctring/7f12d812fb594eecc493 to your computer and use it in GitHub Desktop.
Convert from SysCtlDelay in TivaWare library to milliseconds and microseconds delay.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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)); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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."