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
2 changed files
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 |
---|---|---|
|
@@ -16,3 +16,4 @@ | |
docs/html | ||
build | ||
*_str.c | ||
*~ |
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,86 @@ | ||
/** \file softuart.h | ||
* Utilities for reading and writing to UART devices. | ||
* Defines top level functions which the printf and scanf access. | ||
* The implementation of these functions vary depending on whether | ||
* fast_uart is being used or timer based UART is being used. This | ||
* is configurable depending on the way uart0_init() is called | ||
**/ | ||
|
||
#ifndef FX2_UART | ||
#define FX2_UART | ||
|
||
#include "fx2types.h" | ||
|
||
/** | ||
* \brief initalizes UART. | ||
* This function uart0_init accepts the baud_rate and the mask. The mask | ||
* indicates where the UART_TX pin must be attached. The rx_mask performs a | ||
* similar function. The function will then use a case statement to identify | ||
* the correct location and then do a .equ TX_PIN to define the transmit pin. | ||
* Possible Baud rates:(fast_uart) | ||
* \li 2400 | ||
* \li 4800 | ||
* \li 9600 | ||
* \li 19200 | ||
* \li 28800 | ||
* \li 38400 | ||
* \li 57600 | ||
* \li 115200 | ||
* This function sets the CPUCS to 48Mhz . It then uses assembly to | ||
* delay the pin timing to get the required baud rate with the necessary | ||
* accuracy or initializes and starts a timer depending on the situation. | ||
* This function will map to a timer based delay function | ||
* in case of a the timer based uart. The only restriction is that this | ||
* function will not be able to have a baud rate of a value greater | ||
* than 9600 , if an ISR is used to shift the data out. This is because | ||
* the UART RX logic should run much faster than the TX logic to | ||
* detect the start bit. A decision to have the same UART TX/RX rates | ||
* was chosen. Thus the allowable baud rates for this function is | ||
* 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 mask_tx The pin to which the UART_TX routine must be attached | ||
* \param mask_rx The pin to which the UART_RX routine must be attached | ||
**/ | ||
void uart0_init (enum uart_baud rate, enum uart_type type, unsigned char mask_tx, unsigned char mask_rx) __critical; | ||
|
||
/** | ||
* \brief transmits data through UART. | ||
* The uart0_transmit maps to different functions depending on the underlying | ||
* mechanism which is used to transmit the byte. In the case of bitbanging UART | ||
* without timers, it becomes blocking. If timer based UART is used, then | ||
* it is non blocking. 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 | ||
**/ | ||
void uart0_transmit (char c); | ||
|
||
/** | ||
* \brief receives data through UART. | ||
* This function uart0_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 uart0_receive (); | ||
|
||
/** | ||
* 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 }; | ||
/** | ||
* Defines the type of UART which is used to send out the bits. If FAST_UART is used , high baud | ||
* rates can be achieved. However, only transmit functionality will be supported, and the function | ||
* call will block. TIMER_UART on the other hand uses a Queue(based on buffers) and does not block. | ||
* It allows both transmit and receive functionality , however the baud rates supported are much slower. | ||
* | ||
**/ | ||
enum uart_type { FAST_UART , TIMER_UART }; | ||
|
||
#endif |