generated from Embedded_Projects/NUC200_Template
81 lines
1.5 KiB
C
81 lines
1.5 KiB
C
#include <stdio.h>
|
|
#include <stdint.h>
|
|
#include <sys/stat.h>
|
|
|
|
#include "NUC200Series.h"
|
|
|
|
#include "FreeRTOS.h"
|
|
#include "task.h"
|
|
|
|
#define NEWLIB_HEAP_SIZE 0x400
|
|
|
|
/* Static heap for newlib. */
|
|
static uint8_t __attribute__((section(".heap"))) __attribute__((aligned(4))) s_heap[NEWLIB_HEAP_SIZE];
|
|
|
|
size_t s_heap_sz = 0;
|
|
|
|
int _getpid(void) {
|
|
return 0;
|
|
}
|
|
|
|
int _kill(int i, int j) {
|
|
return 0;
|
|
}
|
|
|
|
int _read(int fd, char *buf, int nbytes) {
|
|
return 0;
|
|
}
|
|
|
|
int _write(int fd, const void *buf, int nbytes) {
|
|
for(int i = 0; i < nbytes; i++) {
|
|
while(UART0->FSR & UART_FSR_TX_FULL_Msk) {
|
|
/* Wait for TX fifo available */
|
|
}
|
|
/* Write FIFO */
|
|
UART0->THR = ((uint8_t *)buf)[i];
|
|
i++;
|
|
}
|
|
|
|
return nbytes;
|
|
}
|
|
|
|
int _close(int file) {
|
|
return -1;
|
|
}
|
|
|
|
int _isatty(int file) {
|
|
return file <= 2;
|
|
}
|
|
|
|
int _fstat(int file, struct stat *st) {
|
|
st->st_mode = S_IFCHR;
|
|
return 0;
|
|
}
|
|
|
|
int _lseek(int file, int ptr, int dir){
|
|
return 0;
|
|
}
|
|
|
|
void *_sbrk(intptr_t count) {
|
|
void *ret, *ptr;
|
|
|
|
/* Note: current implementation does NOT support calling malloc from ISRs. */
|
|
if(xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) {
|
|
taskENTER_CRITICAL(); /* Freeze! */
|
|
}
|
|
|
|
ptr = s_heap + s_heap_sz;
|
|
if(s_heap_sz + count < NEWLIB_HEAP_SIZE) {
|
|
s_heap_sz += count;
|
|
ret = ptr;
|
|
}
|
|
else {
|
|
ret = (void *)-1;
|
|
}
|
|
|
|
if(xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) {
|
|
taskEXIT_CRITICAL();
|
|
}
|
|
|
|
return ret;
|
|
} |