mirror of
https://github.com/mysensors/MySensors.git
synced 2026-02-20 01:21:27 +01:00
Transport code harmonization (#1072)
This commit is contained in:
@@ -200,7 +200,6 @@ LOCAL bool RFM69_initialise(const uint32_t frequencyHz)
|
||||
RFM69.powerLevel = MY_RFM69_TX_POWER_DBM + 1; // will be overwritten when set
|
||||
RFM69.radioMode = RFM69_RADIO_MODE_SLEEP;
|
||||
RFM69.ATCenabled = false;
|
||||
RFM69.listenModeEnabled = false;
|
||||
RFM69.ATCtargetRSSI = RFM69_RSSItoInternal(MY_RFM69_ATC_TARGET_RSSI_DBM);
|
||||
|
||||
// SPI init
|
||||
@@ -354,7 +353,7 @@ LOCAL uint8_t RFM69_receive(uint8_t *buf, const uint8_t maxBufSize)
|
||||
// clear data flag
|
||||
RFM69.dataReceived = false;
|
||||
if (RFM69_getACKRequested(controlFlags) && !RFM69_getACKReceived(controlFlags)) {
|
||||
#if defined(MY_GATEWAY_FEATURE) && (F_CPU>16000000)
|
||||
#if defined(MY_GATEWAY_FEATURE) && (F_CPU>16*1000000ul)
|
||||
// delay for fast GW and slow nodes
|
||||
delay(50);
|
||||
#endif
|
||||
@@ -425,9 +424,9 @@ LOCAL bool RFM69_send(const uint8_t recipient, uint8_t *data, const uint8_t len,
|
||||
LOCAL void RFM69_setFrequency(const uint32_t frequencyHz)
|
||||
{
|
||||
const uint32_t freqHz = (uint32_t)(frequencyHz / RFM69_FSTEP);
|
||||
RFM69_writeReg(RFM69_REG_FRFMSB, (freqHz >> 16) & 0xFF);
|
||||
RFM69_writeReg(RFM69_REG_FRFMID, (freqHz >> 8) & 0xFF);
|
||||
RFM69_writeReg(RFM69_REG_FRFLSB, freqHz & 0xFF);
|
||||
RFM69_writeReg(RFM69_REG_FRFMSB, (uint8_t)((freqHz >> 16) & 0xFF));
|
||||
RFM69_writeReg(RFM69_REG_FRFMID, (uint8_t)((freqHz >> 8) & 0xFF));
|
||||
RFM69_writeReg(RFM69_REG_FRFLSB, (uint8_t)(freqHz & 0xFF));
|
||||
}
|
||||
|
||||
LOCAL void RFM69_setHighPowerRegs(const bool onOff)
|
||||
@@ -774,60 +773,6 @@ LOCAL rfm69_RSSI_t RFM69_readRSSI(const bool forceTrigger)
|
||||
return (rfm69_RSSI_t)RFM69_readReg(RFM69_REG_RSSIVALUE);
|
||||
}
|
||||
|
||||
/* UNUSED
|
||||
|
||||
LOCAL uint8_t RFM69_getVersion(void)
|
||||
{
|
||||
return RFM69_readReg(RFM69_REG_VERSION);
|
||||
}
|
||||
|
||||
LOCAL uint8_t RFM69_readTemperature(const uint8_t calFactor)
|
||||
{
|
||||
(void)RFM69_setRadioMode(RFM69_RADIO_MODE_STDBY);
|
||||
RFM69_writeReg(RFM69_REG_TEMP1, RFM69_TEMP1_MEAS_START);
|
||||
const uint32_t enterMS = hwMillis();
|
||||
while ((RFM69_readReg(RFM69_REG_TEMP1) & RFM69_TEMP1_MEAS_RUNNING) && hwMillis() - enterMS < 500);
|
||||
return ~RFM69_readReg(RFM69_REG_TEMP2) + RFM69_COURSE_TEMP_COEF +
|
||||
calFactor; // 'complement' corrects the slope, rising temp = rising val
|
||||
}
|
||||
|
||||
LOCAL uint8_t RFM69_setLNA(const uint8_t newReg)
|
||||
{
|
||||
const uint8_t oldReg = RFM69_readReg(RFM69_REG_LNA);
|
||||
RFM69_writeReg(RFM69_REG_LNA, ((newReg & 7) | (oldReg &
|
||||
~7))); // just control the LNA Gain bits for now
|
||||
return oldReg; // return the original value in case we need to restore it
|
||||
}
|
||||
|
||||
LOCAL bool RFM69_waitCAD(void)
|
||||
{
|
||||
const uint32_t enterMS = hwMillis();
|
||||
(void)RFM69_setRadioMode(RFM69_RADIO_MODE_RX);
|
||||
while (RFM69.radioMode == RFM69_RADIO_MODE_RX && !RFM69.dataReceived &&
|
||||
RFM69_RSSItoInternal(RFM69_readRSSI()) > RFM69_RSSItoInternal(RFM69_CSMA_LIMIT_DBM)) {
|
||||
if (hwMillis() - enterMS > RFM69_CSMA_TIMEOUT_MS) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
LOCAL void RFM69_rcCalibration(void)
|
||||
{
|
||||
// RC oscillator calibration
|
||||
// On the SX1231 V2a, RC calibration at power-up needs to be performed
|
||||
// This is not required in the version V2b any more, where the calibration is fully automatic
|
||||
// see SX1231 datasheet, chapter 9 (Chip Revision)
|
||||
RFM69_writeReg(0x57, 0x80);
|
||||
RFM69_writeReg(RFM69_REG_OSC1, RFM69_OSC1_RCCAL_START);
|
||||
while (!(RFM69_readReg(RFM69_REG_OSC1) & RFM69_OSC1_RCCAL_DONE)) {};
|
||||
RFM69_writeReg(RFM69_REG_OSC1, RFM69_OSC1_RCCAL_START);
|
||||
while (!(RFM69_readReg(RFM69_REG_OSC1) & RFM69_OSC1_RCCAL_DONE)) {};
|
||||
RFM69_writeReg(0x57, 0x00);
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
LOCAL void RFM69_readAllRegs(void)
|
||||
{
|
||||
#ifdef RFM69_REGISTER_DETAIL
|
||||
|
||||
@@ -326,7 +326,6 @@ typedef struct {
|
||||
rfm69_RSSI_t RSSI; //!< RSSI of current packet, RSSI = value - 137
|
||||
} __attribute__((packed)) rfm69_packet_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief RFM69 internal variables
|
||||
*/
|
||||
@@ -341,8 +340,7 @@ typedef struct {
|
||||
bool dataReceived : 1; //!< data received
|
||||
bool ackReceived : 1; //!< ACK received
|
||||
bool ATCenabled : 1; //!< ATC enabled
|
||||
bool listenModeEnabled : 1; //!< Listen mode enabled
|
||||
bool reserved : 1; //!< Reserved
|
||||
uint8_t reserved : 2; //!< Reserved
|
||||
} rfm69_internal_t;
|
||||
|
||||
#define LOCAL static //!< static
|
||||
|
||||
@@ -347,9 +347,8 @@ LOCAL bool RFM95_sendFrame(rfm95_packet_t *packet, const bool increaseSequenceCo
|
||||
(void)RFM95_setRadioMode(RFM95_RADIO_MODE_TX);
|
||||
// wait until IRQ fires or timeout
|
||||
const uint32_t startTX_MS = hwMillis();
|
||||
while (!RFM95_irq &&
|
||||
(hwMillis() - startTX_MS <
|
||||
MY_RFM95_TX_TIMEOUT_MS) ) { // make this payload length + bit rate dependend
|
||||
// todo: make this payload length + bit rate dependend
|
||||
while (!RFM95_irq && (hwMillis() - startTX_MS < MY_RFM95_TX_TIMEOUT_MS) ) {
|
||||
doYield();
|
||||
}
|
||||
return RFM95_irq;
|
||||
@@ -371,9 +370,9 @@ LOCAL bool RFM95_send(const uint8_t recipient, uint8_t *data, const uint8_t len,
|
||||
LOCAL void RFM95_setFrequency(const uint32_t frequencyHz)
|
||||
{
|
||||
const uint32_t freqReg = (uint32_t)(frequencyHz / RFM95_FSTEP);
|
||||
(void)RFM95_writeReg(RFM95_REG_06_FRF_MSB, (freqReg >> 16) & 0xff);
|
||||
(void)RFM95_writeReg(RFM95_REG_07_FRF_MID, (freqReg >> 8) & 0xff);
|
||||
(void)RFM95_writeReg(RFM95_REG_08_FRF_LSB, freqReg & 0xff);
|
||||
(void)RFM95_writeReg(RFM95_REG_06_FRF_MSB, (uint8_t)((freqReg >> 16) & 0xff));
|
||||
(void)RFM95_writeReg(RFM95_REG_07_FRF_MID, (uint8_t)((freqReg >> 8) & 0xff));
|
||||
(void)RFM95_writeReg(RFM95_REG_08_FRF_LSB, (uint8_t)(freqReg & 0xff));
|
||||
}
|
||||
|
||||
LOCAL bool RFM95_setTxPowerLevel(rfm95_powerLevel_t newPowerLevel)
|
||||
@@ -420,8 +419,8 @@ LOCAL void RFM95_setModemRegisters(const rfm95_modemConfig_t *config)
|
||||
|
||||
LOCAL void RFM95_setPreambleLength(const uint16_t preambleLength)
|
||||
{
|
||||
(void)RFM95_writeReg(RFM95_REG_20_PREAMBLE_MSB, (preambleLength >> 8) & 0xff);
|
||||
(void)RFM95_writeReg(RFM95_REG_21_PREAMBLE_LSB, preambleLength & 0xff);
|
||||
(void)RFM95_writeReg(RFM95_REG_20_PREAMBLE_MSB, (uint8_t)((preambleLength >> 8) & 0xff));
|
||||
(void)RFM95_writeReg(RFM95_REG_21_PREAMBLE_LSB, (uint8_t)(preambleLength & 0xff));
|
||||
}
|
||||
|
||||
LOCAL void RFM95_setAddress(const uint8_t addr)
|
||||
|
||||
@@ -186,8 +186,6 @@ extern HardwareSPI SPI; //!< SPI
|
||||
#define RFM95_setACKReceived(__value, __flag) bitWrite(__value, RFM95_BIT_ACK_RECEIVED,__flag) //!< setACKReceived
|
||||
#define RFM95_setACKRSSIReport(__value, __flag) bitWrite(__value, RFM95_BIT_ACK_RSSI_REPORT,__flag) //!< setACKRSSIReport
|
||||
#define RFM95_getACKRSSIReport(__value) ((bool)bitRead(__value, RFM95_BIT_ACK_RSSI_REPORT)) //!< getACKRSSIReport
|
||||
//#define RFM95_internalToRSSI(__value) ((int16_t)(__value - RFM95_RSSI_OFFSET)) //!< Convert internal RSSI to RSSI
|
||||
//#define RFM95_RSSItoInternal(__value) ((uint8_t)(__value + RFM95_RSSI_OFFSET)) //!< Convert RSSI to internal RSSI
|
||||
#define RFM95_internalToSNR(__value) ((int8_t)(__value / 4)) //!< Convert internal SNR to SNR
|
||||
|
||||
#define RFM95_MIN_POWER_LEVEL_DBM ((rfm95_powerLevel_t)5u) //!< min. power level
|
||||
|
||||
Reference in New Issue
Block a user