stm32_serDes_protobuf_project/app/syscalls.c

205 lines
4.5 KiB
C
Raw Normal View History

2024-04-08 14:21:04 +03:00
/**
*****************************************************************************
**
** File : syscalls.c
**
2024-05-13 15:21:22 +03:00
** Abstract : System Workbench Minimal System calls file
2024-04-08 14:21:04 +03:00
**
** For more information about which c-functions
** need which of these lowlevel functions
** please consult the Newlib libc-manual
**
2024-05-13 15:21:22 +03:00
** Environment : System Workbench for MCU
2024-04-08 14:21:04 +03:00
**
2024-05-13 15:21:22 +03:00
** Distribution: The file is distributed as is without any warranty
2024-04-08 14:21:04 +03:00
** of any kind.
**
2024-05-13 15:21:22 +03:00
*****************************************************************************
**
** <h2><center>&copy; COPYRIGHT(c) 2014 Ac6</center></h2>
**
** Redistribution and use in source and binary forms, with or without modification,
** are permitted provided that the following conditions are met:
** 1. Redistributions of source code must retain the above copyright notice,
** this list of conditions and the following disclaimer.
** 2. Redistributions in binary form must reproduce the above copyright notice,
** this list of conditions and the following disclaimer in the documentation
** and/or other materials provided with the distribution.
** 3. Neither the name of Ac6 nor the names of its contributors
** may be used to endorse or promote products derived from this software
** without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2024-04-08 14:21:04 +03:00
**
*****************************************************************************
*/
/* Includes */
#include <sys/stat.h>
#include <stdlib.h>
#include <errno.h>
#include <stdio.h>
#include <signal.h>
#include <time.h>
#include <sys/time.h>
#include <sys/times.h>
2024-04-30 13:10:11 +03:00
#include "../bsp/bsp.h"
2024-04-08 14:21:04 +03:00
/* Variables */
2024-05-13 15:21:22 +03:00
//#undef errno
2024-04-08 14:21:04 +03:00
extern int errno;
extern int __io_putchar(int ch) __attribute__((weak));
extern int __io_getchar(void) __attribute__((weak));
register char * stack_ptr asm("sp");
char *__env[1] = { 0 };
char **environ = __env;
/* Functions */
void initialise_monitor_handles()
{
}
int _getpid(void)
{
return 1;
}
2024-05-13 15:21:22 +03:00
int _kill(int pid, int sig)
2024-04-08 14:21:04 +03:00
{
2024-05-13 15:21:22 +03:00
errno = EINVAL;
2024-04-08 14:21:04 +03:00
return -1;
}
void _exit (int status)
{
_kill(status, -1);
while (1) {} /* Make sure we hang here */
}
2024-05-13 15:21:22 +03:00
int _read (int file, char *ptr, int len)
2024-04-08 14:21:04 +03:00
{
int DataIdx;
for (DataIdx = 0; DataIdx < len; DataIdx++)
{
2024-05-13 15:21:22 +03:00
*ptr++ = __io_getchar();
2024-04-08 14:21:04 +03:00
}
2024-05-13 15:21:22 +03:00
return len;
2024-04-08 14:21:04 +03:00
}
2024-05-13 15:21:22 +03:00
int _write(int file, char *ptr, int len)
2024-04-08 14:21:04 +03:00
{
int i= 0;
while(i < len) {
while (USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);
USART_SendData(USART2, *ptr++);
2024-05-13 15:02:23 +03:00
i++;
2024-04-08 14:21:04 +03:00
}
return len;
}
caddr_t _sbrk(int incr)
{
extern char end asm("end");
static char *heap_end;
char *prev_heap_end;
if (heap_end == 0)
heap_end = &end;
prev_heap_end = heap_end;
if (heap_end + incr > stack_ptr)
{
// write(1, "Heap and stack collision\n", 25);
// abort();
2024-05-13 15:21:22 +03:00
errno = ENOMEM;
2024-04-08 14:21:04 +03:00
return (caddr_t) -1;
}
heap_end += incr;
return (caddr_t) prev_heap_end;
}
2024-05-13 15:21:22 +03:00
int _close(int file)
2024-04-08 14:21:04 +03:00
{
return -1;
}
2024-05-13 15:21:22 +03:00
int _fstat(int file, struct stat *st)
2024-04-08 14:21:04 +03:00
{
st->st_mode = S_IFCHR;
return 0;
}
2024-05-13 15:21:22 +03:00
int _isatty(int file)
2024-04-08 14:21:04 +03:00
{
return 1;
}
2024-05-13 15:21:22 +03:00
int _lseek(int file, int ptr, int dir)
2024-04-08 14:21:04 +03:00
{
return 0;
}
2024-05-13 15:21:22 +03:00
int _open(char *path, int flags, ...)
2024-04-08 14:21:04 +03:00
{
/* Pretend like we always fail */
return -1;
}
2024-05-13 15:21:22 +03:00
int _wait(int *status)
2024-04-08 14:21:04 +03:00
{
2024-05-13 15:21:22 +03:00
errno = ECHILD;
2024-04-08 14:21:04 +03:00
return -1;
}
2024-05-13 15:21:22 +03:00
int _unlink(char *name)
2024-04-08 14:21:04 +03:00
{
2024-05-13 15:21:22 +03:00
errno = ENOENT;
2024-04-08 14:21:04 +03:00
return -1;
}
2024-05-13 15:21:22 +03:00
int _times(struct tms *buf)
2024-04-08 14:21:04 +03:00
{
return -1;
}
2024-05-13 15:21:22 +03:00
int _stat(char *file, struct stat *st)
2024-04-08 14:21:04 +03:00
{
st->st_mode = S_IFCHR;
return 0;
}
2024-05-13 15:21:22 +03:00
int _link(char *old, char *new)
2024-04-08 14:21:04 +03:00
{
2024-05-13 15:21:22 +03:00
errno = EMLINK;
2024-04-08 14:21:04 +03:00
return -1;
}
int _fork(void)
{
2024-05-13 15:21:22 +03:00
errno = EAGAIN;
2024-04-08 14:21:04 +03:00
return -1;
}
2024-05-13 15:21:22 +03:00
int _execve(char *name, char **argv, char **env)
2024-04-08 14:21:04 +03:00
{
2024-05-13 15:21:22 +03:00
errno = ENOMEM;
2024-04-08 14:21:04 +03:00
return -1;
}