Main Page | Modules | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

ft245_mem.c

00001 /*! \file ft245.c \brief FTDI FT245 USB Inferface Driver Library. */
00002 //*****************************************************************************
00003 //
00004 // File Name    : 'ft245.c'
00005 // Title        : FTDI FT245 USB Inferface Driver Library
00006 // Author       : Pascal Stang - Copyright (C) 2004
00007 // Created      : 2004.02.10
00008 // Revised      : 2004.02.19
00009 // Version      : 0.1
00010 // Target MCU   : Atmel AVR Series
00011 // Editor Tabs  : 4
00012 //
00013 // NOTE: This code is currently below version 1.0, and therefore is considered
00014 // to be lacking in some functionality or documentation, or may not be fully
00015 // tested.  Nonetheless, you can expect most functions to work.
00016 //
00017 // This code is distributed under the GNU Public License
00018 //      which can be found at http://www.gnu.org/licenses/gpl.txt
00019 //
00020 //*****************************************************************************
00021 
00022 #include "lpc2000.h"
00023 //#include <avr/io.h>
00024 //#include <avr/signal.h>
00025 //#include <avr/interrupt.h>
00026 
00027 #include "global.h"
00028 #include "timer.h"
00029 #include "ft245.h"
00030 
00031 #include "mem.h"
00032 
00033 #define FT245_REG_CTRL      (*((volatile u08*)(MEMBANK0+0x006)))
00034 #define FT245_REG_DATA      (*((volatile u08*)(MEMBANK0+0x008)))
00035 #define FT245_REG_CTRL_RXF  1
00036 #define FT245_REG_CTRL_TXE  2
00037 
00038 // global variables
00039 static char ft245RxData[FT245_RX_BUFFER_SIZE];
00040 cBuffer ft245RxBuffer;
00041 
00042 // Functions
00043 void ft245Init(void)
00044 {
00045     // initialize the RX buffer
00046     bufferInit(&ft245RxBuffer, ft245RxData, FT245_RX_BUFFER_SIZE);
00047 
00048     // reset the FT245
00049     //ft245Reset();
00050 }
00051 
00052 u08 ft245ReadByte(void)
00053 {
00054     return FT245_REG_DATA;
00055 }
00056 
00057 void ft245WriteByte(u08 data)
00058 {
00059     FT245_REG_DATA = data;
00060 }
00061 
00062 u08 ft245CheckRxFifo(void)
00063 {
00064     // check state of RXF line
00065     // RXF = L  => Data in fifo ready to be read
00066     // RXF = H  => No data, or not ready
00067     if(FT245_REG_CTRL & FT245_REG_CTRL_RXF)
00068         return FALSE;   // no data
00069     else
00070         return TRUE;    // data is available
00071 }
00072 
00073 u08 ft245CheckTxFifo(void)
00074 {
00075     // check state of TXE line
00076     // TXE = L  => Tx fifo is ready to be written
00077     // TXE = H  => Tx fifo full or not ready
00078     if(FT245_REG_CTRL & FT245_REG_CTRL_TXE)
00079         return FALSE;   // full or not ready
00080     else
00081         return TRUE;    // tx fifo space is available
00082 }
00083 
00084 void ft245SendByte(u08 data)
00085 {
00086     // wait for FT245 to become ready
00087     while(!ft245CheckTxFifo());
00088     // send byte
00089     ft245WriteByte(data);
00090 }
00091 
00092 cBuffer* ft245GetRxBuffer(void)
00093 {
00094     // since there is an internal buffer in the FT245 chip
00095     // we don't read in bytes immediately on reception.
00096     // instead, the FT245 buffer is read in when the 
00097     // receive buffer is requested
00098 
00099     // read in receive buffer
00100     while(ft245CheckRxFifo())
00101     {
00102         bufferAddToEnd(&ft245RxBuffer, ft245ReadByte());
00103     }
00104 
00105     return &ft245RxBuffer;
00106 }

Generated on Mon Nov 6 23:36:59 2006 for Procyon ARMlib by  doxygen 1.4.2