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

The overosync module now uses pios_com interface.

This commit is contained in:
James Cotton 2012-07-20 09:46:28 -05:00
parent 8fc2d10ea6
commit 6b3e5573a0
4 changed files with 35 additions and 96 deletions

View File

@ -55,27 +55,17 @@ static bool overoEnabled;
// Private functions
static void overoSyncTask(void *parameters);
static int32_t packData(uint8_t * data, int32_t length);
static void transmitDataDone(uint32_t error_counter);
static void registerObject(UAVObjHandle obj);
struct dma_transaction {
uint8_t tx_buffer[OVEROSYNC_PACKET_SIZE] __attribute__ ((aligned(4)));
uint8_t rx_buffer[OVEROSYNC_PACKET_SIZE] __attribute__ ((aligned(4)));
};
// External variables
extern uint32_t pios_com_overo_id;
extern uint32_t pios_overo_id;
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 write_pointer;
uint32_t sent_objects;
uint32_t failed_objects;
uint32_t received_objects;
uint32_t framesync_error;
uint32_t underrun_error;
};
struct overosync *overosync;
@ -132,16 +122,7 @@ int32_t OveroSyncStart(void)
if(overosync == NULL)
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->framesync_error = 0;
overosync->packets = 0;
// Process all registered objects and connect queue for updates
UAVObjIterate(&registerObject);
@ -192,22 +173,13 @@ static void overoSyncTask(void *parameters)
portTickType lastUpdateTime = xTaskGetTickCount();
portTickType updateTime;
// Set the comms callback
PIOS_Overo_SetCallback(transmitDataDone);
// Loop forever
while (1) {
// Wait for queue message
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
UAVTalkSendObject(uavTalkCon, ev.obj, ev.instId, false, 0);
}
// Process event. This calls transmitData
UAVTalkSendObject(uavTalkCon, ev.obj, ev.instId, false, 0);
updateTime = xTaskGetTickCount();
if(((portTickType) (updateTime - lastUpdateTime)) > 1000) {
@ -217,14 +189,14 @@ static void overoSyncTask(void *parameters)
syncStats.Received = 0;
syncStats.Connected = syncStats.Send > 500 ? OVEROSYNCSTATS_CONNECTED_TRUE : OVEROSYNCSTATS_CONNECTED_FALSE;
syncStats.DroppedUpdates = overosync->failed_objects;
syncStats.FramesyncErrors = overosync->framesync_error;
syncStats.Packets = overosync->packets;
syncStats.UnderrunErrors = overosync->underrun_error;
syncStats.Packets = PIOS_OVERO_GetPacketCount(pios_overo_id);
OveroSyncStatsSet(&syncStats);
overosync->failed_objects = 0;
overosync->sent_bytes = 0;
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)
{
uint8_t *tx_buffer;
portTickType tickTime = xTaskGetTickCount();
// Get the lock for manipulating the buffer
xSemaphoreTake(overosync->buffer_lock, portMAX_DELAY);
if( PIOS_COM_SendBuffer(pios_com_overo_id, (uint8_t *) &tickTime, sizeof(tickTime)) != 0)
goto fail;
if( PIOS_COM_SendBuffer(pios_com_overo_id, data, length) != 0)
goto fail;
overosync->sent_bytes += length + 4;
// Check this packet will fit
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;
}
/**
* Callback from the overo spi driver at the end of each packet
*/
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;
fail:
overosync->failed_objects++;
return -1;
}
/**

View File

@ -70,6 +70,8 @@ struct pios_overo_dev {
int8_t writing_buffer;
uint32_t writing_offset;
uint32_t packets;
uint8_t tx_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
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;
}
/**

View File

@ -31,6 +31,7 @@
#define PIOS_OVERO_H
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 */

View File

@ -786,7 +786,7 @@ void PIOS_Board_Init(void) {
HwSettingsData hwSettings;
HwSettingsGet(&hwSettings);
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);
}