diff --git a/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/Makefile b/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/Makefile index f29bc48c..71fae43f 100644 --- a/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/Makefile +++ b/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/Makefile @@ -125,7 +125,7 @@ ifeq ($(MINIMAL_DEMO), 1) CFLAGS := -DmainCREATE_MINIMAL_DEMO=1 else ifdef GEN_DEMO - SOURCE_FILES += gen_$(GEN_DEMO).c + SOURCE_FILES += main_gen_$(GEN_DEMO).c CFLAGS := -DmainCREATE_GEN_DEMO=1 else diff --git a/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/gen_3.c b/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/main_gen_3.c similarity index 80% rename from FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/gen_3.c rename to FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/main_gen_3.c index bbc55e25..8c66e988 100644 --- a/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/gen_3.c +++ b/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/main_gen_3.c @@ -26,18 +26,19 @@ target utilization ~95% // Task priorities #define low_TASK_PRIO ( tskIDLE_PRIORITY + 1 ) -#define feeder_TASK_PRIO ( tskIDLE_PRIORITY + 2 ) -#define machine_1_TASK_PRIO ( tskIDLE_PRIORITY + 2 ) -#define machine_2_TASK_PRIO ( tskIDLE_PRIORITY + 3 ) -#define quality_control_TASK_PRIO ( tskIDLE_PRIORITY + 5 ) -#define supervisor_TASK_PRIO ( tskIDLE_PRIORITY + 6 ) -#define conveyor_belt_TASK_PRIO ( tskIDLE_PRIORITY + 7 ) -#define inventory_control_TASK_PRIO ( tskIDLE_PRIORITY + 8 ) -#define maintenance_TASK_PRIO ( tskIDLE_PRIORITY + 9 ) -#define user_interface_TASK_PRIO ( tskIDLE_PRIORITY + 10 ) -#define system_monitor_TASK_PRIO ( tskIDLE_PRIORITY + 11 ) +#define feeder_TASK_PRIO ( tskIDLE_PRIORITY + 5 ) +#define machine_1_TASK_PRIO ( tskIDLE_PRIORITY + 6 ) +#define machine_2_TASK_PRIO ( tskIDLE_PRIORITY + 7 ) +#define quality_control_TASK_PRIO ( tskIDLE_PRIORITY + 4 ) +#define supervisor_TASK_PRIO ( tskIDLE_PRIORITY + 3 ) +#define conveyor_belt_TASK_PRIO ( tskIDLE_PRIORITY + 8 ) +#define inventory_control_TASK_PRIO ( tskIDLE_PRIORITY + 12 ) +#define maintenance_TASK_PRIO ( tskIDLE_PRIORITY + 2 ) +#define user_interface_TASK_PRIO ( tskIDLE_PRIORITY + 11 ) +#define system_monitor_TASK_PRIO ( tskIDLE_PRIORITY + 10 ) // Task handles +TaskHandle_t low_task_handle = NULL; TaskHandle_t feeder_task_handle = NULL; TaskHandle_t machine_1_task_handle = NULL; TaskHandle_t machine_2_task_handle = NULL; @@ -67,16 +68,19 @@ __attribute__((noinline)) static void trigger_Qemu_break( void ) // Input Stuff volatile unsigned int FUZZ_INPUT[2048] = {0xa,0xb,0xc,0xd}; -volatile uint32_t FUZZ_LENGTH = 4; +volatile uint32_t FUZZ_LENGTH = 64; volatile uint32_t FUZZ_POINTER = 0; // Read the Byte of Input, if the Input is exausted trigger the breakpoint instead static unsigned int fuzz_int_next(void) { // printf("Get next Input from %lx \n",FUZZ_INPUT); - if (FUZZ_POINTER < FUZZ_LENGTH) { - FUZZ_POINTER++; - return FUZZ_INPUT[FUZZ_POINTER-1]; + if (FUZZ_POINTER < 2048) { + uint32_t temp = __atomic_add_fetch(&FUZZ_POINTER,(uint32_t)1,__ATOMIC_SEQ_CST); + // FUZZ_POINTER++; + // return FUZZ_INPUT[FUZZ_POINTER-1]; + return ((unsigned int*)FUZZ_INPUT)[temp-1]; } else { // Exausted inputs early + puts("Exhausted"); trigger_Qemu_break(); } } @@ -85,22 +89,32 @@ static unsigned int fuzz_int_next(void) { int collatz(int i) { int in = i; int steps = 0; - while (in != 1) { - if (i & 1) {i=i*3+1;} - else {i>=1;} + while (in > 1) { + if (in % 2 == 1) {in=in*3+1;} + else {in=in/2;} steps++; } return steps; } +void low_task(void *params) { + TickType_t xLastWakeTime = xTaskGetTickCount(); + while (1) { + WASTE_MSEC(10) + trigger_Qemu_break(); + vTaskDelayUntil(&xLastWakeTime, pdMS_TO_TICKS(250)); + } +} + void feeder_task(void *params) { TickType_t xLastWakeTime = xTaskGetTickCount(); while (1) { + puts("feeder_task"); // Perform some work here, such as adding materials to the conveyor belt - int input = fuzz_int_next() & 0xFFFFFF; + int input = fuzz_int_next() & 0xFFFF; int steps = collatz(input); - WASTE_USEC(steps*21); // 701*21 ~= 15ms + WASTE_USEC(steps*5+10000); // 701*21 ~= 15ms // Put something on the conveyor belt xTaskNotify(machine_1_task_handle, steps, eSetValueWithOverwrite); @@ -150,12 +164,13 @@ int small_increase_slow(int value) { void machine_1_task(void *params) { TickType_t xLastWakeTime = xTaskGetTickCount(); while (1) { + puts("machine_1_task"); // Perform some work here, such as processing materials from the conveyor belt int val = ulTaskNotifyTake(pdTRUE,portMAX_DELAY); // max 701 fill_field_rng(val); int swaps = bubbleSort(SORT_FIELD, val); // max swaps ~= 701 * 701/2 = 245700 - WASTE_TIME(swaps*100); // ~ up to 25ms + WASTE_TIME(CLAMP(swaps*500, 10*1000000, 25*100000)); // ~ up to 25ms // Signal completion using a binary semaphore xSemaphoreGive(machine_1_completion_sem); @@ -180,22 +195,24 @@ uint32_t popcount(uint32_t x) { uint32_t count = 0; while (x != 0) { count += (x & 1); - x >>= 1; + x = x >> 1; } return count; } int complex_function(int input1) { + short in1 = input1 && 0xFF; + short in2 = ((input1 >> 16)&0xFF); int result = 0; - for (int i = 0; i < input1; i++) { + for (int i = 0; i < in1; i+=2) { if (i % 2 == 0) { - for (int j = 0; j < i*5; j++) { + for (int j = 0; j < in2; j+=3) { if (j % 3 == 0) { - for (int k = 0; k < 2*j; k++) { + for (int k = 0; k < 2*j; k+=5) { if (k % 5 == 0) { int r = RNG_FROM(i ^ j ^ k ); if ((popcount(r)) > 16) { - result += r; + result += r & 0xFFFF; } } } @@ -210,12 +227,16 @@ static int m2_out = 0; void machine_2_task(void *params) { TickType_t xLastWakeTime = xTaskGetTickCount(); while (1) { + puts("machine_2_task"); // Perform some work here, such as processing materials from machine_1_task int input = fuzz_int_next(); int out = complex_function(input); + // WASTE_TIME(input); + // out = input; - out = collatz(out & 0xFFFFFF); - WASTE_USEC(out*100); + out = collatz(out & 0xFFFF); + // out = 1; + // WASTE_USEC(out*100); m2_out = out; // Signal completion using a binary semaphore @@ -238,6 +259,7 @@ void machine_2_task(void *params) { void quality_control_task(void *params) { TickType_t xLastWakeTime = xTaskGetTickCount(); while (1) { + puts("quality_control_task"); // Perform some work here, such as checking the quality of materials from machine_2_task int waited = xSemaphoreTake(machine_2_completion_sem, 3); if (waited == pdFALSE) { @@ -259,6 +281,7 @@ void quality_control_task(void *params) { void supervisor_task(void *params) { TickType_t xLastWakeTime = xTaskGetTickCount(); while (1) { + puts("supervisor_task"); // Perform some work here, such as monitoring the status of all machines // Wait for notifications from other tasks @@ -279,6 +302,7 @@ void supervisor_task(void *params) { void conveyor_belt_task(void *params) { TickType_t xLastWakeTime = xTaskGetTickCount(); while (1) { + puts("conveyor_belt_task"); // Perform some work here, such as controlling the movement of materials through the assembly line // Wait for signals from other tasks using binary semaphores @@ -296,12 +320,16 @@ void conveyor_belt_task(void *params) { void inventory_control_task(void *params) { TickType_t xLastWakeTime = xTaskGetTickCount(); while (1) { + puts("inventory_control_task"); // Perform some work here, such as keeping track of inventory levels - if (1) { /* more materials needed */ + int input = fuzz_int_next(); + if (popcount(input) > 16) { /* more materials needed */ // Send a notification to the feeder task - WASTE_MSEC(10); + // WASTE_MSEC(popcount(input)/4); xTaskNotifyFromISR(feeder_task_handle, 0, eNoAction, NULL); + } else { + // WASTE_MSEC(popcount(input)/2); } // Wait for the next activation period @@ -312,6 +340,7 @@ void inventory_control_task(void *params) { void maintenance_task(void *params) { TickType_t xLastWakeTime = xTaskGetTickCount(); while (1) { + puts("maintenance_task"); // Perform some work here, such as performing periodic maintenance operations on the machines WASTE_MSEC(10); @@ -323,23 +352,25 @@ void maintenance_task(void *params) { void user_interface_task(void *params) { TickType_t xLastWakeTime = xTaskGetTickCount(); while (1) { + puts("user_interface_task"); // Perform some work here, such as providing a user interface for controlling the system and displaying status information // Wait for updates from other tasks using binary semaphores or task notifications // Update the UI with new data - WASTE_MSEC(5); + WASTE_MSEC(2); // Wait for the next activation period - vTaskDelayUntil(&xLastWakeTime, pdMS_TO_TICKS(100)); + vTaskDelayUntil(&xLastWakeTime, pdMS_TO_TICKS(50)); } } void system_monitor_task(void *params) { TickType_t xLastWakeTime = xTaskGetTickCount(); while (1) { + puts("system_monitor_task"); // Perform some work here, such as monitoring the health of the system and sending notifications if any issues are detected - WASTE_MSEC(10); + WASTE_MSEC(5); // Wait for the next activation period vTaskDelayUntil(&xLastWakeTime, pdMS_TO_TICKS(100)); @@ -353,6 +384,7 @@ void main_gen(void) { shared_resource_mutex = xSemaphoreCreateMutex(); // Create tasks + xTaskCreate(low_task, "low", configMINIMAL_STACK_SIZE, NULL, low_TASK_PRIO, &low_task_handle); xTaskCreate(feeder_task, "feeder", configMINIMAL_STACK_SIZE, NULL, feeder_TASK_PRIO, &feeder_task_handle); xTaskCreate(machine_1_task, "machine_1", configMINIMAL_STACK_SIZE, NULL, machine_1_TASK_PRIO, &machine_1_task_handle); xTaskCreate(machine_2_task, "machine_2", configMINIMAL_STACK_SIZE, NULL, machine_2_TASK_PRIO, &machine_2_task_handle);