From 68319160265a5befbfdc145fe8d8d8cd928c2314 Mon Sep 17 00:00:00 2001 From: Alwin Berger Date: Tue, 9 Jan 2024 15:49:07 +0100 Subject: [PATCH] add trivial example --- .../Demo/CORTEX_M3_MPS2_QEMU_GCC/Makefile | 6 + FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/main.c | 4 + .../CORTEX_M3_MPS2_QEMU_GCC/main_minimal.c | 149 ++++++++++++++++++ 3 files changed, 159 insertions(+) create mode 100644 FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/main_minimal.c diff --git a/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/Makefile b/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/Makefile index d3068511..4c10201b 100644 --- a/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/Makefile +++ b/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/Makefile @@ -118,6 +118,11 @@ ifeq ($(LONGINT_DEMO), 1) SOURCE_FILES += main_micro_longint.c CFLAGS := -DmainCREATE_LONGINT_DEMO=1 +else +ifeq ($(MINIMAL_DEMO), 1) + SOURCE_FILES += main_minimal.c + + CFLAGS := -DmainCREATE_MINIMAL_DEMO=1 else SOURCE_FILES += main_blinky.c @@ -135,6 +140,7 @@ endif endif endif endif +endif ifeq ($(INTERRUPT_ACTIVATION), 1) CFLAGS += -D INTERRUPT_ACTIVATION=1 diff --git a/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/main.c b/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/main.c index 5674d259..d61dcc6a 100644 --- a/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/main.c +++ b/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/main.c @@ -103,6 +103,10 @@ int main() { main_micro_longint(); } + #elif ( mainCREATE_MINIMAL_DEMO == 1 ) + { + main_minimal(); + } #else { diff --git a/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/main_minimal.c b/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/main_minimal.c new file mode 100644 index 00000000..ad1433a6 --- /dev/null +++ b/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/main_minimal.c @@ -0,0 +1,149 @@ +#include +#include +#include +#include +/* +*/ + +#include "arbitrary_loads.c" + +__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; +// Read the Byte of Input, if the Input is exausted trigger the breakpoint instead +static unsigned char fuzz_input_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(); + } +} +// End Input Stuff +static void prvSamplerTask( void * pvParameters ); +static void prvThreadLow( void * pvParameters ); +static void prvThreadMid( void * pvParameters ); +static void prvThreadHigh( void * pvParameters ); + +#define mainLOW_PRIO ( tskIDLE_PRIORITY + 1 ) +#define mainMID_PRIO ( tskIDLE_PRIORITY + 2 ) +#define mainHIGH_PRIO ( tskIDLE_PRIORITY + 3 ) + +#define mainQUEUE_LENGTH ( 1 ) +#define mainQUEUE_SEND_FREQUENCY_MS ( 10 / portTICK_PERIOD_MS ) +#define voterMAXRETRIES 3 +#define WORK_SET_SIZE_POWER 1 +#define WORK_SET_SIZE 2 + +// Handles for direct messages +static TaskHandle_t xLow = NULL; +static TaskHandle_t xMid = NULL; +static TaskHandle_t xHigh = NULL; + + +#define DEBUG_PRINT(X) {puts(X);} +// #define DEBUG_PRINT(X) + + +void main_minimal( void ) +{ + xTaskCreate( prvThreadLow, /* The function that implements the task. */ + "Low", /* 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. */ + mainLOW_PRIO, /* The priority assigned to the task. */ + &xLow ); /* The task handle is not required, so NULL is passed. */ + + xTaskCreate( prvThreadMid, /* The function that implements the task. */ + "Mid", /* 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. */ + mainMID_PRIO, /* The priority assigned to the task. */ + &xMid ); /* The task handle is not required, so NULL is passed. */ + + xTaskCreate( prvThreadHigh, /* The function that implements the task. */ + "High", /* 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. */ + mainHIGH_PRIO, /* The priority assigned to the task. */ + &xHigh ); /* The task handle is not required, so NULL is passed. */ + + /* Start the tasks and timer running. */ + vTaskStartScheduler(); + + for( ; ; ) + { + } +} +volatile unsigned char WORK_SET[WORK_SET_SIZE] = {0}; +static int count_up(unsigned short cinput) +{ + int t = 0; + for (int i=1; i>WORK_SET_SIZE_POWER); +} + +static void prvThreadLow( void * pvParameters ) +{ + while (1) + { + WASTE_TIME(1000*1000000); // work for 1000 ms + trigger_Qemu_break(); + } +} +static void prvThreadMid( void * pvParameters ) +{ + TickType_t xLastWakeTime = xTaskGetTickCount(); + const TickType_t xFrequency = 300 / portTICK_PERIOD_MS; + while (1) + { + unsigned short value = FUZZ_INPUT[FUZZ_POINTER++]; + WASTE_TIME(1*1000000); // work for 1 ms + // if (value=='A') { + if ((value+100) % 11 == 3) { + DEBUG_PRINT("L-Path"); + WASTE_TIME(10*1000000); // work for 10 ms + xTaskNotify(xHigh, 1, eSetValueWithOverwrite); + } else { + DEBUG_PRINT("S-Path"); + WASTE_TIME(100*1000000); // work for 100 ms + } + WASTE_TIME(2*1000000); // work for 2 ms + vTaskDelayUntil( &xLastWakeTime, xFrequency );// Wait for the next cycle. + } +} +static void prvThreadHigh( void * pvParameters ) +{ + while (1) + { + ulTaskNotifyTake(pdTRUE,portMAX_DELAY); + WASTE_TIME(200*1000000); // work for 200 ms + } +} + +void isr_starter( void ) +{ +} + +/*-----------------------------------------------------------*/