Created
February 22, 2013 12:18
-
-
Save rigid/5013056 to your computer and use it in GitHub Desktop.
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
/** use DWT counter to delay */ | |
void dwt_sleep(u32 time) | |
{ | |
static volatile u32 *DWT_CYCCNT = (u32 *) 0xE0001004; | |
static volatile u32 *DWT_CONTROL = (u32 *) 0xE0001000; | |
static volatile u32 *SCB_DEMCR = (u32 *) 0xE000EDFC; | |
/* reset the counter */ | |
*DWT_CYCCNT = 0; | |
/* start DWT counter */ | |
*DWT_CONTROL = *DWT_CONTROL | 1; | |
/* delay */ | |
while(*DWT_CYCCNT <= time); | |
/* stop DWT counter */ | |
*DWT_CONTROL = 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment