finis week 1.6
This commit is contained in:
@@ -16,3 +16,5 @@ auther:
|
||||

|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
@@ -24,20 +24,20 @@ There already is an counter in the task struct. but no function that decrements
|
||||
```c
|
||||
void decrement_sleeping_delay()
|
||||
{
|
||||
for (usize_t i=0; i < MAX_TASKS; i++)
|
||||
{
|
||||
if (taskList[i].state == SLEEPING_DELAY)
|
||||
{
|
||||
if (taskList[i].counter == 0)
|
||||
{
|
||||
taskList[i].state = READY;
|
||||
}
|
||||
else
|
||||
{
|
||||
taskList[i].counter--;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (usize_t i=0; i < MAX_TASKS; i++)
|
||||
{
|
||||
if (taskList[i].state == SLEEPING_DELAY)
|
||||
{
|
||||
if (taskList[i].counter == 0)
|
||||
{
|
||||
taskList[i].state = READY;
|
||||
}
|
||||
else
|
||||
{
|
||||
taskList[i].counter--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
@@ -48,13 +48,13 @@ The `SysTick_Handeler` now look like the following
|
||||
```c
|
||||
void SysTick_Handler(void)
|
||||
{
|
||||
SysTick_flag = true;
|
||||
//decrement counter for task in SLEEPING_DELAY
|
||||
decrement_sleeping_delay();
|
||||
//select the next task
|
||||
taskToExecute = schedule();
|
||||
//request context switch
|
||||
SCB->ICSR |= (1<<28);
|
||||
SysTick_flag = true;
|
||||
//decrement counter for task in SLEEPING_DELAY
|
||||
decrement_sleeping_delay();
|
||||
//select the next task
|
||||
taskToExecute = schedule();
|
||||
//request context switch
|
||||
SCB->ICSR |= (1<<28);
|
||||
}
|
||||
```
|
||||
|
||||
@@ -65,9 +65,9 @@ As last the delay function itself.
|
||||
```c
|
||||
void delay(uint32_t ticks)
|
||||
{
|
||||
currentTask->state = SLEEPING_DELAY;
|
||||
currentTask->counter = ticks;
|
||||
taskYield();
|
||||
currentTask->state = SLEEPING_DELAY;
|
||||
currentTask->counter = ticks;
|
||||
taskYield();
|
||||
}
|
||||
```
|
||||
|
||||
@@ -84,12 +84,12 @@ This implementation works, only the delays are a bit off. To make it a nice coun
|
||||
```c
|
||||
void blocking_delay(unsigned int ticks)
|
||||
{
|
||||
while (ticks != 0) {
|
||||
extern bool SysTick_flag;
|
||||
while (SysTick_flag == false); // busy wait
|
||||
SysTick_flag = false;
|
||||
ticks--;
|
||||
}
|
||||
while (ticks != 0) {
|
||||
extern bool SysTick_flag;
|
||||
while (SysTick_flag == false); // busy wait
|
||||
SysTick_flag = false;
|
||||
ticks--;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
@@ -104,9 +104,9 @@ void toggleBlue(void)
|
||||
{
|
||||
while(1)
|
||||
{
|
||||
GPIOD->ODR ^= 1 << BLUE;
|
||||
delay(800-1);
|
||||
SysTick->LOAD = 2 * CLOCK_FREQ_IN_KHz - 1;
|
||||
GPIOD->ODR ^= 1 << BLUE;
|
||||
delay(800-1);
|
||||
SysTick->LOAD = 2 * CLOCK_FREQ_IN_KHz - 1;
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -123,10 +123,10 @@ The control register is a special register to it need to be set and read with sp
|
||||
.global toUnprivileged
|
||||
|
||||
toUnprivileged:
|
||||
mrs R0, CONTROL // copy control register to R0
|
||||
ORR R0, R0, #1 // clear bit 0 (nPRIV)
|
||||
msr CONTROL, R0 // copy R0 to control register
|
||||
bx lr
|
||||
mrs R0, CONTROL // copy control register to R0
|
||||
ORR R0, R0, #1 // clear bit 0 (nPRIV)
|
||||
msr CONTROL, R0 // copy R0 to control register
|
||||
bx lr
|
||||
```
|
||||
|
||||
And called this function in the `PendSV_Handeler`
|
||||
@@ -137,22 +137,22 @@ void toUnprivileged(void);
|
||||
__attribute__((naked)) // No function entry and exit code
|
||||
void PendSV_Handler(void)
|
||||
{
|
||||
//Push {R4-R11} context to PSP
|
||||
pushRegistersToCurrentPSP();
|
||||
//Save the new stack pointer after the push
|
||||
currentTask->stack = readPSP();
|
||||
//Push {R4-R11} context to PSP
|
||||
pushRegistersToCurrentPSP();
|
||||
//Save the new stack pointer after the push
|
||||
currentTask->stack = readPSP();
|
||||
|
||||
currentTask = taskToExecute;
|
||||
currentTask = taskToExecute;
|
||||
|
||||
//Load the new stack pointer from (new) currentTask
|
||||
writePSP(currentTask->stack);
|
||||
//Load the new stack pointer from (new) currentTask
|
||||
writePSP(currentTask->stack);
|
||||
|
||||
//Pop {R4-R11} context from PSP
|
||||
popRegistersFromCurrentPSP();
|
||||
//Pop {R4-R11} context from PSP
|
||||
popRegistersFromCurrentPSP();
|
||||
|
||||
toUnprivileged(); // <--- this line was added
|
||||
toUnprivileged(); // <--- this line was added
|
||||
|
||||
returnToPSP();
|
||||
returnToPSP();
|
||||
}
|
||||
```
|
||||
|
||||
@@ -192,11 +192,11 @@ void toggleBlue(void)
|
||||
while(1)
|
||||
{
|
||||
GPIOD->ODR ^= 1 << BLUE;
|
||||
delay(800-1);
|
||||
setSysTick_10ms();
|
||||
GPIOD->ODR ^= 1 << BLUE;
|
||||
delay(800-1);
|
||||
setSysTick_1ms();
|
||||
delay(800-1);
|
||||
setSysTick_10ms();
|
||||
GPIOD->ODR ^= 1 << BLUE;
|
||||
delay(800-1);
|
||||
setSysTick_1ms();
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -235,34 +235,34 @@ In the memory map I found a littleendien encoded address witch was very close to
|
||||
```c
|
||||
void SVC_Handler(void)
|
||||
{
|
||||
uint32_t* sp = readPSP();
|
||||
// get PC location
|
||||
sp = sp + 6;
|
||||
// get PC
|
||||
uint16_t* pc = (uint16_t*)*sp;
|
||||
// get SVC intruction
|
||||
uint16_t instruction = *(pc - 1);
|
||||
if ((instruction & 0xFF00) != 0xDF00) {
|
||||
return;
|
||||
}
|
||||
uint32_t* sp = readPSP();
|
||||
// get PC location
|
||||
sp = sp + 6;
|
||||
// get PC
|
||||
uint16_t* pc = (uint16_t*)*sp;
|
||||
// get SVC intruction
|
||||
uint16_t instruction = *(pc - 1);
|
||||
if ((instruction & 0xFF00) != 0xDF00) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t svc_id = instruction & 0x00FF;
|
||||
uint8_t svc_id = instruction & 0x00FF;
|
||||
|
||||
switch (svc_id)
|
||||
{
|
||||
case 1: // taskYield
|
||||
taskToExecute = schedule();
|
||||
SCB->ICSR |= (1<<28);
|
||||
break;
|
||||
switch (svc_id)
|
||||
{
|
||||
case 1: // taskYield
|
||||
taskToExecute = schedule();
|
||||
SCB->ICSR |= (1<<28);
|
||||
break;
|
||||
|
||||
case 2: // setSysTick_10ms
|
||||
SysTick->LOAD = 10 * CLOCK_FREQ_IN_KHz - 1;
|
||||
break;
|
||||
case 2: // setSysTick_10ms
|
||||
SysTick->LOAD = 10 * CLOCK_FREQ_IN_KHz - 1;
|
||||
break;
|
||||
|
||||
case 3: // setSysTick_1ms
|
||||
SysTick->LOAD = 1 * CLOCK_FREQ_IN_KHz - 1;
|
||||
break;
|
||||
}
|
||||
case 3: // setSysTick_1ms
|
||||
SysTick->LOAD = 1 * CLOCK_FREQ_IN_KHz - 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
@@ -347,49 +347,49 @@ I added a new pointer `nextTaskPtr` to store the highest priority task that is r
|
||||
```c
|
||||
task * schedule()
|
||||
{
|
||||
task* nextTaskPtr = NULL;
|
||||
task* tempTaskPtr = currentTask;
|
||||
task* idleTaskPtr = &taskList[IDLE_TASK];
|
||||
task* nextTaskPtr = NULL;
|
||||
task* tempTaskPtr = currentTask;
|
||||
task* idleTaskPtr = &taskList[IDLE_TASK];
|
||||
|
||||
int teller=0;
|
||||
int teller=0;
|
||||
|
||||
do
|
||||
{
|
||||
tempTaskPtr++;
|
||||
do
|
||||
{
|
||||
tempTaskPtr++;
|
||||
|
||||
if( (tempTaskPtr-1) == idleTaskPtr || tempTaskPtr == idleTaskPtr)
|
||||
{
|
||||
//since idle task is the last in the list, we've reached the end
|
||||
//and need to continue at the beginning
|
||||
tempTaskPtr = &taskList[0];
|
||||
}
|
||||
if( (tempTaskPtr-1) == idleTaskPtr || tempTaskPtr == idleTaskPtr)
|
||||
{
|
||||
//since idle task is the last in the list, we've reached the end
|
||||
//and need to continue at the beginning
|
||||
tempTaskPtr = &taskList[0];
|
||||
}
|
||||
|
||||
if (tempTaskPtr->state != READY)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (tempTaskPtr->state != READY)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (nextTaskPtr == NULL)
|
||||
{
|
||||
nextTaskPtr = tempTaskPtr;
|
||||
continue;
|
||||
}
|
||||
if (nextTaskPtr == NULL)
|
||||
{
|
||||
nextTaskPtr = tempTaskPtr;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (tempTaskPtr->priority < nextTaskPtr->priority)
|
||||
{
|
||||
nextTaskPtr = tempTaskPtr;
|
||||
continue;
|
||||
}
|
||||
} while (teller++ < MAX_TASKS);
|
||||
if (tempTaskPtr->priority < nextTaskPtr->priority)
|
||||
{
|
||||
nextTaskPtr = tempTaskPtr;
|
||||
continue;
|
||||
}
|
||||
} while (teller++ < MAX_TASKS);
|
||||
|
||||
//if no task was found
|
||||
if(nextTaskPtr == NULL)
|
||||
{
|
||||
//idle task
|
||||
nextTaskPtr = idleTaskPtr;
|
||||
}
|
||||
//if no task was found
|
||||
if(nextTaskPtr == NULL)
|
||||
{
|
||||
//idle task
|
||||
nextTaskPtr = idleTaskPtr;
|
||||
}
|
||||
|
||||
return nextTaskPtr;
|
||||
return nextTaskPtr;
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
137
report-2/week_1.6.md
Normal file
137
report-2/week_1.6.md
Normal file
@@ -0,0 +1,137 @@
|
||||
|
||||
# Week 1.6
|
||||
|
||||
## Assginment 6.1
|
||||
|
||||
> A program consists of four tasks, $T_1$ through $T_4$. These tasks do not use shared resources. In the table, $i$ represents the task number, $T_i$ represents the period of task , and $C_i$ represents the maximum execution time of task $i$. The deadline of each task is equal to it's period.
|
||||
>
|
||||
> | i | $T_i$ | $C_i$ |
|
||||
> |---|---------|--------|
|
||||
> | 1 | $100ms$ | $50ms$ |
|
||||
> | 2 | $280ms$ | $45ms$ |
|
||||
> | 3 | $200ms$ | $20ms$ |
|
||||
> | 4 | $300ms$ | $40ms$ |
|
||||
>
|
||||
> A) Determine the schedulability of these tasks using the "Utilization based schedulability test" Provide the necessary calculations and draw your conclusions.
|
||||
|
||||
$$
|
||||
U=\sum_{i=1}^N{\frac{C_i}{T_i}}\le N(2^{1/N}-1)
|
||||
$$
|
||||
|
||||
$$
|
||||
U=\frac{C_1}{T_1}+\frac{C_2}{T_2}+\frac{C_3}{T_3}+\frac{C_4}{T_4}\le 4\cdot(2^{1/4}-1)
|
||||
$$
|
||||
|
||||
$$
|
||||
U=\frac{0.05}{0.1}+\frac{0.045}{0.28}+\frac{0.02}{0.2}+\frac{0.04}{0.3}\le N(2^{1/4}-1)
|
||||
$$
|
||||
|
||||
$$
|
||||
U=0.894047619048\le0.756828460011=false
|
||||
$$
|
||||
|
||||
This equetion cannot say if all the deadline are possible to make in this case.
|
||||
|
||||
> B) Determine the priorities $P_i$ of the various tasks when using FPS-RMPA (Fixed-priority Preemptive Scheduling – Rate Monotonic Priority Assignment). The system has four different priorities (1 through 4), with 4 being the highest.
|
||||
|
||||
The task with the shortest deadline should get the highest priority. The deadline are equal to $T_i$, this result in the following priorities:
|
||||
|
||||
| i | $T_i$ | $C_i$ | $P_i$ |
|
||||
| --- | ------- | ------ | ----- |
|
||||
| 1 | $100ms$ | $50ms$ | 4 |
|
||||
| 2 | $280ms$ | $45ms$ | 2 |
|
||||
| 3 | $200ms$ | $20ms$ | 3 |
|
||||
| 4 | $300ms$ | $40ms$ | 1 |
|
||||
|
||||
> C) Calculate for all tasks whether the deadline will be met, and if the deadline is met, provide the response time $R_i$.
|
||||
|
||||
$$
|
||||
R_i=C_i+\sum_{j∈hp(i)}{\left\lceil \frac{R_i}{T_j} \right\rceil} C_j
|
||||
$$
|
||||
|
||||
$$
|
||||
R_1=C_1+\sum_{j∈hp(1)}{\left\lceil \frac{R_1}{T_j} \right\rceil} C_j=C_1=50ms
|
||||
$$
|
||||
|
||||
$$
|
||||
R_3=C_3+\sum_{j∈hp(3)}{\left\lceil \frac{R_3}{T_j} \right\rceil} C_j=C_3+\left\lceil \frac{R_3}{T_1} \right\rceil C_1
|
||||
$$
|
||||
$$
|
||||
\Rightarrow w_{3,1}=C_3+\left\lceil \frac{C_3}{T_1} \right\rceil C_1=0.02+\left\lceil \frac{0.02}{0.1} \right\rceil 0.05=0.07
|
||||
$$
|
||||
$$
|
||||
\rightarrow w_{3,2}=C_3+\left\lceil \frac{w_{3,1}}{T_1} \right\rceil C_1=0.02+\left\lceil \frac{0.02}{0.1} \right\rceil 0.05=0.07
|
||||
$$
|
||||
$$
|
||||
R_3=70ms
|
||||
$$
|
||||
$w_{3,2}$ is the same as $w_{3,1}$ so $R_3$ is equal to both. This is lower then $T_3$ ($200ms$) so this is still possible.
|
||||
|
||||
|
||||
$$
|
||||
R_2=C_2+\sum_{j∈hp(2)}{\left\lceil \frac{R_2}{T_j} \right\rceil C_j}=C_2+\left\lceil \frac{R_2}{T_1} \right\rceil C_1+\left\lceil \frac{R_2}{T_3} \right\rceil C_3
|
||||
$$
|
||||
$$
|
||||
\Rightarrow w_{2,1}=C_2+\left\lceil \frac{C_2}{T_1} \right\rceil C_1+\left\lceil \frac{C_2}{T_3} \right\rceil C_3=0.045+\left\lceil \frac{0.045}{0.1} \right\rceil 0.05+\left\lceil \frac{0.045}{0.2} \right\rceil 0.02=0.115
|
||||
$$
|
||||
$$
|
||||
\Rightarrow w_{2,2}=C_2+\left\lceil \frac{w_{2,1}}{T_1} \right\rceil C_1+\left\lceil \frac{w_{2,1}}{T_3} \right\rceil C_3=0.045+\left\lceil \frac{0.115}{0.1} \right\rceil 0.05+\left\lceil \frac{0.115}{0.2} \right\rceil 0.02=0.165
|
||||
$$
|
||||
$$
|
||||
\Rightarrow w_{2,3}=C_2+\left\lceil \frac{w_{2,2}}{T_1} \right\rceil C_1+\left\lceil \frac{w_{2,2}}{T_3} \right\rceil C_3
|
||||
=0.045+\left\lceil \frac{0.165}{0.1} \right\rceil 0.05+\left\lceil \frac{0.165}{0.2} \right\rceil 0.02=0.165
|
||||
$$
|
||||
$$
|
||||
R_2=165ms
|
||||
$$
|
||||
|
||||
$w_{2,2}$ is the same as $w_{2,1}$ so $R_2$ is equal to both. This is lower then $T_2$ ($280ms$) so this is still possible.
|
||||
|
||||
$$
|
||||
R_4=C_4+\sum_{j∈hp(4)}{\left\lceil \frac{R_4}{T_j} \right\rceil C_j}=C_4+\left\lceil \frac{R_4}{T_1} \right\rceil C_1+\left\lceil \frac{R_4}{T_3} \right\rceil C_3+\left\lceil \frac{R_4}{T_2} \right\rceil C_2
|
||||
$$
|
||||
$$
|
||||
\Rightarrow w_{4,1}=
|
||||
C_4+\left\lceil \frac{C_4}{T_1} \right\rceil C_1
|
||||
+\left\lceil \frac{C_4}{T_3} \right\rceil C_3
|
||||
+\left\lceil \frac{C_4}{T_2} \right\rceil C_2
|
||||
=0.04+\left\lceil \frac{0.04}{0.1} \right\rceil 0.05
|
||||
+\left\lceil \frac{0.04}{0.2} \right\rceil 0.02
|
||||
+\left\lceil \frac{0.04}{0.28} \right\rceil 0.045
|
||||
=0.155
|
||||
$$
|
||||
$$
|
||||
\Rightarrow w_{4,2}=
|
||||
C_4+\left\lceil \frac{w_{4,1}}{T_1} \right\rceil C_1
|
||||
+\left\lceil \frac{w_{4,1}}{T_3} \right\rceil C_3
|
||||
+\left\lceil \frac{w_{4,1}}{T_2} \right\rceil C_2
|
||||
=0.04+\left\lceil \frac{0.155}{0.1} \right\rceil 0.05
|
||||
+\left\lceil \frac{0.155}{0.2} \right\rceil 0.02
|
||||
+\left\lceil \frac{0.155}{0.28} \right\rceil 0.045
|
||||
=0.205
|
||||
$$
|
||||
$$
|
||||
\Rightarrow w_{4,3}=
|
||||
C_4+\left\lceil \frac{w_{4,2}}{T_1} \right\rceil C_1
|
||||
+\left\lceil \frac{w_{4,2}}{T_3} \right\rceil C_3
|
||||
+\left\lceil \frac{w_{4,2}}{T_2} \right\rceil C_2
|
||||
=0.04+\left\lceil \frac{0.205}{0.1} \right\rceil 0.05
|
||||
+\left\lceil \frac{0.205}{0.2} \right\rceil 0.02
|
||||
+\left\lceil \frac{0.205}{0.28} \right\rceil 0.045
|
||||
=0.275
|
||||
$$
|
||||
$$
|
||||
\Rightarrow w_{4,4}=
|
||||
C_4+\left\lceil \frac{w_{4,3}}{T_1} \right\rceil C_1
|
||||
+\left\lceil \frac{w_{4,3}}{T_3} \right\rceil C_3
|
||||
+\left\lceil \frac{w_{4,3}}{T_2} \right\rceil C_2
|
||||
=0.04+\left\lceil \frac{0.275}{0.1} \right\rceil 0.05
|
||||
+\left\lceil \frac{0.275}{0.2} \right\rceil 0.02
|
||||
+\left\lceil \frac{0.275}{0.28} \right\rceil 0.045
|
||||
=0.275
|
||||
$$
|
||||
$$
|
||||
R_4=275ms
|
||||
$$
|
||||
|
||||
$w_{4,3}$ is the same as $w_{4,4}$ so $R_4$ is equal to both. This is lower then $T_4$ ($300ms$) so FPS-RMPA will not miss any deadlines.
|
||||
Reference in New Issue
Block a user