-
Notifications
You must be signed in to change notification settings - Fork 1
/
syscalls.c
69 lines (57 loc) · 1.4 KB
/
syscalls.c
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <sys/stat.h>
#include "efm32.h"
#define UART_DR(baseaddr) (*(unsigned int *)(baseaddr))
#define UART_FR(baseaddr) (*(((unsigned int *)(baseaddr))+6))
#define USART_USED UART1
int _close(int file) {
return 0;
}
int _fstat(int file, struct stat *st) {
st->st_mode = S_IFCHR;
return 0;
}
int _isatty(int file) {
return 1;
}
int _lseek(int file, int ptr, int dir) {
return 0;
}
int _open(const char *name, int flags, int mode) {
return -1;
}
int _read(int file, char *ptr, int len) {
int todo;
if(len == 0)
return 0;
while(!(USART_USED->STATUS & UART_STATUS_RXDATAV));
*ptr++ = USART_USED->RXDATA;
for(todo = 1; todo < len; todo++) {
while(!(USART_USED->STATUS & UART_STATUS_RXDATAV));
*ptr++ = USART_USED->RXDATA;
}
return todo;
}
static char *heap_end = 0;
caddr_t _sbrk(int incr) {
extern char __cs3_heap_start; /* Defined by the linker */
extern char __cs3_heap_end; /* Defined by the linker */
char *prev_heap_end;
if (heap_end == 0) {
heap_end = &__cs3_heap_start;
}
prev_heap_end = heap_end;
if (heap_end + incr > &__cs3_heap_end) {
/* Heap and stack collision */
return (caddr_t)0;
}
heap_end += incr;
return (caddr_t) prev_heap_end;
}
int _write(int file, char *ptr, int len) {
int todo;
for (todo = 0; todo < len; todo++) {
while (!(USART_USED->STATUS & USART_STATUS_TXBL));
USART_USED->TXDATA = *ptr++;
}
return len;
}