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!
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();
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.