返回提示词目录第 1380 页

设计固件任务执行架构

依据硬件与时序需求选择固件执行模型,规划任务通信、分层和资源配置,并制定期限验证措施。

完整提示词

<context>
You design the execution architecture of a firmware product. The core choice is between a superloop with interrupts, a cooperative run-to-completion scheduler (time-triggered or event-driven with active objects), and a preemptive RTOS. Firmware architectures fail in recognisable ways: an RTOS added by habit to a device that needed a simple state machine, too many tasks each with an oversized stack, priorities assigned by importance rather than deadline, priority inversion on a shared mutex, long work inside interrupt handlers, blocking calls in high-priority tasks, and deadlines that were never measured. Hardware abstraction leaking into application logic makes testing off target impossible.

MCU and platform: {{mcu}}
</context>

<task>
<product_requirements>
{{product_requirements}}
</product_requirements>

1. List every timing requirement as an activity with its trigger (periodic or event), period or minimum inter-arrival time, deadline, estimated execution time (mark as estimate) and consequence of a miss (hard, firm or soft). Compute rough CPU utilisation and flag anything above about 70% as needing measurement.
2. Choose the execution model and justify it against the requirements: superloop when there are few activities with loose deadlines; cooperative scheduler or active objects when activities are event-driven and short; preemptive RTOS when there are independent activities with tight deadlines, blocking communication stacks, or long computations that must not delay urgent work. Note low-power implications (tickless idle, sleep entry point).
3. For an RTOS or scheduler design, produce the task table: task, responsibility, trigger, priority with reasoning (rate monotonic: shorter period gets higher priority, adjusted for deadlines), initial stack size as a starting estimate to be measured with high-water marks, and what it blocks on. Keep interrupt handlers minimal: acknowledge, capture data, defer to a task or queue.
4. Specify communication: queues for data flow, event flags or notifications for signals, mutexes with priority inheritance for shared resources (or a single owner task instead), lock-free ring buffers between interrupts and tasks, and which data is shared and how it is protected. Call out any path with priority inversion risk.
5. Define layering: board support and HAL, drivers, middleware (communication stacks, file systems), services, application. State the rule that the application never touches registers, and how layers are faked for off-target tests.
6. Explain how deadlines are met and verified: worst-case execution time measurement (GPIO toggles with a logic analyser or cycle counters), stack high-water checks, a watchdog strategy that feeds only when all critical tasks report progress, and runtime counters for missed deadlines.
</task>

<constraints>
- Mark every execution-time, stack and memory number as an estimate to measure; never present it as fact.
- If timing requirements or the MCU's RAM are missing, ask for them and stop; they decide the model.
- Do not invent vendor API names; describe RTOS features generically (queue, notification, mutex with priority inheritance) and name the API only when sure.
- If the device is safety-critical (medical, automotive, industrial safety functions), say that the design must follow the relevant functional safety standard and process, and that this output is not a substitute for it.
- Fit the design inside the stated RAM with a margin of at least 20%.
</constraints>

<output_format>
## Timing requirements
Table: activity | trigger | period or inter-arrival | deadline | est. execution time | miss consequence. Then utilisation.

## Execution model
The choice and why, in under 150 words.

## Task table
Table: task or ISR | responsibility | trigger | priority | stack (est.) | blocks on.

## Communication
A Mermaid diagram of tasks, ISRs and channels, then bullets on shared data and protection.

## Layering
Layers with responsibilities and the test seam for each.

## Meeting deadlines
Checklist of measurements, watchdog design and runtime checks.

## Risks and questions
Bullets.
</output_format>

可替换内容

  • {{mcu}}
  • {{product_requirements}}

分类与标签

编程开发、嵌入式开发、固件架构、实时调度

前往 AI 图片创作