forked from djmuhlestein/fx2lib
-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Timer based UART for sending and receiving bytes on the FX2 #23
Open
RacingTornado
wants to merge
1
commit into
mithro:linux-descriptors
Choose a base branch
from
RacingTornado:merge_timer_uart_8
base: linux-descriptors
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,15 @@ | ||
#!/bin/bash -e | ||
|
||
DEVS=$(lsusb|grep -E '(2a19|16c0|04b4|1d50|fb9a|1443)' |sed 's/:.*//;s/Bus //;s/Device //;s/ /\//') | ||
|
||
if [ -z "$1" ]; then | ||
echo "$0: usage: $0 <file>" | ||
exit 1; | ||
fi | ||
|
||
for dev in $DEVS;do | ||
echo "Downloading $1 to $dev" | ||
/sbin/fxload -D /dev/bus/usb/$dev -t fx2lp -I $1 | ||
done | ||
|
||
exit 0 |
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,8 @@ | ||
FX2LIBDIR=../.. | ||
BASENAME = uart_timer | ||
SOURCES=uart_timer.c | ||
DSCR_AREA= | ||
INT2JT= | ||
include $(FX2LIBDIR)/lib/fx2.mk | ||
fx2_download: | ||
../download.sh build/$(BASENAME).ihx |
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,61 @@ | ||
/** | ||
* Copyright (C) 2009 Ubixum, Inc. | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
**/ | ||
#include <fx2regs.h> | ||
#include <stdio.h> | ||
#include <fx2ints.h> | ||
#include <uart/api.h> | ||
#include <uart/timer_uart.h> | ||
#include <fx2macros.h> | ||
|
||
//Used for setting the baud rate. | ||
//Currently unimplemented | ||
enum uart_baud baud; | ||
//Extern declaration. | ||
extern void process_isr(); | ||
void main(void) | ||
{ | ||
baud = BAUD_9600; | ||
uartX_init(baud); | ||
printf("Hello"); | ||
while (TRUE) | ||
{ | ||
uart_rx_service(); | ||
uart_tx_service(); | ||
|
||
} | ||
} | ||
|
||
void putchar(char c) | ||
{ | ||
uartX_tx(c); | ||
} | ||
|
||
|
||
/** | ||
* \brief This function is actually an ISR | ||
* It is called periodically to check if data is ready to be transmitted | ||
* The receive logic looks at the rx pin, sampling it continously. The moment | ||
* a start bit is detected, it begins shifting the data in | ||
* and finally sets a flag stating the receive is complete. This flag is reset | ||
* in the uart_rx_service. This helps achieve non blocking behaviour. | ||
**/ | ||
void timer1_isr () | ||
__interrupt TF1_ISR | ||
{ | ||
process_isr(); | ||
} |
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,79 @@ | ||
/** \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" | ||
|
||
/** | ||
* enum Standard available baud rates | ||
* | ||
**/ | ||
enum uart_baud { BAUD_2400, BAUD_4800, BAUD_9600, BAUD_19200, BAUD_38400, BAUD_57600, BAUD_115200, BAUD_ANY, BAUD_FASTEST }; | ||
|
||
/** | ||
* \brief initalizes UART. | ||
* Returns 0 if initialization is successful. | ||
* \param rate See uartX_set_baud() | ||
**/ | ||
BOOL uartX_init(enum uart_baud rate, ...); | ||
|
||
/** | ||
* \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 0 if successful. | ||
**/ | ||
BOOL uartX_set_baud(enum uart_baud rate); | ||
|
||
/** | ||
* \brief Returns the baud rate currently being used. | ||
**/ | ||
enum 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 transmit is blocking or not | ||
* TRUE - Blocking | ||
* FALSE -Non Blocking | ||
**/ | ||
|
||
BOOL uartX_tx_willblock(); | ||
|
||
/** | ||
* \brief receives data through UART. | ||
* Returns one byte at a time from the queue | ||
* | ||
**/ | ||
char uartX_rx(); | ||
|
||
/** | ||
* \brief Returns if the receive is blocking or not | ||
* 0 - Non Blocking | ||
* 1 - Blocking | ||
**/ | ||
BOOL uartX_check_rx_blocking(); | ||
|
||
/** | ||
* \brief Returns count number of bytes present in the buffer | ||
* | ||
**/ | ||
BYTE uartX_check_receive_buffer(); | ||
|
||
#endif |
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,43 @@ | ||
#ifndef TIMER_UART_H | ||
#define TIMER_UART_H | ||
#include "fx2regs.h" | ||
#include "fx2types.h" | ||
|
||
/** | ||
* Enum for controlling transmitter state | ||
* Only 2 states in the enum, it is either | ||
* in IDLE or BUSY | ||
**/ | ||
enum uart_tx_state{IDLE, BUSY}; | ||
|
||
/** | ||
* Enum for controlling receiver state | ||
* Only 4 states in the enum | ||
* 0x00 - IDLE | ||
* 0x01 - Data Reception complete | ||
* 0x02 - Start bit detect | ||
* 0x03 - Data currently being read | ||
**/ | ||
enum uart_rx_state{IDLE_RX,DATA_COMPLETE,START_DETECT,BUSY_RX}; | ||
|
||
void timer_init(); | ||
void softuart_init( void ); | ||
void uart_tx_service(); | ||
void uart_rx_service(); | ||
void QueueInitTX(void); | ||
__bit QueuePutTX(unsigned char data); | ||
__bit QueueGetTX(unsigned char *old); | ||
__bit QueueCheckTX(); | ||
void QueueInitRX(void); | ||
__bit QueuePutRX(unsigned char data); | ||
__bit QueueGetRX(unsigned char * old); | ||
__bit QueueCheckRX(); | ||
void process_isr(); | ||
extern unsigned char volatile tx_buffer; | ||
extern unsigned char volatile rx_buffer; | ||
extern unsigned char volatile tx_count; | ||
extern unsigned char volatile rx_count; | ||
extern unsigned char volatile tx_bits_sent; | ||
extern unsigned char volatile rx_bits_rcvd; | ||
extern unsigned char volatile rx_busy; | ||
#endif |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
process_isr? That isn't a good name for something...