From 586af77267caf6140671066b8180724415a3f9cb Mon Sep 17 00:00:00 2001 From: Brian Webb Date: Sun, 10 Jul 2016 21:09:09 -0700 Subject: [PATCH] LP-190: Fixes an issue with uninitialized OPLink receiver channels. --- flight/modules/RadioComBridge/RadioComBridge.c | 2 +- flight/pios/common/pios_rfm22b.c | 12 +++++++----- flight/pios/inc/pios_rfm22b.h | 4 ++-- .../targets/boards/revolution/firmware/pios_board.c | 5 ++--- flight/targets/boards/sparky2/firmware/pios_board.c | 5 ++--- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/flight/modules/RadioComBridge/RadioComBridge.c b/flight/modules/RadioComBridge/RadioComBridge.c index 5d1b9d261..a9b4c70ae 100644 --- a/flight/modules/RadioComBridge/RadioComBridge.c +++ b/flight/modules/RadioComBridge/RadioComBridge.c @@ -486,7 +486,7 @@ static void PPMInputTask(__attribute__((unused)) void *parameters) } // Pass the channel values to the radio device. - PIOS_RFM22B_PPMSet(pios_rfm22b_id, channels); + PIOS_RFM22B_PPMSet(pios_rfm22b_id, channels, RFM22B_PPM_NUM_CHANNELS); } } diff --git a/flight/pios/common/pios_rfm22b.c b/flight/pios/common/pios_rfm22b.c index 70c8be75f..1bc83015a 100644 --- a/flight/pios/common/pios_rfm22b.c +++ b/flight/pios/common/pios_rfm22b.c @@ -1105,8 +1105,9 @@ void PIOS_RFM22B_SetPPMCallback(uint32_t rfm22b_id, PPMReceivedCallback cb) * * @param[in] rfm22b_dev The RFM22B device ID. * @param[in] channels The PPM channel values. + * @param[out] nchan The number of channels to set. */ -extern void PIOS_RFM22B_PPMSet(uint32_t rfm22b_id, int16_t *channels) +extern void PIOS_RFM22B_PPMSet(uint32_t rfm22b_id, int16_t *channels, uint8_t nchan) { struct pios_rfm22b_dev *rfm22b_dev = (struct pios_rfm22b_dev *)rfm22b_id; @@ -1115,7 +1116,7 @@ extern void PIOS_RFM22B_PPMSet(uint32_t rfm22b_id, int16_t *channels) } for (uint8_t i = 0; i < RFM22B_PPM_NUM_CHANNELS; ++i) { - rfm22b_dev->ppm[i] = channels[i]; + rfm22b_dev->ppm[i] = (i < nchan) ? channels[i] : PIOS_RCVR_INVALID; } } @@ -1124,8 +1125,9 @@ extern void PIOS_RFM22B_PPMSet(uint32_t rfm22b_id, int16_t *channels) * * @param[in] rfm22b_dev The RFM22B device structure pointer. * @param[out] channels The PPM channel values. + * @param[out] nchan The number of channels to get. */ -extern void PIOS_RFM22B_PPMGet(uint32_t rfm22b_id, int16_t *channels) +extern void PIOS_RFM22B_PPMGet(uint32_t rfm22b_id, int16_t *channels, uint8_t nchan) { struct pios_rfm22b_dev *rfm22b_dev = (struct pios_rfm22b_dev *)rfm22b_id; @@ -1141,8 +1143,8 @@ extern void PIOS_RFM22B_PPMGet(uint32_t rfm22b_id, int16_t *channels) return; } - for (uint8_t i = 0; i < RFM22B_PPM_NUM_CHANNELS; ++i) { - channels[i] = rfm22b_dev->ppm[i]; + for (uint8_t i = 0; i < nchan; ++i) { + channels[i] = (i < RFM22B_PPM_NUM_CHANNELS) ? rfm22b_dev->ppm[i] : PIOS_RCVR_INVALID; } } diff --git a/flight/pios/inc/pios_rfm22b.h b/flight/pios/inc/pios_rfm22b.h index 4274b4751..16dd460b2 100644 --- a/flight/pios/inc/pios_rfm22b.h +++ b/flight/pios/inc/pios_rfm22b.h @@ -117,8 +117,8 @@ extern bool PIOS_RFM22B_TransmitPacket(uint32_t rfm22b_id, uint8_t *p, uint8_t l extern pios_rfm22b_int_result PIOS_RFM22B_ProcessTx(uint32_t rfm22b_id); extern pios_rfm22b_int_result PIOS_RFM22B_ProcessRx(uint32_t rfm22b_id); extern void PIOS_RFM22B_SetPPMCallback(uint32_t rfm22b_id, PPMReceivedCallback cb); -extern void PIOS_RFM22B_PPMSet(uint32_t rfm22b_id, int16_t *channels); -extern void PIOS_RFM22B_PPMGet(uint32_t rfm22b_id, int16_t *channels); +extern void PIOS_RFM22B_PPMSet(uint32_t rfm22b_id, int16_t *channels, uint8_t nchan); +extern void PIOS_RFM22B_PPMGet(uint32_t rfm22b_id, int16_t *channels, uint8_t nchan); /* Global Variables */ extern const struct pios_com_driver pios_rfm22b_com_driver; diff --git a/flight/targets/boards/revolution/firmware/pios_board.c b/flight/targets/boards/revolution/firmware/pios_board.c index e83038424..c6a25cd8d 100644 --- a/flight/targets/boards/revolution/firmware/pios_board.c +++ b/flight/targets/boards/revolution/firmware/pios_board.c @@ -368,11 +368,10 @@ static void PIOS_Board_configure_ppm(const struct pios_ppm_cfg *ppm_cfg) static void PIOS_Board_PPM_callback(const int16_t *channels) { - uint8_t max_chan = (RFM22B_PPM_NUM_CHANNELS < OPLINKRECEIVER_CHANNEL_NUMELEM) ? RFM22B_PPM_NUM_CHANNELS : OPLINKRECEIVER_CHANNEL_NUMELEM; OPLinkReceiverData opl_rcvr; - for (uint8_t i = 0; i < max_chan; ++i) { - opl_rcvr.Channel[i] = channels[i]; + for (uint8_t i = 0; i < OPLINKRECEIVER_CHANNEL_NUMELEM; ++i) { + opl_rcvr.Channel[i] = (i < RFM22B_PPM_NUM_CHANNELS) ? channels[i] : PIOS_RCVR_TIMEOUT; } OPLinkReceiverSet(&opl_rcvr); } diff --git a/flight/targets/boards/sparky2/firmware/pios_board.c b/flight/targets/boards/sparky2/firmware/pios_board.c index 4477ff1a9..8d1524fd3 100644 --- a/flight/targets/boards/sparky2/firmware/pios_board.c +++ b/flight/targets/boards/sparky2/firmware/pios_board.c @@ -368,11 +368,10 @@ static void PIOS_Board_configure_hott(const struct pios_usart_cfg *usart_cfg, en static void PIOS_Board_PPM_callback(const int16_t *channels) { - uint8_t max_chan = (RFM22B_PPM_NUM_CHANNELS < OPLINKRECEIVER_CHANNEL_NUMELEM) ? RFM22B_PPM_NUM_CHANNELS : OPLINKRECEIVER_CHANNEL_NUMELEM; OPLinkReceiverData opl_rcvr; - for (uint8_t i = 0; i < max_chan; ++i) { - opl_rcvr.Channel[i] = channels[i]; + for (uint8_t i = 0; i < OPLINKRECEIVER_CHANNEL_NUMELEM; ++i) { + opl_rcvr.Channel[i] = (i < RFM22B_PPM_NUM_CHANNELS) ? channels[i] : PIOS_RCVR_TIMEOUT; } OPLinkReceiverSet(&opl_rcvr); }