mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-12-01 09:24:10 +01:00
Remove discontinued AHRS files
This commit is contained in:
parent
8c6f24afef
commit
304f366338
@ -1,90 +0,0 @@
|
||||
// Regenerate using graphviz/dotty with this command
|
||||
// dot -Tjpg ./flight/Doc/Architecture/ahrs_spi_link_fsm.dot > ./flight/Doc/Architecture/ahrs_spi_link_fsm.jpg
|
||||
|
||||
digraph ahrs_spi_protocol {
|
||||
label="AHRS SPI Link State Machine"
|
||||
labelloc=t
|
||||
labeljust = l
|
||||
|
||||
// Stopped -- Undefined Wire State
|
||||
{
|
||||
node [ style=filled,color=lightgray ]
|
||||
|
||||
stopped [ shape="doublecircle" ]
|
||||
stopping
|
||||
}
|
||||
|
||||
// Wire State Inactive
|
||||
{
|
||||
node [ style=filled,color=lightblue ]
|
||||
|
||||
inactive
|
||||
}
|
||||
|
||||
// Wire State Busy
|
||||
{
|
||||
node [ style=filled,color=red ]
|
||||
|
||||
user_busy
|
||||
user_busy_tx_pending
|
||||
user_busy_rx_pending
|
||||
user_busy_rxtx_pending
|
||||
}
|
||||
{
|
||||
node [ style=filled,color=yellow ]
|
||||
|
||||
user_tx_pending
|
||||
user_rx_pending
|
||||
user_rxtx_pending
|
||||
}
|
||||
|
||||
// Wire State Ready
|
||||
{
|
||||
node [ style=filled,color=green ]
|
||||
|
||||
user_rx_active
|
||||
user_tx_active
|
||||
user_rxtx_active
|
||||
}
|
||||
|
||||
//
|
||||
// State transitions driven by the user
|
||||
//
|
||||
stopped -> inactive [ label="init link" ]
|
||||
|
||||
inactive -> stopping [ label="stop" ]
|
||||
inactive -> user_busy_rx_pending [ label="user set rx" ]
|
||||
inactive -> user_busy_tx_pending [ label="user set tx" ]
|
||||
|
||||
user_busy -> user_busy_tx_pending [ label="user set tx" ]
|
||||
user_busy -> user_busy_rx_pending [ label="user set rx" ]
|
||||
user_busy -> inactive [ label="user done" ]
|
||||
user_busy -> stopping [ label="stop" ]
|
||||
|
||||
user_busy_tx_pending -> user_busy_rxtx_pending [ label="user set rx" ]
|
||||
user_busy_tx_pending -> user_tx_pending [ label="user done" ]
|
||||
|
||||
user_busy_rx_pending -> user_busy_rxtx_pending [ label="user set tx" ]
|
||||
user_busy_rx_pending -> user_rx_pending [ label="user done" ]
|
||||
|
||||
user_busy_rxtx_pending -> user_rxtx_pending [ label="user done" ]
|
||||
|
||||
//
|
||||
// State transitions driven by messaging from the OP board
|
||||
//
|
||||
stopping -> stopped [ label="rx any" ]
|
||||
|
||||
user_tx_pending -> user_tx_active [ label="rx any" ]
|
||||
user_rx_pending -> user_rx_active [ label="rx any" ]
|
||||
|
||||
user_rxtx_pending -> user_rxtx_active [ label="rx any" ]
|
||||
|
||||
// Active -> Busy
|
||||
user_rx_active -> user_busy [ label="rx user" ]
|
||||
|
||||
user_tx_active -> inactive [ label="rx any" ]
|
||||
|
||||
user_rxtx_active -> user_busy [ label="rx user" ]
|
||||
user_rxtx_active -> user_rx_active [ label="rx link" ]
|
||||
user_rxtx_active -> user_rx_active [ label="rx unknown" ]
|
||||
}
|
Binary file not shown.
Before Width: | Height: | Size: 104 KiB |
@ -1,164 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file ahrs_comm_objects.c
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief AHRS comms AUVObjects. This file defined teh objects to be used.
|
||||
*
|
||||
* @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 "pios.h"
|
||||
#include "ahrs_spi_comm.h"
|
||||
#include "pios_debug.h"
|
||||
|
||||
static AttitudeRawData AttitudeRaw;
|
||||
static AttitudeActualData AttitudeActual;
|
||||
static BaroAltitudeData BaroAltitude;
|
||||
static GPSPositionData GPSPosition;
|
||||
static HomeLocationData HomeLocation;
|
||||
static InsStatusData InsStatus;
|
||||
static InsSettingsData InsSettings;
|
||||
static FirmwareIAPObjData FirmwareIAPObj;
|
||||
static PositionActualData PositionActual;
|
||||
static VelocityActualData VelocityActual;
|
||||
static GPSSatellitesData GPSSatellites;
|
||||
static GPSTimeData GPSTime;
|
||||
|
||||
AhrsSharedObject objectHandles[MAX_AHRS_OBJECTS];
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL ((void *)0)
|
||||
#endif
|
||||
|
||||
#ifdef IN_AHRS
|
||||
|
||||
//slightly hacky - implement our own version of the xxxHandle() functions
|
||||
#define CREATEHANDLE(n,obj) \
|
||||
void * obj##Handle() {return (&objectHandles[n]);}
|
||||
|
||||
CREATEHANDLE(0, AttitudeRaw);
|
||||
CREATEHANDLE(1, AttitudeActual);
|
||||
CREATEHANDLE(2, InsSettings);
|
||||
CREATEHANDLE(3, InsStatus);
|
||||
CREATEHANDLE(4, BaroAltitude);
|
||||
CREATEHANDLE(5, GPSPosition);
|
||||
CREATEHANDLE(6, PositionActual);
|
||||
CREATEHANDLE(7, VelocityActual);
|
||||
CREATEHANDLE(8, HomeLocation);
|
||||
CREATEHANDLE(9, FirmwareIAPObj);
|
||||
CREATEHANDLE(10, GPSSatellites);
|
||||
CREATEHANDLE(11, GPSTime);
|
||||
|
||||
#if 12 != MAX_AHRS_OBJECTS //sanity check
|
||||
#error We did not create the correct number of xxxHandle() functions
|
||||
#endif
|
||||
|
||||
#define ADDHANDLE(idx,obj) {\
|
||||
int n = idx;\
|
||||
objectHandles[n].data = &obj;\
|
||||
objectHandles[n].size = sizeof(obj);\
|
||||
objectHandles[n].index = n;\
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static void ObjectUpdatedCb(UAVObjEvent * ev);
|
||||
|
||||
#define ADDHANDLE(idx,obj) {\
|
||||
obj##Initialize();\
|
||||
int n = idx;\
|
||||
objectHandles[n].data = &obj;\
|
||||
objectHandles[n].uavHandle = obj##Handle();\
|
||||
objectHandles[n].size = sizeof(obj);\
|
||||
objectHandles[n].index = n;\
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void AhrsInitHandles(void)
|
||||
{
|
||||
int idx = 0;
|
||||
//Note: the first item in this list has the highest priority
|
||||
//the last has the lowest priority
|
||||
ADDHANDLE(idx++, AttitudeRaw);
|
||||
ADDHANDLE(idx++, AttitudeActual);
|
||||
ADDHANDLE(idx++, InsSettings);
|
||||
ADDHANDLE(idx++, InsStatus);
|
||||
ADDHANDLE(idx++, BaroAltitude);
|
||||
ADDHANDLE(idx++, GPSPosition);
|
||||
ADDHANDLE(idx++, PositionActual);
|
||||
ADDHANDLE(idx++, VelocityActual);
|
||||
ADDHANDLE(idx++, HomeLocation);
|
||||
ADDHANDLE(idx++, FirmwareIAPObj);
|
||||
ADDHANDLE(idx++, GPSSatellites);
|
||||
ADDHANDLE(idx++, GPSTime);
|
||||
|
||||
if (idx != MAX_AHRS_OBJECTS) {
|
||||
PIOS_DEBUG_Assert(0);
|
||||
}
|
||||
//Note: Only connect objects that the AHRS needs to read
|
||||
//When the AHRS writes to these the data does a round trip
|
||||
//AHRS->OP->AHRS due to these events
|
||||
#ifndef IN_AHRS
|
||||
InsSettingsConnectCallback(ObjectUpdatedCb);
|
||||
HomeLocationConnectCallback(ObjectUpdatedCb);
|
||||
FirmwareIAPObjConnectCallback(ObjectUpdatedCb);
|
||||
#endif
|
||||
}
|
||||
|
||||
AhrsObjHandle AhrsFromIndex(uint8_t index)
|
||||
{
|
||||
if (index >= MAX_AHRS_OBJECTS) {
|
||||
return (NULL);
|
||||
}
|
||||
return (&objectHandles[index]);
|
||||
}
|
||||
|
||||
#ifndef IN_AHRS
|
||||
|
||||
AhrsObjHandle AhrsFromUAV(UAVObjHandle obj)
|
||||
{
|
||||
if (objectHandles[0].uavHandle == NULL) { //Oops - we haven't been initialised!
|
||||
PIOS_DEBUG_Assert(0);
|
||||
}
|
||||
for (int ct = 0; ct < MAX_AHRS_OBJECTS; ct++) {
|
||||
if (objectHandles[ct].uavHandle == obj) {
|
||||
return (&objectHandles[ct]);
|
||||
}
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/** Callback to update AHRS from UAVObjects
|
||||
*/
|
||||
static void ObjectUpdatedCb(UAVObjEvent * ev)
|
||||
{
|
||||
if (!(ev->event & EV_MASK_ALL_UPDATES)) {
|
||||
return;
|
||||
}
|
||||
AhrsObjHandle hdl = AhrsFromUAV(ev->obj);
|
||||
if (hdl) {
|
||||
AhrsSharedData data; //this is guaranteed to be big enough
|
||||
UAVObjGetData(ev->obj, &data);
|
||||
AhrsSetData(hdl, &data);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -1,452 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file ahrs_spi_comm.c
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief AHRS SPI communications.
|
||||
*
|
||||
* @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 <pios.h>
|
||||
#include "ahrs_spi_comm.h"
|
||||
#include "ahrs_spi_program.h"
|
||||
|
||||
#ifdef IN_AHRS
|
||||
#include <string.h>
|
||||
#include "pios_debug.h"
|
||||
#include "pios_spi.h"
|
||||
#include "pios_irq.h"
|
||||
#include "ahrs_spi_program_slave.h"
|
||||
//#include "STM32103CB_AHRS.h"
|
||||
#endif
|
||||
|
||||
/*transmit and receive packet magic numbers.
|
||||
These numbers are chosen to be very unlikely to occur due to noise.
|
||||
CRC8 does not always catch noise from cross-coupling between data lines.
|
||||
*/
|
||||
#ifdef IN_AHRS
|
||||
#define TXMAGIC 0xA55AF0C3
|
||||
#define RXMAGIC 0x3C5AA50F
|
||||
#else
|
||||
#define RXMAGIC 0xA55AF0C3
|
||||
#define TXMAGIC 0x3C5AA50F
|
||||
#endif
|
||||
|
||||
//packet types
|
||||
typedef enum { COMMS_NULL, COMMS_OBJECT } COMMSCOMMAND;
|
||||
|
||||
//The maximum number of objects that can be updated in one cycle.
|
||||
//Currently the link is capable of sending 3 packets per cycle but 2 is enough
|
||||
#define MAX_UPDATE_OBJECTS 2
|
||||
|
||||
//Number of transmissions + 1 before we expect to see the data acknowledge
|
||||
//This is controlled by the SPI hardware.
|
||||
#define ACK_LATENCY 4
|
||||
|
||||
/** All data for one object
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t done;
|
||||
uint8_t index;
|
||||
AhrsSharedData object;
|
||||
} ObjectPacketData;
|
||||
|
||||
/** One complete packet.
|
||||
Other packet types are allowed for. The frame size will be the size of this
|
||||
structure.
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t magicNumber;
|
||||
COMMSCOMMAND command;
|
||||
AhrsEndStatus status;
|
||||
union { //allow for expansion to other packet types.
|
||||
ObjectPacketData objects[MAX_UPDATE_OBJECTS];
|
||||
};
|
||||
uint8_t dummy; //For some reason comms trashes the last byte
|
||||
} CommsDataPacket;
|
||||
|
||||
static void FillObjectPacket();
|
||||
static void CommsCallback(uint8_t crc_ok, uint8_t crc_val);
|
||||
static void SetObjectDirty(const int idx);
|
||||
static void HandleObjectPacket();
|
||||
static void HandleRxPacket();
|
||||
static void PollEvents();
|
||||
#ifndef IN_AHRS
|
||||
static void SendPacket(void);
|
||||
static void AhrsUpdatedCb(AhrsObjHandle handle);
|
||||
#endif
|
||||
|
||||
/** Receive data buffer
|
||||
*/
|
||||
static CommsDataPacket rxPacket;
|
||||
|
||||
/** Transmit data buffer
|
||||
*/
|
||||
|
||||
static CommsDataPacket txPacket;
|
||||
/** Objects that have changed and so should be transmitted
|
||||
*/
|
||||
static unsigned int dirtyObjects[MAX_AHRS_OBJECTS];
|
||||
|
||||
/** Objects that have been updated at startup
|
||||
*/
|
||||
static bool readyObjects[MAX_AHRS_OBJECTS];
|
||||
|
||||
/** List of event callbacks
|
||||
*/
|
||||
static AhrsEventCallback objCallbacks[MAX_AHRS_OBJECTS];
|
||||
|
||||
/** True for objects for which new data is received and callback needs to be called
|
||||
*/
|
||||
static bool callbackPending[MAX_AHRS_OBJECTS];
|
||||
|
||||
//More than this number of errors in a row will indicate the link is down
|
||||
#define MAX_CRC_ERRORS 50
|
||||
//At least this number of good frames are needed to indicate the link is up.
|
||||
#define MIN_OK_FRAMES 50
|
||||
//At least this number of empty objects are needed before the initial flood of events is over.
|
||||
#define MIN_EMPTY_OBJECTS 10
|
||||
|
||||
static uint8_t linkOk = false;
|
||||
static int okCount = MIN_OK_FRAMES;
|
||||
static int emptyCount = MIN_EMPTY_OBJECTS;
|
||||
static bool programReceive = false;
|
||||
|
||||
void AhrsInitComms(void)
|
||||
{
|
||||
programReceive = false;
|
||||
AhrsInitHandles();
|
||||
memset(objCallbacks, 0, sizeof(AhrsEventCallback) * MAX_AHRS_OBJECTS);
|
||||
memset(callbackPending, 0, sizeof(bool) * MAX_AHRS_OBJECTS);
|
||||
memset(dirtyObjects, 0, sizeof(unsigned int) * MAX_AHRS_OBJECTS);
|
||||
memset(&txPacket, 0, sizeof(txPacket));
|
||||
memset(&rxPacket, 0, sizeof(rxPacket));
|
||||
memset(&readyObjects, 0, sizeof(bool) * MAX_AHRS_OBJECTS);
|
||||
txPacket.command = COMMS_NULL;
|
||||
rxPacket.command = COMMS_NULL;
|
||||
}
|
||||
|
||||
static uint32_t opahrs_spi_id;
|
||||
void AhrsConnect(uint32_t spi_id)
|
||||
{
|
||||
/* Bind this comms layer to the appropriate SPI id */
|
||||
opahrs_spi_id = spi_id;
|
||||
#ifndef IN_AHRS
|
||||
/* Comms already init in OP code */
|
||||
for (int ct = 0; ct < MAX_AHRS_OBJECTS; ct++) {
|
||||
AhrsObjHandle hdl = AhrsFromIndex(ct);
|
||||
if (hdl) {
|
||||
AhrsConnectCallBack(hdl, AhrsUpdatedCb);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
int32_t AhrsSetData(AhrsObjHandle obj, const void *dataIn)
|
||||
{
|
||||
if (obj == NULL || dataIn == NULL || obj->data == NULL) {
|
||||
return (-1);
|
||||
}
|
||||
if (memcmp(obj->data, dataIn, obj->size) == 0) { //nothing to do, don't generate an event
|
||||
return (0);
|
||||
}
|
||||
memcpy(obj->data, dataIn, obj->size);
|
||||
SetObjectDirty(obj->index);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int32_t AhrsGetData(AhrsObjHandle obj, void *dataOut)
|
||||
{
|
||||
|
||||
if (obj == NULL || dataOut == NULL || obj->data == NULL) {
|
||||
return (-1);
|
||||
}
|
||||
memcpy(dataOut, obj->data, obj->size);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/** Mark an object to be sent
|
||||
*/
|
||||
void SetObjectDirty(const int idx)
|
||||
{
|
||||
if (idx < 0 || idx >= MAX_AHRS_OBJECTS) {
|
||||
return;
|
||||
}
|
||||
dirtyObjects[idx] = ACK_LATENCY;
|
||||
}
|
||||
/** Work out what data needs to be sent.
|
||||
If an object was not sent it will be retried 4 frames later
|
||||
*/
|
||||
static void FillObjectPacket()
|
||||
{
|
||||
txPacket.command = COMMS_OBJECT;
|
||||
txPacket.magicNumber = TXMAGIC;
|
||||
int idx = 0;
|
||||
for (int ct = 0; ct < MAX_UPDATE_OBJECTS; ct++) {
|
||||
txPacket.objects[ct].index = AHRS_NO_OBJECT;
|
||||
for (; idx < MAX_AHRS_OBJECTS; idx++) {
|
||||
if (dirtyObjects[idx] > 0) {
|
||||
if (dirtyObjects[idx] == ACK_LATENCY) {
|
||||
dirtyObjects[idx]--;
|
||||
txPacket.objects[ct].index = idx;
|
||||
AhrsObjHandle hdl = AhrsFromIndex(idx);
|
||||
if (hdl) {
|
||||
memcpy(&txPacket.objects[ct].object, hdl->data, hdl->size);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
dirtyObjects[idx]--;
|
||||
if (dirtyObjects[idx] == 0) { //timed out
|
||||
dirtyObjects[idx] = ACK_LATENCY;
|
||||
txPacket.status.retries++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (; idx < MAX_AHRS_OBJECTS; idx++) {
|
||||
if (dirtyObjects[idx] > 0 && dirtyObjects[idx] != ACK_LATENCY) {
|
||||
dirtyObjects[idx]--;
|
||||
if (dirtyObjects[idx] == 0) { //timed out
|
||||
dirtyObjects[idx] = ACK_LATENCY;
|
||||
txPacket.status.retries++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Process a received packet
|
||||
*/
|
||||
static void HandleRxPacket()
|
||||
{
|
||||
switch (rxPacket.command) {
|
||||
case COMMS_NULL:
|
||||
// Empty packet, nothing to do
|
||||
break;
|
||||
|
||||
case COMMS_OBJECT:
|
||||
HandleObjectPacket();
|
||||
break;
|
||||
|
||||
default:
|
||||
txPacket.status.invalidPacket++;
|
||||
}
|
||||
}
|
||||
|
||||
/** Process a received UAVObject packet
|
||||
*/
|
||||
static void HandleObjectPacket()
|
||||
{
|
||||
for (int ct = 0; ct < MAX_UPDATE_OBJECTS; ct++) {
|
||||
uint8_t idx;
|
||||
|
||||
// Flag objects that have been successfully received at the other end
|
||||
idx = rxPacket.objects[ct].done;
|
||||
txPacket.objects[ct].done = AHRS_NO_OBJECT;
|
||||
if (idx < MAX_AHRS_OBJECTS) {
|
||||
|
||||
if (dirtyObjects[idx] == 1) { //this ack is the correct one for the last send
|
||||
dirtyObjects[idx] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Handle received object if there is one in this packet
|
||||
idx = rxPacket.objects[ct].index;
|
||||
if (idx == AHRS_NO_OBJECT) {
|
||||
if (emptyCount > 0) {
|
||||
emptyCount--;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
AhrsObjHandle obj = AhrsFromIndex(idx);
|
||||
if (obj) {
|
||||
memcpy(obj->data, &rxPacket.objects[ct].object, obj->size);
|
||||
txPacket.objects[ct].done = idx;
|
||||
callbackPending[idx] = true; // New data available, call callback
|
||||
readyObjects[idx] = true;
|
||||
} else {
|
||||
txPacket.status.invalidPacket++;
|
||||
}
|
||||
}
|
||||
#ifdef IN_AHRS
|
||||
FillObjectPacket(); //ready for the next frame
|
||||
#endif
|
||||
}
|
||||
|
||||
int32_t AhrsConnectCallBack(AhrsObjHandle obj, AhrsEventCallback cb)
|
||||
{
|
||||
if (obj == NULL || obj->data == NULL) {
|
||||
return (-1);
|
||||
}
|
||||
objCallbacks[obj->index] = cb;
|
||||
return (0);
|
||||
}
|
||||
|
||||
void AhrsGetStatus(AhrsCommStatus * status)
|
||||
{
|
||||
status->remote = rxPacket.status;
|
||||
status->local = txPacket.status;
|
||||
status->linkOk = linkOk;
|
||||
}
|
||||
|
||||
|
||||
/** Function called after an SPI transfer
|
||||
*/
|
||||
static void CommsCallback(uint8_t crc_ok, uint8_t crc_val)
|
||||
{
|
||||
#ifndef IN_AHRS
|
||||
PIOS_SPI_RC_PinSet(opahrs_spi_id, 1); //signal the end of the transfer
|
||||
#endif
|
||||
txPacket.command = COMMS_NULL; //we must send something so default to null
|
||||
|
||||
// While the crc is ok, there is a magic value in the received data for extra security
|
||||
if (rxPacket.magicNumber != RXMAGIC) {
|
||||
crc_ok = false;
|
||||
}
|
||||
|
||||
|
||||
if (crc_ok) {
|
||||
// The received data is OK, update link state and handle data
|
||||
if (!linkOk && okCount > 0) {
|
||||
okCount--;
|
||||
if (okCount == 0) {
|
||||
linkOk = true;
|
||||
okCount = MAX_CRC_ERRORS;
|
||||
emptyCount = MIN_EMPTY_OBJECTS;
|
||||
}
|
||||
}
|
||||
HandleRxPacket();
|
||||
} else {
|
||||
// The received data is incorrect, update state
|
||||
#ifdef IN_AHRS //AHRS - do we neeed to enter program mode?
|
||||
if (memcmp(&rxPacket, SPI_PROGRAM_REQUEST, SPI_PROGRAM_REQUEST_LENGTH) == 0)
|
||||
{
|
||||
rxPacket.magicNumber = 0;
|
||||
programReceive = true; //flag it to be executed in program space
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
txPacket.status.crcErrors++;
|
||||
if (linkOk && okCount > 0) {
|
||||
okCount--;
|
||||
if (okCount == 0) {
|
||||
linkOk = false;
|
||||
okCount = MIN_OK_FRAMES;
|
||||
}
|
||||
}
|
||||
}
|
||||
rxPacket.magicNumber = 0;
|
||||
#ifdef IN_AHRS
|
||||
/*queue next frame
|
||||
If PIOS_SPI_TransferBlock() fails for any reason, comms will stop working.
|
||||
In that case, AhrsPoll() should kick start things again.
|
||||
*/
|
||||
PIOS_SPI_TransferBlock(opahrs_spi_id, (uint8_t *) & txPacket, (uint8_t *) & rxPacket, sizeof(CommsDataPacket), &CommsCallback);
|
||||
#endif
|
||||
}
|
||||
|
||||
/** Call callbacks for object where new data is received
|
||||
*/
|
||||
static void PollEvents(void)
|
||||
{
|
||||
for (int idx = 0; idx < MAX_AHRS_OBJECTS; idx++) {
|
||||
if (objCallbacks[idx]) {
|
||||
PIOS_IRQ_Disable();
|
||||
if (callbackPending[idx]) {
|
||||
callbackPending[idx] = false;
|
||||
PIOS_IRQ_Enable();
|
||||
objCallbacks[idx] (AhrsFromIndex(idx));
|
||||
} else {
|
||||
PIOS_IRQ_Enable();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef IN_AHRS
|
||||
void AhrsPoll()
|
||||
{
|
||||
if(programReceive)
|
||||
{
|
||||
AhrsProgramReceive(opahrs_spi_id);
|
||||
programReceive = false;
|
||||
}
|
||||
PollEvents();
|
||||
if (PIOS_SPI_Busy(opahrs_spi_id) != 0) { //Everything is working correctly
|
||||
return;
|
||||
}
|
||||
txPacket.status.kickStarts++;
|
||||
//comms have broken down - try kick starting it.
|
||||
txPacket.command = COMMS_NULL; //we must send something so default to null
|
||||
PIOS_SPI_TransferBlock(opahrs_spi_id, (uint8_t *) & txPacket, (uint8_t *) & rxPacket, sizeof(CommsDataPacket), &CommsCallback);
|
||||
}
|
||||
|
||||
bool AhrsLinkReady(void)
|
||||
{
|
||||
|
||||
for (int ct = 0; ct < MAX_AHRS_OBJECTS; ct++) {
|
||||
if (!readyObjects[ct]) {
|
||||
return (false);
|
||||
}
|
||||
}
|
||||
return (linkOk);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
void AhrsSendObjects(void)
|
||||
{
|
||||
static bool oldLink = false;
|
||||
|
||||
PollEvents();
|
||||
|
||||
if (oldLink != linkOk) {
|
||||
oldLink = linkOk;
|
||||
if (linkOk) {
|
||||
for (int ct = 0; ct < MAX_AHRS_OBJECTS; ct++) {
|
||||
AhrsObjHandle hdl = AhrsFromIndex(ct);
|
||||
if (!hdl) { //paranoid - shouldn't ever happen
|
||||
continue;
|
||||
}
|
||||
AhrsSharedData data;
|
||||
UAVObjGetData(hdl->uavHandle, &data);
|
||||
AhrsSetData(hdl, &data);
|
||||
SetObjectDirty(ct); //force even unchanged data to be sent
|
||||
}
|
||||
}
|
||||
}
|
||||
FillObjectPacket();
|
||||
SendPacket();
|
||||
}
|
||||
|
||||
void SendPacket(void)
|
||||
{
|
||||
#ifndef IN_AHRS
|
||||
PIOS_SPI_RC_PinSet(opahrs_spi_id, 0);
|
||||
#endif
|
||||
//no point checking if this failed. There isn't much we could do about it if it did fail
|
||||
PIOS_SPI_TransferBlock(opahrs_spi_id, (uint8_t *) & txPacket, (uint8_t *) & rxPacket, sizeof(CommsDataPacket), &CommsCallback);
|
||||
}
|
||||
|
||||
static void AhrsUpdatedCb(AhrsObjHandle handle)
|
||||
{
|
||||
UAVObjSetData(handle->uavHandle, handle->data);
|
||||
return;
|
||||
}
|
||||
#endif
|
@ -1,95 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file ahrs_comm_objects.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief AHRS SPI comms UAVObject definitions.
|
||||
*
|
||||
* @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 AHRS_COMM_OBJECTS_H
|
||||
#define AHRS_COMM_OBJECTS_H
|
||||
|
||||
#include "attitudeactual.h"
|
||||
#include "attituderaw.h"
|
||||
#include "baroaltitude.h"
|
||||
#include "gpsposition.h"
|
||||
#include "homelocation.h"
|
||||
#include "insstatus.h"
|
||||
#include "inssettings.h"
|
||||
#include "positionactual.h"
|
||||
#include "velocityactual.h"
|
||||
#include "firmwareiapobj.h"
|
||||
#include "gpsposition.h"
|
||||
#include "gpssatellites.h"
|
||||
#include "gpstime.h"
|
||||
/** union that will fit any UAVObject.
|
||||
*/
|
||||
|
||||
typedef union {
|
||||
AttitudeRawData AttitudeRaw;
|
||||
AttitudeActualData AttitudeActual;
|
||||
InsStatusData AhrsStatus;
|
||||
BaroAltitudeData BaroAltitude;
|
||||
GPSPositionData GPSPosition;
|
||||
PositionActualData PositionActual;
|
||||
VelocityActualData VelocityActual;
|
||||
HomeLocationData HomeLocation;
|
||||
InsSettingsData InsSettings;
|
||||
FirmwareIAPObjData FirmwareIAPObj;
|
||||
GPSSatellitesData GPSSatellites;
|
||||
GPSTimeData GPSTime;
|
||||
} __attribute__ ((packed)) AhrsSharedData;
|
||||
|
||||
/** The number of UAVObjects we will be dealing with.
|
||||
*/
|
||||
#define MAX_AHRS_OBJECTS 12
|
||||
|
||||
/** Our own version of a UAVObject.
|
||||
*/
|
||||
typedef struct {
|
||||
void *data;
|
||||
int size;
|
||||
uint8_t index;
|
||||
#ifndef IN_AHRS
|
||||
UAVObjHandle uavHandle;
|
||||
#endif
|
||||
} AhrsSharedObject;
|
||||
|
||||
typedef AhrsSharedObject *AhrsObjHandle;
|
||||
|
||||
/** Initialise the object mapping.
|
||||
It is important that this is called before any of the following functions.
|
||||
*/
|
||||
void AhrsInitHandles(void);
|
||||
|
||||
/** the AHRS object related to the given index.
|
||||
Returns the AHRS object or NULL if not found
|
||||
*/
|
||||
AhrsObjHandle AhrsFromIndex(uint8_t index);
|
||||
|
||||
#ifndef IN_AHRS
|
||||
/** Get the AHRS object associated with the UAVObject.
|
||||
Returns the AHRS object or NULL if not found
|
||||
*/
|
||||
AhrsObjHandle AhrsFromUAV(UAVObjHandle obj);
|
||||
#endif
|
||||
|
||||
#endif //#ifndef AHRS_COMMS_OBJECTS_H
|
@ -1,136 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file ahrs_spi_comm.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief Include file of the AHRS SPI comms exposed functionality.
|
||||
*
|
||||
* @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 AHRS_SPI_COMM_H_INCLUDED
|
||||
#define AHRS_SPI_COMM_H_INCLUDED
|
||||
|
||||
#ifdef IN_AHRS //AHRS only
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
/** Redirect UAVObjGetData call
|
||||
*/
|
||||
#define UAVObjGetData(obj, data) AhrsGetData(obj, data)
|
||||
|
||||
/** Redirect UAVObjSetData call
|
||||
*/
|
||||
#define UAVObjSetData(obj, data) AhrsSetData(obj, data)
|
||||
|
||||
/** Redirect UAVObjConnectCallback call
|
||||
Note: in AHRS, mask is unused because there is only one event type
|
||||
*/
|
||||
#define UAVObjConnectCallback(obj, callback, mask) AhrsConnectCallBack(obj,callback)
|
||||
|
||||
/** define our own UAVObjHandle
|
||||
*/
|
||||
typedef void *UAVObjHandle;
|
||||
|
||||
#else
|
||||
|
||||
#include "openpilot.h"
|
||||
#include "uavobjectmanager.h"
|
||||
|
||||
#endif
|
||||
|
||||
#define AHRS_NO_OBJECT 0xff
|
||||
|
||||
#include "ahrs_comm_objects.h"
|
||||
|
||||
/** Status of each end of the link
|
||||
*/
|
||||
typedef struct { //try to keep this short and in multiples of 4 bytes
|
||||
uint8_t kickStarts; //AHRS end only
|
||||
uint8_t crcErrors;
|
||||
uint8_t retries;
|
||||
uint8_t invalidPacket;
|
||||
} AhrsEndStatus;
|
||||
|
||||
/** AHRS comms status
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t linkOk;
|
||||
AhrsEndStatus remote;
|
||||
AhrsEndStatus local;
|
||||
} AhrsCommStatus;
|
||||
|
||||
/** Event callback, this function is called when an object changes.
|
||||
*/
|
||||
typedef void (*AhrsEventCallback) (AhrsObjHandle obj);
|
||||
|
||||
/** Initialise comms.
|
||||
Note: this must be called before you do anything else.
|
||||
Comms will not start until the first call to AhrsPoll() or
|
||||
AhrsSendObjects()
|
||||
*/
|
||||
void AhrsInitComms(void);
|
||||
|
||||
/** Connect Comms to a specific SPI interface instance.
|
||||
*/
|
||||
void AhrsConnect(uint32_t spi_id);
|
||||
|
||||
/** AHRS version of UAVObject xxxSetData.
|
||||
Returns: 0 if ok, -1 if an error
|
||||
*/
|
||||
int32_t AhrsSetData(AhrsObjHandle obj, const void *dataIn);
|
||||
|
||||
/** AHRS version of UAVObject xxxGetData.
|
||||
Returns: 0 if ok, -1 if an error
|
||||
*/
|
||||
int32_t AhrsGetData(AhrsObjHandle obj, void *dataOut);
|
||||
|
||||
/** Connect a callback for any changes to AHRS data.
|
||||
Returns: 0 if ok, -1 if an error
|
||||
*/
|
||||
int32_t AhrsConnectCallBack(AhrsObjHandle obj, AhrsEventCallback cb);
|
||||
|
||||
/** Get the current link status.
|
||||
Returns: the status.
|
||||
Note: the remote status will only be valid if the link is up and running
|
||||
*/
|
||||
void AhrsGetStatus(AhrsCommStatus * status);
|
||||
|
||||
#ifdef IN_AHRS //slave only
|
||||
/** Send the latest objects to the OP
|
||||
This also polls any pending events and kick starts the DMA
|
||||
if needed
|
||||
*/
|
||||
void AhrsPoll();
|
||||
|
||||
/** Check if the link is up and we have received the first batch of updates
|
||||
Returns: True if the link is up and all objects are up to date
|
||||
*/
|
||||
bool AhrsLinkReady();
|
||||
|
||||
#else //master only
|
||||
|
||||
/** Send the latest objects to the AHRS
|
||||
This also polls any pending events
|
||||
*/
|
||||
void AhrsSendObjects(void);
|
||||
|
||||
#endif
|
||||
|
||||
#endif //#ifndef AHRS_SPI_COMM_H_INCLUDED
|
@ -1,143 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @addtogroup OpenPilotModules OpenPilot Modules
|
||||
* @{
|
||||
* @addtogroup AHRSCommsModule AHRSComms Module
|
||||
* @brief Handles communication with AHRS and updating position
|
||||
* Specifically updates the the @ref AttitudeActual "AttitudeActual" and @ref AttitudeRaw "AttitudeRaw" settings objects
|
||||
* @{
|
||||
*
|
||||
* @file ahrs_comms.c
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief Module to handle all comms to the AHRS on a periodic basis.
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
|
||||
/**
|
||||
* Input objects: As defined in PiOS/inc/pios_ahrs_comms.h
|
||||
* Output objects: As defined in PiOS/inc/pios_ahrs_comms.h
|
||||
*
|
||||
* This module will periodically update the values of latest attitude solution
|
||||
* and other objects that are transferred to and from the AHRS
|
||||
* The module settings can configure how often AHRS is polled for a new solution.
|
||||
*
|
||||
* The module executes in its own thread.
|
||||
*
|
||||
* UAVObjects are automatically generated by the UAVObjectGenerator from
|
||||
* the object definition XML file.
|
||||
*
|
||||
* Modules have no API, all communication to other modules is done through UAVObjects.
|
||||
* However modules may use the API exposed by shared libraries.
|
||||
* See the OpenPilot wiki for more details.
|
||||
* http://www.openpilot.org/OpenPilot_Application_Architecture
|
||||
*
|
||||
*/
|
||||
|
||||
#include "ahrs_comms.h"
|
||||
#include "ahrs_spi_comm.h"
|
||||
#include "insstatus.h"
|
||||
|
||||
// Private constants
|
||||
#define STACK_SIZE configMINIMAL_STACK_SIZE
|
||||
#define TASK_PRIORITY (tskIDLE_PRIORITY+4)
|
||||
|
||||
// Private types
|
||||
|
||||
// Private variables
|
||||
static xTaskHandle taskHandle;
|
||||
|
||||
// Private functions
|
||||
static void ahrscommsTask(void *parameters);
|
||||
|
||||
/**
|
||||
* Initialise the module, called on startup
|
||||
* \returns 0 on success or -1 if initialisation failed
|
||||
*/
|
||||
int32_t AHRSCommsStart(void)
|
||||
{
|
||||
// Start main task
|
||||
xTaskCreate(ahrscommsTask, (signed char *)"AHRSComms", STACK_SIZE, NULL, TASK_PRIORITY, &taskHandle);
|
||||
TaskMonitorAdd(TASKINFO_RUNNING_AHRSCOMMS, taskHandle);
|
||||
PIOS_WDG_RegisterFlag(PIOS_WDG_AHRS);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise the module, called on startup
|
||||
* \returns 0 on success or -1 if initialisation failed
|
||||
*/
|
||||
int32_t AHRSCommsInitialize(void)
|
||||
{
|
||||
InsStatusInitialize();
|
||||
InsSettingsInitialize();
|
||||
AttitudeRawInitialize();
|
||||
AttitudeActualInitialize();
|
||||
VelocityActualInitialize();
|
||||
PositionActualInitialize();
|
||||
|
||||
return 0;
|
||||
}
|
||||
MODULE_INITCALL(AHRSCommsInitialize, AHRSCommsStart)
|
||||
|
||||
/**
|
||||
* Module thread, should not return.
|
||||
*/
|
||||
static void ahrscommsTask(void *parameters)
|
||||
{
|
||||
portTickType lastSysTime;
|
||||
|
||||
AlarmsSet(SYSTEMALARMS_ALARM_AHRSCOMMS, SYSTEMALARMS_ALARM_CRITICAL);
|
||||
|
||||
// Main task loop
|
||||
while (1) {
|
||||
PIOS_WDG_UpdateFlag(PIOS_WDG_AHRS);
|
||||
AhrsCommStatus stat;
|
||||
|
||||
AhrsSendObjects();
|
||||
AhrsGetStatus(&stat);
|
||||
if (stat.linkOk) {
|
||||
AlarmsClear(SYSTEMALARMS_ALARM_AHRSCOMMS);
|
||||
} else {
|
||||
AlarmsSet(SYSTEMALARMS_ALARM_AHRSCOMMS, SYSTEMALARMS_ALARM_WARNING);
|
||||
}
|
||||
InsStatusData sData;
|
||||
InsStatusGet(&sData);
|
||||
|
||||
sData.LinkRunning = stat.linkOk;
|
||||
sData.AhrsKickstarts = stat.remote.kickStarts;
|
||||
sData.AhrsCrcErrors = stat.remote.crcErrors;
|
||||
sData.AhrsRetries = stat.remote.retries;
|
||||
sData.AhrsInvalidPackets = stat.remote.invalidPacket;
|
||||
sData.OpCrcErrors = stat.local.crcErrors;
|
||||
sData.OpRetries = stat.local.retries;
|
||||
sData.OpInvalidPackets = stat.local.invalidPacket;
|
||||
|
||||
InsStatusSet(&sData);
|
||||
/* Wait for the next update interval */
|
||||
vTaskDelayUntil(&lastSysTime, 2 / portTICK_RATE_MS);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
@ -1,37 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @addtogroup OpenPilotModules OpenPilot Modules
|
||||
* @{
|
||||
* @addtogroup AHRSCommsModule AHRSComms Module
|
||||
* @{
|
||||
*
|
||||
* @file ahrs_comms.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief Module to handle all comms to the AHRS on a periodic basis.
|
||||
*
|
||||
* @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 AHRS_COMMS_H
|
||||
#define AHRS_COMMS_H
|
||||
|
||||
#include "openpilot.h"
|
||||
|
||||
int32_t AHRSCommsInitialize(void);
|
||||
|
||||
#endif // AHRS_COMMS_H
|
@ -1,243 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file pios_board.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief Defines board hardware for the OpenPilot Version 1.1 hardware.
|
||||
* @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 STM32103CB_AHRS_H_
|
||||
#define STM32103CB_AHRS_H_
|
||||
|
||||
//------------------------
|
||||
// Timers and Channels Used
|
||||
//------------------------
|
||||
/*
|
||||
Timer | Channel 1 | Channel 2 | Channel 3 | Channel 4
|
||||
------+-----------+-----------+-----------+----------
|
||||
TIM1 | | | |
|
||||
TIM2 | --------------- PIOS_DELAY -----------------
|
||||
TIM3 | | | |
|
||||
TIM4 | | | |
|
||||
TIM5 | | | |
|
||||
TIM6 | | | |
|
||||
TIM7 | | | |
|
||||
TIM8 | | | |
|
||||
------+-----------+-----------+-----------+----------
|
||||
*/
|
||||
|
||||
//------------------------
|
||||
// DMA Channels Used
|
||||
//------------------------
|
||||
/* Channel 1 - */
|
||||
/* Channel 2 - */
|
||||
/* Channel 3 - */
|
||||
/* Channel 4 - */
|
||||
/* Channel 5 - */
|
||||
/* Channel 6 - */
|
||||
/* Channel 7 - */
|
||||
/* Channel 8 - */
|
||||
/* Channel 9 - */
|
||||
/* Channel 10 - */
|
||||
/* Channel 11 - */
|
||||
/* Channel 12 - */
|
||||
|
||||
|
||||
//------------------------
|
||||
// BOOTLOADER_SETTINGS
|
||||
//------------------------
|
||||
#define BOARD_READABLE TRUE
|
||||
#define BOARD_WRITABLE TRUE
|
||||
#define MAX_DEL_RETRYS 3
|
||||
|
||||
//------------------------
|
||||
// PIOS_LED
|
||||
//------------------------
|
||||
#define PIOS_LED_HEARTBEAT 0
|
||||
|
||||
//-------------------------
|
||||
// System Settings
|
||||
//-------------------------
|
||||
#define PIOS_MASTER_CLOCK 72000000
|
||||
#define PIOS_PERIPHERAL_CLOCK (PIOS_MASTER_CLOCK / 2)
|
||||
|
||||
//-------------------------
|
||||
// Interrupt Priorities
|
||||
//-------------------------
|
||||
#define PIOS_IRQ_PRIO_LOW 12 // lower than RTOS
|
||||
#define PIOS_IRQ_PRIO_MID 8 // higher than RTOS
|
||||
#define PIOS_IRQ_PRIO_HIGH 5 // for SPI, ADC, I2C etc...
|
||||
#define PIOS_IRQ_PRIO_HIGHEST 4 // for USART etc...
|
||||
|
||||
//------------------------
|
||||
// PIOS_I2C
|
||||
// See also pios_board.c
|
||||
//------------------------
|
||||
#define PIOS_I2C_MAX_DEVS 1
|
||||
extern uint32_t pios_i2c_main_adapter_id;
|
||||
#define PIOS_I2C_MAIN_ADAPTER (pios_i2c_main_adapter_id)
|
||||
|
||||
//-------------------------
|
||||
// SPI
|
||||
//
|
||||
// See also pios_board.c
|
||||
//-------------------------
|
||||
#define PIOS_SPI_MAX_DEVS 1
|
||||
|
||||
//-------------------------
|
||||
// PIOS_USART
|
||||
//-------------------------
|
||||
#define PIOS_USART_MAX_DEVS 2
|
||||
|
||||
//-------------------------
|
||||
// PIOS_COM
|
||||
//
|
||||
// See also pios_board.c
|
||||
//-------------------------
|
||||
#define PIOS_COM_MAX_DEVS 2
|
||||
|
||||
extern uint32_t pios_com_aux_id;
|
||||
#define PIOS_COM_AUX (pios_com_aux_id)
|
||||
#define PIOS_COM_DEBUG PIOS_COM_AUX
|
||||
|
||||
//-------------------------
|
||||
// ADC
|
||||
// PIOS_ADC_PinGet(0) = Accel Z
|
||||
// PIOS_ADC_PinGet(2) = Accel Y
|
||||
// PIOS_ADC_PinGet(4) = Accel X
|
||||
// PIOS_ADC_PinGet(1) = Gyro X
|
||||
// PIOS_ADC_PinGet(3) = Gyro Y
|
||||
// PIOS_ADC_PinGet(5) = Gyro Z
|
||||
// PIOS_ADC_PinGet(6) = XY Temp
|
||||
// PIOS_ADC_PinGet(7) = Z Temp
|
||||
//-------------------------
|
||||
//#define PIOS_ADC_OVERSAMPLING_RATE 1
|
||||
#define PIOS_ADC_USE_TEMP_SENSOR 0
|
||||
#define PIOS_ADC_TEMP_SENSOR_ADC ADC1
|
||||
#define PIOS_ADC_TEMP_SENSOR_ADC_CHANNEL 1
|
||||
|
||||
#define PIOS_ADC_PIN1_GPIO_PORT GPIOA // PA2 (Accel X)
|
||||
#define PIOS_ADC_PIN1_GPIO_PIN GPIO_Pin_2 // ADC12_IN2
|
||||
#define PIOS_ADC_PIN1_GPIO_CHANNEL ADC_Channel_2
|
||||
#define PIOS_ADC_PIN1_ADC ADC1
|
||||
#define PIOS_ADC_PIN1_ADC_NUMBER 1
|
||||
|
||||
#define PIOS_ADC_PIN2_GPIO_PORT GPIOA // PA1 (Accel Y)
|
||||
#define PIOS_ADC_PIN2_GPIO_PIN GPIO_Pin_1 // ADC123_IN1
|
||||
#define PIOS_ADC_PIN2_GPIO_CHANNEL ADC_Channel_1
|
||||
#define PIOS_ADC_PIN2_ADC ADC1
|
||||
#define PIOS_ADC_PIN2_ADC_NUMBER 2
|
||||
|
||||
#define PIOS_ADC_PIN3_GPIO_PORT GPIOA // PA0 (Accel Z)
|
||||
#define PIOS_ADC_PIN3_GPIO_PIN GPIO_Pin_0 // ADC12_IN0
|
||||
#define PIOS_ADC_PIN3_GPIO_CHANNEL ADC_Channel_0
|
||||
#define PIOS_ADC_PIN3_ADC ADC1
|
||||
#define PIOS_ADC_PIN3_ADC_NUMBER 3
|
||||
|
||||
#define PIOS_ADC_PIN4_GPIO_PORT GPIOA // PA6 (Temp_XY)
|
||||
#define PIOS_ADC_PIN4_GPIO_PIN GPIO_Pin_6 // ADC12_IN6
|
||||
#define PIOS_ADC_PIN4_GPIO_CHANNEL ADC_Channel_6
|
||||
#define PIOS_ADC_PIN4_ADC ADC1
|
||||
#define PIOS_ADC_PIN4_ADC_NUMBER 4
|
||||
|
||||
#define PIOS_ADC_PIN5_GPIO_PORT GPIOA // PA4 (Gyro X)
|
||||
#define PIOS_ADC_PIN5_GPIO_PIN GPIO_Pin_4 // ADC12_IN4
|
||||
#define PIOS_ADC_PIN5_GPIO_CHANNEL ADC_Channel_4
|
||||
#define PIOS_ADC_PIN5_ADC ADC2
|
||||
#define PIOS_ADC_PIN5_ADC_NUMBER 1
|
||||
|
||||
#define PIOS_ADC_PIN6_GPIO_PORT GPIOA // PA5 (Gyro Y)
|
||||
#define PIOS_ADC_PIN6_GPIO_PIN GPIO_Pin_5 // ADC12_IN5
|
||||
#define PIOS_ADC_PIN6_GPIO_CHANNEL ADC_Channel_5
|
||||
#define PIOS_ADC_PIN6_ADC ADC2
|
||||
#define PIOS_ADC_PIN6_ADC_NUMBER 2
|
||||
|
||||
#define PIOS_ADC_PIN7_GPIO_PORT GPIOA // PA7 (Gyro Z)
|
||||
#define PIOS_ADC_PIN7_GPIO_PIN GPIO_Pin_7 // ADC12_IN7
|
||||
#define PIOS_ADC_PIN7_GPIO_CHANNEL ADC_Channel_7
|
||||
#define PIOS_ADC_PIN7_ADC ADC2
|
||||
#define PIOS_ADC_PIN7_ADC_NUMBER 3
|
||||
|
||||
#define PIOS_ADC_PIN8_GPIO_PORT GPIOB // PB1 (Z Temp)
|
||||
#define PIOS_ADC_PIN8_GPIO_PIN GPIO_Pin_1 // ADC12_IN9
|
||||
#define PIOS_ADC_PIN8_GPIO_CHANNEL ADC_Channel_9
|
||||
#define PIOS_ADC_PIN8_ADC ADC2
|
||||
#define PIOS_ADC_PIN8_ADC_NUMBER 4
|
||||
|
||||
#define PIOS_ADC_NUM_PINS 8
|
||||
|
||||
#define PIOS_ADC_PORTS { PIOS_ADC_PIN1_GPIO_PORT, PIOS_ADC_PIN2_GPIO_PORT, PIOS_ADC_PIN3_GPIO_PORT, PIOS_ADC_PIN4_GPIO_PORT, PIOS_ADC_PIN5_GPIO_PORT, PIOS_ADC_PIN6_GPIO_PORT, PIOS_ADC_PIN7_GPIO_PORT, PIOS_ADC_PIN8_GPIO_PORT }
|
||||
#define PIOS_ADC_PINS { PIOS_ADC_PIN1_GPIO_PIN, PIOS_ADC_PIN2_GPIO_PIN, PIOS_ADC_PIN3_GPIO_PIN, PIOS_ADC_PIN4_GPIO_PIN, PIOS_ADC_PIN5_GPIO_PIN, PIOS_ADC_PIN6_GPIO_PIN, PIOS_ADC_PIN7_GPIO_PIN, PIOS_ADC_PIN8_GPIO_PIN }
|
||||
#define PIOS_ADC_CHANNELS { PIOS_ADC_PIN1_GPIO_CHANNEL, PIOS_ADC_PIN2_GPIO_CHANNEL, PIOS_ADC_PIN3_GPIO_CHANNEL, PIOS_ADC_PIN4_GPIO_CHANNEL, PIOS_ADC_PIN5_GPIO_CHANNEL, PIOS_ADC_PIN6_GPIO_CHANNEL, PIOS_ADC_PIN7_GPIO_CHANNEL, PIOS_ADC_PIN8_GPIO_CHANNEL }
|
||||
#define PIOS_ADC_MAPPING { PIOS_ADC_PIN1_ADC, PIOS_ADC_PIN2_ADC, PIOS_ADC_PIN3_ADC, PIOS_ADC_PIN4_ADC, PIOS_ADC_PIN5_ADC, PIOS_ADC_PIN6_ADC, PIOS_ADC_PIN7_ADC, PIOS_ADC_PIN8_ADC }
|
||||
#define PIOS_ADC_CHANNEL_MAPPING { PIOS_ADC_PIN1_ADC_NUMBER, PIOS_ADC_PIN2_ADC_NUMBER, PIOS_ADC_PIN3_ADC_NUMBER, PIOS_ADC_PIN4_ADC_NUMBER, PIOS_ADC_PIN5_ADC_NUMBER, PIOS_ADC_PIN6_ADC_NUMBER, PIOS_ADC_PIN7_ADC_NUMBER, PIOS_ADC_PIN8_ADC_NUMBER }
|
||||
#define PIOS_ADC_NUM_CHANNELS (PIOS_ADC_NUM_PINS + PIOS_ADC_USE_TEMP_SENSOR)
|
||||
#define PIOS_ADC_NUM_ADC_CHANNELS 2
|
||||
#define PIOS_ADC_USE_ADC2 1
|
||||
#define PIOS_ADC_ADCCLK RCC_PCLK2_Div2
|
||||
#define PIOS_ADC_PCLK2 RCC_HCLK_Div16
|
||||
#define PIOS_ADC_CLOCK_FUNCTION RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_ADC2, ENABLE); RCC_PCLK2Config(PIOS_ADC_PCLK2);
|
||||
/* RCC_PCLK2_Div2: ADC clock = PCLK2/2 */
|
||||
/* RCC_PCLK2_Div4: ADC clock = PCLK2/4 */
|
||||
/* RCC_PCLK2_Div6: ADC clock = PCLK2/6 */
|
||||
/* RCC_PCLK2_Div8: ADC clock = PCLK2/8 */
|
||||
#define PIOS_ADC_SAMPLE_TIME ADC_SampleTime_239Cycles5
|
||||
/* Sample time: */
|
||||
/* With an ADCCLK = 14 MHz and a sampling time of 239.5 cycles: */
|
||||
/* Tconv = 239.5 + 12.5 = 252 cycles = 18<31>s */
|
||||
/* (1 / (ADCCLK / CYCLES)) = Sample Time (<28>S) */
|
||||
#define PIOS_ADC_IRQ_PRIO PIOS_IRQ_PRIO_LOW
|
||||
|
||||
// Currently analog acquistion hard coded at 480 Hz
|
||||
// PCKL2 = HCLK / 16
|
||||
// ADCCLK = PCLK2 / 2
|
||||
#define PIOS_ADC_RATE (72.0e6 / 16 / 2 / 252 / (PIOS_ADC_NUM_PINS / 2))
|
||||
#define EKF_RATE (PIOS_ADC_RATE / adc_oversampling / 2)
|
||||
#define PIOS_ADC_MAX_OVERSAMPLING 50
|
||||
|
||||
//-------------------------
|
||||
// GPIO
|
||||
//-------------------------
|
||||
#define PIOS_GPIO_1_PORT GPIOB
|
||||
#define PIOS_GPIO_1_PIN GPIO_Pin_9
|
||||
#define PIOS_GPIO_1_GPIO_CLK RCC_APB2Periph_GPIOB
|
||||
#define PIOS_GPIO_PORTS { PIOS_GPIO_1_PORT }
|
||||
#define PIOS_GPIO_PINS { PIOS_GPIO_1_PIN }
|
||||
#define PIOS_GPIO_CLKS { PIOS_GPIO_1_GPIO_CLK }
|
||||
#define PIOS_GPIO_NUM 1
|
||||
#define SET_ACCEL_2G PIOS_GPIO_On(0);
|
||||
#define SET_ACCEL_6G PIOS_GPIO_Off(0)
|
||||
|
||||
//------------------------
|
||||
// PIOS_HMC5843
|
||||
//------------------------
|
||||
#define PIOS_HMC5843_DRDY_GPIO_PORT GPIOB
|
||||
#define PIOS_HMC5843_DRDY_GPIO_PIN GPIO_Pin_8
|
||||
#define PIOS_HMC5843_DRDY_PORT_SOURCE GPIO_PortSourceGPIOB
|
||||
#define PIOS_HMC5843_DRDY_PIN_SOURCE GPIO_PinSource8
|
||||
#define PIOS_HMC5843_DRDY_CLK RCC_APB2Periph_GPIOB
|
||||
#define PIOS_HMC5843_DRDY_EXTI_LINE EXTI_Line8
|
||||
#define PIOS_HMC5843_DRDY_IRQn EXTI9_5_IRQn
|
||||
#define PIOS_HMC5843_DRDY_PRIO PIOS_IRQ_PRIO_HIGH
|
||||
|
||||
|
||||
|
||||
#endif /* STM32103CB_AHRS_H_ */
|
@ -275,4 +275,4 @@ extern uint32_t pios_com_debug_id;
|
||||
#define PIOS_USB_DETECT_GPIO_PORT GPIOC
|
||||
#define PIOS_USB_MAX_DEVS 1
|
||||
#define PIOS_USB_DETECT_GPIO_PIN GPIO_Pin_15
|
||||
#endif /* STM32103CB_AHRS_H_ */
|
||||
#endif /* STM32103CB_CC_H_ */
|
||||
|
@ -1,9 +1,7 @@
|
||||
#ifndef PIOS_BOARD_H_
|
||||
#define PIOS_BOARD_H_
|
||||
|
||||
#ifdef USE_STM32103CB_AHRS
|
||||
#include "STM32103CB_AHRS.h"
|
||||
#elif USE_STM3210E_OP
|
||||
#ifdef USE_STM3210E_OP
|
||||
#include "STM3210E_OP.h"
|
||||
#elif USE_STM32103CB_PIPXTREME
|
||||
#include "STM32103CB_PIPXTREME_Rev1.h"
|
||||
|
@ -1,343 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @addtogroup PIOS PIOS Core hardware abstraction layer
|
||||
* @{
|
||||
* @addtogroup PIOS_OPAHRS OPAHRS Functions
|
||||
* @brief HAL code to interface to the OpenPilot AHRS module
|
||||
* @{
|
||||
*
|
||||
* @file pios_opahrs.c
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief Hardware commands to communicate with the AHRS
|
||||
* @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
|
||||
*/
|
||||
|
||||
/* Project Includes */
|
||||
#include "pios.h"
|
||||
|
||||
#if defined(PIOS_INCLUDE_OPAHRS)
|
||||
|
||||
#include "pios_opahrs_proto.h"
|
||||
#include "pios_opahrs.h"
|
||||
|
||||
/**
|
||||
* Initialise the OpenPilot AHRS
|
||||
*/
|
||||
void PIOS_OPAHRS_Init(void)
|
||||
{
|
||||
PIOS_SPI_SetClockSpeed(PIOS_OPAHRS_SPI, PIOS_SPI_PRESCALER_8);
|
||||
}
|
||||
|
||||
static int32_t opahrs_msg_txrx(const uint8_t * tx, uint8_t * rx, uint32_t len)
|
||||
{
|
||||
int32_t rc;
|
||||
|
||||
PIOS_SPI_RC_PinSet(PIOS_OPAHRS_SPI, 0);
|
||||
#ifdef PIOS_INCLUDE_FREERTOS
|
||||
vTaskDelay(1 / portTICK_RATE_MS);
|
||||
#else
|
||||
PIOS_DELAY_WaitmS(20);
|
||||
#endif
|
||||
rc = PIOS_SPI_TransferBlock(PIOS_OPAHRS_SPI, tx, rx, len, NULL);
|
||||
PIOS_SPI_RC_PinSet(PIOS_OPAHRS_SPI, 1);
|
||||
return (rc);
|
||||
}
|
||||
|
||||
static enum opahrs_result opahrs_msg_v1_send_req(const struct opahrs_msg_v1 *req)
|
||||
{
|
||||
int32_t rc;
|
||||
struct opahrs_msg_v1 link_rx;
|
||||
|
||||
for (uint8_t retries = 0; retries < 20; retries++) {
|
||||
struct opahrs_msg_v1 *rsp = &link_rx;
|
||||
|
||||
if ((rc = opahrs_msg_txrx((const uint8_t *)req, (uint8_t *) rsp, sizeof(*rsp))) < 0) {
|
||||
return OPAHRS_RESULT_FAILED;
|
||||
}
|
||||
|
||||
/* Make sure we got a sane response by checking the magic */
|
||||
if ((rsp->head.magic != OPAHRS_MSG_MAGIC_HEAD) || (rsp->tail.magic != OPAHRS_MSG_MAGIC_TAIL)) {
|
||||
return OPAHRS_RESULT_FAILED;
|
||||
}
|
||||
|
||||
switch (rsp->head.type) {
|
||||
case OPAHRS_MSG_TYPE_LINK:
|
||||
switch (rsp->payload.link.state) {
|
||||
case OPAHRS_MSG_LINK_STATE_BUSY:
|
||||
case OPAHRS_MSG_LINK_STATE_INACTIVE:
|
||||
/* Wait for a small delay and retry */
|
||||
#ifdef PIOS_INCLUDE_FREERTOS
|
||||
vTaskDelay(1 / portTICK_RATE_MS);
|
||||
#else
|
||||
PIOS_DELAY_WaitmS(20);
|
||||
#endif
|
||||
continue;
|
||||
case OPAHRS_MSG_LINK_STATE_READY:
|
||||
/* Peer was ready when we Tx'd so they have now Rx'd our message */
|
||||
return OPAHRS_RESULT_OK;
|
||||
}
|
||||
break;
|
||||
case OPAHRS_MSG_TYPE_USER_V0:
|
||||
case OPAHRS_MSG_TYPE_USER_V1:
|
||||
/* Wait for a small delay and retry */
|
||||
#ifdef PIOS_INCLUDE_FREERTOS
|
||||
vTaskDelay(1 / portTICK_RATE_MS);
|
||||
#else
|
||||
PIOS_DELAY_WaitmS(50);
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return OPAHRS_RESULT_TIMEOUT;
|
||||
}
|
||||
|
||||
static enum opahrs_result opahrs_msg_v1_recv_rsp(enum opahrs_msg_v1_tag tag, struct opahrs_msg_v1 *rsp)
|
||||
{
|
||||
struct opahrs_msg_v1 link_tx;
|
||||
|
||||
opahrs_msg_v1_init_link_tx(&link_tx, OPAHRS_MSG_LINK_TAG_NOP);
|
||||
|
||||
for (uint8_t retries = 0; retries < 20; retries++) {
|
||||
if (opahrs_msg_txrx((const uint8_t *)&link_tx, (uint8_t *) rsp, sizeof(*rsp)) < 0) {
|
||||
return OPAHRS_RESULT_FAILED;
|
||||
}
|
||||
|
||||
/* Make sure we got a sane response by checking the magic */
|
||||
if ((rsp->head.magic != OPAHRS_MSG_MAGIC_HEAD) || (rsp->tail.magic != OPAHRS_MSG_MAGIC_TAIL)) {
|
||||
return OPAHRS_RESULT_FAILED;
|
||||
}
|
||||
|
||||
switch (rsp->head.type) {
|
||||
case OPAHRS_MSG_TYPE_LINK:
|
||||
switch (rsp->payload.link.state) {
|
||||
case OPAHRS_MSG_LINK_STATE_BUSY:
|
||||
/* Wait for a small delay and retry */
|
||||
#ifdef PIOS_INCLUDE_FREERTOS
|
||||
vTaskDelay(1 / portTICK_RATE_MS);
|
||||
#else
|
||||
PIOS_DELAY_WaitmS(20);
|
||||
#endif
|
||||
continue;
|
||||
case OPAHRS_MSG_LINK_STATE_INACTIVE:
|
||||
case OPAHRS_MSG_LINK_STATE_READY:
|
||||
/* somehow, we've missed our response */
|
||||
return OPAHRS_RESULT_FAILED;
|
||||
}
|
||||
break;
|
||||
case OPAHRS_MSG_TYPE_USER_V0:
|
||||
/* This isn't the type we expected */
|
||||
return OPAHRS_RESULT_FAILED;
|
||||
break;
|
||||
case OPAHRS_MSG_TYPE_USER_V1:
|
||||
if (rsp->payload.user.t == tag) {
|
||||
return OPAHRS_RESULT_OK;
|
||||
} else {
|
||||
return OPAHRS_RESULT_FAILED;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return OPAHRS_RESULT_TIMEOUT;
|
||||
}
|
||||
|
||||
static enum opahrs_result PIOS_OPAHRS_v1_simple_req(enum opahrs_msg_v1_tag req_type, struct opahrs_msg_v1 *rsp, enum opahrs_msg_v1_tag rsp_type)
|
||||
{
|
||||
struct opahrs_msg_v1 req;
|
||||
enum opahrs_result rc;
|
||||
|
||||
/* Make up an empty request */
|
||||
opahrs_msg_v1_init_user_tx(&req, req_type);
|
||||
|
||||
/* Send the message until it is received */
|
||||
rc = opahrs_msg_v1_send_req(&req);
|
||||
if ((rc == OPAHRS_RESULT_OK) && rsp) {
|
||||
/* We need a specific kind of reply, go get it */
|
||||
return opahrs_msg_v1_recv_rsp(rsp_type, rsp);
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
enum opahrs_result PIOS_OPAHRS_GetSerial(struct opahrs_msg_v1 *rsp)
|
||||
{
|
||||
if (!rsp)
|
||||
return OPAHRS_RESULT_FAILED;
|
||||
|
||||
return (PIOS_OPAHRS_v1_simple_req(OPAHRS_MSG_V1_REQ_SERIAL, rsp, OPAHRS_MSG_V1_RSP_SERIAL));
|
||||
}
|
||||
|
||||
enum opahrs_result PIOS_OPAHRS_resync(void)
|
||||
{
|
||||
struct opahrs_msg_v1 req;
|
||||
struct opahrs_msg_v1 rsp;
|
||||
|
||||
enum opahrs_result rc = OPAHRS_RESULT_FAILED;
|
||||
|
||||
opahrs_msg_v1_init_link_tx(&req, OPAHRS_MSG_LINK_TAG_NOP);
|
||||
|
||||
PIOS_SPI_RC_PinSet(PIOS_OPAHRS_SPI, 0);
|
||||
#ifdef PIOS_INCLUDE_FREERTOS
|
||||
vTaskDelay(1 / portTICK_RATE_MS);
|
||||
#else
|
||||
PIOS_DELAY_WaitmS(20);
|
||||
#endif
|
||||
|
||||
for (uint32_t i = 0; i < sizeof(req); i++) {
|
||||
/* Tx a shortened (by one byte) message to walk through all byte positions */
|
||||
opahrs_msg_v1_init_rx(&rsp);
|
||||
PIOS_SPI_TransferBlock(PIOS_OPAHRS_SPI, (uint8_t *) & req, (uint8_t *) & rsp, sizeof(req) - 1, NULL);
|
||||
|
||||
/* Good magic means we're sync'd */
|
||||
if ((rsp.head.magic == OPAHRS_MSG_MAGIC_HEAD) && (rsp.tail.magic == OPAHRS_MSG_MAGIC_TAIL)) {
|
||||
/* We need to shift out one more byte to compensate for the short tx */
|
||||
PIOS_SPI_TransferByte(PIOS_OPAHRS_SPI, 0x00);
|
||||
rc = OPAHRS_RESULT_OK;
|
||||
break;
|
||||
}
|
||||
#ifdef PIOS_INCLUDE_FREERTOS
|
||||
vTaskDelay(1 / portTICK_RATE_MS);
|
||||
#else
|
||||
PIOS_DELAY_WaitmS(10);
|
||||
#endif
|
||||
}
|
||||
|
||||
PIOS_SPI_RC_PinSet(PIOS_OPAHRS_SPI, 1);
|
||||
//vTaskDelay(5 / portTICK_RATE_MS);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
enum opahrs_result PIOS_OPAHRS_GetAttitudeRaw(struct opahrs_msg_v1 *rsp)
|
||||
{
|
||||
if (!rsp)
|
||||
return OPAHRS_RESULT_FAILED;
|
||||
|
||||
return (PIOS_OPAHRS_v1_simple_req(OPAHRS_MSG_V1_REQ_ATTITUDERAW, rsp, OPAHRS_MSG_V1_RSP_ATTITUDERAW));
|
||||
}
|
||||
|
||||
extern enum opahrs_result PIOS_OPAHRS_SetAlgorithm(struct opahrs_msg_v1 *req)
|
||||
{
|
||||
struct opahrs_msg_v1 rsp;
|
||||
enum opahrs_result rc;
|
||||
|
||||
if (!req)
|
||||
return OPAHRS_RESULT_FAILED;
|
||||
|
||||
/* Make up an attituderaw request */
|
||||
opahrs_msg_v1_init_user_tx(req, OPAHRS_MSG_V1_REQ_ALGORITHM);
|
||||
|
||||
/* Send the message until it is received */
|
||||
rc = opahrs_msg_v1_send_req(req);
|
||||
if (rc != OPAHRS_RESULT_OK) {
|
||||
/* Failed to send the request, bail out */
|
||||
return rc;
|
||||
}
|
||||
|
||||
return opahrs_msg_v1_recv_rsp(OPAHRS_MSG_V1_RSP_ALGORITHM, &rsp);
|
||||
}
|
||||
|
||||
enum opahrs_result PIOS_OPAHRS_SetMagNorth(struct opahrs_msg_v1 *req)
|
||||
{
|
||||
struct opahrs_msg_v1 rsp;
|
||||
enum opahrs_result rc;
|
||||
|
||||
if (!req)
|
||||
return OPAHRS_RESULT_FAILED;
|
||||
|
||||
/* Make up an attituderaw request */
|
||||
opahrs_msg_v1_init_user_tx(req, OPAHRS_MSG_V1_REQ_NORTH);
|
||||
|
||||
/* Send the message until it is received */
|
||||
rc = opahrs_msg_v1_send_req(req);
|
||||
if (rc != OPAHRS_RESULT_OK) {
|
||||
/* Failed to send the request, bail out */
|
||||
return rc;
|
||||
}
|
||||
|
||||
return opahrs_msg_v1_recv_rsp(OPAHRS_MSG_V1_RSP_NORTH, &rsp);
|
||||
}
|
||||
|
||||
enum opahrs_result PIOS_OPAHRS_SetGetUpdate(struct opahrs_msg_v1 *req, struct opahrs_msg_v1 *rsp)
|
||||
{
|
||||
enum opahrs_result rc;
|
||||
|
||||
if (!req)
|
||||
return OPAHRS_RESULT_FAILED;
|
||||
|
||||
/* Make up an attituderaw request */
|
||||
opahrs_msg_v1_init_user_tx(req, OPAHRS_MSG_V1_REQ_UPDATE);
|
||||
|
||||
/* Send the message until it is received */
|
||||
rc = opahrs_msg_v1_send_req(req);
|
||||
if (rc != OPAHRS_RESULT_OK) {
|
||||
/* Failed to send the request, bail out */
|
||||
return rc;
|
||||
}
|
||||
|
||||
return opahrs_msg_v1_recv_rsp(OPAHRS_MSG_V1_RSP_UPDATE, rsp);
|
||||
}
|
||||
|
||||
enum opahrs_result PIOS_OPAHRS_SetGetCalibration(struct opahrs_msg_v1 *req, struct opahrs_msg_v1 *rsp)
|
||||
{
|
||||
enum opahrs_result rc;
|
||||
|
||||
if (!req)
|
||||
return OPAHRS_RESULT_FAILED;
|
||||
|
||||
/* Make up an attituderaw request */
|
||||
opahrs_msg_v1_init_user_tx(req, OPAHRS_MSG_V1_REQ_CALIBRATION);
|
||||
|
||||
/* Send the message until it is received */
|
||||
rc = opahrs_msg_v1_send_req(req);
|
||||
if (rc != OPAHRS_RESULT_OK) {
|
||||
/* Failed to send the request, bail out */
|
||||
return rc;
|
||||
}
|
||||
|
||||
return opahrs_msg_v1_recv_rsp(OPAHRS_MSG_V1_RSP_CALIBRATION, rsp);
|
||||
}
|
||||
|
||||
enum opahrs_result PIOS_OPAHRS_SetGetInitialized(struct opahrs_msg_v1 *req, struct opahrs_msg_v1 *rsp)
|
||||
{
|
||||
enum opahrs_result rc;
|
||||
|
||||
if (!req)
|
||||
return OPAHRS_RESULT_FAILED;
|
||||
|
||||
/* Make up an attituderaw request */
|
||||
opahrs_msg_v1_init_user_tx(req, OPAHRS_MSG_V1_REQ_INITIALIZED);
|
||||
|
||||
/* Send the message until it is received */
|
||||
rc = opahrs_msg_v1_send_req(req);
|
||||
if (rc != OPAHRS_RESULT_OK) {
|
||||
/* Failed to send the request, bail out */
|
||||
return rc;
|
||||
}
|
||||
|
||||
return opahrs_msg_v1_recv_rsp(OPAHRS_MSG_V1_RSP_INITIALIZED, rsp);
|
||||
}
|
||||
|
||||
#endif /* PIOS_INCLUDE_OPAHRS */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
@ -1,76 +0,0 @@
|
||||
/**
|
||||
* @addtogroup PIOS PIOS Core hardware abstraction layer
|
||||
* @{
|
||||
* @addtogroup PIOS_OPAHRS OPAHRS Functions
|
||||
* @{
|
||||
*
|
||||
* @file pios_opahrs_proto.c
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief PPM Input functions
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
*
|
||||
*/
|
||||
|
||||
#include "pios_opahrs_proto.h"
|
||||
#include <string.h> /* memset */
|
||||
|
||||
void opahrs_msg_v0_init_rx(struct opahrs_msg_v0 *msg)
|
||||
{
|
||||
/* Make sure we start with bad magic in the rx buffer */
|
||||
msg->head.magic = 0;
|
||||
msg->head.type = 0;
|
||||
msg->tail.magic = 0;
|
||||
}
|
||||
|
||||
void opahrs_msg_v0_init_user_tx(struct opahrs_msg_v0 *msg, enum opahrs_msg_v0_tag tag)
|
||||
{
|
||||
msg->head.magic = OPAHRS_MSG_MAGIC_HEAD;
|
||||
msg->head.type = OPAHRS_MSG_TYPE_USER_V0;
|
||||
|
||||
msg->payload.user.t = tag;
|
||||
|
||||
msg->tail.magic = OPAHRS_MSG_MAGIC_TAIL;
|
||||
}
|
||||
|
||||
void opahrs_msg_v0_init_link_tx(struct opahrs_msg_v0 *msg, enum opahrs_msg_link_tag tag)
|
||||
{
|
||||
msg->head.magic = OPAHRS_MSG_MAGIC_HEAD;
|
||||
msg->head.type = OPAHRS_MSG_TYPE_LINK;
|
||||
|
||||
msg->payload.link.t = tag;
|
||||
|
||||
msg->tail.magic = OPAHRS_MSG_MAGIC_TAIL;
|
||||
}
|
||||
|
||||
void opahrs_msg_v1_init_rx(struct opahrs_msg_v1 *msg)
|
||||
{
|
||||
/* Make sure we start with bad magic in the rx buffer */
|
||||
msg->head.magic = 0;
|
||||
msg->head.type = 0;
|
||||
msg->tail.magic = 0;
|
||||
}
|
||||
|
||||
void opahrs_msg_v1_init_user_tx(struct opahrs_msg_v1 *msg, enum opahrs_msg_v1_tag tag)
|
||||
{
|
||||
msg->head.magic = OPAHRS_MSG_MAGIC_HEAD;
|
||||
msg->head.type = OPAHRS_MSG_TYPE_USER_V1;
|
||||
|
||||
msg->payload.user.t = tag;
|
||||
|
||||
msg->tail.magic = OPAHRS_MSG_MAGIC_TAIL;
|
||||
}
|
||||
|
||||
void opahrs_msg_v1_init_link_tx(struct opahrs_msg_v1 *msg, enum opahrs_msg_link_tag tag)
|
||||
{
|
||||
msg->head.magic = OPAHRS_MSG_MAGIC_HEAD;
|
||||
msg->head.type = OPAHRS_MSG_TYPE_LINK;
|
||||
|
||||
msg->payload.link.t = tag;
|
||||
|
||||
msg->tail.magic = OPAHRS_MSG_MAGIC_TAIL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
@ -1,330 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @addtogroup PIOS PIOS Core hardware abstraction layer
|
||||
* @{
|
||||
* @addtogroup PIOS_OPAHRS OPAHRS Functions
|
||||
* @brief HAL code to interface to the OpenPilot AHRS module's bootloader
|
||||
* @{
|
||||
*
|
||||
* @file pios_opahrs_download.c
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief Hardware commands to communicate with the AHRS bootloader
|
||||
* @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
|
||||
*/
|
||||
|
||||
/* Project Includes */
|
||||
#include "pios.h"
|
||||
|
||||
#if defined(PIOS_INCLUDE_OPAHRS)
|
||||
|
||||
#include "pios_opahrs_proto.h"
|
||||
#include "pios_opahrs.h"
|
||||
|
||||
static uint32_t PIOS_OPAHRS_SPI;
|
||||
|
||||
void PIOS_OPAHRS_Attach(uint32_t spi_id)
|
||||
{
|
||||
PIOS_OPAHRS_SPI = spi_id;
|
||||
}
|
||||
|
||||
void PIOS_OPAHRS_ForceSlaveSelected(bool selected)
|
||||
{
|
||||
if (selected) {
|
||||
PIOS_SPI_RC_PinSet(PIOS_OPAHRS_SPI, 0);
|
||||
} else {
|
||||
PIOS_SPI_RC_PinSet(PIOS_OPAHRS_SPI, 1);
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t opahrs_msg_txrx(const uint8_t * tx, uint8_t * rx, uint32_t len)
|
||||
{
|
||||
int32_t rc;
|
||||
|
||||
PIOS_SPI_RC_PinSet(PIOS_OPAHRS_SPI, 0);
|
||||
#ifdef PIOS_INCLUDE_FREERTOS
|
||||
vTaskDelay(20 / portTICK_RATE_MS);
|
||||
#else
|
||||
PIOS_DELAY_WaitmS(1);
|
||||
#endif
|
||||
rc = PIOS_SPI_TransferBlock(PIOS_OPAHRS_SPI, tx, rx, len, NULL);
|
||||
PIOS_SPI_RC_PinSet(PIOS_OPAHRS_SPI, 1);
|
||||
return (rc);
|
||||
}
|
||||
|
||||
static enum opahrs_result opahrs_msg_v0_send_req(const struct opahrs_msg_v0 *req)
|
||||
{
|
||||
int32_t rc;
|
||||
struct opahrs_msg_v0 link_rx;
|
||||
|
||||
for (uint8_t retries = 0; retries < 20; retries++) {
|
||||
struct opahrs_msg_v0 *rsp = &link_rx;
|
||||
|
||||
if ((rc = opahrs_msg_txrx((const uint8_t *)req, (uint8_t *) rsp, sizeof(*rsp))) < 0) {
|
||||
return OPAHRS_RESULT_FAILED;
|
||||
}
|
||||
|
||||
/* Make sure we got a sane response by checking the magic */
|
||||
if ((rsp->head.magic != OPAHRS_MSG_MAGIC_HEAD) || (rsp->tail.magic != OPAHRS_MSG_MAGIC_TAIL)) {
|
||||
return OPAHRS_RESULT_FAILED;
|
||||
}
|
||||
|
||||
switch (rsp->head.type) {
|
||||
case OPAHRS_MSG_TYPE_LINK:
|
||||
switch (rsp->payload.link.state) {
|
||||
case OPAHRS_MSG_LINK_STATE_BUSY:
|
||||
case OPAHRS_MSG_LINK_STATE_INACTIVE:
|
||||
/* Wait for a small delay and retry */
|
||||
#ifdef PIOS_INCLUDE_FREERTOS
|
||||
vTaskDelay(20 / portTICK_RATE_MS);
|
||||
#else
|
||||
//PIOS_DELAY_WaitmS(1);
|
||||
#endif
|
||||
continue;
|
||||
case OPAHRS_MSG_LINK_STATE_READY:
|
||||
/* Peer was ready when we Tx'd so they have now Rx'd our message */
|
||||
return OPAHRS_RESULT_OK;
|
||||
}
|
||||
break;
|
||||
case OPAHRS_MSG_TYPE_USER_V0:
|
||||
case OPAHRS_MSG_TYPE_USER_V1:
|
||||
/* Wait for a small delay and retry */
|
||||
#ifdef PIOS_INCLUDE_FREERTOS
|
||||
vTaskDelay(50 / portTICK_RATE_MS);
|
||||
#else
|
||||
//PIOS_DELAY_WaitmS(1);
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return OPAHRS_RESULT_TIMEOUT;
|
||||
}
|
||||
|
||||
static enum opahrs_result opahrs_msg_v0_recv_rsp(enum opahrs_msg_v0_tag tag, struct opahrs_msg_v0 *rsp)
|
||||
{
|
||||
struct opahrs_msg_v0 link_tx;
|
||||
|
||||
opahrs_msg_v0_init_link_tx(&link_tx, OPAHRS_MSG_LINK_TAG_NOP);
|
||||
|
||||
for (uint8_t retries = 0; retries < 20; retries++) {
|
||||
if (opahrs_msg_txrx((const uint8_t *)&link_tx, (uint8_t *) rsp, sizeof(*rsp)) < 0) {
|
||||
return OPAHRS_RESULT_FAILED;
|
||||
}
|
||||
|
||||
/* Make sure we got a sane response by checking the magic */
|
||||
if ((rsp->head.magic != OPAHRS_MSG_MAGIC_HEAD) || (rsp->tail.magic != OPAHRS_MSG_MAGIC_TAIL)) {
|
||||
return OPAHRS_RESULT_FAILED;
|
||||
}
|
||||
|
||||
switch (rsp->head.type) {
|
||||
case OPAHRS_MSG_TYPE_LINK:
|
||||
switch (rsp->payload.link.state) {
|
||||
case OPAHRS_MSG_LINK_STATE_BUSY:
|
||||
/* Wait for a small delay and retry */
|
||||
#ifdef PIOS_INCLUDE_FREERTOS
|
||||
vTaskDelay(20 / portTICK_RATE_MS);
|
||||
#else
|
||||
PIOS_DELAY_WaitmS(1);
|
||||
#endif
|
||||
continue;
|
||||
case OPAHRS_MSG_LINK_STATE_INACTIVE:
|
||||
case OPAHRS_MSG_LINK_STATE_READY:
|
||||
/* somehow, we've missed our response */
|
||||
return OPAHRS_RESULT_FAILED;
|
||||
}
|
||||
break;
|
||||
case OPAHRS_MSG_TYPE_USER_V0:
|
||||
if (rsp->payload.user.t == tag) {
|
||||
return OPAHRS_RESULT_OK;
|
||||
} else {
|
||||
return OPAHRS_RESULT_FAILED;
|
||||
}
|
||||
break;
|
||||
case OPAHRS_MSG_TYPE_USER_V1:
|
||||
/* This isn't the type we expected */
|
||||
return OPAHRS_RESULT_FAILED;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return OPAHRS_RESULT_TIMEOUT;
|
||||
}
|
||||
|
||||
static enum opahrs_result PIOS_OPAHRS_v0_simple_req(enum opahrs_msg_v0_tag req_type, struct opahrs_msg_v0 *rsp, enum opahrs_msg_v0_tag rsp_type)
|
||||
{
|
||||
struct opahrs_msg_v0 req;
|
||||
enum opahrs_result rc;
|
||||
|
||||
/* Make up an empty request */
|
||||
opahrs_msg_v0_init_user_tx(&req, req_type);
|
||||
|
||||
/* Send the message until it is received */
|
||||
|
||||
rc = opahrs_msg_v0_send_req(&req);
|
||||
if ((rc == OPAHRS_RESULT_OK) && rsp) {
|
||||
/* We need a specific kind of reply, go get it */
|
||||
return opahrs_msg_v0_recv_rsp(rsp_type, rsp);
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
enum opahrs_result PIOS_OPAHRS_bl_GetVersions(struct opahrs_msg_v0 *rsp)
|
||||
{
|
||||
if (!rsp)
|
||||
return OPAHRS_RESULT_FAILED;
|
||||
|
||||
return (PIOS_OPAHRS_v0_simple_req(OPAHRS_MSG_V0_REQ_VERSIONS, rsp, OPAHRS_MSG_V0_RSP_VERSIONS));
|
||||
}
|
||||
|
||||
enum opahrs_result PIOS_OPAHRS_bl_GetMemMap(struct opahrs_msg_v0 *rsp)
|
||||
{
|
||||
if (!rsp)
|
||||
return OPAHRS_RESULT_FAILED;
|
||||
|
||||
return (PIOS_OPAHRS_v0_simple_req(OPAHRS_MSG_V0_REQ_MEM_MAP, rsp, OPAHRS_MSG_V0_RSP_MEM_MAP));
|
||||
}
|
||||
|
||||
enum opahrs_result PIOS_OPAHRS_bl_GetSerial(struct opahrs_msg_v0 *rsp)
|
||||
{
|
||||
if (!rsp)
|
||||
return OPAHRS_RESULT_FAILED;
|
||||
|
||||
return (PIOS_OPAHRS_v0_simple_req(OPAHRS_MSG_V0_REQ_SERIAL, rsp, OPAHRS_MSG_V0_RSP_SERIAL));
|
||||
}
|
||||
|
||||
enum opahrs_result PIOS_OPAHRS_bl_FwupStart(struct opahrs_msg_v0 *rsp)
|
||||
{
|
||||
if (!rsp)
|
||||
return OPAHRS_RESULT_FAILED;
|
||||
return (PIOS_OPAHRS_v0_simple_req(OPAHRS_MSG_V0_REQ_FWUP_START, rsp, OPAHRS_MSG_V0_RSP_FWUP_STATUS));
|
||||
}
|
||||
|
||||
enum opahrs_result PIOS_OPAHRS_bl_FwupStatus(struct opahrs_msg_v0 *rsp)
|
||||
{
|
||||
if (!rsp)
|
||||
return OPAHRS_RESULT_FAILED;
|
||||
return (PIOS_OPAHRS_v0_simple_req(OPAHRS_MSG_V0_REQ_FWUP_STATUS, rsp, OPAHRS_MSG_V0_RSP_FWUP_STATUS));
|
||||
}
|
||||
|
||||
enum opahrs_result PIOS_OPAHRS_bl_FwupData(struct opahrs_msg_v0 *req, struct opahrs_msg_v0 *rsp)
|
||||
{
|
||||
if (!req || !rsp)
|
||||
return OPAHRS_RESULT_FAILED;
|
||||
|
||||
/* Make up an attituderaw request */
|
||||
opahrs_msg_v0_init_user_tx(req, OPAHRS_MSG_V0_REQ_FWUP_DATA);
|
||||
enum opahrs_result rc;
|
||||
/* Send the message until it is received */
|
||||
rc = opahrs_msg_v0_send_req(req);
|
||||
if (rc != OPAHRS_RESULT_OK) {
|
||||
/* Failed to send the request, bail out */
|
||||
return rc;
|
||||
}
|
||||
|
||||
return opahrs_msg_v0_recv_rsp(OPAHRS_MSG_V0_RSP_FWUP_STATUS, rsp);
|
||||
}
|
||||
|
||||
enum opahrs_result PIOS_OPAHRS_bl_FwDlData(struct opahrs_msg_v0 *req, struct opahrs_msg_v0 *rsp)
|
||||
{
|
||||
if (!req || !rsp)
|
||||
return OPAHRS_RESULT_FAILED;
|
||||
|
||||
/* Make up an attituderaw request */
|
||||
opahrs_msg_v0_init_user_tx(req, OPAHRS_MSG_V0_REQ_FWDN_DATA);
|
||||
enum opahrs_result rc;
|
||||
/* Send the message until it is received */
|
||||
rc = opahrs_msg_v0_send_req(req);
|
||||
if (rc != OPAHRS_RESULT_OK) {
|
||||
/* Failed to send the request, bail out */
|
||||
return rc;
|
||||
}
|
||||
|
||||
return opahrs_msg_v0_recv_rsp(OPAHRS_MSG_V0_RSP_FWDN_DATA, rsp);
|
||||
}
|
||||
|
||||
enum opahrs_result PIOS_OPAHRS_bl_FwupVerify(struct opahrs_msg_v0 *rsp)
|
||||
{
|
||||
if (!rsp)
|
||||
return OPAHRS_RESULT_FAILED;
|
||||
|
||||
return (PIOS_OPAHRS_v0_simple_req(OPAHRS_MSG_V0_REQ_FWUP_VERIFY, rsp, OPAHRS_MSG_V0_RSP_FWUP_STATUS));
|
||||
}
|
||||
|
||||
enum opahrs_result PIOS_OPAHRS_bl_resync(void)
|
||||
{
|
||||
struct opahrs_msg_v0 req;
|
||||
struct opahrs_msg_v0 rsp;
|
||||
|
||||
enum opahrs_result rc = OPAHRS_RESULT_FAILED;
|
||||
|
||||
opahrs_msg_v0_init_link_tx(&req, OPAHRS_MSG_LINK_TAG_NOP);
|
||||
|
||||
PIOS_SPI_RC_PinSet(PIOS_OPAHRS_SPI, 0);
|
||||
#ifdef PIOS_INCLUDE_FREERTOS
|
||||
vTaskDelay(20 / portTICK_RATE_MS);
|
||||
#else
|
||||
//PIOS_DELAY_WaitmS(1);
|
||||
#endif
|
||||
|
||||
for (uint32_t i = 0; i < sizeof(req); i++) {
|
||||
/* Tx a shortened (by one byte) message to walk through all byte positions */
|
||||
opahrs_msg_v0_init_rx(&rsp);
|
||||
PIOS_SPI_TransferBlock(PIOS_OPAHRS_SPI, (uint8_t *) & req, (uint8_t *) & rsp, sizeof(req) - 1, NULL);
|
||||
|
||||
/* Good magic means we're sync'd */
|
||||
if ((rsp.head.magic == OPAHRS_MSG_MAGIC_HEAD) && (rsp.tail.magic == OPAHRS_MSG_MAGIC_TAIL)) {
|
||||
/* We need to shift out one more byte to compensate for the short tx */
|
||||
PIOS_SPI_TransferByte(PIOS_OPAHRS_SPI, 0x00);
|
||||
rc = OPAHRS_RESULT_OK;
|
||||
break;
|
||||
}
|
||||
#ifdef PIOS_INCLUDE_FREERTOS
|
||||
vTaskDelay(10 / portTICK_RATE_MS);
|
||||
#else
|
||||
PIOS_DELAY_WaitmS(1);
|
||||
#endif
|
||||
}
|
||||
|
||||
PIOS_SPI_RC_PinSet(PIOS_OPAHRS_SPI, 1);
|
||||
//vTaskDelay(5 / portTICK_RATE_MS);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
enum opahrs_result PIOS_OPAHRS_bl_reset(uint32_t delay)
|
||||
{
|
||||
struct opahrs_msg_v0 req;
|
||||
/* Make up an attituderaw request */
|
||||
opahrs_msg_v0_init_user_tx(&req, OPAHRS_MSG_V0_REQ_RESET);
|
||||
req.payload.user.v.req.reset.reset_delay_in_ms = delay;
|
||||
/* Send the message until it is received */
|
||||
return opahrs_msg_v0_send_req(&req);
|
||||
}
|
||||
|
||||
enum opahrs_result PIOS_OPAHRS_bl_boot(uint32_t delay)
|
||||
{
|
||||
struct opahrs_msg_v0 req;
|
||||
/* Make up an attituderaw request */
|
||||
opahrs_msg_v0_init_user_tx(&req, OPAHRS_MSG_V0_REQ_BOOT);
|
||||
req.payload.user.v.req.boot.boot_delay_in_ms = delay;
|
||||
/* Send the message until it is received */
|
||||
return opahrs_msg_v0_send_req(&req);
|
||||
}
|
||||
#endif /* PIOS_INCLUDE_OPAHRS */
|
@ -1,56 +0,0 @@
|
||||
_estack = 0x20004FF0;
|
||||
|
||||
/* Section Definitions */
|
||||
SECTIONS
|
||||
{
|
||||
.text :
|
||||
{
|
||||
PROVIDE (pios_isr_vector_table_base = .);
|
||||
KEEP(*(.isr_vector .isr_vector.*))
|
||||
*(.text .text.* .gnu.linkonce.t.*)
|
||||
*(.glue_7t) *(.glue_7)
|
||||
*(.rodata .rodata* .gnu.linkonce.r.*)
|
||||
} > BL_FLASH
|
||||
|
||||
.ARM.extab :
|
||||
{
|
||||
*(.ARM.extab* .gnu.linkonce.armextab.*)
|
||||
} > BL_FLASH
|
||||
|
||||
.ARM.exidx :
|
||||
{
|
||||
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
|
||||
} > BL_FLASH
|
||||
|
||||
. = ALIGN(4);
|
||||
_etext = .;
|
||||
_sidata = .;
|
||||
|
||||
.data : AT (_etext)
|
||||
{
|
||||
_sdata = .;
|
||||
*(.data .data.*)
|
||||
. = ALIGN(4);
|
||||
_edata = . ;
|
||||
} > SRAM
|
||||
|
||||
/* .bss section which is used for uninitialized data */
|
||||
.bss (NOLOAD) :
|
||||
{
|
||||
_sbss = . ;
|
||||
*(.bss .bss.*)
|
||||
*(COMMON)
|
||||
. = ALIGN(4);
|
||||
_ebss = . ;
|
||||
} > SRAM
|
||||
|
||||
. = ALIGN(4);
|
||||
_end = . ;
|
||||
|
||||
.boardinfo :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
KEEP(*(.boardinfo))
|
||||
. = ALIGN(4);
|
||||
} > BD_INFO
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
MEMORY
|
||||
{
|
||||
BL_FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 0x02000 - 0x00080
|
||||
BD_INFO (r) : ORIGIN = 0x08002000 - 0x80, LENGTH = 0x00080
|
||||
FLASH (rx) : ORIGIN = 0x08002000, LENGTH = 0x20000 - 0x02000
|
||||
SRAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x05000
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
PROVIDE(pios_board_info_blob = ORIGIN(BD_INFO));
|
||||
|
||||
_estack = 0x20004FF0;
|
||||
|
||||
/* Section Definitions */
|
||||
SECTIONS
|
||||
{
|
||||
.text :
|
||||
{
|
||||
PROVIDE (pios_isr_vector_table_base = .);
|
||||
KEEP(*(.isr_vector .isr_vector.*))
|
||||
*(.text .text.* .gnu.linkonce.t.*)
|
||||
*(.glue_7t) *(.glue_7)
|
||||
*(.rodata .rodata* .gnu.linkonce.r.*)
|
||||
} > FLASH
|
||||
|
||||
.ARM.extab :
|
||||
{
|
||||
*(.ARM.extab* .gnu.linkonce.armextab.*)
|
||||
} > FLASH
|
||||
|
||||
.ARM.exidx :
|
||||
{
|
||||
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
|
||||
} > FLASH
|
||||
|
||||
. = ALIGN(4);
|
||||
_etext = .;
|
||||
_sidata = .;
|
||||
|
||||
.data : AT (_etext)
|
||||
{
|
||||
_sdata = .;
|
||||
*(.data .data.*)
|
||||
. = ALIGN(4);
|
||||
_edata = . ;
|
||||
} > SRAM
|
||||
|
||||
/* .bss section which is used for uninitialized data */
|
||||
.bss (NOLOAD) :
|
||||
{
|
||||
_sbss = . ;
|
||||
*(.bss .bss.*)
|
||||
*(COMMON)
|
||||
. = ALIGN(4);
|
||||
_ebss = . ;
|
||||
} > SRAM
|
||||
|
||||
. = ALIGN(4);
|
||||
_end = . ;
|
||||
}
|
@ -1,77 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @addtogroup PIOS PIOS Core hardware abstraction layer
|
||||
* @{
|
||||
* @addtogroup PIOS_OPAHRS OPAHRS Functions
|
||||
* @{
|
||||
*
|
||||
* @file pios_opahrs.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief OpenPilot AHRS functions header.
|
||||
* @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 PIOS_OPAHRS_H
|
||||
#define PIOS_OPAHRS_H
|
||||
|
||||
#include "pios_opahrs_proto.h" /* opahrs message structs */
|
||||
|
||||
enum opahrs_result {
|
||||
OPAHRS_RESULT_OK = 0,
|
||||
OPAHRS_RESULT_TIMEOUT,
|
||||
OPAHRS_RESULT_FAILED,
|
||||
};
|
||||
|
||||
extern void PIOS_OPAHRS_Attach(uint32_t spi_id);
|
||||
extern void PIOS_OPAHRS_ForceSlaveSelected(bool selected);
|
||||
|
||||
/*
|
||||
* Protocol V0 messages used to talk to bootloaders
|
||||
*/
|
||||
|
||||
extern enum opahrs_result PIOS_OPAHRS_bl_GetVersions(struct opahrs_msg_v0 *rsp);
|
||||
extern enum opahrs_result PIOS_OPAHRS_bl_GetSerial(struct opahrs_msg_v0 *rsp);
|
||||
extern enum opahrs_result PIOS_OPAHRS_bl_FwupStart(struct opahrs_msg_v0 *rsp);
|
||||
extern enum opahrs_result PIOS_OPAHRS_bl_FwupStatus(struct opahrs_msg_v0 *rsp);
|
||||
extern enum opahrs_result PIOS_OPAHRS_bl_FwupData(struct opahrs_msg_v0 *req, struct opahrs_msg_v0 *rsp);
|
||||
extern enum opahrs_result PIOS_OPAHRS_bl_FwupVerify(struct opahrs_msg_v0 *rsp);
|
||||
extern enum opahrs_result PIOS_OPAHRS_bl_resync(void);
|
||||
extern enum opahrs_result PIOS_OPAHRS_bl_GetMemMap(struct opahrs_msg_v0 *rsp);
|
||||
extern enum opahrs_result PIOS_OPAHRS_bl_reset(uint32_t delay);
|
||||
extern enum opahrs_result PIOS_OPAHRS_bl_boot(uint32_t delay);
|
||||
extern enum opahrs_result PIOS_OPAHRS_bl_FwDlData(struct opahrs_msg_v0 *req, struct opahrs_msg_v0 *rsp);
|
||||
/*
|
||||
* Protocol V1 messages used by application
|
||||
*/
|
||||
extern enum opahrs_result PIOS_OPAHRS_Sync(struct opahrs_msg_v1 *rsp);
|
||||
extern enum opahrs_result PIOS_OPAHRS_GetSerial(struct opahrs_msg_v1 *rsp);
|
||||
extern enum opahrs_result PIOS_OPAHRS_SetGetUpdate(struct opahrs_msg_v1 *rsp, struct opahrs_msg_v1 *req);
|
||||
extern enum opahrs_result PIOS_OPAHRS_GetAttitudeRaw(struct opahrs_msg_v1 *rsp);
|
||||
extern enum opahrs_result PIOS_OPAHRS_SetAlgorithm(struct opahrs_msg_v1 *req);
|
||||
extern enum opahrs_result PIOS_OPAHRS_SetMagNorth(struct opahrs_msg_v1 *req);
|
||||
extern enum opahrs_result PIOS_OPAHRS_SetGetCalibration(struct opahrs_msg_v1 *req, struct opahrs_msg_v1 *rsp);
|
||||
extern enum opahrs_result PIOS_OPAHRS_SetGetInitialized(struct opahrs_msg_v1 *req, struct opahrs_msg_v1 *rsp);
|
||||
extern enum opahrs_result PIOS_OPAHRS_resync(void);
|
||||
|
||||
#endif /* PIOS_OPAHRS_H */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
@ -1,406 +0,0 @@
|
||||
/**
|
||||
* @addtogroup PIOS PIOS Core hardware abstraction layer
|
||||
* @{
|
||||
* @addtogroup PIOS_OPAHRS OPAHRS Functions
|
||||
* @{
|
||||
*
|
||||
* @file pios_opahrs_proto.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief PPM Input functions
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef PIOS_OPAHRS_PROTO_H
|
||||
#define PIOS_OPAHRS_PROTO_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
enum opahrs_msg_type {
|
||||
OPAHRS_MSG_TYPE_LINK = 0x00,
|
||||
|
||||
OPAHRS_MSG_TYPE_USER_V0,
|
||||
OPAHRS_MSG_TYPE_USER_V1,
|
||||
};
|
||||
|
||||
enum opahrs_msg_link_state {
|
||||
OPAHRS_MSG_LINK_STATE_INACTIVE,
|
||||
OPAHRS_MSG_LINK_STATE_BUSY,
|
||||
OPAHRS_MSG_LINK_STATE_READY,
|
||||
};
|
||||
|
||||
#define OPAHRS_MSG_MAGIC_HEAD 0x53524841 /* ASCII "AHRS" */
|
||||
struct opahrs_msg_link_head {
|
||||
uint32_t magic; /* Set to OPAHRS_MSG_MAGIC_HEAD */
|
||||
enum opahrs_msg_type type;
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
#define OPAHRS_MSG_MAGIC_TAIL 0xFEFE
|
||||
struct opahrs_msg_link_tail {
|
||||
uint16_t magic;
|
||||
uint8_t crc8;
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
enum opahrs_msg_link_tag {
|
||||
OPAHRS_MSG_LINK_TAG_NOP,
|
||||
};
|
||||
|
||||
#define SPI_MSG_LINK_ERROR_BADCRC 0x00000001
|
||||
struct opahrs_msg_link {
|
||||
enum opahrs_msg_link_state state;
|
||||
uint16_t errors;
|
||||
|
||||
enum opahrs_msg_link_tag t;
|
||||
union {
|
||||
} v;
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
/********
|
||||
* SPI protocol v0 definitions
|
||||
*
|
||||
* This protocol version is NOT to be changed after release since it is the
|
||||
* protocol used for upgrading the firmware of AHRS boards that are already
|
||||
* in end user hands.
|
||||
*
|
||||
********/
|
||||
|
||||
struct opahrs_msg_v0_req_nop {
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
struct opahrs_msg_v0_req_versions {
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
struct opahrs_msg_v0_req_reset {
|
||||
uint32_t reset_delay_in_ms;
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
struct opahrs_msg_v0_req_boot {
|
||||
uint32_t boot_delay_in_ms;
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
struct opahrs_msg_v0_req_serial {
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
struct opahrs_msg_v0_req_fwup_start {
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
struct opahrs_msg_v0_req_fwup_status {
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
struct opahrs_msg_v0_req_fwup_data {
|
||||
uint32_t adress;
|
||||
uint32_t data[14];
|
||||
uint8_t size;
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
struct opahrs_msg_v0_req_fwdn_data {
|
||||
uint32_t adress;
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
struct opahrs_msg_v0_req_mem_map {
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
struct opahrs_msg_v0_req_fwup_verify {
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
union opahrs_msg_v0_req {
|
||||
struct opahrs_msg_v0_req_nop nop;
|
||||
struct opahrs_msg_v0_req_versions versions;
|
||||
struct opahrs_msg_v0_req_reset reset;
|
||||
struct opahrs_msg_v0_req_boot boot;
|
||||
struct opahrs_msg_v0_req_serial serial;
|
||||
struct opahrs_msg_v0_req_fwup_status status_req;
|
||||
struct opahrs_msg_v0_req_fwdn_data fwdn_data;
|
||||
struct opahrs_msg_v0_req_mem_map mem_map;
|
||||
struct opahrs_msg_v0_req_fwup_start fwup_start;
|
||||
struct opahrs_msg_v0_req_fwup_data fwup_data;
|
||||
struct opahrs_msg_v0_req_fwup_verify fwup_verify;
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
struct opahrs_msg_v0_rsp_fwdn_data {
|
||||
uint8_t data[4];
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
struct opahrs_msg_v0_rsp_versions {
|
||||
uint16_t hw_version;
|
||||
uint16_t bl_version;
|
||||
uint32_t fw_crc;
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
struct opahrs_msg_v0_rsp_serial {
|
||||
uint8_t serial_bcd[24];
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
enum bootloader_status { idle, started, start_failed, write_error, outside_dev_capabilities, jump_failed };
|
||||
struct opahrs_msg_v0_rsp_fwup_status {
|
||||
enum bootloader_status status;
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
enum hw_density { high_density, medium_density };
|
||||
struct opahrs_msg_v0_rsp_mem_map {
|
||||
uint32_t start_of_user_code;
|
||||
uint32_t size_of_code_memory;
|
||||
uint8_t size_of_description;
|
||||
uint8_t rw_flags;
|
||||
enum hw_density density;
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
union opahrs_msg_v0_rsp {
|
||||
struct opahrs_msg_v0_rsp_versions versions;
|
||||
struct opahrs_msg_v0_rsp_serial serial;
|
||||
struct opahrs_msg_v0_rsp_fwup_status fwup_status;
|
||||
struct opahrs_msg_v0_rsp_mem_map mem_map;
|
||||
struct opahrs_msg_v0_rsp_fwdn_data fw_dn;
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
enum opahrs_msg_v0_tag {
|
||||
OPAHRS_MSG_V0_REQ_NOP = 0x00,
|
||||
OPAHRS_MSG_V0_REQ_VERSIONS,
|
||||
OPAHRS_MSG_V0_REQ_RESET,
|
||||
OPAHRS_MSG_V0_REQ_BOOT,
|
||||
OPAHRS_MSG_V0_REQ_SERIAL,
|
||||
OPAHRS_MSG_V0_REQ_FWDN_DATA,
|
||||
OPAHRS_MSG_V0_REQ_MEM_MAP,
|
||||
|
||||
OPAHRS_MSG_V0_REQ_FWUP_START,
|
||||
OPAHRS_MSG_V0_REQ_FWUP_DATA,
|
||||
OPAHRS_MSG_V0_REQ_FWUP_VERIFY,
|
||||
OPAHRS_MSG_V0_REQ_FWUP_STATUS,
|
||||
|
||||
OPAHRS_MSG_V0_RSP_VERSIONS,
|
||||
OPAHRS_MSG_V0_RSP_SERIAL,
|
||||
OPAHRS_MSG_V0_RSP_FWUP_STATUS,
|
||||
OPAHRS_MSG_V0_RSP_FWDN_DATA,
|
||||
OPAHRS_MSG_V0_RSP_MEM_MAP,
|
||||
};
|
||||
|
||||
struct opahrs_msg_v0_payload {
|
||||
enum opahrs_msg_v0_tag t;
|
||||
union {
|
||||
union opahrs_msg_v0_req req;
|
||||
union opahrs_msg_v0_rsp rsp;
|
||||
} v;
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
struct opahrs_msg_v0 {
|
||||
struct opahrs_msg_link_head head;
|
||||
union {
|
||||
struct opahrs_msg_link link;
|
||||
struct opahrs_msg_v0_payload user;
|
||||
} payload;
|
||||
struct opahrs_msg_link_tail tail;
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
/********
|
||||
* SPI protocol v1 definitions
|
||||
********/
|
||||
|
||||
struct opahrs_msg_v1_req_nop {
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
struct opahrs_msg_v1_req_versions {
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
struct opahrs_msg_v1_req_reset {
|
||||
uint32_t reset_delay_in_ms;
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
struct opahrs_msg_v1_req_serial {
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
enum initialized_mode { AHRS_UNINITIALIZED, AHRS_INITIALIZED, AHRS_INIT_QUERY };
|
||||
|
||||
struct opahrs_msg_v1_req_initialized {
|
||||
enum initialized_mode initialized;
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
struct opahrs_msg_v1_req_north {
|
||||
float Be[3];
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
enum algorithms { SIMPLE_Algo, INSGPS_Algo };
|
||||
|
||||
struct opahrs_msg_v1_req_algorithm {
|
||||
enum algorithms algorithm;
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
struct opahrs_msg_v1_req_update {
|
||||
struct {
|
||||
uint8_t updated;
|
||||
float NED[3];
|
||||
float groundspeed;
|
||||
float heading;
|
||||
float quality;
|
||||
} gps;
|
||||
struct {
|
||||
uint8_t updated;
|
||||
float altitude;
|
||||
} barometer;
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
struct opahrs_msg_v1_req_attituderaw {
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
enum measure_mode { AHRS_SET, AHRS_MEASURE, AHRS_ECHO };
|
||||
|
||||
struct opahrs_msg_v1_req_calibration {
|
||||
enum measure_mode measure_var;
|
||||
float accel_bias[3];
|
||||
float accel_scale[3];
|
||||
float accel_var[3];
|
||||
float gyro_bias[3];
|
||||
float gyro_scale[3];
|
||||
float gyro_var[3];
|
||||
float mag_bias[3];
|
||||
float mag_scale[3];
|
||||
float mag_var[3];
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
union opahrs_msg_v1_req {
|
||||
struct opahrs_msg_v1_req_nop nop;
|
||||
struct opahrs_msg_v1_req_versions versions;
|
||||
struct opahrs_msg_v1_req_reset reset;
|
||||
struct opahrs_msg_v1_req_initialized initialized;
|
||||
struct opahrs_msg_v1_req_serial serial;
|
||||
struct opahrs_msg_v1_req_update update;
|
||||
struct opahrs_msg_v1_req_algorithm algorithm;
|
||||
struct opahrs_msg_v1_req_north north;
|
||||
struct opahrs_msg_v1_req_attituderaw attituderaw;
|
||||
struct opahrs_msg_v1_req_calibration calibration;
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
struct opahrs_msg_v1_rsp_versions {
|
||||
uint8_t hw_version;
|
||||
uint16_t bl_version;
|
||||
uint32_t fw_crc;
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
struct opahrs_msg_v1_rsp_serial {
|
||||
uint8_t serial_bcd[25];
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
struct opahrs_msg_v1_rsp_initialized {
|
||||
enum initialized_mode initialized;
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
struct opahrs_msg_v1_rsp_north {
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
struct opahrs_msg_v1_rsp_algorithm {
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
struct opahrs_msg_v1_rsp_attituderaw {
|
||||
struct {
|
||||
int16_t x;
|
||||
int16_t y;
|
||||
int16_t z;
|
||||
} mags;
|
||||
struct {
|
||||
uint16_t x;
|
||||
uint16_t y;
|
||||
uint16_t z;
|
||||
uint16_t xy_temp;
|
||||
uint16_t z_temp;
|
||||
} gyros;
|
||||
struct {
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
} gyros_filtered;
|
||||
struct {
|
||||
uint16_t x;
|
||||
uint16_t y;
|
||||
uint16_t z;
|
||||
} accels;
|
||||
struct {
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
} accels_filtered;
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
struct opahrs_msg_v1_rsp_update {
|
||||
struct {
|
||||
float q1;
|
||||
float q2;
|
||||
float q3;
|
||||
float q4;
|
||||
} quaternion;
|
||||
int32_t NED[3];
|
||||
int32_t Vel[3];
|
||||
uint8_t load;
|
||||
uint8_t idle_time;
|
||||
uint8_t run_time;
|
||||
uint8_t dropped_updates;
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
struct opahrs_msg_v1_rsp_calibration {
|
||||
float accel_var[3];
|
||||
float gyro_var[3];
|
||||
float mag_var[3];
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
union opahrs_msg_v1_rsp {
|
||||
struct opahrs_msg_v1_rsp_versions versions;
|
||||
struct opahrs_msg_v1_rsp_serial serial;
|
||||
struct opahrs_msg_v1_rsp_initialized initialized;
|
||||
struct opahrs_msg_v1_rsp_north north;
|
||||
struct opahrs_msg_v1_rsp_algorithm algorithm;
|
||||
struct opahrs_msg_v1_rsp_attituderaw attituderaw;
|
||||
struct opahrs_msg_v1_rsp_update update;
|
||||
struct opahrs_msg_v1_rsp_calibration calibration;
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
enum opahrs_msg_v1_tag {
|
||||
OPAHRS_MSG_V1_REQ_NOP = 0x02000000,
|
||||
OPAHRS_MSG_V1_REQ_VERSIONS,
|
||||
OPAHRS_MSG_V1_REQ_RESET,
|
||||
OPAHRS_MSG_V1_REQ_SERIAL,
|
||||
OPAHRS_MSG_V1_REQ_INITIALIZED,
|
||||
OPAHRS_MSG_V1_REQ_NORTH,
|
||||
OPAHRS_MSG_V1_REQ_ALGORITHM,
|
||||
OPAHRS_MSG_V1_REQ_UPDATE,
|
||||
OPAHRS_MSG_V1_REQ_ATTITUDERAW,
|
||||
OPAHRS_MSG_V1_REQ_CALIBRATION,
|
||||
|
||||
OPAHRS_MSG_V1_RSP_VERSIONS,
|
||||
OPAHRS_MSG_V1_RSP_SERIAL,
|
||||
OPAHRS_MSG_V1_RSP_INITIALIZED,
|
||||
OPAHRS_MSG_V1_RSP_NORTH,
|
||||
OPAHRS_MSG_V1_RSP_ALGORITHM,
|
||||
OPAHRS_MSG_V1_RSP_UPDATE,
|
||||
OPAHRS_MSG_V1_RSP_ATTITUDERAW,
|
||||
OPAHRS_MSG_V1_RSP_CALIBRATION,
|
||||
};
|
||||
|
||||
struct opahrs_msg_v1_payload {
|
||||
enum opahrs_msg_v1_tag t;
|
||||
union {
|
||||
union opahrs_msg_v1_req req;
|
||||
union opahrs_msg_v1_rsp rsp;
|
||||
} v;
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
struct opahrs_msg_v1 {
|
||||
struct opahrs_msg_link_head head;
|
||||
union {
|
||||
struct opahrs_msg_link link;
|
||||
struct opahrs_msg_v1_payload user;
|
||||
} payload;
|
||||
struct opahrs_msg_link_tail tail;
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
/* Helper functions for setting up messages */
|
||||
extern void opahrs_msg_v0_init_rx(struct opahrs_msg_v0 *msg);
|
||||
extern void opahrs_msg_v0_init_user_tx(struct opahrs_msg_v0 *msg, enum opahrs_msg_v0_tag tag);
|
||||
extern void opahrs_msg_v0_init_link_tx(struct opahrs_msg_v0 *msg, enum opahrs_msg_link_tag tag);
|
||||
extern void opahrs_msg_v1_init_rx(struct opahrs_msg_v1 *msg);
|
||||
extern void opahrs_msg_v1_init_user_tx(struct opahrs_msg_v1 *msg, enum opahrs_msg_v1_tag tag);
|
||||
extern void opahrs_msg_v1_init_link_tx(struct opahrs_msg_v1 *msg, enum opahrs_msg_link_tag tag);
|
||||
|
||||
#endif /* PIOS_OPAHRS_PROTO_H */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
@ -1,15 +0,0 @@
|
||||
#
|
||||
# Floss JTAG OpenPilot
|
||||
#
|
||||
|
||||
interface ft2232
|
||||
ft2232_vid_pid 0x0403 0x6010
|
||||
#ft2232_device_desc "Dual RS232-HS"
|
||||
#ft2232_bus_addr "002:088"
|
||||
#ft2232_serial "1234567890"
|
||||
ft2232_layout "usbjtag"
|
||||
ft2232_latency 2
|
||||
|
||||
gdb_port 3334
|
||||
tcl_port 6666
|
||||
telnet_port 4444
|
@ -1,20 +0,0 @@
|
||||
BOARD_TYPE := 0x02
|
||||
BOARD_REVISION := 0x01
|
||||
BOOTLOADER_VERSION := 0x00
|
||||
HW_TYPE := 0x00
|
||||
|
||||
MCU := cortex-m3
|
||||
CHIP := STM32F103CBT
|
||||
BOARD := STM32103CB_AHRS
|
||||
MODEL := MD
|
||||
MODEL_SUFFIX :=
|
||||
|
||||
OPENOCD_CONFIG := stm32f1x.cfg
|
||||
|
||||
# Note: These must match the values in link_$(BOARD)_memory.ld
|
||||
BL_BANK_BASE := 0x08000000 # Start of bootloader flash
|
||||
BL_BANK_SIZE := 0x00002000 # Should include BD_INFO region
|
||||
FW_BANK_BASE := 0x08002000 # Start of firmware flash
|
||||
FW_BANK_SIZE := 0x0001E000 # Should include FW_DESC_SIZE
|
||||
|
||||
FW_DESC_SIZE := 0x00000064
|
Loading…
Reference in New Issue
Block a user