2021-07-12 21:50:48 +02:00
|
|
|
/*!
|
|
|
|
* @file syscalls.c
|
|
|
|
* Implements some base-level for libc for heap management and printing on
|
|
|
|
* the debug port.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <errno.h>
|
2022-05-22 15:30:38 +02:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2021-07-12 21:50:48 +02:00
|
|
|
#include <string.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
2022-05-22 15:30:38 +02:00
|
|
|
#include <unistd.h>
|
2021-07-12 21:50:48 +02:00
|
|
|
|
|
|
|
#include <boardconfig.h>
|
2022-05-22 15:30:38 +02:00
|
|
|
#include <hardware_init.h>
|
2021-07-12 21:50:48 +02:00
|
|
|
|
2022-05-22 15:30:38 +02:00
|
|
|
#define AUTO_RETURN_AFTER_NEWLINE 1
|
2021-07-12 21:50:48 +02:00
|
|
|
|
|
|
|
// _write currently adds \n after \r automatically.
|
|
|
|
// If the At91lib\utility\stdio.c printf implementation is not used anymore:
|
|
|
|
// remove if there are spurious newlines!
|
|
|
|
|
2022-05-22 15:30:38 +02:00
|
|
|
// int _read(int file, void *ptr, size_t len) {
|
2021-07-12 21:50:48 +02:00
|
|
|
// (void)len;
|
|
|
|
// if(file <= STDERR_FILENO) {
|
|
|
|
// *(char *) ptr = DBGU_GetChar();
|
|
|
|
//#if AUTO_RETURN_AFTER_NEWLINE
|
|
|
|
// if((*(char *) ptr != '\n') && (*(char *) ptr != '\r')) {
|
|
|
|
// DBGU_PutChar(*(char *) ptr);
|
|
|
|
// }
|
|
|
|
// else if(*(char *) ptr == '\r') {
|
|
|
|
// DBGU_PutChar('\n');
|
|
|
|
// DBGU_PutChar('\r');
|
|
|
|
// }
|
|
|
|
//#endif
|
|
|
|
// return 1;
|
|
|
|
// }
|
|
|
|
// else {
|
|
|
|
// return -1;
|
|
|
|
// }
|
|
|
|
//
|
2022-05-22 15:30:38 +02:00
|
|
|
// }
|
2021-07-12 21:50:48 +02:00
|
|
|
|
|
|
|
int _write(int file, const void *ptr, size_t len) {
|
2022-05-22 15:30:38 +02:00
|
|
|
size_t i;
|
2021-07-12 21:50:48 +02:00
|
|
|
|
2022-05-22 15:30:38 +02:00
|
|
|
if (file <= STDERR_FILENO) {
|
|
|
|
for (i = 0; i < len; i++) {
|
2021-07-12 21:50:48 +02:00
|
|
|
#if AUTO_RETURN_AFTER_NEWLINE
|
2022-05-22 15:30:38 +02:00
|
|
|
if (((const char *)ptr)[i] == '\n' &&
|
|
|
|
((const char *)ptr)[i + 1] != '\r') {
|
|
|
|
HAL_UART_Transmit(&huart3, (uint8_t *)"\r", 1, DEBUG_UART_MS_TIMEOUT);
|
|
|
|
}
|
2021-07-12 21:50:48 +02:00
|
|
|
#endif
|
2022-05-22 15:30:38 +02:00
|
|
|
uint8_t *character = (uint8_t *)ptr;
|
|
|
|
HAL_UART_Transmit(&huart3, (uint8_t *)(character + i), 1,
|
|
|
|
DEBUG_UART_MS_TIMEOUT);
|
|
|
|
}
|
|
|
|
return len;
|
|
|
|
} else {
|
|
|
|
return -1;
|
|
|
|
}
|
2021-07-12 21:50:48 +02:00
|
|
|
}
|
|
|
|
|
2022-05-22 15:30:38 +02:00
|
|
|
int _lseek(int file, int ptr, int dir) {
|
|
|
|
(void)file;
|
|
|
|
(void)ptr;
|
|
|
|
(void)dir;
|
|
|
|
return 0;
|
2021-07-12 21:50:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int _close(int file) {
|
2022-05-22 15:30:38 +02:00
|
|
|
(void)file;
|
|
|
|
return -1;
|
2021-07-12 21:50:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int _open(const char *name, int flags, ...) {
|
2022-05-22 15:30:38 +02:00
|
|
|
(void)name;
|
|
|
|
(void)flags;
|
|
|
|
return -1;
|
2021-07-12 21:50:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int _link(const char *oldpath, const char *newpath) {
|
2022-05-22 15:30:38 +02:00
|
|
|
(void)oldpath;
|
|
|
|
(void)newpath;
|
|
|
|
return -1;
|
2021-07-12 21:50:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int _rename(const char *oldpath, const char *newpath) {
|
2022-05-22 15:30:38 +02:00
|
|
|
(void)oldpath;
|
|
|
|
(void)newpath;
|
|
|
|
return -1;
|
2021-07-12 21:50:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int _unlink(const char *pathname) {
|
2022-05-22 15:30:38 +02:00
|
|
|
(void)pathname;
|
|
|
|
return -1;
|
2021-07-12 21:50:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int fsync(int fd) {
|
2022-05-22 15:30:38 +02:00
|
|
|
(void)fd;
|
|
|
|
return -1;
|
2021-07-12 21:50:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int _fstat(int fd, struct stat *st) {
|
2022-05-22 15:30:38 +02:00
|
|
|
(void)fd;
|
|
|
|
(void)st;
|
|
|
|
return -1;
|
2021-07-12 21:50:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int _stat(const char *path, struct stat *st) {
|
2022-05-22 15:30:38 +02:00
|
|
|
(void)path;
|
|
|
|
(void)st;
|
|
|
|
return -1;
|
2021-07-12 21:50:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int _isatty(int fd) {
|
2022-05-22 15:30:38 +02:00
|
|
|
if (fd <= STDERR_FILENO) {
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
2021-07-12 21:50:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void exit(int n) {
|
2022-05-22 15:30:38 +02:00
|
|
|
printf("\n\r EXITING WITH CODE: %u \n\r", n);
|
|
|
|
// restart();
|
|
|
|
while (1)
|
|
|
|
;
|
2021-07-12 21:50:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void _exit(int n) {
|
2022-05-22 15:30:38 +02:00
|
|
|
printf("\n\r EXITING WITH CODE: %u \n\r", n);
|
|
|
|
// restart();
|
|
|
|
while (1)
|
|
|
|
;
|
2021-07-12 21:50:48 +02:00
|
|
|
}
|
|
|
|
|
2022-05-22 15:30:38 +02:00
|
|
|
int _kill() { return -1; }
|
2021-07-12 21:50:48 +02:00
|
|
|
|
2022-05-22 15:30:38 +02:00
|
|
|
int _getpid() { return 1; }
|
2021-07-12 21:50:48 +02:00
|
|
|
|
2022-05-22 15:30:38 +02:00
|
|
|
int _gettimeofday() { return -1; }
|