source: trunk/fw_g473rct/Core/Src/syscalls.c

Last change on this file was 20, checked in by f.jahn, 5 days ago

adc dma funktioniert und modbus funktioniert

File size: 5.0 KB
Line 
1/**
2 ******************************************************************************
3 * @file      syscalls.c
4 * @author    Auto-generated by STM32CubeMX
5 * @brief     Minimal System calls file
6 *
7 *            For more information about which c-functions
8 *            need which of these lowlevel functions
9 *            please consult the Newlib or Picolibc libc-manual
10 ******************************************************************************
11 * @attention
12 *
13 * Copyright (c) 2020-2025 STMicroelectronics.
14 * All rights reserved.
15 *
16 * This software is licensed under terms that can be found in the LICENSE file
17 * in the root directory of this software component.
18 * If no LICENSE file comes with this software, it is provided AS-IS.
19 *
20 ******************************************************************************
21 */
22
23/* Includes */
24#include <sys/stat.h>
25#include <stdlib.h>
26#include <errno.h>
27#include <stdio.h>
28#include <signal.h>
29#include <time.h>
30#include <sys/time.h>
31#include <sys/times.h>
32
33
34/* Variables */
35extern int __io_putchar(int ch) __attribute__((weak));
36extern int __io_getchar(void) __attribute__((weak));
37
38
39char *__env[1] = { 0 };
40char **environ = __env;
41
42
43/* Functions */
44void initialise_monitor_handles()
45{
46}
47
48int _getpid(void)
49{
50  return 1;
51}
52
53int _kill(int pid, int sig)
54{
55  (void)pid;
56  (void)sig;
57  errno = EINVAL;
58  return -1;
59}
60
61void _exit (int status)
62{
63  _kill(status, -1);
64  while (1) {}    /* Make sure we hang here */
65}
66
67__attribute__((weak)) int _read(int file, char *ptr, int len)
68{
69  (void)file;
70  int DataIdx;
71
72  for (DataIdx = 0; DataIdx < len; DataIdx++)
73  {
74    *ptr++ = __io_getchar();
75  }
76
77  return len;
78}
79
80__attribute__((weak)) int _write(int file, char *ptr, int len)
81{
82  (void)file;
83  int DataIdx;
84
85  for (DataIdx = 0; DataIdx < len; DataIdx++)
86  {
87    __io_putchar(*ptr++);
88  }
89  return len;
90}
91
92int _close(int file)
93{
94  (void)file;
95  return -1;
96}
97
98
99int _fstat(int file, struct stat *st)
100{
101  (void)file;
102  st->st_mode = S_IFCHR;
103  return 0;
104}
105
106int _isatty(int file)
107{
108  (void)file;
109  return 1;
110}
111
112int _lseek(int file, int ptr, int dir)
113{
114  (void)file;
115  (void)ptr;
116  (void)dir;
117  return 0;
118}
119
120int _open(char *path, int flags, ...)
121{
122  (void)path;
123  (void)flags;
124  /* Pretend like we always fail */
125  return -1;
126}
127
128int _wait(int *status)
129{
130  (void)status;
131  errno = ECHILD;
132  return -1;
133}
134
135int _unlink(char *name)
136{
137  (void)name;
138  errno = ENOENT;
139  return -1;
140}
141
142clock_t _times(struct tms *buf)
143{
144  (void)buf;
145  return -1;
146}
147
148int _stat(const char *file, struct stat *st)
149{
150  (void)file;
151  st->st_mode = S_IFCHR;
152  return 0;
153}
154
155int _link(char *old, char *new)
156{
157  (void)old;
158  (void)new;
159  errno = EMLINK;
160  return -1;
161}
162
163int _fork(void)
164{
165  errno = EAGAIN;
166  return -1;
167}
168
169int _execve(char *name, char **argv, char **env)
170{
171  (void)name;
172  (void)argv;
173  (void)env;
174  errno = ENOMEM;
175  return -1;
176}
177
178// --- Picolibc Specific Section ---
179#if defined(__PICOLIBC__)
180
181/**
182 * @brief Picolibc helper function to output a character to a FILE stream.
183 *        This redirects the output to the low-level __io_putchar function.
184 * @param c Character to write.
185 * @param file FILE stream pointer (ignored).
186 * @retval int The character written.
187 */
188static int starm_putc(char c, FILE *file)
189{
190        (void) file;
191  __io_putchar(c);
192        return c;
193}
194
195/**
196 * @brief Picolibc helper function to input a character from a FILE stream.
197 *        This redirects the input from the low-level __io_getchar function.
198 * @param file FILE stream pointer (ignored).
199 * @retval int The character read, cast to an unsigned char then int.
200 */
201static int starm_getc(FILE *file)
202{
203        unsigned char c;
204        (void) file;
205  c = __io_getchar();
206        return c;
207}
208
209// Define and initialize the standard I/O streams for Picolibc.
210// FDEV_SETUP_STREAM connects the starm_putc and starm_getc helper functions to a FILE structure.
211// _FDEV_SETUP_RW indicates the stream is for reading and writing.
212static FILE __stdio = FDEV_SETUP_STREAM(starm_putc,
213                                        starm_getc,
214                                        NULL,
215                                        _FDEV_SETUP_RW);
216
217// Assign the standard stream pointers (stdin, stdout, stderr) to the initialized stream.
218// Picolibc uses these pointers for standard I/O operations (printf, scanf, etc.).
219FILE *const stdin = &__stdio;
220__strong_reference(stdin, stdout);
221__strong_reference(stdin, stderr);
222
223// Create strong aliases mapping standard C library function names (without underscore)
224// to the implemented system call stubs (with underscore). Picolibc uses these
225// standard names internally, so this linking is required.
226__strong_reference(_read, read);
227__strong_reference(_write, write);
228__strong_reference(_times, times);
229__strong_reference(_execve, execve);
230__strong_reference(_fork, fork);
231__strong_reference(_link, link);
232__strong_reference(_unlink, unlink);
233__strong_reference(_stat, stat);
234__strong_reference(_wait, wait);
235__strong_reference(_open, open);
236__strong_reference(_close, close);
237__strong_reference(_lseek, lseek);
238__strong_reference(_isatty, isatty);
239__strong_reference(_fstat, fstat);
240__strong_reference(_exit, exit);
241__strong_reference(_kill, kill);
242__strong_reference(_getpid, getpid);
243
244#endif //__PICOLIBC__
Note: See TracBrowser for help on using the repository browser.