From 6650ad2ad3d0689b8e0a11ff8565a4929e37af2e Mon Sep 17 00:00:00 2001 From: Alwin Berger Date: Fri, 3 Mar 2023 12:31:04 +0100 Subject: [PATCH] add micro_longint --- .../Demo/CORTEX_M3_MPS2_QEMU_GCC/Makefile | 6 + FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/main.c | 4 + .../main_micro_longint.c | 212 ++++++++++++++++++ 3 files changed, 222 insertions(+) create mode 100644 FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/main_micro_longint.c diff --git a/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/Makefile b/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/Makefile index 522a47a5..44598bc4 100644 --- a/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/Makefile +++ b/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/Makefile @@ -103,6 +103,11 @@ ifeq ($(INT_DEMO), 1) SOURCE_FILES += main_micro_int.c CFLAGS := -DmainCREATE_INT_DEMO=1 +else +ifeq ($(LONGINT_DEMO), 1) + SOURCE_FILES += main_micro_longint.c + + CFLAGS := -DmainCREATE_LONGINT_DEMO=1 else SOURCE_FILES += main_blinky.c @@ -117,6 +122,7 @@ endif endif endif endif +endif DEFINES := -DQEMU_SOC_MPS2 -DHEAP3 diff --git a/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/main.c b/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/main.c index cf74e0c3..5674d259 100644 --- a/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/main.c +++ b/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/main.c @@ -99,6 +99,10 @@ int main() { main_micro_int(); } + #elif ( mainCREATE_LONGINT_DEMO == 1 ) + { + main_micro_longint(); + } #else { diff --git a/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/main_micro_longint.c b/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/main_micro_longint.c new file mode 100644 index 00000000..987f48b1 --- /dev/null +++ b/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/main_micro_longint.c @@ -0,0 +1,212 @@ +/* + * FreeRTOS V202111.00 + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * https://www.FreeRTOS.org + * https://github.com/FreeRTOS + * + */ + +#include +#include +#include +#include +#include +#include "arbitrary_loads.c" +/* +Interrupt Demo without priority inheritance +Async | I +A | RxxP xxxVD +B | RxxxD +C RxxxPx xx xxxV xxxD +*/ +// #undef PRINT_TIME +// #define PRINT_TIME(X,Y) WASTE_TIME(X) +// #define WCET_CLAMP(X, LB, UB, LABEL) PRINT_TIME(UB,LABEL) +#define WCET_CLAMP(X, LB, UB, LABEL) PRINT_TIME(CLAMP(X,LB,UB),LABEL) + +__attribute__((noinline)) static void trigger_Qemu_break( void ) +{ + puts("Trigger"); +} + +// Begin Input Stuff +volatile unsigned char FUZZ_INPUT[4096] = {0xa,0xb,0xc,0xd,0xe,0xf}; +volatile uint32_t FUZZ_LENGTH = 32; +volatile uint32_t FUZZ_POINTER = 0; + +static unsigned char fuzz_char_next(void) { + // printf("Get next Input from %lx \n",FUZZ_INPUT); + if (FUZZ_POINTER < FUZZ_LENGTH) { + FUZZ_POINTER++; + // printf("Input no. %d %x\n",FUZZ_POINTER-1,FUZZ_INPUT[FUZZ_POINTER-1]); + return FUZZ_INPUT[FUZZ_POINTER-1]; + } else { + // puts("End of Input"); + // Exausted inputs early + trigger_Qemu_break(); + } +} +static uint16_t fuzz_short_next(void) { + unsigned char field[2]; + field[0]=fuzz_char_next(); + field[1]=fuzz_char_next(); + uint16_t* sf = (uint16_t*) field; + return *sf; +} +static uint32_t fuzz_long_next(void) { + unsigned char field[4]; + field[0]=fuzz_char_next(); + field[1]=fuzz_char_next(); + field[2]=fuzz_char_next(); + field[3]=fuzz_char_next(); + uint32_t* sf = (uint32_t*) field; + return *sf; +} +// End Input Stuff +static void prvTaskA( void * pvParameters ); +static void prvTaskB( void * pvParameters ); +static void prvTaskC( void * pvParameters ); +static void prvSpor( void * pvParameters ); + +#define mainREPLICA_SPOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 6 ) +#define mainREPLICA_A_TASK_PRIORITY ( tskIDLE_PRIORITY + 5 ) +#define mainREPLICA_B_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 ) +#define mainREPLICA_C_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 ) + +// Handles for direct messages +static TaskHandle_t xReplA = NULL; +static TaskHandle_t xReplB = NULL; +static TaskHandle_t xReplC = NULL; +static TaskHandle_t xSpor = NULL; + +static SemaphoreHandle_t xSemaphoreAC; + +void main_micro_longint( void ) +{ + xSemaphoreAC = xSemaphoreCreateBinary(); + xSemaphoreGive(xSemaphoreAC); + + if( xSemaphoreAC != NULL ) + { + /* Start the two tasks as described in the comments at the top of this + * file. */ + xTaskCreate( prvTaskA, /* The function that implements the task. */ + "TaskA", /* 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. */ + mainREPLICA_A_TASK_PRIORITY, /* The priority assigned to the task. */ + &xReplA ); /* The task handle is not required, so NULL is passed. */ + + xTaskCreate( prvTaskB, /* The function that implements the task. */ + "TaskB", /* 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. */ + mainREPLICA_B_TASK_PRIORITY, /* The priority assigned to the task. */ + &xReplB ); /* The task handle is not required, so NULL is passed. */ + + xTaskCreate( prvTaskC, /* The function that implements the task. */ + "TaskC", /* 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. */ + mainREPLICA_C_TASK_PRIORITY, /* The priority assigned to the task. */ + &xReplC ); /* The task handle is not required, so NULL is passed. */ + + xTaskCreate( prvSpor, /* 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. */ + mainREPLICA_SPOR_TASK_PRIORITY, /* The priority assigned to the task. */ + &xSpor ); /* The task handle is not required, so NULL is passed. */ + + /* Start the tasks and timer running. */ + vTaskStartScheduler(); + } + + /* If all is well, the scheduler will now be running, and the following + * line will never be reached. If the following line does execute, then + * there was insufficient FreeRTOS heap memory available for the Idle and/or + * timer tasks to be created. See the memory management section on the + * FreeRTOS web site for more details on the FreeRTOS heap + * http://www.freertos.org/a00111.html. */ + for( ; ; ) + { + } +} + +static void prvTaskA( void * pvParameters ) +{ + while (1) + { + ulTaskNotifyTake(pdTRUE, portMAX_DELAY); + uint32_t to_run = fuzz_long_next() % 1<<24; + WCET_CLAMP(to_run,0, 1<<24, "A ") + xTaskNotifyStateClear(NULL); + ulTaskNotifyValueClear(NULL, 0xffffffff); + ulTaskNotifyTake(pdTRUE,portMAX_DELAY); + } +} +static void prvTaskB( void * pvParameters ) +{ + while (1) + { + ulTaskNotifyTake(pdTRUE, portMAX_DELAY); + uint32_t to_run = fuzz_long_next() % 1<<26; + WCET_CLAMP(to_run,0, 1<<26, "B ") + xTaskNotifyStateClear(NULL); + ulTaskNotifyValueClear(NULL, 0xffffffff); + ulTaskNotifyTake(pdTRUE,portMAX_DELAY); + } +} +static void prvTaskC( void * pvParameters ) +{ + while (1) + { + ulTaskNotifyTake(pdTRUE, portMAX_DELAY); + uint32_t to_run = fuzz_long_next() % 1<<28; + WCET_CLAMP(to_run,0, 1<<28, "C ") + trigger_Qemu_break(); + } +} +static void prvSpor( void * pvParameters ) +{ + uint32_t x = fuzz_short_next(); + xTaskNotifyGive(xReplC); + while (1) + { + ulTaskNotifyTake(pdTRUE,portMAX_DELAY); + puts("Fire"); + if (CHANCE_1_IN_POWOF2(x, 2)) { + xTaskNotifyGive(xReplB); + } else { + xTaskNotifyGive(xReplA); + } + } + +} + +void isr_starter( void ) +{ + if (xSpor) { + vTaskNotifyGiveFromISR(xSpor, NULL); + } +} + +/*-----------------------------------------------------------*/