NetBurner 3.5.0
PDF Version
 
Serial Interfaces

Topics

 Serial Port Error Codes
 

Macros

#define ADDR_ESCAPE_CHAR   (0xFF)
 Address escape character.
 
#define SimpleOpenSerial(p, b)   OpenSerial(p, b, 1, 8, eParityNone)
 Simple open a serial port.
 

Enumerations

enum  parity_mode {
  eParityNone , eParityOdd , eParityEven , eParityMulti ,
  eParityMultiOdd , eParityMultiEven
}
 Serial Parity Modes. More...
 

Functions

int OpenSerial (int portnum, unsigned int baudrate, int stop_bits, int data_bits, parity_mode parity)
 Open a serial port.
 
int OpenDefaultSerial ()
 Opens the Default serial port as defined by the Boot Config settings.
 
void SerialExpandRxBuffer (int fd, int nb)
 Expand the received serial buffer.
 
int SerialClose (int portnum)
 Close a serial port.
 
void SerialEnableTxFlow (int port, int enab)
 Enable transmit software flow control on the specified UART.
 
void SerialEnableRxFlow (int port, int enab)
 
void SerialEnableHwTxFlow (int port, int enab)
 
void SerialEnableHwRxFlow (int port, int enab)
 
void Serial485HalfDupMode (int port, int enab)
 
void SendBreak (int port, uint32_t time)
 
int serwriteaddress (int fd, const char c)
 
int GetUartErrorReg (int fd)
 
void SetRTS (int port, bool val)
 
BOOL SerialSendComplete (int fd)
 

Detailed Description

#include< serial.h >

The NetBurner Serial

Macro Definition Documentation

◆ SimpleOpenSerial

#define SimpleOpenSerial ( p,
b )   OpenSerial(p, b, 1, 8, eParityNone)

#include <serial.h>

Simple open a serial port.

Select the UART number and baud rate, default parameters will be 1 stop bit, no parity, 8 data bits.

Parameters
pThe UART to open. First port is 0. The maximum number is platform dependent
bThe speed of the serial port in bits per second
See also
OpenSerial()

Enumeration Type Documentation

◆ parity_mode

#include <serial.h>

Serial Parity Modes.

Enumerator
eParityNone 

No parity.

eParityOdd 

Odd parity.

eParityEven 

Even parity.

eParityMulti 

Multi parity.

eParityMultiOdd 

Multi mode, Odd parity.

eParityMultiEven 

Multi mode, Even parity.

Function Documentation

◆ GetUartErrorReg()

int GetUartErrorReg ( int fd)

#include <serial.h>

Gets the UART error register. This is only applicable on select platforms. Any errors are added to this register in a logical OR operation. Calling this function to read the error status will clear the register.

Bit Description


3 Received break 2 Framing error 1 Parity error 0 Overrun error

fd - The file descriptor associated with the UART serial port whose error register is to be retrieved.

return - The value of the error register if successful (positive int - the bitwise values are represented by the UART_ERR_* definitions found near the top of this file); otherwise, one of the error codes is returned: SERIAL_ERR_NOSUCH_PORT (-1) SERIAL_ERR_PORT_NOTOPEN (-2)

◆ OpenDefaultSerial()

int OpenDefaultSerial ( )

#include <serial.h>

Opens the Default serial port as defined by the Boot Config settings.

This function opens the Default serial port as defined by the Boot Config settings. It is called automatically by the system as part of the system initialization process. Unlike OpenSerial and SimpleOpenSerial, OpenDefaultSerial will configure the Tx and Rx pins to the Boot Config settings.

Returns
The file descriptor of the default serial port ( > 0), or Serial Port Error Codes
See also
OpenSerial()

◆ OpenSerial()

int OpenSerial ( int portnum,
unsigned int baudrate,
int stop_bits,
int data_bits,
parity_mode parity )

#include <serial.h>

Open a serial port.

This function opens a serial port. Note that functions to open a serial port, such as OpenSerial() and SimpleOpenSerial(), must be called before any functions or pin assignments that configure the operation of the serial port. You must also configure all pins that have the same UART capability. For example, if UART 1 TX can be configured to come out on more than one pin (as a second or third alternate function), you must set those pins to some function other than UART 1 TX. This is because the functions that open a serial port will configure all serial port functions to default operation and default pins. For example, hardware flow control will be off, and the default pin assignments will be used on those platform that have multiple outputs.

Parameters
portnumThe UART to open. First port is 0. The maximum number is platform dependent
baudrateThe speed of the serial port in bits per second
stop_bitsThe number of stop bits, 1 or 2
data_bitsThe number of data bits sent per character or frame: 5, 6, 7 or 8
parityThe type of parity checking to use: eParityNone, eParityEven, eParityOdd or eParityMulti
Returns
The file descriptor of the serial port ( > 0), or Serial Port Error Codes
See also
SimpleOpenSerial()

◆ SendBreak()

void SendBreak ( int port,
uint32_t time )

#include <serial.h>

