DHCOM_HAL
Hardware-abstraction library (HAL) for multiple targets, including DHCOM modules
 All Data Structures Namespaces Files Functions Typedefs Enumerations Enumerator Macros Pages
Public Types | Public Member Functions
dhcom::UART Class Reference

Provides access to an UART on a DHCOM Module. The class does not provide protection from re-opening the same UART device many times. The class provides non-blocking IO, returning the number of symbols actually sent or received. More...

#include <UART.h>

Public Types

enum  DEVICE {
  DEVICE_UART0 = 0, DEVICE_UART1, DEVICE_UART2, DEVICE_UART3,
  DEVICE_UART4, DEVICE_UART5, DEVICE_UART6, DEVICE_UART7,
  DEVICE_UART8, DEVICE_UART9, DEVICE_UART10, DEVICE_UART11,
  DEVICE_UART12, DEVICE_UART13, DEVICE_UART14, DEVICE_UART15,
  DEVICE_UART16, DEVICE_UART17, DEVICE_UART18, DEVICE_UART19
}
 Enumeration of the UART devices. More...
 
enum  BAUDRATE {
  BAUDRATE_110, BAUDRATE_300, BAUDRATE_600, BAUDRATE_1200,
  BAUDRATE_2400, BAUDRATE_4800, BAUDRATE_9600, BAUDRATE_19200,
  BAUDRATE_38400, BAUDRATE_57600, BAUDRATE_115200
}
 Enumeration of supported baud rates. More...
 
enum  PARITY { PARITY_NONE, PARITY_ODD, PARITY_EVEN }
 Enumeration of supported parity bit configurations. More...
 
enum  STOPBITS { STOPBITS_1, STOPBITS_2 }
 Enumeration of supported stop bit configurations. More...
 
enum  FLOWCONTROL { FLOW_NONE, FLOW_RTS_CTS, FLOW_XON_XOFF }
 Enumeration of supported flow control methods. More...
 
enum  IPIN { IPIN_CD, IPIN_CTS, IPIN_DSR, IPIN_RI }
 Enumeration of UART pins, which can be used as discrete inputs. More...
 
enum  OPIN { OPIN_RTS, OPIN_DTR }
 Enumeration of UART pins, which can be used as discrete outputs. More...
 

Public Member Functions

 UART (const System &sys, DEVICE device)
 Creates the UART object. Requires to know on which system we run (a fully set System object).
 
 ~UART ()
 Destroys the UART object, closing it if necessary.
 
STATUS setCommParams (BAUDRATE baudRate, PARITY parity, STOPBITS stopBits, FLOWCONTROL flowControl)
 Sets the communication parameters for the UART.
 
STATUS open ()
 Opens the UART device for I/O.
 
STATUS close ()
 Closes the UART device.
 
bool isOpen () const
 Checks if the UART device is open.
 
uint32_t write (const uint8_t *buffer, uint32_t size, STATUS *status=NULL)
 Writes an array of bytes (at least partially) to the UART.
 
uint32_t read (uint8_t *buffer, uint32_t size, STATUS *status=NULL)
 Reads an array of bytes (at least partially) from the UART.
 
STATUS setPin (OPIN pin, bool value)
 Setting level of a pin.
 
bool getPin (IPIN pin, STATUS *status=NULL) const
 Getting status of a pin.
 

Detailed Description

Provides access to an UART on a DHCOM Module. The class does not provide protection from re-opening the same UART device many times. The class provides non-blocking IO, returning the number of symbols actually sent or received.

Member Enumeration Documentation

Enumeration of supported baud rates.

Enumerator:
BAUDRATE_110 
BAUDRATE_300 
BAUDRATE_600 
BAUDRATE_1200 
BAUDRATE_2400 
BAUDRATE_4800 
BAUDRATE_9600 
BAUDRATE_19200 
BAUDRATE_38400 
BAUDRATE_57600 
BAUDRATE_115200 

Enumeration of the UART devices.

Enumerator:
DEVICE_UART0 
DEVICE_UART1 
DEVICE_UART2 
DEVICE_UART3 
DEVICE_UART4 
DEVICE_UART5 
DEVICE_UART6 
DEVICE_UART7 
DEVICE_UART8 
DEVICE_UART9 
DEVICE_UART10 
DEVICE_UART11 
DEVICE_UART12 
DEVICE_UART13 
DEVICE_UART14 
DEVICE_UART15 
DEVICE_UART16 
DEVICE_UART17 
DEVICE_UART18 
DEVICE_UART19 

