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