stm32f769/stm32f769i-disco/Src/syscalls.c
Go to the documentation of this file.
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 
20 
21 #define FreeRTOS
22 #define MAX_STACK_SIZE 0x2000
23 
24 extern int __io_putchar(int ch) __attribute__((weak));
25 extern int __io_getchar(void) __attribute__((weak));
26 
27 #ifndef FreeRTOS
28  register char * stack_ptr asm("sp");
29 #endif
30 
31 
32 
33 
34 caddr_t _sbrk(int incr)
35 {
36  extern char end asm("end");
37  static char *heap_end;
38  char *prev_heap_end,*min_stack_ptr;
39 
40  if (heap_end == 0)
41  heap_end = &end;
42 
43  prev_heap_end = heap_end;
44 
45 #ifdef FreeRTOS
46  /* Use the NVIC offset register to locate the main stack pointer. */
47  min_stack_ptr = (char*)(*(unsigned int *)*(unsigned int *)0xE000ED08);
48  /* Locate the STACK bottom address */
49  min_stack_ptr -= MAX_STACK_SIZE;
50 
51  if (heap_end + incr > min_stack_ptr)
52 #else
53  if (heap_end + incr > stack_ptr)
54 #endif
55  {
56 // write(1, "Heap and stack collision\n", 25);
57 // abort();
58  errno = ENOMEM;
59  return (caddr_t) -1;
60  }
61 
62  heap_end += incr;
63 
64  return (caddr_t) prev_heap_end;
65 }
66 
67 /*
68  * _gettimeofday primitive (Stub function)
69  * */
70 int _gettimeofday (struct timeval * tp, struct timezone * tzp)
71 {
72  /* Return fixed data for the timezone. */
73  if (tzp)
74  {
75  tzp->tz_minuteswest = 0;
76  tzp->tz_dsttime = 0;
77  }
78 
79  return 0;
80 }
82 {
83 }
84 
85 int _getpid(void)
86 {
87  return 1;
88 }
89 
90 int _kill(int pid, int sig)
91 {
92  errno = EINVAL;
93  return -1;
94 }
95 
96 void _exit (int status)
97 {
98  _kill(status, -1);
99  while (1) {}
100 }
101 
102 int _write(int file, char *ptr, int len)
103 {
104  int DataIdx;
105 
106  for (DataIdx = 0; DataIdx < len; DataIdx++)
107  {
108  __io_putchar( *ptr++ );
109  }
110  return len;
111 }
112 
113 int _close(int file)
114 {
115  return -1;
116 }
117 
118 int _fstat(int file, struct stat *st)
119 {
120  st->st_mode = S_IFCHR;
121  return 0;
122 }
123 
124 int _isatty(int file)
125 {
126  return 1;
127 }
128 
129 int _lseek(int file, int ptr, int dir)
130 {
131  return 0;
132 }
133 
134 int _read(int file, char *ptr, int len)
135 {
136  int DataIdx;
137 
138  for (DataIdx = 0; DataIdx < len; DataIdx++)
139  {
140  *ptr++ = __io_getchar();
141  }
142 
143  return len;
144 }
145 
146 int _open(char *path, int flags, ...)
147 {
148  /* Pretend like we always fail */
149  return -1;
150 }
151 
152 int _wait(int *status)
153 {
154  errno = ECHILD;
155  return -1;
156 }
157 
158 int _unlink(char *name)
159 {
160  errno = ENOENT;
161  return -1;
162 }
163 
164 int _times(struct tms *buf)
165 {
166  return -1;
167 }
168 
169 int _stat(char *file, struct stat *st)
170 {
171  st->st_mode = S_IFCHR;
172  return 0;
173 }
174 
175 int _link(char *old, char *new)
176 {
177  errno = EMLINK;
178  return -1;
179 }
180 
181 int _fork(void)
182 {
183  errno = EAGAIN;
184  return -1;
185 }
186 
187 int _execve(char *name, char **argv, char **env)
188 {
189  errno = ENOMEM;
190  return -1;
191 }
_gettimeofday
int _gettimeofday(struct timeval *tp, struct timezone *tzp)
Definition: stm32f769/stm32f769i-disco/Src/syscalls.c:70
errno
int errno
_times
int _times(struct tms *buf)
Definition: stm32f769/stm32f769i-disco/Src/syscalls.c:164
time.h
_fstat
int _fstat(int file, struct stat *st)
Definition: stm32f769/stm32f769i-disco/Src/syscalls.c:118
MAX_STACK_SIZE
#define MAX_STACK_SIZE
Definition: stm32f769/stm32f769i-disco/Src/syscalls.c:22
_unlink
int _unlink(char *name)
Definition: stm32f769/stm32f769i-disco/Src/syscalls.c:158
_write
int _write(int file, char *ptr, int len)
Definition: stm32f769/stm32f769i-disco/Src/syscalls.c:102
_exit
void _exit(int status)
Definition: stm32f769/stm32f769i-disco/Src/syscalls.c:96
python.setup.name
name
Definition: porcupine/binding/python/setup.py:69
_isatty
int _isatty(int file)
Definition: stm32f769/stm32f769i-disco/Src/syscalls.c:124
_open
int _open(char *path, int flags,...)
Definition: stm32f769/stm32f769i-disco/Src/syscalls.c:146
_stat
int _stat(char *file, struct stat *st)
Definition: stm32f769/stm32f769i-disco/Src/syscalls.c:169
_read
int _read(int file, char *ptr, int len)
Definition: stm32f769/stm32f769i-disco/Src/syscalls.c:134
_sbrk
void * _sbrk(ptrdiff_t incr)
_sbrk() allocates memory to the newlib heap and is used by malloc and others from the C library
Definition: stm32f411/stm32f411e-disco/Src/sysmem.c:54
_close
int _close(int file)
Definition: stm32f769/stm32f769i-disco/Src/syscalls.c:113
__io_putchar
int __io_putchar(int ch) __attribute__((weak))
Definition: pv_stm32f469.c:141
_kill
int _kill(int pid, int sig)
Definition: stm32f769/stm32f769i-disco/Src/syscalls.c:90
_fork
int _fork(void)
Definition: stm32f769/stm32f769i-disco/Src/syscalls.c:181
_execve
int _execve(char *name, char **argv, char **env)
Definition: stm32f769/stm32f769i-disco/Src/syscalls.c:187
initialise_monitor_handles
void initialise_monitor_handles()
Definition: stm32f769/stm32f769i-disco/Src/syscalls.c:81
__io_getchar
int __io_getchar(void)
Definition: stm32f769/stm32f769i-disco/Src/syscalls.c:25
python.test_porcupine.argv
argv
Definition: test_porcupine.py:158
_lseek
int _lseek(int file, int ptr, int dir)
Definition: stm32f769/stm32f769i-disco/Src/syscalls.c:129
_link
int _link(char *old, char *new)
Definition: stm32f769/stm32f769i-disco/Src/syscalls.c:175
__attribute__
__attribute__((section(".rev16_text"))) __STATIC_INLINE __ASM uint32_t __REV16(uint32_t value)
Reverse byte order (16 bit)
Definition: imxrt1050/imxrt1050-evkb/CMSIS/cmsis_armcc.h:492
_wait
int _wait(int *status)
Definition: stm32f769/stm32f769i-disco/Src/syscalls.c:152
_getpid
int _getpid(void)
Definition: stm32f769/stm32f769i-disco/Src/syscalls.c:85


picovoice_driver
Author(s):
autogenerated on Fri Apr 1 2022 02:14:55