mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-26 15:54:15 +01:00
LP-345 RFM22: Add frequency band selection. 433, 868 and 915Mhz band
This commit is contained in:
parent
33188bd78e
commit
f332d48e9b
@ -66,54 +66,56 @@
|
||||
#include <sha1.h>
|
||||
|
||||
/* Local Defines */
|
||||
#define STACK_SIZE_BYTES 200
|
||||
#define TASK_PRIORITY (tskIDLE_PRIORITY + 4) // flight control relevant device driver (ppm link)
|
||||
#define ISR_TIMEOUT 1 // ms
|
||||
#define EVENT_QUEUE_SIZE 5
|
||||
#define RFM22B_DEFAULT_RX_DATARATE RFM22_datarate_9600
|
||||
#define RFM22B_DEFAULT_TX_POWER RFM22_tx_pwr_txpow_0
|
||||
#define RFM22B_NOMINAL_CARRIER_FREQUENCY 430000000
|
||||
#define RFM22B_LINK_QUALITY_THRESHOLD 20
|
||||
#define RFM22B_DEFAULT_MIN_CHANNEL 0
|
||||
#define RFM22B_DEFAULT_MAX_CHANNEL 250
|
||||
#define RFM22B_PPM_ONLY_DATARATE RFM22_datarate_9600
|
||||
#define STACK_SIZE_BYTES 200
|
||||
#define TASK_PRIORITY (tskIDLE_PRIORITY + 4) // flight control relevant device driver (ppm link)
|
||||
#define ISR_TIMEOUT 1 // ms
|
||||
#define EVENT_QUEUE_SIZE 5
|
||||
#define RFM22B_DEFAULT_RX_DATARATE RFM22_datarate_9600
|
||||
#define RFM22B_DEFAULT_TX_POWER RFM22_tx_pwr_txpow_0
|
||||
#define RFM22B_NOMINAL_CARRIER_FREQUENCY_433 430000000
|
||||
#define RFM22B_NOMINAL_CARRIER_FREQUENCY_868 860000000
|
||||
#define RFM22B_NOMINAL_CARRIER_FREQUENCY_915 900000000
|
||||
#define RFM22B_LINK_QUALITY_THRESHOLD 20
|
||||
#define RFM22B_DEFAULT_MIN_CHANNEL 0
|
||||
#define RFM22B_DEFAULT_MAX_CHANNEL 250
|
||||
#define RFM22B_PPM_ONLY_DATARATE RFM22_datarate_9600
|
||||
|
||||
// PPM encoding limits
|
||||
#define RFM22B_PPM_MIN 1
|
||||
#define RFM22B_PPM_MAX 511
|
||||
#define RFM22B_PPM_INVALID 0
|
||||
#define RFM22B_PPM_SCALE 2
|
||||
#define RFM22B_PPM_MIN_US 990
|
||||
#define RFM22B_PPM_MAX_US (RFM22B_PPM_MIN_US + (RFM22B_PPM_MAX - RFM22B_PPM_MIN) * RFM22B_PPM_SCALE)
|
||||
#define RFM22B_PPM_MIN 1
|
||||
#define RFM22B_PPM_MAX 511
|
||||
#define RFM22B_PPM_INVALID 0
|
||||
#define RFM22B_PPM_SCALE 2
|
||||
#define RFM22B_PPM_MIN_US 990
|
||||
#define RFM22B_PPM_MAX_US (RFM22B_PPM_MIN_US + (RFM22B_PPM_MAX - RFM22B_PPM_MIN) * RFM22B_PPM_SCALE)
|
||||
|
||||
// The maximum amount of time without activity before initiating a reset.
|
||||
#define PIOS_RFM22B_SUPERVISOR_TIMEOUT 150 // ms
|
||||
#define PIOS_RFM22B_SUPERVISOR_TIMEOUT 150 // ms
|
||||
|
||||
// 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 0x7F // cap = 12.5pf .. default
|
||||
|
||||
#define TX_PREAMBLE_NIBBLES 12 // 7 to 511 (number of nibbles)
|
||||
#define RX_PREAMBLE_NIBBLES 6 // 5 to 31 (number of nibbles)
|
||||
#define SYNC_BYTES 4
|
||||
#define HEADER_BYTES 4
|
||||
#define LENGTH_BYTES 1
|
||||
#define TX_PREAMBLE_NIBBLES 12 // 7 to 511 (number of nibbles)
|
||||
#define RX_PREAMBLE_NIBBLES 6 // 5 to 31 (number of nibbles)
|
||||
#define SYNC_BYTES 4
|
||||
#define HEADER_BYTES 4
|
||||
#define LENGTH_BYTES 1
|
||||
|
||||
// the size of the rf modules internal FIFO buffers
|
||||
#define FIFO_SIZE 64
|
||||
#define FIFO_SIZE 64
|
||||
|
||||
#define TX_FIFO_HI_WATERMARK 62 // 0-63
|
||||
#define TX_FIFO_LO_WATERMARK 32 // 0-63
|
||||
#define TX_FIFO_HI_WATERMARK 62 // 0-63
|
||||
#define TX_FIFO_LO_WATERMARK 32 // 0-63
|
||||
|
||||
#define RX_FIFO_HI_WATERMARK 32 // 0-63
|
||||
#define RX_FIFO_HI_WATERMARK 32 // 0-63
|
||||
|
||||
// preamble byte (preceeds SYNC_BYTE's)
|
||||
#define PREAMBLE_BYTE 0x55
|
||||
#define PREAMBLE_BYTE 0x55
|
||||
|
||||
// RF sync bytes (32-bit in all)
|
||||
#define SYNC_BYTE_1 0x2D
|
||||
#define SYNC_BYTE_2 0xD4
|
||||
#define SYNC_BYTE_3 0x4B
|
||||
#define SYNC_BYTE_4 0x59
|
||||
#define SYNC_BYTE_1 0x2D
|
||||
#define SYNC_BYTE_2 0xD4
|
||||
#define SYNC_BYTE_3 0x4B
|
||||
#define SYNC_BYTE_4 0x59
|
||||
|
||||
#ifndef RX_LED_ON
|
||||
#define RX_LED_ON
|
||||
@ -187,7 +189,7 @@ static enum pios_radio_event rfm22_timeout(struct pios_rfm22b_dev *rfm22b_dev);
|
||||
static enum pios_radio_event rfm22_error(struct pios_rfm22b_dev *rfm22b_dev);
|
||||
static enum pios_radio_event rfm22_fatal_error(struct pios_rfm22b_dev *rfm22b_dev);
|
||||
static void rfm22b_add_rx_status(struct pios_rfm22b_dev *rfm22b_dev, enum pios_rfm22b_rx_packet_status status);
|
||||
static void rfm22_setNominalCarrierFrequency(struct pios_rfm22b_dev *rfm22b_dev, uint8_t init_chan);
|
||||
static void rfm22_setNominalCarrierFrequency(struct pios_rfm22b_dev *rfm22b_dev, uint8_t init_chan, uint32_t frequency_hz);
|
||||
static bool rfm22_setFreqHopChannel(struct pios_rfm22b_dev *rfm22b_dev, uint8_t channel);
|
||||
static void rfm22_generateDeviceID(struct pios_rfm22b_dev *rfm22b_dev);
|
||||
static void rfm22_updatePairStatus(struct pios_rfm22b_dev *radio_dev);
|
||||
@ -391,7 +393,7 @@ static struct pios_rfm22b_dev *g_rfm22b_dev = NULL;
|
||||
* @param[in] slave_num The SPI bus slave number.
|
||||
* @param[in] cfg The device configuration.
|
||||
*/
|
||||
int32_t PIOS_RFM22B_Init(uint32_t *rfm22b_id, uint32_t spi_id, uint32_t slave_num, const struct pios_rfm22b_cfg *cfg)
|
||||
int32_t PIOS_RFM22B_Init(uint32_t *rfm22b_id, uint32_t spi_id, uint32_t slave_num, const struct pios_rfm22b_cfg *cfg, OPLinkSettingsRFBandOptions band)
|
||||
{
|
||||
PIOS_DEBUG_Assert(rfm22b_id);
|
||||
PIOS_DEBUG_Assert(cfg);
|
||||
@ -436,6 +438,20 @@ int32_t PIOS_RFM22B_Init(uint32_t *rfm22b_id, uint32_t spi_id, uint32_t slave_nu
|
||||
rfm22b_dev->stats.rx_seq = 0;
|
||||
rfm22b_dev->stats.tx_failure = 0;
|
||||
|
||||
// Set the frequency band
|
||||
switch (band) {
|
||||
case OPLINKSETTINGS_RFBAND_915MHZ:
|
||||
rfm22b_dev->base_freq = RFM22B_NOMINAL_CARRIER_FREQUENCY_915;
|
||||
break;
|
||||
case OPLINKSETTINGS_RFBAND_868MHZ:
|
||||
rfm22b_dev->base_freq = RFM22B_NOMINAL_CARRIER_FREQUENCY_868;
|
||||
break;
|
||||
case OPLINKSETTINGS_RFBAND_433MHZ:
|
||||
default:
|
||||
rfm22b_dev->base_freq = RFM22B_NOMINAL_CARRIER_FREQUENCY_433;
|
||||
break;
|
||||
}
|
||||
|
||||
// Initialize the channels.
|
||||
PIOS_RFM22B_SetChannelConfig(*rfm22b_id, RFM22B_DEFAULT_RX_DATARATE, RFM22B_DEFAULT_MIN_CHANNEL,
|
||||
RFM22B_DEFAULT_MAX_CHANNEL, false, true, false);
|
||||
@ -1566,7 +1582,7 @@ static enum pios_radio_event rfm22_init(struct pios_rfm22b_dev *rfm22b_dev)
|
||||
vTaskDelay(1 + (1 / (portTICK_RATE_MS + 1)));
|
||||
|
||||
// Initialize the frequency and datarate to te default.
|
||||
rfm22_setNominalCarrierFrequency(rfm22b_dev, 0);
|
||||
rfm22_setNominalCarrierFrequency(rfm22b_dev, 0, rfm22b_dev->base_freq);
|
||||
pios_rfm22_setDatarate(rfm22b_dev);
|
||||
|
||||
return RADIO_EVENT_INITIALIZED;
|
||||
@ -1656,10 +1672,8 @@ static void pios_rfm22_setDatarate(struct pios_rfm22b_dev *rfm22b_dev)
|
||||
* @param[in] rfm33b_dev The device structure pointer.
|
||||
* @param[in] init_chan The initial channel to tune to.
|
||||
*/
|
||||
static void rfm22_setNominalCarrierFrequency(struct pios_rfm22b_dev *rfm22b_dev, uint8_t init_chan)
|
||||
static void rfm22_setNominalCarrierFrequency(struct pios_rfm22b_dev *rfm22b_dev, uint8_t init_chan, uint32_t frequency_hz)
|
||||
{
|
||||
// Set the frequency channels to start at 430MHz
|
||||
uint32_t frequency_hz = RFM22B_NOMINAL_CARRIER_FREQUENCY;
|
||||
// The step size is 10MHz / 250 = 40khz, and the step size is specified in 10khz increments.
|
||||
uint8_t freq_hop_step_size = 4;
|
||||
|
||||
@ -1682,7 +1696,7 @@ static void rfm22_setNominalCarrierFrequency(struct pios_rfm22b_dev *rfm22b_dev,
|
||||
// Claim the SPI bus.
|
||||
rfm22_claimBus(rfm22b_dev);
|
||||
|
||||
// Setthe frequency hopping step size.
|
||||
// Set the frequency hopping step size.
|
||||
rfm22_write(rfm22b_dev, RFM22_frequency_hopping_step_size, freq_hop_step_size);
|
||||
|
||||
// frequency hopping channel (0-255)
|
||||
|
@ -101,7 +101,7 @@ struct rfm22b_stats {
|
||||
};
|
||||
|
||||
/* Public Functions */
|
||||
extern int32_t PIOS_RFM22B_Init(uint32_t *rfb22b_id, uint32_t spi_id, uint32_t slave_num, const struct pios_rfm22b_cfg *cfg);
|
||||
extern int32_t PIOS_RFM22B_Init(uint32_t *rfb22b_id, uint32_t spi_id, uint32_t slave_num, const struct pios_rfm22b_cfg *cfg, OPLinkSettingsRFBandOptions band);
|
||||
extern void PIOS_RFM22B_Reinit(uint32_t rfb22b_id);
|
||||
extern void PIOS_RFM22B_SetTxPower(uint32_t rfm22b_id, enum rfm22b_tx_power tx_pwr);
|
||||
extern void PIOS_RFM22B_SetChannelConfig(uint32_t rfm22b_id, enum rfm22b_datarate datarate, uint8_t min_chan, uint8_t max_chan, bool coordinator, bool ppm_mode, bool ppm_only);
|
||||
|
@ -283,6 +283,9 @@ struct pios_rfm22b_dev {
|
||||
// Are we sending / receiving only PPM data?
|
||||
bool ppm_only_mode;
|
||||
|
||||
// The base freq in Hertz
|
||||
uint32_t base_freq;
|
||||
|
||||
// The channel list
|
||||
uint8_t channels[RFM22B_NUM_CHANNELS];
|
||||
// The number of frequency hopping channels.
|
||||
|
@ -784,7 +784,7 @@ void PIOS_Board_Init(void)
|
||||
if (oplinkSettings.MaxRFPower != OPLINKSETTINGS_MAXRFPOWER_0) {
|
||||
/* Configure the RFM22B device. */
|
||||
const struct pios_rfm22b_cfg *rfm22b_cfg = PIOS_BOARD_HW_DEFS_GetRfm22Cfg(bdinfo->board_rev);
|
||||
if (PIOS_RFM22B_Init(&pios_rfm22b_id, PIOS_RFM22_SPI_PORT, rfm22b_cfg->slave_num, rfm22b_cfg)) {
|
||||
if (PIOS_RFM22B_Init(&pios_rfm22b_id, PIOS_RFM22_SPI_PORT, rfm22b_cfg->slave_num, rfm22b_cfg, oplinkSettings.RFBand)) {
|
||||
PIOS_Assert(0);
|
||||
}
|
||||
|
||||
|
@ -413,7 +413,7 @@ void PIOS_Board_Init(void)
|
||||
|
||||
// Configure the RFM22B device
|
||||
const struct pios_rfm22b_cfg *rfm22b_cfg = PIOS_BOARD_HW_DEFS_GetRfm22Cfg(bdinfo->board_rev);
|
||||
if (PIOS_RFM22B_Init(&pios_rfm22b_id, PIOS_RFM22_SPI_PORT, rfm22b_cfg->slave_num, rfm22b_cfg)) {
|
||||
if (PIOS_RFM22B_Init(&pios_rfm22b_id, PIOS_RFM22_SPI_PORT, rfm22b_cfg->slave_num, rfm22b_cfg, oplinkSettings.RFBand)) {
|
||||
PIOS_Assert(0);
|
||||
}
|
||||
|
||||
|
@ -912,7 +912,7 @@ void PIOS_Board_Init(void)
|
||||
} else {
|
||||
/* Configure the RFM22B device. */
|
||||
const struct pios_rfm22b_cfg *rfm22b_cfg = PIOS_BOARD_HW_DEFS_GetRfm22Cfg(bdinfo->board_rev);
|
||||
if (PIOS_RFM22B_Init(&pios_rfm22b_id, PIOS_RFM22_SPI_PORT, rfm22b_cfg->slave_num, rfm22b_cfg)) {
|
||||
if (PIOS_RFM22B_Init(&pios_rfm22b_id, PIOS_RFM22_SPI_PORT, rfm22b_cfg->slave_num, rfm22b_cfg, oplinkSettings.RFBand)) {
|
||||
PIOS_Assert(0);
|
||||
}
|
||||
|
||||
|
@ -852,7 +852,7 @@ void PIOS_Board_Init(void)
|
||||
} else {
|
||||
/* Configure the RFM22B device. */
|
||||
const struct pios_rfm22b_cfg *rfm22b_cfg = PIOS_BOARD_HW_DEFS_GetRfm22Cfg(bdinfo->board_rev);
|
||||
if (PIOS_RFM22B_Init(&pios_rfm22b_id, PIOS_RFM22_SPI_PORT, rfm22b_cfg->slave_num, rfm22b_cfg)) {
|
||||
if (PIOS_RFM22B_Init(&pios_rfm22b_id, PIOS_RFM22_SPI_PORT, rfm22b_cfg->slave_num, rfm22b_cfg, oplinkSettings.RFBand)) {
|
||||
PIOS_Assert(0);
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@
|
||||
<field name="VCPPort" units="" type="enum" elements="1" options="Disabled,Serial,ComBridge" defaultvalue="Disabled"/>
|
||||
<field name="ComSpeed" units="bps" type="enum" elements="1" options="4800,9600,19200,38400,57600,115200" defaultvalue="38400"/>
|
||||
<field name="MaxRFPower" units="mW" type="enum" elements="1" options="0,1.25,1.6,3.16,6.3,12.6,25,50,100" defaultvalue="0"/>
|
||||
<field name="RFBand" units="" type="enum" elements="1" options="433MHz,868MHz,915MHz" defaultvalue="433MHz"/>
|
||||
<field name="MinChannel" units="" type="uint8" elements="1" defaultvalue="0"/>
|
||||
<field name="MaxChannel" units="" type="uint8" elements="1" defaultvalue="250"/>
|
||||
<field name="CustomDeviceID" units="hex" type="uint32" elements="1" defaultvalue="0"/>
|
||||
@ -16,19 +17,19 @@
|
||||
<!-- OpenLRS options -->
|
||||
<field name="Version" units="" type="uint8" elements="1" defaultvalue="0"/>
|
||||
<field name="SerialBaudrate" units="bps" type="uint32" elements="1" defaultvalue="0"/>
|
||||
<field name="RFFrequency" units="hz" type="uint32" elements="1" defaultvalue="0"/>
|
||||
<field name="RFFrequency" units="Hz" type="uint32" elements="1" defaultvalue="0"/>
|
||||
<field name="FailsafeDelay" units="ms" type="uint32" elements="1" defaultvalue="1000"/>
|
||||
<field name="RSSIType" units="function" type="enum" elements="1" options="Combined,RSSI,LinkQuality" defaultvalue="Combined"/>
|
||||
|
||||
<!-- rf_magic === CoordID -->
|
||||
<field name="RFPower" units="" type="uint8" elements="1" defaultvalue="0"/>
|
||||
<field name="RFChannelSpacing" units="hz" type="uint8" elements="1" defaultvalue="0"/>
|
||||
<field name="RFChannelSpacing" units="Hz" type="uint8" elements="1" defaultvalue="0"/>
|
||||
<field name="HopChannel" units="" type="uint8" elements="24" defaultvalue="0"/>
|
||||
<field name="ModemParams" units="" type="uint8" elements="1" defaultvalue="0"/>
|
||||
<field name="Flags" units="" type="uint8" elements="1" defaultvalue="0"/>
|
||||
|
||||
<!-- beacon options -->
|
||||
<field name="BeaconFrequency" units="hz" type="uint32" elements="1" defaultvalue="462712500"/>
|
||||
<field name="BeaconFrequency" units="Hz" type="uint32" elements="1" defaultvalue="462712500"/>
|
||||
<field name="BeaconDelay" units="s" type="uint8" elements="1" defaultvalue="30"/>
|
||||
<field name="BeaconPeriod" units="s" type="uint8" elements="1" defaultvalue="15"/>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user