forked from djmuhlestein/fx2lib
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created a UART API definition in softuart.h to allow the example code…
… to access UART in a standard manner , irrespective of how it is implemented.
- Loading branch information
Showing
2 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/** \file include/uart/api.h | ||
* This file is for defining a common API for accessing UARTs. | ||
**/ | ||
|
||
#ifndef UART_API_H | ||
#define UART_API_H | ||
|
||
#include "fx2types.h" | ||
#include "stdarg.h" | ||
|
||
/** | ||
* \brief Initalizes UART. | ||
* Returns TRUE if initialization is successful. | ||
* \param Rate See uartX_set_baud(). | ||
**/ | ||
BOOL uartX_init(enum uart_baud rate, ...); | ||
|
||
/** | ||
* \brief enum Standard available baud rates. | ||
* All enum values less than 0 are not to be used unless absolutely necessary. | ||
* Enum values greater than 0 are supported. | ||
**/ | ||
typedef enum { | ||
BAUD_FASTEST = -2, ///< The fastest BAUD available on the system. | ||
BAUD_ANY = -1, ///< Virtual baud, Most efficient BAUD rate for the UART. | ||
BAUD_INVALID = 0, ///< A divider between actual baud rates and virtual baud rates. | ||
BAUD_2400 = 1, ///< Sets the baud rate to 2400. | ||
BAUD_4800 = 2, ///< Sets the baud rate to 4800. | ||
BAUD_9600 = 3, ///< Sets the baud rate to 9600. | ||
BAUD_19200 = 4, ///< Sets the baud rate to 19200. | ||
BAUD_38400 = 5, ///< Sets the baud rate to 38400. | ||
BAUD_57600 = 6, ///< Sets the baud rate to 57600. | ||
BAUD_115200 = 7 ///< Sets the baud rate to 115200. | ||
} uart_baud; | ||
|
||
/** | ||
* \brief Sets the UART baud rate to one of the allowed parameters. | ||
* Possible Baud rates: | ||
* \li 2400 | ||
* \li 4800 | ||
* \li 9600 | ||
* \li 19200 | ||
* \li 28800 | ||
* \li 38400 | ||
* \li 57600 | ||
* \li 115200 | ||
* Returns TRUE if successful. | ||
**/ | ||
BOOL uartX_set_baud(uart_baud rate); | ||
|
||
/** | ||
* \brief Returns the baud rate currently being used. | ||
**/ | ||
uart_baud uartX_get_baud(); | ||
|
||
/** | ||
* \brief Transmits data through UART. | ||
* \param c The character to be sent out. | ||
**/ | ||
|
||
void uartX_tx(char c); | ||
|
||
/** | ||
* \brief Returns if the next transmit call will block. | ||
* FALSE - Non Blocking. | ||
* TRUE - Blocking. | ||
**/ | ||
|
||
BOOL uartX_tx_will_block(); | ||
|
||
/** | ||
* \brief Returns how many more bytes can be loaded into the buffer. | ||
**/ | ||
BYTE uartX_tx_queue_len(); | ||
|
||
/** | ||
* \brief Receives data through UART. | ||
* Returns one byte at a time from the queue. | ||
**/ | ||
char uartX_rx(); | ||
|
||
/** | ||
* \brief Returns if the next receive call will block. | ||
* FALSE - Non Blocking. | ||
* TRUE - Blocking. | ||
**/ | ||
BOOL uartX_rx_will_block(); | ||
|
||
/** | ||
* \brief Returns count number of bytes present in the buffer. | ||
**/ | ||
BYTE uartX_rx_queue_len(); | ||
|
||
#endif |