esp-modem(VFS): Reworked decouple resources from the file system

This commit is contained in:
David Cermak
2021-05-23 20:43:50 +02:00
parent 69ad3ea589
commit 8f17a90026
17 changed files with 332 additions and 177 deletions

View File

@ -56,23 +56,14 @@ struct esp_modem_uart_term_config {
int event_queue_size; /*!< UART Event Queue Size, set to 0 if no event queue needed */
};
/**
* @brief Resources used by VFS terminal
*
*/
typedef enum {
ESP_MODEM_VFS_IS_EXTERN = 0, /*!< External resource: internal VFS terminal takes no action to setup this */
ESP_MODEM_VFS_IS_UART, /*!< VFS uses UART: internal VFS initializes UART based on esp_modem_uart_term_config */
} esp_modem_vfs_resource_t;
/**
* @brief VFS configuration structure
*
*/
struct esp_modem_vfs_term_config {
const char* dev_name; /*!< VFS device name, e.g. /dev/uart/n */
esp_modem_vfs_resource_t resource; /*!< Underlying device which gets initialized during VFS init */
int fd; /*!< Already created file descriptor */
void (*deleter)(int, struct esp_modem_vfs_resource*); /*!< Custom close function for the fd */
struct esp_modem_vfs_resource *resource; /*!< Resource attached to the VFS (need for clenaup) */
};
/**
@ -86,8 +77,10 @@ struct esp_modem_dte_config {
size_t dte_buffer_size; /*!< DTE buffer size */
uint32_t task_stack_size; /*!< Terminal task stack size */
int task_priority; /*!< Terminal task priority */
struct esp_modem_uart_term_config uart_config; /*!< Configuration for UART Terminal */
struct esp_modem_vfs_term_config vfs_config; /*!< Configuration for VFS Terminal */
union {
struct esp_modem_uart_term_config uart_config; /*!< Configuration for UART Terminal */
struct esp_modem_vfs_term_config vfs_config; /*!< Configuration for VFS Terminal */
};
};
@ -115,10 +108,6 @@ struct esp_modem_dte_config {
.tx_buffer_size = 512, \
.event_queue_size = 30, \
}, \
.vfs_config = { \
.dev_name = "/null", \
.resource = ESP_MODEM_VFS_IS_EXTERN \
}\
}
typedef struct esp_modem_dte_config esp_modem_dte_config_t;

View File

@ -0,0 +1,72 @@
// 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.
#ifndef _VFS_CREATE_HPP_
#define _VFS_CREATE_HPP_
#define ESP_MODEM_VFS_DEFAULT_UART_CONFIG(name) { \
.dev_name = (name), \
.uart = { \
.port_num = UART_NUM_1, \
.data_bits = UART_DATA_8_BITS, \
.stop_bits = UART_STOP_BITS_1, \
.parity = UART_PARITY_DISABLE, \
.flow_control = ESP_MODEM_FLOW_CONTROL_NONE,\
.baud_rate = 115200, \
.tx_io_num = 25, \
.rx_io_num = 26, \
.rts_io_num = 27, \
.cts_io_num = 23, \
.rx_buffer_size = 4096, \
.tx_buffer_size = 512, \
.event_queue_size = 0, \
}, \
}
/**
* @brief UART init struct for VFS
*/
struct esp_modem_vfs_uart_creator {
const char* dev_name; /*!< VFS device name, e.g. /dev/uart/n */
const struct esp_modem_uart_term_config uart; /*!< UART driver init struct */
};
/**
* @brief UART init struct for VFS
*/
struct esp_modem_vfs_socket_creator {
const char* host_name; /*!< VFS socket: host name (or IP address) */
int port; /*!< VFS socket: port number */
};
/**
* @brief Creates a socket VFS and configures the DTE struct
*
* @param config Socket config option, basically host + port
* @param created_config reference to the VFS portion of the DTE config to be set up
* @return true on success
*/
bool vfs_create_socket(struct esp_modem_vfs_socket_creator *config, struct esp_modem_vfs_term_config *created_config);
/**
* @brief Creates a uart VFS and configures the DTE struct
*
* @param config Uart config option, basically file name and console options
* @param created_config reference to the VFS portion of the DTE config to be set up
* @return true on success
*/
bool vfs_create_uart(struct esp_modem_vfs_uart_creator *config, struct esp_modem_vfs_term_config *created_config);
#endif //_VFS_CREATE_HPP_