Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Real Time OS using FreeRTOS and Visual Studio as simulator. I need help implemen

ID: 3870206 • Letter: R

Question


Real Time OS

using FreeRTOS and Visual Studio as simulator. I need help implementing the 3 periodic tasks and finding their arrival & response times.

thank you!

1. Task programming on FreeRTOS (http://www.freertos.org/) Use the examples in Chapter 3, Section 3.4 of the FreeRTOS manual Mastering the FreeRTOS Real Time Kernel") to create three periodic tasks. Assign different priority values to the tasks. Task 1 (highest priority) monitors a parking lot in the Discovery Park. It generates random coordinates (x,y) of a car and uses the Euclidean distance and period to calculate the speed of the car (output). If the speed is above 10 (to simulate 10 mph), a warning is generated. Task 2 (medium priority) simulates an occupancy monitoring system for B190. Each time (simulates one hour) a random value between 20 and 50, representing the number of students in B190, is generated. Task 2 calculates the accumulated sum, average, maximum and minimum number of students as output, and clears the statistics after every 24 readings (i.c., one day) e Task 3 (lowest priority) records the power and energy consumption of the Discovery Park. A power reading (random number between 10KW and 200KW) is sent to Task 3 every minute (simulated). Task 3 estimates the energy consumption by calculating Power Time. The total energy consumption in a month and spikes of power use (i.e, instant power reading 5 average power use) are outputted a.) Create the three periodic tasks. They generate random sensor readings in memory Simulate their execution and measure the average response time of each task. Also record the arrival times of jobs of the three tasks and check if there is any pattern b.) Task 1 reads random (x,y) coordinates from a file, while Task 2 and Task 3 sll generate random sensor readings in memory. Simulate their execution and measure the average response time of each task. Compare the results from a.) and b.)

Explanation / Answer

void vKeyHandlerTask( void *pvParameters )

{

/* Key handling is a continuous process and as such the task

is implemented using an infinite loop (as most tasks are). */

for( ;; )

{

[Suspend waiting for a key press]

[Process the key press]

}

}

void vControlTask( void *pvParameters )

{

for( ;; )

{

[Suspend waiting for 2ms since the start of the previous

cycle]

[Sample the input]

[Filter the sampled input]

[Perform control algorithm]

[Output result]

}

}

;void SIG_OUTPUT_COMPARE1A( void )

;{

; ---------------------------------------

; CODE GENERATED BY THE COMPILER TO SAVE

; THE REGISTERS THAT GET ALTERED BY THE

; APPLICATION CODE DURING THE ISR.

PUSH R1

PUSH R0

IN R0,0x3F

PUSH R0

CLR R1

PUSH R18

PUSH R19

PUSH R20

PUSH R21

PUSH R22

PUSH R23

PUSH R24

PUSH R25

PUSH R26

PUSH R27

PUSH R30

PUSH R31

; ---------------------------------------

; CODE GENERATED BY THE COMPILER FROM THE

; APPLICATION C CODE.

;vTaskIncrementTick();

CALL 0x0000029B ;Call subroutine

; ---------------------------------------

; CODE GENERATED BY THE COMPILER TO

; RESTORE THE REGISTERS PREVIOUSLY

; SAVED.

POP R31

POP R30

POP R27

POP R26

POP R25

POP R24

POP R23

POP R22

POP R21

POP R20

POP R19

POP R18

POP R0

OUT 0x3F,R0

POP R0

POP R1

RETI

;}

#define portSAVE_CONTEXT()

asm volatile (

"push r0 " (1)

"in r0, __SREG__ " (2)

"cli " (3)

"push r0 " (4)

"push r1 " (5)

"clr r1 " (6)

"push r2 " (7)

"push r3 "

"push r4 "

"push r5 "

:

:

:

"push r30 "

"push r31 "

"lds r26, pxCurrentTCB " (8)

"lds r27, pxCurrentTCB + 1 " (9)

"in r0, __SP_L__ " (10)

"st x+, r0 " (11)

"in r0, __SP_H__ " (12)

"st x+, r0 " (13)

);

#define portRESTORE_CONTEXT()

asm volatile (

"lds r26, pxCurrentTCB " (1)

"lds r27, pxCurrentTCB + 1 " (2)

"ld r28, x+ "

"out __SP_L__, r28 " (3)

"ld r29, x+ "

"out __SP_H__, r29 " (4)

"pop r31 "

"pop r30 "

:

:

:

"pop r1 "

"pop r0 " (5)

"out __SREG__, r0 " (6)

"pop r0 " (7)

);

#include "task.h"
#include "croutine.h"

#define PRIORITY_0 0
#define NUM_COROUTINES 8

void main( void )
{
int i;

for( i = 0; i < NUM_COROUTINES; i++ )
{
// This time i is passed in as the index.
xCoRoutineCreate( vFlashCoRoutine, PRIORITY_0, i );
}

// NOTE: Tasks can also be created here!

// Start the RTOS scheduler.
vTaskStartScheduler();
}
The co-routine function is also extended so each uses a different LED and flash rate.
const int iFlashRates[ NUM_COROUTINES ] = { 10, 20, 30, 40, 50, 60, 70, 80 };
const int iLEDToFlash[ NUM_COROUTINES ] = { 0, 1, 2, 3, 4, 5, 6, 7 }

void vFlashCoRoutine( CoRoutineHandle_t xHandle, UBaseType_t uxIndex )
{
// Co-routines must start with a call to crSTART().
crSTART( xHandle );

for( ;; )
{
// Delay for a fixed period. uxIndex is used to index into
// the iFlashRates. As each co-routine was created with
// a different index value each will delay for a different
// period.
crDELAY( xHandle, iFlashRate[ uxIndex ] );

// Flash an LED. Again uxIndex is used as an array index,
// this time to locate the LED that should be toggled.
vParTestToggleLED( iLEDToFlash[ uxIndex ] );
}

// Co-routines must end with a call to crEND().
crEND();
}