forked from commaai/panda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibc.h
51 lines (43 loc) · 992 Bytes
/
libc.h
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
50
// **** shitty libc ****
void delay(int a) {
volatile int i;
for (i=0;i<a;i++);
}
void *memset(void *str, int c, unsigned int n) {
int i;
for (i = 0; i < n; i++) {
*((uint8_t*)str) = c;
++str;
}
return str;
}
void *memcpy(void *dest, const void *src, unsigned int n) {
int i;
// TODO: make not slow
for (i = 0; i < n; i++) {
((uint8_t*)dest)[i] = *(uint8_t*)src;
++src;
}
return dest;
}
int memcmp(const void * ptr1, const void * ptr2, unsigned int num) {
int i;
for (i = 0; i < num; i++) {
if ( ((uint8_t*)ptr1)[i] != ((uint8_t*)ptr2)[i] ) return -1;
}
return 0;
}
// ********************* IRQ helpers *********************
int critical_depth = 0;
void enter_critical_section() {
__disable_irq();
// this is safe because interrupts are disabled
critical_depth += 1;
}
void exit_critical_section() {
// this is safe because interrupts are disabled
critical_depth -= 1;
if (critical_depth == 0) {
__enable_irq();
}
}