BeRTOS
|
00001 00042 #include "hw/hw_ft245rl.h" 00043 #include "ft245rl.h" 00044 00045 #include <cfg/macros.h> 00046 #include <cfg/debug.h> 00047 #include <cfg/module.h> 00048 00049 #include <drv/timer.h> 00050 00051 #include <io/kfile.h> 00052 00053 #include <string.h> 00054 00055 00056 MOD_DEFINE(ft245rl); 00057 00061 static size_t ft245rl_read(struct KFile *_fd, void *_buf, size_t size) 00062 { 00063 Ft245rl *fd = FT245RL_CAST(_fd); 00064 (void)fd; //unused 00065 uint8_t *buf = (uint8_t *)_buf; 00066 size_t total_read = 0; 00067 00068 while (size--) 00069 { 00070 while(!FT245RL_DATA_RDY()) 00071 /* busy waiy */; 00072 00073 *buf++ = FT245RL_GETDATA(); 00074 total_read++; 00075 } 00076 00077 return total_read; 00078 } 00079 00083 static size_t ft245rl_write(struct KFile *_fd, const void *_buf, size_t size) 00084 { 00085 Ft245rl *fd = FT245RL_CAST(_fd); 00086 (void)fd; //unused 00087 const uint8_t *buf = (const uint8_t *)_buf; 00088 size_t total_write = 0; 00089 00090 while (size--) 00091 { 00092 while(!FT245RL_TX_ALLOWED()) 00093 /* busy waiy */; 00094 00095 FT245RL_SETDATA(*buf++); 00096 total_write++; 00097 } 00098 00099 return total_write; 00100 } 00101 00105 void ft245rl_init(Ft245rl *fd) 00106 { 00107 memset(fd, 0, sizeof(*fd)); 00108 DB(fd->fd._type = KFT_FT245RL); 00109 00110 // Setup data ft245rl communication functions. 00111 fd->fd.read = ft245rl_read; 00112 fd->fd.write = ft245rl_write; 00113 00114 FT245RL_INIT(); 00115 while (FT245RL_DATA_RDY()) 00116 FT245RL_GETDATA(); 00117 00118 MOD_INIT(ft245rl); 00119 }