《嵌入式系统软件教程5课件.pptx》由会员分享,可在线阅读,更多相关《嵌入式系统软件教程5课件.pptx(92页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、TaskEach 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.A tasks context is saved in the task control block(TCB).第1页/共92页TaskA tasks context includes:-a thread of execution;that is,the tasks program counter
2、-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第2页/共92页TaskThe default task scheduling algorithm in wind is prio
3、rity-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.第3页/共92页Task Scheduler Control Routines第4页/共92页TaskTask LockWhen a task disables the scheduler by calling task
4、Lock(),no priority-based preemption can take place while that task is running.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.The taskLock
5、()prevent task context switching,but do not lock out interrupt handling.第5页/共92页Task Control Routine第6页/共92页TasktaskSpawnTask Name and ID RoutinesTask Information RoutinesTask Deleting RoutinesTask Control RoutinesTask Hook Routines第7页/共92页Task Spawn第8页/共92页Task Name and ID Routines第9页/共92页Task Info
6、rmation Routines第10页/共92页Task Information Routines第11页/共92页Task Deleting Routines第12页/共92页Task Deleting Routines第13页/共92页Task Control Routines第14页/共92页Task Hook Routines第15页/共92页Shared Code and ReentrancyA single copy of code executed by multiple tasks is called shared code.A subroutine is reentrant
7、 if a single copy of the routine can be called from several task contexts simultaneously without conflict.Modify global or static variables.第16页/共92页Code Reentrancy SolutionsDynamic Stack VariablesGuarded Global and Static VariablesTask Variables第17页/共92页Dynamic Stack Variables第18页/共92页Guarded Globa
8、l and Static VariablesProviding a mutual-exclusion mechanism to prohibit tasks from simultaneously executing critical sections of code.第19页/共92页Task Variables第20页/共92页Intertask CommunicationShared Data StructureMutual ExclusionSemaphoresMessage QueuesPipesNetwork Intertask CommunicationSignals第21页/共
9、92页Shared Data StructuresGlobal variablesLinear buffersRing buffersLinked listsPointers第22页/共92页Shared Data Structures第23页/共92页Mutual ExclusionDisable interruptsDisable preemptionResource locking with semaphores第24页/共92页Disable InterruptsThe most powerful methodIt prevents the system from responding
10、 to external events for the duration of these locks.Keep the duration of interrupt lockouts short.第25页/共92页Preemptive locksLess restrictive form of mutual exclusion.No other task is allowed to preemptive the current executing task,ISR are able to execute.Tasks of higher priority are unable to execut
11、e until the locking task leaves the critical region.第26页/共92页SemaphoresHighly optimized and provide the fastest intertask communication mechanism in VxWorks.Three types of Wind semaphores:-Binary-Mutual exclusion-Counting第27页/共92页Semaphore Control Routines第28页/共92页Binary Semaphore第29页/共92页Binary Sem
12、aphore第30页/共92页Binary Semaphore-Mutual Exclusion第31页/共92页Binary Semaphore-Mutual Exclusion第32页/共92页Binary Semaphore-Synchronization第33页/共92页Binary Semaphore-Synchronization第34页/共92页Binary Semaphore-Synchronization第35页/共92页Mutual Semaphore-Recursive Resource Access第36页/共92页Mutual Semaphore-Recursive
13、Resource Access第37页/共92页Counting Semaphores第38页/共92页Message QueueMessage queues allow a variable number of messages,each of variable length,to be queued.Tasks and ISRs can send messages to a message queue,and tasks can receive message form a message queue.Multiple tasks can send to and receive from
14、the same message queue.Full-duplex communication between two tasks generally requires two message queues,one for each direction.第39页/共92页Message Queues第40页/共92页Wind Message Queue Control第41页/共92页Message Queue Example第42页/共92页Message Queue Example第43页/共92页Message Queue Example第44页/共92页Message Queues第
15、45页/共92页PipesPipes provide an alternative interface to the message queue facility that goes through the VxWorks I/O system.第46页/共92页SocketsIn VxWorks,the basis of intertask communication across the network is sockets.VxWorks supports the Internet protocols TCP and UDP.TCP provides reliable,guarantee
16、d,two-way transmission of data with stream sockets.UDP provides a simple but less robust form of communication.第47页/共92页RPCRemote Procedure Calls(RPC)is a facility that allows a process on a machine to call a procedure that is executed by another process on either the same machine or a remote machin
17、e.第48页/共92页SignalSignals asynchronously alter the control flow of a task.Any task or ISR can raise a signal for a particular task.The task being signaled immediately suspends its current thread of execution and executes the task-specified signal handler routine.第49页/共92页SignalSignals asynchronously
18、alter the control flow of a task.Any task or ISR can raise a signal for a particular task.The task being signaled immediately suspends its current thread of execution and executes the task-specified signal handler routine.第50页/共92页EventVxWorks events are means of communication between tasks and inte
19、rrupt routine,between tasks and other tasks,or between tasks and VxWorks objects.VxWorks objects are referred to as resources such as semaphores and message queue.第51页/共92页EventSending and Receiving EventsEvents can be sent from a resource to a task,from an ISR to a task,or directly between two task
20、s.Waiting for EventsA task can wait for multiple events from one or more resources.Each source can send multiple events,and a task can also wait to receive only one event,or all events.第52页/共92页EventRegistering for EventsOnly one task can register itself to receive events from a resource.If another
21、task subsequently registers with the same resource,the previously registered task is automatically unregistered.Freeing ResourceWhen a resource sends to a task to indicate that it is free,it does not mean that resource is reserved.第53页/共92页EventFree Resource DefinitionMutex Semaphore-A mutex semapho
22、re is considered free when it no longer has an owner and no one is pending on it.Binary Semaphore-A binary semaphore is considered free when no task owns it and no one is waiting for it.第54页/共92页EventFree Resource DefinitionCounting Semaphore-A counting semaphore is considered free when its counts i
23、s nonzero and no one is pending on it.Message Queue-A message queue is considered free when a message queue is present in the queue and no one is pending for the arrival of a message in that queue.第55页/共92页EventSending and Receiving EventsEvents can be sent from a resource to a task,from an ISR to a
24、 task,or directly between two tasks.Waiting for EventsA task can wait for multiple events from one or more resources.Each source can send multiple events,and a task can also wait to receive only one event,or all events.第56页/共92页Watchdog TimersVxWorks includes a watchdog-timer mechanism that allows a
25、ny C function to be connect to a specified time delay.Function invoked by watchdog timers execute as interrupt service code at the interrupt level of the system clock.第57页/共92页Watchdog Timers Calls第58页/共92页Watchdog Timers Example第59页/共92页Event Register Routine第60页/共92页Interrupt Service Routine第61页/共
26、92页intConnect Routine第62页/共92页Appendix:Shell Run a shellVariables in shellC commands in shell:printfShell commands:i,ti,w,tw,第63页/共92页Run a shell 第64页/共92页Variables in shell第65页/共92页C commands in shell第66页/共92页Shell commands:i第67页/共92页Shell Commands:td第68页/共92页Shell Commands:ts&tr第69页/共92页Shell Comm
27、ands:ti第70页/共92页Shell Commands:w第71页/共92页Shell Commands:tw第72页/共92页Shell Commands:checkStack第73页/共92页Shell Commands:d第74页/共92页Shell Commands:d第75页/共92页Shell Commands:d第76页/共92页Shell Commands:ls第77页/共92页Shell Commands:pwd&cd第78页/共92页Shell Commands:h第79页/共92页Shell Commands:reboot第80页/共92页Shell Command
28、s:semaphore第81页/共92页Shell Commands:semaphore第82页/共92页Shell Commands:semaphore第83页/共92页Shell Commands:semaphore第84页/共92页Shell Commands:semaphore第85页/共92页Shell Commands:Message Queue第86页/共92页Shell Commands:Message Queue第87页/共92页Shell Commands:Message Queue第88页/共92页Shell Commands:Message Queue第89页/共92页Shell Commands:Message Queue第90页/共92页Shell Commands:Message Queue第91页/共92页感谢您的观看。第92页/共92页