quec_dispatch.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /** @file
  2. quec_dispatch.c
  3. @brief
  4. This file is used to define quectel at function.
  5. */
  6. /*================================================================
  7. Copyright (c) 2022 Quectel Wireless Solution, Co., Ltd. All Rights Reserved.
  8. Quectel Wireless Solution Proprietary and Confidential.
  9. =================================================================*/
  10. /*=================================================================
  11. EDIT HISTORY FOR MODULE
  12. This section contains comments describing changes made to the module.
  13. Notice that changes are listed in reverse chronological order.
  14. WHEN WHO WHAT, WHERE, WHY
  15. ------------ ------- --------------------------------------
  16. =================================================================*/
  17. #ifndef _QUEC_SIO_ADAPTER_H_
  18. #define _QUEC_SIO_ADAPTER_H_
  19. #include "stdio.h"
  20. #include "stdlib.h"
  21. #include "string.h"
  22. #include "ql_api_osi.h"
  23. #include "ql_uart.h"
  24. /*========================================================================
  25. * General Definition
  26. *========================================================================*/
  27. #define BYPSAA_TASK_STACK 10*1024
  28. #define BYPASS_TASK_PRIO OSI_PRIORITY_NORMAL
  29. #define BYPASS_TASK_EVENT_CNT 60
  30. #define QUSB_FIFO_SIZE_MIN 4*1024
  31. #define QUSB_RX_FIFO_SIZE 24*1024
  32. #define QUSB_TX_FIFO_SIZE 12*1024
  33. /*========================================================================
  34. * enum
  35. *========================================================================*/
  36. typedef enum
  37. {
  38. QL_MODE_NONE = 0,
  39. QL_ATC_MODE = 1, //AT模式
  40. QL_DATA_MODE_DATA = 2, //数传数据模式
  41. QL_DATA_MODE_OPEN = 3, //open模式
  42. QL_DATA_MODE_BYPASS = 4, //数据将通过回调函数传给应用层
  43. QL_DATA_MODE_DATA_ESCAPE = 5, //+++,DTR(at&d1)退出data/ppp模式后处于escape模式,此时可以用ATO返回
  44. }ql_uart_mode_e;
  45. typedef enum
  46. {
  47. QL_DISPATCH_TYPE_REAL = 0, //真实sio通道
  48. QL_DISPATCH_TYPE_VIRTUAL, //虚拟通道
  49. }ql_dispatch_type_e;
  50. typedef enum
  51. {
  52. QL_UART_PROTOCAL_NONE, //UART口不走传输协议
  53. QL_UART_PROTOCAL_CMUX //UART口走CMUX协议
  54. }ql_uart_protocal_e;
  55. typedef enum quec_at_mode_switch_cause
  56. {
  57. /**
  58. * @brief start data mode
  59. */
  60. QUEC_AT_MODE_SWITCH_DATA_START,
  61. /**
  62. * @brief end data mode
  63. */
  64. QUEC_AT_MODE_SWITCH_DATA_END,
  65. /**
  66. * @brief escape from data mode to command line mode
  67. *
  68. * The data engine will be kept, and push data to command line engine.
  69. * Typical usage is to process command temporally.
  70. */
  71. QUEC_AT_MODE_SWITCH_DATA_ESCAPE,
  72. /**
  73. * @brief resume data mode from escaped command line mode
  74. */
  75. QUEC_AT_MODE_SWITCH_DATA_RESUME,
  76. } quec_at_mode_switch_e;
  77. /*========================================================================
  78. * struct
  79. *========================================================================*/
  80. typedef struct
  81. {
  82. bool baud_flag;
  83. uint baud_value;
  84. bool ifc_flag;
  85. uint8 ifc_tx;
  86. uint8 ifc_rx;
  87. bool icf_flag;
  88. uint8 icf_format;
  89. uint8 icf_parity;
  90. }ql_sio_hw_param_t;
  91. typedef struct ql_dispatch
  92. {
  93. uint8 dev; //dispatch对应的物理口
  94. ql_mutex_t lock; //dispatch互斥锁
  95. ql_dispatch_type_e type; //通道为真实通道还是虚拟通道
  96. ql_uart_mode_e mode; //数据模式
  97. ql_uart_protocal_e protocal; //数据协议
  98. void *switch_cb; //数据模式切换回调函数
  99. void *bypass_param; //bypass模式下的参数
  100. void *cmux_engine; //cmux引擎
  101. int8 dlci; //cmux编号
  102. void *ppp_session; //底层ppp结构
  103. atDevice_t *device; //底层sio结构
  104. ql_sio_hw_param_t hw_setting; //用于需要先写完当前数据,再设置波特率,ifc的场景
  105. }ql_dispatch_t;
  106. typedef void (*ql_at_mode_switch_cb_t)(ql_dispatch_t *th, quec_at_mode_switch_e cause);
  107. typedef int (*ql_at_bypass_cb_t)(ql_dispatch_t *th, uint8 *data, int size, void *param);
  108. typedef struct
  109. {
  110. void *user_ctx;
  111. ql_dispatch_t *dispatch;
  112. ql_at_bypass_cb_t cb;
  113. uint8 mode; //进bypass模式前的模式
  114. } ql_bypass_param_t;
  115. /*========================================================================
  116. * Function
  117. *========================================================================*/
  118. #ifdef CONFIG_QUEC_PROJECT_FEATURE_CMUX
  119. void *quec_get_cmux_engine(ql_dispatch_t *dispatch);
  120. int quec_dispatch_exit_cmux_mode(ql_dispatch_t *th);
  121. int quec_dispatch_set_cmux_mode(ql_dispatch_t *th, void *cfg);
  122. int quec_dispatch_get_cmux_cfg(ql_dispatch_t *th, void *config);
  123. #endif
  124. bool quec_dispatch_in_data_mode(ql_dispatch_t *th);
  125. bool quec_dispatch_in_atc_mode(ql_dispatch_t *th);
  126. bool quec_dispatch_in_data_escape(ql_dispatch_t *th);
  127. bool quec_dispatch_is_valid(ql_dispatch_t *th);
  128. int8 quec_dispatch_get_mode(ql_dispatch_t *th);
  129. int8 quec_dispatch_get_protocal(ql_dispatch_t *th);
  130. ql_dispatch_t *quec_atcmd_get_dispatch(ql_dispatch_t *th);
  131. ql_dispatch_t *quec_dispatch_create(atDevice_t *device, uint32 name, void *cmux_engine, uint8 dlci);
  132. ql_dispatch_t *quec_at_find_data_channel(void);
  133. int quec_at_dispatch_write(ql_dispatch_t *th, unsigned char *data_buff, unsigned int len);
  134. void quec_at_set_sio_hw_needed(ql_dispatch_t *th, ql_sio_hw_param_t *param);
  135. void quec_dispatch_set_mode(ql_dispatch_t *th, ql_uart_mode_e mode);
  136. void quec_dispatch_set_device(atDevice_t *th, ql_dispatch_t *recv);
  137. void quec_at_mode_switch(quec_at_mode_switch_e cause, ql_dispatch_t *d);
  138. void quec_at_set_mode_switch_cb(ql_dispatch_t *th, ql_at_mode_switch_cb_t cb);
  139. void quec_at_invoke_mode_switch_cb(ql_dispatch_t *th, quec_at_mode_switch_e cause);
  140. void quec_dispatch_auto_sleep(int timeout);
  141. void quec_dispatch_delete(ql_dispatch_t *dispatch);
  142. void *quec_dispatch_get_ppp_session(ql_dispatch_t *th);
  143. void quec_dispatch_set_ppp_session(ql_dispatch_t *th, void *ppp);
  144. int quec_at_bypass_rec_data(ql_dispatch_t *th);
  145. int quec_at_exit_bypass_mode(ql_dispatch_t *th);
  146. int quec_at_enter_bypass_mode(ql_dispatch_t *th, ql_at_bypass_cb_t cb, void *param);
  147. #endif