universalisos/microkernel/test/test_uos_esp32.c
Fábio Coutada 98ed638f3c WIP: emergency commit — ESP32 GDB stub, boot chain work, docs, AGENTS.md rules
All uncommitted work from ESP32 GDB stub development session.
Includes:
- GDB stub (uos_gdbstub.c/.h/_entry.S)
- Startup vector table rewrite
- ESP32 HAL integration files
- Boot chain design docs
- AGENTS.md absolute rules (commit before refactor, no unauthorized changes)
- All prior deepseek session work

This commit prevents further data loss. No claims of correctness.
2026-07-17 01:36:58 +01:00

100 lines
2.5 KiB
C

/*
* UniversalisOS ESP32 — 2-Task Demo
*
* Task A prints "A0\n" through "A9\n"
* Task B prints "B0\n" through "B9\n"
* Alternating via semaphore. Co-routine pattern.
*
* Build: make TARGET=esp32hw
* Load: U-Boot auto-boot (jumps to entry point)
*/
#include "uos_api.h"
#include "uos_hal.h"
/* ---- Task stacks (static allocation, Tier 0) ---- */
UOS_TASK_DEF(task_a, 1, 1024);
UOS_TASK_DEF(task_b, 1, 1024);
/* ---- Semaphore for alternating ---- */
UOS_SEM_DEF(sync_a);
UOS_SEM_DEF(sync_b);
/* ---- Shared counter ---- */
static volatile int s_counter = 0;
/* ---- Task A entry ---- */
static void task_a_entry(void *arg)
{
(void)arg;
while (s_counter < 10) {
uos_sem_wait(&sync_a_sem, UOS_WAIT_FOREVER);
uos_hal_uart_putc('A');
uos_hal_uart_putc('0' + s_counter);
uos_hal_uart_putc('\n');
s_counter++;
uos_sem_post(&sync_b_sem);
}
/* Task A done — signal B one last time and exit */
uos_sem_post(&sync_b_sem);
uos_task_delete(NULL); /* delete self */
}
/* ---- Task B entry ---- */
static void task_b_entry(void *arg)
{
(void)arg;
while (s_counter < 10) {
uos_sem_wait(&sync_b_sem, UOS_WAIT_FOREVER);
if (s_counter >= 10) break;
uos_hal_uart_putc('B');
uos_hal_uart_putc('0' + s_counter);
uos_hal_uart_putc('\n');
uos_sem_post(&sync_a_sem);
}
uos_hal_uart_puts("DONE\n");
/* Infinite idle — keep running */
for (;;) {
__asm__ volatile("waiti 0");
}
}
/* ---- Main entry (called by startup) ---- */
int main(void)
{
/* 1. Early hardware init */
uos_hal_wdt_disable_all();
uos_hal_uart_init(115200);
uos_hal_uart_puts("UOS ESP32 2-Task Demo\n");
/* 2. Initialize kernel */
uos_init();
/* 3. Create synchronization semaphores */
uos_sem_init(&sync_a_sem, "sync_a", 1); /* Task A starts first */
uos_sem_init(&sync_b_sem, "sync_b", 0);
/* 4. Create tasks */
uos_task_create("task_a", 1, task_a_entry, NULL,
task_a_stack_mem, sizeof(task_a_stack_mem));
uos_task_create("task_b", 1, task_b_entry, NULL,
task_b_stack_mem, sizeof(task_b_stack_mem));
/* Suppress unused-variable warnings for static task structs */
(void)&task_a_task; (void)&task_b_task;
/* 5. Start scheduler — never returns */
uos_hal_uart_puts("Starting scheduler...\n");
uos_sched_start();
/* NOTREACHED */
for (;;) __asm__ volatile("waiti 0");
return 0;
}