ql_api_ethernet.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. /*============================================================================
  2. Copyright (c) 2020 Quectel Wireless Solution, Co., Ltd. All Rights Reserved.
  3. Quectel Wireless Solution Proprietary and Confidential.
  4. =============================================================================*/
  5. /*===========================================================================
  6. EDIT HISTORY FOR MODULE
  7. This section contains comments describing changes made to the module.
  8. Notice that changes are listed in reverse chronological order.
  9. WHEN WHO WHAT, WHERE, WHY
  10. ---------- ------------ ----------------------------------------------------
  11. =============================================================================*/
  12. #ifndef QL_API_ETHERNET_H
  13. #define QL_API_ETHERNET_H
  14. #include "ql_api_common.h"
  15. #include "ql_api_spi.h"
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. /*========================================================================
  20. * Marco Definition
  21. *========================================================================*/
  22. /*========================================================================
  23. * Enumeration Definition
  24. *========================================================================*/
  25. typedef enum
  26. {
  27. QL_ETHERNET_SUCCESS = 0,
  28. QL_ETHERNET_EXECUTE_ERR = 1| (QL_COMPONENT_ETHERNET << 16),
  29. QL_ETHERNET_MEM_ADDR_NULL_ERR,
  30. QL_ETHERNET_INVALID_PARAM_ERR,
  31. QL_ETHERNET_NO_MEMORY_ERR,
  32. QL_ETHERNET_REPEAT_REGISTER_ERR = 5| (QL_COMPONENT_ETHERNET << 16),
  33. QL_ETHERNET_NO_NETCARD_ERR,
  34. } ql_ethernet_errcode_e;
  35. typedef enum
  36. {
  37. QL_ETHERNET_MODE_NONE = 0,
  38. QL_ETHERNET_MODE_MAX,
  39. }ql_ethernet_mode_e;
  40. typedef enum
  41. {
  42. QL_ETHERNET_PHY_HW_SPI_MODE = 0, //HW SPI mode.The ctx passed to ql_ethernet_phy_init will be phased as hw_spi in ql_ethernet_phy_s.
  43. QL_ETHERNET_PHY_MODE_MAX
  44. }ql_ethernet_phy_mode;
  45. /*========================================================================
  46. * Callback Definition
  47. *========================================================================*/
  48. typedef void (*ql_ethernet_linkoutput_cb)(uint8_t *data,uint32_t len);
  49. /*========================================================================
  50. * Type Definition
  51. *========================================================================*/
  52. typedef struct
  53. {
  54. uint8_t *ip4;
  55. uint8_t *gw;
  56. uint8_t *netmask;
  57. uint8_t *mac;
  58. ql_ethernet_mode_e mode;
  59. ql_ethernet_linkoutput_cb cb; //Physical data output for SPI/UART and so on.
  60. }ql_ethernet_ctx_s;
  61. typedef struct
  62. {
  63. ql_ethernet_phy_mode mode;
  64. union
  65. {
  66. struct
  67. {
  68. uint8_t mosi_pin_num;
  69. uint8_t mosi_func_sel;
  70. uint8_t miso_pin_num;
  71. uint8_t miso_func_sel;
  72. uint8_t clk_pin_num;
  73. uint8_t clk_func_sel;
  74. uint8_t cs_pin_num;
  75. uint8_t cs_func_sel;
  76. ql_spi_config_s config;
  77. }hw_spi;
  78. };
  79. }ql_ethernet_phy_s;
  80. /*========================================================================
  81. * function Definition
  82. *========================================================================*/
  83. /*****************************************************************
  84. * Function: ql_ethernet_phy_init
  85. *
  86. * Description: Init the physical device by mode.
  87. *
  88. * Parameters:
  89. * ctx [in] see ql_ethernet_phy_mode and ql_ethernet_phy_s.
  90. * Return:
  91. * 0 success
  92. * other error code
  93. *
  94. *****************************************************************/
  95. ql_ethernet_errcode_e ql_ethernet_phy_init(ql_ethernet_phy_s *ctx);
  96. /*****************************************************************
  97. * Function: ql_ethernet_phy_write
  98. *
  99. * Description: Write to data bus,e.g. SPI or UART.Depend on mode after ql_ethernet_phy_init is called.
  100. *
  101. * Parameters:
  102. * data [in] output data which write to data bus
  103. * len [in] output data len which write to data bus
  104. * Return:
  105. * 0 success
  106. * other error code
  107. *
  108. *****************************************************************/
  109. ql_ethernet_errcode_e ql_ethernet_phy_write(uint8_t *data,uint32_t len);
  110. /*****************************************************************
  111. * Function: ql_ethernet_phy_read
  112. *
  113. * Description: Read from data bus,e.g. SPI or UART.Depend on mode after ql_ethernet_phy_init is called.
  114. *
  115. * Parameters:
  116. * data [out] input data which read from data bus
  117. * len [out] input data len which read from data bus
  118. * Return:
  119. * 0 success
  120. * other error code
  121. *
  122. *****************************************************************/
  123. ql_ethernet_errcode_e ql_ethernet_phy_read(uint8_t *data,uint32_t len);
  124. /*****************************************************************
  125. * Function: ql_ethernet_phy_deinit
  126. *
  127. * Description: Deinit the physical device.
  128. *
  129. * Parameters:
  130. * ctx [in] No defined yet.
  131. * Return:
  132. * 0 success
  133. * other error code
  134. *
  135. *****************************************************************/
  136. ql_ethernet_errcode_e ql_ethernet_phy_deinit(void* ctx);
  137. /*****************************************************************
  138. * Function: ql_ethernet_phy_append
  139. *
  140. * Description: An append data bus function defined by user.Use for adapter.See ethernet_demo.h
  141. *
  142. *
  143. * Parameters:
  144. * cb [in] callback function defined by user
  145. * ctx [in] parameter pass to callback function
  146. * Return:
  147. * 0 success
  148. * other error code
  149. *
  150. *****************************************************************/
  151. ql_ethernet_errcode_e ql_ethernet_phy_append(void *cb,void *ctx);
  152. /*****************************************************************
  153. * Function: ql_ethernet_register
  154. *
  155. * Description: Register a netcard for ethernet PHY.
  156. *
  157. * Parameters:
  158. * ql_ethernet_ctx_s [in] see ql_ethernet_ctx_s.
  159. * Return:
  160. * 0 success
  161. * other error code
  162. *
  163. *****************************************************************/
  164. ql_ethernet_errcode_e ql_ethernet_register(ql_ethernet_ctx_s *ctx);
  165. /*****************************************************************
  166. * Function: ql_ethernet_data_input
  167. *
  168. * Description: Data input from ethernet PHY.
  169. *
  170. * Parameters:
  171. * data [in] ethernet PHY input data
  172. * len [in] ethernet PHY input data len
  173. * Return:
  174. * 0 success
  175. * other error code
  176. *
  177. *****************************************************************/
  178. ql_ethernet_errcode_e ql_ethernet_data_input(uint8_t *data,uint32_t len);
  179. /*****************************************************************
  180. * Function: ql_ethernet_deregister
  181. *
  182. * Description: Unregister exist netcard.Must be called when no data transfer.
  183. *
  184. * Parameters:
  185. *
  186. *
  187. * Return:
  188. * 0 success
  189. * other error code
  190. *
  191. *****************************************************************/
  192. ql_ethernet_errcode_e ql_ethernet_deregister(void);
  193. /*****************************************************************
  194. * Function: ql_ethernet_set_down
  195. *
  196. * Description: Set netcard down.Must be called when no data transfer.
  197. *
  198. * Parameters:
  199. *
  200. *
  201. * Return:
  202. * 0 success
  203. * other error code
  204. *
  205. *****************************************************************/
  206. ql_ethernet_errcode_e ql_ethernet_set_down(void);
  207. /*****************************************************************
  208. * Function: ql_ethernet_set_up
  209. *
  210. * Description: Set netcard up.
  211. *
  212. * Parameters:
  213. *
  214. *
  215. * Return:
  216. * 0 success
  217. * other error code
  218. *
  219. *****************************************************************/
  220. ql_ethernet_errcode_e ql_ethernet_set_up(void);
  221. #ifdef __cplusplus
  222. }/*"C" */
  223. #endif
  224. #endif /*QL_API_ETHERNET_H*/