esp_modem.h 4.0 KB

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