loragw_mcu.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /*
  2. / _____) _ | |
  3. ( (____ _____ ____ _| |_ _____ ____| |__
  4. \____ \| ___ | (_ _) ___ |/ ___) _ \
  5. _____) ) ____| | | || |_| ____( (___| | | |
  6. (______/|_____)_|_|_| \__)_____)\____)_| |_|
  7. (C)2020 Semtech
  8. Description:
  9. Host specific functions to address the LoRa concentrator MCU for USB
  10. interface.
  11. Single-byte read/write and burst read/write.
  12. License: Revised BSD License, see LICENSE.TXT file include in the project
  13. */
  14. #ifndef _LORAGW_MCU_H
  15. #define _LORAGW_MCU_H
  16. /* -------------------------------------------------------------------------- */
  17. /* --- DEPENDANCIES --------------------------------------------------------- */
  18. #include <stdint.h> /* C99 types*/
  19. #include "config.h" /* library configuration options (dynamically generated) */
  20. /* -------------------------------------------------------------------------- */
  21. /* --- PUBLIC CONSTANTS ----------------------------------------------------- */
  22. static const char mcu_version_string[] = "01.00.00";
  23. #define MAX_SIZE_COMMAND ( 4200 )
  24. #define MAX_SPI_COMMAND ( MAX_SIZE_COMMAND - CMD_OFFSET__DATA - 1 )
  25. #define LGW_USB_BURST_CHUNK ( 4096 )
  26. /* -------------------------------------------------------------------------- */
  27. /* --- PUBLIC TYPES --------------------------------------------------------- */
  28. typedef enum order_id_e
  29. {
  30. ORDER_ID__REQ_PING = 0x00,
  31. ORDER_ID__REQ_GET_STATUS = 0x01,
  32. ORDER_ID__REQ_BOOTLOADER_MODE = 0x02,
  33. ORDER_ID__REQ_RESET = 0x03,
  34. ORDER_ID__REQ_WRITE_GPIO = 0x04,
  35. ORDER_ID__REQ_MULTIPLE_SPI = 0x05,
  36. ORDER_ID__ACK_PING = 0x40,
  37. ORDER_ID__ACK_GET_STATUS = 0x41,
  38. ORDER_ID__ACK_BOOTLOADER_MODE = 0x42,
  39. ORDER_ID__ACK_RESET = 0x43,
  40. ORDER_ID__ACK_WRITE_GPIO = 0x44,
  41. ORDER_ID__ACK_MULTIPLE_SPI = 0x45,
  42. ORDER_ID__CMD_ERROR = 0xFF
  43. } order_id_t;
  44. typedef enum
  45. {
  46. CMD_OFFSET__ID,
  47. CMD_OFFSET__SIZE_MSB,
  48. CMD_OFFSET__SIZE_LSB,
  49. CMD_OFFSET__CMD,
  50. CMD_OFFSET__DATA
  51. } e_cmd_order_offset;
  52. typedef enum
  53. {
  54. REQ_RESET__TYPE,
  55. REQ_RESET_SIZE
  56. } e_cmd_offset_req_reset;
  57. typedef enum
  58. {
  59. REQ_WRITE_GPIO__PORT,
  60. REQ_WRITE_GPIO__PIN,
  61. REQ_WRITE_GPIO__STATE,
  62. REQ_WRITE_GPIO_SIZE
  63. } e_cmd_offset_req_write_gpio;
  64. typedef enum
  65. {
  66. ACK_PING__UNIQUE_ID_0, ACK_PING__UNIQUE_ID_1, ACK_PING__UNIQUE_ID_2, ACK_PING__UNIQUE_ID_3,
  67. ACK_PING__UNIQUE_ID_4, ACK_PING__UNIQUE_ID_5, ACK_PING__UNIQUE_ID_6, ACK_PING__UNIQUE_ID_7,
  68. ACK_PING__UNIQUE_ID_8, ACK_PING__UNIQUE_ID_9, ACK_PING__UNIQUE_ID_10, ACK_PING__UNIQUE_ID_11,
  69. ACK_PING__VERSION_0, ACK_PING__VERSION_1, ACK_PING__VERSION_2, ACK_PING__VERSION_3, ACK_PING__VERSION_4,
  70. ACK_PING__VERSION_5, ACK_PING__VERSION_6, ACK_PING__VERSION_7, ACK_PING__VERSION_8,
  71. ACK_PING_SIZE,
  72. } e_cmd_offset_ack_ping;
  73. typedef enum
  74. {
  75. ACK_GET_STATUS__SYSTEM_TIME_31_24, ACK_GET_STATUS__SYSTEM_TIME_23_16, ACK_GET_STATUS__SYSTEM_TIME_15_8, ACK_GET_STATUS__SYSTEM_TIME_7_0,
  76. ACK_GET_STATUS__TEMPERATURE_15_8, ACK_GET_STATUS__TEMPERATURE_7_0,
  77. ACK_GET_STATUS_SIZE
  78. } e_cmd_offset_ack_get_status;
  79. typedef enum
  80. {
  81. ACK_GPIO_WRITE__STATUS,
  82. ACK_GPIO_WRITE_SIZE
  83. } e_cmd_offset_ack_gpio_write;
  84. typedef enum
  85. {
  86. ACK_RESET__STATUS,
  87. ACK_RESET_SIZE
  88. } e_cmd_offset_ack_reset;
  89. typedef enum
  90. {
  91. MCU_SPI_TARGET_SX1302, /* SX1302 + SX1250 */
  92. MCU_SPI_TARGET_SX1261 /* LBT/Spectral Scan additional radio */
  93. } e_cmd_spi_target;
  94. typedef enum
  95. {
  96. MCU_SPI_REQ_TYPE_READ_WRITE = 0x01, /* Read/Write SPI request */
  97. MCU_SPI_REQ_TYPE_READ_MODIFY_WRITE = 0x02 /* Read-Modify-Write SPI request */
  98. } e_cmd_spi_req_type;
  99. typedef enum
  100. {
  101. RESET_TYPE__GTW
  102. } e_reset_type;
  103. typedef enum
  104. {
  105. SPI_STATUS_OK,
  106. SPI_STATUS_FAIL,
  107. SPI_STATUS_WRONG_PARAM,
  108. SPI_STATUS_TIMEOUT
  109. } e_spi_status;
  110. typedef struct {
  111. uint32_t unique_id_high;
  112. uint32_t unique_id_mid;
  113. uint32_t unique_id_low;
  114. char version[10]; /* format is V00.00.00\0 */
  115. } s_ping_info;
  116. typedef struct {
  117. uint32_t system_time_ms;
  118. float temperature;
  119. } s_status;
  120. /* -------------------------------------------------------------------------- */
  121. /* --- PUBLIC FUNCTIONS PROTOTYPES ------------------------------------------ */
  122. /**
  123. *
  124. */
  125. int mcu_ping(int fd, s_ping_info * info);
  126. /**
  127. *
  128. */
  129. int mcu_boot(int fd);
  130. /**
  131. *
  132. */
  133. int mcu_get_status(int fd, s_status * status);
  134. /**
  135. *
  136. */
  137. int mcu_gpio_write(int fd, uint8_t gpio_port, uint8_t gpio_id, uint8_t gpio_value);
  138. /**
  139. @brief Send a SX1302 read/write SPI request to the MCU
  140. @param fd File descriptor of the device used to access the MCU
  141. @param in_out_buf The buffer containing the multiple requests to be sent to the
  142. SX1302 with the SPI header (r/w, target mux). This buffer will also contain the
  143. SPI answer when the function exits.
  144. @param buf_size The size of the given input/output buffer
  145. @return 0 for SUCCESS, -1 for failure
  146. */
  147. int mcu_spi_write(int fd, uint8_t * in_out_buf, size_t buf_size);
  148. /**
  149. *
  150. */
  151. int mcu_spi_store(uint8_t * in_out_buf, size_t buf_size);
  152. /**
  153. *
  154. */
  155. int mcu_spi_flush(int fd);
  156. #endif
  157. /* --- EOF ------------------------------------------------------------------ */