嵌入式系统软件教程5
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Code Reentrancy Solutions
Dynamic Stack Variables Guarded Global and Static Variables Task Variables
Dynamic Stack Variables
Guarded Global and Static Variables
Agenda
Task Intertask communication ISR
Task
Each task has its own context, which is the CPU environment and system resources that the task sees each time it is scheduled to run by the kernel.
Task Spawn
Task Name and ID Routines
Task Information Routines
Task Information Routines
Task Deleting Routines
Task Deleting Routines
Task Control Routines
Task Scheduler Control Routines
Task
Task Lock When a task disables the scheduler by calling taskLock(), no priority-based preemption can take place while that task is running.
A task’s context is saved in the task control block (TCB).
Task
A task’s context includes: - a thread of execution; that is, the task’s program counter - the CPU registers and (optionally) floating-point registers - I/O assignments for standard input, output, and error - a delay timer - a time-slice timer - kernel control structures - signal handlers - debugging and performance monitoring values
Shared Data Structures
Mutual Exclusion
Disable interrupts Disable preemption Resource wk.baidu.comocking with semaphores
Task Hook Routines
Shared Code and Reentrancy
A single copy of code executed by multiple tasks is called shared code. A subroutine is reentrant if a single copy of the routine can be called from several task contexts simultaneously without conflict. Modify global or static variables.
The taskLock() prevent task context switching, but do not lock out interrupt handling.
Task Control Routine
Task
taskSpawn Task Name and ID Routines Task Information Routines Task Deleting Routines Task Control Routines Task Hook Routines
If the task explicitly blocks or suspends, the scheduler selects the next highest-priority eligible task to execute.
When the preemption-locked task unblocks and begins running again, preemption is again disabled.
Task
The default task scheduling algorithm in wind is priority-based preemptive scheduling. Round Robin is an optional algorithm. The wind kernel has 256 priority levels, numbered 0 through 255. Priority 0 is the highest and priority 255 is the lowest.
Shared Data Structure Mutual Exclusion Semaphores Message Queues Pipes Network Intertask Communication Signals
Shared Data Structures
Global variables Linear buffers Ring buffers Linked lists Pointers
Providing a mutual-exclusion mechanism to prohibit tasks from simultaneously executing critical sections of code.
Task Variables
Intertask Communication