PropWare
3.0.0.229
C++ objects and CMake build system for Parallax Propeller
|
#include <libpropeller/libpropeller/mtk3339/serial.h>
Public Member Functions | |
bool | Start (const int rxpin, const int txpin, const int rate, const int ctspin=-1) |
void | Stop (void) |
bool | SetBaud (const int rate) |
bool | SetBaudClock (const unsigned int rate, const unsigned int sysclock) |
void | Put (const char character) |
int | Put (const char *buffer_ptr, const int count) |
int | Put (const char *buffer_ptr) |
int | Get (const int timeout=-1) |
int | Get (char *const buffer, const int length, const int timeout=-1) |
int | Get (char *const buffer, const char terminator='\n') |
void | GetFlush (void) |
int | GetCount (void) const |
int | PutFormatted (const char *formatString,...) |
bool | Start (const int rxpin, const int txpin, const int rate, const int ctspin=-1) |
void | Stop (void) |
bool | SetBaud (const int rate) |
bool | SetBaudClock (const unsigned int rate, const unsigned int sysclock) |
void | Put (const char character) |
int | Put (const char *buffer_ptr, const int count) |
int | Put (const char *buffer_ptr) |
int | Get (const int timeout=-1) |
int | Get (char *const buffer, const int length, const int timeout=-1) |
int | Get (char *const buffer, const char terminator='\n') |
void | GetFlush (void) |
int | GetCount (void) const |
int | PutFormatted (const char *formatString,...) |
Static Public Attributes | |
static const int | kBufferLength = 512 |
A high speed and high accuracy serial driver. Based on Fast Full-Duplex Serial 1 (FFDS1) version 0.9 by Jonathan Dummer (lonesock). C++ Port done by SRLM.
Serial provides a fast and stable serial interface using a single cog.
Max baudrate = clkfreq / (86 * 2)
Clock | MaxBaud | Standard ----—+------—+------— 96 MHz | 558_139 | 500_000 - 6MHz XTAL at 16x PLL 80 MHz | 465_116 | 460_800 - 5MHz XTAL at 16x PLL (most common) 12 MHz | 69_767 | 57_600 - approx RCFAST 20 kHz | 116 | hah hah - approx RCSLOW
Bit period is calculated to the nearest 2 clocks. So, the bit period should be within 1 clock, or 12.5 ns at 80 MHz.
Get a terminated string of characters
buffer | The buffer to store the received characters in. Note: an extra '\0' is always added to the end (null terminate). |
terminator | The last character to put into the buffer. On the first instance of this character, the function returns. |
Definition at line 284 of file serial.h.
Get a terminated string of characters
buffer | The buffer to store the received characters in. Note: an extra '\0' is always added to the end (null terminate). |
terminator | The last character to put into the buffer. On the first instance of this character, the function returns. |
Definition at line 284 of file serial.h.
int libpropeller::Serial::Get | ( | char *const | buffer, |
const int | length, | ||
const int | timeout = -1 |
||
) |
Get a buffer of characters
buffer | The buffer to store the received characters in. |
length | The maximum number of characters to read (may be less than length if timeout is enabled. |
timeout | The maximum amount of time to wait for each character, not the total time of the function. |
Definition at line 261 of file serial.h.
int libpropeller::Serial::Get | ( | char *const | buffer, |
const int | length, | ||
const int | timeout = -1 |
||
) |
Get a buffer of characters
buffer | The buffer to store the received characters in. |
length | The maximum number of characters to read (may be less than length if timeout is enabled. |
timeout | The maximum amount of time to wait for each character, not the total time of the function. |
Definition at line 261 of file serial.h.
int libpropeller::Serial::Get | ( | const int | timeout = -1 | ) |
Receive a byte (wait) or timeout.
The timeout duration is a minimum, not a precise number. Experimental results indicate that a timeout of 10ms results in a total function time of 10.047ms.
timeout | the number of milliseconds to wait. Defaults to forever wait (negative timeout). Maximum value is 53000 milliseconds (no bounds checking). |
Definition at line 226 of file serial.h.
int libpropeller::Serial::Get | ( | const int | timeout = -1 | ) |
Receive a byte (wait) or timeout.
The timeout duration is a minimum, not a precise number. Experimental results indicate that a timeout of 10ms results in a total function time of 10.047ms.
timeout | the number of milliseconds to wait. Defaults to forever wait (negative timeout). Maximum value is 53000 milliseconds (no bounds checking). |
Definition at line 226 of file serial.h.
int libpropeller::Serial::GetCount | ( | void | ) | const |
int libpropeller::Serial::GetCount | ( | void | ) | const |
void libpropeller::Serial::GetFlush | ( | void | ) |
void libpropeller::Serial::GetFlush | ( | void | ) |
int libpropeller::Serial::Put | ( | const char * | buffer_ptr | ) |
Transmit a C string.
buffer_ptr | The null terminated string to put. Note: does not transmit the trailing null. |
Definition at line 206 of file serial.h.
int libpropeller::Serial::Put | ( | const char * | buffer_ptr | ) |
Transmit a C string.
buffer_ptr | The null terminated string to put. Note: does not transmit the trailing null. |
Definition at line 206 of file serial.h.
int libpropeller::Serial::Put | ( | const char * | buffer_ptr, |
const int | count | ||
) |
int libpropeller::Serial::Put | ( | const char * | buffer_ptr, |
const int | count | ||
) |
void libpropeller::Serial::Put | ( | const char | character | ) |
void libpropeller::Serial::Put | ( | const char | character | ) |
bool libpropeller::Serial::SetBaud | ( | const int | rate | ) |
bool libpropeller::Serial::SetBaud | ( | const int | rate | ) |
bool libpropeller::Serial::SetBaudClock | ( | const unsigned int | rate, |
const unsigned int | sysclock | ||
) |
Does a live update of the baud rate in the Serial engine.
Examples: got_desired_rate = SetBaudClock( 9600, CLKFREQ ) got_desired_rate = SetBaudClock( 9600, actual_sys_clock_freq )
rate | desired baud rate of the Serial engine. |
sysclock | the system clock (use CLKFREQ), or provide your own (useful when using RCFAST). |
Definition at line 161 of file serial.h.
bool libpropeller::Serial::SetBaudClock | ( | const unsigned int | rate, |
const unsigned int | sysclock | ||
) |
Does a live update of the baud rate in the Serial engine.
Examples: got_desired_rate = SetBaudClock( 9600, CLKFREQ ) got_desired_rate = SetBaudClock( 9600, actual_sys_clock_freq )
rate | desired baud rate of the Serial engine. |
sysclock | the system clock (use CLKFREQ), or provide your own (useful when using RCFAST). |
bool libpropeller::Serial::Start | ( | const int | rxpin, |
const int | txpin, | ||
const int | rate, | ||
const int | ctspin = -1 |
||
) |
Start Serial driver in a new cog.
Set any pin to -1 to disable it. No pin can match any other pin.
rxpin | the pin [0..31] for incoming data. |
txpin | the pin [0..31] for outgoing data. |
rate | the initial baud rate in bits per second. |
ctspin | cts is an input for control of flow from the tx pin. If high, it disables transmissions. |
bool libpropeller::Serial::Start | ( | const int | rxpin, |
const int | txpin, | ||
const int | rate, | ||
const int | ctspin = -1 |
||
) |
Start Serial driver in a new cog.
Set any pin to -1 to disable it. No pin can match any other pin.
rxpin | the pin [0..31] for incoming data. |
txpin | the pin [0..31] for outgoing data. |
rate | the initial baud rate in bits per second. |
ctspin | cts is an input for control of flow from the tx pin. If high, it disables transmissions. |
Definition at line 64 of file serial.h.
void libpropeller::Serial::Stop | ( | void | ) |
void libpropeller::Serial::Stop | ( | void | ) |
|
static |
Size of the RX buffer in bytes. No restrictions on size (well, Hub RAM limits [8^) Does not need to be a power of 2. There is no TX buffer, Serial sends directly from Hub RAM.
For some reason, 117 seems to be the minimum buffer size before the tests start to lock up. Originally, it was 512. Seems safe to change, as long as it's >= 117.