mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-20 10:54:14 +01:00
Added a RTC supervisor timer to RFM22B driver.
This commit is contained in:
parent
5a2a3ad49b
commit
f726cc6a9d
@ -39,6 +39,8 @@
|
||||
*/
|
||||
|
||||
#include <openpilot.h>
|
||||
#include <pipxstatus.h>
|
||||
#include <pios_board_info.h>
|
||||
#include "systemmod.h"
|
||||
|
||||
// Private constants
|
||||
@ -97,6 +99,22 @@ int32_t PipXtremeModInitialize(void)
|
||||
|
||||
// Must registers objects here for system thread because ObjectManager started in OpenPilotInit
|
||||
|
||||
// Initialize out status object.
|
||||
PipXStatusInitialize();
|
||||
PipXStatusData pipxStatus;
|
||||
PipXStatusGet(&pipxStatus);
|
||||
|
||||
// Get our hardware information.
|
||||
const struct pios_board_info * bdinfo = &pios_board_info_blob;
|
||||
|
||||
pipxStatus.BoardType= bdinfo->board_type;
|
||||
PIOS_BL_HELPER_FLASH_Read_Description(pipxStatus.Description, PIPXSTATUS_DESCRIPTION_NUMELEM);
|
||||
PIOS_SYS_SerialNumberGetBinary(pipxStatus.CPUSerial);
|
||||
pipxStatus.BoardRevision= bdinfo->board_rev;
|
||||
|
||||
// Update the object
|
||||
PipXStatusSet(&pipxStatus);
|
||||
|
||||
// Call the module start function.
|
||||
PipXtremeModStart();
|
||||
|
||||
|
@ -42,7 +42,7 @@
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#undef PIOS_INCLUDE_USB
|
||||
//#undef PIOS_INCLUDE_USB
|
||||
|
||||
// ****************
|
||||
// Private functions
|
||||
@ -173,7 +173,6 @@ static int32_t RadioComBridgeInitialize(void)
|
||||
|
||||
// Initialize the UAVObjects that we use
|
||||
GCSReceiverInitialize();
|
||||
PipXStatusInitialize();
|
||||
PipXSettingsInitialize();
|
||||
data->send_gcsreceiver = false;
|
||||
data->send_pipxstatus = false;
|
||||
@ -355,6 +354,7 @@ static void radioStatusTask(void *parameters)
|
||||
// Update the status
|
||||
pipxStatus.DeviceID = PIOS_RFM22B_DeviceID(pios_rfm22b_id);
|
||||
pipxStatus.RSSI = PIOS_RFM22B_RSSI(pios_rfm22b_id);
|
||||
pipxStatus.Resets = PIOS_RFM22B_Resets(pios_rfm22b_id);
|
||||
|
||||
// Update the potential pairing contacts
|
||||
for (uint8_t i = 0; i < PIPXSTATUS_PAIRIDS_NUMELEM; ++i)
|
||||
|
@ -63,6 +63,11 @@
|
||||
/* Local Defines */
|
||||
#define STACK_SIZE_BYTES 200
|
||||
|
||||
// RTC timer is running at 625Hz (1.6ms or 5 ticks == 8ms).
|
||||
// A 256 byte message at 56kbps should take less than 40ms
|
||||
// Note: This timeout should be rate dependent.
|
||||
#define PIOS_RFM22B_SUPERVISOR_TIMEOUT 65 // ~100ms
|
||||
|
||||
// this is too adjust the RF module so that it is on frequency
|
||||
#define OSC_LOAD_CAP 0x7F // cap = 12.5pf .. default
|
||||
#define OSC_LOAD_CAP_1 0x7D // board 1
|
||||
@ -156,14 +161,19 @@ struct pios_rfm22b_dev {
|
||||
uint32_t rx_in_context;
|
||||
pios_com_callback tx_out_cb;
|
||||
uint32_t tx_out_context;
|
||||
|
||||
// The supervisor countdown timer.
|
||||
uint16_t supv_timer;
|
||||
uint16_t resets;
|
||||
};
|
||||
|
||||
uint32_t random32 = 0x459ab8d8;
|
||||
|
||||
/* Local function forwared declarations */
|
||||
void rfm22_processInt(void);
|
||||
void PIOS_RFM22_EXT_Int(void);
|
||||
void rfm22_setTxMode(uint8_t mode);
|
||||
static void PIOS_RFM22B_Supervisor(uint32_t ppm_id);
|
||||
static void rfm22_processInt(void);
|
||||
static void PIOS_RFM22_EXT_Int(void);
|
||||
static void rfm22_setTxMode(uint8_t mode);
|
||||
|
||||
// SPI read/write functions
|
||||
void rfm22_startBurstWrite(uint8_t addr);
|
||||
@ -290,6 +300,8 @@ const uint8_t ss_reg_71[] = { 0x2B, 0x23}; // rfm22_modulation_mode_control2
|
||||
|
||||
volatile bool initialized = false;
|
||||
|
||||
struct pios_rfm22b_dev * rfm22b_dev;
|
||||
|
||||
#if defined(RFM22_EXT_INT_USE)
|
||||
volatile bool exec_using_spi; // set this if you want to access the SPI bus outside of the interrupt
|
||||
#endif
|
||||
@ -430,8 +442,6 @@ int32_t PIOS_RFM22B_Init(uint32_t *rfm22b_id, const struct pios_rfm22b_cfg *cfg)
|
||||
PIOS_DEBUG_Assert(rfm22b_id);
|
||||
PIOS_DEBUG_Assert(cfg);
|
||||
|
||||
struct pios_rfm22b_dev * rfm22b_dev;
|
||||
|
||||
// Allocate the device structure.
|
||||
rfm22b_dev = (struct pios_rfm22b_dev *) PIOS_RFM22B_alloc();
|
||||
if (!rfm22b_dev)
|
||||
@ -457,6 +467,10 @@ int32_t PIOS_RFM22B_Init(uint32_t *rfm22b_id, const struct pios_rfm22b_cfg *cfg)
|
||||
rfm22b_dev->deviceID = crcs[0] | crcs[1] << 8 | crcs[2] << 16 | crcs[3] << 24;
|
||||
DEBUG_PRINTF(2, "RF device ID: %x\n\r", rfm22b_dev->deviceID);
|
||||
|
||||
// Initialize the supervisor timer.
|
||||
rfm22b_dev->supv_timer = PIOS_RFM22B_SUPERVISOR_TIMEOUT;
|
||||
rfm22b_dev->resets = 0;
|
||||
|
||||
// Initialize the radio device.
|
||||
int initval = rfm22_init_normal(rfm22b_dev->deviceID, cfg->minFrequencyHz, cfg->maxFrequencyHz, 50000);
|
||||
|
||||
@ -501,6 +515,11 @@ int32_t PIOS_RFM22B_Init(uint32_t *rfm22b_id, const struct pios_rfm22b_cfg *cfg)
|
||||
DEBUG_PRINTF(2, "RF frequency: %dHz\n\r", rfm22_getNominalCarrierFrequency());
|
||||
DEBUG_PRINTF(2, "RF TX power: %d\n\r", rfm22_getTxPower());
|
||||
|
||||
// Setup a real-time clock callback to kickstart the radio if a transfer lock sup.
|
||||
if (!PIOS_RTC_RegisterTickCallback(PIOS_RFM22B_Supervisor, *rfm22b_id)) {
|
||||
PIOS_DEBUG_Assert(0);
|
||||
}
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
@ -511,11 +530,18 @@ uint32_t PIOS_RFM22B_DeviceID(uint32_t rfm22b_id)
|
||||
return rfm22b_dev->deviceID;
|
||||
}
|
||||
|
||||
int8_t PIOS_RFM22B_RSSI(uint32_t rfb22b_id)
|
||||
int8_t PIOS_RFM22B_RSSI(uint32_t rfm22b_id)
|
||||
{
|
||||
return rfm22_receivedRSSI();
|
||||
}
|
||||
|
||||
int16_t PIOS_RFM22B_Resets(uint32_t rfm22b_id)
|
||||
{
|
||||
struct pios_rfm22b_dev *rfm22b_dev = (struct pios_rfm22b_dev *)rfm22b_id;
|
||||
|
||||
return rfm22b_dev->resets;
|
||||
}
|
||||
|
||||
static void PIOS_RFM22B_RxStart(uint32_t rfm22b_id, uint16_t rx_bytes_avail)
|
||||
{
|
||||
struct pios_rfm22b_dev * rfm22b_dev = (struct pios_rfm22b_dev *)rfm22b_id;
|
||||
@ -602,12 +628,39 @@ static void PIOS_RFM22B_RegisterTxCallback(uint32_t rfm22b_id, pios_com_callback
|
||||
rfm22b_dev->tx_out_cb = tx_out_cb;
|
||||
}
|
||||
|
||||
void rfm22_setDebug(const char* msg)
|
||||
static void PIOS_RFM22B_Supervisor(uint32_t rfm22b_id)
|
||||
{
|
||||
/* Recover our device context */
|
||||
struct pios_rfm22b_dev * rfm22b_dev = (struct pios_rfm22b_dev *)rfm22b_id;
|
||||
|
||||
if (!PIOS_RFM22B_validate(rfm22b_dev)) {
|
||||
/* Invalid device specified */
|
||||
return;
|
||||
}
|
||||
|
||||
/* Not a problem if we're waiting for a packet. */
|
||||
if(rf_mode == RX_WAIT_SYNC_MODE)
|
||||
return;
|
||||
|
||||
/* The radio must be locked up if the timer reaches 0 */
|
||||
if(--(rfm22b_dev->supv_timer) != 0)
|
||||
return;
|
||||
++(rfm22b_dev->resets);
|
||||
|
||||
/* Start a packet transfer if one is available. */
|
||||
if(!rfm22_txStart())
|
||||
{
|
||||
/* Otherwise, switch to RX mode */
|
||||
rfm22_setRxMode(RX_WAIT_PREAMBLE_MODE, false);
|
||||
}
|
||||
}
|
||||
|
||||
static void rfm22_setDebug(const char* msg)
|
||||
{
|
||||
debug_msg = msg;
|
||||
}
|
||||
|
||||
void rfm22_setError(const char* msg)
|
||||
static void rfm22_setError(const char* msg)
|
||||
{
|
||||
error_msg = msg;
|
||||
}
|
||||
@ -687,7 +740,7 @@ uint8_t rfm22_read(uint8_t addr)
|
||||
// external interrupt
|
||||
|
||||
|
||||
void PIOS_RFM22_EXT_Int(void)
|
||||
static void PIOS_RFM22_EXT_Int(void)
|
||||
{
|
||||
rfm22_setDebug("Ext Int");
|
||||
if (!exec_using_spi)
|
||||
@ -1126,6 +1179,9 @@ uint8_t rfm22_txStart()
|
||||
// Disable interrrupts.
|
||||
PIOS_IRQ_Disable();
|
||||
|
||||
// Initialize the supervisor timer.
|
||||
rfm22b_dev->supv_timer = PIOS_RFM22B_SUPERVISOR_TIMEOUT;
|
||||
|
||||
// disable interrupts
|
||||
rfm22_write(RFM22_interrupt_enable1, 0x00);
|
||||
rfm22_write(RFM22_interrupt_enable2, 0x00);
|
||||
@ -1202,7 +1258,7 @@ uint8_t rfm22_txStart()
|
||||
}
|
||||
|
||||
|
||||
void rfm22_setTxMode(uint8_t mode)
|
||||
static void rfm22_setTxMode(uint8_t mode)
|
||||
{
|
||||
rfm22_setDebug("setTxMode");
|
||||
if (mode != TX_DATA_MODE && mode != TX_STREAM_MODE && mode != TX_CARRIER_MODE && mode != TX_PN_MODE)
|
||||
@ -1582,7 +1638,7 @@ void rfm22_processTxInt(void)
|
||||
rfm22_setDebug("ProcessTxInt done");
|
||||
}
|
||||
|
||||
void rfm22_processInt(void)
|
||||
static void rfm22_processInt(void)
|
||||
{
|
||||
rfm22_setDebug("ProcessInt");
|
||||
// this is called from the external interrupt handler
|
||||
@ -1593,6 +1649,9 @@ void rfm22_processInt(void)
|
||||
|
||||
exec_using_spi = TRUE;
|
||||
|
||||
// Reset the supervisor timer.
|
||||
rfm22b_dev->supv_timer = PIOS_RFM22B_SUPERVISOR_TIMEOUT;
|
||||
|
||||
// ********************************
|
||||
// read the RF modules current status registers
|
||||
|
||||
|
@ -48,7 +48,8 @@ struct pios_rfm22b_cfg {
|
||||
/* Public Functions */
|
||||
extern int32_t PIOS_RFM22B_Init(uint32_t *rfb22b_id, const struct pios_rfm22b_cfg *cfg);
|
||||
extern uint32_t PIOS_RFM22B_DeviceID(uint32_t rfb22b_id);
|
||||
extern int8_t PIOS_RFM22B_RSSI(uint32_t rfb22b_id);
|
||||
extern int8_t PIOS_RFM22B_RSSI(uint32_t rfm22b_id);
|
||||
extern int16_t PIOS_RFM22B_Resets(uint32_t rfm22b_id);
|
||||
|
||||
#endif /* PIOS_RFM22B_H */
|
||||
|
||||
|
@ -483,8 +483,8 @@ const struct pios_rfm22b_cfg pios_rfm22b_cfg = {
|
||||
.maxFrequencyHz = 434000000 + 2000000,
|
||||
.RFXtalCap = 0x7f,
|
||||
.maxRFBandwidth = 128000,
|
||||
.maxTxPower = RFM22_tx_pwr_txpow_0, // +1dBm ... 1.25mW
|
||||
//.maxTxPower = RFM22_tx_pwr_txpow_7, // +20dBm .. 100mW
|
||||
//.maxTxPower = RFM22_tx_pwr_txpow_0, // +1dBm ... 1.25mW
|
||||
.maxTxPower = RFM22_tx_pwr_txpow_7, // +20dBm .. 100mW
|
||||
.sendTimeout = 25, /* ms */
|
||||
.minPacketSize = 100,
|
||||
.txWinSize = 4,
|
||||
|
@ -13,6 +13,7 @@
|
||||
<field name="AFC" units="" type="int32" elements="1" defaultvalue="0"/>
|
||||
<field name="Retries" units="" type="uint16" elements="1" defaultvalue="0"/>
|
||||
<field name="Errors" units="" type="uint16" elements="1" defaultvalue="0"/>
|
||||
<field name="Resets" units="" type="uint16" elements="1" defaultvalue="0"/>
|
||||
<field name="RSSI" units="dBm" type="int8" elements="1" defaultvalue="0"/>
|
||||
<field name="LinkState" units="function" type="enum" elements="1" options="Disconnected,Connecting,Connected" defaultvalue="Disconnected"/>
|
||||
<field name="PairIDs" units="" type="uint32" elements="4" defaultvalue="0"/>
|
||||
|
Loading…
x
Reference in New Issue
Block a user