loragw_sx1302_rx.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. / _____) _ | |
  3. ( (____ _____ ____ _| |_ _____ ____| |__
  4. \____ \| ___ | (_ _) ___ |/ ___) _ \
  5. _____) ) ____| | | || |_| ____( (___| | | |
  6. (______/|_____)_|_|_| \__)_____)\____)_| |_|
  7. (C)2019 Semtech
  8. Description:
  9. SX1302 RX buffer Hardware Abstraction Layer
  10. License: Revised BSD License, see LICENSE.TXT file include in the project
  11. */
  12. #ifndef _LORAGW_SX1302_RX_H
  13. #define _LORAGW_SX1302_RX_H
  14. /* -------------------------------------------------------------------------- */
  15. /* --- DEPENDANCIES --------------------------------------------------------- */
  16. #include <stdint.h> /* C99 types*/
  17. #include "config.h" /* library configuration options (dynamically generated) */
  18. /* -------------------------------------------------------------------------- */
  19. /* --- PUBLIC CONSTANTS ----------------------------------------------------- */
  20. /* -------------------------------------------------------------------------- */
  21. /* --- PUBLIC MACROS -------------------------------------------------------- */
  22. /* -------------------------------------------------------------------------- */
  23. /* --- PUBLIC TYPES --------------------------------------------------------- */
  24. /**
  25. @struct rx_packet_s
  26. @brief packet structure as contained in the sx1302 RX packet engine
  27. */
  28. typedef struct rx_packet_s {
  29. uint8_t rxbytenb_modem;
  30. uint8_t rx_channel_in;
  31. bool crc_en;
  32. uint8_t coding_rate; /* LoRa only */
  33. uint8_t rx_rate_sf; /* LoRa only */
  34. uint8_t modem_id;
  35. int32_t frequency_offset_error; /* LoRa only */
  36. uint8_t payload[255];
  37. bool payload_crc_error;
  38. bool sync_error; /* LoRa only */
  39. bool header_error; /* LoRa only */
  40. bool timing_set; /* LoRa only */
  41. int8_t snr_average; /* LoRa only */
  42. uint8_t rssi_chan_avg;
  43. uint8_t rssi_signal_avg; /* LoRa only */
  44. uint8_t rssi_chan_max_neg_delta;
  45. uint8_t rssi_chan_max_pos_delta;
  46. uint8_t rssi_sig_max_neg_delta; /* LoRa only */
  47. uint8_t rssi_sig_max_pos_delta; /* LoRa only */
  48. uint32_t timestamp_cnt;
  49. uint16_t rx_crc16_value; /* LoRa only */
  50. uint8_t num_ts_metrics_stored; /* LoRa only */
  51. int8_t timestamp_avg[255]; /* LoRa only */
  52. int8_t timestamp_stddev[255]; /* LoRa only */
  53. uint8_t packet_checksum;
  54. } rx_packet_t;
  55. /**
  56. @struct rx_buffer_s
  57. @brief buffer to hold the data fetched from the sx1302 RX buffer
  58. */
  59. typedef struct rx_buffer_s {
  60. uint8_t buffer[4096]; /*!> byte array to hald the data fetched from the RX buffer */
  61. uint16_t buffer_size; /*!> The number of bytes currently stored in the buffer */
  62. int buffer_index; /*!> Current parsing index in the buffer */
  63. uint8_t buffer_pkt_nb;
  64. } rx_buffer_t;
  65. /* -------------------------------------------------------------------------- */
  66. /* --- PUBLIC FUNCTIONS PROTOTYPES ------------------------------------------ */
  67. /**
  68. @brief Initialize the rx_buffer instance
  69. @param self A pointer to a rx_buffer handler
  70. @return LGW_REG_SUCCESS if success, LGW_REG_ERROR otherwise
  71. */
  72. int rx_buffer_new(rx_buffer_t * self);
  73. /**
  74. @brief Reset the rx_buffer instance
  75. @param self A pointer to a rx_buffer handler
  76. @return LGW_REG_SUCCESS if success, LGW_REG_ERROR otherwise
  77. */
  78. int rx_buffer_del(rx_buffer_t * self);
  79. /**
  80. @brief Fetch packets from the SX1302 internal RX buffer, and count packets available.
  81. @param self A pointer to a rx_buffer handler
  82. @return LGW_REG_SUCCESS if success, LGW_REG_ERROR otherwise
  83. */
  84. int rx_buffer_fetch(rx_buffer_t * self);
  85. /**
  86. @brief Parse the rx_buffer and return the first packet available in the given structure.
  87. @param self A pointer to a rx_buffer handler
  88. @param pkt A pointer to the structure to receive the packet parsed
  89. @return LGW_REG_SUCCESS if success, LGW_REG_ERROR otherwise
  90. */
  91. int rx_buffer_pop(rx_buffer_t * self, rx_packet_t * pkt);
  92. /* -------------------------------------------------------------------------- */
  93. /* --- DEBUG FUNCTIONS PROTOTYPES ------------------------------------------- */
  94. uint16_t rx_buffer_read_ptr_addr(void);
  95. uint16_t rx_buffer_write_ptr_addr(void);
  96. void rx_buffer_dump(FILE * file, uint16_t start_addr, uint16_t end_addr);
  97. #endif
  98. /* --- EOF ------------------------------------------------------------------ */