FEC and 32-bit sync word emulation for CC1101

This commit is contained in:
Ilya Kuznetsov 2022-11-27 16:42:59 +05:00
parent 8c37da0720
commit 8505892bff
3 changed files with 36 additions and 6 deletions

View file

@ -328,6 +328,11 @@
*/ */
#define RADIOLIB_ERR_INVALID_NUM_BROAD_ADDRS (-601) #define RADIOLIB_ERR_INVALID_NUM_BROAD_ADDRS (-601)
/*!
\brief FEC cannot be enabled for variable packet length mode
*/
#define RADIOLIB_ERR_FEC_UNAVAILABLE (-602)
// SX126x-specific status codes // SX126x-specific status codes
/*! /*!

View file

@ -624,7 +624,7 @@ int16_t CC1101::setOutputPower(int8_t power) {
} }
} }
int16_t CC1101::setSyncWord(uint8_t* syncWord, uint8_t len, uint8_t maxErrBits, bool requireCarrierSense) { int16_t CC1101::setSyncWord(uint8_t* syncWord, uint8_t len, uint8_t maxErrBits, bool requireCarrierSense, bool repeatSyncWord) {
if((maxErrBits > 1) || (len != 2)) { if((maxErrBits > 1) || (len != 2)) {
return(RADIOLIB_ERR_INVALID_SYNC_WORD); return(RADIOLIB_ERR_INVALID_SYNC_WORD);
} }
@ -637,7 +637,7 @@ int16_t CC1101::setSyncWord(uint8_t* syncWord, uint8_t len, uint8_t maxErrBits,
} }
// enable sync word filtering // enable sync word filtering
int16_t state = enableSyncWordFiltering(maxErrBits, requireCarrierSense); int16_t state = enableSyncWordFiltering(maxErrBits, requireCarrierSense, repeatSyncWord);
RADIOLIB_ASSERT(state); RADIOLIB_ASSERT(state);
// set sync word register // set sync word register
@ -786,7 +786,19 @@ int16_t CC1101::variablePacketLengthMode(uint8_t maxLen) {
return(setPacketMode(RADIOLIB_CC1101_LENGTH_CONFIG_VARIABLE, maxLen)); return(setPacketMode(RADIOLIB_CC1101_LENGTH_CONFIG_VARIABLE, maxLen));
} }
int16_t CC1101::enableSyncWordFiltering(uint8_t maxErrBits, bool requireCarrierSense) { int16_t CC1101::setForwardErrorCorrection(bool enable) {
if(_packetLengthConfig == RADIOLIB_CC1101_LENGTH_CONFIG_FIXED) {
return(SPIsetRegValue(RADIOLIB_CC1101_REG_MDMCFG1, (enable ? RADIOLIB_CC1101_FEC_ON : RADIOLIB_CC1101_FEC_OFF), 7, 7));
} else {
return(RADIOLIB_ERR_FEC_UNAVAILABLE);
}
}
int16_t CC1101::enableSyncWordFiltering(uint8_t maxErrBits, bool requireCarrierSense, bool repeatSyncWord) {
if (repeatSyncWord) {
// if 32-bit sync word emulation is enabled, maxErrBits parameter is useless since it's always 30/32
return(SPIsetRegValue(RADIOLIB_CC1101_REG_MDMCFG2, (requireCarrierSense ? RADIOLIB_CC1101_SYNC_MODE_30_32_THR : RADIOLIB_CC1101_SYNC_MODE_30_32), 2, 0));
}
switch(maxErrBits){ switch(maxErrBits){
case 0: case 0:
// in 16 bit sync word, expect all 16 bits // in 16 bit sync word, expect all 16 bits

View file

@ -765,9 +765,11 @@ class CC1101: public PhysicalLayer {
\param requireCarrierSense Require carrier sense above threshold in addition to sync word. \param requireCarrierSense Require carrier sense above threshold in addition to sync word.
\param repeatSyncWord Enable repeated transmission in TX to emulate 32-bit sync word and force 32-bit word detection in RX.
\returns \ref status_codes \returns \ref status_codes
*/ */
int16_t setSyncWord(uint8_t syncH, uint8_t syncL, uint8_t maxErrBits = 0, bool requireCarrierSense = false); int16_t setSyncWord(uint8_t syncH, uint8_t syncL, uint8_t maxErrBits = 0, bool requireCarrierSense = false, bool repeatSyncWord = false);
/*! /*!
\brief Sets 1 or 2 bytes of sync word. \brief Sets 1 or 2 bytes of sync word.
@ -780,9 +782,11 @@ class CC1101: public PhysicalLayer {
\param requireCarrierSense Require carrier sense above threshold in addition to sync word. \param requireCarrierSense Require carrier sense above threshold in addition to sync word.
\param repeatSyncWord Enable repeated transmission in TX to emulate 32-bit sync word and force 32-bit word detection in RX.
\returns \ref status_codes \returns \ref status_codes
*/ */
int16_t setSyncWord(uint8_t* syncWord, uint8_t len, uint8_t maxErrBits = 0, bool requireCarrierSense = false); int16_t setSyncWord(uint8_t* syncWord, uint8_t len, uint8_t maxErrBits = 0, bool requireCarrierSense = false, bool repeatSyncWord = false);
/*! /*!
\brief Sets preamble length. \brief Sets preamble length.
@ -863,6 +867,13 @@ class CC1101: public PhysicalLayer {
*/ */
int16_t variablePacketLengthMode(uint8_t maxLen = RADIOLIB_CC1101_MAX_PACKET_LENGTH); int16_t variablePacketLengthMode(uint8_t maxLen = RADIOLIB_CC1101_MAX_PACKET_LENGTH);
/*!
\brief Enable or disable forward error correction for fixed length packets.
\returns \ref status_codes
*/
int16_t setForwardErrorCorrection(bool enable = true);
/*! /*!
\brief Enable sync word filtering and generation. \brief Enable sync word filtering and generation.
@ -870,9 +881,11 @@ class CC1101: public PhysicalLayer {
\param requireCarrierSense Require carrier sense above threshold in addition to sync word. \param requireCarrierSense Require carrier sense above threshold in addition to sync word.
\param repeatSyncWord Enable repeated transmission in TX to emulate 32-bit sync word and force 32-bit word detection in RX.
\returns \ref status_codes \returns \ref status_codes
*/ */
int16_t enableSyncWordFiltering(uint8_t maxErrBits = 0, bool requireCarrierSense = false); int16_t enableSyncWordFiltering(uint8_t maxErrBits = 0, bool requireCarrierSense = false, bool repeatSyncWord);
/*! /*!
\brief Disable preamble and sync word filtering and generation. \brief Disable preamble and sync word filtering and generation.