STM32F769IDiscovery  1.00
uDANTE Audio Networking with STM32F7 DISCO board
syscalls.c
Go to the documentation of this file.
1 
46 /* Includes */
47 #include <sys/stat.h>
48 #include <stdlib.h>
49 #include <errno.h>
50 #include <stdio.h>
51 #include <signal.h>
52 #include <time.h>
53 #include <sys/time.h>
54 #include <sys/times.h>
55 
56 
57 /* Variables */
58 //#undef errno
59 extern int errno;
60 extern int __io_putchar(int ch) __attribute__((weak));
61 extern int __io_getchar(void) __attribute__((weak));
62 
63 register char * stack_ptr asm("sp");
64 
65 char *__env[1] = { 0 };
66 char **environ = __env;
67 
68 
69 /* Functions */
71 {
72 }
73 
74 int _getpid(void)
75 {
76  return 1;
77 }
78 
79 int _kill(int pid, int sig)
80 {
81  errno = EINVAL;
82  return -1;
83 }
84 
85 void _exit (int status)
86 {
87  _kill(status, -1);
88  while (1) {} /* Make sure we hang here */
89 }
90 
91 int _read (int file, char *ptr, int len)
92 {
93  int DataIdx;
94 
95  for (DataIdx = 0; DataIdx < len; DataIdx++)
96  {
97  *ptr++ = __io_getchar();
98  }
99 
100 return len;
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 caddr_t _sbrk(int incr)
115 {
116  extern char end asm("end");
117  static char *heap_end;
118  char *prev_heap_end;
119 
120  if (heap_end == 0)
121  heap_end = &end;
122 
123  prev_heap_end = heap_end;
124  if (heap_end + incr > stack_ptr)
125  {
126 // write(1, "Heap and stack collision\n", 25);
127 // abort();
128  errno = ENOMEM;
129  return (caddr_t) -1;
130  }
131 
132  heap_end += incr;
133 
134  return (caddr_t) prev_heap_end;
135 }
136 
137 int _close(int file)
138 {
139  return -1;
140 }
141 
142 
143 int _fstat(int file, struct stat *st)
144 {
145  st->st_mode = S_IFCHR;
146  return 0;
147 }
148 
149 int _isatty(int file)
150 {
151  return 1;
152 }
153 
154 int _lseek(int file, int ptr, int dir)
155 {
156  return 0;
157 }
158 
159 int _open(char *path, int flags, ...)
160 {
161  /* Pretend like we always fail */
162  return -1;
163 }
164 
165 int _wait(int *status)
166 {
167  errno = ECHILD;
168  return -1;
169 }
170 
171 int _unlink(char *name)
172 {
173  errno = ENOENT;
174  return -1;
175 }
176 
177 int _times(struct tms *buf)
178 {
179  return -1;
180 }
181 
182 int _stat(char *file, struct stat *st)
183 {
184  st->st_mode = S_IFCHR;
185  return 0;
186 }
187 
188 int _link(char *old, char *new)
189 {
190  errno = EMLINK;
191  return -1;
192 }
193 
194 int _fork(void)
195 {
196  errno = EAGAIN;
197  return -1;
198 }
199 
200 int _execve(char *name, char **argv, char **env)
201 {
202  errno = ENOMEM;
203  return -1;
204 }
int _read(int file, char *ptr, int len)
Definition: syscalls.c:91
int _unlink(char *name)
Definition: syscalls.c:171
int _open(char *path, int flags,...)
Definition: syscalls.c:159
int __io_getchar(void)
Definition: syscalls.c:61
caddr_t _sbrk(int incr)
Definition: syscalls.c:114
__attribute__((section(".rev16_text"))) __STATIC_INLINE __ASM uint32_t __REV16(uint32_t value)
Reverse byte order (16 bit)
Definition: cmsis_armcc.h:388
int __io_putchar(int ch) __attribute__((weak))
return ch
Definition: lcd_log.c:311
int _link(char *old, char *new)
Definition: syscalls.c:188
void _exit(int status)
Definition: syscalls.c:85
void initialise_monitor_handles()
Definition: syscalls.c:70
int _stat(char *file, struct stat *st)
Definition: syscalls.c:182
int _getpid(void)
Definition: syscalls.c:74
int _times(struct tms *buf)
Definition: syscalls.c:177
int _isatty(int file)
Definition: syscalls.c:149
int _kill(int pid, int sig)
Definition: syscalls.c:79
int _fstat(int file, struct stat *st)
Definition: syscalls.c:143
char ** environ
Definition: syscalls.c:66
int _execve(char *name, char **argv, char **env)
Definition: syscalls.c:200
int _fork(void)
Definition: syscalls.c:194
int errno
int _close(int file)
Definition: syscalls.c:137
int _lseek(int file, int ptr, int dir)
Definition: syscalls.c:154
int _wait(int *status)
Definition: syscalls.c:165
int _write(int file, char *ptr, int len)
Definition: syscalls.c:103