Sets a break in the UART transmission for a given period of time. The break starts when character transmission completes. The break is delayed until any character in the transmitter shift register is sent. Any character in the transmitter holding register is sent after the break.

Note: This feature may not be supported on all UART modules. Please refer to the processor's datasheet for details on supported features.

port - The UART whose transmitter will be forced low (start break). time - Specifies the amount of time in ticks that the break will hold; when time expires, the break will be stopped; 20 ticks equal 1 second by default.

return - Nothing to return.

◆ Serial485HalfDupMode()

void Serial485HalfDupMode ( int port,
int enab )

#include <serial.h>

Enables or disables RS-485 half-duplex mode. Full-duplex mode is automatically enabled when half-duplex mode is disabled. This must be explicitly called before RS-485 functionality can be used. Jumpers may also be needed depending on the hardware device and/or development board used.

port - The UART port to use; the UART that can only be used for RS-485 depends on the platform (e.g., MOD52xx mounted on the MOD-DEV-100 development board use only UART 0 for RS-485, CB34-EX use only UART 1 for RS-485). enab - '0' disables half-duplex (enables full-duplex); '1' enables half- duplex (disables full-duplex)

return - Nothing to return.

◆ SerialClose()

int SerialClose ( int portnum)

#include <serial.h>

Close a serial port.

Parameters
portnumThe UART to close. First port is 0. The maximum number is platform dependent
Returns
0 if successful, otherwise Serial Port Error Codes
See also
OpenSerial()

◆ SerialEnableHwRxFlow()

void SerialEnableHwRxFlow ( int port,
int enab )

#include <serial.h>

Enables or disables request-to-send hardware flow control on receive (RxRTS). When enabled, receive throttles the transmitter on the other end. Jumpers may also be needed to enable the RxRTS line depending on the device and/or development board used.

(NB Device) Rx <–<–< Tx (Other Device) (NB Device) RxRTS >-->--> TxCTS (Other Device)

port - The UART whose flow control will be toggled. enab - '0' disables flow control; '1' (or any non-zero number) will enable it.

return - Nothing to return.

◆ SerialEnableHwTxFlow()

void SerialEnableHwTxFlow ( int port,
int enab )

#include <serial.h>

Enables or disables clear-to-send hardware flow control on transmit (TxCTS). When enabled, transmit is throttled by the receiver on the other end. Jumpers may also be needed to enable the TxCTS line depending on the device and/or development board used.

(NB Device) Tx >-->--> Rx (Other Device) (NB Device) TxCTS <–<–< RxRTS (Other Device)

Note: Calling this function to disable Tx hardware flow control after enabling RS-485 full-duplex mode configures for RS-422 mode (Tx stays actively driven).

port - The UART whose flow control will be toggled. enab - '0' disables flow control; '1' (or any non-zero number) will enable it.

return - Nothing to return.

◆ SerialEnableRxFlow()

void SerialEnableRxFlow ( int port,
int enab )

#include <serial.h>

Enables or disables software flow control (XON/XOFF) on receive. When enabled, the NetBurner device will send special XON and XOFF characters to another device in order to control the flow of incoming data.

port - The UART whose flow control will be toggled. enab - '0' disables flow control; '1' (or any non-zero number) will enable it.

return - Nothing to return.

◆ SerialEnableTxFlow()

void SerialEnableTxFlow ( int port,
int enab )

#include <serial.h>

Enable transmit software flow control on the specified UART.

Enables or disables software flow control (XON/XOFF) on transmit. When enabled, the NetBurner device will recognize the special XON and XOFF characters being sent from another device in order to throttle the output.

Parameters
portUART number
enab0 disables flow control, 1 enables flow control

◆ SerialExpandRxBuffer()

void SerialExpandRxBuffer ( int fd,
int nb )

#include <serial.h>

Expand the received serial buffer.

This function expands the number of buffer descriptors the specific serial port is allowed to use. Each buffer descriptor counts for 1500 bytes fo setting this to 10 would make the serial Rx buffer 15000 bytes.

◆ SerialSendComplete()

BOOL SerialSendComplete ( int fd)

#include <serial.h>

Determines if data waiting in transmitter holding/shift registers are already sent out.

return - True if finished, false if data still sending

◆ serwriteaddress()

int serwriteaddress ( int fd,
const char c )

#include <serial.h>

Sends an address character via the UART port number associated with the given file descriptor. This function can only be utilized if the UART is initialized in multidrop mode.

fd - The file descriptor associated with the UART serial port that will be used. c - The address character to be sent.

return - '1' if successful; otherwise, one of the error codes is returned (note that SERIAL_ERR_PORT_NOTOPEN is also returned if UART is not initialized to be in multidrop mode): SERIAL_ERR_NOSUCH_PORT (-1) SERIAL_ERR_PORT_NOTOPEN (-2)

◆ SetRTS()

void SetRTS ( int port,
bool val )

#include <serial.h>

Sets or clears the Request To Send signal for the specified serial port.

port - The UART port whose RTS signal will be set or cleared. (0 or 1) val - The Boolean value to configure the signal; TRUE sets it, while FALSE clears it.

return - Nothing to return.