EoS Developer Documentation v0.1.0
Complete API reference for the EoS multi-platform operating system. EoS scales from bare-metal microcontrollers to full desktop, TV, and any device — with the same unified API. ebuild auto-resolves all platform-specific dependencies (toolchains, runtimes, packages) based on the target profile.
Headers: #include <eos/*.h> | License: MIT | Standards: ISO/IEC 25000
Embedded: MCU/SoC targets (Cortex-M, RISC-V, Xtensa) — bare-metal RTOS, minimal footprint.
Desktop: x86_64/ARM64 PCs — full GUI, Python 3.10+, OpenGL 3.3+, runs EoStudio and eApps.
TV: Smart TV (ARM/x86) — 4K UI, media apps, remote control input.
Tablet/Laptop: ARM64/x86_64 — touch UI, battery management, productivity apps.
Kiosk: x86/ARM — single-app mode, touchscreen, digital signage.
ebuild handles all dependencies for each profile automatically.
⚙ Hardware Abstraction Layer
Platform-independent peripheral API. Header: <eos/hal.h>
HAL Initialization
int eos_hal_init(void)Initialize the HAL subsystem for the current platform. Must be called before any other HAL function.
Returns
0 on success, negative error code on failure.
Example
int ret = eos_hal_init();
if (ret != 0) { printf("HAL init failed: %d\n", ret); return ret; }void eos_hal_deinit(void)Deinitialize the HAL subsystem, releasing all resources.
void eos_delay_ms(uint32_t ms)Blocking delay for ms milliseconds. For RTOS tasks use eos_task_delay_ms() instead.
Parameters
| ms | uint32_t | Milliseconds to delay. |
Example
eos_gpio_write(13, true);
eos_delay_ms(500);
eos_gpio_write(13, false);uint32_t eos_get_tick_ms(void)Get system tick count in milliseconds since eos_hal_init(). Wraps at UINT32_MAX (~49.7 days).
Returns
Current tick count in milliseconds.
Example
uint32_t start = eos_get_tick_ms();
do_work();
printf("Elapsed: %u ms\n", eos_get_tick_ms() - start);GPIO
eos_gpio_config_t
pin | uint16_t | GPIO pin number |
mode | eos_gpio_mode_t | INPUT, OUTPUT, AF, ANALOG |
pull | eos_gpio_pull_t | PULL_NONE, PULL_UP, PULL_DOWN |
speed | eos_gpio_speed_t | SPEED_LOW, MEDIUM, HIGH, VHIGH |
af_num | uint8_t | Alternate function number |
int eos_gpio_init(const eos_gpio_config_t *cfg)Initialize a GPIO pin. Must be called before read/write/toggle on the pin.
Parameters
| cfg | const eos_gpio_config_t * | Pin configuration struct. |
Returns
0 on success, negative error code on failure.
Example
eos_gpio_config_t led = {
.pin = 13, .mode = EOS_GPIO_OUTPUT,
.pull = EOS_GPIO_PULL_NONE, .speed = EOS_GPIO_SPEED_LOW
};
eos_gpio_init(&led);void eos_gpio_deinit(uint16_t pin)Release a GPIO pin, resetting it to default state.
Parameters
| pin | uint16_t | Pin number to release. |
void eos_gpio_write(uint16_t pin, bool value)Set GPIO output pin high or low.
Parameters
| pin | uint16_t | Pin number. |
| value | bool | true=high, false=low. |
Example
eos_gpio_write(13, true); // LED on
eos_delay_ms(1000);
eos_gpio_write(13, false); // LED offbool eos_gpio_read(uint16_t pin)Read current state of a GPIO pin. Works for input and output pins.
Parameters
| pin | uint16_t | Pin number. |
Returns
true if high, false if low.
Example
eos_gpio_config_t btn = { .pin=2, .mode=EOS_GPIO_INPUT, .pull=EOS_GPIO_PULL_UP };
eos_gpio_init(&btn);
if (!eos_gpio_read(2)) printf("Button pressed!\n");void eos_gpio_toggle(uint16_t pin)Toggle a GPIO output pin (high→low or low→high).
Parameters
| pin | uint16_t | Pin number. |
Example
while (1) { eos_gpio_toggle(13); eos_delay_ms(500); } // 1 Hz blinkint eos_gpio_set_irq(uint16_t pin, eos_gpio_edge_t edge, eos_gpio_callback_t cb, void *ctx)Attach interrupt callback to a GPIO pin on specified edge(s).
Parameters
| pin | uint16_t | Pin number. |
| edge | eos_gpio_edge_t | EDGE_RISING, FALLING, BOTH, or NONE. |
| cb | eos_gpio_callback_t | void (*)(uint16_t pin, void *ctx) |
| ctx | void * | User context passed to callback. |
Returns
0 on success, negative error code.
Example
void on_btn(uint16_t pin, void *ctx) { *(int*)ctx += 1; }
int count = 0;
eos_gpio_set_irq(2, EOS_GPIO_EDGE_FALLING, on_btn, &count);UART
eos_uart_config_t
port | uint8_t | UART port number |
baudrate | uint32_t | Baud rate (9600, 115200, etc.) |
data_bits | uint8_t | Data bits (7 or 8) |
parity | eos_uart_parity_t | NONE, EVEN, ODD |
stop_bits | eos_uart_stop_t | STOP_1, STOP_2 |
int eos_uart_init(const eos_uart_config_t *cfg)Initialize a UART port with baud rate, parity, and stop bits.
Parameters
| cfg | const eos_uart_config_t * | UART configuration. |
Returns
0 on success, negative error code.
Example
eos_uart_config_t uart = { .port=0, .baudrate=115200, .data_bits=8,
.parity=EOS_UART_PARITY_NONE, .stop_bits=EOS_UART_STOP_1 };
eos_uart_init(&uart);int eos_uart_write(uint8_t port, const uint8_t *data, size_t len)Write data to UART. Blocks until all bytes transmitted.
Parameters
| port | uint8_t | UART port. |
| data | const uint8_t * | Data buffer. |
| len | size_t | Bytes to write. |
Returns
Bytes written, or negative error code.
Example
const char *msg = "Hello UART\r\n";
eos_uart_write(0, (const uint8_t *)msg, strlen(msg));int eos_uart_read(uint8_t port, uint8_t *data, size_t len, uint32_t timeout_ms)Read data from UART. Blocks until len bytes received or timeout expires.
Parameters
| port | uint8_t | UART port. |
| data | uint8_t * | Receive buffer. |
| len | size_t | Max bytes to read. |
| timeout_ms | uint32_t | Timeout in ms. EOS_WAIT_FOREVER to block indefinitely. |
Returns
Bytes read, or negative error code.
void eos_uart_deinit(uint8_t port)Deinitialize UART port, releasing resources.
Parameters
| port | uint8_t | UART port to release. |
int eos_uart_set_rx_callback(uint8_t port, eos_uart_rx_callback_t cb, void *ctx)Register per-byte receive callback. Fires from ISR context.
Parameters
| port | uint8_t | UART port. |
| cb | eos_uart_rx_callback_t | void (*)(uint8_t port, uint8_t byte, void *ctx) |
| ctx | void * | User context. |
Returns
0 on success, negative error code.
SPI
int eos_spi_init(const eos_spi_config_t *cfg)Initialize SPI port with clock speed, mode (CPOL/CPHA 0-3), bits per word, and CS pin.
Parameters
| cfg | const eos_spi_config_t * | SPI config: port, clock_hz, mode, bits_per_word, cs_pin. |
Returns
0 on success, negative error code.
Example
eos_spi_config_t spi = { .port=0, .clock_hz=1000000,
.mode=EOS_SPI_MODE_0, .bits_per_word=8, .cs_pin=10 };
eos_spi_init(&spi);int eos_spi_transfer(uint8_t port, const uint8_t *tx, uint8_t *rx, size_t len)Full-duplex SPI transfer. Either tx or rx may be NULL for half-duplex.
Parameters
| port | uint8_t | SPI port. |
| tx | const uint8_t * | TX buffer (NULL = receive only). |
| rx | uint8_t * | RX buffer (NULL = transmit only). |
| len | size_t | Transfer length in bytes. |
Returns
0 on success, negative error code.
int eos_spi_write(uint8_t port, const uint8_t *data, size_t len)Write-only SPI transfer (discards received data).
Parameters
| port | uint8_t | SPI port. |
| data | const uint8_t * | Data to send. |
| len | size_t | Byte count. |
Returns
0 on success, negative error code.
int eos_spi_read(uint8_t port, uint8_t *data, size_t len)Read-only SPI transfer (clocks out zeros).
Parameters
| port | uint8_t | SPI port. |
| data | uint8_t * | Receive buffer. |
| len | size_t | Byte count. |
Returns
0 on success, negative error code.
I2C
int eos_i2c_init(const eos_i2c_config_t *cfg)Initialize I2C port with clock frequency and optional own address.
Parameters
| cfg | const eos_i2c_config_t * | I2C config: port, clock_hz (100k/400k), own_addr. |
Returns
0 on success, negative error code.
Example
eos_i2c_config_t i2c = { .port=0, .clock_hz=400000, .own_addr=0 };
eos_i2c_init(&i2c);int eos_i2c_write(uint8_t port, uint16_t addr, const uint8_t *data, size_t len)Write data to I2C device at 7-bit address.
Parameters
| port | uint8_t | I2C port. |
| addr | uint16_t | Device address. |
| data | const uint8_t * | Data buffer. |
| len | size_t | Byte count. |
Returns
0 on success, negative error code.
int eos_i2c_read(uint8_t port, uint16_t addr, uint8_t *data, size_t len)Read data from I2C device.
Parameters
| port | uint8_t | I2C port. |
| addr | uint16_t | Device address. |
| data | uint8_t * | Receive buffer. |
| len | size_t | Byte count. |
Returns
0 on success, negative error code.
int eos_i2c_write_reg(uint8_t port, uint16_t addr, uint8_t reg, const uint8_t *data, size_t len)Write to a specific register on an I2C device (register address + data in one transaction).
Parameters
| port | uint8_t | I2C port. |
| addr | uint16_t | Device address. |
| reg | uint8_t | Register address. |
| data | const uint8_t * | Data to write. |
| len | size_t | Byte count. |
Returns
0 on success, negative error code.
int eos_i2c_read_reg(uint8_t port, uint16_t addr, uint8_t reg, uint8_t *data, size_t len)Read from a specific register on an I2C device.
Parameters
| port | uint8_t | I2C port. |
| addr | uint16_t | Device address. |
| reg | uint8_t | Register address. |
| data | uint8_t * | Receive buffer. |
| len | size_t | Byte count. |
Returns
0 on success, negative error code.
Example
uint8_t who;
eos_i2c_read_reg(0, 0x68, 0x75, &who, 1); // MPU6050 WHO_AM_I
printf("WHO_AM_I = 0x%02X\n", who);Timer
int eos_timer_init(const eos_timer_config_t *cfg)Initialize a hardware timer with period, auto-reload, and callback.
Parameters
| cfg | const eos_timer_config_t * | Timer config: timer_id, period_us, auto_reload, callback, ctx. |
Returns
0 on success, negative error code.
Example
void tick(uint8_t id, void *ctx) { eos_gpio_toggle(13); }
eos_timer_config_t t = { .timer_id=0, .period_us=1000000,
.auto_reload=true, .callback=tick };
eos_timer_init(&t);
eos_timer_start(0);int eos_timer_start(uint8_t timer_id)Start a previously initialized timer.
Parameters
| timer_id | uint8_t | Timer ID. |
Returns
0 on success, negative error code.
int eos_timer_stop(uint8_t timer_id)Stop a running timer. Can be restarted with eos_timer_start().
Parameters
| timer_id | uint8_t | Timer ID. |
Returns
0 on success, negative error code.
uint32_t eos_timer_get_count(uint8_t timer_id)Get current timer counter value.
Parameters
| timer_id | uint8_t | Timer ID. |
Returns
Counter value in microseconds.
Interrupts
void eos_irq_disable(void)Globally disable interrupts. Pair with eos_irq_enable().
void eos_irq_enable(void)Re-enable globally disabled interrupts.
int eos_irq_register(uint16_t irq_num, void (*handler)(void), uint8_t priority)Register an ISR for a specific IRQ number with given priority.
Parameters
| irq_num | uint16_t | IRQ number (platform-specific). |
| handler | void (*)(void) | Interrupt handler function. |
| priority | uint8_t | Priority (0=highest). |
Returns
0 on success, negative error code.
void eos_irq_unregister(uint16_t irq_num)Unregister an ISR for the specified IRQ.
Parameters
| irq_num | uint16_t | IRQ number. |
⚙ Kernel (RTOS)
Task management, mutexes, semaphores, message queues, software timers. Header: <eos/kernel.h>
EOS_MAX_TASKS=16 • EOS_MAX_MUTEXES=8 • EOS_MAX_SEMAPHORES=8 • EOS_MAX_QUEUES=8 • EOS_WAIT_FOREVER=0xFFFFFFFF • EOS_NO_WAIT=0Return codes:
EOS_KERN_OK=0, ERR=-1, TIMEOUT=-2, FULL=-3, EMPTY=-4, INVALID=-5, NO_MEMORY=-6Lifecycle
int eos_kernel_init(void)Initialize the RTOS kernel — scheduler, idle task, tick timer. Call before creating tasks.
Returns
EOS_KERN_OK on success.
void eos_kernel_start(void)Start the scheduler. Does not return. Create at least one task first.
Example
int main(void) {
eos_hal_init();
eos_kernel_init();
eos_task_create("app", app_task, NULL, 1, 1024);
eos_kernel_start(); // never returns
}bool eos_kernel_is_running(void)Check if the scheduler is active.
Returns
true if running.
Task Management
int eos_task_create(const char *name, eos_task_func_t entry, void *arg, uint8_t priority, uint32_t stack_size)Create a new task in READY state. Higher priority number = scheduled first.
Parameters
| name | const char * | Task name (debug display). |
| entry | eos_task_func_t | Entry point: void (*)(void *arg) |
| arg | void * | Argument passed to entry. |
| priority | uint8_t | Priority level. |
| stack_size | uint32_t | Stack size in bytes. |
Returns
Task handle (>=0) on success, negative error code.
Example
void sensor_task(void *arg) {
while (1) {
read_sensor();
eos_task_delay_ms(100);
}
}
int h = eos_task_create("sensor", sensor_task, NULL, 2, 512);int eos_task_delete(eos_task_handle_t handle)Delete a task and free its resources.
Parameters
| handle | eos_task_handle_t | Task handle from eos_task_create(). |
Returns
EOS_KERN_OK on success.
int eos_task_suspend(eos_task_handle_t handle)Suspend a task. Task remains in memory but will not be scheduled until resumed.
Parameters
| handle | eos_task_handle_t | Task handle. |
Returns
EOS_KERN_OK on success.
int eos_task_resume(eos_task_handle_t handle)Resume a previously suspended task.
Parameters
| handle | eos_task_handle_t | Task handle. |
Returns
EOS_KERN_OK on success.
void eos_task_yield(void)Voluntarily yield the CPU to the next ready task of equal or higher priority.
void eos_task_delay_ms(uint32_t ms)Block the current task for ms milliseconds. Yields to the scheduler (non-blocking to other tasks).
Parameters
| ms | uint32_t | Delay in milliseconds. |
eos_task_handle_t eos_task_get_current(void)Get the handle of the currently running task.
Returns
Current task handle.
eos_task_state_t eos_task_get_state(eos_task_handle_t handle)Get the state of a task: READY, RUNNING, BLOCKED, SUSPENDED, or DELETED.
Parameters
| handle | eos_task_handle_t | Task handle. |
Returns
eos_task_state_t enum value.
const char * eos_task_get_name(eos_task_handle_t handle)Get the name string of a task.
Parameters
| handle | eos_task_handle_t | Task handle. |
Returns
Pointer to task name string.
Mutex
int eos_mutex_create(eos_mutex_handle_t *out)Create a new mutex. Stores handle in *out.
Parameters
| out | eos_mutex_handle_t * | Output handle. |
Returns
EOS_KERN_OK on success, EOS_KERN_NO_MEMORY if limit reached.
Example
eos_mutex_handle_t mtx;
eos_mutex_create(&mtx);
eos_mutex_lock(mtx, EOS_WAIT_FOREVER);
// critical section
eos_mutex_unlock(mtx);int eos_mutex_lock(eos_mutex_handle_t handle, uint32_t timeout_ms)Acquire a mutex. Blocks until acquired or timeout.
Parameters
| handle | eos_mutex_handle_t | Mutex handle. |
| timeout_ms | uint32_t | Timeout. EOS_WAIT_FOREVER or EOS_NO_WAIT. |
Returns
EOS_KERN_OK or EOS_KERN_TIMEOUT.
int eos_mutex_unlock(eos_mutex_handle_t handle)Release a previously acquired mutex.
Parameters
| handle | eos_mutex_handle_t | Mutex handle. |
Returns
EOS_KERN_OK on success.
int eos_mutex_delete(eos_mutex_handle_t handle)Delete a mutex and free resources.
Parameters
| handle | eos_mutex_handle_t | Mutex handle. |
Returns
EOS_KERN_OK on success.
Semaphore
int eos_sem_create(eos_sem_handle_t *out, uint32_t initial, uint32_t max)Create a counting semaphore.
Parameters
| out | eos_sem_handle_t * | Output handle. |
| initial | uint32_t | Initial count. |
| max | uint32_t | Maximum count. |
Returns
EOS_KERN_OK on success.
Example
eos_sem_handle_t sem;
eos_sem_create(&sem, 0, 10); // binary-like: start at 0
// Producer: eos_sem_post(sem);
// Consumer: eos_sem_wait(sem, EOS_WAIT_FOREVER);int eos_sem_wait(eos_sem_handle_t handle, uint32_t timeout_ms)Decrement semaphore. Blocks if count is 0 until posted or timeout.
Parameters
| handle | eos_sem_handle_t | Semaphore handle. |
| timeout_ms | uint32_t | Timeout in ms. |
Returns
EOS_KERN_OK or EOS_KERN_TIMEOUT.
int eos_sem_post(eos_sem_handle_t handle)Increment semaphore count and wake one waiting task.
Parameters
| handle | eos_sem_handle_t | Semaphore handle. |
Returns
EOS_KERN_OK or EOS_KERN_FULL.
int eos_sem_delete(eos_sem_handle_t handle)Delete a semaphore.
uint32_t eos_sem_get_count(eos_sem_handle_t handle)Get current semaphore count.
Returns
Current count value.
Message Queue
int eos_queue_create(eos_queue_handle_t *out, size_t item_size, uint32_t capacity)Create a fixed-size message queue.
Parameters
| out | eos_queue_handle_t * | Output handle. |
| item_size | size_t | Size of each item in bytes. |
| capacity | uint32_t | Maximum number of items. |
Returns
EOS_KERN_OK on success.
Example
typedef struct { int type; float value; } msg_t;
eos_queue_handle_t q;
eos_queue_create(&q, sizeof(msg_t), 16);
msg_t m = { .type = 1, .value = 23.5f };
eos_queue_send(q, &m, EOS_WAIT_FOREVER);
msg_t rx;
eos_queue_receive(q, &rx, EOS_WAIT_FOREVER);int eos_queue_send(eos_queue_handle_t handle, const void *item, uint32_t timeout_ms)Send an item to the queue. Blocks if full until space available or timeout.
Parameters
| handle | eos_queue_handle_t | Queue handle. |
| item | const void * | Pointer to item data. |
| timeout_ms | uint32_t | Timeout. |
Returns
EOS_KERN_OK, EOS_KERN_FULL, or EOS_KERN_TIMEOUT.
int eos_queue_receive(eos_queue_handle_t handle, void *item, uint32_t timeout_ms)Receive an item from the queue. Blocks if empty.
Parameters
| handle | eos_queue_handle_t | Queue handle. |
| item | void * | Buffer for received item. |
| timeout_ms | uint32_t | Timeout. |
Returns
EOS_KERN_OK, EOS_KERN_EMPTY, or EOS_KERN_TIMEOUT.
int eos_queue_peek(eos_queue_handle_t handle, void *item)Read front item without removing it.
uint32_t eos_queue_count(eos_queue_handle_t handle)Get number of items currently in queue.
bool eos_queue_is_full(eos_queue_handle_t handle)Check if queue is full.
bool eos_queue_is_empty(eos_queue_handle_t handle)Check if queue is empty.
int eos_queue_delete(eos_queue_handle_t handle)Delete a message queue.
Software Timers
int eos_swtimer_create(eos_swtimer_handle_t *out, const char *name, uint32_t period_ms, bool auto_reload, eos_swtimer_callback_t callback, void *ctx)Create a software timer that runs in the timer task context.
Parameters
| out | eos_swtimer_handle_t * | Output handle. |
| name | const char * | Timer name. |
| period_ms | uint32_t | Timer period. |
| auto_reload | bool | Auto-restart after expiry. |
| callback | eos_swtimer_callback_t | void (*)(handle, void *ctx) |
| ctx | void * | User context. |
Returns
EOS_KERN_OK on success.
Example
void heartbeat(eos_swtimer_handle_t h, void *ctx) {
eos_gpio_toggle(13);
}
eos_swtimer_handle_t t;
eos_swtimer_create(&t, "hb", 1000, true, heartbeat, NULL);
eos_swtimer_start(t);int eos_swtimer_start(eos_swtimer_handle_t handle)Start a software timer.
int eos_swtimer_stop(eos_swtimer_handle_t handle)Stop a running software timer.
int eos_swtimer_reset(eos_swtimer_handle_t handle)Reset timer counter to zero and restart.
int eos_swtimer_delete(eos_swtimer_handle_t handle)Delete a software timer.
⚙ Multicore Framework
SMP/AMP, spinlocks, IPI, shared memory, core affinity, atomics. Header: <eos/multicore.h> (requires EOS_ENABLE_MULTICORE)
Core Management
int eos_multicore_init(eos_mp_mode_t mode)Initialize multicore framework in SMP or AMP mode.
Parameters
| mode | eos_mp_mode_t | EOS_MP_SMP (same OS image) or EOS_MP_AMP (per-core firmware). |
Returns
0 on success, negative error code.
Example
eos_multicore_init(EOS_MP_SMP);
printf("Cores: %u, I am core %u\n", eos_core_count(), eos_core_id());uint8_t eos_core_count(void)Get total number of cores available on the platform.
Returns
Number of cores (1-16).
uint8_t eos_core_id(void)Get the ID of the core executing this call.
Returns
Core ID (0-based).
int eos_core_start(uint8_t core_id, eos_core_entry_fn entry, void *arg)Start a secondary core with the given entry function.
Parameters
| core_id | uint8_t | Core to start. |
| entry | eos_core_entry_fn | void (*)(void *arg) |
| arg | void * | Argument for entry. |
Returns
0 on success.
Example
void core1_main(void *arg) { while(1) process_audio(); }
eos_core_start(1, core1_main, NULL);int eos_core_stop(uint8_t core_id)Stop a secondary core.
int eos_core_get_info(uint8_t core_id, eos_core_info_t *info)Get core info: state, frequency, load percentage, MP mode.
Parameters
| core_id | uint8_t | Core ID. |
| info | eos_core_info_t * | Output info struct. |
Returns
0 on success.
Spinlocks
void eos_spin_init(eos_spinlock_t *lock)Initialize a spinlock. Use EOS_SPINLOCK_INIT for static init.
void eos_spin_lock(eos_spinlock_t *lock)Acquire spinlock. Busy-waits until lock is available. Use for short critical sections only.
bool eos_spin_trylock(eos_spinlock_t *lock)Try to acquire spinlock without blocking.
Returns
true if acquired, false if already held.
void eos_spin_unlock(eos_spinlock_t *lock)Release a previously acquired spinlock.
void eos_spin_lock_irqsave(eos_spinlock_t *lock, uint32_t *flags)Acquire spinlock and save/disable IRQs. Use when lock is shared between task and ISR context.
void eos_spin_unlock_irqrestore(eos_spinlock_t *lock, uint32_t flags)Release spinlock and restore IRQ state.
Inter-Processor Interrupts
int eos_ipi_send(uint8_t target_core, eos_ipi_type_t type, uint32_t data)Send an inter-processor interrupt to a specific core.
Parameters
| target_core | uint8_t | Destination core ID. |
| type | eos_ipi_type_t | RESCHEDULE, CALL_FUNC, STOP, or USER. |
| data | uint32_t | User data payload. |
Returns
0 on success.
int eos_ipi_broadcast(eos_ipi_type_t type, uint32_t data)Broadcast IPI to all other cores.
int eos_ipi_register_handler(eos_ipi_type_t type, eos_ipi_handler_t handler, void *ctx)Register handler for a specific IPI type: void (*)(uint8_t from_core, uint32_t data, void *ctx)
Shared Memory
int eos_shmem_create(const eos_shmem_config_t *cfg, eos_shmem_region_t *region)Create a named shared memory region accessible by all cores.
Parameters
| cfg | const eos_shmem_config_t * | Config: name, base address, size, cached flag. |
| region | eos_shmem_region_t * | Output region info (addr, size, id). |
Returns
0 on success.
Example
eos_shmem_config_t cfg = { .name="ipc_buf", .base=NULL, .size=4096, .cached=false };
eos_shmem_region_t region;
eos_shmem_create(&cfg, ®ion);
memcpy(region.addr, data, len);int eos_shmem_open(const char *name, eos_shmem_region_t *region)Open an existing shared memory region by name.
int eos_shmem_close(eos_shmem_region_t *region)Close a shared memory region.
Atomics
int32_t eos_atomic_add(volatile int32_t *ptr, int32_t val)Atomically add val to *ptr and return the previous value.
int32_t eos_atomic_sub(volatile int32_t *ptr, int32_t val)Atomically subtract val from *ptr and return previous value.
int32_t eos_atomic_cas(volatile int32_t *ptr, int32_t expected, int32_t desired)Compare-and-swap: if *ptr == expected, set to desired. Returns old value.
int32_t eos_atomic_load(volatile const int32_t *ptr)Atomic load with acquire semantics.
void eos_atomic_store(volatile int32_t *ptr, int32_t val)Atomic store with release semantics.
void eos_dmb(void) / eos_dsb(void) / eos_isb(void)Memory barriers: Data Memory Barrier, Data Synchronization Barrier, Instruction Synchronization Barrier.
Task Affinity
int eos_task_set_affinity(uint32_t task_id, eos_core_mask_t mask)Pin a task to specific core(s). Use EOS_CORE_MASK(c) to build mask.
Example
eos_task_set_affinity(tid, EOS_CORE_MASK(0) | EOS_CORE_MASK(1)); // cores 0,1 onlyint eos_task_migrate(uint32_t task_id, uint8_t target_core)Migrate a running task to a different core.
🔒 Cryptographic Services
SHA-256/512, CRC32/64, AES-128/256, RSA, ECC. Header: <eos/crypto.h>
SHA-256
void eos_sha256_init(EosSha256 *ctx)Initialize SHA-256 hash context.
void eos_sha256_update(EosSha256 *ctx, const void *data, size_t len)Feed data into the SHA-256 hash. Can be called multiple times for streaming.
void eos_sha256_final(EosSha256 *ctx, uint8_t digest[32])Finalize and output the 32-byte SHA-256 digest.
void eos_sha256_data(const void *data, size_t len, char hex[65])One-shot SHA-256: compute hash and output as hex string.
Example
char hex[65];
eos_sha256_data("hello", 5, hex);
printf("SHA-256: %s\n", hex);int eos_sha256_file(const char *path, char hex[65])Compute SHA-256 of a file. Returns 0 on success.
CRC
uint32_t eos_crc32(uint32_t crc, const void *data, size_t len)Compute CRC32. Pass crc=0 for initial, chain for streaming.
Example
uint32_t crc = eos_crc32(0, firmware_data, firmware_size);
printf("CRC32: 0x%08X\n", crc);AES
void eos_aes_init(EosAesCtx *ctx, const uint8_t *key, int key_bits)Initialize AES context. key_bits = 128 or 256.
void eos_aes_cbc_encrypt(const EosAesCtx *ctx, const uint8_t *iv, const uint8_t *in, uint8_t *out, size_t len)AES-CBC encrypt. len must be multiple of 16.
void eos_aes_cbc_decrypt(const EosAesCtx *ctx, const uint8_t *iv, const uint8_t *in, uint8_t *out, size_t len)AES-CBC decrypt.
RSA & ECC
int eos_rsa_sign_sha256(const EosRsaKey *key, const uint8_t hash[32], uint8_t *sig, size_t *sig_len)RSA sign a SHA-256 hash. Private key required.
int eos_rsa_verify_sha256(const EosRsaKey *key, const uint8_t hash[32], const uint8_t *sig, size_t sig_len)RSA verify a SHA-256 signature. Returns 0 if valid.
int eos_ecc_sign(const EosEccKey *key, const uint8_t *hash, size_t hash_len, uint8_t *sig, size_t *sig_len)ECDSA sign.
int eos_ecc_verify(const EosEccKey *key, const uint8_t *hash, size_t hash_len, const uint8_t *sig, size_t sig_len)ECDSA verify. Returns 0 if valid.
🔃 OTA Updates
Firmware download, verification, A/B slot management, rollback. Header: <eos/ota.h>
int eos_ota_init(void) / eos_ota_deinit(void)Initialize/deinitialize the OTA subsystem.
int eos_ota_check_update(const eos_ota_source_t *source, bool *available)Check if a firmware update is available at the given URL.
Parameters
| source | const eos_ota_source_t * | URL, version, expected_size, sha256, use_tls. |
| available | bool * | Output: true if newer version exists. |
int eos_ota_begin(const eos_ota_source_t *source)Begin OTA download to the inactive slot.
int eos_ota_write_chunk(const uint8_t *data, size_t len)Write a firmware chunk. Call repeatedly until all data written.
int eos_ota_finish(void)Finalize OTA write. Pads and commits to flash.
int eos_ota_verify(void)Verify the downloaded image (CRC, SHA-256, signature).
int eos_ota_apply(void)Mark update slot as pending and trigger reboot.
int eos_ota_rollback(void)Rollback to the previous firmware slot.
int eos_ota_get_status(eos_ota_status_t *status)Get current OTA status: state, progress, active/update slot, versions.
int eos_ota_set_progress_callback(eos_ota_progress_cb cb, void *ctx)Register progress callback: void (*)(uint8_t pct, void *ctx)
Full OTA Example
eos_ota_init();
eos_ota_source_t src = { .url="https://fw.example.com/v2.bin", .version="2.0.0", .use_tls=true };
bool avail;
eos_ota_check_update(&src, &avail);
if (avail) {
eos_ota_begin(&src);
// ... write chunks ...
eos_ota_finish();
if (eos_ota_verify() == 0) eos_ota_apply(); // reboots
}📡 Sensor Framework
Unified sensor API with filtering and calibration. Header: <eos/sensor.h>
int eos_sensor_init(void) / eos_sensor_deinit(void)Initialize/deinitialize the sensor subsystem.
int eos_sensor_register(const eos_sensor_config_t *cfg)Register a sensor with ID, name, type, filter, sample interval, and read function.
Parameters
| cfg | const eos_sensor_config_t * | Config: id, name, type (TEMPERATURE..CUSTOM), filter type (NONE/AVERAGE/MEDIAN/LOWPASS/KALMAN), window, interval_ms, read_fn. |
Example
int read_temp(uint8_t id, float *val) { *val = adc_to_celsius(adc_read(0)); return 0; }
eos_sensor_config_t cfg = { .id=0, .name="temp", .type=EOS_SENSOR_TEMPERATURE,
.filter=EOS_FILTER_KALMAN, .filter_window=8, .sample_interval_ms=1000, .read_fn=read_temp };
eos_sensor_register(&cfg);int eos_sensor_read(uint8_t id, eos_sensor_reading_t *reading)Read raw sensor value. Returns value, min, max, timestamp, valid flag.
int eos_sensor_read_filtered(uint8_t id, eos_sensor_reading_t *reading)Read filtered sensor value using configured filter (average, median, lowpass, Kalman).
int eos_sensor_calibrate(uint8_t id, const eos_sensor_calib_t *calib)Set calibration offset and scale for a sensor.
int eos_sensor_auto_calibrate(uint8_t id)Automatically calibrate sensor using built-in algorithm.
int eos_sensor_set_filter(uint8_t id, eos_filter_type_t filter, uint8_t window_size)Change filter type and window size at runtime.
⚙ Motor Control
PID loops, trajectory planning, encoder feedback. Header: <eos/motor_ctrl.h>
int eos_motor_ctrl_init(void) / eos_motor_ctrl_deinit(void)Initialize/deinitialize motor control subsystem.
int eos_motor_ctrl_configure(const eos_motor_ctrl_config_t *cfg)Configure a motor with PID parameters, encoder CPR, and control rate.
Parameters
| cfg | const eos_motor_ctrl_config_t * | motor_id, pid_speed {kp,ki,kd,integral_max,output_min,output_max}, pid_position, encoder_cpr, control_rate_hz. |
Example
eos_motor_ctrl_config_t cfg = {
.motor_id = 0,
.pid_speed = { .kp=1.0, .ki=0.1, .kd=0.01, .output_min=-100, .output_max=100 },
.encoder_cpr = 1024,
.control_rate_hz = 1000
};
eos_motor_ctrl_configure(&cfg);int eos_motor_ctrl_set_speed(uint8_t motor_id, int16_t target_speed)Set closed-loop speed target in RPM.
int eos_motor_ctrl_set_position(uint8_t motor_id, int32_t target_position)Set closed-loop absolute position target in encoder steps.
int eos_motor_ctrl_move_relative(uint8_t motor_id, int32_t delta)Move motor by relative number of encoder steps.
int eos_motor_ctrl_run_trajectory(uint8_t motor_id, const eos_trajectory_t *segments, size_t num_segments)Execute a multi-segment trajectory with position, speed, acceleration, and duration per segment.
int eos_motor_ctrl_stop(uint8_t motor_id) / eos_motor_ctrl_emergency_stop(uint8_t motor_id)Stop motor (controlled deceleration) or emergency stop (immediate).
int eos_motor_ctrl_get_status(uint8_t motor_id, eos_motor_ctrl_status_t *status)Get motor status: current/target position, speed, PID output, in_motion, stalled flags.
void eos_motor_ctrl_update(void)Run one PID control loop iteration. Call from timer ISR at control_rate_hz.
📁 Filesystem
File operations over flash, SD, or RAM. Supports FAT, LittleFS, SPIFFS, RAMFS. Header: <eos/filesystem.h>
int eos_fs_init(const eos_fs_config_t *cfg)Initialize filesystem. Config: type (FAT/LITTLEFS/SPIFFS/RAMFS), flash_id, base_addr, size.
Example
eos_fs_config_t fs = { .type=EOS_FS_LITTLEFS, .flash_id=0, .base_addr=0x08100000, .size=1048576 };
eos_fs_init(&fs);eos_file_t eos_fs_open(const char *path, uint32_t flags)Open a file. Flags: EOS_O_READ, EOS_O_WRITE, EOS_O_CREATE, EOS_O_APPEND, EOS_O_TRUNC (bitwise OR).
Returns
File descriptor (≥0) or EOS_FILE_INVALID (-1).
Example
eos_file_t f = eos_fs_open("/config.json", EOS_O_READ);
char buf[256];
int n = eos_fs_read(f, buf, sizeof(buf));
eos_fs_close(f);int eos_fs_read(eos_file_t fd, void *buf, size_t len)Read up to len bytes from file. Returns bytes read.
int eos_fs_write(eos_file_t fd, const void *data, size_t len)Write data to file. Returns bytes written.
int eos_fs_close(eos_file_t fd)Close file descriptor.
int eos_fs_seek(eos_file_t fd, int32_t offset, eos_seek_whence_t whence)Seek within file. Whence: EOS_SEEK_SET, EOS_SEEK_CUR, EOS_SEEK_END.
int eos_fs_mkdir(const char *path)Create a directory.
int eos_fs_remove(const char *path) / eos_fs_rename(const char *old, const char *new) / eos_fs_exists(const char *path)Remove file, rename, or check existence.
int eos_fs_stat(eos_fs_stat_t *stat)Get filesystem statistics: total_bytes, used_bytes, free_bytes.
int eos_fs_format(void)Format the entire filesystem. All data will be lost.
⚡ Power Management
Sleep modes, battery monitoring, wake sources, peripheral power, CPU scaling. Header: <eos/power.h>
int eos_power_init(const eos_power_config_t *cfg)Initialize power management. Config: ADC channel, battery full/empty voltages, divider ratio.
int eos_power_enter_mode(eos_power_mode_t mode)Enter a power mode: EOS_POWER_RUN, SLEEP, DEEP_SLEEP, or SHUTDOWN.
Example
eos_power_set_wake_sources(EOS_WAKE_GPIO | EOS_WAKE_RTC);
eos_power_enter_mode(EOS_POWER_DEEP_SLEEP); // wakes on GPIO or RTCint eos_power_set_wake_sources(uint32_t wake_mask)Configure wake sources: EOS_WAKE_GPIO, TIMER, RTC, UART, BLE, USB, INTERRUPT (bitwise OR).
uint32_t eos_power_get_battery_mv(void) / eos_power_get_battery_pct(void)Get battery voltage in millivolts or percentage (0-100).
int eos_power_get_battery_info(eos_battery_info_t *info)Get full battery info: voltage_mv, percentage, charging, charger_connected, current_ma, temperature_c.
int eos_power_enable_peripheral(eos_peripheral_id_t periph) / eos_power_disable_peripheral(...)Enable/disable power to individual peripherals (GPIO, UART, SPI, I2C, WiFi, BLE, etc.).
int eos_power_set_cpu_freq(uint32_t freq_hz) / eos_power_get_cpu_freq(void)Set/get CPU frequency for dynamic voltage-frequency scaling.
🌐 Networking
Socket API, HTTP client, MQTT client, mDNS. Header: <eos/net.h>
Sockets
eos_socket_t eos_net_socket(eos_net_proto_t proto)Create a socket. EOS_NET_TCP or EOS_NET_UDP.
Returns
Socket descriptor or EOS_SOCKET_INVALID.
int eos_net_connect(eos_socket_t sock, const eos_net_addr_t *addr)Connect a TCP socket to a remote address (ip + port).
int eos_net_send(eos_socket_t sock, const void *data, size_t len)Send data on a connected socket. Returns bytes sent.
int eos_net_recv(eos_socket_t sock, void *buf, size_t len, uint32_t timeout_ms)Receive data. Returns bytes received or negative on error/timeout.
int eos_net_bind(eos_socket_t sock, uint16_t port) / eos_net_listen(sock, int backlog) / eos_net_accept(sock, eos_net_addr_t *client)Server socket operations: bind to port, listen, accept connections.
int eos_net_close(eos_socket_t sock)Close a socket.
int eos_net_resolve(const char *hostname, uint32_t *ip)DNS resolve hostname to IP address.
HTTP Client
int eos_http_get(const char *url, eos_http_response_t *resp)HTTP GET request. Response contains status_code, body, body_len, content_type.
Example
eos_http_response_t resp;
eos_http_get("http://api.example.com/data", &resp);
printf("Status: %d, Body: %.*s\n", resp.status_code, (int)resp.body_len, resp.body);
eos_http_response_free(&resp);int eos_http_post(const char *url, const void *body, size_t body_len, const char *content_type, eos_http_response_t *resp)HTTP POST with body and content type.
MQTT Client
eos_mqtt_handle_t eos_mqtt_connect(const eos_mqtt_config_t *cfg)Connect to MQTT broker. Config: broker_host, port, client_id, username, password, keepalive_sec.
Example
eos_mqtt_config_t cfg = { .broker_host="mqtt.example.com", .broker_port=1883,
.client_id="sensor01", .keepalive_sec=60 };
eos_mqtt_handle_t mqtt = eos_mqtt_connect(&cfg);
eos_mqtt_publish(mqtt, "sensors/temp", "23.5", 4, 1);int eos_mqtt_publish(eos_mqtt_handle_t h, const char *topic, const void *payload, size_t len, uint8_t qos)Publish a message to an MQTT topic with QoS 0, 1, or 2.
int eos_mqtt_subscribe(eos_mqtt_handle_t h, const char *topic, uint8_t qos, eos_mqtt_msg_callback_t cb, void *ctx)Subscribe to topic with callback: void (*)(const char *topic, const uint8_t *payload, size_t len, void *ctx)
int eos_mqtt_loop(eos_mqtt_handle_t h, uint32_t timeout_ms)Process MQTT events. Call periodically to handle incoming messages and keepalive.
mDNS
int eos_mdns_register(const char *service_name, const char *service_type, uint16_t port)Register a service for mDNS discovery.
int eos_mdns_resolve(const char *service_type, eos_net_addr_t *addr, uint32_t timeout_ms)Discover a service via mDNS.
🐛 Debug Tools
GDB remote stub and core dump capture. Headers: <eos/gdb_stub.h>, <eos/coredump.h>
GDB Stub
int eos_gdb_init(EosGdbStub *stub, EosGdbTransport transport)Initialize GDB stub with UART or TCP transport.
Example
EosGdbStub stub;
eos_gdb_init(&stub, EOS_GDB_TRANSPORT_UART);
eos_gdb_start(&stub, 115200); // baud rate for UART
// For TCP: eos_gdb_start(&stub, 3333); // portint eos_gdb_start(EosGdbStub *stub, int port_or_baud)Start listening for GDB connections. For UART: baud rate; for TCP: port number.
void eos_gdb_stop(EosGdbStub *stub)Stop GDB stub and disconnect.
void eos_gdb_handle_exception(EosGdbStub *stub, int signal)Handle a debug exception — call from your fault handler.
int eos_gdb_add_breakpoint(EosGdbStub *stub, uint32_t addr) / eos_gdb_remove_breakpoint(...)Add/remove software breakpoints at memory address. Max 16 breakpoints.
void eos_gdb_breakpoint(void)Trigger a breakpoint programmatically (like BKPT instruction).
int eos_gdb_is_connected(EosGdbStub *stub)Check if a GDB client is connected.
Core Dump
int eos_coredump_init(EosDumpTarget target)Initialize core dump subsystem. Target: EOS_DUMP_TARGET_FLASH, UART, or RAM.
int eos_coredump_capture(EosCrashReason reason, const EosCrashRegs *regs)Capture crash state. Reasons: HARDFAULT, MEMFAULT, BUSFAULT, USAGEFAULT, ASSERT, WATCHDOG, STACK_OVF.
Example
void HardFault_Handler(void) {
EosCrashRegs regs;
// ... populate regs from exception frame ...
eos_coredump_capture(EOS_CRASH_HARDFAULT, ®s);
}int eos_coredump_save(const EosCoreDump *dump) / eos_coredump_load(EosCoreDump *dump)Save/load core dump to/from configured target. Magic: 0xC0DEDEAD.
void eos_coredump_print(const EosCoreDump *dump)Print formatted crash report to serial/stderr.
int eos_coredump_exists(void) / eos_coredump_clear(void) / eos_coredump_validate(const EosCoreDump *dump)Check if dump exists, clear saved dump, or validate CRC32.
🔌 Driver Framework
Device driver registration, probe/bind, power management. Header: <eos/driver.h>
int eos_drv_init(EosDrvRegistry *reg)Initialize the driver registry (max 64 drivers).
int eos_drv_register(EosDrvRegistry *reg, EosDriver *drv)Register a driver. Driver struct provides name, class, probe/remove/suspend/resume/ioctl ops.
Example
int my_probe(EosDriver *d, void *pd) { /* init hardware */ return 0; }
void my_remove(EosDriver *d) { /* cleanup */ }
EosDriver my_drv = {
.name = "my_sensor", .version = 1,
.class_id = EOS_DRV_CLASS_SENSOR,
.probe = my_probe, .remove = my_remove
};
eos_drv_register(®istry, &my_drv);
eos_drv_probe(®istry, "my_sensor", platform_data);int eos_drv_probe(EosDrvRegistry *reg, const char *name, void *platform_data)Probe (bind) a specific driver with platform data.
int eos_drv_probe_all(EosDrvRegistry *reg)Probe all registered drivers.
EosDriver * eos_drv_find(EosDrvRegistry *reg, const char *name)Find a driver by name. Returns pointer or NULL.
EosDriver * eos_drv_find_by_class(EosDrvRegistry *reg, EosDrvClass class_id, int index)Find nth driver of a given class (GPIO, UART, SPI, SENSOR, etc.).
int eos_drv_suspend_all(EosDrvRegistry *reg) / eos_drv_resume_all(...)Suspend/resume all bound drivers for power management.
int eos_drv_ioctl(EosDrvRegistry *reg, const char *name, uint32_t cmd, void *arg)Send an I/O control command to a named driver.
🔧 Service Manager
Service lifecycle, health checks, restart policies, dependencies. Header: <eos/service.h>
int eos_svc_init(EosSvcManager *mgr)Initialize the service manager (max 32 services).
int eos_svc_register(EosSvcManager *mgr, const char *name, const EosSvcOps *ops)Register a service with start/stop/health callbacks.
Example
int wifi_start(void *ctx) { return wifi_connect(); }
void wifi_stop(void *ctx) { wifi_disconnect(); }
int wifi_health(void *ctx) { return wifi_is_connected() ? 0 : -1; }
EosSvcOps wifi_ops = { .start=wifi_start, .stop=wifi_stop, .health=wifi_health };
eos_svc_register(&mgr, "wifi", &wifi_ops);
eos_svc_set_restart_policy(&mgr, "wifi", EOS_SVC_RESTART_ON_FAIL, 5, 3000);
eos_svc_set_watchdog(&mgr, "wifi", 30000);int eos_svc_set_restart_policy(EosSvcManager *mgr, const char *name, EosSvcRestartPolicy policy, uint32_t max, uint32_t delay_ms)Set restart policy: NEVER, ALWAYS, or ON_FAIL with max restarts and delay.
int eos_svc_add_dependency(EosSvcManager *mgr, const char *name, const char *depends_on)Add service dependency — ensures ordering during start/stop.
int eos_svc_start(EosSvcManager *mgr, const char *name) / eos_svc_stop(...) / eos_svc_restart(...)Start, stop, or restart an individual service.
int eos_svc_start_all(EosSvcManager *mgr) / eos_svc_stop_all(...)Start/stop all registered services in dependency order.
void eos_svc_tick(EosSvcManager *mgr, uint32_t now_ms)Service manager tick — call periodically. Checks health, handles restarts, watchdogs.
EosSvcState eos_svc_get_state(EosSvcManager *mgr, const char *name)Get service state: STOPPED, STARTING, RUNNING, STOPPING, FAILED, RESTARTING.
📄 Logging
Multi-output, module-scoped, crash-safe ring buffer. Header: <eos/log.h>
void eos_log_set_level(EosLogLevel level)Set global log level: EOS_LOG_TRACE, DEBUG, INFO, WARN, ERROR, FATAL, NONE.
void eos_log_set_module_level(const char *module, EosLogLevel level)Set per-module log level (e.g., eos_log_set_module_level("hal", EOS_LOG_DEBUG)).
void eos_log_set_output(uint32_t outputs)Set output targets (bitwise OR): EOS_LOG_OUTPUT_STDERR, UART, FILE, RING, SYSLOG.
void eos_log(EosLogLevel level, const char *fmt, ...)Core log function with printf-style formatting.
void eos_log_module(EosLogLevel level, const char *module, const char *fmt, ...)Log with module tag for filtering.
EOS_TRACE(...), EOS_DEBUG(...), EOS_INFO(...), EOS_WARN(...), EOS_ERROR(...), EOS_FATAL(...)Module-scoped: Define
EOS_LOG_MODULE then use MLOG_INFO(...), MLOG_ERROR(...), etc.
void eos_log_ring_dump(void) / eos_log_ring_clear(void)Dump or clear the crash-safe ring buffer (64 entries). Use after reboot to inspect pre-crash logs.
Example
#define EOS_LOG_MODULE "app"
#include <eos/log.h>
eos_log_set_level(EOS_LOG_DEBUG);
eos_log_set_output(EOS_LOG_OUTPUT_UART | EOS_LOG_OUTPUT_RING);
MLOG_INFO("Application started, version %s", APP_VERSION);
MLOG_DEBUG("Sensor reading: %.2f", temperature);