/* Allocate memory from the heap. 
The current heap implementation is very rudimentary, it is only able to allocate memory. But it does not */
void* _sbrk_r(struct _reent *r, ptrdiff_t incr)
/* Allocate memory from the heap. 
The current heap implementation is very rudimentary, it is only able to allocate memory. But it does not */
void* _sbrk_r(struct _reent *r, ptrdiff_t incr)
{
    unsigned int state = disableIRQ();
    void *res = heap_top;
    if ((heap_top + incr > &_eheap) || (heap_top + incr < &_sheap)) {
        r->_errno = ENOMEM;
        res = (void *)-1;
    }
    else {
        heap_top += incr;
    }
    restoreIRQ(state);
    return res;
}