esp_modem.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. // Copyright 2015-2018 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #pragma once
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #include "esp_modem_dce.h"
  19. #include "esp_modem_dte.h"
  20. #include "esp_event.h"
  21. #include "driver/uart.h"
  22. #include "esp_modem_compat.h"
  23. /**
  24. * @brief Declare Event Base for ESP Modem
  25. *
  26. */
  27. ESP_EVENT_DECLARE_BASE(ESP_MODEM_EVENT);
  28. /**
  29. * @brief ESP Modem Event
  30. *
  31. */
  32. typedef enum {
  33. ESP_MODEM_EVENT_PPP_START = 0, /*!< ESP Modem Start PPP Session */
  34. ESP_MODEM_EVENT_PPP_STOP = 3, /*!< ESP Modem Stop PPP Session*/
  35. ESP_MODEM_EVENT_UNKNOWN = 4 /*!< ESP Modem Unknown Response */
  36. } esp_modem_event_t;
  37. /**
  38. * @brief ESP Modem DTE Configuration
  39. *
  40. */
  41. typedef struct {
  42. uart_port_t port_num; /*!< UART port number */
  43. uart_word_length_t data_bits; /*!< Data bits of UART */
  44. uart_stop_bits_t stop_bits; /*!< Stop bits of UART */
  45. uart_parity_t parity; /*!< Parity type */
  46. modem_flow_ctrl_t flow_control; /*!< Flow control type */
  47. uint32_t baud_rate; /*!< Communication baud rate */
  48. } esp_modem_dte_config_t;
  49. /**
  50. * @brief Type used for reception callback
  51. *
  52. */
  53. typedef esp_err_t (*esp_modem_on_receive)(void *buffer, size_t len, void *context);
  54. /**
  55. * @brief ESP Modem DTE Default Configuration
  56. *
  57. */
  58. #define ESP_MODEM_DTE_DEFAULT_CONFIG() \
  59. { \
  60. .port_num = UART_NUM_1, \
  61. .data_bits = UART_DATA_8_BITS, \
  62. .stop_bits = UART_STOP_BITS_1, \
  63. .parity = UART_PARITY_DISABLE, \
  64. .baud_rate = 115200, \
  65. .flow_control = MODEM_FLOW_CONTROL_NONE \
  66. }
  67. /**
  68. * @brief Create and initialize Modem DTE object
  69. *
  70. * @param config configuration of ESP Modem DTE object
  71. * @return modem_dte_t*
  72. * - Modem DTE object
  73. */
  74. modem_dte_t *esp_modem_dte_init(const esp_modem_dte_config_t *config);
  75. /**
  76. * @brief Register event handler for ESP Modem event loop
  77. *
  78. * @param dte modem_dte_t type object
  79. * @param handler event handler to register
  80. * @param handler_args arguments for registered handler
  81. * @return esp_err_t
  82. * - ESP_OK on success
  83. * - ESP_ERR_NO_MEM on allocating memory for the handler failed
  84. * - ESP_ERR_INVALID_ARG on invalid combination of event base and event id
  85. */
  86. esp_err_t esp_modem_set_event_handler(modem_dte_t *dte, esp_event_handler_t handler, int32_t event_id, void *handler_args);
  87. /**
  88. * @brief Unregister event handler for ESP Modem event loop
  89. *
  90. * @param dte modem_dte_t type object
  91. * @param handler event handler to unregister
  92. * @return esp_err_t
  93. * - ESP_OK on success
  94. * - ESP_ERR_INVALID_ARG on invalid combination of event base and event id
  95. */
  96. esp_err_t esp_modem_remove_event_handler(modem_dte_t *dte, esp_event_handler_t handler);
  97. /**
  98. * @brief Setup PPP Session
  99. *
  100. * @param dte Modem DTE object
  101. * @return esp_err_t
  102. * - ESP_OK on success
  103. * - ESP_FAIL on error
  104. */
  105. esp_err_t esp_modem_start_ppp(modem_dte_t *dte);
  106. /**
  107. * @brief Exit PPP Session
  108. *
  109. * @param dte Modem DTE Object
  110. * @return esp_err_t
  111. * - ESP_OK on success
  112. * - ESP_FAIL on error
  113. */
  114. esp_err_t esp_modem_stop_ppp(modem_dte_t *dte);
  115. /**
  116. * @brief Setup on reception callback
  117. *
  118. * @param dte ESP Modem DTE object
  119. * @param receive_cb Function pointer to the reception callback
  120. * @param receive_cb_ctx Contextual pointer to be passed to the reception callback
  121. *
  122. * @return ESP_OK on success
  123. */
  124. esp_err_t esp_modem_set_rx_cb(modem_dte_t *dte, esp_modem_on_receive receive_cb, void *receive_cb_ctx);
  125. /**
  126. * @brief Notify the modem, that ppp netif has closed
  127. *
  128. * @note This API should only be used internally by the modem-netif layer
  129. *
  130. * @param dte ESP Modem DTE object
  131. *
  132. * @return ESP_OK on success
  133. */
  134. esp_err_t esp_modem_notify_ppp_netif_closed(modem_dte_t *dte);
  135. #ifdef __cplusplus
  136. }
  137. #endif