comparison syscalls.c @ 3:74e9b3baac1e

Jumbo commit to make things work. Note I have t
author Daniel O'Connor <darius@dons.net.au>
date Sun, 01 Jan 2012 11:01:13 +1030
parents c59513fd84fb
children
comparison
equal deleted inserted replaced
2:274e01fa5a4c 3:74e9b3baac1e
3 * 3 *
4 * Created on: 03.12.2009 4 * Created on: 03.12.2009
5 * Author: Martin Thomas, 3BSD license 5 * Author: Martin Thomas, 3BSD license
6 */ 6 */
7 7
8 //#define SBRK_VERBOSE 1
9
10 #include <stdio.h> 8 #include <stdio.h>
11 #include <reent.h> 9 #include <reent.h>
12 #include <errno.h> 10 #include <errno.h>
13 #include <stdlib.h> /* abort */ 11 #include <stdlib.h> /* abort */
14 #include <sys/types.h> 12 #include <sys/types.h>
15 #include <sys/stat.h> 13 #include <sys/stat.h>
14 #include <sys/time.h>
16 15
17 #include "comm.h" 16 #include "comm.h"
18 #include "stm32f10x.h" /* for _get_PSP() from core_cm3.h*/ 17 #include "stm32f10x.h" /* for _get_PSP() from core_cm3.h*/
19 18
20 #undef errno 19 #undef errno
25 pid = pid; sig = sig; /* avoid warnings */ 24 pid = pid; sig = sig; /* avoid warnings */
26 errno = EINVAL; 25 errno = EINVAL;
27 return -1; 26 return -1;
28 } 27 }
29 28
30 void _exit(int status) { 29 void
30 _exit(int status) {
31 printf("_exit called with parameter %d\n", status); 31 printf("_exit called with parameter %d\n", status);
32 while(1) 32 while(1)
33 ; 33 ;
34 } 34 }
35 35
36 int 36 int
37 _getpid(void) { 37 _getpid(void) {
38 return 1; 38 return 1;
39 } 39 }
40
41 40
42 extern char _end; /* Defined by the linker */ 41 extern char _end; /* Defined by the linker */
43 static char *heap_end; 42 static char *heap_end;
44 43
45 char * 44 char *
47 return (char*) heap_end; 46 return (char*) heap_end;
48 } 47 }
49 48
50 char * 49 char *
51 get_stack_top(void) { 50 get_stack_top(void) {
51 /* Use MSP (vs PSP) - the processor is in Thread mode out of reset */
52 return (char*) __get_MSP(); 52 return (char*) __get_MSP();
53 //return (char*) __get_PSP();
54 } 53 }
55 54
56 caddr_t 55 caddr_t
57 _sbrk(int incr) { 56 _sbrk(int incr) {
58 char *prev_heap_end; 57 char *prev_heap_end;
59 #if SBRK_VERBOSE 58
60 printf("_sbrk called with incr %d\n", incr);
61 #endif
62 if (heap_end == 0) { 59 if (heap_end == 0) {
63 heap_end = &_end; 60 heap_end = &_end;
64 } 61 }
65 prev_heap_end = heap_end; 62 prev_heap_end = heap_end;
66 #if 1 63
67 if (heap_end + incr > get_stack_top()) { 64 if (heap_end + incr > get_stack_top()) {
68 printf("Heap and stack collision\n"); 65 printf("Heap and stack collision\n");
69 abort(); 66 abort();
70 } 67 }
71 #endif 68
72 heap_end += incr; 69 heap_end += incr;
73 return (caddr_t) prev_heap_end; 70 return (caddr_t) prev_heap_end;
74 } 71 }
75 72
76 int 73 int
116 for (todo = 0; todo < len; todo++) { 113 for (todo = 0; todo < len; todo++) {
117 comm_put(*ptr++); 114 comm_put(*ptr++);
118 } 115 }
119 return len; 116 return len;
120 } 117 }
118
119 int
120 _gettimeofday_r(struct _reent *reent __attribute__((unused)), struct timeval *tp, void *tzp __attribute__((unused))) {
121 tp->tv_sec = RTC_GetCounter();
122 tp->tv_usec = 0;
123
124 return 0;
125 }
126
127 int
128 settimeofday(const struct timeval *tp, const struct timezone *tzp __attribute__((unused))) {
129 RTC_SetCounter(tp->tv_sec);
130
131 return 0;
132 }
133
134 clock_t
135 _clock (void) {
136 return RTC_GetCounter();
137 }
138
139 void
140 __tz_lock (void) {
141 }
142
143
144 void
145 __tz_unlock (void) {
146 }
147
148 static __tzinfo_type tzinfo = {1, 0,
149 { {'J', 0, 0, 0, 0, (time_t)0, 0L },
150 {'J', 0, 0, 0, 0, (time_t)0, 0L }
151 }
152 };
153
154 __tzinfo_type *
155 __gettzinfo (void) {
156 return &tzinfo;
157 }
158
159 /* Stub, required for strftime?! */
160 int
161 _open(const char *name __attribute__((unused)), int mode __attribute__((unused)), ...) {
162 return -1;
163 }