STSW-STLKT01: Projects/SensorTile/Applications/DataLog/Src/syscalls.c Source File

STSW-STLKT01

syscalls.c
1 /* Support files for GNU libc. Files in the system namespace go here.
2  Files in the C namespace (ie those that do not start with an
3  underscore) go in .c. */
4 
5 #include <_ansi.h>
6 #include <sys/types.h>
7 #include <sys/stat.h>
8 #include <sys/fcntl.h>
9 #include <stdio.h>
10 #include <string.h>
11 #include <time.h>
12 #include <sys/time.h>
13 #include <sys/times.h>
14 #include <errno.h>
15 #include <reent.h>
16 #include <unistd.h>
17 #include <sys/wait.h>
18 
19 //#undef errno
20 extern int errno;
21 
22 //#define FreeRTOS
23 #define MAX_STACK_SIZE 0x200
24 
25 extern int __io_putchar(int ch) __attribute__((weak));
26 extern int __io_getchar(void) __attribute__((weak));
27 
28 #ifndef FreeRTOS
29  register char * stack_ptr asm("sp");
30 #endif
31 
32 
33 
34 
35 caddr_t _sbrk(int incr)
36 {
37  extern char end /*asm("end")*/;
38  static char *heap_end;
39  char *prev_heap_end;
40 #ifdef FreeRTOS
41  char *min_stack_ptr;
42 #endif
43 
44  if (heap_end == 0)
45  heap_end = &end;
46 
47  prev_heap_end = heap_end;
48 
49 #ifdef FreeRTOS
50  /* Use the NVIC offset register to locate the main stack pointer. */
51  min_stack_ptr = (char*)(*(unsigned int *)*(unsigned int *)0xE000ED08);
52  /* Locate the STACK bottom address */
53  min_stack_ptr -= MAX_STACK_SIZE;
54 
55  if (heap_end + incr > min_stack_ptr)
56 #else
57  if (heap_end + incr > stack_ptr)
58 #endif
59  {
60 // write(1, "Heap and stack collision\n", 25);
61 // abort();
62  errno = ENOMEM;
63  return (caddr_t) -1;
64  }
65 
66  heap_end += incr;
67 
68  return (caddr_t) prev_heap_end;
69 }
70 
71 /*
72  * _gettimeofday primitive (Stub function)
73  * */
74 int _gettimeofday (struct timeval * tp, struct timezone * tzp)
75 {
76  /* Return fixed data for the timezone. */
77  if (tzp)
78  {
79  tzp->tz_minuteswest = 0;
80  tzp->tz_dsttime = 0;
81  }
82 
83  return 0;
84 }
85 void initialise_monitor_handles()
86 {
87 }
88 
89 int _getpid(void)
90 {
91  return 1;
92 }
93 
94 int _kill(int pid, int sig)
95 {
96  errno = EINVAL;
97  return -1;
98 }
99 
100 void _exit (int status)
101 {
102  _kill(status, -1);
103  while (1) {}
104 }
105 
106 int _write(int file, char *ptr, int len)
107 {
108  int DataIdx;
109 
110  for (DataIdx = 0; DataIdx < len; DataIdx++)
111  {
112  __io_putchar( *ptr++ );
113  }
114  return len;
115 }
116 
117 int _close(int file)
118 {
119  return -1;
120 }
121 
122 int _fstat(int file, struct stat *st)
123 {
124  st->st_mode = S_IFCHR;
125  return 0;
126 }
127 
128 int _isatty(int file)
129 {
130  return 1;
131 }
132 
133 int _lseek(int file, int ptr, int dir)
134 {
135  return 0;
136 }
137 
138 int _read(int file, char *ptr, int len)
139 {
140  /* scanf calls _read() with len=1024, so eat one character at time */
141  *ptr = __io_getchar();
142  return 1;
143 }
144 
145 int _open(char *path, int flags, ...)
146 {
147  /* Pretend like we always fail */
148  return -1;
149 }
150 
151 int _wait(int *status)
152 {
153  errno = ECHILD;
154  return -1;
155 }
156 
157 int _unlink(char *name)
158 {
159  errno = ENOENT;
160  return -1;
161 }
162 
163 int _times(struct tms *buf)
164 {
165  return -1;
166 }
167 
168 int _stat(char *file, struct stat *st)
169 {
170  st->st_mode = S_IFCHR;
171  return 0;
172 }
173 
174 int _link(char *old, char *new)
175 {
176  errno = EMLINK;
177  return -1;
178 }
179 
180 int _fork(void)
181 {
182  errno = EAGAIN;
183  return -1;
184 }
185 
186 int _execve(char *name, char **argv, char **env)
187 {
188  errno = ENOMEM;
189  return -1;
190 }
Generated by   doxygen 1.8.13