From 24f2f09b7f8cc0ed3e37c489683e25d25f995b56 Mon Sep 17 00:00:00 2001 From: Alwin Berger Date: Wed, 9 Feb 2022 22:20:28 +0100 Subject: [PATCH] Add dummy controll flow demo --- .../Demo/CORTEX_M3_MPS2_QEMU_GCC/Makefile | 8 +- FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/main.c | 4 + .../Demo/CORTEX_M3_MPS2_QEMU_GCC/main_1char.c | 136 ++++++++++++++++++ 3 files changed, 147 insertions(+), 1 deletion(-) create mode 100644 FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/main_1char.c diff --git a/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/Makefile b/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/Makefile index d61b9172..c5b8744f 100644 --- a/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/Makefile +++ b/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/Makefile @@ -63,12 +63,18 @@ ifeq ($(INCREASING_DEMO), 1) SOURCE_FILES += main_increasing.c CFLAGS := -DmainCREATE_INCREASING_DEMO=1 +else +ifeq ($(1CHAR_DEMO), 1) + SOURCE_FILES += main_1char.c + + CFLAGS := -DmainCREATE_1CHAR_DEMO=1 else SOURCE_FILES += main_blinky.c CFLAGS := -DmainCREATE_SIMPLE_BLINKY_DEMO_ONLY=1 endif endif +endif DEFINES := -DQEMU_SOC_MPS2 -DHEAP3 @@ -81,7 +87,7 @@ CFLAGS += -Wno-builtin-declaration-mismatch -Werror ifeq ($(DEBUG), 1) CFLAGS += -ggdb3 -Og else - CFLAGS += -O3 + CFLAGS += -O0 endif CFLAGS += -fstrict-aliasing -Wstrict-aliasing -Wno-error=address-of-packed-member diff --git a/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/main.c b/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/main.c index b1acde9b..a29a645d 100644 --- a/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/main.c +++ b/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/main.c @@ -67,6 +67,10 @@ int main() { main_increasing(); } + #elif ( mainCREATE_1CHAR_DEMO == 1 ) + { + main_increasing(); + } #else { #error "Invalid Selection...\nPlease Select a Demo application from the main command" diff --git a/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/main_1char.c b/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/main_1char.c new file mode 100644 index 00000000..85e9a45d --- /dev/null +++ b/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/main_1char.c @@ -0,0 +1,136 @@ +/* + * 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 + +__attribute__((noinline)) static void trigger_Qemu_break( void ) +{ + puts("Trigger"); +} +static void prvQueueReceiveTask( void * pvParameters ); +static void prvQueueSendTask( void * pvParameters ); + +#define mainQUEUE_RECEIVE_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 ) +#define mainQUEUE_SEND_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 ) +#define mainQUEUE_LENGTH ( 1 ) +#define mainQUEUE_SEND_FREQUENCY_MS ( 10 / portTICK_PERIOD_MS ) +/* The queue used by both tasks. */ +static QueueHandle_t xQueue = NULL; +static volatile int i; + +int inc(void) { + i++; + return i; +} + +volatile unsigned char FUZZ_INPUT[4096] = {33}; +void main_increasing( void ) +{ + + + if ((FUZZ_INPUT[0] % 4) == 0) { + // puts("inc1 mod 4"); + inc(); + } + if (FUZZ_INPUT[0] >= 42) { + // puts("inc2 >= 42"); + inc(); + } + if (FUZZ_INPUT[0] <= 44) { + // puts("inc3 <= 44"); + inc(); + } + printf("Value of i: %d\n",i); + + trigger_Qemu_break(); + + + /* 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( ; ; ) + { + } +} + +volatile uint32_t FUZZ_LENGTH = 32; + +volatile unsigned char last_value = 32; // ascii space + +static void prvQueueSendTask( void * pvParameters ) +{ + unsigned char ulValueToSend = 0; + /* Remove compiler warning about unused parameter. */ + ( void ) pvParameters; + + for(int i=0; i last_value & ulValueToSend >= 33 & ulValueToSend < 127) + { + // printf("send: %c\n",ulValueToSend); + last_value = ulValueToSend; + xQueueSend( xQueue, &ulValueToSend, portMAX_DELAY ); + } + } + // since priority of this task is lower we only reach this after the Recieve Task is done. + trigger_Qemu_break(); +} + + +volatile uint32_t ulRxEvents = 0; +volatile uint32_t agg = 0; +static void prvQueueReceiveTask( void * pvParameters ) +{ + unsigned char ulReceivedValue = 0; + + /* Remove compiler warning about unused parameter. */ + ( void ) pvParameters; + + for( ; ; ) + { + /* Wait until something arrives in the queue - this task will block + * indefinitely provided INCLUDE_vTaskSuspend is set to 1 in + * FreeRTOSConfig.h. */ + xQueueReceive( xQueue, &ulReceivedValue, portMAX_DELAY ); + + //Some computation which depends on the value recieved + int t = 0; + for (int i=1; i