amos 2465ffc7cf Add 4 tasks from batch 28: ESP ringbuf, RT-Thread dataqueue and cond wait, NuttX NSH quoting
Batch 28 commit 3847b17 gave ESP ringbuf reserve/publish (1 of 3 passed)
and RT-Thread dataqueue wrap reset (0 of 3) as HARD, and RT-Thread
condition wait transitions and NuttX NSH quoted script flow (2 of 3) as
MEDIUM. Each task comes from the commit Qwen measured, its digest
matches, and it is still present at the batch branch head.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 04:00:02 +08:00

47 lines
1.8 KiB
C

/* SPDX-License-Identifier: Apache-2.0
* User-space CPU context, interrupt-mask, console and heap support. */
#define _XOPEN_SOURCE 700
#include <ucontext.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <rtthread.h>
#include <rthw.h>
struct host_context { ucontext_t ctx; void (*entry)(void *); void *arg; void (*finish)(void); };
static rt_base_t irq_mask;
static void launch(uintptr_t raw) {
struct host_context *c = (void *)raw;
c->entry(c->arg);
c->finish();
abort();
}
rt_uint8_t *rt_hw_stack_init(void *entry, void *arg, rt_uint8_t *top, void *finish) {
struct host_context *c = calloc(1, sizeof(*c));
(void)top;
if (!c) abort();
c->entry = entry; c->arg = arg; c->finish = finish;
if (getcontext(&c->ctx)) abort();
c->ctx.uc_stack.ss_sp = malloc(131072);
c->ctx.uc_stack.ss_size = 131072;
c->ctx.uc_link = NULL;
if (!c->ctx.uc_stack.ss_sp) abort();
makecontext(&c->ctx, (void (*)(void))launch, 1, (uintptr_t)c);
return (void *)c;
}
void rt_hw_context_switch(rt_ubase_t from, rt_ubase_t to) {
struct host_context *a = *(void **)from, *b = *(void **)to;
if (swapcontext(&a->ctx, &b->ctx)) abort();
}
void rt_hw_context_switch_to(rt_ubase_t to) {
struct host_context *b = *(void **)to;
if (setcontext(&b->ctx)) abort();
}
void rt_hw_context_switch_interrupt(rt_ubase_t from, rt_ubase_t to) { rt_hw_context_switch(from,to); }
rt_base_t rt_hw_interrupt_disable(void) { rt_base_t old=irq_mask; irq_mask=1; return old; }
void rt_hw_interrupt_enable(rt_base_t level) { irq_mask=level; }
void rt_hw_console_output(const char *s) { fputs(s,stderr); }
void *rt_malloc(rt_size_t n) { return malloc(n); }
void rt_free(void *p) { free(p); }
void *rt_realloc(void *p, rt_size_t n) { return realloc(p,n); }
void *rt_calloc(rt_size_t a, rt_size_t b) { return calloc(a,b); }