Enumeration of supported flow control methods.

Enumerator:
FLOW_NONE 

No flow control.

FLOW_RTS_CTS 

Hardware flow control.

FLOW_XON_XOFF 

Software flow control.

Enumeration of UART pins, which can be used as discrete inputs.

Enumerator:
IPIN_CD 

the carrier detect pin

IPIN_CTS 

the Clear To Send (CTS) pin

IPIN_DSR 

the DSR pin

IPIN_RI 

the Ring Incoming pin

Enumeration of UART pins, which can be used as discrete outputs.

Enumerator:
OPIN_RTS 

the Ready To Send (RTS) pin

OPIN_DTR 

the DTR pin

Enumeration of supported parity bit configurations.

Enumerator:
PARITY_NONE 
PARITY_ODD 
PARITY_EVEN 

Enumeration of supported stop bit configurations.

Enumerator:
STOPBITS_1 

one stop bit

STOPBITS_2 

two stop bits

Constructor & Destructor Documentation

dhcom::UART::UART ( const System sys,
DEVICE  device 
)

Creates the UART object. Requires to know on which system we run (a fully set System object).

dhcom::UART::~UART ( )

Destroys the UART object, closing it if necessary.

Member Function Documentation

STATUS dhcom::UART::close ( )

Closes the UART device.

Returns
STATUS_SUCCESS.
bool dhcom::UART::getPin ( UART::IPIN  pin,
STATUS status = NULL 
) const

Getting status of a pin.

Parameters
pin- the pin for which to get the status;
status- if NULL, no status returned, otherwise may return STATUS_DEVICE_NOT_OPEN, STATUS_DEVICE_READ_FAILED or STATUS_SUCCESS.
Returns
true for high level on pin, false for low.
bool dhcom::UART::isOpen ( ) const

Checks if the UART device is open.

Returns
true if the device is open.
STATUS dhcom::UART::open ( )

Opens the UART device for I/O.

Returns
- can return STATUS_HARDWARE_UNDEFINED, STATUS_DEVICE_DOESNT_EXIST, STATUS_DEVICE_ALREADY_OPEN, STATUS_DEVICE_OPEN_FAILED or STATUS_SUCCESS.
uint32_t dhcom::UART::read ( uint8_t buffer,
uint32_t  length,
STATUS status = NULL 
)

Reads an array of bytes (at least partially) from the UART.

Parameters
buffer- the destination array, must be at least of size length
length- the number of bytes to read
status- if NULL, no status returned, otherwise may return STATUS_DEVICE_NOT_OPEN, STATUS_DEVICE_READ_FAILED or STATUS_SUCCESS.
Returns
- the number of bytes actually gotten (0 and up to length) The function is non-blocking, which means that if the UART read buffer becomes empty, it will return with result less than length. It also may return with result of 0, which means that the buffer is still empty.
STATUS dhcom::UART::setCommParams ( BAUDRATE  baudRate,
PARITY  parity,
STOPBITS  stopBits,
FLOWCONTROL  flowControl 
)

Sets the communication parameters for the UART.

Parameters
baudRate- the baud rate;
parity- the parity setting;
stopBits- 1 or 2 stop bits;
flowControl- the flow control setting.
Returns
- can return STATUS_DEVICE_NOT_OPEN, STATUS_DEVICE_CONFIG_FAILED or STATUS_SUCCESS.
STATUS dhcom::UART::setPin ( UART::OPIN  pin,
bool  value 
)

Setting level of a pin.

Parameters
pin- the pin for which to set the level;
value- true for high level, false for low level;
Returns
may return STATUS_DEVICE_NOT_OPEN, STATUS_DEVICE_WRITE_FAILED or STATUS_SUCCESS;
uint32_t dhcom::UART::write ( const uint8_t buffer,
uint32_t  length,
STATUS status = NULL 
)

Writes an array of bytes (at least partially) to the UART.

Parameters
buffer- the source array
length- the number of bytes to write
status- if NULL, no status returned, otherwise may return STATUS_DEVICE_NOT_OPEN, STATUS_DEVICE_WRITE_FAILED or STATUS_SUCCESS.
Returns
- the number of bytes actually written (0 and up to length) The function is non-blocking, which means that if the UART write buffer is full, it will return with result less than the length. It also may return with result of 0, which means that the buffer is still full.

The documentation for this class was generated from the following file: