From 573747af5c2eac71076d9d5ad5e33749bece58e6 Mon Sep 17 00:00:00 2001 From: Felix Ruess Date: Thu, 20 Nov 2014 21:42:34 +0100 Subject: [PATCH 1/5] [radio_control] cleanup channel defines - PPM: remove PPM_NB_CHANNEL define an always decode RADIO_CTL_NB (number of channels in radio.xml) - PPM: the actually used/needed channels RADIO_CONTROL_NB_CHANNEL default to RADIO_CTL_NB but can be overwritten by user e.g. to use less channels for intermcu - SBUS: only provide a default for RADIO_CONTROL_NB_CHANNEL --- .../lpc21/subsystems/radio_control/ppm_arch.h | 2 -- .../arch/sim/subsystems/radio_control/ppm_arch.h | 2 -- .../stm32/subsystems/radio_control/ppm_arch.h | 2 -- sw/airborne/subsystems/radio_control.h | 5 ++++- sw/airborne/subsystems/radio_control/ppm.c | 16 ++++++++-------- sw/airborne/subsystems/radio_control/ppm.h | 10 +++++++--- .../subsystems/radio_control/sbus_common.h | 9 +++++++++ 7 files changed, 28 insertions(+), 18 deletions(-) diff --git a/sw/airborne/arch/lpc21/subsystems/radio_control/ppm_arch.h b/sw/airborne/arch/lpc21/subsystems/radio_control/ppm_arch.h index 6f62ac3a16..1c5465771a 100644 --- a/sw/airborne/arch/lpc21/subsystems/radio_control/ppm_arch.h +++ b/sw/airborne/arch/lpc21/subsystems/radio_control/ppm_arch.h @@ -44,8 +44,6 @@ #define RC_PPM_SIGNED_TICKS_OF_USEC(_v) signed_cpu_ticks_of_usec(_v) #define USEC_OF_RC_PPM_TICKS(_v) usec_of_cpu_ticks(_v) -#define PPM_NB_CHANNEL RADIO_CONTROL_NB_CHANNEL - #define PPM_IT PPM_CRI #define PPM_ISR() { \ diff --git a/sw/airborne/arch/sim/subsystems/radio_control/ppm_arch.h b/sw/airborne/arch/sim/subsystems/radio_control/ppm_arch.h index 4b0ab5edad..90132b0079 100644 --- a/sw/airborne/arch/sim/subsystems/radio_control/ppm_arch.h +++ b/sw/airborne/arch/sim/subsystems/radio_control/ppm_arch.h @@ -39,8 +39,6 @@ #define RC_PPM_SIGNED_TICKS_OF_USEC(_x) (_x) #define USEC_OF_RC_PPM_TICKS(_x) (_x) -#define PPM_NB_CHANNEL RADIO_CONTROL_NB_CHANNEL - #if USE_NPS extern void radio_control_feed(void); #endif diff --git a/sw/airborne/arch/stm32/subsystems/radio_control/ppm_arch.h b/sw/airborne/arch/stm32/subsystems/radio_control/ppm_arch.h index cf5252860d..c355884fcc 100644 --- a/sw/airborne/arch/stm32/subsystems/radio_control/ppm_arch.h +++ b/sw/airborne/arch/stm32/subsystems/radio_control/ppm_arch.h @@ -46,6 +46,4 @@ #define RC_PPM_SIGNED_TICKS_OF_USEC(_v) (int32_t)((_v)*RC_PPM_TICKS_PER_USEC) #define USEC_OF_RC_PPM_TICKS(_v) ((_v)/RC_PPM_TICKS_PER_USEC) -#define PPM_NB_CHANNEL RADIO_CONTROL_NB_CHANNEL - #endif /* PPM_ARCH_H */ diff --git a/sw/airborne/subsystems/radio_control.h b/sw/airborne/subsystems/radio_control.h index 6d0543d6e4..48ed0db5bd 100644 --- a/sw/airborne/subsystems/radio_control.h +++ b/sw/airborne/subsystems/radio_control.h @@ -30,10 +30,13 @@ /* underlying hardware, also include if RADIO_CONTROL is not defined for ap in dual mcu case */ #include RADIO_CONTROL_TYPE_H +/* RADIO_CONTROL_NB_CHANNEL needs to be defined to suitable default the implementation. + * If not all available channels are needed, can be overridden in airframe file. + */ + #if defined RADIO_CONTROL /* must be defined by underlying hardware */ extern void radio_control_impl_init(void); -/* RADIO_CONTROL_NB_CHANNEL has to be defined by the implementation */ /* timeouts - for now assumes 60Hz periodic */ #define RC_AVG_PERIOD 8 /* TODO remove if IIR filter is used */ diff --git a/sw/airborne/subsystems/radio_control/ppm.c b/sw/airborne/subsystems/radio_control/ppm.c index 5dc5effbba..b03cc0267c 100644 --- a/sw/airborne/subsystems/radio_control/ppm.c +++ b/sw/airborne/subsystems/radio_control/ppm.c @@ -28,7 +28,7 @@ #include "subsystems/radio_control.h" #include "subsystems/radio_control/ppm.h" -uint16_t ppm_pulses[ PPM_NB_CHANNEL ]; +uint16_t ppm_pulses[RADIO_CTL_NB]; volatile bool_t ppm_frame_available; /* @@ -60,12 +60,12 @@ static bool_t ppm_data_valid; static void send_ppm(struct transport_tx *trans, struct link_device *dev) { - uint16_t ppm_pulses_usec[RADIO_CONTROL_NB_CHANNEL]; - for (int i = 0; i < RADIO_CONTROL_NB_CHANNEL; i++) { + uint16_t ppm_pulses_usec[RADIO_CTL_NB]; + for (int i = 0; i < RADIO_CTL_NB; i++) { ppm_pulses_usec[i] = USEC_OF_RC_PPM_TICKS(ppm_pulses[i]); } pprz_msg_send_PPM(trans, dev, AC_ID, - &radio_control.frame_rate, PPM_NB_CHANNEL, ppm_pulses_usec); + &radio_control.frame_rate, RADIO_CTL_NB, ppm_pulses_usec); } #endif @@ -73,7 +73,7 @@ void radio_control_impl_init(void) { ppm_frame_available = FALSE; ppm_last_pulse_time = 0; - ppm_cur_pulse = RADIO_CONTROL_NB_CHANNEL; + ppm_cur_pulse = RADIO_CTL_NB; ppm_data_valid = FALSE; ppm_arch_init(); @@ -111,7 +111,7 @@ void ppm_decode_frame(uint32_t ppm_time) uint32_t length = ppm_time - ppm_last_pulse_time; ppm_last_pulse_time = ppm_time; - if (ppm_cur_pulse == PPM_NB_CHANNEL) { + if (ppm_cur_pulse == RADIO_CTL_NB) { if (length > RC_PPM_TICKS_OF_USEC(PPM_SYNC_MIN_LEN) && length < RC_PPM_TICKS_OF_USEC(PPM_SYNC_MAX_LEN)) { if (ppm_data_valid && RssiValid()) { @@ -127,11 +127,11 @@ void ppm_decode_frame(uint32_t ppm_time) length < RC_PPM_TICKS_OF_USEC(PPM_DATA_MAX_LEN)) { ppm_pulses[ppm_cur_pulse] = length; ppm_cur_pulse++; - if (ppm_cur_pulse == PPM_NB_CHANNEL) { + if (ppm_cur_pulse == RADIO_CTL_NB) { ppm_data_valid = TRUE; } } else { - ppm_cur_pulse = PPM_NB_CHANNEL; + ppm_cur_pulse = RADIO_CTL_NB; ppm_data_valid = FALSE; } } diff --git a/sw/airborne/subsystems/radio_control/ppm.h b/sw/airborne/subsystems/radio_control/ppm.h index e909400c2e..a912066544 100644 --- a/sw/airborne/subsystems/radio_control/ppm.h +++ b/sw/airborne/subsystems/radio_control/ppm.h @@ -24,6 +24,9 @@ #include "std.h" +/* in case you want to override RADIO_CONTROL_NB_CHANNEL */ +#include "generated/airframe.h" + /** * Architecture dependant code */ @@ -38,10 +41,11 @@ extern void ppm_arch_init(void); #include "generated/radio.h" /** - * Define number of channels - * Using generated code radio.h + * Default number of channels to actually use. */ +#ifndef RADIO_CONTROL_NB_CHANNEL #define RADIO_CONTROL_NB_CHANNEL RADIO_CTL_NB +#endif /** * ppm pulse type : futaba is falling edge clocked whereas JR is rising edge @@ -49,7 +53,7 @@ extern void ppm_arch_init(void); #define PPM_PULSE_TYPE_POSITIVE 0 #define PPM_PULSE_TYPE_NEGATIVE 1 -extern uint16_t ppm_pulses[ RADIO_CONTROL_NB_CHANNEL ]; +extern uint16_t ppm_pulses[RADIO_CTL_NB]; extern volatile bool_t ppm_frame_available; /** diff --git a/sw/airborne/subsystems/radio_control/sbus_common.h b/sw/airborne/subsystems/radio_control/sbus_common.h index 6e8067f183..ac1769164a 100644 --- a/sw/airborne/subsystems/radio_control/sbus_common.h +++ b/sw/airborne/subsystems/radio_control/sbus_common.h @@ -30,6 +30,9 @@ #include "std.h" #include "mcu_periph/uart.h" +/* in case you want to override RADIO_CONTROL_NB_CHANNEL */ +#include "generated/airframe.h" + /** * Macro to use radio.h file * @@ -57,7 +60,13 @@ */ #define SBUS_BUF_LENGTH 24 #define SBUS_NB_CHANNEL 16 + +/** + * Default number of channels to actually use. + */ +#ifndef RADIO_CONTROL_NB_CHANNEL #define RADIO_CONTROL_NB_CHANNEL SBUS_NB_CHANNEL +#endif /** * SBUS structure From 46714e9b6eac300f18c022f2becab263f6fbbb48 Mon Sep 17 00:00:00 2001 From: Felix Ruess Date: Thu, 20 Nov 2014 22:55:22 +0100 Subject: [PATCH 2/5] [radio_control] spektrum: copy only actually used channels to radio_control.values --- conf/conf_tests.xml | 2 +- .../arch/stm32/subsystems/radio_control/spektrum_arch.c | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/conf/conf_tests.xml b/conf/conf_tests.xml index 48b4cb6b1a..9808b0f09e 100644 --- a/conf/conf_tests.xml +++ b/conf/conf_tests.xml @@ -150,7 +150,7 @@ telemetry="telemetry/default_fixedwing_imu.xml" flight_plan="flight_plans/nav_modules.xml" settings="settings/fixedwing_basic.xml settings/control/ctl_basic.xml settings/control/ctl_dash_loiter_trim.xml" - settings_modules="modules/nav_smooth.xml" + settings_modules="modules/air_data.xml modules/nav_smooth.xml" gui_color="blue" /> Date: Thu, 20 Nov 2014 23:52:34 +0100 Subject: [PATCH 3/5] [radio_control] error if RADIO_CONTROL_NB_CHANNEL > max available channels --- sw/airborne/arch/sim/subsystems/radio_control/spektrum_arch.h | 4 ++++ .../arch/stm32/subsystems/radio_control/spektrum_arch.h | 4 ++++ sw/airborne/subsystems/radio_control/ppm.h | 4 ++++ sw/airborne/subsystems/radio_control/sbus_common.h | 4 ++++ sw/airborne/subsystems/radio_control/superbitrf_rc.h | 4 ++++ 5 files changed, 20 insertions(+) diff --git a/sw/airborne/arch/sim/subsystems/radio_control/spektrum_arch.h b/sw/airborne/arch/sim/subsystems/radio_control/spektrum_arch.h index 95f7b901e8..94239f7db9 100644 --- a/sw/airborne/arch/sim/subsystems/radio_control/spektrum_arch.h +++ b/sw/airborne/arch/sim/subsystems/radio_control/spektrum_arch.h @@ -34,6 +34,10 @@ #define RADIO_CONTROL_NB_CHANNEL 12 #endif +#if RADIO_CONTROL_NB_CHANNEL > 12 +#error "RADIO_CONTROL_NB_CHANNEL mustn't be higher than 12." +#endif + /* channel assignments */ #define RADIO_THROTTLE 0 #define RADIO_ROLL 1 diff --git a/sw/airborne/arch/stm32/subsystems/radio_control/spektrum_arch.h b/sw/airborne/arch/stm32/subsystems/radio_control/spektrum_arch.h index bf6a370580..1228086922 100644 --- a/sw/airborne/arch/stm32/subsystems/radio_control/spektrum_arch.h +++ b/sw/airborne/arch/stm32/subsystems/radio_control/spektrum_arch.h @@ -34,6 +34,10 @@ #define RADIO_CONTROL_NB_CHANNEL 12 #endif +#if RADIO_CONTROL_NB_CHANNEL > 12 +#error "RADIO_CONTROL_NB_CHANNEL mustn't be higher than 12." +#endif + /* default channel assignments */ #ifndef RADIO_THROTTLE #define RADIO_THROTTLE 0 diff --git a/sw/airborne/subsystems/radio_control/ppm.h b/sw/airborne/subsystems/radio_control/ppm.h index a912066544..022abb9d7c 100644 --- a/sw/airborne/subsystems/radio_control/ppm.h +++ b/sw/airborne/subsystems/radio_control/ppm.h @@ -47,6 +47,10 @@ extern void ppm_arch_init(void); #define RADIO_CONTROL_NB_CHANNEL RADIO_CTL_NB #endif +#if RADIO_CONTROL_NB_CHANNEL > RADIO_CTL_NB +#error "RADIO_CONTROL_NB_CHANNEL mustn't be higher than number of channels in radio file." +#endif + /** * ppm pulse type : futaba is falling edge clocked whereas JR is rising edge */ diff --git a/sw/airborne/subsystems/radio_control/sbus_common.h b/sw/airborne/subsystems/radio_control/sbus_common.h index ac1769164a..48b4476662 100644 --- a/sw/airborne/subsystems/radio_control/sbus_common.h +++ b/sw/airborne/subsystems/radio_control/sbus_common.h @@ -68,6 +68,10 @@ #define RADIO_CONTROL_NB_CHANNEL SBUS_NB_CHANNEL #endif +#if RADIO_CONTROL_NB_CHANNEL > SBUS_NB_CHANNEL +#error "RADIO_CONTROL_NB_CHANNEL mustn't be higher than 16." +#endif + /** * SBUS structure */ diff --git a/sw/airborne/subsystems/radio_control/superbitrf_rc.h b/sw/airborne/subsystems/radio_control/superbitrf_rc.h index d20458a0f7..ae91df2f52 100644 --- a/sw/airborne/subsystems/radio_control/superbitrf_rc.h +++ b/sw/airborne/subsystems/radio_control/superbitrf_rc.h @@ -33,6 +33,10 @@ #define RADIO_CONTROL_NB_CHANNEL 14 #endif +#if RADIO_CONTROL_NB_CHANNEL > 14 +#error "RADIO_CONTROL_NB_CHANNEL mustn't be higher than 14." +#endif + /* The channel ordering is always the same for DSM2 and DSMX */ #define RADIO_THROTTLE 0 #define RADIO_ROLL 1 From f38c5db2db2e9693bf72d6e1ae80e9c87c0dcc0e Mon Sep 17 00:00:00 2001 From: dewagter Date: Fri, 21 Nov 2014 14:21:59 +0100 Subject: [PATCH 4/5] [conf] Example that needs the RADIO_CONTROL_NB_CHANNEL --- conf/airframes/CDW/TwoSeas.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/conf/airframes/CDW/TwoSeas.xml b/conf/airframes/CDW/TwoSeas.xml index 71bcd57613..39a2c8d6bb 100644 --- a/conf/airframes/CDW/TwoSeas.xml +++ b/conf/airframes/CDW/TwoSeas.xml @@ -13,6 +13,7 @@ + From 7ae4ab3a6f209ed8d07d529afb60db7aadd2d9ab Mon Sep 17 00:00:00 2001 From: Felix Ruess Date: Fri, 28 Nov 2014 14:59:04 +0100 Subject: [PATCH 5/5] [stm32] spektrum: always decode up to 12 channels but only copy RADIO_CONTROL_NB_CHANNEL to radio_control.values --- .../arch/stm32/subsystems/radio_control/spektrum_arch.c | 4 ++-- .../arch/stm32/subsystems/radio_control/spektrum_arch.h | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/sw/airborne/arch/stm32/subsystems/radio_control/spektrum_arch.c b/sw/airborne/arch/stm32/subsystems/radio_control/spektrum_arch.c index a7b24a6ac2..57ea6cfed6 100644 --- a/sw/airborne/arch/stm32/subsystems/radio_control/spektrum_arch.c +++ b/sw/airborne/arch/stm32/subsystems/radio_control/spektrum_arch.c @@ -446,7 +446,7 @@ void RadioControlEventImp(void (*frame_handler)(void)) { case(0) : /* 10 bit */ ChannelNum = (ChannelData >> 10) & 0x0f; /* don't bother decoding unused channels */ - if (ChannelNum < RADIO_CONTROL_NB_CHANNEL) { + if (ChannelNum < SPEKTRUM_NB_CHANNEL) { SpektrumBuf[ChannelNum] = ChannelData & 0x3ff; SpektrumBuf[ChannelNum] -= 0x200; SpektrumBuf[ChannelNum] *= MAX_PPRZ/0x156; @@ -457,7 +457,7 @@ void RadioControlEventImp(void (*frame_handler)(void)) { case(1) : /* 11 bit */ ChannelNum = (ChannelData >> 11) & 0x0f; /* don't bother decoding unused channels */ - if (ChannelNum < RADIO_CONTROL_NB_CHANNEL) { + if (ChannelNum < SPEKTRUM_NB_CHANNEL) { SpektrumBuf[ChannelNum] = ChannelData & 0x7ff; SpektrumBuf[ChannelNum] -= 0x400; SpektrumBuf[ChannelNum] *= MAX_PPRZ/0x2AC; diff --git a/sw/airborne/arch/stm32/subsystems/radio_control/spektrum_arch.h b/sw/airborne/arch/stm32/subsystems/radio_control/spektrum_arch.h index 1228086922..a8e72e5c69 100644 --- a/sw/airborne/arch/stm32/subsystems/radio_control/spektrum_arch.h +++ b/sw/airborne/arch/stm32/subsystems/radio_control/spektrum_arch.h @@ -29,6 +29,7 @@ * have the same channel assignments. */ +#define SPEKTRUM_NB_CHANNEL 12 #ifndef RADIO_CONTROL_NB_CHANNEL #define RADIO_CONTROL_NB_CHANNEL 12