Mercurial > ~darius > hgwebdir.cgi > stm32temp
comparison syscalls.c @ 0:c59513fd84fb
Initial commit of STM32 test code.
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Mon, 03 Oct 2011 21:19:15 +1030 |
parents | |
children | 74e9b3baac1e |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c59513fd84fb |
---|---|
1 /* | |
2 * syscalls.c | |
3 * | |
4 * Created on: 03.12.2009 | |
5 * Author: Martin Thomas, 3BSD license | |
6 */ | |
7 | |
8 //#define SBRK_VERBOSE 1 | |
9 | |
10 #include <stdio.h> | |
11 #include <reent.h> | |
12 #include <errno.h> | |
13 #include <stdlib.h> /* abort */ | |
14 #include <sys/types.h> | |
15 #include <sys/stat.h> | |
16 | |
17 #include "comm.h" | |
18 #include "stm32f10x.h" /* for _get_PSP() from core_cm3.h*/ | |
19 | |
20 #undef errno | |
21 extern int errno; | |
22 | |
23 int | |
24 _kill(int pid, int sig) { | |
25 pid = pid; sig = sig; /* avoid warnings */ | |
26 errno = EINVAL; | |
27 return -1; | |
28 } | |
29 | |
30 void _exit(int status) { | |
31 printf("_exit called with parameter %d\n", status); | |
32 while(1) | |
33 ; | |
34 } | |
35 | |
36 int | |
37 _getpid(void) { | |
38 return 1; | |
39 } | |
40 | |
41 | |
42 extern char _end; /* Defined by the linker */ | |
43 static char *heap_end; | |
44 | |
45 char * | |
46 get_heap_end(void) { | |
47 return (char*) heap_end; | |
48 } | |
49 | |
50 char * | |
51 get_stack_top(void) { | |
52 return (char*) __get_MSP(); | |
53 //return (char*) __get_PSP(); | |
54 } | |
55 | |
56 caddr_t | |
57 _sbrk(int incr) { | |
58 char *prev_heap_end; | |
59 #if SBRK_VERBOSE | |
60 printf("_sbrk called with incr %d\n", incr); | |
61 #endif | |
62 if (heap_end == 0) { | |
63 heap_end = &_end; | |
64 } | |
65 prev_heap_end = heap_end; | |
66 #if 1 | |
67 if (heap_end + incr > get_stack_top()) { | |
68 printf("Heap and stack collision\n"); | |
69 abort(); | |
70 } | |
71 #endif | |
72 heap_end += incr; | |
73 return (caddr_t) prev_heap_end; | |
74 } | |
75 | |
76 int | |
77 _close(int file) { | |
78 file = file; /* avoid warning */ | |
79 return -1; | |
80 } | |
81 | |
82 int | |
83 _fstat(int file, struct stat *st) { | |
84 file = file; /* avoid warning */ | |
85 st->st_mode = S_IFCHR; | |
86 return 0; | |
87 } | |
88 | |
89 int | |
90 _isatty(int file) { | |
91 file = file; /* avoid warning */ | |
92 return 1; | |
93 } | |
94 | |
95 int | |
96 _lseek(int file, int ptr, int dir) { | |
97 file = file; /* avoid warning */ | |
98 ptr = ptr; /* avoid warning */ | |
99 dir = dir; /* avoid warning */ | |
100 return 0; | |
101 } | |
102 | |
103 int | |
104 _read(int file, char *ptr, int len) { | |
105 file = file; /* avoid warning */ | |
106 ptr = ptr; /* avoid warning */ | |
107 len = len; /* avoid warning */ | |
108 return 0; | |
109 } | |
110 | |
111 int | |
112 _write(int file, char *ptr, int len) { | |
113 int todo; | |
114 | |
115 file = file; /* avoid warning */ | |
116 for (todo = 0; todo < len; todo++) { | |
117 comm_put(*ptr++); | |
118 } | |
119 return len; | |
120 } |