bedrock[RTOS]

A nanokernel real-time operating system written in C11. Static allocation, alarm-driven time, and a hardware abstraction layer that keeps platform code out of the kernel.

git clone --recursive https://github.com/bedrockRTOS/bedrock-core.git
cd bedrock-core
chorus && chorus run

Static allocation

The kernel does not call malloc. Task control blocks are a fixed array. Stacks, queue buffers and IPC objects come from the caller.

Alarm-driven time

The kernel keeps one sorted sleep list and asks the HAL for a one-shot alarm at the earliest wake time. Time is a 64-bit microsecond counter.

Isolated hardware code

The kernel reaches hardware only through br_hal.h. Ports live in arch/ and boards/. A new port does not change kernel sources.

Kernel

Scheduler
Preemptive, fixed priority. 8 levels by default, 0 is the highest. Round-robin within a level.
Synchronization
Counting semaphores, mutexes with priority inheritance, fixed-size message queues. Priority-ordered wait queues and timeouts on every blocking call.
Tasks
Create, suspend, resume, yield. Delete is available as an experimental API.
Diagnostics
Stack canary checked on every context switch. br_assert and BR_PANIC with a user panic handler.
Memory
Optional fixed-block pool allocator in lib/.
Configuration
Kconfig with defconfig and menuconfig, or plain -D flags.
Targets
ARM Cortex-M3 on QEMU lm3s6965evb. x86-64 Linux host port for tests.
Language
C11, built with -Wall -Wextra -Werror.

Example

Two tasks at different priorities. Shortened from examples/main.c.

#include "bedrock/bedrock.h"

extern void br_uart_puts(const char *s);

static uint8_t stack_a[1024];
static uint8_t stack_b[1024];

static void task_a(void *arg)
{
    (void)arg;
    while (1) {
        br_uart_puts("[A] tick\n");
        br_sleep_ms(500);
    }
}

static void task_b(void *arg)
{
    (void)arg;
    while (1) {
        br_uart_puts("[B] tock\n");
        br_sleep_ms(1000);
    }
}

int main(void)
{
    br_kernel_init();

    br_task_create(NULL, "task_a", task_a, NULL, 1,
                   stack_a, sizeof(stack_a));
    br_task_create(NULL, "task_b", task_b, NULL, 2,
                   stack_b, sizeof(stack_b));

    br_kernel_start();
}

Projects