Agenda Task Intertask communication ISR Task Each task

  • Slides: 92
Download presentation
Agenda Task Intertask communication ISR

Agenda Task Intertask communication ISR

Task Each task has its own context, which is the CPU environment and system

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. 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

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

Task The default task scheduling algorithm in wind is priority-based preemptive scheduling. Round Robin

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.

Task Scheduler Control Routines

Task Scheduler Control Routines

Task Lock When a task disables the scheduler by calling task. Lock(), no priority-based

Task Lock When a task disables the scheduler by calling task. 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 task. Lock() prevent task context switching, but do not lock out interrupt handling.

Task Control Routine

Task Control Routine

Task task. Spawn Task Name and ID Routines Task Information Routines Task Deleting Routines

Task task. Spawn Task Name and ID Routines Task Information Routines Task Deleting Routines Task Control Routines Task Hook Routines

Task Spawn

Task Spawn

Task Name and ID Routines

Task Name and ID Routines

Task Information Routines

Task Information Routines

Task Information Routines

Task Information Routines

Task Deleting Routines

Task Deleting Routines

Task Deleting Routines

Task Deleting Routines

Task Control Routines

Task Control Routines

Task Hook Routines

Task Hook Routines

Shared Code and Reentrancy A single copy of code executed by multiple tasks is

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.

Code Reentrancy Solutions Dynamic Stack Variables Guarded Global and Static Variables Task Variables

Code Reentrancy Solutions Dynamic Stack Variables Guarded Global and Static Variables Task Variables

Dynamic Stack Variables

Dynamic Stack Variables

Guarded Global and Static Variables Providing a mutual-exclusion mechanism to prohibit tasks from simultaneously

Guarded Global and Static Variables Providing a mutual-exclusion mechanism to prohibit tasks from simultaneously executing critical sections of code.

Task Variables

Task Variables

Intertask Communication Shared Data Structure Mutual Exclusion Semaphores Message Queues Pipes Network Intertask Communication

Intertask Communication 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

Shared Data Structures Global variables Linear buffers Ring buffers Linked lists Pointers

Shared Data Structures

Shared Data Structures

Mutual Exclusion Disable interrupts Disable preemption Resource locking with semaphores

Mutual Exclusion Disable interrupts Disable preemption Resource locking with semaphores

Disable Interrupts The most powerful method It prevents the system from responding to external

Disable Interrupts The most powerful method It prevents the system from responding to external events for the duration of these locks. Keep the duration of interrupt lockouts short.

Preemptive locks Less restrictive form of mutual exclusion. No other task is allowed to

Preemptive locks Less 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 execute until the locking task leaves the critical region.

Semaphores Highly optimized and provide the fastest intertask communication mechanism in Vx. Works. Three

Semaphores Highly optimized and provide the fastest intertask communication mechanism in Vx. Works. Three types of Wind semaphores: - Binary - Mutual exclusion - Counting

Semaphore Control Routines

Semaphore Control Routines

Binary Semaphore

Binary Semaphore

Binary Semaphore

Binary Semaphore

Binary Semaphore - Mutual Exclusion

Binary Semaphore - Mutual Exclusion

Binary Semaphore - Mutual Exclusion

Binary Semaphore - Mutual Exclusion

Binary Semaphore - Synchronization

Binary Semaphore - Synchronization

Binary Semaphore - Synchronization

Binary Semaphore - Synchronization

Binary Semaphore - Synchronization

Binary Semaphore - Synchronization

Mutual Semaphore - Recursive Resource Access

Mutual Semaphore - Recursive Resource Access

Mutual Semaphore - Recursive Resource Access

Mutual Semaphore - Recursive Resource Access

Counting Semaphores

Counting Semaphores

Message Queue Message queues allow a variable number of messages, each of variable length,

Message Queue Message 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 the same message queue. Full-duplex communication between two tasks generally requires two message queues, one for each direction.

Message Queues

Message Queues

Wind Message Queue Control

Wind Message Queue Control

Message Queue Example

Message Queue Example

Message Queue Example

Message Queue Example

Message Queue Example

Message Queue Example

Message Queues

Message Queues

Pipes provide an alternative interface to the message queue facility that goes through the

