-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.h
More file actions
49 lines (41 loc) · 1.88 KB
/
util.h
File metadata and controls
49 lines (41 loc) · 1.88 KB
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
39
40
41
42
43
44
45
46
47
48
49
#ifndef _UTIL_H_
#define _UTIL_H_
#include "usbserial.h"
#define assert(cond) \
if(!(cond)) { \
disable_all_interrupts(); \
\
if (usbserial_is_rts()) { \
enable_interrupt(35); \
prioritize_interrupt(35, 0); \
usbserial_trace("assertion failed: %s.\n", #cond); \
} \
\
while(1) { \
delay_ms(50); \
/* toggle_led(); */ \
} \
}
#define cycles_in_ms(t) ((t) * (F_CPU / 1000))
#define cycles_in_us(t) ((t) * (F_CPU / 1000000))
uint64_t cycles();
void delay_ms(uint64_t n);
void delay_us(uint64_t n);
#define set_led_color(c) { \
if (c & (1 << 0)) { \
GPIOD_PSOR = (1ul << 6); \
} else { \
GPIOD_PCOR = (1ul << 6); \
} \
\
if (c & (1 << 1)) { \
GPIOC_PSOR = (1ul << 2); \
} else { \
GPIOC_PCOR = (1ul << 2); \
}
#define toggle_led() GPIOC_PTOR = (1ul << 1)
#define turn_on_led() GPIOC_PCOR = (1ul << 1)
#define turn_off_led() GPIOC_PSOR = (1ul << 1)
#define LCG_RAND_MAX 2147483647
uint32_t lcg_rand();
#endif