ft245rl.c

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