From 47d86ca153f11e81e0da45d1e9e45fe456c0e77e Mon Sep 17 00:00:00 2001 From: Alwin Berger Date: Tue, 19 Apr 2022 23:44:08 +0200 Subject: [PATCH] add interrupts to demo --- .../CORTEX_M3_MPS2_QEMU_GCC/init/startup.c | 5 +++- .../Demo/CORTEX_M3_MPS2_QEMU_GCC/main_tmr.c | 30 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/init/startup.c b/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/init/startup.c index d856dba3..41a561fd 100644 --- a/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/init/startup.c +++ b/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/init/startup.c @@ -36,6 +36,7 @@ extern void xPortPendSVHandler( void ); extern void xPortSysTickHandler( void ); extern void uart_init(); extern int main(); +extern void isr_starter( void ); // main_tmr.c void __attribute__( ( weak ) ) EthernetISR( void ); @@ -176,7 +177,7 @@ const uint32_t * isr_vector[] __attribute__( ( section( ".isr_vector" ) ) ) = 0, /* reserved */ ( uint32_t * ) &xPortPendSVHandler, /* PendSV handler -2 */ ( uint32_t * ) &xPortSysTickHandler, /* SysTick_Handler -1 */ - 0, /* uart0 receive 0 */ + ( uint32_t * ) &isr_starter, /* uart0 receive 0 */ 0, /* uart0 transmit */ 0, /* uart1 receive */ 0, /* uart1 transmit */ @@ -195,6 +196,8 @@ const uint32_t * isr_vector[] __attribute__( ( section( ".isr_vector" ) ) ) = void _start( void ) { uart_init(); + NVIC_EnableIRQ(0); + NVIC_SetPriority (0, 6); // need to stay above configMAX_SYSCALL_INTERRUPT_PRIORITY main( 0, 0 ); exit( 0 ); } diff --git a/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/main_tmr.c b/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/main_tmr.c index 1882315a..13820383 100644 --- a/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/main_tmr.c +++ b/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/main_tmr.c @@ -70,12 +70,14 @@ static void prvReplicaA( void * pvParameters ); static void prvReplicaB( void * pvParameters ); static void prvReplicaC( void * pvParameters ); static void prvVoterTask( void * pvParameters ); +static void prvSporadicTask( void * pvParameters ); #define mainSAMPLER_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 ) #define mainVOTER_TASK_PRIORITY ( tskIDLE_PRIORITY + 5 ) #define mainREPLICA_A_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 ) #define mainREPLICA_B_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 ) #define mainREPLICA_C_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 ) +#define mainSPORADIC_TASK_PRIORITY ( tskIDLE_PRIORITY + 6 ) #define mainQUEUE_LENGTH ( 1 ) #define mainQUEUE_SEND_FREQUENCY_MS ( 10 / portTICK_PERIOD_MS ) #define voterMAXRETRIES 1 @@ -86,6 +88,7 @@ static void prvVoterTask( void * pvParameters ); static TaskHandle_t xReplA = NULL; static TaskHandle_t xReplB = NULL; static TaskHandle_t xReplC = NULL; +static TaskHandle_t xSporadic = NULL; /* The queue used by both tasks. */ static QueueHandle_t xQueueOutputA = NULL; static QueueHandle_t xQueueOutputB = NULL; @@ -141,6 +144,13 @@ void main_tmr( void ) mainVOTER_TASK_PRIORITY, NULL ); + xTaskCreate( prvSporadicTask, /* The function that implements the task. */ + "Spor", /* The text name assigned to the task - for debug only as it is not used by the kernel. */ + configMINIMAL_STACK_SIZE, /* The size of the stack to allocate to the task. */ + NULL, /* The parameter passed to the task - not used in this case. */ + mainSPORADIC_TASK_PRIORITY, /* The priority assigned to the task. */ + &xSporadic ); /* The task handle is not required, so NULL is passed. */ + /* Start the tasks and timer running. */ vTaskStartScheduler(); } @@ -250,5 +260,25 @@ static void prvVoterTask( void * pvParameters ) // Finisched one TMR Cycle trigger_Qemu_break(); } +static void prvSporadicTask( void * pvParameters ) +{ + int tmp = 1; + while (1) + { + ulTaskNotifyTake(pdTRUE,portMAX_DELAY); + for (int i=0; i<1000; i++) { + tmp *= i; + if (i > 2<<16) { + tmp = tmp >> 8; + } + } + } +} +void isr_starter( void ) +{ + if (xSporadic) { + vTaskNotifyGiveFromISR(xSporadic, NULL); + } +} /*-----------------------------------------------------------*/