Pipes provide an alternative interface to the message queue facility that goes through the Vx. Works I/O system.

Sockets In Vx. Works, the basis of intertask communication across the network is sockets.

Sockets In Vx. Works, the basis of intertask communication across the network is sockets. Vx. Works supports the Internet protocols TCP and UDP. TCP provides reliable, guaranteed, two-way transmission of data with stream sockets. UDP provides a simple but less robust form of communication.

RPC Remote Procedure Calls (RPC) is a facility that allows a process on a

RPC Remote 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 machine.

Signals asynchronously alter the control flow of a task. Any task or ISR can

Signals 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.

Signals asynchronously alter the control flow of a task. Any task or ISR can

Signals 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.

Event Vx. Works events are means of communication between tasks and interrupt routine, between

Event Vx. Works events are means of communication between tasks and interrupt routine, between tasks and other tasks, or between tasks and Vx. Works objects are referred to as resources such as semaphores and message queue.

Event Sending and Receiving Events can be sent from a resource to a task,

Event Sending and Receiving Events can be sent from a resource to a task, from an ISR to a task, or directly between two tasks. Waiting for Events A 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.

Event Registering for Events Only one task can register itself to receive events from

Event Registering for Events Only one task can register itself to receive events from a resource. If another task subsequently registers with the same resource, the previously registered task is automatically unregistered. Freeing Resource When a resource sends to a task to indicate that it is free, it does not mean that resource is reserved.

Event Free Resource Definition Mutex Semaphore - A mutex semaphore is considered free when

Event Free Resource Definition Mutex Semaphore - A mutex semaphore 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.

Event Free Resource Definition Counting Semaphore - A counting semaphore is considered free when

Event Free Resource Definition Counting Semaphore - A counting semaphore is considered free when its counts is 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.

Event Sending and Receiving Events can be sent from a resource to a task,

Event Sending and Receiving Events can be sent from a resource to a task, from an ISR to a task, or directly between two tasks. Waiting for Events A 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.

Watchdog Timers Vx. Works includes a watchdog-timer mechanism that allows any C function to

Watchdog Timers Vx. Works includes a watchdog-timer mechanism that allows any 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.

Watchdog Timers Calls

Watchdog Timers Calls

Watchdog Timers Example

Watchdog Timers Example

Event Register Routine

Event Register Routine

Interrupt Service Routine

Interrupt Service Routine

int. Connect Routine

int. Connect Routine

Appendix: Shell Run a shell Variables in shell C commands in shell: printf Shell

Appendix: Shell Run a shell Variables in shell C commands in shell: printf Shell commands: i, ti, w, tw,

Run a shell

Run a shell

Variables in shell

Variables in shell

C commands in shell

C commands in shell

Shell commands : i

Shell commands : i

Shell Commands : td

Shell Commands : td

Shell Commands : ts & tr

Shell Commands : ts & tr

Shell Commands : ti

Shell Commands : ti

Shell Commands : w

Shell Commands : w

Shell Commands : tw

Shell Commands : tw

Shell Commands : check. Stack

Shell Commands : check. Stack

Shell Commands : d

Shell Commands : d

Shell Commands : d

Shell Commands : d

Shell Commands : d

Shell Commands : d

Shell Commands : ls

Shell Commands : ls

Shell Commands : pwd & cd

Shell Commands : pwd & cd

Shell Commands : h

Shell Commands : h

Shell Commands : reboot

Shell Commands : reboot

Shell Commands : semaphore

Shell Commands : semaphore

Shell Commands : semaphore

Shell Commands : semaphore

Shell Commands : semaphore

Shell Commands : semaphore

Shell Commands : semaphore

Shell Commands : semaphore

Shell Commands : semaphore

Shell Commands : semaphore

Shell Commands : Message Queue

Shell Commands : Message Queue

Shell Commands : Message Queue

Shell Commands : Message Queue

Shell Commands : Message Queue

Shell Commands : Message Queue

Shell Commands : Message Queue

Shell Commands : Message Queue

Shell Commands : Message Queue

Shell Commands : Message Queue

Shell Commands : Message Queue

Shell Commands : Message Queue