TikuOS: Simple. Ubiquitous. Intelligence, Everywhere.

An open-source operating system for microwatt computers.
Deploy-and-forget embedded systems that run for years on a coin cell or indefinitely on harvested energy.

API Reference / CPU & Watchdog

Module · CPU & Watchdog

CPU & Watchdog

The CPU abstraction layer exposes low-level primitives that don't fit into any of the other modules: the watchdog timer (fault recovery and periodic interrupt mode), blocking delays, and convenience helpers for board LEDs. All of these are implemented against the arch-specific HAL under arch/msp430/.

Headers: kernel/cpu/tiku_watchdog.h, kernel/cpu/tiku_common.h.

Watchdog Timer

Header: kernel/cpu/tiku_watchdog.h

The watchdog has two modes: watchdog mode resets the CPU if it isn't kicked within the configured interval (for fault recovery), while interval mode delivers a periodic interrupt that can be used as a lightweight clock source. Both the clock source (ACLK or SMCLK) and the divider (64, 512, 8192, 32768) are runtime-configurable.

Types

typedef enum {
    TIKU_WDT_MODE_WATCHDOG = 0,        /* Reset on timeout      */
    TIKU_WDT_MODE_INTERVAL = WDTTMSEL  /* Periodic interrupt    */
} tiku_wdt_mode_t;

typedef enum {
    TIKU_WDT_SRC_SMCLK = WDTSSEL__SMCLK,
    TIKU_WDT_SRC_ACLK  = WDTSSEL__ACLK
} tiku_wdt_clk_t;

typedef uint16_t tiku_wdt_interval_t;
/* Valid values: WDTIS__64, WDTIS__512, WDTIS__8192, WDTIS__32768 */

Functions

FunctionDescription
tiku_watchdog_init()Initialize with default settings.
tiku_watchdog_config(mode, clk, interval, start_held, kick_on_start)Configure with custom parameters.
tiku_watchdog_kick()Kick (reset) to prevent a timeout.
tiku_watchdog_pause()Pause the watchdog.
tiku_watchdog_resume()Resume the watchdog.
tiku_watchdog_resume_with_kick()Resume with an immediate kick.
tiku_watchdog_off()Disable entirely.
tiku_watchdog_mode_str()Returns "watchdog" or "interval".
tiku_watchdog_get_mode()Returns the current tiku_wdt_mode_t.
tiku_watchdog_get_clk()Returns the current tiku_wdt_clk_t.
tiku_watchdog_get_interval()Returns the current tiku_wdt_interval_t.

VFS Integration

The watchdog is exposed via the VFS under /sys/watchdog/ so it can be inspected and reconfigured from the shell without recompiling:

PathReadWrite
/sys/watchdog/mode"watchdog" or "interval""watchdog" or "interval"
/sys/watchdog/clock"aclk" or "smclk""aclk" or "smclk"
/sys/watchdog/interval64, 512, 8192, or 32768Same values (divider)
/sys/watchdog/kickNot readable (returns -1)Any write kicks the timer

All watchdog writes call tiku_watchdog_config() internally, preserving unchanged parameters and kicking the timer to avoid an immediate timeout.

Common Utilities

Header: kernel/cpu/tiku_common.h

Small helpers that don't deserve their own module. The LED functions are backward-compatible aliases for the newer indexed tiku_led_* API; use the indexed API for new code.

Functions

FunctionDescription
tiku_common_delay_ms(ms)Blocking delay in milliseconds.
tiku_common_led1_init()Initialize LED1 hardware.
tiku_common_led2_init()Initialize LED2 hardware.
tiku_common_led1_on() / led1_off() / led1_toggle()LED1 control.
tiku_common_led2_on() / led2_off() / led2_toggle()LED2 control.

Indexed LED Interface

Header: interfaces/led/tiku_led.h

Board-independent, index-based LED API. The number of LEDs is set per board via TIKU_BOARD_LED_COUNT; the interface adapts automatically. This is the preferred API for new code — the tiku_common_led* helpers above are thin compatibility wrappers.

Functions

uint8_t tiku_led_count(void);      /* board LED count              */
void    tiku_led_init(uint8_t idx);  /* init LED idx (0-based)      */
void    tiku_led_on(uint8_t idx);
void    tiku_led_off(uint8_t idx);
void    tiku_led_toggle(uint8_t idx);
void    tiku_led_init_all(void);   /* init every board LED at once */

VFS nodes /dev/led0/dev/ledN are created automatically for each board LED and support the same 0/1/t value protocol as the indexed API.