99 lines
2.1 KiB
C
99 lines
2.1 KiB
C
|
|
/* glue code for Newlib */
|
|
|
|
#include <sys/types.h>
|
|
#include <sys/stat.h>
|
|
|
|
void uart_putc(char c);
|
|
void uart_puts(const char* s);
|
|
void uart_putdata(const uint8_t* p, size_t size);
|
|
|
|
/* 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)];
|
|
uart_puts(file);
|
|
uart_putc(':');
|
|
/* 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;
|
|
uart_puts(linestr);
|
|
uart_puts(": ");
|
|
}
|
|
if (func != NULL) {
|
|
uart_puts(func);
|
|
uart_puts(": ");
|
|
}
|
|
uart_puts("Assertion ");
|
|
if (failedexpr != NULL) {
|
|
uart_putc('`');
|
|
uart_puts(failedexpr);
|
|
uart_puts("' ");
|
|
}
|
|
uart_puts("failed.\n");
|
|
//Fx3UartTxFlush();
|
|
for(;;) ;
|
|
}
|
|
|
|
int _write(int fd, char* data, int size) {
|
|
if (fd >= 0 && fd < 3) {
|
|
if (size > 0)
|
|
uart_putdata((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;
|
|
}
|
|
|
|
#define HEAPSIZE (256*1024*1024)
|
|
extern uint8_t _heap[];
|
|
|
|
caddr_t _sbrk_r(int incr) {
|
|
static uint8_t* heap_end = 0;
|
|
uint8_t* prev_heap_end;
|
|
|
|
/* initialize */
|
|
if (heap_end == 0)
|
|
heap_end = _heap;
|
|
|
|
prev_heap_end = heap_end;
|
|
|
|
if (heap_end + incr - _heap > HEAPSIZE) {
|
|
/* heap overflow - announce on stderr */
|
|
_write (2, "Heap overflow!\r\n", 16);
|
|
for (;;) asm volatile("nop");
|
|
}
|
|
|
|
heap_end += incr;
|
|
|
|
return (caddr_t)prev_heap_end;
|
|
}
|
|
|