PropWare  3.0.0.229
C++ objects and CMake build system for Parallax Propeller
Classes | Macros | Typedefs | Functions
fdserial.h File Reference

This library supports creating and managing one or more full duplex serial connections with peripheral devices. The pointer returned when a connection is opened can be used to identify the connection for other calls with fdserial parameter types in this library. The identifier can also be used to identify the serial connection for higher level formatted text transmit/receive functions with text_t parameter types in the simpletext library.
More...

#include "simpletext.h"
+ Include dependency graph for fdserial.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  fdserial_struct
 Defines fdserial interface structure of 9 contiguous longs + buffers. More...
 

Macros

#define FDSERIAL_BUFF_MASK   0x3f
 
#define FDSERIAL_MODE_NONE   0
 
#define FDSERIAL_MODE_INVERT_RX   1
 
#define FDSERIAL_MODE_INVERT_TX   2
 
#define FDSERIAL_MODE_OPENDRAIN_TX   4
 
#define FDSERIAL_MODE_IGNORE_TX_ECHO   8
 
#define FDSERIAL_MODE_RX_ONLY   16
 
#define FDSERIAL_MODE_ECHO_RX_TO_TX   32
 

Typedefs

typedef text_t fdserial
 Defines text_t data type as fdserial to allow declarations like fdserial *MyDevice. After storing the value returned by fdserial_start in MyDevice, it can be passed as an identifying parameter to fdserial and simpletext library functions that have fdserial or text_t parameter types.
 
typedef struct fdserial_struct fdserial_st
 Defines fdserial interface structure of 9 contiguous longs + buffers.
 

Functions

fdserialfdserial_open (int rxpin, int txpin, int mode, int baudrate)
 Open a full duplex serial connection. More...
 
void fdserial_close (fdserial *term)
 Stop stops the cog running the native assembly driver. More...
 
int fdserial_rxCheck (fdserial *term)
 Gets a byte from the receive buffer if available, but does not wait if there's nothing in the buffer. More...
 
void fdserial_rxFlush (fdserial *term)
 Empties the receive buffer. More...
 
int fdserial_rxReady (fdserial *term)
 Check if a byte is ready in the receive buffer. More...
 
int fdserial_rxTime (fdserial *term, int ms)
 Gets a byte from the receive buffer if available, or wait for up to timeout ms to receive a byte. More...
 
int fdserial_rxChar (fdserial *term)
 Get a byte from the receive buffer, or if it's emtpy, wait until a byte is received. More...
 
int fdserial_rxCount (fdserial *term)
 Get number of bytes available in the receive buffer without receiving any. NOTE: This function is not designed for detecting buffer overflow, just for reporting how many bytes have accumulated in the input buffer. More...
 
int fdserial_rxPeek (fdserial *term)
 Get a byte from the receive buffer without changing the pointers. The function does not block. More...
 
int fdserial_txChar (fdserial *term, int txbyte)
 Send a byte by adding it to the transmit buffer. More...
 
int fdserial_txEmpty (fdserial *term)
 Check if the transmit buffer is empty. More...
 
void fdserial_txFlush (fdserial *term)
 Remove any bytes that might be waiting in the transmit buffer.
 

Detailed Description

This library supports creating and managing one or more full duplex serial connections with peripheral devices. The pointer returned when a connection is opened can be used to identify the connection for other calls with fdserial parameter types in this library. The identifier can also be used to identify the serial connection for higher level formatted text transmit/receive functions with text_t parameter types in the simpletext library.

Author
Steve Denson, with naming conventions supplied by Parallax.
Core Usage
Each call to fdserial_open launches an additional cog that can support an additional UART communication process.
Memory Models
Use with CMM or LMM.
Version
0.88 Add Rx-only
0.86
Help Improve this Library
Please submit bug reports, suggestions, and improvements to this code to edito.nosp@m.r@pa.nosp@m.ralla.nosp@m.x.co.nosp@m.m.

Definition in file fdserial.h.


Class Documentation

◆ fdserial_struct

struct fdserial_struct

Defines fdserial interface structure of 9 contiguous longs + buffers.

Definition at line 97 of file fdserial.h.

+ Collaboration diagram for fdserial_struct:
Class Members
char * buffptr

pointer to rx buffer

int mode

interface mode

int rx_head

receive buffer head

int rx_pin

receive pin

int rx_tail

receive buffer tail

int ticks

clkfreq / baud

int tx_head

transmit buffer head

int tx_pin

transmit pin

int tx_tail

transmit buffer tail

Macro Definition Documentation

◆ FDSERIAL_BUFF_MASK

#define FDSERIAL_BUFF_MASK   0x3f

Defines buffer length. hard coded into asm driver ... s/b bigger

Definition at line 56 of file fdserial.h.

◆ FDSERIAL_MODE_ECHO_RX_TO_TX

#define FDSERIAL_MODE_ECHO_RX_TO_TX   32

Mode bit 5 can be set to 1 to locally echo characters.

Definition at line 92 of file fdserial.h.

◆ FDSERIAL_MODE_IGNORE_TX_ECHO

#define FDSERIAL_MODE_IGNORE_TX_ECHO   8

Mode bit 3 can be set to 1 to ignore copy of txpin's signal if received by rxpin.

