From 69ad3ea589fae8fa051c519d79649e411eedb0aa Mon Sep 17 00:00:00 2001 From: David Cermak Date: Fri, 21 May 2021 16:05:37 +0200 Subject: [PATCH] Make the component compatible with IDFv4.1, v4.2, v4.3 --- .../esp_modem/examples/ap_to_pppos/README.md | 4 +++ .../esp_modem/examples/linux_modem/README.md | 4 +++ .../examples/modem_console/README.md | 6 +++- .../esp_modem/examples/pppos_client/README.md | 4 +++ .../examples/simple_cmux_client/README.md | 4 +++ .../cxx_include/esp_modem_primitives.hpp | 4 ++- .../linux/esp_event_mock/include/esp_event.h | 2 ++ .../esp_modem/private_include/uart_compat.h | 35 +++++++++++++++++++ .../private_include/uart_resource.hpp | 4 ++- .../esp_modem/src/esp_modem_term_uart.cpp | 2 +- components/esp_modem/src/esp_modem_uart.cpp | 9 +++-- .../esp_modem/src/esp_modem_uart_linux.cpp | 2 +- 12 files changed, 72 insertions(+), 8 deletions(-) create mode 100644 components/esp_modem/private_include/uart_compat.h diff --git a/components/esp_modem/examples/ap_to_pppos/README.md b/components/esp_modem/examples/ap_to_pppos/README.md index 8a22a730d..6f8d184ce 100644 --- a/components/esp_modem/examples/ap_to_pppos/README.md +++ b/components/esp_modem/examples/ap_to_pppos/README.md @@ -15,3 +15,7 @@ By default, this example simply connects to the PPP server using a supported dev This example however, doesn't rely on sending specific AT commands, just the bare minimum to setup the cellular network. Thus, if the `EXAMPLE_USE_MINIMAL_DCE` option is enabled, we directly inherit from the `ModuleIf` and implement only the basic commands. Also, to demonstrate the dce_factory functionality, a new `NetDCE_Factory` is implemented for creating the network module and the DCE. + +### Supported IDF versions + +This example is only supported from `v4.2`, since is uses NAPT feature. \ No newline at end of file diff --git a/components/esp_modem/examples/linux_modem/README.md b/components/esp_modem/examples/linux_modem/README.md index 47873cd5d..c480dde00 100644 --- a/components/esp_modem/examples/linux_modem/README.md +++ b/components/esp_modem/examples/linux_modem/README.md @@ -17,3 +17,7 @@ over PPPoS, i.e. over the modem serial line. * Experiment with the network, after getting the IP from the modem device - directly in the code - in the system (need to set `tun` interface IP, dns servers, and routing the desired traffic over the tun interface) + +### Supported IDF versions + +This example (using the default CMake IDF build system) is only supported from `v4.4`, since is uses `idf.py`'s linux target. \ No newline at end of file diff --git a/components/esp_modem/examples/modem_console/README.md b/components/esp_modem/examples/modem_console/README.md index 0dbf5c4cb..852ec533f 100644 --- a/components/esp_modem/examples/modem_console/README.md +++ b/components/esp_modem/examples/modem_console/README.md @@ -14,4 +14,8 @@ This example implements two very simple network commands to demonstrate and test To demonstrate creating custom modem devices, this example creates a DCE object using a locally defined create method, that sets up the DCE based on a custom module implemented in the `my_module_dce.hpp` file. The module class only overrides `get_module_name()` method supplying a user defined name, but keeps all other commands the same as defined in the `GenericModule` -class. \ No newline at end of file +class. + +### Supported IDF versions + +This example is only supported from `v4.2`, due to support of the console repl mode. \ No newline at end of file diff --git a/components/esp_modem/examples/pppos_client/README.md b/components/esp_modem/examples/pppos_client/README.md index 376f37eb8..a29687b91 100644 --- a/components/esp_modem/examples/pppos_client/README.md +++ b/components/esp_modem/examples/pppos_client/README.md @@ -8,3 +8,7 @@ This example shows how to act as a MQTT client after the PPPoS channel created b ## How to use this example See the README.md file in the upper level `pppos` directory for more information about the PPPoS examples. + +### Supported IDF versions + +This example is only supported from `v4.1`, as this is the default dependency of `esp-modem` component. \ No newline at end of file diff --git a/components/esp_modem/examples/simple_cmux_client/README.md b/components/esp_modem/examples/simple_cmux_client/README.md index 3f9b2528a..71438d512 100644 --- a/components/esp_modem/examples/simple_cmux_client/README.md +++ b/components/esp_modem/examples/simple_cmux_client/README.md @@ -15,3 +15,7 @@ The example uses the following configuration options to demonstrate basic esp-mo ## About the esp_modem Please check the component [README](../../README.md) + +### Supported IDF versions + +This example is only supported from `v4.3`, since is uses an experimental `esp_event_cxx` component. \ No newline at end of file diff --git a/components/esp_modem/include/cxx_include/esp_modem_primitives.hpp b/components/esp_modem/include/cxx_include/esp_modem_primitives.hpp index 3c11e97c9..4dcef99b3 100644 --- a/components/esp_modem/include/cxx_include/esp_modem_primitives.hpp +++ b/components/esp_modem/include/cxx_include/esp_modem_primitives.hpp @@ -14,6 +14,8 @@ #ifndef _ESP_MODEM_PRIMITIVES_HPP_ #define _ESP_MODEM_PRIMITIVES_HPP_ + +#include "esp_event.h" #include "esp_modem_exception.hpp" #if defined(CONFIG_IDF_TARGET_LINUX) @@ -34,7 +36,7 @@ namespace esp_modem { using TaskFunction_t = void (*)(void*); #if !defined(CONFIG_IDF_TARGET_LINUX) struct Lock { - using MutexT = QueueDefinition*; + using MutexT = QueueHandle_t; explicit Lock(); ~Lock(); void lock(); diff --git a/components/esp_modem/port/linux/esp_event_mock/include/esp_event.h b/components/esp_modem/port/linux/esp_event_mock/include/esp_event.h index 070ca0dde..8d21a1a81 100644 --- a/components/esp_modem/port/linux/esp_event_mock/include/esp_event.h +++ b/components/esp_modem/port/linux/esp_event_mock/include/esp_event.h @@ -38,4 +38,6 @@ esp_err_t esp_event_handler_register(const char * event_base, int32_t event_id, esp_err_t esp_event_handler_unregister(const char * event_base, int32_t event_id, void* event_handler); +typedef void * QueueHandle_t; + #endif //MDNS_HOST_ESP_EVENT_H diff --git a/components/esp_modem/private_include/uart_compat.h b/components/esp_modem/private_include/uart_compat.h new file mode 100644 index 000000000..30ee65ed7 --- /dev/null +++ b/components/esp_modem/private_include/uart_compat.h @@ -0,0 +1,35 @@ +// Copyright 2021 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "esp_log.h" +#include "driver/uart.h" + +#ifndef _UART_COMPAT_H_ +#define _UART_COMPAT_H_ + +/** + * @brief This is a compatible header, which just takes care of different data ptr type + * across different IDF version in driver/uart + */ +static inline int uart_write_bytes_compat(uart_port_t uart_num, const void* src, size_t size) +{ +#if ESP_IDF_VERSION_MAJOR >= 4 && ESP_IDF_VERSION_MINOR >= 3 + const void *data = src; +#else + auto *data = reinterpret_cast(src); +#endif + return uart_write_bytes(uart_num, data, size); +} + +#endif //_UART_COMPAT_H_ diff --git a/components/esp_modem/private_include/uart_resource.hpp b/components/esp_modem/private_include/uart_resource.hpp index 3be5efb4b..5d8be1b09 100644 --- a/components/esp_modem/private_include/uart_resource.hpp +++ b/components/esp_modem/private_include/uart_resource.hpp @@ -26,8 +26,10 @@ namespace esp_modem { * @brief Uart Resource is a platform specific struct which is implemented separately for ESP_PLATFORM and linux target */ struct uart_resource { - explicit uart_resource(const esp_modem_dte_config *config, struct QueueDefinition** event_queue, int fd); + explicit uart_resource(const esp_modem_dte_config *config, QueueHandle_t* event_queue, int fd); + ~uart_resource(); + uart_port_t port{}; }; diff --git a/components/esp_modem/src/esp_modem_term_uart.cpp b/components/esp_modem/src/esp_modem_term_uart.cpp index 2828f440e..594fadd32 100644 --- a/components/esp_modem/src/esp_modem_term_uart.cpp +++ b/components/esp_modem/src/esp_modem_term_uart.cpp @@ -25,7 +25,7 @@ uart_resource::~uart_resource() } } -uart_resource::uart_resource(const esp_modem_dte_config *config, struct QueueDefinition** event_queue, int fd) +uart_resource::uart_resource(const esp_modem_dte_config *config, QueueHandle_t* event_queue, int fd) :port(-1) { esp_err_t res; diff --git a/components/esp_modem/src/esp_modem_uart.cpp b/components/esp_modem/src/esp_modem_uart.cpp index 9c670863c..fe163fb1b 100644 --- a/components/esp_modem/src/esp_modem_uart.cpp +++ b/components/esp_modem/src/esp_modem_uart.cpp @@ -17,6 +17,7 @@ #include "freertos/semphr.h" #include "esp_log.h" #include "driver/uart.h" +#include "uart_compat.h" #include "esp_modem_config.h" #include "exception_stub.hpp" #include "cxx_include/esp_modem_dte.hpp" @@ -163,7 +164,8 @@ void UartTerminal::task() { } } -int UartTerminal::read(uint8_t *data, size_t len) { +int UartTerminal::read(uint8_t *data, size_t len) +{ size_t length = 0; uart_get_buffered_data_len(uart.port, &length); length = std::min(len, length); @@ -173,8 +175,9 @@ int UartTerminal::read(uint8_t *data, size_t len) { return 0; } -int UartTerminal::write(uint8_t *data, size_t len) { - return uart_write_bytes(uart.port, data, len); +int UartTerminal::write(uint8_t *data, size_t len) +{ + return uart_write_bytes_compat(uart.port, data, len); } } // namespace esp_modem diff --git a/components/esp_modem/src/esp_modem_uart_linux.cpp b/components/esp_modem/src/esp_modem_uart_linux.cpp index da68e7757..ad696c2e3 100644 --- a/components/esp_modem/src/esp_modem_uart_linux.cpp +++ b/components/esp_modem/src/esp_modem_uart_linux.cpp @@ -23,7 +23,7 @@ namespace esp_modem { constexpr const char *TAG = "uart_resource"; -uart_resource::uart_resource(const esp_modem_dte_config *config, struct QueueDefinition** event_queue, int fd): port(-1) +uart_resource::uart_resource(const esp_modem_dte_config *config, QueueHandle_t* event_queue, int fd): port(-1) { ESP_LOGD(TAG, "Creating uart resource" ); struct termios tty = {};