Add dummy controll flow demo

This commit is contained in:
Alwin Berger 2022-02-09 22:20:28 +01:00
parent c276778a1c
commit 24f2f09b7f
3 changed files with 147 additions and 1 deletions

View File

@ -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

View File

@ -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"

View File

@ -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 <FreeRTOS.h>
#include <task.h>
#include <queue.h>
#include <stdio.h>
__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<FUZZ_LENGTH; i++)
{
ulValueToSend = FUZZ_INPUT[i];
if (ulValueToSend > 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<ulReceivedValue; i++)
{
t+=i;
}
agg+=t;
// printf("recieved: %u, result: %u\n",ulReceivedValue,t);
}
}
/*-----------------------------------------------------------*/