rtos
Use when the user asks about FreeRTOS, task priorities, xTaskCreate, ISR-safe queues, mutex vs semaphore, priority inversion, task notifications, task stack…
by j4flmao★ 47 GitHub stars
Install rtos in Claude Code & Claude Desktop
Sign up to install this skill
Create a free account to reveal the install command and save the skill to your library.
- Reveal the one-line install command
- Save skills to your synced library
- Get notified when skills update
About this skill
RTOS Engineering (FreeRTOS / Zephyr)
Purpose
Turn a firmware feature into a set of tasks, priorities and communication primitives that meet deadlines deterministically. The skill covers how the FreeRTOS kernel actually schedules, which primitive to use for each interaction, how to keep ISRs short, how to size stacks and heaps statically, and how to prove timing on the target.
Agent Protocol
Trigger
"FreeRTOS", "RTOS task", "xTaskCreate", "task priority", "mutex vs semaphore", "priority inversion", "task notification", "stack overflow", "Zephyr thread", "RTOS queue", "ISR to task", "hard real-time", "rate monotonic", "EDF", "WCET", "RTOS vs Linux", "PREEMPT_RT".
Input Context
- MCU/core (Cortex-M0/M3/M4F/M7/M33, RISC-V, ESP32), clock, RAM/flash budget
- Kernel and version (FreeRTOS V10/V11, SMP or not; Zephyr version)
- Deadlines and periods of each activity, interrupt sources and rates
- Safety/coding standard (MISRA C, IEC 61508/ISO 26262 context)
Output Artifact
Task table, primitive choices, C code for tasks/ISRs, FreeRTOSConfig.h settings. No file unless requested.
Response Format
Tasks: {name | priority | period/deadline | stack words | blocks on}
IPC: {producer -> primitive -> consumer}
ISRs: {source | work done in ISR | deferred to}
Config: {key FreeRTOSConfig.h settings}
Code: {snippet}
Verification: {WCET/response-time check, stack high-water marks, trace}
0. Is It Real-Time, and Which Platform?
- Real-time means bounded worst-case response, not fast. Classify each activity: hard (miss = failure, needs a worst-case proof), firm (late result useless), soft (statistics such as p99 are enough).
- Fixed-priority kernels (FreeRTOS, Zephyr, VxWorks, QNX) → Rate/Deadline Monotonic priorities + response-time analysis (section 7). The Liu & Layland bound U <= n(2^(1/n) - 1) (~0.69 for large n) is sufficient, not necessary; EDF is schedulable up to U <= 1 on one core but degrades badly under overload.
- Platform: superloop for one or two timing domains; FreeRTOS for small MCUs; Zephyr when you need its drivers/networking/devicetree; certified RTOS (SafeRTOS, VxWorks, QNX, INTEGRITY) for DO-178C/ISO 26262; Linux PREEMPT_RT (mainline since 6.12) when tens-of-microseconds latency is acceptable and no proof is required.
- Theory, worked RTA example and WCET sources:
references/merged-rtos-fundamentals.md.
1. How the FreeRTOS Scheduler Works
- Fixed-priority preemptive scheduling (
configUSE_PREEMPTION 1). The highest-priority Ready task always runs; equal priorities round-robin on each tick whenconfigUSE_TIME_SLICING 1(default). - Ready tasks live in
pxReadyTasksLists[configMAX_PRIORITIES]; a context switch saves registers on the task's stack and updates the TCB stack pointer. On Cortex-M the switch runs in the lowest-priorityPendSVexception, triggered byportYIELD(); the tick comes from SysTick (xTaskIncrementTick()moves delayed tasks to Ready). - Priority 0 is the idle task. Higher number = higher priority (opposite of Cortex-M NVIC, where lower number = more urgent).
- Tickless idle (
configUSE_TICKLESS_IDLE 1) suppresses ticks while idle for low power. - SMP: FreeRTOS V11 merged SMP support (
configNUMBER_OF_CORES > 1, e.g. RP2040, ESP32 via ESP-IDF's own variant). Two tasks of different priority can then run simultaneously — do not use priority as a mutual-exclusion mechanism.
2. Task Design Rules
- One task per independent timing domain (sensor sampling, control loop, comms, UI), not one per feature.
- Assign priorities by deadline (Rate/Deadline Monotonic): shorter deadline → higher priority. Not by "importance".
- Every task blocks somewhere (
xQueueReceive,ulTaskNotifyTake,vTaskDelayUntil). A task that never blocks starves everything below it. - Periodic tasks use
vTaskDelayUntil(&lastWake, period)(orxTaskDelayUntil) —vTaskDelaydrifts because it is relative to the call time. - Create everything at startup with static allocation; never create/delete tasks in steady state.
#define CTRL_STACK_WORDS 512
static StackType_t ctrlStack[CTRL_STACK_WORDS];
static StaticTask_t ctrlTcb;
static void vControlTask(void *arg)
{
(void)arg;
TickType_t lastWake = xTaskGetTickCount();
const TickType_t period = pdMS_TO_TICKS(5); /* 200 Hz loop */
for (;;) {
vTaskDelayUntil(&lastWake, period);
control_step(); /* bounded WCET */
}
}
void app_start(void)
{
TaskHandle_t h = xTaskCreateStatic(vControlTask, "ctrl", CTRL_STACK_WORDS,
NULL, tskIDLE_PRIORITY + 4, ctrlStack, &ctrlTcb);
configASSERT(h != NULL);
vTaskStartScheduler(); /* does not return */
for (;;) { }
}
Note: the stack depth argument is in words (StackType_t), not bytes.
3. Choosing the Communication Primitive
| Need | Primitive | Notes |
|---|---|---|
| ISR or task signals one specific ta |
Allowed tools
Tools this skill is permitted to call.
No restriction — this skill can use any tool.
Bundled files
- references/merged-rtos-fundamentals.md
FAQ
What does the rtos skill do?
Use when the user asks about FreeRTOS, task priorities, xTaskCreate, ISR-safe queues, mutex vs semaphore, priority inversion, task notifications, task stack overflow or Zephyr threads. Produces RTOS task design, ISR deferral and timing analysis. Not for bare-metal superloops (use c-cpp-patterns or bare-metal-rust).
How do I install the rtos skill?
Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.
Does the rtos skill run scripts?
No, this skill is instructions only (SKILL.md) with no executable scripts.
Related skills
skill-creator
AnthropicCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
discernment-nudge
AnthropicAfter you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
data-consolidate
AnthropicJoins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
inspection-to-capa
AnthropicRuns the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…