00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "lpc2000.h"
00023
00024
00025
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
00039 static char ft245RxData[FT245_RX_BUFFER_SIZE];
00040 cBuffer ft245RxBuffer;
00041
00042
00043 void ft245Init(void)
00044 {
00045
00046 bufferInit(&ft245RxBuffer, ft245RxData, FT245_RX_BUFFER_SIZE);
00047
00048
00049
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
00065
00066
00067 if(FT245_REG_CTRL & FT245_REG_CTRL_RXF)
00068 return FALSE;
00069 else
00070 return TRUE;
00071 }
00072
00073 u08 ft245CheckTxFifo(void)
00074 {
00075
00076
00077
00078 if(FT245_REG_CTRL & FT245_REG_CTRL_TXE)
00079 return FALSE;
00080 else
00081 return TRUE;
00082 }
00083
00084 void ft245SendByte(u08 data)
00085 {
00086
00087 while(!ft245CheckTxFifo());
00088
00089 ft245WriteByte(data);
00090 }
00091
00092 cBuffer* ft245GetRxBuffer(void)
00093 {
00094
00095
00096
00097
00098
00099
00100 while(ft245CheckRxFifo())
00101 {
00102 bufferAddToEnd(&ft245RxBuffer, ft245ReadByte());
00103 }
00104
00105 return &ft245RxBuffer;
00106 }