From 545018244c5af9b521ecd7e8a83a75a1bb484cff Mon Sep 17 00:00:00 2001 From: James Cotton Date: Sun, 22 Jul 2012 23:03:27 -0500 Subject: [PATCH 1/3] Make saving occur within the system thread instead of the event system thread --- flight/Modules/System/systemmod.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/flight/Modules/System/systemmod.c b/flight/Modules/System/systemmod.c index 827b264d2..7d0118583 100644 --- a/flight/Modules/System/systemmod.c +++ b/flight/Modules/System/systemmod.c @@ -73,6 +73,7 @@ static uint32_t idleCounter; static uint32_t idleCounterClear; static xTaskHandle systemTaskHandle; +static xQueueHandle objectPersistenceQueue; static bool stackOverflow; static bool mallocFailed; @@ -124,6 +125,8 @@ int32_t SystemModInitialize(void) SystemModStart(); + objectPersistenceQueue = xQueueCreate(1, sizeof(UAVObjEvent)); + return 0; } @@ -133,8 +136,6 @@ MODULE_INITCALL(SystemModInitialize, 0) */ static void systemTask(void *parameters) { - portTickType lastSysTime; - /* create all modules thread */ MODULE_TASKCREATE_ALL; @@ -154,10 +155,9 @@ static void systemTask(void *parameters) // Initialize vars idleCounter = 0; idleCounterClear = 0; - lastSysTime = xTaskGetTickCount(); // Listen for SettingPersistance object updates, connect a callback function - ObjectPersistenceConnectCallback(&objectUpdatedCb); + ObjectPersistenceConnectQueue(objectPersistenceQueue); // Main system loop while (1) { @@ -193,11 +193,14 @@ static void systemTask(void *parameters) FlightStatusData flightStatus; FlightStatusGet(&flightStatus); - // Wait until next period - if(flightStatus.Armed == FLIGHTSTATUS_ARMED_ARMED) { - vTaskDelayUntil(&lastSysTime, SYSTEM_UPDATE_PERIOD_MS / portTICK_RATE_MS / (LED_BLINK_RATE_HZ * 2) ); - } else { - vTaskDelayUntil(&lastSysTime, SYSTEM_UPDATE_PERIOD_MS / portTICK_RATE_MS); + UAVObjEvent ev; + int delayTime = flightStatus.Armed == FLIGHTSTATUS_ARMED_ARMED ? + SYSTEM_UPDATE_PERIOD_MS / portTICK_RATE_MS / (LED_BLINK_RATE_HZ * 2) : + SYSTEM_UPDATE_PERIOD_MS / portTICK_RATE_MS; + + if(xQueueReceive(objectPersistenceQueue, &ev, delayTime) == pdTRUE) { + // If object persistence is updated call the callback + objectUpdatedCb(&ev); } } } From e38325c745a1a8e0962e22fdc247c97f75134a31 Mon Sep 17 00:00:00 2001 From: James Cotton Date: Mon, 23 Jul 2012 08:47:43 -0500 Subject: [PATCH 2/3] Should check that the queue allocates and initialize shoudl return -1 if not --- flight/Modules/System/systemmod.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/flight/Modules/System/systemmod.c b/flight/Modules/System/systemmod.c index 7d0118583..005a0c565 100644 --- a/flight/Modules/System/systemmod.c +++ b/flight/Modules/System/systemmod.c @@ -126,6 +126,8 @@ int32_t SystemModInitialize(void) SystemModStart(); objectPersistenceQueue = xQueueCreate(1, sizeof(UAVObjEvent)); + if (objectPersistenceQueue == NULL) + return -1; return 0; } From 9865466da9ddc556d645cc5a93c17f9463d48f41 Mon Sep 17 00:00:00 2001 From: James Cotton Date: Tue, 24 Jul 2012 09:51:03 -0500 Subject: [PATCH 3/3] Make sure to create the system queue BEFORE calling task start. Systemmod initializes differently than other threads and I missed htat. Huge thanks to Hyper for making me realize that despite the fact I didn't see it :D. --- flight/Modules/System/systemmod.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flight/Modules/System/systemmod.c b/flight/Modules/System/systemmod.c index 005a0c565..33bf462fb 100644 --- a/flight/Modules/System/systemmod.c +++ b/flight/Modules/System/systemmod.c @@ -123,12 +123,12 @@ int32_t SystemModInitialize(void) WatchdogStatusInitialize(); #endif - SystemModStart(); - objectPersistenceQueue = xQueueCreate(1, sizeof(UAVObjEvent)); if (objectPersistenceQueue == NULL) return -1; + SystemModStart(); + return 0; }