Private
Public Access
2
0

uart: add uart device open and close functionality

Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
Jon Trulson
2015-04-29 16:03:53 -06:00
committed by Thomas Ingleby
parent bdadbb8b01
commit 6d269eeabd
3 changed files with 122 additions and 0 deletions

View File

@@ -1,5 +1,6 @@
/*
* Author: Thomas Ingleby <thomas.c.ingleby@intel.com>
* Contributions: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2014 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
@@ -41,6 +42,15 @@ extern "C" {
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <termios.h>
#include <sys/time.h>
#include <sys/select.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "common.h"
@@ -63,6 +73,26 @@ mraa_uart_context mraa_uart_init(int uart);
*/
char* mraa_uart_get_dev_path(mraa_uart_context dev);
/**
* Open the TTY device associated with a UART context, and set up the
* terminal modes and baud rate. The TTY is setup for a 'raw'
* mode. 81N, no echo or special character handling, such as flow
* control or line editing semantics.
*
* @param dev uart context
* @param baud desired baud rate
* @return mraa_result_t
*/
mraa_result_t mraa_uart_open_dev(mraa_uart_context dev, speed_t baud);
/**
* Close a device previously opened with mraa_uart_open_dev().
*
* @param dev uart context
* @return mraa_result_t
*/
mraa_result_t mraa_uart_close_dev(mraa_uart_context dev);
#ifdef __cplusplus
}
#endif

View File

@@ -1,5 +1,6 @@
/*
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
* Contributions: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2014 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
@@ -57,6 +58,7 @@ class Uart
*/
~Uart()
{
closeDevice();
return;
}
@@ -73,6 +75,33 @@ class Uart
return ret_val;
}
/**
* Open the TTY device associated with a UART context, and set up the
* terminal modes and baud rate. The TTY is setup for a 'raw'
* mode. 81N, no echo or special character handling, such as flow
* control or line editing semantics.
*
* @param baud desired baud rate
* @return mraa_result_t
*/
mraa_result_t
openDevice(speed_t baud)
{
return mraa_uart_open_dev(m_uart, baud);
}
/**
* Close a device previously opened with mraa_uart_open_dev().
*
* @param dev uart context
* @return mraa_result_t
*/
mraa_result_t
closeDevice()
{
return mraa_uart_close_dev(m_uart);
}
private:
mraa_uart_context m_uart;
};