stm32f407/stm32f407g-disc1/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 <sys/errno.h>
15 #include <reent.h>
16 #include <unistd.h>
17 #include <sys/wait.h>
18 #include "stm32f4xx.h"
19 
20 #define FreeRTOS
21 #define MAX_STACK_SIZE 0x200
22 
23 extern int __io_putchar(int ch) __attribute__((weak));
24 extern int __io_getchar(void) __attribute__((weak));
25 
26 #ifndef FreeRTOS
27  register char * stack_ptr asm("sp");
28 #endif
29 
30 
31 
32 
33 caddr_t _sbrk(int incr)
34 {
35  extern char end asm("end");
36  static char *heap_end;
37  char *prev_heap_end,*min_stack_ptr;
38 
39  if (heap_end == 0)
40  heap_end = &end;
41 
42  prev_heap_end = heap_end;
43 
44 #ifdef FreeRTOS
45  /* Use the NVIC offset register to locate the main stack pointer. */
46  min_stack_ptr = (char*)(*(unsigned int *)*(unsigned int *)0xE000ED08);
47  /* Locate the STACK bottom address */
48  min_stack_ptr -= MAX_STACK_SIZE;
49 
50  if (heap_end + incr > min_stack_ptr)
51 #else
52  if (heap_end + incr > stack_ptr)
53 #endif
54  {
55 // write(1, "Heap and stack collision\n", 25);
56 // abort();
57  errno = ENOMEM;
58  return (caddr_t) -1;
59  }
60 
61  heap_end += incr;
62 
63  return (caddr_t) prev_heap_end;
64 }
65 
66 /*
67  * _gettimeofday primitive (Stub function)
68  * */
69 int _gettimeofday (struct timeval * tp, struct timezone * tzp)
70 {
71  /* Return fixed data for the timezone. */
72  if (tzp)
73  {
74  tzp->tz_minuteswest = 0;
75  tzp->tz_dsttime = 0;
76  }
77 
78  return 0;
79 }
81 {
82 }
83 
84 int _getpid(void)
85 {
86  return 1;
87 }
88 
89 int _kill(int pid, int sig)
90 {
91  errno = EINVAL;
92  return -1;
93 }
94 
95 void _exit (int status)
96 {
97  _kill(status, -1);
98  while (1) {}
99 }
100 
101 int _write(int file, char *ptr, int len)
102 {
103  int DataIdx;
104 
105  for (DataIdx = 0; DataIdx < len; DataIdx++)
106  {
107  __io_putchar( *ptr++ );
108  }
109  return len;
110 }
111 
112 int _close(int file)
113 {
114  return -1;
115 }
116 
117 int _fstat(int file, struct stat *st)
118 {
119  st->st_mode = S_IFCHR;
120  return 0;
121 }
122 
123 int _isatty(int file)
124 {
125  return 1;
126 }
127 
128 int _lseek(int file, int ptr, int dir)
129 {
130  return 0;
131 }
132 
133 int _read(int file, char *ptr, int len)
134 {
135  int DataIdx;
136 
137  for (DataIdx = 0; DataIdx < len; DataIdx++)
138  {
139  *ptr++ = __io_getchar();
140  }
141 
142  return len;
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 }
_getpid
int _getpid(void)
Definition: stm32f407/stm32f407g-disc1/Src/syscalls.c:84
__io_getchar
int __io_getchar(void)
Definition: stm32f407/stm32f407g-disc1/Src/syscalls.c:24
_close
int _close(int file)
Definition: stm32f407/stm32f407g-disc1/Src/syscalls.c:112
_kill
int _kill(int pid, int sig)
Definition: stm32f407/stm32f407g-disc1/Src/syscalls.c:89
initialise_monitor_handles
void initialise_monitor_handles()
Definition: stm32f407/stm32f407g-disc1/Src/syscalls.c:80
errno
int errno
_exit
void _exit(int status)
Definition: stm32f407/stm32f407g-disc1/Src/syscalls.c:95
time.h
_lseek
int _lseek(int file, int ptr, int dir)
Definition: stm32f407/stm32f407g-disc1/Src/syscalls.c:128
_isatty
int _isatty(int file)
Definition: stm32f407/stm32f407g-disc1/Src/syscalls.c:123
_times
int _times(struct tms *buf)
Definition: stm32f407/stm32f407g-disc1/Src/syscalls.c:163
_gettimeofday
int _gettimeofday(struct timeval *tp, struct timezone *tzp)
Definition: stm32f407/stm32f407g-disc1/Src/syscalls.c:69
__io_putchar
int __io_putchar(int ch) __attribute__((weak))
Definition: pv_stm32f469.c:141
python.setup.name
name
Definition: porcupine/binding/python/setup.py:69
_write
int _write(int file, char *ptr, int len)
Definition: stm32f407/stm32f407g-disc1/Src/syscalls.c:101
_read
int _read(int file, char *ptr, int len)
Definition: stm32f407/stm32f407g-disc1/Src/syscalls.c:133
_execve
int _execve(char *name, char **argv, char **env)
Definition: stm32f407/stm32f407g-disc1/Src/syscalls.c:186
_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
_wait
int _wait(int *status)
Definition: stm32f407/stm32f407g-disc1/Src/syscalls.c:151
_stat
int _stat(char *file, struct stat *st)
Definition: stm32f407/stm32f407g-disc1/Src/syscalls.c:168
_fork
int _fork(void)
Definition: stm32f407/stm32f407g-disc1/Src/syscalls.c:180
_open
int _open(char *path, int flags,...)
Definition: stm32f407/stm32f407g-disc1/Src/syscalls.c:145
_unlink
int _unlink(char *name)
Definition: stm32f407/stm32f407g-disc1/Src/syscalls.c:157
python.test_porcupine.argv
argv
Definition: test_porcupine.py:158
_link
int _link(char *old, char *new)
Definition: stm32f407/stm32f407g-disc1/Src/syscalls.c:174
_fstat
int _fstat(int file, struct stat *st)
Definition: stm32f407/stm32f407g-disc1/Src/syscalls.c:117
__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
MAX_STACK_SIZE
#define MAX_STACK_SIZE
Definition: stm32f407/stm32f407g-disc1/Src/syscalls.c:21


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