Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// Error holder
- extern int errno;
- /// End of heap
- char *heap_end = 0;
- caddr_t _sbrk(unsigned int incr)
- {
- /// Start of heap
- extern char _heap_bottom;
- /// Start of stack (also end of heap)
- extern char _stack_bottom;
- /// Temporal heap pointer
- char *prev_heap_end;
- tBoolean intStat;
- /// Disable interrupts to avoid heap corruption if _sbrk() is called from
- /// inside an interrupt.
- intStat = MAP_IntMasterDisable();
- /// Heap initialization
- if (heap_end == 0) heap_end = &_heap_bottom;
- /// Store current heap pointer
- prev_heap_end = heap_end;
- if ((heap_end + incr) > &_stack_bottom)
- {
- /// Error: Not enough heap space available
- errno = ENOMEM;
- /// Enable interrupts if they were already enabled when entering
- if (intStat == false) MAP_IntMasterEnable();
- /// \todo Should we return -1?
- return (caddr_t)0;
- }
- /// Allocate requested heap
- heap_end += incr;
- /// Enable interrupts if they were already enabled when entering
- if (intStat == false) MAP_IntMasterEnable();
- /// Return pointer to allocated data
- return (caddr_t)prev_heap_end;
- }
- int _write(int file, char *ptr, unsigned int len)
- {
- unsigned int i;
- for(i = 0; i < len; i++) MAP_UARTCharPut(UART0_BASE, ptr[i]);
- return i;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement