-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelay.c
More file actions
38 lines (33 loc) · 999 Bytes
/
Copy pathdelay.c
File metadata and controls
38 lines (33 loc) · 999 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
* delay.c
*
* Created: 1/24/2025 5:24:49 PM
* Author: itsLydt
*/
#include <stdint.h>
#include "config.h"
/* default number of cpu cycles in one millisecond */
const uint32_t CYCLES_PER_MS = SYSTEM_CLOCK_FREQ / 1000;
#define CYCLES_PER_US (CYCLES_PER_MS / 1000)
#define CYCLES_PER_NS (CYCLES_PER_US / 1000)
/* wait at least ms milliseconds, approximately */
void delay_ms(uint32_t ms){
ms *= CYCLES_PER_MS / 6; //6 = appx number of instructions in the loop body below
for(; ms > 0; --ms){
__asm volatile("nop");
}
}
/* wait at least us microseconds, approximately */
void delay_us(uint32_t us){
us *= CYCLES_PER_US / 6; //6 = appx number of instructions in the loop body below
for(; us > 0; --us){
__asm volatile("nop");
}
}
/* wait at least ns nanoseconds, approximately */
void delay_ns(uint32_t ns){
ns *= CYCLES_PER_NS / 6; //6 = appx number of instructions in the loop body below
for(; ns > 0; --ns){
__asm volatile("nop");
}
}