zephyrproject-rtos / zephyr

Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
https://docs.zephyrproject.org
Apache License 2.0
10.05k stars 6.18k forks source link

LoRa Driver extended features #42122

Open mjm987 opened 2 years ago

mjm987 commented 2 years ago

Is your enhancement proposal related to a problem? Please describe. The current implementation of the LoRa driver seems to be based on the LoRaWAN default configuration but for standalone LoRa applications, some features are missing, eg. carrier activity detection (CAD), CRC on/off, fixed length payload (Header suppression), IQ inversion, paDutyCycle, etc. etc.

Describe the solution you'd like Implementation of all possible features

Describe alternatives you've considered Have a software interface in the LoRa driver that allows calling arbitrary sx12xx commands via the lora radio library.

5frank commented 1 year ago

Other suggested changes to struct lora_modem_config:

I will try to make a PR when I have time but I'm afraid lots of things would break in this fork https://github.com/zephyrproject-rtos/loramac-node.

Example on some changes to lora.h:

struct lora_coding_rate {
    uint8_t info_bits : 3;  //!< useful information bits
    uint8_t data_bits : 4;  //!< total data bits
    uint8_t interleave : 1; //!< long interleaving if set
};

#define LORA_CR(INFO_BITS, DATA_BITS, INTERLEAVE)                              \
    (struct lora_coding_rate){                                                 \
        .info_bits = (INFO_BITS),                                              \
        .data_bits = (DATA_BITS),                                              \
        .interleave = (INTERLEAVE)                                             \
    }

#define LORA_CR_4_5   LORA_CR(4, 5, 0)
#define LORA_CR_4_6   LORA_CR(4, 6, 0)
#define LORA_CR_4_7   LORA_CR(4, 7, 0)
#define LORA_CR_4_8   LORA_CR(4, 8, 0)

struct lora_modem_config {
    uint32_t frequency; //!< frequency in Hz
    uint32_t bandwidth; //!< bandwidth in Hz
    uint16_t preamble_len;
    struct lora_coding_rate coding_rate;
    uint8_t spreading_factor;
    int8_t tx_power; //!< transmit power in dBm
};

/**
 * @return data rate in bits per second (bps) */
static inline uint32_t lora_datarate_bps(const struct lora_modem_config *config)
{
    uint32_t sf = config->spreading_factor;
    uint32_t bw = config->bandwidth;

    // avoid div by zero below
    if (sf >= 32) {
        return 0;
    }
    /* pow2(sf) */
    uint32_t pow2_sf = (uint32_t)1 << sf;

    /* symbol period length in seconds  calculated as:
     *    uint32_t t_symbol =  pow2_sf / config->bandwidth; */

    /* div round near */
    uint32_t datarate_bps = (sf * bw + (pow2_sf -1)) / pow2_sf;

    return datarate_bps;
}
warrenb78 commented 9 months ago

Another big issue I have with this driver is the lack of support of all bandwidths, which is cuurently limited to 125, 250, 500 KHz.