Scheduler Example

CleverOS Boot

Start the CleverOS runtime with two tasks, SysTick, PendSV context switching, LED output, and serial logs.

Board LPCXpresso51U68 EVB OM40005
Status Verified

Run It

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

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

What To Look For

  • rtos_init receives task entry points.
  • SysTick drives scheduler timing.
  • PendSV switches between the two task contexts.
#include <stdint.h>

#include "cos_lpc51u68_bsp.h"
#include "cos_lpc51u68_rtos.h"

static void task_uart(void)
{
    uint32_t count = 0u;

    for (;;) {
        rtos_log_task_state("rtos task0 uart tick ", rtos_tick_ms(), count++);
        rtos_delay_ticks(1000u);
    }
}

static void task_led(void)
{
    uint32_t count = 0u;
    cos_lpc51u68_led_step_t step = COS_LPC51U68_LED_STEP_RED;

    for (;;) {
        rtos_set_led_step(step);
        rtos_log_task_state("rtos task1 led tick ", rtos_tick_ms(), count++);
        step = (cos_lpc51u68_led_step_t)(((uint32_t)step + 1u) & 0x3u);
        rtos_delay_ticks(1000u);
    }
}

int main(void)
{
    cos_lpc51u68_uart0_init_9600_8n1();
    cos_lpc51u68_gpio_leds_init();
    cos_lpc51u68_uart0_puts("\r\nCleverOS first boot on LPC51U68\r\n");

    rtos_init(task_uart, task_led);
    cos_lpc51u68_systick_init_1ms();
    rtos_boot_scheduler();

    for (;;) {
        __asm volatile("wfi");
    }
}