jacking/nl-glue.c

73 lines
1.6 KiB
C

/* glue code for Newlib */
#include <bsp/uart.h>
#include <sys/types.h>
#include <sys/stat.h>
/* Newlib's assert() calls this function if the assertion fails */
void __assert_func (const char *file, int line, const char *func, const char *failedexpr)
{
if (file != NULL) {
char linestrbuf[16], *linestr = &linestrbuf[sizeof(linestrbuf)];
Fx3UartTxString(file);
Fx3UartTxChar(':');
/* Avoid using newlib functions like itoa so as not to trigger
a recursive assert... */
*--linestr = '\0';
while (line >= 10 && linestr != &linestrbuf[1]) {
*--linestr = '0' + (line % 10);
line /= 10;
}
*--linestr = '0' + line;
Fx3UartTxString(linestr);
Fx3UartTxString(": ");
}
if (func != NULL) {
Fx3UartTxString(func);
Fx3UartTxString(": ");
}
Fx3UartTxString("Assertion ");
if (failedexpr != NULL) {
Fx3UartTxChar('`');
Fx3UartTxString(failedexpr);
Fx3UartTxString("' ");
}
Fx3UartTxString("failed.\n");
Fx3UartTxFlush();
for(;;) ;
}
int _write(int fd, char* data, int size) {
if (fd >= 0 && fd < 3) {
if (size > 0)
Fx3UartTxBytes((const uint8_t*)data, (size_t)size);
Fx3UartTxFlush();
return size;
}
return -1;
}
int _close(int fd) { (void)fd; return 0; }
int _stat(char *file, struct stat *st) {
(void)file;
st->st_mode = S_IFCHR;
return 0;
}
int _read(int fd, char *ptr, int len) { (void)fd; (void)ptr; (void)len; return 0; }
int _lseek(int fd, int ptr, int dir) { (void)fd; (void)ptr; (void)dir; return 0; }
int _isatty(int fd) { (void)fd; return 1; }
int _fstat(int fd, struct stat *st) {
(void)fd;
st->st_mode = S_IFCHR;
return 0;
}