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

Fixed race condition on getting packets.

This commit is contained in:
Brian Webb 2012-05-15 19:38:14 -07:00
parent bb491b8a3f
commit 93ec7c11a6
6 changed files with 45 additions and 33 deletions

View File

@ -174,7 +174,10 @@ PHPacketHandle PHGetTXPacket(PHInstHandle h)
// Is the window full? // Is the window full?
uint8_t next_end = (data->tx_win_end + 1) % data->cfg.winSize; uint8_t next_end = (data->tx_win_end + 1) % data->cfg.winSize;
if(next_end == data->tx_win_start) if(next_end == data->tx_win_start)
{
xSemaphoreGiveRecursive(data->lock);
return NULL; return NULL;
}
data->tx_win_end = next_end; data->tx_win_end = next_end;
// Release lock // Release lock
@ -226,7 +229,11 @@ PHPacketHandle PHGetRXPacket(PHInstHandle h)
// Is the window full? // Is the window full?
uint8_t next_end = (data->rx_win_end + 1) % data->cfg.winSize; uint8_t next_end = (data->rx_win_end + 1) % data->cfg.winSize;
if(next_end == data->rx_win_start) if(next_end == data->rx_win_start)
{
// Release lock
xSemaphoreGiveRecursive(data->lock);
return NULL; return NULL;
}
data->rx_win_end = next_end; data->rx_win_end = next_end;
// Release lock // Release lock

View File

