Next Example

Allocator And Leak Demo

Demonstrate allocation accounting and leak reporting hooks for future product firmware.

Board LPCXpresso51U68 EVB OM40005
Status Planned

Run It

Use these commands from the COS workspace when the board and serial adapter are attached.

make -C firmware/lpc51u68_cleveros_alloc_demo clean allmake -C firmware/lpc51u68_cleveros_alloc_demo flashpython3 tools/uart_viewer.py --device <serial-device> --baud 9600

What To Look For

  • Each allocation is tagged by task.
  • The report task prints current and peak use.
  • The demo intentionally leaves one block allocated to prove leak detection.
static void task_allocator_demo(void)
{
    void *buffer = rtos_malloc_tagged(64u, "telemetry");
    rtos_free(buffer);

    (void)rtos_malloc_tagged(16u, "intentional-leak");

    for (;;) {
        rtos_alloc_report_t report = rtos_alloc_report();
        cos_lpc51u68_uart0_puts("alloc current ");
        cos_lpc51u68_uart0_put_hex32(report.current_bytes);
        cos_lpc51u68_uart0_puts(" peak ");
        cos_lpc51u68_uart0_put_hex32(report.peak_bytes);
        cos_lpc51u68_uart0_puts(" leaks ");
        cos_lpc51u68_uart0_put_hex32(report.leak_count);
        cos_lpc51u68_uart0_puts("\r\n");
        rtos_delay_ticks(1000u);
    }
}