esp_modem: Refactor the modem to a standalone managed component

This commit is contained in:
David Cermak
2020-11-18 21:20:35 +01:00
parent 5565a09ed1
commit c8e89098bd
63 changed files with 5081 additions and 2180 deletions

View File

@ -0,0 +1,62 @@
// Copyright 2020 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.
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include "esp_modem_dce.h"
#include "esp_modem.h"
/**
* @brief Finds the command par its symbolic name
*
* @param dce Modem DCE object
* @param command Symbolic name of the command
*
* @return Function pointer to the
*/
dce_command_t esp_modem_dce_find_command(esp_modem_dce_t *dce, const char *command);
/**
* @brief Delete specific command from the list
*
* @param dce Modem DCE object
* @param command Symbolic name of the command to delete
*
* @return ESP_OK on success
*/
esp_err_t esp_modem_dce_delete_command(esp_modem_dce_t *dce, const char *command_id);
/**
* @brief Deletes all commands in the list
*
* @param dce Modem DCE object
*
* @return ESP_OK on success
*/
esp_err_t esp_modem_dce_delete_all_commands(esp_modem_dce_t *dce);
/**
* @brief Creates internal structure for holding the command list
*
* @return Pointer to the command list struct on success, NULL otherwise
*/
struct esp_modem_dce_cmd_list *esp_modem_command_list_create(void);
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,51 @@
// Copyright 2020 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.
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include "esp_modem.h"
/**
* @brief Specific init of SIM800 device
*
* @param dce Modem DCE object
*
* @return ESP_OK on success
*/
esp_err_t esp_modem_sim800_specific_init(esp_modem_dce_t *dce);
/**
* @brief Specific init of SIM7600 device
*
* @param dce Modem DCE object
*
* @return ESP_OK on success
*/
esp_err_t esp_modem_sim7600_specific_init(esp_modem_dce_t *dce);
/**
* @brief Specific init of BG96 device
*
* @param dce Modem DCE object
*
* @return ESP_OK on success
*/
esp_err_t esp_modem_bg96_specific_init(esp_modem_dce_t *dce);
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,57 @@
// Copyright 2020 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.
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include "esp_log.h"
#include "esp_modem.h"
#include "esp_modem_dte.h"
#include "freertos/FreeRTOS.h"
#include "freertos/event_groups.h"
/**
* @brief Main lifecycle states of the esp-modem
*
* The bits below are used to indicate events in process_group
* field of the esp_modem_dte_internal_t
*/
#define ESP_MODEM_START_BIT BIT0
#define ESP_MODEM_COMMAND_BIT BIT1
#define ESP_MODEM_STOP_PPP_BIT BIT2
#define ESP_MODEM_STOP_BIT BIT3
/**
* @brief ESP32 Modem DTE
*
*/
typedef struct {
uart_port_t uart_port; /*!< UART port */
uint8_t *buffer; /*!< Internal buffer to store response lines/data from DCE */
QueueHandle_t event_queue; /*!< UART event queue handle */
esp_event_loop_handle_t event_loop_hdl; /*!< Event loop handle */
TaskHandle_t uart_event_task_hdl; /*!< UART event task handle */
EventGroupHandle_t process_group; /*!< Event group used for indicating DTE state changes */
esp_modem_dte_t parent; /*!< DTE interface that should extend */
esp_modem_on_receive receive_cb; /*!< ptr to data reception */
void *receive_cb_ctx; /*!< ptr to rx fn context data */
int line_buffer_size; /*!< line buffer size in command mode */
int pattern_queue_size; /*!< UART pattern queue size */
} esp_modem_dte_internal_t;
#ifdef __cplusplus
}
#endif

View File

@ -1,4 +1,4 @@
// Copyright 2015-2018 Espressif Systems (Shanghai) PTE LTD
// Copyright 2020 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.
@ -13,25 +13,36 @@
// limitations under the License.
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include "esp_log.h"
#include "esp_modem.h"
/**
* @brief Macro defined for error checking
*
*/
#define DCE_CHECK(a, str, goto_tag, ...) \
* @brief Macro defined for error checking
*
*/
#define ESP_MODEM_ERR_CHECK(a, str, goto_tag, ...) \
do \
{ \
if (!(a)) \
{ \
ESP_LOGE(DCE_TAG, "%s(%d): " str, __FUNCTION__, __LINE__, ##__VA_ARGS__); \
ESP_LOGE(TAG, "%s(%d): " str, __FUNCTION__, __LINE__, ##__VA_ARGS__); \
goto goto_tag; \
} \
} while (0)
/**
* @brief BG96 Modem
*
*/
typedef struct {
void *priv_resource; /*!< Private resource */
modem_dce_t parent; /*!< DCE parent class */
} bg96_modem_dce_t;
* @brief common modem delay function
*
*/
static inline void esp_modem_wait_ms(size_t time)
{
vTaskDelay(pdMS_TO_TICKS(time));
}
#ifdef __cplusplus
}
#endif