Timing Requiriments: ELT048 - EOS
Timing Requiriments: ELT048 - EOS
Timing Requiriments: ELT048 - EOS
ELT048 – EOS
Review
Review
• Processes
Rescheduling
• Kernel
U
UNN II F
FEE II
microkernel(3);
//return code
#define SUCCESS 0
#define FAIL 1
#define REPEAT 2
//process struct
typedef struct {
ptrFunc func;
} process;
Process * pool[POOL_SIZE];
microkernel(3);
char kernelInit(void){
start = 0;
end = 0;
return SUCCESS;
}
char kernelAddProc(process * newProc){
//checking for free space
if ( ((end+1)%POOL_SIZE) != start){
pool[end] = newProc;
end = (end+1)%POOL_SIZE;
return SUCCESS;
}
return FAIL;
}
microkernel(3);
void kernelLoop(void){
for(;;){
//Do we have any process to execute?
if (start != end){
//check if there is need to reschedule
if (pool[start]->func() == REPEAT){
kernelAddProc(pool[start]);
}
//prepare to get the next process;
start = (start+1)%POOL_SIZE;
}
}
}
microkernel(3);
void main(void){
//declaring the processes
process p1 = {tst1};
process p2 = {tst2};
process p3 = {tst3};
kernelInit();
//Test if the process were added
if (kernelAddProc(&p1) == FAIL){
for(;;);}
if (kernelAddProc(&p2) == FAIL){
for(;;);}
if (kernelAddProc(&p3) == FAIL){
for(;;);}
kernelLoop();
}
Exercise
U
UNN II F
FEE II
Hands on!
Real time
Timing requirements
• In most embedded systems it is necessary to ensure
that some functions are performed at a certain
frequency. Some systems may even fail if these
requirements are not met.
U
UNN II F
FEE II
Timing requirements
• Real time
Speed
Instantaneity
U
UNN II F
FEE II
Real time
• The ability of a system
to guarantee the
periodicity of a task
business2community.com
U
UNN II F
FEE II
Real time
• Determinism
• Periodicity
• Time Service
U
UNN II F
FEE II
Real time
• Hard real time • Soft real time
A failure / delay in An eventual failure /
meeting the temporal delay in meeting the
requirements will temporal requirements
CAUSE problems does not cause problems
Power-electronic driver Delay in receiving data
(zero-crossing) packets for video
transmission
U
UNN II F
FEE II
Timing requirements
• To implement a system that works with time
requirements:
1. There must be a clock that works with a precise
frequency.
2. The kernel must be informed of the frequency, or
period, of execution of each process.
3. The sum of the times of each process must "fit" in the
available time of the processor.
U
UNN II F
FEE II
Timing requirements
• 1st condition:
A timer that can generate an interrupt.
• 2nd condition:
Add the information in the process structure
• 3rd condition:
Test, test and test.
In case of failure:
• Faster Chip
• Optimization
U
UNN II F
FEE II
Scheduling
• The use of a finite timer to measure time can cause
overflow
• Example: scheduling 2 processes for 10 and 50
seconds (1 bit = 1ms)
U
UNN II F
FEE II
Scheduling
• What if the two processes are scheduled for the
same time?
U
UNN II F
FEE II
Scheduling
• Assuming the first process was executed:
From the time diagram below the process P2 is delayed
10(s) or has been scheduled to happen 55(s) from now?
U
UNN II F
FEE II
Scheduling
• Solution:
Use a decreasing timed counter for each process instead
of a scheduling value.
• Problem:
Each of the counters must be decremented in the
interrupt routine.
Is that really a problem for your application?
Collateral advantages: ability to verify "backward
processes"
U
UNN II F
FEE II
Kernel with timing requirements
• The first modification is in the process definition.
• You should add:
One counter for each process
A variable to store the execution period
//process struct
typedef struct {
ptrFunc function;
int period;
int start;
} process;
U
UNN II F
FEE II
Kernel with timing requirements
• An interrupt function must be created to decrement
each of the process counters
• The intrinsic details of the process of creating and
handling interrupts are beyond the scope of this
lesson.
U
UNN II F
FEE II
Interrupt function
KernelClock();
//limpa a flag
BitClr(INTCON,2);
}
}
Interrupt function
//add at kernel.h
void KernelClock(void);
Kernel with timing requirements
• The process addition function must initialize
variables correctly
U
UNN II F
FEE II
if (start != end){
//Find the process with the lowest timer
next = start;
j = (start+1) % POOLSIZE;
while(j!=end){
if (pool[j]->start < pool[next]->start){
next = j;
}
j = (j+1)%POOLSIZE;
}
//Exchanging processes positions
tempProc = pool[next];
pool[next] = pool[start];
pool[start] = tempProc;
//waiting for the process to be ready
while(pool[start]->start > 0){
//Great place for energy saving
}
if (pool[start]->func() == REPEAT ){
kernelAddProc(pool[start]);
}
start = (start+1)%POOLSIZE;
}
Exercise
• Building a clock
One process updates the seven segments display (ssd)
One process makes the counting and change the digits
value
• Update the last class kernel
Interrupt
KernelAddProc()
KernelClock()
KernelLoop()
U
UNN II F
FEE II