diff --git a/radio/src/Makefile b/radio/src/Makefile index 1a0da41d8..9d1e9627d 100644 --- a/radio/src/Makefile +++ b/radio/src/Makefile @@ -613,7 +613,7 @@ ifeq ($(PCB), $(filter $(PCB), SKY9X 9XRPRO)) EEPROMSRC = eeprom_common.cpp eeprom_raw.cpp eeprom_conversions.cpp LCDSRC = lcd_common.cpp lcd_default.cpp PULSESSRC = pulses/pulses_arm.cpp pulses/ppm_arm.cpp pulses/pxx_arm.cpp pulses/dsm2_arm.cpp - CPPSRC += audio_arm.cpp haptic.cpp gui/view_about.cpp gui/view_text.cpp + CPPSRC += tasks_arm.cpp audio_arm.cpp haptic.cpp gui/view_about.cpp gui/view_text.cpp CPPSRC += targets/sky9x/telemetry_driver.cpp targets/sky9x/second_serial_driver.cpp targets/sky9x/pwr_driver.cpp targets/sky9x/adc_driver.cpp targets/sky9x/eeprom_driver.cpp targets/sky9x/pulses_driver.cpp targets/sky9x/keys_driver.cpp targets/sky9x/audio_driver.cpp targets/sky9x/buzzer_driver.cpp targets/sky9x/haptic_driver.cpp targets/sky9x/sdcard_driver.cpp targets/sky9x/massstorage.cpp CPPSRC += loadboot.cpp @@ -683,7 +683,7 @@ ifeq ($(PCB), TARANIS) EEPROMSRC = eeprom_common.cpp eeprom_rlc.cpp eeprom_conversions.cpp LCDSRC = lcd_common.cpp lcd_taranis.cpp PULSESSRC = pulses/pulses_arm.cpp pulses/ppm_arm.cpp pulses/pxx_arm.cpp - CPPSRC += audio_arm.cpp sbus.cpp + CPPSRC += tasks_arm.cpp audio_arm.cpp sbus.cpp CPPSRC += targets/taranis/pulses_driver.cpp targets/taranis/keys_driver.cpp targets/taranis/adc_driver.cpp targets/taranis/trainer_driver.cpp targets/taranis/audio_driver.cpp targets/taranis/uart3_driver.cpp targets/taranis/telemetry_driver.cpp CPPSRC += bmp.cpp gui/view_channels.cpp gui/view_about.cpp gui/view_text.cpp loadboot.cpp SRC += targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/CMSIS/Device/ST/STM32F2xx/Source/Templates/system_stm32f2xx.c diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index e53281de1..9d51a6013 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -36,44 +36,6 @@ #include "opentx.h" -#if defined(CPUARM) -#define MENUS_STACK_SIZE 2000 -#define MIXER_STACK_SIZE 500 -#define AUDIO_STACK_SIZE 500 -#define BT_STACK_SIZE 500 -#define DEBUG_STACK_SIZE 500 - -#if defined(_MSC_VER) - #define _ALIGNED(x) __declspec(align(x)) -#elif defined(__GNUC__) - #define _ALIGNED(x) __attribute__ ((aligned(x))) -#endif - -OS_TID menusTaskId; -// stack must be aligned to 8 bytes otherwise printf for %f does not work! -OS_STK _ALIGNED(8) menusStack[MENUS_STACK_SIZE]; - -OS_TID mixerTaskId; -OS_STK mixerStack[MIXER_STACK_SIZE]; - -OS_TID audioTaskId; -OS_STK audioStack[AUDIO_STACK_SIZE]; - -#if defined(BLUETOOTH) -OS_TID btTaskId; -OS_STK btStack[BT_STACK_SIZE]; -#endif - -#if defined(DEBUG) -OS_TID debugTaskId; -OS_STK debugStack[DEBUG_STACK_SIZE]; -#endif - -OS_MutexID audioMutex; -OS_MutexID mixerMutex; - -#endif // defined(CPUARM) - #if defined(SPLASH) const pm_uchar splashdata[] PROGMEM = { 'S','P','S',0, #if defined(PCBTARANIS) @@ -3301,48 +3263,7 @@ void saveTimers() volatile rotenc_t g_rotenc[1] = {0}; #endif -#ifndef SIMU - -#if defined(CPUARM) -void stack_paint() -{ - for (uint16_t i=0; i maxMixerDuration) maxMixerDuration = t0 ; - } - - CoTickDelay(1); // 2ms for now - } -} - -void menusTask(void * pdata) -{ - opentxInit(); - - while (pwrCheck() != e_power_off) { - perMain(); - // TODO remove completely massstorage from sky9x firmware - CoTickDelay(5); // 5*2ms for now - } - - lcd_clear(); - displayPopup(STR_SHUTDOWN); - - opentxClose(); - - lcd_clear(); - lcdRefresh(); - lcdSetRefVolt(0); - - SysTick->CTRL = 0; // turn off systick - - pwrOff(); // Only turn power off if necessary -} - -extern void audioTask(void* pdata); - -#endif - +#if !defined(SIMU) int main(void) { // G: The WDT remains active after a WDT reset -- at maximum clock speed. So it's @@ -3597,30 +3460,13 @@ int main(void) #endif #if defined(CPUARM) - CoInitOS(); - -#if defined(CPUARM) && defined(DEBUG) - debugTaskId = CoCreateTaskEx(debugTask, NULL, 10, &debugStack[DEBUG_STACK_SIZE-1], DEBUG_STACK_SIZE, 1, false); -#endif - -#if defined(BLUETOOTH) - btTaskId = CoCreateTask(btTask, NULL, 15, &btStack[BT_STACK_SIZE-1], BT_STACK_SIZE); -#endif - - mixerTaskId = CoCreateTask(mixerTask, NULL, 5, &mixerStack[MIXER_STACK_SIZE-1], MIXER_STACK_SIZE); - menusTaskId = CoCreateTask(menusTask, NULL, 10, &menusStack[MENUS_STACK_SIZE-1], MENUS_STACK_SIZE); - audioTaskId = CoCreateTask(audioTask, NULL, 7, &audioStack[AUDIO_STACK_SIZE-1], AUDIO_STACK_SIZE); - - audioMutex = CoCreateMutex(); - mixerMutex = CoCreateMutex(); - - CoStartOS(); + tasksStart(); #else #if defined(CPUM2560) uint8_t shutdown_state = 0; #endif - while(1) { + while (1) { #if defined(CPUM2560) if ((shutdown_state=pwrCheck()) > e_power_trainer) break; diff --git a/radio/src/opentx.h b/radio/src/opentx.h index 9e4179031..0ebf25d19 100644 --- a/radio/src/opentx.h +++ b/radio/src/opentx.h @@ -912,7 +912,7 @@ extern uint16_t maxLuaDuration; #endif #if defined(CPUARM) - uint16_t stack_free(uint8_t tid); + uint32_t stack_free(uint32_t tid); #else uint16_t stack_free(); #endif diff --git a/radio/src/targets/simu/simpgmspace.cpp b/radio/src/targets/simu/simpgmspace.cpp index 54b4b779b..d69992eb4 100644 --- a/radio/src/targets/simu/simpgmspace.cpp +++ b/radio/src/targets/simu/simpgmspace.cpp @@ -436,14 +436,12 @@ void eeWriteBlockCmp(const void *pointer_ram, uint16_t pointer_eeprom, size_t si #endif -#if defined(CPUARM) -uint16_t stack_free(uint8_t) -#else +#if !defined(CPUARM) uint16_t stack_free() -#endif { return 500; } +#endif #if 0 static void EeFsDump(){ diff --git a/radio/src/targets/simu/simpgmspace.h b/radio/src/targets/simu/simpgmspace.h index bae53a4ec..3620d5493 100644 --- a/radio/src/targets/simu/simpgmspace.h +++ b/radio/src/targets/simu/simpgmspace.h @@ -358,19 +358,25 @@ void eeprom_read_block (void *pointer_ram, uint16_t pointer_eeprom, size_t size) void eeprom_read_block (void *pointer_ram, const void *pointer_eeprom, size_t size); #endif +#define wdt_enable(...) sleep(1/*ms*/) #define wdt_reset() sleep(1/*ms*/) #define boardInit() #define OS_MutexID pthread_mutex_t extern OS_MutexID audioMutex; -#define OS_FlagID int -#define OS_TID int -#define OS_TCID int -#define OS_STK char +#define OS_FlagID uint32_t +#define OS_TID uint32_t +#define OS_TCID uint32_t +#define OS_STK uint32_t #define E_OK 0 +#define WDRF 0 +#define CoInitOS(...) +#define CoStartOS(...) +#define CoCreateTask(...) sleep(1/*ms*/) +#define CoCreateMutex(...) PTHREAD_MUTEX_INITIALIZER #define CoSetFlag(...) #define CoClearFlag(...) #define CoSetTmrCnt(...) diff --git a/radio/src/tasks_arm.cpp b/radio/src/tasks_arm.cpp new file mode 100755 index 000000000..b4597a247 --- /dev/null +++ b/radio/src/tasks_arm.cpp @@ -0,0 +1,193 @@ +/* + * Authors (alphabetical order) + * - Andre Bernet + * - Andreas Weitl + * - Bertrand Songis + * - Bryan J. Rentoul (Gruvin) + * - Cameron Weeks + * - Erez Raviv + * - Gabriel Birkus + * - Jean-Pierre Parisy + * - Karl Szmutny + * - Michael Blandford + * - Michal Hlavinka + * - Pat Mackenzie + * - Philip Moss + * - Rob Thomson + * - Romolo Manfredini + * - Thomas Husterer + * + * opentx is based on code named + * gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/, + * er9x by Erez Raviv: http://code.google.com/p/er9x/, + * and the original (and ongoing) project by + * Thomas Husterer, th9x: http://code.google.com/p/th9x/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + +#include "opentx.h" + +#define MENUS_STACK_SIZE 2000 +#define MIXER_STACK_SIZE 500 +#define AUDIO_STACK_SIZE 500 +#define BT_STACK_SIZE 500 +#define DEBUG_STACK_SIZE 500 + +#if defined(_MSC_VER) + #define _ALIGNED(x) __declspec(align(x)) +#elif defined(__GNUC__) + #define _ALIGNED(x) __attribute__ ((aligned(x))) +#endif + +OS_TID menusTaskId; +// stack must be aligned to 8 bytes otherwise printf for %f does not work! +OS_STK _ALIGNED(8) menusStack[MENUS_STACK_SIZE]; + +OS_TID mixerTaskId; +OS_STK mixerStack[MIXER_STACK_SIZE]; + +OS_TID audioTaskId; +OS_STK audioStack[AUDIO_STACK_SIZE]; + +#if defined(BLUETOOTH) +OS_TID btTaskId; +OS_STK btStack[BT_STACK_SIZE]; +#endif + +#if defined(DEBUG) +OS_TID debugTaskId; +OS_STK debugStack[DEBUG_STACK_SIZE]; +#endif + +OS_MutexID audioMutex; +OS_MutexID mixerMutex; + +void stack_paint() +{ + for (uint32_t i=0; i maxMixerDuration) maxMixerDuration = t0 ; + } + + CoTickDelay(1); // 2ms for now + } +} + +extern void opentxClose(); +extern void opentxInit(); +void menusTask(void * pdata) +{ + opentxInit(); + + while (pwrCheck() != e_power_off) { + perMain(); + // TODO remove completely massstorage from sky9x firmware + CoTickDelay(5); // 5*2ms for now + } + + lcd_clear(); + displayPopup(STR_SHUTDOWN); + + opentxClose(); + + lcd_clear(); + lcdRefresh(); + lcdSetRefVolt(0); + + SysTick->CTRL = 0; // turn off systick + + pwrOff(); // Only turn power off if necessary +} + +extern void audioTask(void* pdata); + +void tasksStart() +{ + CoInitOS(); + +#if defined(CPUARM) && defined(DEBUG) + debugTaskId = CoCreateTaskEx(debugTask, NULL, 10, &debugStack[DEBUG_STACK_SIZE-1], DEBUG_STACK_SIZE, 1, false); +#endif + +#if defined(BLUETOOTH) + btTaskId = CoCreateTask(btTask, NULL, 15, &btStack[BT_STACK_SIZE-1], BT_STACK_SIZE); +#endif + + mixerTaskId = CoCreateTask(mixerTask, NULL, 5, &mixerStack[MIXER_STACK_SIZE-1], MIXER_STACK_SIZE); + menusTaskId = CoCreateTask(menusTask, NULL, 10, &menusStack[MENUS_STACK_SIZE-1], MENUS_STACK_SIZE); + audioTaskId = CoCreateTask(audioTask, NULL, 7, &audioStack[AUDIO_STACK_SIZE-1], AUDIO_STACK_SIZE); + +#if !defined(SIMU) + audioMutex = CoCreateMutex(); + mixerMutex = CoCreateMutex(); +#endif + + CoStartOS(); +}