Private
Public Access
2
0

uart: add tcsendbreak support

Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Alex Tereschenko <alext.mkrs@gmail.com>
This commit is contained in:
Jon Trulson
2017-05-03 12:14:36 -06:00
committed by Alex Tereschenko
parent 6d5b2c0642
commit e0a0dac47b
10 changed files with 111 additions and 0 deletions

View File

@@ -72,6 +72,18 @@ mraa_uart_context mraa_uart_init_raw(const char* path);
*/
mraa_result_t mraa_uart_flush(mraa_uart_context dev);
/**
* Send a break to the device.
* Blocks until complete.
*
* @param dev The UART context
* @param duration When 0, send a break lasting at least 250
* milliseconds, and not more than 500 milliseconds. When non zero,
* the break duration is implementation specific.
* @return Result of operation
*/
mraa_result_t mraa_uart_sendbreak(mraa_uart_context dev, int duration);
/**
* Set the baudrate.
* Takes an int and will attempt to decide what baudrate is

View File

@@ -197,6 +197,21 @@ class Uart
return (Result) mraa_uart_flush(m_uart);
}
/**
* Send a break to the device.
* Blocks until complete.
*
* @param duration When 0, send a break lasting at least 250
* milliseconds, and not more than 500 milliseconds. When non zero,
* the break duration is implementation specific.
* @return Result of operation
*/
Result
sendBreak(int duration)
{
return (Result) mraa_uart_sendbreak(m_uart, duration);
}
/**
* Set the baudrate.
* Takes an int and will attempt to decide what baudrate is

View File

@@ -42,6 +42,9 @@ mraa_mock_uart_init_raw_replace(mraa_uart_context dev, const char* path);
mraa_result_t
mraa_mock_uart_flush_replace(mraa_uart_context dev);
mraa_result_t
mraa_mock_uart_sendbreak_replace(mraa_uart_context dev, int duration);
mraa_result_t
mraa_mock_uart_set_flowcontrol_replace(mraa_uart_context dev, mraa_boolean_t xonxoff, mraa_boolean_t rtscts);

View File

@@ -113,6 +113,7 @@ typedef struct {
mraa_result_t (*uart_init_post) (mraa_uart_context uart);
mraa_result_t (*uart_init_raw_replace) (mraa_uart_context dev, const char* path);
mraa_result_t (*uart_flush_replace) (mraa_uart_context dev);
mraa_result_t (*uart_sendbreak_replace) (mraa_uart_context dev, int duration);
mraa_result_t (*uart_set_baudrate_replace) (mraa_uart_context dev, unsigned int baud);
mraa_result_t (*uart_set_mode_replace) (mraa_uart_context dev, int bytesize, mraa_uart_parity_t parity, int stopbits);
mraa_result_t (*uart_set_flowcontrol_replace) (mraa_uart_context dev, mraa_boolean_t xonxoff, mraa_boolean_t rtscts);

View File

@@ -128,6 +128,7 @@ mraa_mock_board()
b->adv_func->uart_init_raw_replace = &mraa_mock_uart_init_raw_replace;
b->adv_func->uart_set_baudrate_replace = &mraa_mock_uart_set_baudrate_replace;
b->adv_func->uart_flush_replace = &mraa_mock_uart_flush_replace;
b->adv_func->uart_sendbreak_replace = &mraa_mock_uart_sendbreak_replace;
b->adv_func->uart_set_flowcontrol_replace = &mraa_mock_uart_set_flowcontrol_replace;
b->adv_func->uart_set_mode_replace = &mraa_mock_uart_set_mode_replace;
b->adv_func->uart_set_non_blocking_replace = &mraa_mock_uart_set_non_blocking_replace;

View File

@@ -53,6 +53,12 @@ mraa_mock_uart_flush_replace(mraa_uart_context dev)
return MRAA_SUCCESS;
}
mraa_result_t
mraa_mock_uart_sendbreak_replace(mraa_uart_context dev, int duration)
{
return MRAA_SUCCESS;
}
mraa_result_t
mraa_mock_uart_set_flowcontrol_replace(mraa_uart_context dev, mraa_boolean_t xonxoff, mraa_boolean_t rtscts)
{

View File

@@ -137,6 +137,12 @@ mraa_pman_uart_flush_replace(mraa_uart_context dev)
return MRAA_ERROR_FEATURE_NOT_IMPLEMENTED;
}
static mraa_result_t
mraa_pman_uart_sendbreak_replace(mraa_uart_context dev)
{
return MRAA_ERROR_FEATURE_NOT_IMPLEMENTED;
}
static int
mraa_pman_uart_read_replace(mraa_uart_context dev, char* buf, size_t len)
{
@@ -854,6 +860,7 @@ mraa_peripheralman_plat_init()
b->adv_func->uart_init_raw_replace = &mraa_pman_uart_init_raw_replace;
b->adv_func->uart_set_baudrate_replace = &mraa_pman_uart_set_baudrate_replace;
b->adv_func->uart_flush_replace = &mraa_pman_uart_flush_replace;
b->adv_func->uart_sendbreak_replace = &mraa_pman_uart_sendbreak_replace;
b->adv_func->uart_set_flowcontrol_replace = &mraa_pman_uart_set_flowcontrol_replace;
b->adv_func->uart_set_mode_replace = &mraa_pman_uart_set_mode_replace;
b->adv_func->uart_set_non_blocking_replace = &mraa_pman_uart_set_non_blocking_replace;

View File

@@ -323,6 +323,27 @@ mraa_uart_flush(mraa_uart_context dev)
return MRAA_SUCCESS;
}
mraa_result_t
mraa_uart_sendbreak(mraa_uart_context dev, int duration)
{
if (!dev) {
syslog(LOG_ERR, "uart: sendbreak: context is NULL");
return MRAA_ERROR_INVALID_HANDLE;
}
if (IS_FUNC_DEFINED(dev, uart_sendbreak_replace)) {
return dev->advance_func->uart_sendbreak_replace(dev, duration);
}
#if !defined(PERIPHERALMAN)
if (tcsendbreak(dev->fd, duration) == -1) {
return MRAA_ERROR_INVALID_PARAMETER;
}
#endif
return MRAA_SUCCESS;
}
mraa_result_t
mraa_uart_set_baudrate(mraa_uart_context dev, unsigned int baud)
{

View File

@@ -39,6 +39,7 @@ add_test (NAME py_uart_checks_set_timeout COMMAND ${PYTHON_DEFAULT_EXECUTABLE} $
add_test (NAME py_uart_checks_data_available COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/uart_checks_data_available.py)
add_test (NAME py_uart_checks_write COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/uart_checks_write.py)
add_test (NAME py_uart_checks_read COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/uart_checks_read.py)
add_test (NAME py_uart_checks_sendbreak COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/uart_checks_sendbreak.py)
set_tests_properties(py_general
py_platform
@@ -76,4 +77,5 @@ set_tests_properties(py_general
py_uart_checks_data_available
py_uart_checks_write
py_uart_checks_read
py_uart_checks_sendbreak
PROPERTIES ENVIRONMENT "PYTHONPATH=${PYTHON_DEFAULT_PYTHONPATH}")

View File

@@ -0,0 +1,43 @@
#!/usr/bin/env python
# Author: Jon Trulson <jtrulson@ics.com>
# Copyright (c) 2017 Intel Corporation.
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import mraa as m
import unittest as u
from uart_checks_shared import *
class UartChecksSendbreak(u.TestCase):
def setUp(self):
self.uart = m.Uart(MRAA_UART_DEV_NUM)
def tearDown(self):
del self.uart
def test_uart_sendbreak(self):
self.assertEqual(self.uart.sendBreak(0),
m.SUCCESS,
"Running UART sendBreak() did not return success")
if __name__ == "__main__":
u.main()