Fixes #1968 - I ported the last changes from Damjan in the same time.

Please review (I push it anyway as there was a freeze before on startup
when radio in Slave mode)
This commit is contained in:
bsongis
2015-01-28 23:22:04 +01:00
parent a63bb7f9be
commit 76937ea566
5 changed files with 86 additions and 55 deletions
@@ -150,6 +150,10 @@ void init_no_pulses(uint32_t port);
void disable_no_pulses(uint32_t port);
void init_ppm( uint32_t module_index );
void disable_ppm( uint32_t module_index );
void set_external_ppm_parameters(uint32_t idleTime, uint32_t delay, uint32_t positive);
#if defined(TARANIS_INTERNAL_PPM)
void set_internal_ppm_parameters(uint32_t idleTime, uint32_t delay, uint32_t positive);
#endif
void init_pxx( uint32_t module_index );
void disable_pxx( uint32_t module_index );
void init_dsm2( uint32_t module_index );
@@ -158,6 +162,7 @@ void disable_dsm2( uint32_t module_index );
// Trainer driver
void init_trainer_ppm(void);
void stop_trainer_ppm(void);
void set_trainer_ppm_parameters(uint32_t idleTime, uint32_t delay, uint32_t positive);
void init_trainer_capture(void);
void stop_trainer_capture(void);
void init_cppm_on_heartbeat_capture(void);
+48 -22
View File
@@ -47,8 +47,10 @@ extern uint16_t dsm2Stream[400];
static void init_pa10_pxx( void ) ;
static void disable_pa10_pxx( void ) ;
static void init_pa10_ppm( void ) ;
static void disable_pa10_ppm( void ) ;
#if defined(TARANIS_INTERNAL_PPM)
static void init_pa10_ppm( void ) ;
static void disable_pa10_ppm( void ) ;
#endif
static void init_pa7_pxx( void ) ;
static void disable_pa7_pxx( void ) ;
#if defined(DSM2)
@@ -96,20 +98,45 @@ void disable_dsm2(uint32_t port)
void init_ppm(uint32_t port)
{
if (port == INTERNAL_MODULE)
init_pa10_ppm(); // TODO needed?
else
if (port == EXTERNAL_MODULE) {
init_pa7_ppm();
}
#if defined(TARANIS_INTERNAL_PPM)
else if (port == INTERNAL_MODULE) {
init_pa10_ppm();
}
#endif
}
void disable_ppm(uint32_t port)
{
if (port == INTERNAL_MODULE)
disable_pa10_ppm(); // TODO needed?
else
if (port == EXTERNAL_MODULE) {
disable_pa7_ppm();
}
#if defined(TARANIS_INTERNAL_PPM)
else if (port == INTERNAL_MODULE) {
disable_pa10_ppm();
}
#endif
}
void set_external_ppm_parameters(uint32_t idleTime, uint32_t delay, uint32_t positive)
{
TIM8->CCR2 = idleTime;
TIM8->CCR1 = delay;
// we are using complementary output so logic has to be reversed here
TIM8->CCER = TIM_CCER_CC1NE | (positive ? 0 : TIM_CCER_CC1NP);
}
#if defined(TARANIS_INTERNAL_PPM)
void set_internal_ppm_parameters(uint32_t idleTime, uint32_t delay, uint32_t positive)
{
TIM1->CCR2 = idleTime;
TIM1->CCR3 = delay;
TIM1->CCER = TIM_CCER_CC3E | (positive ? TIM_CCER_CC3P : 0);
}
#endif
void init_no_pulses(uint32_t port)
{
if (port == INTERNAL_MODULE)
@@ -283,6 +310,7 @@ static void disable_pa10_pxx()
INTERNAL_RF_OFF();
}
#if defined(TARANIS_INTERNAL_PPM)
// PPM output
// Timer 1, channel 1 on PA8 for prototype
// Pin is AF1 function for timer 1
@@ -290,7 +318,6 @@ static void init_pa10_ppm()
{
INTERNAL_RF_ON();
// Timer1
setupPulsesPPM(INTERNAL_MODULE) ;
ppmStreamPtr[INTERNAL_MODULE] = ppmStream[INTERNAL_MODULE];
//RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN ; // Enable portA clock
@@ -299,8 +326,12 @@ static void init_pa10_ppm()
configure_pins( PIN_INTPPM_OUT, PIN_PERIPHERAL | PIN_PORTA | PIN_PER_1 | PIN_OS25 | PIN_PUSHPULL ) ;
RCC->APB2ENR |= RCC_APB2ENR_TIM1EN ; // Enable clock
TIM1->CR1 &= ~TIM_CR1_CEN ;
// setupPulsesPPM() is also configuring registers,
// so it has to be called after the peripheral is enabled
setupPulsesPPM(INTERNAL_MODULE) ;
TIM1->ARR = *ppmStreamPtr[INTERNAL_MODULE]++ ;
TIM1->PSC = (PERI2_FREQUENCY * TIMER_MULT_APB2) / 2000000 - 1 ; // 0.5uS from 30MHz
@@ -308,7 +339,6 @@ static void init_pa10_ppm()
TIM1->CCMR2 = TIM_CCMR2_OC3M_1 | TIM_CCMR2_OC3M_2 ; // PWM mode 1
TIM1->CCMR1 = TIM_CCMR1_OC2PE ; // PWM mode 1
TIM1->CCR3 = (g_model.moduleData[INTERNAL_MODULE].ppmDelay*50+300)*2;
TIM1->BDTR = TIM_BDTR_MOE ;
TIM1->EGR = 1 ;
TIM1->DIER = TIM_DIER_UDE ;
@@ -334,6 +364,7 @@ static void disable_pa10_ppm()
INTERNAL_RF_OFF();
}
#endif // #if defined(TARANIS_INTERNAL_PPM)
#if !defined(SIMU)
extern "C" void TIM1_CC_IRQHandler()
@@ -535,7 +566,6 @@ static void init_pa7_ppm()
EXTERNAL_MODULE_ON();
// Timer1
setupPulsesPPM(EXTERNAL_MODULE) ;
ppmStreamPtr[EXTERNAL_MODULE] = ppmStream[EXTERNAL_MODULE];
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN ; // Enable portA clock
@@ -545,20 +575,16 @@ static void init_pa7_ppm()
configure_pins( PIN_EXTPPM_OUT, PIN_PERIPHERAL | PIN_PORTA | PIN_PER_3 | PIN_OS25 | PIN_PUSHPULL ) ;
#endif
RCC->APB2ENR |= RCC_APB2ENR_TIM8EN ; // Enable clock
TIM8->CR1 &= ~TIM_CR1_CEN ;
// setupPulsesPPM() is also configuring registers,
// so it has to be called after the peripheral is enabled
setupPulsesPPM(EXTERNAL_MODULE) ;
TIM8->ARR = *ppmStreamPtr[EXTERNAL_MODULE]++ ;
TIM8->PSC = (PERI2_FREQUENCY * TIMER_MULT_APB2) / 2000000 - 1 ; // 0.5uS from 30MHz
#if defined(REV3)
TIM8->CCER = TIM_CCER_CC1E ;
#else
TIM8->CCER = TIM_CCER_CC1NE;
if(g_model.moduleData[EXTERNAL_MODULE].ppmPulsePol)
TIM8->CCER |= TIM_CCER_CC1NP;
#endif
TIM8->CCMR1 = TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC2PE ; // PWM mode 1
TIM8->CCR1 = (g_model.moduleData[EXTERNAL_MODULE].ppmDelay*50+300)*2;
TIM8->BDTR = TIM_BDTR_MOE ;
TIM8->EGR = 1 ;
TIM8->DIER = TIM_DIER_UDE ;
+22 -17
View File
@@ -45,28 +45,27 @@ extern Fifo<32> sbusFifo;
// Trainer PPM oputput PC9, Timer 3 channel 4, (Alternate Function 2)
void init_trainer_ppm()
{
setupTrainerPulses() ;
TrainerPulsePtr = ppmStream[TRAINER_MODULE];
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOCEN ; // Enable portC clock
configure_pins( PIN_TR_PPM_OUT, PIN_PERIPHERAL | PIN_PORTC | PIN_PER_2 | PIN_OS25 | PIN_PUSHPULL ) ;
configure_pins( PIN_TR_PPM_IN, PIN_PORTA | PIN_INPUT ) ;
RCC->APB1ENR |= RCC_APB1ENR_TIM3EN ; // Enable clock
TIM3->CR1 &= ~TIM_CR1_CEN ;
// setupTrainerPulses() is also configuring registers,
// so it has to be called after the peripheral is enabled
setupTrainerPulses() ;
TIM3->ARR = *TrainerPulsePtr++ ;
TIM3->PSC = (PERI1_FREQUENCY * TIMER_MULT_APB1) / 2000000 - 1 ; // 0.5uS
TIM3->CCER = TIM_CCER_CC4E ;
if(!g_model.moduleData[TRAINER_MODULE].ppmPulsePol)
TIM3->CCER |= TIM_CCER_CC4P;
TIM3->CCMR2 = TIM_CCMR2_OC4M_1 | TIM_CCMR2_OC4M_2 | TIM_CCMR2_OC4PE ; // PWM mode 1
TIM3->CCR4 = (g_model.moduleData[TRAINER_MODULE].ppmDelay*50+300)*2;
TIM3->BDTR = TIM_BDTR_MOE ;
TIM3->EGR = 1 ;
// TIM3->DIER = TIM_DIER_UDE ;
TIM3->SR &= ~TIM_SR_UIF ; // Clear flag
TIM3->SR &= ~TIM_SR_CC2IF ; // Clear flag
TIM3->DIER |= TIM_DIER_CC2IE ;
TIM3->SR &= ~TIM_SR_CC1IF ; // Clear flag
TIM3->DIER |= TIM_DIER_CC1IE ;
TIM3->DIER |= TIM_DIER_UIE ;
TIM3->CR1 = TIM_CR1_CEN ;
@@ -78,11 +77,18 @@ void init_trainer_ppm()
void stop_trainer_ppm()
{
configure_pins( PIN_TR_PPM_OUT, PIN_INPUT | PIN_PORTC ) ; // Pin as input
TIM3->CR1 &= ~TIM_CR1_CEN ; // Stop counter
TIM3->DIER = 0 ; // Stop Interrupt
TIM3->CR1 &= ~TIM_CR1_CEN ; // Stop counter
NVIC_DisableIRQ(TIM3_IRQn) ; // Stop Interrupt
}
void set_trainer_ppm_parameters(uint32_t idleTime, uint32_t delay, uint32_t positive)
{
TIM3->CCR1 = idleTime;
TIM3->CCR4 = delay;
TIM3->CCER = TIM_CCER_CC4E | (positive ? TIM_CCER_CC4P : 0);
}
// Trainer capture, PC8, Timer 3 channel 3
void init_trainer_capture()
{
@@ -98,8 +104,8 @@ void init_trainer_capture()
TIM3->SR &= ~TIM_SR_CC3IF & ~TIM_SR_CC2IF & ~TIM_SR_UIF ; // Clear flags
TIM3->DIER |= TIM_DIER_CC3IE ;
TIM3->CR1 = TIM_CR1_CEN ;
NVIC_SetPriority(TIM3_IRQn, 7);
NVIC_EnableIRQ(TIM3_IRQn) ;
NVIC_SetPriority(TIM3_IRQn, 7);
}
void stop_trainer_capture()
@@ -124,7 +130,7 @@ extern "C" void TIM3_IRQHandler()
doCapture = true;
}
if ( (TIM3->DIER & TIM_DIER_CC2IE ) && ( TIM3->SR & TIM_SR_CC2IF ) ) {
if ( ( TIM3->DIER & TIM_DIER_CC2IE ) && ( TIM3->SR & TIM_SR_CC2IF ) ) {
// capture mode on heartbeat pin (external module)
capture = TIM3->CCR2 ;
doCapture = true ;
@@ -153,11 +159,10 @@ extern "C" void TIM3_IRQHandler()
}
// PPM out compare interrupt
if ( ( TIM3->DIER & TIM_DIER_CC2IE ) && ( TIM3->SR & TIM_SR_CC2IF ) ) {
if ( ( TIM3->DIER & TIM_DIER_CC1IE ) && ( TIM3->SR & TIM_SR_CC1IF ) ) {
// compare interrupt
TIM3->SR &= ~TIM_SR_CC2IF ; // Clear flag
TIM3->DIER &= ~TIM_DIER_CC2IE ; // stop this interrupt
TIM3->SR &= ~TIM_SR_CC2IF ; // Clear flag
TIM3->DIER &= ~TIM_DIER_CC1IE ; // stop this interrupt
TIM3->SR &= ~TIM_SR_CC1IF ; // Clear flag
setupTrainerPulses() ;
@@ -172,8 +177,8 @@ extern "C" void TIM3_IRQHandler()
TIM3->SR &= ~TIM_SR_UIF ; // Clear flag
TIM3->ARR = *TrainerPulsePtr++ ;
if ( *TrainerPulsePtr == 0 ) {
TIM3->SR &= ~TIM_SR_CC2IF ; // Clear this flag
TIM3->DIER |= TIM_DIER_CC2IE ; // Enable this interrupt
TIM3->SR &= ~TIM_SR_CC1IF ; // Clear this flag
TIM3->DIER |= TIM_DIER_CC1IE ; // Enable this interrupt
}
}
}