esp_modem.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 "lwip/ip_addr.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. MODEM_EVENT_PPP_START, /*!< ESP Modem Start PPP Session */
  34. MODEM_EVENT_PPP_CONNECT, /*!< ESP Modem Connect to PPP Server */
  35. MODEM_EVENT_PPP_DISCONNECT, /*!< ESP Modem Disconnect from PPP Server */
  36. MODEM_EVENT_PPP_STOP, /*!< ESP Modem Stop PPP Session*/
  37. MODEM_EVENT_UNKNOWN /*!< ESP Modem Unknown Response */
  38. } esp_modem_event_t;
  39. /**
  40. * @brief ESP Modem DTE Configuration
  41. *
  42. */
  43. typedef struct {
  44. uart_port_t port_num; /*!< UART port number */
  45. uart_word_length_t data_bits; /*!< Data bits of UART */
  46. uart_stop_bits_t stop_bits; /*!< Stop bits of UART */
  47. uart_parity_t parity; /*!< Parity type */
  48. modem_flow_ctrl_t flow_control; /*!< Flow control type */
  49. uint32_t baud_rate; /*!< Communication baud rate */
  50. } esp_modem_dte_config_t;
  51. /**
  52. * @brief ESP Modem DTE Default Configuration
  53. *
  54. */
  55. #define ESP_MODEM_DTE_DEFAULT_CONFIG() \
  56. { \
  57. .port_num = UART_NUM_1, \
  58. .data_bits = UART_DATA_8_BITS, \
  59. .stop_bits = UART_STOP_BITS_1, \
  60. .parity = UART_PARITY_DISABLE, \
  61. .baud_rate = 115200, \
  62. .flow_control = MODEM_FLOW_CONTROL_NONE \
  63. }
  64. /**
  65. * @brief Create and initialize Modem DTE object
  66. *
  67. * @param config configuration of ESP Modem DTE object
  68. * @return modem_dte_t*
  69. * - Modem DTE object
  70. */
  71. modem_dte_t *esp_modem_dte_init(const esp_modem_dte_config_t *config);
  72. /**
  73. * @brief Register event handler for ESP Modem event loop
  74. *
  75. * @param dte modem_dte_t type object
  76. * @param handler event handler to register
  77. * @param handler_args arguments for registered handler
  78. * @return esp_err_t
  79. * - ESP_OK on success
  80. * - ESP_ERR_NO_MEM on allocating memory for the handler failed
  81. * - ESP_ERR_INVALID_ARG on invalid combination of event base and event id
  82. */
  83. esp_err_t esp_modem_add_event_handler(modem_dte_t *dte, esp_event_handler_t handler, void *handler_args);
  84. /**
  85. * @brief Unregister event handler for ESP Modem event loop
  86. *
  87. * @param dte modem_dte_t type object
  88. * @param handler event handler to unregister
  89. * @return esp_err_t
  90. * - ESP_OK on success
  91. * - ESP_ERR_INVALID_ARG on invalid combination of event base and event id
  92. */
  93. esp_err_t esp_modem_remove_event_handler(modem_dte_t *dte, esp_event_handler_t handler);
  94. /**
  95. * @brief PPPoS Client IP Information
  96. *
  97. */
  98. typedef struct {
  99. ip4_addr_t ip; /*!< IP Address */
  100. ip4_addr_t netmask; /*!< Net Mask */
  101. ip4_addr_t gw; /*!< Gateway */
  102. ip4_addr_t ns1; /*!< Name Server1 */
  103. ip4_addr_t ns2; /*!< Name Server2 */
  104. } ppp_client_ip_info_t;
  105. /**
  106. * @brief Setup PPP Session
  107. *
  108. * @param dte Modem DTE object
  109. * @return esp_err_t
  110. * - ESP_OK on success
  111. * - ESP_FAIL on error
  112. */
  113. esp_err_t esp_modem_setup_ppp(modem_dte_t *dte);
  114. /**
  115. * @brief Exit PPP Session
  116. *
  117. * @param dte Modem DTE Object
  118. * @return esp_err_t
  119. * - ESP_OK on success
  120. * - ESP_FAIL on error
  121. */
  122. esp_err_t esp_modem_exit_ppp(modem_dte_t *dte);
  123. #ifdef __cplusplus
  124. }
  125. #endif