mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-18 03:52:11 +01:00
Added module to send updates out the SPI port
This commit is contained in:
parent
e434ab94a9
commit
95abb56d5e
46
flight/Modules/OveroSync/inc/overosync.h
Normal file
46
flight/Modules/OveroSync/inc/overosync.h
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @addtogroup OpenPilotModules OpenPilot Modules
|
||||||
|
* @{
|
||||||
|
* @addtogroup TelemetryModule Telemetry Module
|
||||||
|
* @brief Main telemetry module
|
||||||
|
* Starts three tasks (RX, TX, and priority TX) that watch event queues
|
||||||
|
* and handle all the telemetry of the UAVobjects
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
* @file telemetry.h
|
||||||
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||||
|
* @brief Include file of the telemetry module.
|
||||||
|
* As with all modules only the initialize function is exposed all other
|
||||||
|
* interactions with the module take place through the event queue and
|
||||||
|
* objects.
|
||||||
|
* @see The GNU Public License (GPL) Version 3
|
||||||
|
*
|
||||||
|
*****************************************************************************/
|
||||||
|
/*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef TELEMETRY_H
|
||||||
|
#define TELEMETRY_H
|
||||||
|
|
||||||
|
int32_t TelemetryInitialize(void);
|
||||||
|
|
||||||
|
#endif // TELEMETRY_H
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
* @}
|
||||||
|
*/
|
175
flight/Modules/OveroSync/overosync.c
Normal file
175
flight/Modules/OveroSync/overosync.c
Normal file
@ -0,0 +1,175 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @addtogroup OpenPilotModules OpenPilot Modules
|
||||||
|
* @{
|
||||||
|
* @addtogroup TelemetryModule Telemetry Module
|
||||||
|
* @brief Main telemetry module
|
||||||
|
* Starts three tasks (RX, TX, and priority TX) that watch event queues
|
||||||
|
* and handle all the telemetry of the UAVobjects
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
* @file telemetry.c
|
||||||
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||||
|
* @brief Telemetry module, handles telemetry and UAVObject updates
|
||||||
|
* @see The GNU Public License (GPL) Version 3
|
||||||
|
*
|
||||||
|
*****************************************************************************/
|
||||||
|
/*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "openpilot.h"
|
||||||
|
#include "overosync.h"
|
||||||
|
|
||||||
|
// Private constants
|
||||||
|
#define OVEROSYNC_PACKET_SIZE 256
|
||||||
|
#define MAX_QUEUE_SIZE 3
|
||||||
|
#define STACK_SIZE_BYTES 512
|
||||||
|
#define TASK_PRIORITY (tskIDLE_PRIORITY + 2)
|
||||||
|
|
||||||
|
// Private types
|
||||||
|
|
||||||
|
// Private variables
|
||||||
|
static xQueueHandle queue;
|
||||||
|
static xSemaphoreHandle lock;
|
||||||
|
static UAVTalkConnection uavTalkCon;
|
||||||
|
static xTaskHandle overoSyncTaskHandle;
|
||||||
|
|
||||||
|
// Private functions
|
||||||
|
static void overoSyncTask(void *parameters);
|
||||||
|
static int32_t transmitData(uint8_t * data, int32_t length);
|
||||||
|
static void transmitDataDone(bool crc_ok, uint8_t crc_val);
|
||||||
|
static void registerObject(UAVObjHandle obj);
|
||||||
|
|
||||||
|
// External variables
|
||||||
|
extern int32_t pios_spi_overo_id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialise the telemetry module
|
||||||
|
* \return -1 if initialisation failed
|
||||||
|
* \return 0 on success
|
||||||
|
*/
|
||||||
|
int32_t OveroSyncInitialize(void)
|
||||||
|
{
|
||||||
|
// Create object queues
|
||||||
|
queue = xQueueCreate(MAX_QUEUE_SIZE, sizeof(UAVObjEvent));
|
||||||
|
|
||||||
|
// Create the semaphore for sending data
|
||||||
|
lock = xSemaphoreCreateMutex();
|
||||||
|
|
||||||
|
// Initialise UAVTalk
|
||||||
|
uavTalkCon = UAVTalkInitialize(&transmitData);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialise the telemetry module
|
||||||
|
* \return -1 if initialisation failed
|
||||||
|
* \return 0 on success
|
||||||
|
*/
|
||||||
|
int32_t OveroSyncStart(void)
|
||||||
|
{
|
||||||
|
// Process all registered objects and connect queue for updates
|
||||||
|
UAVObjIterate(®isterObject);
|
||||||
|
|
||||||
|
// Start telemetry tasks
|
||||||
|
if(pios_spi_overo_id != 0)
|
||||||
|
xTaskCreate(overoSyncTask, (signed char *)"OveroSync", STACK_SIZE_BYTES/4, NULL, TASK_PRIORITY, &overoSyncTaskHandle);
|
||||||
|
|
||||||
|
// TaskMonitorAdd(TASKINFO_RUNNING_TELEMETRYRX, telemetryRxTaskHandle);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
MODULE_INITCALL(OveroSyncInitialize, OveroSyncStart)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register a new object, adds object to local list and connects the queue depending on the object's
|
||||||
|
* telemetry settings.
|
||||||
|
* \param[in] obj Object to connect
|
||||||
|
*/
|
||||||
|
static void registerObject(UAVObjHandle obj)
|
||||||
|
{
|
||||||
|
int32_t eventMask;
|
||||||
|
eventMask = EV_UPDATED | EV_UPDATED_MANUAL | EV_UPDATE_REQ;
|
||||||
|
if (UAVObjIsMetaobject(obj)) {
|
||||||
|
eventMask |= EV_UNPACKED; // we also need to act on remote updates (unpack events)
|
||||||
|
}
|
||||||
|
UAVObjConnectQueue(obj, queue, eventMask);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int32_t overosync_transfers = 0;
|
||||||
|
/**
|
||||||
|
* Telemetry transmit task, regular priority
|
||||||
|
*/
|
||||||
|
static void overoSyncTask(void *parameters)
|
||||||
|
{
|
||||||
|
UAVObjEvent ev;
|
||||||
|
|
||||||
|
// Loop forever
|
||||||
|
while (1) {
|
||||||
|
// Wait for queue message
|
||||||
|
if (xQueueReceive(queue, &ev, portMAX_DELAY) == pdTRUE) {
|
||||||
|
// Lock
|
||||||
|
xSemaphoreTake(lock, portMAX_DELAY);
|
||||||
|
|
||||||
|
// Process event
|
||||||
|
UAVTalkSendObject(uavTalkCon, ev.obj, ev.instId, false, 0);
|
||||||
|
overosync_transfers++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t tx_buffer[OVEROSYNC_PACKET_SIZE];
|
||||||
|
uint8_t rx_buffer[OVEROSYNC_PACKET_SIZE];
|
||||||
|
|
||||||
|
int32_t transactionsDone = 0;
|
||||||
|
static void transmitDataDone(bool crc_ok, uint8_t crc_val)
|
||||||
|
{
|
||||||
|
transactionsDone ++;
|
||||||
|
xSemaphoreGive(lock);
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t transactionsStarted = 0;
|
||||||
|
/**
|
||||||
|
* Transmit data buffer to the modem or USB port.
|
||||||
|
* \param[in] data Data buffer to send
|
||||||
|
* \param[in] length Length of buffer
|
||||||
|
* \return -1 on failure
|
||||||
|
* \return number of bytes transmitted on success
|
||||||
|
*/
|
||||||
|
static int32_t transmitData(uint8_t * data, int32_t length)
|
||||||
|
{
|
||||||
|
memcpy(tx_buffer,data,length);
|
||||||
|
memset(tx_buffer + length, 0, sizeof(tx_buffer) - length);
|
||||||
|
|
||||||
|
int32_t retval = 0;
|
||||||
|
|
||||||
|
transactionsStarted++;
|
||||||
|
retval = PIOS_SPI_TransferBlock(pios_spi_overo_id, (uint8_t *) tx_buffer, (uint8_t *) rx_buffer, OVEROSYNC_PACKET_SIZE, &transmitDataDone);
|
||||||
|
|
||||||
|
// for (uint32_t i = 0; rx_buffer[0] != 0 && i < OVEROSYNC_PACKET_SIZE; i++)
|
||||||
|
// UAVTalkProcessInputStream(uavTalkCon, rx_buffer[i]);
|
||||||
|
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
* @}
|
||||||
|
*/
|
@ -52,6 +52,7 @@
|
|||||||
65140DFA1496927D00E01D11 /* sensors.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sensors.h; sourceTree = "<group>"; };
|
65140DFA1496927D00E01D11 /* sensors.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sensors.h; sourceTree = "<group>"; };
|
||||||
65140DFB1496927D00E01D11 /* sensors.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = sensors.c; sourceTree = "<group>"; };
|
65140DFB1496927D00E01D11 /* sensors.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = sensors.c; sourceTree = "<group>"; };
|
||||||
65173C9F12EBFD1700D6A7CB /* Makefile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.make; name = Makefile; path = ../../../Makefile; sourceTree = SOURCE_ROOT; };
|
65173C9F12EBFD1700D6A7CB /* Makefile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.make; name = Makefile; path = ../../../Makefile; sourceTree = SOURCE_ROOT; };
|
||||||
|
6517932B14DA76E200FCDAC0 /* OveroSync */ = {isa = PBXFileReference; lastKnownFileType = folder; path = OveroSync; sourceTree = "<group>"; };
|
||||||
651913371256C5240039C0A3 /* ahrs_comm_objects.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ahrs_comm_objects.c; sourceTree = "<group>"; };
|
651913371256C5240039C0A3 /* ahrs_comm_objects.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ahrs_comm_objects.c; sourceTree = "<group>"; };
|
||||||
651913381256C5240039C0A3 /* ahrs_spi_comm.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ahrs_spi_comm.c; sourceTree = "<group>"; };
|
651913381256C5240039C0A3 /* ahrs_spi_comm.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ahrs_spi_comm.c; sourceTree = "<group>"; };
|
||||||
6519133A1256C52B0039C0A3 /* ahrs_comm_objects.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ahrs_comm_objects.h; sourceTree = "<group>"; };
|
6519133A1256C52B0039C0A3 /* ahrs_comm_objects.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ahrs_comm_objects.h; sourceTree = "<group>"; };
|
||||||
@ -3401,6 +3402,7 @@
|
|||||||
650D8E5112DFE16400D05CC9 /* ManualControl */,
|
650D8E5112DFE16400D05CC9 /* ManualControl */,
|
||||||
650D8E5512DFE16400D05CC9 /* MK */,
|
650D8E5512DFE16400D05CC9 /* MK */,
|
||||||
650D8E5A12DFE16400D05CC9 /* Osd */,
|
650D8E5A12DFE16400D05CC9 /* Osd */,
|
||||||
|
6517932B14DA76E200FCDAC0 /* OveroSync */,
|
||||||
65140DF81496927D00E01D11 /* Sensors */,
|
65140DF81496927D00E01D11 /* Sensors */,
|
||||||
650D8E5D12DFE16400D05CC9 /* Stabilization */,
|
650D8E5D12DFE16400D05CC9 /* Stabilization */,
|
||||||
650D8E6112DFE16400D05CC9 /* System */,
|
650D8E6112DFE16400D05CC9 /* System */,
|
||||||
|
@ -49,7 +49,9 @@ endif
|
|||||||
FLASH_TOOL = OPENOCD
|
FLASH_TOOL = OPENOCD
|
||||||
|
|
||||||
# List of modules to include
|
# List of modules to include
|
||||||
MODULES = Sensors Attitude/revolution ManualControl Stabilization Altitude/revolution Actuator GPS Telemetry FirmwareIAP
|
MODULES = Sensors Attitude/revolution ManualControl Stabilization Altitude/revolution Actuator GPS FirmwareIAP
|
||||||
|
MODULES += Telemetry
|
||||||
|
MODULES += OveroSync
|
||||||
PYMODULES =
|
PYMODULES =
|
||||||
#FlightPlan
|
#FlightPlan
|
||||||
|
|
||||||
|
@ -466,7 +466,7 @@ static const struct pios_spi_cfg pios_spi_overo_cfg = {
|
|||||||
.dma = {
|
.dma = {
|
||||||
.irq = {
|
.irq = {
|
||||||
// Note this is the stream ID that triggers interrupts (in this case RX)
|
// Note this is the stream ID that triggers interrupts (in this case RX)
|
||||||
.flags = (DMA_IT_TCIF3 | DMA_IT_TEIF3 | DMA_IT_HTIF3),
|
.flags = (DMA_IT_TCIF3 | DMA_IT_TEIF3 | DMA_IT_HTIF3 | DMA_IT_DMEIF3 | DMA_IT_FEIF3),
|
||||||
.init = {
|
.init = {
|
||||||
.NVIC_IRQChannel = DMA1_Stream0_IRQn,
|
.NVIC_IRQChannel = DMA1_Stream0_IRQn,
|
||||||
.NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGH,
|
.NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGH,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user