Definition at line 82 of file fdserial.h.

◆ FDSERIAL_MODE_INVERT_RX

#define FDSERIAL_MODE_INVERT_RX   1

Mode bit 0 can be set to 1 for inverted signal to rxpin.

Definition at line 66 of file fdserial.h.

◆ FDSERIAL_MODE_INVERT_TX

#define FDSERIAL_MODE_INVERT_TX   2

Mode bit 1 can be set to 1 for inverted signal from txpin.

Definition at line 71 of file fdserial.h.

◆ FDSERIAL_MODE_NONE

#define FDSERIAL_MODE_NONE   0

All mode bits set to 0 for non-inverted asynchronous serial communication.

Definition at line 61 of file fdserial.h.

◆ FDSERIAL_MODE_OPENDRAIN_TX

#define FDSERIAL_MODE_OPENDRAIN_TX   4

Mode bit 2 can be set to 1 to open collector/drain txpin communication with a pull-up resistor on the line.

Definition at line 77 of file fdserial.h.

◆ FDSERIAL_MODE_RX_ONLY

#define FDSERIAL_MODE_RX_ONLY   16

Mode bit 4 can be set to 1 to only receive serial data but not transmit.

Definition at line 87 of file fdserial.h.

Function Documentation

◆ fdserial_close()

void fdserial_close ( fdserial term)

Stop stops the cog running the native assembly driver.

Parameters
*termDevice ID returned by fdserial_open.

Definition at line 115 of file fdserial.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fdserial_open()

fdserial* fdserial_open ( int  rxpin,
int  txpin,
int  mode,
int  baudrate 
)

Open a full duplex serial connection.

Parameters
rxpinSerial receive input pin number.
txpinSerial transmit output pin number.
modeSet/clear bits to define mode: mode bit 0 = invert rx mode bit 1 = invert tx mode bit 2 = open-drain/source tx mode bit 3 = ignore tx echo on rx
baudrateRate binary values are transmitted, like 115200, 57600,..., 9600 etc.
Returns
fdserial pointer for use as an identifier for fdserial and simpletext library functions that have fdserial or text_t parameter types.

Definition at line 20 of file fdserial.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fdserial_rxChar()

int fdserial_rxChar ( fdserial term)

Get a byte from the receive buffer, or if it's emtpy, wait until a byte is received.

Parameters
*termDevice ID returned by fdserial_open.

Oldest byte (0 to 255) in receive buffer

Definition at line 164 of file fdserial.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fdserial_rxCheck()

int fdserial_rxCheck ( fdserial term)

Gets a byte from the receive buffer if available, but does not wait if there's nothing in the buffer.

Parameters
*termDevice ID returned by fdserial_open.
Returns
Oldest byte (0 to 255) in receive buffer, or -1 if buffer is empty.

Definition at line 146 of file fdserial.c.

+ Here is the caller graph for this function:

◆ fdserial_rxCount()

int fdserial_rxCount ( fdserial term)

Get number of bytes available in the receive buffer without receiving any. NOTE: This function is not designed for detecting buffer overflow, just for reporting how many bytes have accumulated in the input buffer.

Parameters
*termDevice ID returned by fdserial_open.
Returns
Number of bytes available.

Definition at line 79 of file fdserial_utils.c.

◆ fdserial_rxFlush()

void fdserial_rxFlush ( fdserial term)

Empties the receive buffer.

Parameters
*termDevice ID returned by fdserial_open.

Definition at line 14 of file fdserial_utils.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fdserial_rxPeek()

int fdserial_rxPeek ( fdserial term)

Get a byte from the receive buffer without changing the pointers. The function does not block.

Returns
non-zero if a valid byte is available.

Definition at line 61 of file fdserial_utils.c.

◆ fdserial_rxReady()

int fdserial_rxReady ( fdserial term)

Check if a byte is ready in the receive buffer.

Parameters
*termDevice ID returned by fdserial_open.
Returns
Non-zero if one or more bytes are waiting in the receive buffer, or 0 if it's empty.

Definition at line 25 of file fdserial_utils.c.

◆ fdserial_rxTime()

int fdserial_rxTime ( fdserial term,
int  ms 
)

Gets a byte from the receive buffer if available, or wait for up to timeout ms to receive a byte.

Parameters
*termDevice ID returned by fdserial_open.
msis number of milliseconds to wait for a char
Returns
receive byte 0 to 0xff or -1 if none available

Definition at line 37 of file fdserial_utils.c.

+ Here is the call graph for this function:

◆ fdserial_txChar()

int fdserial_txChar ( fdserial term,
int  txbyte 
)

Send a byte by adding it to the transmit buffer.

Parameters
*termDevice ID returned by fdserial_open.
txbyteis byte to send.
Returns
The byte that was sent, or returns the byte that was received if mode bit 3 was set in the fdserial_open call.

Definition at line 176 of file fdserial.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fdserial_txEmpty()

int fdserial_txEmpty ( fdserial term)

Check if the transmit buffer is empty.

Parameters
*termDevice ID returned by fdserial_open.
Returns
non-zero if transmit buffer is empty.

Definition at line 135 of file fdserial.c.

+ Here is the caller graph for this function: