add bubblesort demo
This commit is contained in:
parent
24f2f09b7f
commit
f0728a8a5e
@ -68,6 +68,11 @@ ifeq ($(1CHAR_DEMO), 1)
|
|||||||
SOURCE_FILES += main_1char.c
|
SOURCE_FILES += main_1char.c
|
||||||
|
|
||||||
CFLAGS := -DmainCREATE_1CHAR_DEMO=1
|
CFLAGS := -DmainCREATE_1CHAR_DEMO=1
|
||||||
|
else
|
||||||
|
ifeq ($(BUBBLESORT_DEMO), 1)
|
||||||
|
SOURCE_FILES += main_bubblesort.c
|
||||||
|
|
||||||
|
CFLAGS := -DmainCREATE_BUBBLESORT_DEMO=1
|
||||||
else
|
else
|
||||||
SOURCE_FILES += main_blinky.c
|
SOURCE_FILES += main_blinky.c
|
||||||
|
|
||||||
@ -75,6 +80,7 @@ else
|
|||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
DEFINES := -DQEMU_SOC_MPS2 -DHEAP3
|
DEFINES := -DQEMU_SOC_MPS2 -DHEAP3
|
||||||
|
|
||||||
|
@ -69,7 +69,11 @@ int main()
|
|||||||
}
|
}
|
||||||
#elif ( mainCREATE_1CHAR_DEMO == 1 )
|
#elif ( mainCREATE_1CHAR_DEMO == 1 )
|
||||||
{
|
{
|
||||||
main_increasing();
|
main_1char();
|
||||||
|
}
|
||||||
|
#elif ( mainCREATE_BUBBLESORT_DEMO == 1 )
|
||||||
|
{
|
||||||
|
main_bubblesort();
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
{
|
{
|
||||||
|
@ -41,7 +41,6 @@ static void prvQueueSendTask( void * pvParameters );
|
|||||||
#define mainQUEUE_LENGTH ( 1 )
|
#define mainQUEUE_LENGTH ( 1 )
|
||||||
#define mainQUEUE_SEND_FREQUENCY_MS ( 10 / portTICK_PERIOD_MS )
|
#define mainQUEUE_SEND_FREQUENCY_MS ( 10 / portTICK_PERIOD_MS )
|
||||||
/* The queue used by both tasks. */
|
/* The queue used by both tasks. */
|
||||||
static QueueHandle_t xQueue = NULL;
|
|
||||||
static volatile int i;
|
static volatile int i;
|
||||||
|
|
||||||
int inc(void) {
|
int inc(void) {
|
||||||
@ -50,7 +49,8 @@ int inc(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
volatile unsigned char FUZZ_INPUT[4096] = {33};
|
volatile unsigned char FUZZ_INPUT[4096] = {33};
|
||||||
void main_increasing( void )
|
volatile uint32_t FUZZ_LENGTH = 32;
|
||||||
|
void main_1char( void )
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
@ -81,56 +81,4 @@ void main_increasing( void )
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
81
FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/main_bubblesort.c
Normal file
81
FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/main_bubblesort.c
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
* 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. */
|
||||||
|
volatile unsigned char FUZZ_INPUT[4096] = {33};
|
||||||
|
volatile uint32_t FUZZ_LENGTH = 32;
|
||||||
|
|
||||||
|
volatile int misses = 0;
|
||||||
|
void main_bubblesort( void )
|
||||||
|
{
|
||||||
|
printf("Input: %.*s\n",FUZZ_LENGTH,FUZZ_INPUT);
|
||||||
|
int tmp=0;
|
||||||
|
for (int i=0; i<FUZZ_LENGTH; i++)
|
||||||
|
{
|
||||||
|
for (int j=0; j<FUZZ_LENGTH-i-1;j++)
|
||||||
|
{
|
||||||
|
if (FUZZ_INPUT[j]>FUZZ_INPUT[j+1])
|
||||||
|
{
|
||||||
|
tmp=FUZZ_INPUT[j];
|
||||||
|
FUZZ_INPUT[j]=FUZZ_INPUT[j+1];
|
||||||
|
FUZZ_INPUT[j+1]=tmp;
|
||||||
|
} else {
|
||||||
|
misses++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf("Output: %.*s\n",FUZZ_LENGTH,FUZZ_INPUT);
|
||||||
|
|
||||||
|
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( ; ; )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*-----------------------------------------------------------*/
|
Loading…
x
Reference in New Issue
Block a user