Professional Documents
Culture Documents
Static Scheduling
Dynamic Scheduling
Static Scheduling
This involves analyzing the tasks statically and determining their timing properties. This
timing property can be used to create a fixed scheduling table, according to which tasks
will be dispatched for execution at run time. Thus the order of execution of the task is
fixed, and it is assumed that their execution time is also fixed.
Round-Robin Scheduling
Round Robin scheduling by Time Slicing is one of the ways to achieve static scheduling.
Round robin is one of the simplest and most widely used scheduling algorithms; in
which a small unit of time known as time slice is defined. Schedulers go around the
queue of ready-to-run processes and allocate a time slice to each such process.
Pre-Emptive Scheduling
Preemptive Priority based execution is when the processor is idle, the ready task with
highest priority is chosen for execution; at any time, the execution of a task can be
preempted if a task of higher priority becomes ready. Thus, at all times, the processor is
idle or executing the ready task with the highest priority.
Dynamic Scheduling
Another kind of scheduling mechanism is known as Dynamic Scheduling – In this case, a
real-time program requires a sequence of decisions to be taken during execution of the
assignment of resource to transactions. Here each decision must be taken without prior
knowledge of the needs of future tasks. Dynamic scheduling is not in the scope of this
article, so I am not discussing it in detail here. Perhaps we can discuss it in another
article.
Code Snippet
Let us take a example of a Master-Slave communication system. Master system is
connected to n number of slave systems over serial port (RS 485 network) in multi-drop
architecture. Figure 1 shows the typical configuration of this system. Here only one
system can talk at a time and others are in listen mode. The Master controls the
communication.
Main Routine
Collapse | Copy Code
void main(void)
{
/* Initialise all register of processor and the peripheral devices
*/
InitMain();
RegisterTask(CheckDataIntegrity);
..............
/* Link-list definition */
typedef struct TaskRecord
{
tEventHandler EventHandler;
struct TaskRecord *pNext;
}tTaskRecord;
if(mpTaskList == NULL)
{
/* Store the address of the first task in the task list */
mpTaskList = pNewTask;
}
else
{
/* Move to the last task in the list */
mpActiveTask = mpTaskList;
while(mpActiveTask->pNext != NULL)
{
mpActiveTask = mpActiveTask->pNext;
}
For this type of application, after initialization there should be an infinite loop for
continuous execution. The function EventManager() at the end of
the main which is nothing but a infinite loop always checks for active tasks or events.
If any event occurs, then it passes that event flag as an argument of the function which
is already added into the mpTaskList. So EventManager() function
calls MainEventHandler() function with eventIDas an
argument. MainEventHandler will check the eventId and do the necessary
action or execute the corresponding code. Here the event should be unique for each
event-handler function, i.e. two event-handler functions should not check the
same eventID.
Definition of EventManager Function
Collapse | Copy Code
void EventManager(void)
{
unsigned short AllEvents;
tTaskRecord pActiveTask
/* No return */
while(1)
{
/* Read application events */
AllEvents = mEventID;
Event can be generated from interrupt service routine or by checking the status of an
input pin in polling mode.SerialReceiveISR function generates an event after
receiving the complete packet. Since the variablemEventID is modified in the
interrupt service routine, it is recommended to disable interrupt while reading.
#pragma interrupt_level 0
void interrupt IService(void)
{
/* Receive bit is set when a byte is received */
if(Receivebit == 1)
{
SerialReceiveISR()
}
...........
/* code for other interrupt */
}
SerialReceiveISR Function
Collapse | Copy Code
When the flag is set, the EventManager will call all the registered functions with
the eventID as argument.
Now we can change the variable type to increase the number of flags. If you want to
generate multiple number of events, then use a structure rather than a single variable.