1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-02 10:24:11 +01:00

Added PPM input to the PipXtreme. Also added configurable GCSReceiver timeout.

This commit is contained in:
Brian Webb 2012-05-20 18:30:37 -07:00
parent bc9dcd415f
commit 2f1a9e3e7d
9 changed files with 161 additions and 77 deletions

View File

@ -353,7 +353,7 @@ uint8_t PHReceivePacket(PHInstHandle h, PHPacketHandle p, bool rx_error)
if (!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) if(data->status_handler)
data->status_handler((PHStatusPacketHandle)p); data->status_handler((PHStatusPacketHandle)p);

View File

@ -85,6 +85,7 @@ typedef struct {
xTaskHandle sendDataTaskHandle; xTaskHandle sendDataTaskHandle;
xTaskHandle radioStatusTaskHandle; xTaskHandle radioStatusTaskHandle;
xTaskHandle transparentCommTaskHandle; xTaskHandle transparentCommTaskHandle;
xTaskHandle ppmInputTaskHandle;
// The UAVTalk connection on the com side. // The UAVTalk connection on the com side.
UAVTalkConnection inUAVTalkCon; UAVTalkConnection inUAVTalkCon;
@ -135,6 +136,7 @@ static void sendPacketTask(void *parameters);
static void sendDataTask(void *parameters); static void sendDataTask(void *parameters);
static void transparentCommTask(void * parameters); static void transparentCommTask(void * parameters);
static void radioStatusTask(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 transmitData(uint8_t * data, int32_t length);
static int32_t transmitPacket(PHPacketHandle packet); static int32_t transmitPacket(PHPacketHandle packet);
static void receiveData(uint8_t *buf, uint8_t len); 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(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(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)); 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 #ifdef PIOS_INCLUDE_WDG
PIOS_WDG_RegisterFlag(PIOS_WDG_COMUAVTALK); PIOS_WDG_RegisterFlag(PIOS_WDG_COMUAVTALK);
if(PIOS_COM_TRANS_COM) 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_RADIORECEIVE);
PIOS_WDG_RegisterFlag(PIOS_WDG_SENDPACKET); PIOS_WDG_RegisterFlag(PIOS_WDG_SENDPACKET);
//PIOS_WDG_RegisterFlag(PIOS_WDG_SENDDATA); //PIOS_WDG_RegisterFlag(PIOS_WDG_SENDDATA);
if(PIOS_PPM_RECEIVER)
PIOS_WDG_RegisterFlag(PIOS_WDG_PPMINPUT);
#endif #endif
return 0; return 0;
} }
@ -679,9 +685,6 @@ static void transparentCommTask(void * parameters)
static void radioStatusTask(void *parameters) static void radioStatusTask(void *parameters)
{ {
PHStatusPacket status_packet; 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) { while (1) {
PipXStatusData pipxStatus; PipXStatusData pipxStatus;
@ -730,6 +733,9 @@ static void radioStatusTask(void *parameters)
if(cntr++ == RADIOSTATS_UPDATE_PERIOD_MS / STATS_UPDATE_PERIOD_MS) if(cntr++ == RADIOSTATS_UPDATE_PERIOD_MS / STATS_UPDATE_PERIOD_MS)
{ {
// Queue the status message // 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.source_id = pipxStatus.DeviceID;
status_packet.header.rssi = pipxStatus.RSSI; status_packet.header.rssi = pipxStatus.RSSI;
status_packet.retries = data->comTxRetries; 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. * Transmit data buffer to the com port.
* \param[in] buf Data buffer to send * \param[in] buf Data buffer to send

View File

@ -215,6 +215,7 @@ extern uint32_t pios_com_telem_usb_id;
//------------------------ //------------------------
#define PIOS_RCVR_MAX_DEVS 3 #define PIOS_RCVR_MAX_DEVS 3
#define PIOS_RCVR_MAX_CHANNELS 12 #define PIOS_RCVR_MAX_CHANNELS 12
#define PIOS_GCSRCVR_TIMEOUT_MS 100
//------------------------- //-------------------------
// Receiver PPM input // Receiver PPM input

View File

@ -76,6 +76,7 @@ TIM4 | RC In 1 | Servo 3 | Servo 2 | Servo 1
#define PIOS_WDG_SENDPACKET 0x0004 #define PIOS_WDG_SENDPACKET 0x0004
#define PIOS_WDG_SENDDATA 0x0008 #define PIOS_WDG_SENDDATA 0x0008
#define PIOS_WDG_TRANSCOMM 0x0010 #define PIOS_WDG_TRANSCOMM 0x0010
#define PIOS_WDG_PPMINPUT 0x0020
//------------------------ //------------------------
// TELEMETRY // 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_trans_com_id;
extern uint32_t pios_com_debug_id; extern uint32_t pios_com_debug_id;
extern uint32_t pios_com_rfm22b_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_USB_HID (pios_com_telem_usb_id)
#define PIOS_COM_TELEMETRY (pios_com_telemetry_id) #define PIOS_COM_TELEMETRY (pios_com_telemetry_id)
#define PIOS_COM_FLEXI (pios_com_flexi_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_DEBUG (pios_com_debug_id)
#define PIOS_COM_RADIO (pios_com_rfm22b_id) #define PIOS_COM_RADIO (pios_com_rfm22b_id)
#define PIOS_COM_TELEM_USB PIOS_COM_USB_HID #define PIOS_COM_TELEM_USB PIOS_COM_USB_HID
#define PIOS_PPM_RECEIVER (pios_ppm_rcvr_id)
#define DEBUG_LEVEL 2 #define DEBUG_LEVEL 2
#if DEBUG_LEVEL > 0 #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_DEVS 3
#define PIOS_RCVR_MAX_CHANNELS 12 #define PIOS_RCVR_MAX_CHANNELS 12
#define PIOS_GCSRCVR_TIMEOUT_MS 100
//------------------------- //-------------------------
// Receiver PPM input // Receiver PPM input
//------------------------- //-------------------------
#define PIOS_PPM_MAX_DEVS 1 #define PIOS_PPM_MAX_DEVS 1
#define PIOS_PPM_NUM_INPUTS 12 #define PIOS_PPM_NUM_INPUTS 12
#define PIOS_PPM_PACKET_UPDATE_PERIOD_MS 25
//-------------------------
// Receiver PWM input
//-------------------------
#define PIOS_PWM_MAX_DEVS 1
#define PIOS_PWM_NUM_INPUTS 1
//------------------------- //-------------------------
// Servo outputs // Servo outputs

View File

@ -152,10 +152,9 @@ static void PIOS_gcsrcvr_Supervisor(uint32_t gcsrcvr_id) {
} }
/* /*
* RTC runs at 625Hz so divide down the base rate so * RTC runs at 625Hz.
* that this loop runs at 25Hz.
*/ */
if(++(gcsrcvr_dev->supv_timer) < 25) { if(++(gcsrcvr_dev->supv_timer) < (PIOS_GCSRCVR_TIMEOUT_MS * 1000 / 625)) {
return; return;
} }
gcsrcvr_dev->supv_timer = 0; gcsrcvr_dev->supv_timer = 0;

View File

@ -44,7 +44,6 @@
/* Supported receiver interfaces */ /* Supported receiver interfaces */
#define PIOS_INCLUDE_PPM #define PIOS_INCLUDE_PPM
#define PIOS_INCLUDE_PWM
/* Supported USART-based PIOS modules */ /* Supported USART-based PIOS modules */
#define PIOS_INCLUDE_SPI #define PIOS_INCLUDE_SPI

View File

@ -57,6 +57,7 @@ uint32_t pios_com_trans_com_id = 0;
uint32_t pios_com_debug_id = 0; uint32_t pios_com_debug_id = 0;
uint32_t pios_com_rfm22b_id = 0; uint32_t pios_com_rfm22b_id = 0;
uint32_t pios_rfm22b_id = 0; uint32_t pios_rfm22b_id = 0;
uint32_t pios_ppm_rcvr_id = 0;
/** /**
* PIOS_Board_Init() * PIOS_Board_Init()
@ -243,9 +244,6 @@ void PIOS_Board_Init(void) {
} }
break; break;
} }
case PIPXSETTINGS_TELEMETRYCONFIG_PPM_IN:
case PIPXSETTINGS_TELEMETRYCONFIG_PPM_OUT:
case PIPXSETTINGS_TELEMETRYCONFIG_RSSI:
case PIPXSETTINGS_TELEMETRYCONFIG_DISABLED: case PIPXSETTINGS_TELEMETRYCONFIG_DISABLED:
break; break;
} }
@ -285,6 +283,16 @@ void PIOS_Board_Init(void) {
break; break;
} }
case PIPXSETTINGS_FLEXICONFIG_PPM_IN: 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_PPM_OUT:
case PIPXSETTINGS_FLEXICONFIG_RSSI: case PIPXSETTINGS_FLEXICONFIG_RSSI:
case PIPXSETTINGS_FLEXICONFIG_DISABLED: case PIPXSETTINGS_FLEXICONFIG_DISABLED:

View File

@ -236,6 +236,89 @@ void PIOS_ADC_handler() {
#endif /* PIOS_INCLUDE_ADC */ #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) #if defined(PIOS_INCLUDE_USART)
#include <pios_usart_priv.h> #include <pios_usart_priv.h>
@ -359,71 +442,29 @@ void PIOS_RTC_IRQ_Handler (void)
#endif #endif
#if defined(PIOS_INCLUDE_TIM) /*
* PPM Inputs
*/
#if defined(PIOS_INCLUDE_PPM)
#include <pios_ppm_priv.h>
#include "pios_tim_priv.h" const struct pios_ppm_cfg pios_ppm_cfg = {
.tim_ic_init = {
static const TIM_TimeBaseInitTypeDef tim_1_2_3_4_time_base = { .TIM_ICPolarity = TIM_ICPolarity_Rising,
.TIM_Prescaler = (PIOS_MASTER_CLOCK / 1000000) - 1, .TIM_ICSelection = TIM_ICSelection_DirectTI,
.TIM_ClockDivision = TIM_CKD_DIV1, .TIM_ICPrescaler = TIM_ICPSC_DIV1,
.TIM_CounterMode = TIM_CounterMode_Up, .TIM_ICFilter = 0x0,
.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,
},
}, },
.channels = &pios_tim_ppm_flexi_port,
.num_channels = 1,
}; };
static const struct pios_tim_clock_cfg tim_2_cfg = { #endif /* PIOS_INCLUDE_PPM */
.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 = { #if defined(PIOS_INCLUDE_RCVR)
.timer = TIM3, #include "pios_rcvr_priv.h"
.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 = { #endif /* PIOS_INCLUDE_RCVR */
.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 */
#if defined(PIOS_INCLUDE_USB) #if defined(PIOS_INCLUDE_USB)
#include "pios_usb_priv.h" #include "pios_usb_priv.h"

View File

@ -2,7 +2,7 @@
<object name="PipXSettings" singleinstance="true" settings="true"> <object name="PipXSettings" singleinstance="true" settings="true">
<description>PipXtreme configurations options.</description> <description>PipXtreme configurations options.</description>
<field name="PairID" units="" type="uint32" elements="1" defaultvalue="0"/> <field name="PairID" units="" type="uint32" elements="1" defaultvalue="0"/>
<field name="TelemetryConfig" units="function" type="enum" elements="1" options="Disabled,Serial,UAVTalk,PPM_In,PPM_Out,RSSI,Debug" defaultvalue="UAVTalk"/> <field name="TelemetryConfig" units="function" type="enum" elements="1" options="Disabled,Serial,UAVTalk,Debug" defaultvalue="UAVTalk"/>
<field name="TelemetrySpeed" units="bps" type="enum" elements="1" options="2400,4800,9600,19200,38400,57600,115200" defaultvalue="57600"/> <field name="TelemetrySpeed" units="bps" type="enum" elements="1" options="2400,4800,9600,19200,38400,57600,115200" defaultvalue="57600"/>
<field name="FlexiConfig" units="function" type="enum" elements="1" options="Disabled,Serial,UAVTalk,PPM_In,PPM_Out,RSSI,Debug" defaultvalue="Disabled"/> <field name="FlexiConfig" units="function" type="enum" elements="1" options="Disabled,Serial,UAVTalk,PPM_In,PPM_Out,RSSI,Debug" defaultvalue="Disabled"/>
<field name="FlexiSpeed" units="bps" type="enum" elements="1" options="2400,4800,9600,19200,38400,57600,115200" defaultvalue="57600"/> <field name="FlexiSpeed" units="bps" type="enum" elements="1" options="2400,4800,9600,19200,38400,57600,115200" defaultvalue="57600"/>