mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-04-10 02:02:21 +02:00
OP-932: Fixes vitual com port and (not tested) raw comms over a UART on the OPLink.
This commit is contained in:
parent
3aa828788d
commit
80cef9dbcc
@ -71,6 +71,7 @@ typedef struct {
|
|||||||
|
|
||||||
// The task handles.
|
// The task handles.
|
||||||
xTaskHandle telemetryTxTaskHandle;
|
xTaskHandle telemetryTxTaskHandle;
|
||||||
|
xTaskHandle telemetryRxTaskHandle;
|
||||||
xTaskHandle radioRxTaskHandle;
|
xTaskHandle radioRxTaskHandle;
|
||||||
xTaskHandle radioTxTaskHandle;
|
xTaskHandle radioTxTaskHandle;
|
||||||
|
|
||||||
@ -103,6 +104,7 @@ typedef struct {
|
|||||||
// Private functions
|
// Private functions
|
||||||
|
|
||||||
static void telemetryTxTask(void *parameters);
|
static void telemetryTxTask(void *parameters);
|
||||||
|
static void telemetryRxTask(void *parameters);
|
||||||
static void radioRxTask(void *parameters);
|
static void radioRxTask(void *parameters);
|
||||||
static void radioTxTask(void *parameters);
|
static void radioTxTask(void *parameters);
|
||||||
static int32_t UAVTalkSendHandler(uint8_t *buf, int32_t length);
|
static int32_t UAVTalkSendHandler(uint8_t *buf, int32_t length);
|
||||||
@ -172,26 +174,38 @@ static int32_t RadioComBridgeStart(void)
|
|||||||
|
|
||||||
// Set the frequency range.
|
// Set the frequency range.
|
||||||
PIOS_RFM22B_SetFrequencyRange(pios_rfm22b_id, oplinkSettings.MinFrequency, oplinkSettings.MaxFrequency, oplinkSettings.ChannelSpacing);
|
PIOS_RFM22B_SetFrequencyRange(pios_rfm22b_id, oplinkSettings.MinFrequency, oplinkSettings.MaxFrequency, oplinkSettings.ChannelSpacing);
|
||||||
|
|
||||||
// Reinitilize the modem.
|
// Reinitilize the modem.
|
||||||
PIOS_RFM22B_Reinit(pios_rfm22b_id);
|
PIOS_RFM22B_Reinit(pios_rfm22b_id);
|
||||||
|
|
||||||
|
// We will not parse/send UAVTalk if any ports are configured as Serial (except for over the USB HID port).
|
||||||
|
data->parseUAVTalk = ((oplinkSettings.MainPort != OPLINKSETTINGS_MAINPORT_SERIAL) &&
|
||||||
|
(oplinkSettings.FlexiPort != OPLINKSETTINGS_FLEXIPORT_SERIAL) &&
|
||||||
|
(oplinkSettings.VCPPort != OPLINKSETTINGS_VCPPORT_SERIAL));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the initial frequency.
|
// Set the initial frequency.
|
||||||
PIOS_RFM22B_SetInitialFrequency(pios_rfm22b_id, oplinkSettings.InitFrequency);
|
PIOS_RFM22B_SetInitialFrequency(pios_rfm22b_id, oplinkSettings.InitFrequency);
|
||||||
|
|
||||||
// Start the primary tasks for receiving/sending UAVTalk packets from the GCS.
|
// Start the primary tasks for receiving/sending UAVTalk packets from the GCS.
|
||||||
xTaskCreate(telemetryTxTask, (signed char *)"telemTxTask", STACK_SIZE_BYTES, NULL, TASK_PRIORITY, &(data->telemetryTxTaskHandle));
|
xTaskCreate(telemetryTxTask, (signed char *)"telemetryTxTask", STACK_SIZE_BYTES, NULL, TASK_PRIORITY, &(data->telemetryTxTaskHandle));
|
||||||
|
xTaskCreate(telemetryRxTask, (signed char *)"telemetryRxTask", STACK_SIZE_BYTES, NULL, TASK_PRIORITY, &(data->telemetryRxTaskHandle));
|
||||||
xTaskCreate(radioRxTask, (signed char *)"radioRxTask", STACK_SIZE_BYTES, NULL, TASK_PRIORITY, &(data->radioRxTaskHandle));
|
xTaskCreate(radioRxTask, (signed char *)"radioRxTask", STACK_SIZE_BYTES, NULL, TASK_PRIORITY, &(data->radioRxTaskHandle));
|
||||||
xTaskCreate(radioTxTask, (signed char *)"radioTxTask", STACK_SIZE_BYTES, NULL, TASK_PRIORITY, &(data->radioTxTaskHandle));
|
|
||||||
|
|
||||||
// Register the watchdog timers.
|
// Register the watchdog timers.
|
||||||
#ifdef PIOS_INCLUDE_WDG
|
#ifdef PIOS_INCLUDE_WDG
|
||||||
PIOS_WDG_RegisterFlag(PIOS_WDG_TELEMETRY);
|
PIOS_WDG_RegisterFlag(PIOS_WDG_TELEMETRYTX);
|
||||||
|
PIOS_WDG_RegisterFlag(PIOS_WDG_TELEMETRYRX);
|
||||||
PIOS_WDG_RegisterFlag(PIOS_WDG_RADIORX);
|
PIOS_WDG_RegisterFlag(PIOS_WDG_RADIORX);
|
||||||
PIOS_WDG_RegisterFlag(PIOS_WDG_RADIOTX);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// If we're doing raw comms, we need to have another thread that relays data from the com port to the radio.
|
||||||
|
if (!data->parseUAVTalk) {
|
||||||
|
xTaskCreate(radioTxTask, (signed char *)"radioTxTask", STACK_SIZE_BYTES, NULL, TASK_PRIORITY, &(data->radioTxTaskHandle));
|
||||||
|
#ifdef PIOS_INCLUDE_WDG
|
||||||
|
PIOS_WDG_RegisterFlag(PIOS_WDG_RADIOTX);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -234,7 +248,7 @@ static int32_t RadioComBridgeInitialize(void)
|
|||||||
data->comTxErrors = 0;
|
data->comTxErrors = 0;
|
||||||
data->comTxRetries = 0;
|
data->comTxRetries = 0;
|
||||||
data->UAVTalkErrors = 0;
|
data->UAVTalkErrors = 0;
|
||||||
data->parseUAVTalk = false;
|
data->parseUAVTalk = true;
|
||||||
data->configured = false;
|
data->configured = false;
|
||||||
data->comSpeed = OPLINKSETTINGS_COMSPEED_9600;
|
data->comSpeed = OPLINKSETTINGS_COMSPEED_9600;
|
||||||
PIOS_COM_RADIO = PIOS_COM_RFM22B;
|
PIOS_COM_RADIO = PIOS_COM_RFM22B;
|
||||||
@ -255,7 +269,7 @@ static void telemetryTxTask(void *parameters)
|
|||||||
// Loop forever
|
// Loop forever
|
||||||
while (1) {
|
while (1) {
|
||||||
#ifdef PIOS_INCLUDE_WDG
|
#ifdef PIOS_INCLUDE_WDG
|
||||||
PIOS_WDG_UpdateFlag(PIOS_WDG_TELEMETRY);
|
PIOS_WDG_UpdateFlag(PIOS_WDG_TELEMETRYTX);
|
||||||
#endif
|
#endif
|
||||||
// Wait for queue message
|
// Wait for queue message
|
||||||
if (xQueueReceive(data->uavtalkEventQueue, &ev, MAX_PORT_DELAY) == pdTRUE) {
|
if (xQueueReceive(data->uavtalkEventQueue, &ev, MAX_PORT_DELAY) == pdTRUE) {
|
||||||
@ -309,17 +323,22 @@ static void radioRxTask(void *parameters)
|
|||||||
uint8_t serial_data[1];
|
uint8_t serial_data[1];
|
||||||
uint16_t bytes_to_process = PIOS_COM_ReceiveBuffer(PIOS_COM_RADIO, serial_data, sizeof(serial_data), MAX_PORT_DELAY);
|
uint16_t bytes_to_process = PIOS_COM_ReceiveBuffer(PIOS_COM_RADIO, serial_data, sizeof(serial_data), MAX_PORT_DELAY);
|
||||||
if (bytes_to_process > 0) {
|
if (bytes_to_process > 0) {
|
||||||
for (uint8_t i = 0; i < bytes_to_process; i++) {
|
// Either pass the data through the UAVTalk parser, or just send it to the radio (if we're doing raw comms).
|
||||||
if (UAVTalkRelayInputStream(data->outUAVTalkCon, serial_data[i]) == UAVTALK_STATE_ERROR) {
|
if (data->parseUAVTalk) {
|
||||||
data->UAVTalkErrors++;
|
for (uint8_t i = 0; i < bytes_to_process; i++) {
|
||||||
|
if (UAVTalkRelayInputStream(data->outUAVTalkCon, serial_data[i]) == UAVTALK_STATE_ERROR) {
|
||||||
|
data->UAVTalkErrors++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else if (PIOS_COM_TELEMETRY) {
|
||||||
|
PIOS_COM_SendBufferNonBlocking(PIOS_COM_TELEMETRY, serial_data, bytes_to_process);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Radio rx task. Receive data from a com port and pass it on to the radio.
|
* Radio tx task. Receive data packets from the com port and send to the radio.
|
||||||
*
|
*
|
||||||
* @param[in] parameters The task parameters
|
* @param[in] parameters The task parameters
|
||||||
*/
|
*/
|
||||||
@ -327,10 +346,38 @@ static void radioTxTask(void *parameters)
|
|||||||
{
|
{
|
||||||
// Task loop
|
// Task loop
|
||||||
while (1) {
|
while (1) {
|
||||||
uint32_t inputPort = PIOS_COM_TELEMETRY;
|
|
||||||
#ifdef PIOS_INCLUDE_WDG
|
#ifdef PIOS_INCLUDE_WDG
|
||||||
PIOS_WDG_UpdateFlag(PIOS_WDG_RADIOTX);
|
PIOS_WDG_UpdateFlag(PIOS_WDG_RADIOTX);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Wait until the com port is available.
|
||||||
|
if (!PIOS_COM_TELEMETRY) {
|
||||||
|
vTaskDelay(5);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read from the com port.
|
||||||
|
uint8_t serial_data[1];
|
||||||
|
uint16_t bytes_to_process = PIOS_COM_ReceiveBuffer(PIOS_COM_TELEMETRY, serial_data, sizeof(serial_data), MAX_PORT_DELAY);
|
||||||
|
if (bytes_to_process > 0) {
|
||||||
|
PIOS_COM_SendBufferNonBlocking(PIOS_COM_RADIO, serial_data, bytes_to_process);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Receive telemetry from the USB/COM port.
|
||||||
|
*
|
||||||
|
* @param[in] parameters The task parameters
|
||||||
|
*/
|
||||||
|
static void telemetryRxTask(void *parameters)
|
||||||
|
{
|
||||||
|
// Task loop
|
||||||
|
while (1) {
|
||||||
|
uint32_t inputPort = data->parseUAVTalk ? PIOS_COM_TELEMETRY : 0;
|
||||||
|
#ifdef PIOS_INCLUDE_WDG
|
||||||
|
PIOS_WDG_UpdateFlag(PIOS_WDG_TELEMETRYRX);
|
||||||
|
#endif
|
||||||
#if defined(PIOS_INCLUDE_USB)
|
#if defined(PIOS_INCLUDE_USB)
|
||||||
// Determine output port (USB takes priority over telemetry port)
|
// Determine output port (USB takes priority over telemetry port)
|
||||||
if (PIOS_USB_CheckAvailable(0) && PIOS_COM_TELEM_USB_HID) {
|
if (PIOS_USB_CheckAvailable(0) && PIOS_COM_TELEM_USB_HID) {
|
||||||
@ -360,7 +407,7 @@ static void radioTxTask(void *parameters)
|
|||||||
*/
|
*/
|
||||||
static int32_t UAVTalkSendHandler(uint8_t *buf, int32_t length)
|
static int32_t UAVTalkSendHandler(uint8_t *buf, int32_t length)
|
||||||
{
|
{
|
||||||
uint32_t outputPort = PIOS_COM_TELEMETRY;
|
uint32_t outputPort = data->parseUAVTalk ? PIOS_COM_TELEMETRY : 0;
|
||||||
#if defined(PIOS_INCLUDE_USB)
|
#if defined(PIOS_INCLUDE_USB)
|
||||||
// Determine output port (USB takes priority over telemetry port)
|
// Determine output port (USB takes priority over telemetry port)
|
||||||
if (PIOS_COM_TELEM_USB_HID && PIOS_COM_Available(PIOS_COM_TELEM_USB_HID)) {
|
if (PIOS_COM_TELEM_USB_HID && PIOS_COM_Available(PIOS_COM_TELEM_USB_HID)) {
|
||||||
@ -604,7 +651,6 @@ static void updateSettings()
|
|||||||
bool is_coordinator = PIOS_RFM22B_IsCoordinator(pios_rfm22b_id);
|
bool is_coordinator = PIOS_RFM22B_IsCoordinator(pios_rfm22b_id);
|
||||||
switch (oplinkSettings.MainPort) {
|
switch (oplinkSettings.MainPort) {
|
||||||
case OPLINKSETTINGS_MAINPORT_TELEMETRY:
|
case OPLINKSETTINGS_MAINPORT_TELEMETRY:
|
||||||
data->parseUAVTalk = true;
|
|
||||||
case OPLINKSETTINGS_MAINPORT_SERIAL:
|
case OPLINKSETTINGS_MAINPORT_SERIAL:
|
||||||
/* Configure the main port for uart serial */
|
/* Configure the main port for uart serial */
|
||||||
PIOS_InitUartMainPort();
|
PIOS_InitUartMainPort();
|
||||||
@ -620,7 +666,6 @@ static void updateSettings()
|
|||||||
// Configure the flexi port
|
// Configure the flexi port
|
||||||
switch (oplinkSettings.FlexiPort) {
|
switch (oplinkSettings.FlexiPort) {
|
||||||
case OPLINKSETTINGS_FLEXIPORT_TELEMETRY:
|
case OPLINKSETTINGS_FLEXIPORT_TELEMETRY:
|
||||||
data->parseUAVTalk = true;
|
|
||||||
case OPLINKSETTINGS_FLEXIPORT_SERIAL:
|
case OPLINKSETTINGS_FLEXIPORT_SERIAL:
|
||||||
/* Configure the flexi port as uart serial */
|
/* Configure the flexi port as uart serial */
|
||||||
PIOS_InitUartFlexiPort();
|
PIOS_InitUartFlexiPort();
|
||||||
|
@ -2294,7 +2294,6 @@ static enum pios_radio_event rfm22_receiveAck(struct pios_rfm22b_dev *rfm22b_dev
|
|||||||
portTickType local_tx_time = rfm22_coordinatorTime(rfm22b_dev, rfm22b_dev->tx_complete_ticks);
|
portTickType local_tx_time = rfm22_coordinatorTime(rfm22b_dev, rfm22b_dev->tx_complete_ticks);
|
||||||
portTickType remote_rx_time = aph->packet_recv_time;
|
portTickType remote_rx_time = aph->packet_recv_time;
|
||||||
// Adjust the time delta based on the difference between our estimated time offset and the coordinator offset.
|
// Adjust the time delta based on the difference between our estimated time offset and the coordinator offset.
|
||||||
// This is not working yet
|
|
||||||
rfm22b_dev->time_delta += remote_rx_time - local_tx_time;
|
rfm22b_dev->time_delta += remote_rx_time - local_tx_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,16 +9,8 @@ BOARD := STM32103CB_OPLINKMINI
|
|||||||
MODEL := MD
|
MODEL := MD
|
||||||
MODEL_SUFFIX := _PX
|
MODEL_SUFFIX := _PX
|
||||||
|
|
||||||
OPENOCD_CONFIG := stm32f1x.cfg
|
OPENOCD_JTAG_CONFIG := stlink-v2.cfg
|
||||||
|
OPENOCD_CONFIG := stm32f1x.stlink.cfg
|
||||||
OPENOCD_JTAG_CONFIG := foss-jtag.revb.cfg
|
|
||||||
OPENOCD_CONFIG := stm32f1x.cfg
|
|
||||||
|
|
||||||
OPENOCD_JTAG_CONFIG := foss-jtag.revb.cfg
|
|
||||||
OPENOCD_CONFIG := stm32f1x.cfg
|
|
||||||
|
|
||||||
OPENOCD_JTAG_CONFIG := foss-jtag.revb.cfg
|
|
||||||
OPENOCD_CONFIG := stm32f1x.cfg
|
|
||||||
|
|
||||||
# Note: These must match the values in link_$(BOARD)_memory.ld
|
# Note: These must match the values in link_$(BOARD)_memory.ld
|
||||||
BL_BANK_BASE := 0x08000000 # Start of bootloader flash
|
BL_BANK_BASE := 0x08000000 # Start of bootloader flash
|
||||||
|
@ -71,10 +71,11 @@ TIM4 | RC In 1 | Servo 3 | Servo 2 | Servo 1
|
|||||||
//------------------------
|
//------------------------
|
||||||
#define PIOS_WATCHDOG_TIMEOUT 500
|
#define PIOS_WATCHDOG_TIMEOUT 500
|
||||||
#define PIOS_WDG_REGISTER BKP_DR4
|
#define PIOS_WDG_REGISTER BKP_DR4
|
||||||
#define PIOS_WDG_TELEMETRY 0x0001
|
#define PIOS_WDG_TELEMETRYTX 0x0001
|
||||||
#define PIOS_WDG_RADIORX 0x0002
|
#define PIOS_WDG_TELEMETRYRX 0x0002
|
||||||
#define PIOS_WDG_RADIOTX 0x0004
|
#define PIOS_WDG_RADIOTX 0x0004
|
||||||
#define PIOS_WDG_RFM22B 0x0008
|
#define PIOS_WDG_RADIORX 0x0008
|
||||||
|
#define PIOS_WDG_RFM22B 0x0016
|
||||||
|
|
||||||
//------------------------
|
//------------------------
|
||||||
// TELEMETRY
|
// TELEMETRY
|
||||||
|
Loading…
x
Reference in New Issue
Block a user