[riot-notifications] [RIOT-OS/RIOT] cpu/atmega_common: make remaining RAM available as heap (#10934)

Gunar Schorcht notifications at github.com
Sun Feb 3 18:27:58 CET 2019


### Contribution description

This PR make the remaining RAM of AVR MCUs available as heap for `malloc/free` functions of `avr-libc`.

`__malloc_heap_end` is set to 0 by default. Therefore, `malloc` checks `__brkval` against the SP instead of `__malloc_heap_end`.
```c
	cp = __malloc_heap_end;
	if (cp == 0)
		cp = STACK_POINTER() - __malloc_margin;
	if (cp <= __brkval)
```
In thread mode, however, the SP is is always in `.data` section below `__bss_end` and thus below `__malloc_heap_start`. Since `__brkval` points at least to `__malloc_heap_start`, the check always fails.

This PR sets `__malloc_heap_end` to the current SP before switching to thread mode. Thus, `malloc` checks `__brkval` against `__malloc_heap_end`.

### Testing procedure

Use `tests/malloc` to check `malloc/free` functions of `avr-libc`, for example:
```
make -C tests/malloc BOARD=arduino-mega2560 PORT=/dev/ttyUSB0 flash
```

You can view, comment on, or merge this pull request online at:

  https://github.com/RIOT-OS/RIOT/pull/10934

-- Commit Summary --

  * cpu/atmega_common: make RAM available as heap

-- File Changes --

    M cpu/atmega_common/thread_arch.c (17)

-- Patch Links --

https://github.com/RIOT-OS/RIOT/pull/10934.patch
https://github.com/RIOT-OS/RIOT/pull/10934.diff

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/pull/10934
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20190203/838d6456/attachment.html>


More information about the notifications mailing list