mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-12-03 11:24:10 +01:00
The overosync module now uses pios_com interface.
This commit is contained in:
parent
8fc2d10ea6
commit
6b3e5573a0
@ -55,27 +55,17 @@ static bool overoEnabled;
|
|||||||
// Private functions
|
// Private functions
|
||||||
static void overoSyncTask(void *parameters);
|
static void overoSyncTask(void *parameters);
|
||||||
static int32_t packData(uint8_t * data, int32_t length);
|
static int32_t packData(uint8_t * data, int32_t length);
|
||||||
static void transmitDataDone(uint32_t error_counter);
|
|
||||||
static void registerObject(UAVObjHandle obj);
|
static void registerObject(UAVObjHandle obj);
|
||||||
|
|
||||||
struct dma_transaction {
|
// External variables
|
||||||
uint8_t tx_buffer[OVEROSYNC_PACKET_SIZE] __attribute__ ((aligned(4)));
|
extern uint32_t pios_com_overo_id;
|
||||||
uint8_t rx_buffer[OVEROSYNC_PACKET_SIZE] __attribute__ ((aligned(4)));
|
extern uint32_t pios_overo_id;
|
||||||
};
|
|
||||||
|
|
||||||
struct overosync {
|
struct overosync {
|
||||||
struct dma_transaction transactions[2];
|
|
||||||
uint32_t active_transaction_id;
|
|
||||||
uint32_t loading_transaction_id;
|
|
||||||
xSemaphoreHandle buffer_lock;
|
|
||||||
uint32_t packets;
|
|
||||||
uint32_t sent_bytes;
|
uint32_t sent_bytes;
|
||||||
uint32_t write_pointer;
|
|
||||||
uint32_t sent_objects;
|
uint32_t sent_objects;
|
||||||
uint32_t failed_objects;
|
uint32_t failed_objects;
|
||||||
uint32_t received_objects;
|
uint32_t received_objects;
|
||||||
uint32_t framesync_error;
|
|
||||||
uint32_t underrun_error;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct overosync *overosync;
|
struct overosync *overosync;
|
||||||
@ -132,16 +122,7 @@ int32_t OveroSyncStart(void)
|
|||||||
if(overosync == NULL)
|
if(overosync == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
overosync->buffer_lock = xSemaphoreCreateMutex();
|
|
||||||
if(overosync->buffer_lock == NULL)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
overosync->active_transaction_id = 0;
|
|
||||||
overosync->loading_transaction_id = 0;
|
|
||||||
overosync->write_pointer = 0;
|
|
||||||
overosync->sent_bytes = 0;
|
overosync->sent_bytes = 0;
|
||||||
overosync->framesync_error = 0;
|
|
||||||
overosync->packets = 0;
|
|
||||||
|
|
||||||
// Process all registered objects and connect queue for updates
|
// Process all registered objects and connect queue for updates
|
||||||
UAVObjIterate(®isterObject);
|
UAVObjIterate(®isterObject);
|
||||||
@ -192,22 +173,13 @@ static void overoSyncTask(void *parameters)
|
|||||||
portTickType lastUpdateTime = xTaskGetTickCount();
|
portTickType lastUpdateTime = xTaskGetTickCount();
|
||||||
portTickType updateTime;
|
portTickType updateTime;
|
||||||
|
|
||||||
// Set the comms callback
|
|
||||||
PIOS_Overo_SetCallback(transmitDataDone);
|
|
||||||
|
|
||||||
// Loop forever
|
// Loop forever
|
||||||
while (1) {
|
while (1) {
|
||||||
// Wait for queue message
|
// Wait for queue message
|
||||||
if (xQueueReceive(queue, &ev, portMAX_DELAY) == pdTRUE) {
|
if (xQueueReceive(queue, &ev, portMAX_DELAY) == pdTRUE) {
|
||||||
|
|
||||||
// Check it will fit before packetizing
|
|
||||||
if ((overosync->write_pointer + UAVObjGetNumBytes(ev.obj) + 12) >=
|
|
||||||
sizeof(overosync->transactions[overosync->loading_transaction_id].tx_buffer)) {
|
|
||||||
overosync->failed_objects ++;
|
|
||||||
} else {
|
|
||||||
// Process event. This calls transmitData
|
// Process event. This calls transmitData
|
||||||
UAVTalkSendObject(uavTalkCon, ev.obj, ev.instId, false, 0);
|
UAVTalkSendObject(uavTalkCon, ev.obj, ev.instId, false, 0);
|
||||||
}
|
|
||||||
|
|
||||||
updateTime = xTaskGetTickCount();
|
updateTime = xTaskGetTickCount();
|
||||||
if(((portTickType) (updateTime - lastUpdateTime)) > 1000) {
|
if(((portTickType) (updateTime - lastUpdateTime)) > 1000) {
|
||||||
@ -217,14 +189,14 @@ static void overoSyncTask(void *parameters)
|
|||||||
syncStats.Received = 0;
|
syncStats.Received = 0;
|
||||||
syncStats.Connected = syncStats.Send > 500 ? OVEROSYNCSTATS_CONNECTED_TRUE : OVEROSYNCSTATS_CONNECTED_FALSE;
|
syncStats.Connected = syncStats.Send > 500 ? OVEROSYNCSTATS_CONNECTED_TRUE : OVEROSYNCSTATS_CONNECTED_FALSE;
|
||||||
syncStats.DroppedUpdates = overosync->failed_objects;
|
syncStats.DroppedUpdates = overosync->failed_objects;
|
||||||
syncStats.FramesyncErrors = overosync->framesync_error;
|
syncStats.Packets = PIOS_OVERO_GetPacketCount(pios_overo_id);
|
||||||
syncStats.Packets = overosync->packets;
|
|
||||||
syncStats.UnderrunErrors = overosync->underrun_error;
|
|
||||||
OveroSyncStatsSet(&syncStats);
|
OveroSyncStatsSet(&syncStats);
|
||||||
overosync->failed_objects = 0;
|
overosync->failed_objects = 0;
|
||||||
overosync->sent_bytes = 0;
|
overosync->sent_bytes = 0;
|
||||||
lastUpdateTime = updateTime;
|
lastUpdateTime = updateTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Check the receive buffer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -238,69 +210,20 @@ static void overoSyncTask(void *parameters)
|
|||||||
*/
|
*/
|
||||||
static int32_t packData(uint8_t * data, int32_t length)
|
static int32_t packData(uint8_t * data, int32_t length)
|
||||||
{
|
{
|
||||||
uint8_t *tx_buffer;
|
|
||||||
|
|
||||||
portTickType tickTime = xTaskGetTickCount();
|
portTickType tickTime = xTaskGetTickCount();
|
||||||
|
|
||||||
// Get the lock for manipulating the buffer
|
if( PIOS_COM_SendBuffer(pios_com_overo_id, (uint8_t *) &tickTime, sizeof(tickTime)) != 0)
|
||||||
xSemaphoreTake(overosync->buffer_lock, portMAX_DELAY);
|
goto fail;
|
||||||
|
if( PIOS_COM_SendBuffer(pios_com_overo_id, data, length) != 0)
|
||||||
|
goto fail;
|
||||||
|
|
||||||
// Check this packet will fit
|
overosync->sent_bytes += length + 4;
|
||||||
if ((overosync->write_pointer + length + sizeof(tickTime)) >
|
|
||||||
sizeof(overosync->transactions[overosync->loading_transaction_id].tx_buffer)) {
|
|
||||||
overosync->failed_objects ++;
|
|
||||||
xSemaphoreGive(overosync->buffer_lock);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get offset into buffer and copy contents
|
|
||||||
tx_buffer = overosync->transactions[overosync->loading_transaction_id].tx_buffer +
|
|
||||||
overosync->write_pointer;
|
|
||||||
memcpy(tx_buffer, &tickTime, sizeof(tickTime));
|
|
||||||
memcpy(tx_buffer + sizeof(tickTime),data,length);
|
|
||||||
overosync->write_pointer += length + sizeof(tickTime);
|
|
||||||
overosync->sent_bytes += length;
|
|
||||||
overosync->sent_objects++;
|
|
||||||
|
|
||||||
xSemaphoreGive(overosync->buffer_lock);
|
|
||||||
|
|
||||||
return length;
|
return length;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
fail:
|
||||||
* Callback from the overo spi driver at the end of each packet
|
overosync->failed_objects++;
|
||||||
*/
|
return -1;
|
||||||
static void transmitDataDone(uint32_t error_counter)
|
|
||||||
{
|
|
||||||
uint8_t *tx_buffer, *rx_buffer;
|
|
||||||
|
|
||||||
// Get lock to manipulate buffers
|
|
||||||
if(xSemaphoreTake(overosync->buffer_lock, 0) == pdFALSE) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
overosync->packets++;
|
|
||||||
|
|
||||||
// Swap buffers
|
|
||||||
overosync->active_transaction_id = overosync->loading_transaction_id;
|
|
||||||
overosync->loading_transaction_id = (overosync->loading_transaction_id + 1) %
|
|
||||||
NELEMENTS(overosync->transactions);
|
|
||||||
|
|
||||||
// Release the buffer lock
|
|
||||||
xSemaphoreGive(overosync->buffer_lock);
|
|
||||||
|
|
||||||
// Get the new buffers and configure the overo driver
|
|
||||||
tx_buffer = overosync->transactions[overosync->active_transaction_id].tx_buffer;
|
|
||||||
rx_buffer = overosync->transactions[overosync->active_transaction_id].rx_buffer;
|
|
||||||
|
|
||||||
PIOS_Overo_SetNewBuffer((uint8_t *) tx_buffer, (uint8_t *) rx_buffer,
|
|
||||||
sizeof(overosync->transactions[overosync->active_transaction_id].tx_buffer));
|
|
||||||
|
|
||||||
// Prepare the new loading buffer
|
|
||||||
memset(overosync->transactions[overosync->loading_transaction_id].tx_buffer, 0xff,
|
|
||||||
sizeof(overosync->transactions[overosync->loading_transaction_id].tx_buffer));
|
|
||||||
overosync->write_pointer = 0;
|
|
||||||
overosync->underrun_error = error_counter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -70,6 +70,8 @@ struct pios_overo_dev {
|
|||||||
int8_t writing_buffer;
|
int8_t writing_buffer;
|
||||||
uint32_t writing_offset;
|
uint32_t writing_offset;
|
||||||
|
|
||||||
|
uint32_t packets;
|
||||||
|
|
||||||
uint8_t tx_buffer[2][PACKET_SIZE];
|
uint8_t tx_buffer[2][PACKET_SIZE];
|
||||||
uint8_t rx_buffer[2][PACKET_SIZE];
|
uint8_t rx_buffer[2][PACKET_SIZE];
|
||||||
|
|
||||||
@ -164,6 +166,19 @@ void PIOS_OVERO_DMA_irq_handler(uint32_t overo_id)
|
|||||||
|
|
||||||
// Load any pending bytes from TX fifo
|
// Load any pending bytes from TX fifo
|
||||||
PIOS_OVERO_WriteData(overo_dev);
|
PIOS_OVERO_WriteData(overo_dev);
|
||||||
|
|
||||||
|
overo_dev->packets++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Debugging information to check how it is runnign
|
||||||
|
*/
|
||||||
|
int32_t PIOS_OVERO_GetPacketCount(uint32_t overo_id)
|
||||||
|
{
|
||||||
|
struct pios_overo_dev * overo_dev = (struct pios_overo_dev *) overo_id;
|
||||||
|
PIOS_Assert(PIOS_OVERO_validate(overo_dev));
|
||||||
|
|
||||||
|
return overo_dev->packets;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
#define PIOS_OVERO_H
|
#define PIOS_OVERO_H
|
||||||
|
|
||||||
extern void PIOS_OVERO_DMA_irq_handler(uint32_t overo_id);
|
extern void PIOS_OVERO_DMA_irq_handler(uint32_t overo_id);
|
||||||
|
extern int32_t PIOS_OVERO_GetPacketCount(uint32_t overo_id);
|
||||||
|
|
||||||
#endif /* PIOS_OVERO_H */
|
#endif /* PIOS_OVERO_H */
|
||||||
|
|
||||||
|
@ -786,7 +786,7 @@ void PIOS_Board_Init(void) {
|
|||||||
HwSettingsData hwSettings;
|
HwSettingsData hwSettings;
|
||||||
HwSettingsGet(&hwSettings);
|
HwSettingsGet(&hwSettings);
|
||||||
if(hwSettings.OptionalModules[HWSETTINGS_OPTIONALMODULES_OVERO] == HWSETTINGS_OPTIONALMODULES_ENABLED) {
|
if(hwSettings.OptionalModules[HWSETTINGS_OPTIONALMODULES_OVERO] == HWSETTINGS_OPTIONALMODULES_ENABLED) {
|
||||||
if (PIOS_Overo_Init(&pios_overo_id, &pios_overo_cfg)) {
|
if (PIOS_OVERO_Init(&pios_overo_id, &pios_overo_cfg)) {
|
||||||
PIOS_DEBUG_Assert(0);
|
PIOS_DEBUG_Assert(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user