lora.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #ifndef __LORA_H__
  2. #define __LORA_H__
  3. #include "stm32f10x.h"
  4. #include "project_config.h"
  5. #include "tools.h"
  6. #include "os.h"
  7. //#define LORA_DEBUG_EN 1
  8. #ifdef LORA_DEBUG_EN
  9. #define LORA_DEBUG(fmt, x...) \
  10. do \
  11. { \
  12. printf(fmt,##x); \
  13. }while(0)
  14. #define LORA_DEBUG_F(fmt, x...) \
  15. do \
  16. { \
  17. printf("\r\n%s(Line %d): "fmt,__FUNCTION__,__LINE__, ##x); \
  18. }while(0)
  19. #else
  20. #define LORA_DEBUG(fmt, x...)
  21. #define LORA_DEBUG_H(fmt, x...)
  22. #define LORA_DEBUG_F(fmt, x...)
  23. #endif
  24. extern volatile uint32_t TickCounter;
  25. #define MODE_TIMEOUT 3000
  26. extern timeout_t tt_lora_rcv_state;
  27. extern timeout_t tt_lora_rst_rcv_state;
  28. extern timeout_t tt_lora_irq;
  29. typedef enum LORA_STATE_ENUM {
  30. lora_state_idle,
  31. lora_state_rcv,
  32. lora_state_send,
  33. lora_state_cad,
  34. lora_state_rcvRunning,
  35. lora_state_sendRunning,
  36. lora_state_cadRunning,
  37. lora_state_cadTimeout,
  38. lora_state_cadDone,
  39. lora_state_max
  40. } LORA_STATE_ENUM;
  41. extern uint8_t lora_state;
  42. #define SYS_LORA_RX 1
  43. #define SYS_LORA_TX 2
  44. #define LORA_DELAY_TIME_BASE 150
  45. #define LORA_DELAY_TIME_ADD_MAX 50
  46. typedef struct _system_lora {
  47. uint8_t memory[8][256]; //必须4字节对齐
  48. OS_Q lora_q;
  49. OS_SEM sem;
  50. OS_MEM lora_m;
  51. OS_TMR lora_tmr;
  52. } system_lora_t;
  53. extern system_lora_t sys_lora_rx;
  54. extern system_lora_t sys_lora_tx;
  55. //lora参数
  56. typedef struct _lora_para_single
  57. {
  58. uint32_t lora_fre; // 收发频率
  59. uint8_t lora_tx_output_power; // 测试默认使用的发射功率,126x发射功率0~22dbm,127x发射功率2~20dbm
  60. uint8_t lora_bandwidth; // [0: 125 kHz, 测试默认使用的带宽,sx126x:[0: 125 kHz,1: 250 kHz,2: 500 kHz,3: Reserved]
  61. uint8_t lora_spreading_factor; // 测试默认使用的扩频因子范围7~12
  62. uint8_t lora_codingrate; // 测试默认使用的纠错编码率[1: 4/5,2: 4/6,3: 4/7,4: 4/8]
  63. uint16_t lora_preamble_length; // 前导码长度
  64. // uint8_t reserve[2]; // 预留
  65. }__attribute__((packed)) lora_para_single_t;
  66. typedef struct _lora_para
  67. {
  68. lora_para_single_t lora_para_group[4];
  69. }__attribute__((packed)) lora_para_t;
  70. extern lora_para_t lora_para;
  71. extern uint8_t lora_para_choice;
  72. extern lora_para_single_t lora_para_fixed[];
  73. void lora_queue_init(void);
  74. void* lora_queue_mem_calloc_must(uint8_t state);
  75. int lora_queue_mem_free(uint8_t state,void * p_msg);
  76. void lora_queue_insert(uint8_t state,char *p_msg, uint32_t msg_len);
  77. void lora_queue_init(void);
  78. void lora_init(void);
  79. void lora_task(void);
  80. void lora_rcv_interval_set(uint8_t state);
  81. void lora_queue_proc_rx(void);
  82. void lora_queue_proc_tx(void);
  83. void lora_queue_delete(uint8_t state);
  84. #endif