2021-04-04 22:15:46 +02:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
2022-10-11 16:31:57 +02:00
|
|
|
*
|
2021-04-04 22:15:46 +02:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
2021-05-15 22:09:08 +02:00
|
|
|
#include <termios.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include "esp_log.h"
|
2021-05-17 18:24:35 +02:00
|
|
|
#include "cxx_include/esp_modem_dte.hpp"
|
2021-05-15 22:09:08 +02:00
|
|
|
#include "esp_modem_config.h"
|
2021-05-17 18:24:35 +02:00
|
|
|
#include "uart_resource.hpp"
|
2021-05-15 22:09:08 +02:00
|
|
|
|
2021-05-17 18:24:35 +02:00
|
|
|
namespace esp_modem {
|
2021-05-15 22:09:08 +02:00
|
|
|
|
2021-05-17 18:24:35 +02:00
|
|
|
constexpr const char *TAG = "uart_resource";
|
2021-05-15 22:09:08 +02:00
|
|
|
|
2021-06-01 10:21:51 +02:00
|
|
|
uart_resource::uart_resource(const esp_modem_uart_term_config *config, QueueHandle_t *event_queue, int fd): port(-1)
|
2021-05-15 22:09:08 +02:00
|
|
|
{
|
|
|
|
ESP_LOGD(TAG, "Creating uart resource" );
|
|
|
|
struct termios tty = {};
|
2022-07-13 08:45:43 +02:00
|
|
|
ESP_MODEM_THROW_IF_FALSE(tcgetattr(fd, &tty) == 0, "Failed to tcgetattr()");
|
2021-05-15 22:09:08 +02:00
|
|
|
|
|
|
|
tty.c_cflag &= ~PARENB;
|
|
|
|
tty.c_cflag &= ~CSTOPB;
|
|
|
|
tty.c_cflag &= ~CSIZE; // Clear all the size bits, then use one of the statements below
|
|
|
|
tty.c_cflag |= CS8; // 8 bits per byte (most common)
|
|
|
|
tty.c_cflag &= ~CRTSCTS; // Disable RTS/CTS hardware flow control (most common)
|
|
|
|
tty.c_cflag |= CREAD | CLOCAL; // Turn on READ & ignore ctrl lines (CLOCAL = 1)
|
|
|
|
tty.c_lflag &= ~ICANON;
|
|
|
|
tty.c_lflag &= ~ECHO; // Disable echo
|
|
|
|
tty.c_lflag &= ~ISIG; // Disable interpretation of INTR, QUIT and SUSP
|
|
|
|
tty.c_iflag &= ~(IXON | IXOFF | IXANY); // Turn off s/w flow ctrl
|
2021-06-01 10:21:51 +02:00
|
|
|
tty.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL); // Disable any special handling of received bytes
|
2021-05-15 22:09:08 +02:00
|
|
|
tty.c_oflag &= ~OPOST; // Prevent special interpretation of output bytes (e.g. newline chars)
|
|
|
|
tty.c_oflag &= ~ONLCR; // Prevent conversion of newline to carriage return/line feed
|
|
|
|
tty.c_cc[VTIME] = 0;
|
|
|
|
tty.c_cc[VMIN] = 0;
|
|
|
|
cfsetispeed(&tty, B115200);
|
|
|
|
cfsetospeed(&tty, B115200);
|
|
|
|
cfsetspeed(&tty, B115200);
|
|
|
|
ioctl(fd, TCSETS, &tty);
|
|
|
|
}
|
|
|
|
|
2021-05-17 18:24:35 +02:00
|
|
|
uart_resource::~uart_resource() = default;
|
2021-05-15 22:09:08 +02:00
|
|
|
|
2021-05-17 18:24:35 +02:00
|
|
|
} // namespace esp_modem
|