void menusTask(void * pdata) { opentxInit(); #if defined(PCBTARANIS) && defined(REV9E) while (1) { uint32_t pwr_check = pwrCheck(); if (pwr_check == e_power_off) { break; } else if (pwr_check == e_power_press) { continue; } #else while (pwrCheck() != e_power_off) { #endif U64 start = CoGetOSTime(); perMain(); // TODO remove completely massstorage from sky9x firmware U32 runtime = (U32)(CoGetOSTime() - start); // deduct the thread run-time from the wait, if run-time was more than // desired period, then skip the wait all together if (runtime < MENU_TASK_PERIOD_TICKS) { CoTickDelay(MENU_TASK_PERIOD_TICKS - runtime); } } #if defined(REV9E) topLcdOff(); #endif BACKLIGHT_OFF(); #if defined(PCBTARANIS) displaySleepBitmap(); #else lcd_clear(); displayPopup(STR_SHUTDOWN); #endif opentxClose(); boardOff(); // Only turn power off if necessary } extern void audioTask(void* pdata); void tasksStart() { CoInitOS(); #if defined(CLI) cliStart(); #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(); }
void boardInit() { RCC_AHB1PeriphClockCmd(PWR_RCC_AHB1Periph | KEYS_RCC_AHB1Periph | LCD_RCC_AHB1Periph | BACKLIGHT_RCC_AHB1Periph | ADC_RCC_AHB1Periph | I2C_RCC_AHB1Periph | SD_RCC_AHB1Periph | HAPTIC_RCC_AHB1Periph | INTMODULE_RCC_AHB1Periph | EXTMODULE_RCC_AHB1Periph | TELEMETRY_RCC_AHB1Periph | SERIAL_RCC_AHB1Periph | TRAINER_RCC_AHB1Periph | HEARTBEAT_RCC_AHB1Periph, ENABLE); RCC_APB1PeriphClockCmd(LCD_RCC_APB1Periph | BACKLIGHT_RCC_APB1Periph | INTERRUPT_5MS_APB1Periph | TIMER_2MHz_APB1Periph | I2C_RCC_APB1Periph | SD_RCC_APB1Periph | TRAINER_RCC_APB1Periph | TELEMETRY_RCC_APB1Periph | SERIAL_RCC_APB1Periph, ENABLE); RCC_APB2PeriphClockCmd(BACKLIGHT_RCC_APB2Periph | ADC_RCC_APB2Periph | HAPTIC_RCC_APB2Periph | INTMODULE_RCC_APB2Periph | EXTMODULE_RCC_APB2Periph | HEARTBEAT_RCC_APB2Periph, ENABLE); #if !defined(REV9E) // some REV9E boards need that the pwrInit() is moved a little bit later pwrInit(); #endif keysInit(); adcInit(); delaysInit(); lcdInit(); // delaysInit() must be called before audioInit(); init2MhzTimer(); init5msTimer(); __enable_irq(); i2cInit(); usbInit(); #if defined(HAPTIC) hapticInit(); #endif #if defined(REV9E) bluetoothInit(BLUETOOTH_DEFAULT_BAUDRATE); #endif #if defined(DEBUG) DBGMCU_APB1PeriphConfig(DBGMCU_IWDG_STOP|DBGMCU_TIM1_STOP|DBGMCU_TIM2_STOP|DBGMCU_TIM3_STOP|DBGMCU_TIM6_STOP|DBGMCU_TIM8_STOP|DBGMCU_TIM10_STOP|DBGMCU_TIM13_STOP|DBGMCU_TIM14_STOP, ENABLE); #endif #if defined(REV9E) if (!WAS_RESET_BY_WATCHDOG_OR_SOFTWARE()) { lcd_clear(); lcd_bmp(76, 2, bmp_lock, 0, 60); lcdRefresh(); lcdRefreshWait(); tmr10ms_t start = get_tmr10ms(); tmr10ms_t duration = 0; uint8_t pwr_on = 0; while (pwrPressed()) { duration = get_tmr10ms() - start; if (duration < PWR_PRESS_DURATION_MIN) { unsigned index = duration / (PWR_PRESS_DURATION_MIN / 4); lcd_clear(); lcd_bmp(76, 2, bmp_startup, index*60, 60); } else if (duration >= PWR_PRESS_DURATION_MAX) { displaySleepBitmap(); turnBacklightOff(); } else { if (pwr_on != 1) { pwr_on = 1; pwrInit(); backlightInit(); haptic.play(15, 3, PLAY_NOW); } } lcdRefresh(); lcdRefreshWait(); } if (duration < PWR_PRESS_DURATION_MIN || duration >= PWR_PRESS_DURATION_MAX) { boardOff(); } } else { pwrInit(); backlightInit(); } topLcdInit(); #else backlightInit(); #endif }