STSW-STLKT01: Projects/SensorTile/Applications/AudioLoop/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,*min_stack_ptr;
40 
41  if (heap_end == 0)
42  heap_end = &end;
43 
44  prev_heap_end = heap_end;
45 
46 #ifdef FreeRTOS
47  /* Use the NVIC offset register to locate the main stack pointer. */
48  min_stack_ptr = (char*)(*(unsigned int *)*(unsigned int *)0xE000ED08);
49  /* Locate the STACK bottom address */
50  min_stack_ptr -= MAX_STACK_SIZE;
51 
52  if (heap_end + incr > min_stack_ptr)
53 #else
54  if (heap_end + incr > stack_ptr)
55 #endif
56  {
57 // write(1, "Heap and stack collision\n", 25);
58 // abort();
59  errno = ENOMEM;
60  return (caddr_t) -1;
61  }
62 
63  heap_end += incr;
64 
65  return (caddr_t) prev_heap_end;
66 }
67 
68 /*
69  * _gettimeofday primitive (Stub function)
70  * */
71 int _gettimeofday (struct timeval * tp, struct timezone * tzp)
72 {
73  /* Return fixed data for the timezone. */
74  if (tzp)
75  {
76  tzp->tz_minuteswest = 0;
77  tzp->tz_dsttime = 0;
78  }
79 
80  return 0;
81 }
82 void initialise_monitor_handles()
83 {
84 }
85 
86 int _getpid(void)
87 {
88  return 1;
89 }
90 
91 int _kill(int pid, int sig)
92 {
93  errno = EINVAL;
94  return -1;
95 }
96 
97 void _exit (int status)
98 {
99  _kill(status, -1);
100  while (1) {}
101 }
102 
103 int _write(int file, char *ptr, int len)
104 {
105  int DataIdx;
106 
107  for (DataIdx = 0; DataIdx < len; DataIdx++)
108  {
109  __io_putchar( *ptr++ );
110  }
111  return len;
112 }
113 
114 int _close(int file)
115 {
116  return -1;
117 }
118 
119 int _fstat(int file, struct stat *st)
120 {
121  st->st_mode = S_IFCHR;
122  return 0;
123 }
124 
125 int _isatty(int file)
126 {
127  return 1;
128 }
129 
130 int _lseek(int file, int ptr, int dir)
131 {
132  return 0;
133 }
134 
135 int _read(int file, char *ptr, int len)
136 {
137  /* scanf calls _read() with len=1024, so eat one character at time */
138  *ptr = __io_getchar();
139  return 1;
140 }
141 
142 int _open(char *path, int flags, ...)
143 {
144  /* Pretend like we always fail */
145  return -1;
146 }
147 
148 int _wait(int *status)
149 {
150  errno = ECHILD;
151  return -1;
152 }
153 
154 int _unlink(char *name)
155 {
156  errno = ENOENT;
157  return -1;
158 }
159 
160 int _times(struct tms *buf)
161 {
162  return -1;
163 }
164 
165 int _stat(char *file, struct stat *st)
166 {
167  st->st_mode = S_IFCHR;
168  return 0;
169 }
170 
171 int _link(char *old, char *new)
172 {
173  errno = EMLINK;
174  return -1;
175 }
176 
177 int _fork(void)
178 {
179  errno = EAGAIN;
180  return -1;
181 }
182 
183 int _execve(char *name, char **argv, char **env)
184 {
185  errno = ENOMEM;
186  return -1;
187 }
Generated by   doxygen 1.8.13