/* * 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" extern "C" { #include "STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_OTG_Driver/inc/usb_dcd_int.h" #include "STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_OTG_Driver/inc/usb_bsp.h" #include "STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/inc/stm32f2xx_dbgmcu.h" } volatile uint32_t Tenms ; // TODO to remove everywhere / use a #define void watchdogInit(unsigned int duration) { IWDG->KR = 0x5555 ; // Unlock registers IWDG->PR = 3 ; // Divide by 32 => 1kHz clock IWDG->KR = 0x5555 ; // Unlock registers IWDG->RLR = duration ; // 1.5 seconds nominal IWDG->KR = 0xAAAA ; // reload IWDG->KR = 0xCCCC ; // start } // Starts TIMER at 200Hz, 5mS period void init5msTimer() { // Timer14 RCC->APB1ENR |= RCC_APB1ENR_TIM14EN ; // Enable clock TIM14->ARR = 4999 ; // 5mS TIM14->PSC = (PERI1_FREQUENCY * TIMER_MULT_APB1) / 1000000 - 1 ; // 1uS from 30MHz TIM14->CCER = 0 ; TIM14->CCMR1 = 0 ; TIM14->EGR = 0 ; TIM14->CR1 = 5 ; TIM14->DIER |= 1 ; NVIC_EnableIRQ(TIM8_TRG_COM_TIM14_IRQn) ; NVIC_SetPriority(TIM8_TRG_COM_TIM14_IRQn, 7); } void stop5msTimer( void ) { TIM14->CR1 = 0 ; // stop timer NVIC_DisableIRQ(TIM8_TRG_COM_TIM14_IRQn) ; RCC->APB1ENR &= ~RCC_APB1ENR_TIM14EN ; // Disable clock } // TODO use the same than board_sky9x.cpp void interrupt5ms() { static uint32_t pre_scale ; // Used to get 10 Hz counter AUDIO_HEARTBEAT(); #if defined(HAPTIC) HAPTIC_HEARTBEAT(); #endif if ( ++pre_scale >= 2 ) { pre_scale = 0 ; per10ms(); } } extern "C" void TIM8_TRG_COM_TIM14_IRQHandler() { TIM14->SR &= ~TIM_SR_UIF ; interrupt5ms() ; } #if !defined(SIMU) void boardInit() { pwrInit(); keysInit(); adcInit(); delaysInit(); audioInit(); init5msTimer(); __enable_irq(); eepromInit(); usbInit(); #if defined(HAPTIC) hapticInit(); #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 } #endif