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 printf() and scanf() functionality
- Loading branch information
Showing
1 changed file
with
87 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/** \file include/uart/api.h | ||
* This file is for defining a common API for accessing UARTs. | ||
* Defines top level functions which the printf and scanf access. | ||
**/ | ||
|
||
#ifndef FX2_UART | ||
#define FX2_UART | ||
|
||
#include "fx2types.h" | ||
|
||
/** | ||
* \brief initalizes UART. | ||
* This function uartX_init accepts the baud_rate and the mask.Returns 0 if successful. | ||
* The mask indicates where the UART_TX pin must be attached. The rx_mask performs a | ||
* similar function. If FAST_UART is used, only transmit is allowed. | ||
* Possible Baud rates:(fast_uart) | ||
* \li 2400 | ||
* \li 4800 | ||
* \li 9600 | ||
* \li 19200 | ||
* \li 28800 | ||
* \li 38400 | ||
* \li 57600 | ||
* \li 115200 | ||
* If TIMER_UART used then the allowed baud rates are | ||
* Possible Baud rates:(timer based uart) | ||
* \li 2400 | ||
* \li 4800 | ||
* \li 9600 | ||
* \param rate enum for baud_rate | ||
* \param type enum for selecting what type of UART is actually used | ||
* \param tx_pin The pin to which the UART_TX routine must be attached | ||
* \param rx_pin The pin to which the UART_RX routine must be attached | ||
**/ | ||
BOOL uartX_init (enum uart_baud rate, enum pins_fx2 tx_pin, enum pins_fx2 rx_pin) __critical; | ||
|
||
/** | ||
* \brief transmits data through UART , and blocks till complete. | ||
* uartX_transmit_blocking(char c) blocks until the character | ||
* has been transmitted out. | ||
**/ | ||
void uartX_transmit_blocking (char c); | ||
|
||
|
||
/** | ||
* \brief transmits data through UART without blocking. | ||
* Returns 0 is queue is not full , and data has been inserted. | ||
* It puts the data into the queue and returns without | ||
* doing anything else. The ISR then handles the shifting of the data out. | ||
* Be careful regarding queue overflows when using non-blocking UART, | ||
* that is make sure there is enough time between calls to printf. | ||
* \param c character to be written to UART | ||
**/ | ||
|
||
BOOL uartX_transmit_nonblocking (char c); | ||
|
||
/** | ||
* \brief receives data through UART. | ||
* This function uartX_receive is basically empty for fast_uart. However, in case of | ||
* timer based UART. It reads data from the queue, and returns a single character which | ||
* can then be used by the calling program. | ||
* | ||
**/ | ||
char uartX_receive (); | ||
|
||
/** | ||
* \brief Returns count number of bytes present in the buffer | ||
* | ||
**/ | ||
unsigned char uartX_check_receive_buffer (); | ||
|
||
/** | ||
* enum used for easy access for baud rate selection. | ||
* | ||
**/ | ||
enum uart_baud { U_2400, U_4800, U_9600, U_19200, U_38400, U_57600, U_115200 }; | ||
|
||
/** | ||
* enum used for easy access to fx2 pins | ||
* | ||
**/ | ||
enum pins_fx2 { PA_0,PA_1,PA_2,PA_3,PA_4,PA_5,PA_6,PA_7, | ||
PB_0,PB_1,PB_2,PB_3,PB_4,PB_5,PB_6,PB_7, | ||
PD_0,PD_1,PD_2,PD_3,PD_4,PD_5,PD_6,PD_7 | ||
}; | ||
|
||
#endif |