INSERT_WC = worst case

This commit is contained in:
Alwin Berger 2025-02-27 17:01:11 +01:00
parent c42d3baa89
commit 59b2ca79cb
4 changed files with 133 additions and 71 deletions

View File

@ -158,15 +158,15 @@ int32_t valley(int32_t x, int32_t off, int32_t h, int32_t w) {
- JITTER(X, 1000)
#define TRANSLATE_1(LB,UB) TRANSLATE_BOUNDS(x, 180000, 1000000, LB, UB) // FN 1
#define TRANSLATE_2(LB,UB) TRANSLATE_BOUNDS(x, -500000, 390000, LB, UB) // FN 2
#define TRANSLATE_3(LB,UB) TRANSLATE_BOUNDS(x, -8000, 80000, LB, UB) // FN 3
#define TRANSLATE_4(LB,UB) TRANSLATE_BOUNDS(x, -480000, -250000, LB, UB) // FN 4
#define TRANSLATE_5(LB,UB) TRANSLATE_BOUNDS(x, -193000, -155000, LB, UB) // FN 5
#define TRANSLATE_6(LB,UB) TRANSLATE_BOUNDS(x, -400000000, 400000000, LB, UB) // FN 6
#define TRANSLATE_7(LB,UB) TRANSLATE_BOUNDS(x, -20000, 120000, LB, UB) // FN 7
#define TRANSLATE_8(LB,UB) TRANSLATE_BOUNDS(x, -20000000, 120000000, LB, UB) // FN 8
#define TRANSLATE_9(LB,UB) TRANSLATE_BOUNDS(x, -200000, 220000, LB, UB) // FN 9
#define TRANSLATE_10(LB,UB) TRANSLATE_BOUNDS(x, -10000, 150000, LB, UB) // FN 10
#define TRANSLATE_1(I, LB,UB) TRANSLATE_BOUNDS((I), 180000, 1000000, LB, UB) // FN 1
#define TRANSLATE_2(I, LB,UB) TRANSLATE_BOUNDS((I), -500000, 390000, LB, UB) // FN 2
#define TRANSLATE_3(I, LB,UB) TRANSLATE_BOUNDS((I), -8000, 80000, LB, UB) // FN 3
#define TRANSLATE_4(I, LB,UB) TRANSLATE_BOUNDS((I), -480000, -250000, LB, UB) // FN 4
#define TRANSLATE_5(I, LB,UB) TRANSLATE_BOUNDS((I), -193000, -155000, LB, UB) // FN 5
#define TRANSLATE_6(I, LB,UB) TRANSLATE_BOUNDS((I), -400000000, 400000000, LB, UB) // FN 6
#define TRANSLATE_7(I, LB,UB) TRANSLATE_BOUNDS((I), -20000, 120000, LB, UB) // FN 7
#define TRANSLATE_8(I, LB,UB) TRANSLATE_BOUNDS((I), -20000000, 120000000, LB, UB) // FN 8
#define TRANSLATE_9(I, LB,UB) TRANSLATE_BOUNDS((I), -200000, 220000, LB, UB) // FN 9
#define TRANSLATE_10(I, LB,UB) TRANSLATE_BOUNDS((I), -10000, 150000, LB, UB) // FN 10
#endif

View File

@ -15,9 +15,13 @@
// #endif
#ifdef INSERT_WC
#define WC_SWITCH(X,D) ((X)*0+(D))
#define WC_SWITCH(X,D) ((X)*0+(D)*1)
#else
#define WC_SWITCH(X,D) ((X)+(D)*0)
#ifdef IGNORE_BYTES
#define WC_SWITCH(X,D) ((X)*0+(D)*1)
#else
#define WC_SWITCH(X,D) ((X)*1+(D)*0)
#endif
#endif
// #define SHORT_CALC 50
@ -189,7 +193,7 @@ static void prv_SignalGatherInitiateTask(void *pvParameters) {
TickType_t xLastWakeTime = initial_release_time;
const TickType_t xFrequency = 3 / portTICK_PERIOD_MS;
uint16_t inp = 0;
int x=0;
volatile int x=0;
do {
RNG_RESET
// timing_start(0);
@ -197,7 +201,9 @@ static void prv_SignalGatherInitiateTask(void *pvParameters) {
inp = INPUT_SHORT_NEXT;
x = STRETCH_i32(inp);
x = FUNCTION_1(x);
WASTE_USEC(WC_SWITCH(TRANSLATE_1(50, 200), 200));
x = TRANSLATE_1(x, 50, 200);
x = WC_SWITCH(x, 200);
WASTE_USEC(x);
if ((round % 2) == 0) {
xTaskNotify(xTask_SignalGatherTimeoutTask, MAKE_OUTPUT, eSetValueWithOverwrite);
} else {
@ -207,12 +213,16 @@ static void prv_SignalGatherInitiateTask(void *pvParameters) {
inp = INPUT_SHORT_NEXT;
x = STRETCH_i32(inp);
x = FUNCTION_2(x);
WASTE_USEC(WC_SWITCH(TRANSLATE_2(50, 200), 200));
x = TRANSLATE_2(x, 50, 200);
x = WC_SWITCH(x, 200);
WASTE_USEC(x);
xSemaphoreGive(xSemaphore_SPIBus);
inp = INPUT_SHORT_NEXT;
x = STRETCH_i32(inp);
x = FUNCTION_3(x);
WASTE_USEC(WC_SWITCH(TRANSLATE_3(50, 200), 200));
x = TRANSLATE_3(x, 50, 200);
x = WC_SWITCH(x, 200);
WASTE_USEC(x);
trigger_job_done();
xTaskDelayUntil( &xLastWakeTime, xFrequency );
} while (1);
@ -221,7 +231,7 @@ static void prv_SignalGatherInitiateTask(void *pvParameters) {
static void prv_SignalGatherFinishedTask(void *pvParameters) {
const int task_id = 1;
uint16_t inp = 0;
int x=0;
volatile int x=0;
trigger_job_done();
do {
RNG_RESET
@ -230,17 +240,23 @@ static void prv_SignalGatherFinishedTask(void *pvParameters) {
inp = INPUT_SHORT_NEXT * CLAMP(y, 1, 3);
x = STRETCH_i32(inp);
x = FUNCTION_1(x);
WASTE_USEC(WC_SWITCH(TRANSLATE_1(50, 200), 200));
x = TRANSLATE_1(x, 50, 200);
x = WC_SWITCH(x, 200);
WASTE_USEC(x);
xTaskNotify(xTask_SignalProcessingAttitudeTask, MAKE_OUTPUT, eSetValueWithOverwrite);
inp = INPUT_SHORT_NEXT * CLAMP(y, 1, 3);
x = STRETCH_i32(inp);
x = FUNCTION_4(x);
WASTE_USEC(WC_SWITCH(TRANSLATE_4(50, 200), 200));
x = TRANSLATE_4(x, 50, 200);
x = WC_SWITCH(x, 200);
WASTE_USEC(x);
xTaskNotify(xTask_SignalProcessingActuateTask, MAKE_OUTPUT, eSetValueWithOverwrite);
inp = INPUT_SHORT_NEXT * CLAMP(y, 1, 3);
x = STRETCH_i32(inp);
x = FUNCTION_5(x);
WASTE_USEC(WC_SWITCH(TRANSLATE_5(50, 200), 200));
x = TRANSLATE_5(x, 50, 200);
x = WC_SWITCH(x, 200);
WASTE_USEC(x);
trigger_job_done();
} while (1);
}
@ -248,7 +264,7 @@ static void prv_SignalGatherFinishedTask(void *pvParameters) {
static void prv_SignalGatherTimeoutTask(void *pvParameters) {
const int task_id = 2;
uint16_t inp = 0;
int x=0;
volatile int x=0;
trigger_job_done();
do {
RNG_RESET
@ -257,17 +273,23 @@ static void prv_SignalGatherTimeoutTask(void *pvParameters) {
inp = INPUT_SHORT_NEXT * CLAMP(y, 1, 3);
x = STRETCH_i32(inp);
x = FUNCTION_6(x);
WASTE_USEC(WC_SWITCH(TRANSLATE_6(50, 200), 200));
x = TRANSLATE_6(x, 50, 200);
x = WC_SWITCH(x, 200);
WASTE_USEC(x);
xSemaphoreTake(xSemaphore_SPIBus, portMAX_DELAY);
inp = INPUT_SHORT_NEXT * CLAMP(y, 1, 3);
x = STRETCH_i32(inp);
x = FUNCTION_7(x);
WASTE_USEC(WC_SWITCH(TRANSLATE_7(50, 200), 200));
x = TRANSLATE_7(x, 50, 200);
x = WC_SWITCH(x, 200);
WASTE_USEC(x);
xSemaphoreGive(xSemaphore_SPIBus);
inp = INPUT_SHORT_NEXT * CLAMP(y, 1, 3);
x = STRETCH_i32(inp);
x = FUNCTION_8(x);
WASTE_USEC(WC_SWITCH(TRANSLATE_8(50, 200), 200));
x = TRANSLATE_8(x, 50, 200);
x = WC_SWITCH(x, 200);
WASTE_USEC(x);
xTaskNotify(xTask_SignalGatherFinishedTask, MAKE_OUTPUT, eSetValueWithOverwrite);
trigger_job_done();
} while (1);
@ -278,7 +300,7 @@ volatile int calculate;
static void prv_SignalProcessingActuateTask(void *pvParameters) {
const int task_id = 3;
uint16_t inp = 0;
int x=0;
volatile int x=0;
trigger_job_done();
do {
RNG_RESET
@ -287,7 +309,9 @@ static void prv_SignalProcessingActuateTask(void *pvParameters) {
inp = INPUT_SHORT_NEXT * CLAMP(y, 1, 3);
x = STRETCH_i32(inp);
x = FUNCTION_9(x);
WASTE_USEC(WC_SWITCH(TRANSLATE_9(50, 200), 200));
x = TRANSLATE_9(x, 50, 200);
x = WC_SWITCH(x, 200);
WASTE_USEC(x);
trigger_job_done();
} while (1);
}
@ -295,7 +319,7 @@ static void prv_SignalProcessingActuateTask(void *pvParameters) {
static void prv_SignalProcessingAttitudeTask(void *pvParameters) {
const int task_id = 4;
uint16_t inp = 0;
int x=0;
volatile int x=0;
trigger_job_done();
do {
RNG_RESET
@ -304,7 +328,9 @@ static void prv_SignalProcessingAttitudeTask(void *pvParameters) {
inp = INPUT_SHORT_NEXT * CLAMP(y, 1, 3);
x = STRETCH_i32(inp);
x = FUNCTION_10(x);
WASTE_USEC(WC_SWITCH(TRANSLATE_10(50, 200), 200));
x = TRANSLATE_10(x, 50, 200);
x = WC_SWITCH(x, 200);
WASTE_USEC(x);
trigger_job_done();
} while (1);
}
@ -314,21 +340,25 @@ static void prv_FlightControlTask(void *pvParameters) {
TickType_t xLastWakeTime = initial_release_time;
const TickType_t xFrequency = 9 / portTICK_PERIOD_MS;
uint16_t inp = 0;
int x=0;
volatile int x=0;
do {
RNG_RESET
// timing_start(1 | TIMING_POINT_IS_HIGHEST_PRIO);
inp = INPUT_SHORT_NEXT;
x = STRETCH_i32(inp);
x = FUNCTION_1(x);
WASTE_USEC(WC_SWITCH(TRANSLATE_1(50, 200), 200));
x = TRANSLATE_1(x, 50, 200);
x = WC_SWITCH(x, 200);
WASTE_USEC(x);
xTaskNotify(xTask_FlightControlAttitudeTask, 0, eSetValueWithOverwrite);
xTaskNotify(xTask_FlightControlActuateTask, 0, eSetValueWithOverwrite);
xTaskNotify(xTask_MavlinkSendTask, 0, eSetValueWithOverwrite);
inp = INPUT_SHORT_NEXT;
x = STRETCH_i32(inp);
x = FUNCTION_2(x);
WASTE_USEC(WC_SWITCH(TRANSLATE_2(50, 200), 200));
x = TRANSLATE_2(x, 50, 200);
x = WC_SWITCH(x, 200);
WASTE_USEC(x);
trigger_job_done();
xTaskDelayUntil( &xLastWakeTime, xFrequency );
} while (1);
@ -337,7 +367,7 @@ static void prv_FlightControlTask(void *pvParameters) {
static void prv_FlightControlAttitudeTask(void *pvParameters) {
const int task_id = 6;
uint16_t inp = 0;
int x=0;
volatile int x=0;
trigger_job_done();
do {
RNG_RESET
@ -346,7 +376,9 @@ static void prv_FlightControlAttitudeTask(void *pvParameters) {
inp = INPUT_SHORT_NEXT * CLAMP(y, 1, 3);
x = STRETCH_i32(inp);
x = FUNCTION_3(x);
WASTE_USEC(WC_SWITCH(TRANSLATE_3(50, 200), 200));
x = TRANSLATE_3(x, 50, 200);
x = WC_SWITCH(x, 200);
WASTE_USEC(x);
trigger_job_done();
} while (1);
}
@ -354,7 +386,7 @@ static void prv_FlightControlAttitudeTask(void *pvParameters) {
static void prv_FlightControlActuateTask(void *pvParameters) {
const int task_id = 7;
uint16_t inp = 0;
int x=0;
volatile int x=0;
trigger_job_done();
do {
RNG_RESET
@ -363,7 +395,9 @@ static void prv_FlightControlActuateTask(void *pvParameters) {
inp = INPUT_SHORT_NEXT * CLAMP(y, 1, 3);
x = STRETCH_i32(inp);
x = FUNCTION_4(x);
WASTE_USEC(WC_SWITCH(TRANSLATE_4(50, 200), 200));
x = TRANSLATE_4(x, 50, 200);
x = WC_SWITCH(x, 200);
WASTE_USEC(x);
trigger_job_done();
} while (1);
}
@ -371,7 +405,7 @@ static void prv_FlightControlActuateTask(void *pvParameters) {
static void prv_MavlinkSendTask(void *pvParameters) {
const int task_id = 8;
uint16_t inp = 0;
int x=0;
volatile int x=0;
trigger_job_done();
do {
RNG_RESET
@ -380,15 +414,24 @@ static void prv_MavlinkSendTask(void *pvParameters) {
inp = INPUT_SHORT_NEXT * CLAMP(y, 1, 3);
x = STRETCH_i32(inp);
x = FUNCTION_5(x);
WASTE_USEC(WC_SWITCH(TRANSLATE_5(50, 200), 200));
x = TRANSLATE_5(x, 50, 200);
x = WC_SWITCH(x, 200);
WASTE_USEC(x);
xSemaphoreTake(xSemaphore_SPIBus, portMAX_DELAY);
WASTE_USEC(WC_SWITCH(TRANSLATE_1(15, 50), 50));
inp = INPUT_SHORT_NEXT * CLAMP(y, 1, 3);
x = STRETCH_i32(inp);
x = FUNCTION_1(x);
x = TRANSLATE_1(x, 50, 200);
x = WC_SWITCH(x, 200);
WASTE_USEC(x);
// NVIC_SetPendingIRQ(1);
xSemaphoreGive(xSemaphore_SPIBus);
inp = INPUT_SHORT_NEXT * CLAMP(y, 1, 3);
x = STRETCH_i32(inp);
x = FUNCTION_6(x);
WASTE_USEC(WC_SWITCH(TRANSLATE_6(50, 200), 200));
x = TRANSLATE_6(x, 50, 200);
x = WC_SWITCH(x, 200);
WASTE_USEC(x);
// timing_end(1);
trigger_job_done();
} while (1);
@ -399,7 +442,7 @@ static void prv_CopterControlTask(void *pvParameters) {
TickType_t xLastWakeTime = initial_release_time;
const TickType_t xFrequency = 5 / portTICK_PERIOD_MS;
uint16_t inp = 0;
int x=0;
volatile int x=0;
trigger_job_done();
do {
RNG_RESET
@ -413,14 +456,23 @@ static void prv_CopterControlTask(void *pvParameters) {
inp = INPUT_SHORT_NEXT * CLAMP(y, 1, 3);
x = STRETCH_i32(inp);
x = FUNCTION_7(x);
WASTE_USEC(WC_SWITCH(TRANSLATE_7(50, 200), 200));
x = TRANSLATE_7(x, 50, 200);
x = WC_SWITCH(x, 200);
WASTE_USEC(x);
vTaskSuspendAll();
WASTE_USEC(WC_SWITCH(TRANSLATE_8(15, 50), 50));
inp = INPUT_SHORT_NEXT * CLAMP(y, 1, 3);
x = STRETCH_i32(inp);
x = FUNCTION_6(x);
x = TRANSLATE_6(x, 15, 50);
x = WC_SWITCH(x, 50);
WASTE_USEC(x);
xTaskResumeAll();
inp = INPUT_SHORT_NEXT * CLAMP(y, 1, 3);
x = STRETCH_i32(inp);
x = FUNCTION_8(x);
WASTE_USEC(WC_SWITCH(TRANSLATE_8(50, 200), 200));
x = TRANSLATE_8(x, 50, 200);
x = WC_SWITCH(x, 200);
WASTE_USEC(x);
// timing_end(2);
trigger_job_done();
@ -429,7 +481,7 @@ static void prv_CopterControlTask(void *pvParameters) {
void ISR_0_Handler(void) {
uint16_t inp = 0;
int x=0;
volatile int x=0;
if (xTask_CopterControlTask != NULL) {
const int task_id = 10;
RNG_RESET
@ -437,9 +489,16 @@ void ISR_0_Handler(void) {
inp = INPUT_SHORT_NEXT;
x = STRETCH_i32(inp);
x = FUNCTION_9(x);
WASTE_USEC(WC_SWITCH(TRANSLATE_9(15, 50), 50));
x = TRANSLATE_9(x, 15, 50);
x = WC_SWITCH(x, 50);
WASTE_USEC(x);
xTaskNotifyFromISR(xTask_CopterControlTask, MAKE_OUTPUT, eNoAction, NULL);
WASTE_USEC(WC_SWITCH(TRANSLATE_10(15, 50), 50));
inp = INPUT_SHORT_NEXT;
x = STRETCH_i32(inp);
x = FUNCTION_10(x);
x = TRANSLATE_10(x, 15, 50);
x = WC_SWITCH(x, 50);
WASTE_USEC(x);
}
}
@ -448,13 +507,15 @@ static void prv_CopterControlWatchdogTask(void *pvParameters) {
TickType_t xLastWakeTime = initial_release_time;
const TickType_t xFrequency = 10 / portTICK_PERIOD_MS;
uint16_t inp = 0;
int x=0;
volatile int x=0;
do {
RNG_RESET
inp = INPUT_SHORT_NEXT;
x = STRETCH_i32(inp);
x = FUNCTION_9(x);
WASTE_USEC(WC_SWITCH(TRANSLATE_1(50, 200), 200));
x = TRANSLATE_9(x, 50, 200);
x = WC_SWITCH(x, 200);
WASTE_USEC(x);
trigger_job_done();
xTaskDelayUntil( &xLastWakeTime, xFrequency );
} while (1);

View File

@ -36,12 +36,15 @@
#define DO_TIME(X,Y) WASTE_USEC((X))
#ifdef INSERT_WC
#define DEBUG_VAL(X,D) ((D)+0*(X))
#define WCET_CLAMP(X, LB, UB, LABEL) WASTE_USEC(UB)
#define DEBUG_VAL(X,D) ((D)*1+(X)*0)
#define DEBUG_INST(X) {X}
#else
#define DEBUG_VAL(X,D) ((X)+(D)*0)
#define WCET_CLAMP(X, LB, UB, LABEL) WASTE_USEC(CLAMP(X,LB,UB))
#define DEBUG_VAL(X,D) ((X)*1+(D)*0)
#define DEBUG_INST(X) {}
#endif
#define WCET_CLAMP(X, LB, UB, LABEL) {volatile int _xtime = CLAMP(X,LB,UB); volatile int _timetorun = DEBUG_VAL(_xtime, UB); WASTE_USEC(_timetorun);}
// #define DO_TIME(X,Y) WASTE_USEC(DEBUG_VAL((X),(Y)))
static void prvTask1( void * pvParameters );
static void prvTask2( void * pvParameters );
@ -176,13 +179,13 @@ static void prvTask2( void * pvParameters ) {
RNG_RESET
// Actions --------------------------------------
uint16_t x = INPUT_SHORT_NEXT;
DO_TIME(1000, TASK_2_MESSAGE)
DO_TIME(1000, 1000)
xSemaphoreTake(xMutex, portMAX_DELAY);
volatile int torun = 1000;
if (DEBUG_VAL(CHANCE_1_IN_POWOF2(x, 5), 1)) {
torun += 1000;
}
DO_TIME(torun, TASK_2_MESSAGE)
WCET_CLAMP(torun, 1000, 2000, "")
int y = ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
xSemaphoreGive(xMutex);
// ---------------------------------------------
@ -198,24 +201,24 @@ static void prvTask3( void * pvParameters ) {
for( ;; ){
#ifdef IGNORE_INTERRUPTS
xTaskDelayUntil( &xLastWakeTime, xFrequency ); // periodic
int y = ulTaskNotifyTake(pdTRUE, 0);
int y = ulTaskNotifyTake(pdTRUE, 0)-1;
#else
int y = ulTaskNotifyTake(pdTRUE, portMAX_DELAY)-1; // sporadic
#endif
RNG_RESET
// Actions --------------------------------------
DO_TIME(100, TASK_3_MESSAGE)
DO_TIME(100, 100)
xSemaphoreTake(xMutex, portMAX_DELAY); // wost time: right after T2 locks the mutex
volatile uint16_t x = INPUT_SHORT_NEXT;
int torun = 0;
if (y) {
torun = CLAMP(x, 1000, 4000);
} else {
if (y>0) {
torun = CLAMP(x, 0, 5000);
} else {
torun = CLAMP(x, 1000, 4000);
}
DO_TIME(torun, TASK_3_MESSAGE)
WCET_CLAMP(torun, 4000, 5000, "")
xSemaphoreGive(xMutex);
DO_TIME(100, TASK_3_MESSAGE)
DO_TIME(100, 100)
// ---------------------------------------------
trigger_job_done();
}
@ -252,13 +255,10 @@ static void prvTask5( void * pvParameters ) {
int succ = xSemaphoreTake(xMutex, 0); // try to take the mutex
if (succ == pdTRUE) {
volatile uint16_t x = INPUT_SHORT_NEXT;
// uint16_t x = 2000;
int torun = 0;
torun = CLAMP(x, 0, 2000);
DO_TIME(torun, TASK_5_MESSAGE)
WCET_CLAMP(x, 0, 2000, "")
xSemaphoreGive(xMutex);
} else {
DO_TIME(50, TASK_5_MESSAGE)
DO_TIME(50, 50)
}
// ---------------------------------------------
trigger_job_done();
@ -274,10 +274,12 @@ void vWatersIdleFunction() {
void ISR_0_Handler( void )
{
const int task_id = 5;
puts("Interrupt");
if (xTask3) {
volatile uint16_t x = INPUT_SHORT_NEXT;
BaseType_t _tmp = 0;
xTaskNotifyFromISR(xTask3, 1, eSetValueWithOverwrite, &_tmp);
xTaskNotifyFromISR(xTask3, DEBUG_VAL((x%10) == 0 + 1, 2), eSetValueWithOverwrite, &_tmp);
}
}

View File

@ -34,12 +34,11 @@
#include "fuzzhelper.c"
#ifdef INSERT_WC
#define DEBUG_VAL(X,D) ((D)+0*(X))
#define WCET_CLAMP(X, LB, UB, LABEL) WASTE_NSEC((X)*0+UB)
#define DEBUG_VAL(X,D) ((D)+1*(X)*0)
#else
#define DEBUG_VAL(X,D) ((X)+0*(D))
#define WCET_CLAMP(X, LB, UB, LABEL) WASTE_NSEC(CLAMP(X,LB,UB))
#define DEBUG_VAL(X,D) ((X)+1*(D)*0)
#endif
#define WCET_CLAMP(X, LB, UB, LABEL) {volatile int _xtime = CLAMP(X,LB,UB); volatile int _timetorun = DEBUG_VAL(_xtime, UB); WASTE_NSEC(_timetorun);}
#ifdef WATERS_UNSYNCHRONIZED
#define NOTIFY_WAIT_TIME 0