From 2f1a9e3e7dab2f4cfffa296ffdc3ad58f1a780a3 Mon Sep 17 00:00:00 2001 From: Brian Webb Date: Sun, 20 May 2012 18:30:37 -0700 Subject: [PATCH] Added PPM input to the PipXtreme. Also added configurable GCSReceiver timeout. --- flight/Libraries/packet_handler.c | 2 +- .../Modules/RadioComBridge/RadioComBridge.c | 43 ++++- flight/PiOS/Boards/STM32103CB_CC_Rev1.h | 1 + .../PiOS/Boards/STM32103CB_PIPXTREME_Rev1.h | 11 +- flight/PiOS/Common/pios_gcsrcvr.c | 5 +- flight/PipXtreme/System/inc/pios_config.h | 1 - flight/PipXtreme/System/pios_board.c | 14 +- .../board_hw_defs/pipxtreme/board_hw_defs.c | 159 +++++++++++------- shared/uavobjectdefinition/pipxsettings.xml | 2 +- 9 files changed, 161 insertions(+), 77 deletions(-) diff --git a/flight/Libraries/packet_handler.c b/flight/Libraries/packet_handler.c index 83d79990c..fc78764db 100644 --- a/flight/Libraries/packet_handler.c +++ b/flight/Libraries/packet_handler.c @@ -353,7 +353,7 @@ uint8_t PHReceivePacket(PHInstHandle h, PHPacketHandle p, bool rx_error) if (!rx_error) - // Pass on the channels to the PPM handler. + // Pass on the channels to the status handler. if(data->status_handler) data->status_handler((PHStatusPacketHandle)p); diff --git a/flight/Modules/RadioComBridge/RadioComBridge.c b/flight/Modules/RadioComBridge/RadioComBridge.c index df5d17790..5797f4189 100644 --- a/flight/Modules/RadioComBridge/RadioComBridge.c +++ b/flight/Modules/RadioComBridge/RadioComBridge.c @@ -85,6 +85,7 @@ typedef struct { xTaskHandle sendDataTaskHandle; xTaskHandle radioStatusTaskHandle; xTaskHandle transparentCommTaskHandle; + xTaskHandle ppmInputTaskHandle; // The UAVTalk connection on the com side. UAVTalkConnection inUAVTalkCon; @@ -135,6 +136,7 @@ static void sendPacketTask(void *parameters); static void sendDataTask(void *parameters); static void transparentCommTask(void * parameters); static void radioStatusTask(void *parameters); +static void ppmInputTask(void *parameters); static int32_t transmitData(uint8_t * data, int32_t length); static int32_t transmitPacket(PHPacketHandle packet); static void receiveData(uint8_t *buf, uint8_t len); @@ -166,6 +168,8 @@ static int32_t RadioComBridgeStart(void) xTaskCreate(sendPacketTask, (signed char *)"SendPacketTask", STACK_SIZE_BYTES, NULL, TASK_PRIORITY + 2, &(data->sendPacketTaskHandle)); xTaskCreate(sendDataTask, (signed char *)"SendDataTask", STACK_SIZE_BYTES, NULL, TASK_PRIORITY+ 2, &(data->sendDataTaskHandle)); xTaskCreate(radioStatusTask, (signed char *)"RadioStatus", STACK_SIZE_BYTES, NULL, TASK_PRIORITY, &(data->radioStatusTaskHandle)); + if(PIOS_PPM_RECEIVER) + xTaskCreate(ppmInputTask, (signed char *)"PPMInputTask", STACK_SIZE_BYTES, NULL, TASK_PRIORITY + 2, &(data->ppmInputTaskHandle)); #ifdef PIOS_INCLUDE_WDG PIOS_WDG_RegisterFlag(PIOS_WDG_COMUAVTALK); if(PIOS_COM_TRANS_COM) @@ -173,6 +177,8 @@ static int32_t RadioComBridgeStart(void) PIOS_WDG_RegisterFlag(PIOS_WDG_RADIORECEIVE); PIOS_WDG_RegisterFlag(PIOS_WDG_SENDPACKET); //PIOS_WDG_RegisterFlag(PIOS_WDG_SENDDATA); + if(PIOS_PPM_RECEIVER) + PIOS_WDG_RegisterFlag(PIOS_WDG_PPMINPUT); #endif return 0; } @@ -679,9 +685,6 @@ static void transparentCommTask(void * parameters) static void radioStatusTask(void *parameters) { PHStatusPacket status_packet; - status_packet.header.destination_id = 0xffffffff; - status_packet.header.type = PACKET_TYPE_STATUS; - status_packet.header.data_size = PH_STATUS_DATA_SIZE(&status_packet); while (1) { PipXStatusData pipxStatus; @@ -730,6 +733,9 @@ static void radioStatusTask(void *parameters) if(cntr++ == RADIOSTATS_UPDATE_PERIOD_MS / STATS_UPDATE_PERIOD_MS) { // Queue the status message + status_packet.header.destination_id = 0xffffffff; + status_packet.header.type = PACKET_TYPE_STATUS; + status_packet.header.data_size = PH_STATUS_DATA_SIZE(&status_packet); status_packet.header.source_id = pipxStatus.DeviceID; status_packet.header.rssi = pipxStatus.RSSI; status_packet.retries = data->comTxRetries; @@ -747,6 +753,37 @@ static void radioStatusTask(void *parameters) } } +/** + * The PPM input task. + */ +static void ppmInputTask(void *parameters) +{ + PHPpmPacket ppm_packet; + PHPacketHandle pph = (PHPacketHandle)&ppm_packet; + + while (1) { + +#ifdef PIOS_INCLUDE_WDG + // Update the watchdog timer. + PIOS_WDG_UpdateFlag(PIOS_WDG_PPMINPUT); +#endif /* PIOS_INCLUDE_WDG */ + + // Send the PPM packet + for (uint8_t i = 1; i <= PIOS_PPM_NUM_INPUTS; ++i) + ppm_packet.channels[i - 1] = PIOS_RCVR_Read(PIOS_PPM_RECEIVER, i); + + // Send the packet. + ppm_packet.header.destination_id = data->destination_id; + ppm_packet.header.source_id = PIOS_RFM22B_DeviceID(pios_rfm22b_id); + ppm_packet.header.type = PACKET_TYPE_PPM; + ppm_packet.header.data_size = PH_PPM_DATA_SIZE(&ppm_packet); + xQueueSend(data->sendPacketQueue, &pph, MAX_PORT_DELAY); + + // Delay until the next update period. + vTaskDelay(PIOS_PPM_PACKET_UPDATE_PERIOD_MS / portTICK_RATE_MS); + } +} + /** * Transmit data buffer to the com port. * \param[in] buf Data buffer to send diff --git a/flight/PiOS/Boards/STM32103CB_CC_Rev1.h b/flight/PiOS/Boards/STM32103CB_CC_Rev1.h index fd391c46c..18d977cf4 100644 --- a/flight/PiOS/Boards/STM32103CB_CC_Rev1.h +++ b/flight/PiOS/Boards/STM32103CB_CC_Rev1.h @@ -215,6 +215,7 @@ extern uint32_t pios_com_telem_usb_id; //------------------------ #define PIOS_RCVR_MAX_DEVS 3 #define PIOS_RCVR_MAX_CHANNELS 12 +#define PIOS_GCSRCVR_TIMEOUT_MS 100 //------------------------- // Receiver PPM input diff --git a/flight/PiOS/Boards/STM32103CB_PIPXTREME_Rev1.h b/flight/PiOS/Boards/STM32103CB_PIPXTREME_Rev1.h index d3af05861..868bba722 100755 --- a/flight/PiOS/Boards/STM32103CB_PIPXTREME_Rev1.h +++ b/flight/PiOS/Boards/STM32103CB_PIPXTREME_Rev1.h @@ -76,6 +76,7 @@ TIM4 | RC In 1 | Servo 3 | Servo 2 | Servo 1 #define PIOS_WDG_SENDPACKET 0x0004 #define PIOS_WDG_SENDDATA 0x0008 #define PIOS_WDG_TRANSCOMM 0x0010 +#define PIOS_WDG_PPMINPUT 0x0020 //------------------------ // TELEMETRY @@ -159,6 +160,7 @@ extern uint32_t pios_com_uavtalk_com_id; extern uint32_t pios_com_trans_com_id; extern uint32_t pios_com_debug_id; extern uint32_t pios_com_rfm22b_id; +extern uint32_t pios_ppm_rcvr_id; #define PIOS_COM_USB_HID (pios_com_telem_usb_id) #define PIOS_COM_TELEMETRY (pios_com_telemetry_id) #define PIOS_COM_FLEXI (pios_com_flexi_id) @@ -168,6 +170,7 @@ extern uint32_t pios_com_rfm22b_id; #define PIOS_COM_DEBUG (pios_com_debug_id) #define PIOS_COM_RADIO (pios_com_rfm22b_id) #define PIOS_COM_TELEM_USB PIOS_COM_USB_HID +#define PIOS_PPM_RECEIVER (pios_ppm_rcvr_id) #define DEBUG_LEVEL 2 #if DEBUG_LEVEL > 0 @@ -221,18 +224,14 @@ extern uint32_t pios_com_rfm22b_id; //------------------------ #define PIOS_RCVR_MAX_DEVS 3 #define PIOS_RCVR_MAX_CHANNELS 12 +#define PIOS_GCSRCVR_TIMEOUT_MS 100 //------------------------- // Receiver PPM input //------------------------- #define PIOS_PPM_MAX_DEVS 1 #define PIOS_PPM_NUM_INPUTS 12 - -//------------------------- -// Receiver PWM input -//------------------------- -#define PIOS_PWM_MAX_DEVS 1 -#define PIOS_PWM_NUM_INPUTS 1 +#define PIOS_PPM_PACKET_UPDATE_PERIOD_MS 25 //------------------------- // Servo outputs diff --git a/flight/PiOS/Common/pios_gcsrcvr.c b/flight/PiOS/Common/pios_gcsrcvr.c index ad34b5c20..eda2a94ed 100644 --- a/flight/PiOS/Common/pios_gcsrcvr.c +++ b/flight/PiOS/Common/pios_gcsrcvr.c @@ -152,10 +152,9 @@ static void PIOS_gcsrcvr_Supervisor(uint32_t gcsrcvr_id) { } /* - * RTC runs at 625Hz so divide down the base rate so - * that this loop runs at 25Hz. + * RTC runs at 625Hz. */ - if(++(gcsrcvr_dev->supv_timer) < 25) { + if(++(gcsrcvr_dev->supv_timer) < (PIOS_GCSRCVR_TIMEOUT_MS * 1000 / 625)) { return; } gcsrcvr_dev->supv_timer = 0; diff --git a/flight/PipXtreme/System/inc/pios_config.h b/flight/PipXtreme/System/inc/pios_config.h index 39d51ef1d..a94b2af89 100755 --- a/flight/PipXtreme/System/inc/pios_config.h +++ b/flight/PipXtreme/System/inc/pios_config.h @@ -44,7 +44,6 @@ /* Supported receiver interfaces */ #define PIOS_INCLUDE_PPM -#define PIOS_INCLUDE_PWM /* Supported USART-based PIOS modules */ #define PIOS_INCLUDE_SPI diff --git a/flight/PipXtreme/System/pios_board.c b/flight/PipXtreme/System/pios_board.c index 37bf5c2c1..28c21f40b 100644 --- a/flight/PipXtreme/System/pios_board.c +++ b/flight/PipXtreme/System/pios_board.c @@ -57,6 +57,7 @@ uint32_t pios_com_trans_com_id = 0; uint32_t pios_com_debug_id = 0; uint32_t pios_com_rfm22b_id = 0; uint32_t pios_rfm22b_id = 0; +uint32_t pios_ppm_rcvr_id = 0; /** * PIOS_Board_Init() @@ -243,9 +244,6 @@ void PIOS_Board_Init(void) { } break; } - case PIPXSETTINGS_TELEMETRYCONFIG_PPM_IN: - case PIPXSETTINGS_TELEMETRYCONFIG_PPM_OUT: - case PIPXSETTINGS_TELEMETRYCONFIG_RSSI: case PIPXSETTINGS_TELEMETRYCONFIG_DISABLED: break; } @@ -285,6 +283,16 @@ void PIOS_Board_Init(void) { break; } case PIPXSETTINGS_FLEXICONFIG_PPM_IN: +#if defined(PIOS_INCLUDE_PPM) + { + uint32_t pios_ppm_id; + PIOS_PPM_Init(&pios_ppm_id, &pios_ppm_cfg); + + if (PIOS_RCVR_Init(&pios_ppm_rcvr_id, &pios_ppm_rcvr_driver, pios_ppm_id)) { + PIOS_Assert(0); + } + } +#endif /* PIOS_INCLUDE_PPM */ case PIPXSETTINGS_FLEXICONFIG_PPM_OUT: case PIPXSETTINGS_FLEXICONFIG_RSSI: case PIPXSETTINGS_FLEXICONFIG_DISABLED: diff --git a/flight/board_hw_defs/pipxtreme/board_hw_defs.c b/flight/board_hw_defs/pipxtreme/board_hw_defs.c index 3572ff9b7..e68154181 100644 --- a/flight/board_hw_defs/pipxtreme/board_hw_defs.c +++ b/flight/board_hw_defs/pipxtreme/board_hw_defs.c @@ -236,6 +236,89 @@ void PIOS_ADC_handler() { #endif /* PIOS_INCLUDE_ADC */ +#if defined(PIOS_INCLUDE_TIM) + +#include "pios_tim_priv.h" + +static const TIM_TimeBaseInitTypeDef tim_1_2_3_4_time_base = { + .TIM_Prescaler = (PIOS_MASTER_CLOCK / 1000000) - 1, + .TIM_ClockDivision = TIM_CKD_DIV1, + .TIM_CounterMode = TIM_CounterMode_Up, + .TIM_Period = ((1000000 / PIOS_SERVO_UPDATE_HZ) - 1), + .TIM_RepetitionCounter = 0x0000, +}; + +static const struct pios_tim_clock_cfg tim_1_cfg = { + .timer = TIM1, + .time_base_init = &tim_1_2_3_4_time_base, + .irq = { + .init = { + .NVIC_IRQChannel = TIM1_CC_IRQn, + .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID, + .NVIC_IRQChannelSubPriority = 0, + .NVIC_IRQChannelCmd = ENABLE, + }, + }, +}; + +static const struct pios_tim_clock_cfg tim_2_cfg = { + .timer = TIM2, + .time_base_init = &tim_1_2_3_4_time_base, + .irq = { + .init = { + .NVIC_IRQChannel = TIM2_IRQn, + .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID, + .NVIC_IRQChannelSubPriority = 0, + .NVIC_IRQChannelCmd = ENABLE, + }, + }, +}; + +static const struct pios_tim_clock_cfg tim_3_cfg = { + .timer = TIM3, + .time_base_init = &tim_1_2_3_4_time_base, + .irq = { + .init = { + .NVIC_IRQChannel = TIM3_IRQn, + .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID, + .NVIC_IRQChannelSubPriority = 0, + .NVIC_IRQChannelCmd = ENABLE, + }, + }, +}; + +static const struct pios_tim_clock_cfg tim_4_cfg = { + .timer = TIM4, + .time_base_init = &tim_1_2_3_4_time_base, + .irq = { + .init = { + .NVIC_IRQChannel = TIM4_IRQn, + .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID, + .NVIC_IRQChannelSubPriority = 0, + .NVIC_IRQChannelCmd = ENABLE, + }, + }, +}; + +static const struct pios_tim_channel pios_tim_ppm_flexi_port = { + //.timer = TIM2, + .timer = TIM4, + //.timer_chan = TIM_Channel_4, + .timer_chan = TIM_Channel_4, + .pin = { + .gpio = GPIOB, + .init = { + //.GPIO_Pin = GPIO_Pin_11, + .GPIO_Pin = GPIO_Pin_9, + .GPIO_Mode = GPIO_Mode_IPD, + .GPIO_Speed = GPIO_Speed_2MHz, + }, + }, + //.remap = GPIO_PartialRemap_TIM2, +}; + +#endif /* PIOS_INCLUDE_TIM */ + #if defined(PIOS_INCLUDE_USART) #include @@ -359,71 +442,29 @@ void PIOS_RTC_IRQ_Handler (void) #endif -#if defined(PIOS_INCLUDE_TIM) +/* + * PPM Inputs + */ +#if defined(PIOS_INCLUDE_PPM) +#include -#include "pios_tim_priv.h" - -static const TIM_TimeBaseInitTypeDef tim_1_2_3_4_time_base = { - .TIM_Prescaler = (PIOS_MASTER_CLOCK / 1000000) - 1, - .TIM_ClockDivision = TIM_CKD_DIV1, - .TIM_CounterMode = TIM_CounterMode_Up, - .TIM_Period = ((1000000 / PIOS_SERVO_UPDATE_HZ) - 1), - .TIM_RepetitionCounter = 0x0000, -}; - -static const struct pios_tim_clock_cfg tim_1_cfg = { - .timer = TIM1, - .time_base_init = &tim_1_2_3_4_time_base, - .irq = { - .init = { - .NVIC_IRQChannel = TIM1_CC_IRQn, - .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID, - .NVIC_IRQChannelSubPriority = 0, - .NVIC_IRQChannelCmd = ENABLE, - }, +const struct pios_ppm_cfg pios_ppm_cfg = { + .tim_ic_init = { + .TIM_ICPolarity = TIM_ICPolarity_Rising, + .TIM_ICSelection = TIM_ICSelection_DirectTI, + .TIM_ICPrescaler = TIM_ICPSC_DIV1, + .TIM_ICFilter = 0x0, }, + .channels = &pios_tim_ppm_flexi_port, + .num_channels = 1, }; -static const struct pios_tim_clock_cfg tim_2_cfg = { - .timer = TIM2, - .time_base_init = &tim_1_2_3_4_time_base, - .irq = { - .init = { - .NVIC_IRQChannel = TIM2_IRQn, - .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID, - .NVIC_IRQChannelSubPriority = 0, - .NVIC_IRQChannelCmd = ENABLE, - }, - }, -}; +#endif /* PIOS_INCLUDE_PPM */ -static const struct pios_tim_clock_cfg tim_3_cfg = { - .timer = TIM3, - .time_base_init = &tim_1_2_3_4_time_base, - .irq = { - .init = { - .NVIC_IRQChannel = TIM3_IRQn, - .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID, - .NVIC_IRQChannelSubPriority = 0, - .NVIC_IRQChannelCmd = ENABLE, - }, - }, -}; +#if defined(PIOS_INCLUDE_RCVR) +#include "pios_rcvr_priv.h" -static const struct pios_tim_clock_cfg tim_4_cfg = { - .timer = TIM4, - .time_base_init = &tim_1_2_3_4_time_base, - .irq = { - .init = { - .NVIC_IRQChannel = TIM4_IRQn, - .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID, - .NVIC_IRQChannelSubPriority = 0, - .NVIC_IRQChannelCmd = ENABLE, - }, - }, -}; - -#endif /* PIOS_INCLUDE_TIM */ +#endif /* PIOS_INCLUDE_RCVR */ #if defined(PIOS_INCLUDE_USB) #include "pios_usb_priv.h" diff --git a/shared/uavobjectdefinition/pipxsettings.xml b/shared/uavobjectdefinition/pipxsettings.xml index 745945866..a8899ff47 100644 --- a/shared/uavobjectdefinition/pipxsettings.xml +++ b/shared/uavobjectdefinition/pipxsettings.xml @@ -2,7 +2,7 @@ PipXtreme configurations options. - +