loragw_spi.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. / _____) _ | |
  3. ( (____ _____ ____ _| |_ _____ ____| |__
  4. \____ \| ___ | (_ _) ___ |/ ___) _ \
  5. _____) ) ____| | | || |_| ____( (___| | | |
  6. (______/|_____)_|_|_| \__)_____)\____)_| |_|
  7. (C)2019 Semtech
  8. Description:
  9. Host specific functions to address the LoRa concentrator registers through
  10. a SPI interface.
  11. Single-byte read/write and burst read/write.
  12. Could be used with multiple SPI ports in parallel (explicit file descriptor)
  13. License: Revised BSD License, see LICENSE.TXT file include in the project
  14. */
  15. #ifndef _LORAGW_SPI_H
  16. #define _LORAGW_SPI_H
  17. /* -------------------------------------------------------------------------- */
  18. /* --- DEPENDANCIES --------------------------------------------------------- */
  19. #include <stdint.h> /* C99 types*/
  20. #include "config.h" /* library configuration options (dynamically generated) */
  21. /* -------------------------------------------------------------------------- */
  22. /* --- PUBLIC CONSTANTS ----------------------------------------------------- */
  23. #define LGW_SPI_SUCCESS 0
  24. #define LGW_SPI_ERROR -1
  25. #define SPI_SPEED 2000000
  26. /* -------------------------------------------------------------------------- */
  27. /* --- PUBLIC FUNCTIONS PROTOTYPES ------------------------------------------ */
  28. /**
  29. @brief LoRa concentrator SPI setup (configure I/O and peripherals)
  30. @param com_path path to the SPI device to be used to connect to the SX1302
  31. @param spi_target_ptr pointer on a generic pointer to SPI target (implementation dependant)
  32. @return status of register operation (LGW_SPI_SUCCESS/LGW_SPI_ERROR)
  33. */
  34. int lgw_spi_open(const char * com_path, void **com_target_ptr);
  35. /**
  36. @brief LoRa concentrator SPI close
  37. @param spi_target generic pointer to SPI target (implementation dependant)
  38. @return status of register operation (LGW_SPI_SUCCESS/LGW_SPI_ERROR)
  39. */
  40. int lgw_spi_close(void *com_target);
  41. /**
  42. @brief LoRa concentrator SPI single-byte write
  43. @param spi_target generic pointer to SPI target (implementation dependant)
  44. @param address 7-bit register address
  45. @param data data byte to write
  46. @return status of register operation (LGW_SPI_SUCCESS/LGW_SPI_ERROR)
  47. */
  48. int lgw_spi_w(void *com_target, uint8_t spi_mux_target, uint16_t address, uint8_t data);
  49. /**
  50. @brief LoRa concentrator SPI single-byte read
  51. @param spi_target generic pointer to SPI target (implementation dependant)
  52. @param address 7-bit register address
  53. @param data data byte to write
  54. @return status of register operation (LGW_SPI_SUCCESS/LGW_SPI_ERROR)
  55. */
  56. int lgw_spi_r(void *com_target, uint8_t spi_mux_target, uint16_t address, uint8_t *data);
  57. /**
  58. @brief LoRa concentrator SPI single-byte read-modify-write
  59. @param spi_target generic pointer to SPI target (implementation dependant)
  60. @param address 7-bit register address
  61. @param offs start offset of the bits to be modified
  62. @param leng number of bits to be modified
  63. @param data value to be written in the selected bits
  64. @return status of register operation (LGW_SPI_SUCCESS/LGW_SPI_ERROR)
  65. */
  66. int lgw_spi_rmw(void *com_target, uint8_t spi_mux_target, uint16_t address, uint8_t offs, uint8_t leng, uint8_t data);
  67. /**
  68. @brief LoRa concentrator SPI burst (multiple-byte) write
  69. @param spi_target generic pointer to SPI target (implementation dependant)
  70. @param address 7-bit register address
  71. @param data pointer to byte array that will be sent to the LoRa concentrator
  72. @param size size of the transfer, in byte(s)
  73. @return status of register operation (LGW_SPI_SUCCESS/LGW_SPI_ERROR)
  74. */
  75. int lgw_spi_wb(void *com_target, uint8_t spi_mux_target, uint16_t address, const uint8_t *data, uint16_t size);
  76. /**
  77. @brief LoRa concentrator SPI burst (multiple-byte) read
  78. @param spi_target generic pointer to SPI target (implementation dependant)
  79. @param address 7-bit register address
  80. @param data pointer to byte array that will be written from the LoRa concentrator
  81. @param size size of the transfer, in byte(s)
  82. @return status of register operation (LGW_SPI_SUCCESS/LGW_SPI_ERROR)
  83. */
  84. int lgw_spi_rb(void *com_target, uint8_t spi_mux_target, uint16_t address, uint8_t *data, uint16_t size);
  85. /**
  86. *
  87. **/
  88. uint16_t lgw_spi_chunk_size(void);
  89. #endif
  90. /* --- EOF ------------------------------------------------------------------ */