1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-29 08:21:18 +01:00

Merge pull request #10934 from gschorcht/cpu_atmega_common_heap

cpu/atmega_common: make remaining RAM available as heap
This commit is contained in:
Sebastian Meiling 2019-04-15 13:17:57 +02:00 committed by GitHub
commit d08a6132bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -203,6 +203,12 @@ void cpu_switch_context_exit(void)
__enter_thread_mode();
}
#define STACK_POINTER ((char *)AVR_STACK_POINTER_REG)
extern size_t __malloc_margin;
extern char * __malloc_heap_start;
extern char * __malloc_heap_end;
extern char *__brkval;
/**
* @brief Set the MCU into Thread-Mode and load the initial task from the stack and run it
*/
@ -210,6 +216,19 @@ void NORETURN __enter_thread_mode(void) __attribute__((naked));
void NORETURN __enter_thread_mode(void)
{
irq_enable();
/*
* Save the current stack pointer to __malloc_heap_end. Since
* context_restore is always inline, there is no function call and the
* current stack pointer is the lowest possible stack address outside the
* thread-mode. Therefore, it can be considered as the top of the heap.
*/
__malloc_heap_end = STACK_POINTER - __malloc_margin;
/* __brkval has to be initialized if necessary */
if (__brkval == NULL) {
__brkval = __malloc_heap_start;
}
__context_restore();
__asm__ volatile ("ret");