sx1250_com.c 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. / _____) _ | |
  3. ( (____ _____ ____ _| |_ _____ ____| |__
  4. \____ \| ___ | (_ _) ___ |/ ___) _ \
  5. _____) ) ____| | | || |_| ____( (___| | | |
  6. (______/|_____)_|_|_| \__)_____)\____)_| |_|
  7. (C)2019 Semtech
  8. Description:
  9. Functions used to handle LoRa concentrator SX1250 radios.
  10. License: Revised BSD License, see LICENSE.TXT file include in the project
  11. */
  12. /* -------------------------------------------------------------------------- */
  13. /* --- DEPENDANCIES --------------------------------------------------------- */
  14. #include <stdint.h> /* C99 types */
  15. #include <stdio.h> /* printf fprintf */
  16. #include "sx1250_com.h"
  17. #include "sx1250_spi.h"
  18. #include "sx1250_usb.h"
  19. /* -------------------------------------------------------------------------- */
  20. /* --- PRIVATE MACROS ------------------------------------------------------- */
  21. #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
  22. #if DEBUG_RAD == 1
  23. #define DEBUG_MSG(str) fprintf(stdout, str)
  24. #define DEBUG_PRINTF(fmt, args...) fprintf(stdout,"%s:%d: "fmt, __FUNCTION__, __LINE__, args)
  25. #define CHECK_NULL(a) if(a==NULL){fprintf(stderr,"%s:%d: ERROR: NULL POINTER AS ARGUMENT\n", __FUNCTION__, __LINE__);return -1;}
  26. #else
  27. #define DEBUG_MSG(str)
  28. #define DEBUG_PRINTF(fmt, args...)
  29. #define CHECK_NULL(a) if(a==NULL){return -1;}
  30. #endif
  31. /* -------------------------------------------------------------------------- */
  32. /* --- PRIVATE CONSTANTS ---------------------------------------------------- */
  33. /* -------------------------------------------------------------------------- */
  34. /* --- PUBLIC FUNCTIONS DEFINITION ------------------------------------------ */
  35. int sx1250_com_w(lgw_com_type_t com_type, void *com_target, uint8_t spi_mux_target, sx1250_op_code_t op_code, uint8_t *data, uint16_t size) {
  36. int com_stat;
  37. /* Check input parameters */
  38. CHECK_NULL(com_target);
  39. CHECK_NULL(data);
  40. switch (com_type) {
  41. case LGW_COM_SPI:
  42. com_stat = sx1250_spi_w(com_target, spi_mux_target, op_code, data, size);
  43. break;
  44. case LGW_COM_USB:
  45. com_stat = sx1250_usb_w(com_target, spi_mux_target, op_code, data, size);
  46. break;
  47. default:
  48. printf("ERROR: wrong communication type (SHOULD NOT HAPPEN)\n");
  49. com_stat = LGW_COM_ERROR;
  50. break;
  51. }
  52. return com_stat;
  53. }
  54. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  55. int sx1250_com_r(lgw_com_type_t com_type, void *com_target, uint8_t spi_mux_target, sx1250_op_code_t op_code, uint8_t *data, uint16_t size) {
  56. int com_stat;
  57. /* Check input parameters */
  58. CHECK_NULL(com_target);
  59. CHECK_NULL(data);
  60. switch (com_type) {
  61. case LGW_COM_SPI:
  62. com_stat = sx1250_spi_r(com_target, spi_mux_target, op_code, data, size);
  63. break;
  64. case LGW_COM_USB:
  65. com_stat = sx1250_usb_r(com_target, spi_mux_target, op_code, data, size);
  66. break;
  67. default:
  68. printf("ERROR: wrong communication type (SHOULD NOT HAPPEN)\n");
  69. com_stat = LGW_COM_ERROR;
  70. break;
  71. }
  72. return com_stat;
  73. }
  74. /* --- EOF ------------------------------------------------------------------ */