mirror of
https://github.com/stnolting/neorv32.git
synced 2025-04-23 21:57:33 -04:00
[demo_newlib] add heap size check
This commit is contained in:
parent
5a759c1580
commit
4897ca2b3c
1 changed files with 17 additions and 5 deletions
|
@ -52,6 +52,12 @@
|
|||
/**@}*/
|
||||
|
||||
|
||||
/**********************************************************************//**
|
||||
* @name Max heap size (from linker script)
|
||||
**************************************************************************/
|
||||
extern const unsigned __crt0_max_heap;
|
||||
|
||||
|
||||
/**********************************************************************//**
|
||||
* Main function: Check some of newlib's core functions.
|
||||
*
|
||||
|
@ -78,6 +84,15 @@ int main() {
|
|||
// say hello
|
||||
neorv32_uart0_printf("<<< Newlib demo/test program >>>\n\n");
|
||||
|
||||
// heap size definition
|
||||
volatile uint32_t max_heap = (uint32_t)&__crt0_max_heap;
|
||||
if (max_heap > 0){
|
||||
neorv32_uart0_printf("MAX heap size: %u bytes\n", max_heap);
|
||||
}
|
||||
else {
|
||||
neorv32_uart0_printf("ERROR! No heap size defined (linker script -> '__heap_size')!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// check if newlib is really available
|
||||
#ifndef __NEWLIB__
|
||||
|
@ -90,14 +105,12 @@ int main() {
|
|||
neorv32_uart0_printf("<rand> test... ");
|
||||
srand(neorv32_cpu_csr_read(CSR_CYCLE)); // set random seed
|
||||
neorv32_uart0_printf("%i, %i, %i, %i ", rand() % 100, rand() % 100, rand() % 100, rand() % 100);
|
||||
neorv32_uart0_printf("ok\n");
|
||||
|
||||
|
||||
char *char_buffer; // pointer for dynamic memory allocation
|
||||
|
||||
neorv32_uart0_printf("<malloc> test... ");
|
||||
neorv32_uart0_printf("<malloc> test...\n");
|
||||
char_buffer = (char *) malloc(4 * sizeof(char)); // 4 bytes
|
||||
neorv32_uart0_printf("ok\n");
|
||||
|
||||
// do not test read & write in simulation as there would be no UART RX input
|
||||
if (NEORV32_SYSINFO.SOC & (1<<SYSINFO_SOC_IS_SIM)) {
|
||||
|
@ -117,9 +130,8 @@ int main() {
|
|||
neorv32_uart0_printf("\nok\n");
|
||||
}
|
||||
|
||||
neorv32_uart0_printf("<free> test... ");
|
||||
neorv32_uart0_printf("<free> test...\n");
|
||||
free(char_buffer);
|
||||
neorv32_uart0_printf("ok\n");
|
||||
|
||||
|
||||
// NOTE: exit is highly oversized as it also includes clean-up functions (destructors), which
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue