-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsyscalls.c
68 lines (50 loc) · 1.13 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
#include <sys/stat.h>
#include "stm32f4xx.h"
#include "stm32f4xx_conf.h"
#include "usbd_cdc_vcp.h"
int __errno;
int _close(int file) {
return 0;
}
int _fstat(int file, struct stat *st) {
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) {
if (file != 0) {
return 0;
}
// Use USB CDC Port for stdin
while(!VCP_get_char((uint8_t*)ptr)){};
// Echo typed characters
VCP_put_char((uint8_t)*ptr);
return 1;
}
/* Register name faking - works in collusion with the linker. */
register char * stack_ptr asm ("sp");
caddr_t _sbrk_r (struct _reent *r, int incr) {
extern char end asm ("end"); /* Defined by the linker. */
static char * heap_end;
char * prev_heap_end;
if (heap_end == NULL)
heap_end = & end;
prev_heap_end = heap_end;
if (heap_end + incr > stack_ptr) {
//errno = ENOMEM;
return (caddr_t) -1;
}
heap_end += incr;
return (caddr_t) prev_heap_end;
}
int _write(int file, char *ptr, int len) {
VCP_send_buffer((uint8_t*)ptr, len);
return len;
}