@ -50,11 +50,11 @@
// Private constants // Private constants
#define TEMP_BUFFER_SIZE 25 #define TEMP_BUFFER_SIZE 25
#define STACK_SIZE_BYTES 300 #define STACK_SIZE_BYTES 150
#define TASK_PRIORITY (tskIDLE_PRIORITY + 1) #define TASK_PRIORITY (tskIDLE_PRIORITY + 1)
#define BRIDGE_BUF_LEN 512 #define BRIDGE_BUF_LEN 512
#define MAX_RETRIES 2 #define MAX_RETRIES 2
#define REQ_TIMEOUT_MS 10 #define RETRY_TIMEOUT_MS 20
#define STATS_UPDATE_PERIOD_MS 2000 #define STATS_UPDATE_PERIOD_MS 2000
#define RADIOSTATS_UPDATE_PERIOD_MS 1000 #define RADIOSTATS_UPDATE_PERIOD_MS 1000
#define MAX_LOST_CONTACT_TIME 4 #define MAX_LOST_CONTACT_TIME 4
@ -159,13 +159,13 @@ static int32_t RadioComBridgeStart(void)
{ {
if(data) { if(data) {
// Start the tasks // Start the tasks
xTaskCreate(comUAVTalkTask, (signed char *)"ComUAVTalk", STACK_SIZE_BYTES/2, NULL, TASK_PRIORITY + 2, &(data->comUAVTalkTaskHandle)); xTaskCreate(comUAVTalkTask, (signed char *)"ComUAVTalk", STACK_SIZE_BYTES, NULL, TASK_PRIORITY + 2, &(data->comUAVTalkTaskHandle));
if(PIOS_COM_TRANS_COM) if(PIOS_COM_TRANS_COM)
xTaskCreate(transparentCommTask, (signed char *)"transparentComm", STACK_SIZE_BYTES/2, NULL, TASK_PRIORITY + 2, &(data->transparentCommTaskHandle)); xTaskCreate(transparentCommTask, (signed char *)"transparentComm", STACK_SIZE_BYTES, NULL, TASK_PRIORITY + 2, &(data->transparentCommTaskHandle));
xTaskCreate(radioReceiveTask, (signed char *)"RadioReceive", STACK_SIZE_BYTES/2, NULL, TASK_PRIORITY, &(data->radioReceiveTaskHandle)); xTaskCreate(radioReceiveTask, (signed char *)"RadioReceive", STACK_SIZE_BYTES, NULL, TASK_PRIORITY+ 2, &(data->radioReceiveTaskHandle));
xTaskCreate(sendPacketTask, (signed char *)"SendPacketTask", STACK_SIZE_BYTES/2, NULL, TASK_PRIORITY, &(data->sendPacketTaskHandle)); xTaskCreate(sendPacketTask, (signed char *)"SendPacketTask", STACK_SIZE_BYTES, NULL, TASK_PRIORITY + 2, &(data->sendPacketTaskHandle));
xTaskCreate(sendDataTask, (signed char *)"SendDataTask", STACK_SIZE_BYTES/2, NULL, TASK_PRIORITY, &(data->sendDataTaskHandle)); xTaskCreate(sendDataTask, (signed char *)"SendDataTask", STACK_SIZE_BYTES, NULL, TASK_PRIORITY+ 2, &(data->sendDataTaskHandle));
xTaskCreate(radioStatusTask, (signed char *)"RadioStatus", STACK_SIZE_BYTES/2, NULL, TASK_PRIORITY, &(data->radioStatusTaskHandle)); xTaskCreate(radioStatusTask, (signed char *)"RadioStatus", STACK_SIZE_BYTES, NULL, TASK_PRIORITY, &(data->radioStatusTaskHandle));
#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)
@ -268,7 +268,7 @@ static void comUAVTalkTask(void *parameters)
// Receive from USB HID if available, otherwise UAVTalk com if it's available. // Receive from USB HID if available, otherwise UAVTalk com if it's available.
#if defined(PIOS_INCLUDE_USB) #if defined(PIOS_INCLUDE_USB)
// Determine input port (USB takes priority over telemetry port) // Determine input port (USB takes priority over telemetry port)
if (PIOS_USB_CheckAvailable(0) && PIOS_COM_USB_HID) if (PIOS_USB_CheckAvailable(0))
BufferedReadSetCom(f, PIOS_COM_USB_HID); BufferedReadSetCom(f, PIOS_COM_USB_HID);
else else
#endif /* PIOS_INCLUDE_USB */ #endif /* PIOS_INCLUDE_USB */
@ -322,8 +322,8 @@ static void comUAVTalkTask(void *parameters)
UAVTalkConnectionData *connection = (UAVTalkConnectionData*)(data->inUAVTalkCon); UAVTalkConnectionData *connection = (UAVTalkConnectionData*)(data->inUAVTalkCon);
UAVTalkInputProcessor *iproc = &(connection->iproc); UAVTalkInputProcessor *iproc = &(connection->iproc);
if (state == UAVTALK_STATE_COMPLETE) { if (state == UAVTALK_STATE_COMPLETE)
{
// Is this a local UAVObject? // Is this a local UAVObject?
if (iproc->obj != NULL) if (iproc->obj != NULL)
{ {
@ -475,6 +475,7 @@ static void radioReceiveTask(void *parameters)
// Get a RX packet from the packet handler if required. // Get a RX packet from the packet handler if required.
if (p == NULL) if (p == NULL)
p = PHGetRXPacket(pios_packet_handler); p = PHGetRXPacket(pios_packet_handler);
if(p == NULL) { if(p == NULL) {
DEBUG_PRINTF(2, "RX Packet Unavailable.!\n\r"); DEBUG_PRINTF(2, "RX Packet Unavailable.!\n\r");
// Wait a bit for a packet to come available. // Wait a bit for a packet to come available.
@ -519,7 +520,8 @@ static void sendPacketTask(void *parameters)
// Wait for a packet on the queue. // Wait for a packet on the queue.
if (xQueueReceive(data->sendPacketQueue, &p, MAX_PORT_DELAY) == pdTRUE) { if (xQueueReceive(data->sendPacketQueue, &p, MAX_PORT_DELAY) == pdTRUE) {
// Send the packet. // Send the packet.
PHTransmitPacket(pios_packet_handler, p); if(!PHTransmitPacket(pios_packet_handler, p))
PHReleaseTXPacket(pios_packet_handler, p);
} }
} }
} }
@ -547,7 +549,7 @@ static void sendDataTask(void *parameters)
uint32_t retries = 0; uint32_t retries = 0;
int32_t success = -1; int32_t success = -1;
while (retries < MAX_RETRIES && success == -1) { while (retries < MAX_RETRIES && success == -1) {
success = UAVTalkSendObject(data->outUAVTalkCon, ev.obj, 0, 0, REQ_TIMEOUT_MS); success = UAVTalkSendObject(data->outUAVTalkCon, ev.obj, 0, 0, RETRY_TIMEOUT_MS);
++retries; ++retries;
} }
data->comTxRetries += retries; data->comTxRetries += retries;

View File

@ -59,7 +59,7 @@
#define PIOS_INCLUDE_GPIO #define PIOS_INCLUDE_GPIO
#define PIOS_INCLUDE_EXTI #define PIOS_INCLUDE_EXTI
#define PIOS_INCLUDE_RTC #define PIOS_INCLUDE_RTC
#define PIOS_INCLUDE_WDG //#define PIOS_INCLUDE_WDG
#define PIOS_INCLUDE_BL_HELPER #define PIOS_INCLUDE_BL_HELPER
#define PIOS_INCLUDE_FLASH_EEPROM #define PIOS_INCLUDE_FLASH_EEPROM

27
flight/PipXtreme/System/pios_board.c Executable file → Normal file
View File

@ -94,7 +94,7 @@ void PIOS_Board_Init(void) {
#endif /* PIOS_INCLUDE_LED */ #endif /* PIOS_INCLUDE_LED */
PipXSettingsData pipxSettings; PipXSettingsData pipxSettings;
#if defined(PIOS_INCLUDE_FLASH_EEPROM) #if defined(PIOS_INCLUDE_FLASH_EEPROM__NOT)
PIOS_EEPROM_Init(&pios_eeprom_cfg); PIOS_EEPROM_Init(&pios_eeprom_cfg);
/* Read the settings from flash. */ /* Read the settings from flash. */
@ -126,10 +126,23 @@ void PIOS_Board_Init(void) {
/* Initialize board specific USB data */ /* Initialize board specific USB data */
PIOS_USB_BOARD_DATA_Init(); PIOS_USB_BOARD_DATA_Init();
bool usb_cdc_present = false;
#if defined(PIOS_INCLUDE_USB_CDC) #if defined(PIOS_INCLUDE_USB_CDC)
switch (pipxSettings.VCPConfig)
{
case PIPXSETTINGS_VCPCONFIG_SERIAL:
case PIPXSETTINGS_VCPCONFIG_DEBUG:
if (PIOS_USB_DESC_HID_CDC_Init()) { if (PIOS_USB_DESC_HID_CDC_Init()) {
PIOS_Assert(0); PIOS_Assert(0);
} }
usb_cdc_present = true;
break;
case PIPXSETTINGS_VCPCONFIG_DISABLED:
if (PIOS_USB_DESC_HID_ONLY_Init()) {
PIOS_Assert(0);
}
break;
}
#else #else
if (PIOS_USB_DESC_HID_ONLY_Init()) { if (PIOS_USB_DESC_HID_ONLY_Init()) {
PIOS_Assert(0); PIOS_Assert(0);
@ -142,10 +155,7 @@ void PIOS_Board_Init(void) {
#if defined(PIOS_INCLUDE_USB_CDC) #if defined(PIOS_INCLUDE_USB_CDC)
#if defined(PIOS_INCLUDE_COM) #if defined(PIOS_INCLUDE_COM)
switch (pipxSettings.VCPConfig) if(usb_cdc_present)
{
case PIPXSETTINGS_VCPCONFIG_SERIAL:
case PIPXSETTINGS_VCPCONFIG_DEBUG:
{ {
uint32_t pios_usb_cdc_id; uint32_t pios_usb_cdc_id;
if (PIOS_USB_CDC_Init(&pios_usb_cdc_id, &pios_usb_cdc_cfg, pios_usb_id)) { if (PIOS_USB_CDC_Init(&pios_usb_cdc_id, &pios_usb_cdc_cfg, pios_usb_id)) {
@ -165,17 +175,10 @@ void PIOS_Board_Init(void) {
case PIPXSETTINGS_VCPCONFIG_SERIAL: case PIPXSETTINGS_VCPCONFIG_SERIAL:
pios_com_trans_com_id = pios_com_vcp_id; pios_com_trans_com_id = pios_com_vcp_id;
break; break;
case PIPXSETTINGS_VCPCONFIG_UAVTALK:
pios_com_uavtalk_com_id = pios_com_vcp_id;
break;
case PIPXSETTINGS_VCPCONFIG_DEBUG: case PIPXSETTINGS_VCPCONFIG_DEBUG:
pios_com_debug_id = pios_com_vcp_id; pios_com_debug_id = pios_com_vcp_id;
break; break;
} }
break;
}
case PIPXSETTINGS_VCPCONFIG_DISABLED:
break;
} }
#endif /* PIOS_INCLUDE_COM */ #endif /* PIOS_INCLUDE_COM */

View File

@ -463,7 +463,7 @@ static const struct pios_usb_cfg pios_usb_main_cfg = {
#include <pios_usb_hid_priv.h> #include <pios_usb_hid_priv.h>
const struct pios_usb_hid_cfg pios_usb_hid_cfg = { const struct pios_usb_hid_cfg pios_usb_hid_cfg = {
.data_if = 2, .data_if = 0,
.data_rx_ep = 1, .data_rx_ep = 1,
.data_tx_ep = 1, .data_tx_ep = 1,
}; };
@ -473,10 +473,10 @@ const struct pios_usb_hid_cfg pios_usb_hid_cfg = {
#include <pios_usb_cdc_priv.h> #include <pios_usb_cdc_priv.h>
const struct pios_usb_cdc_cfg pios_usb_cdc_cfg = { const struct pios_usb_cdc_cfg pios_usb_cdc_cfg = {
.ctrl_if = 0, .ctrl_if = 1,
.ctrl_tx_ep = 2, .ctrl_tx_ep = 2,
.data_if = 1, .data_if = 2,
.data_rx_ep = 3, .data_rx_ep = 3,
.data_tx_ep = 3, .data_tx_ep = 3,
}; };

View File

@ -6,7 +6,7 @@
<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"/>
<field name="VCPConfig" units="function" type="enum" elements="1" options="Disabled,Serial,UAVTalk,Debug" defaultvalue="Disabled"/> <field name="VCPConfig" units="function" type="enum" elements="1" options="Disabled,Serial,Debug" defaultvalue="Disabled"/>
<field name="VCPSpeed" units="bps" type="enum" elements="1" options="2400,4800,9600,19200,38400,57600,115200" defaultvalue="57600"/> <field name="VCPSpeed" units="bps" type="enum" elements="1" options="2400,4800,9600,19200,38400,57600,115200" defaultvalue="57600"/>
<field name="RFSpeed" units="bps" type="enum" elements="1" options="2400,4800,9600,19200,38400,57600,115200" defaultvalue="115200"/> <field name="RFSpeed" units="bps" type="enum" elements="1" options="2400,4800,9600,19200,38400,57600,115200" defaultvalue="115200"/>
<field name="MaxRFPower" units="mW" type="enum" elements="1" options="1.25,1.6,3.16,6.3,12.6,25,50,100" defaultvalue="100"/> <field name="MaxRFPower" units="mW" type="enum" elements="1" options="1.25,1.6,3.16,6.3,12.6,25,50,100" defaultvalue="100"/>