#include "resets.h" #include "gpio.h" #include "uart.h" #include "timer.h" #include "stdio.h" #include "stdlib.h" #include "mem.h" int memheap_test(void) { char *ptr = NULL; for (int i = 1;; i++) { ptr = malloc(i * 128); printf("remain %lu byte\r\n", kfree_size()); if (ptr != NULL) { memcpy(ptr, "hello123456789123456789123456789", 33); printf("ptr :%s\r\n", ptr); printf("get memory :%d byte\r\n", i * 128); free(ptr); printf("free memory :%d byte\r\n", i * 128); ptr = NULL; timer_delay_ms(100); } else { printf("try to get %d byte memory failed!\r\n", i * 128); return -1; } } return 0; } int main(void) { reset_unreset_blocks_wait(RESETS_BLOCK_IO_BANK0 | RESETS_BLOCK_UART0 | RESETS_BLOCK_TIMER); gpio_init(0, GPIO_FUNC_UART | GPIO_PULL_UP | GPIO_DRIVE_4MA); /* UART_TX pin */ gpio_init(1, GPIO_FUNC_UART | GPIO_PULL_UP | GPIO_SCHMITT | GPIO_PAD_IE | GPIO_PAD_OD); /* UART_RX pin */ uart_init(uart0_hw, 6 * 1000 * 1000, UART_DATABITS_8 | UART_PARITY_NONE | UART_STOPBITS_1); printf("memory heap example\r\n"); kmem_init((void *)0x20030000, 64 * 1024); if (memheap_test() == -1) { printf("memheap test fail\r\n"); while (1) { } } printf("memheap test success\r\n"); return 0; }