HVAC_BOOT_M7/APP/syscalls.c

76 lines
1.8 KiB
C

#if (defined(__ICCARM__))
#elif defined(__ARMCC_VERSION)
#elif defined __GNUC__
#include "sys/types.h"
#include "sys/stat.h"
#endif
static uint32_t s_u32Current_heap_end;
#if (defined(__ICCARM__))
extern uint32_t __HeapBegin[1]; // Defined by the linker.
extern uint32_t __HeapLimit[1]; // Defined by the linker.
#elif defined __GNUC__
extern uint32_t __HeapBegin[1]; // Defined by the linker.
extern uint32_t __HeapLimit[1]; // Defined by the linker.
#endif
#if (defined(__ICCARM__))
/**
* TODO: something can be done to make sure the start address used in heap is defined heap start
*/
#elif defined(__ARMCC_VERSION)
#elif defined __GNUC__
extern caddr_t _sbrk(int incr);
/**
* \brief Replacement of C library of _sbrk
*/
caddr_t _sbrk(int incr)
{
if (s_u32Current_heap_end == 0U)
{
#if (defined(__ICCARM__))
s_u32Current_heap_end = (uint32_t)__HeapBegin;
#elif defined __GNUC__
s_u32Current_heap_end = (uint32_t)__HeapBegin;
#endif
}
// Need to align heap to word boundary, else will get
// hard faults on Cortex-M0. So we assume that heap starts on
// word boundary, hence make sure we always add a multiple of
// 4 to it.
incr = (incr + 3) & (~3); // align value to 4
#if (defined(__ICCARM__))
if ( (s_u32Current_heap_end + incr) > (uint32_t)__HeapLimit )
#elif defined __GNUC__
if ( (s_u32Current_heap_end + incr) > (uint32_t)__HeapLimit )
#endif
{
// Some of the libstdc++-v3 tests rely upon detecting
// out of memory errors, so do not abort here.
#if 0
extern void abort(void);
_write(1, "_sbrk: Heap and stack collision\n", 32);
abort();
#else
return (caddr_t) - 1;
#endif
}
else
{
s_u32Current_heap_end+= incr;
}
return (caddr_t) s_u32Current_heap_end;
}
#endif