4 * This file is part of BeRTOS.
6 * Bertos is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * As a special exception, you may use this file as part of a free software
21 * library without restriction. Specifically, if other files instantiate
22 * templates or use macros or inline functions from this file, or you compile
23 * this file and link it with other files to produce an executable, this
24 * file does not by itself cause the resulting executable to be covered by
25 * the GNU General Public License. This exception does not however
26 * invalidate any other reasons why the executable file might be covered by
27 * the GNU General Public License.
29 * Copyright 2007 Develer S.r.l. (http://www.develer.com/)
33 * \brief Function library for Accessing FT245RL USB interface.
35 * This module handles USB communication with FT245RL chip.
36 * This chip is a parallel USB interface with data flow control.
37 * A kfile-like interface is supplied.
40 * \author Francesco Sacchi <batt@develer.com>
43 #include "hw/hw_ft245rl.h"
46 #include <cfg/macros.h>
47 #include <cfg/debug.h>
48 #include <cfg/module.h>
49 #include <drv/timer.h>
50 #include <kern/kfile.h>
58 * Read \a size bytes in buffer \a buf, from fid \a _fd.
60 static size_t ft245rl_read(struct KFile *_fd, void *_buf, size_t size)
62 Ft245rl *fd = FT245RL_CAST(_fd);
64 uint8_t *buf = (uint8_t *)_buf;
65 size_t total_read = 0;
69 while(!FT245RL_DATA_RDY())
72 *buf++ = FT245RL_GETDATA();
80 * Write \a size bytes from buffer \a buf, of fid \a _fd.
82 static size_t ft245rl_write(struct KFile *_fd, const void *_buf, size_t size)
84 Ft245rl *fd = FT245RL_CAST(_fd);
86 const uint8_t *buf = (const uint8_t *)_buf;
87 size_t total_write = 0;
91 while(!FT245RL_TX_ALLOWED())
94 FT245RL_SETDATA(*buf++);
102 * Ft245rl init function.
104 void ft245rl_init(Ft245rl *fd)
106 memset(fd, 0, sizeof(*fd));
107 DB(fd->fd._type = KFT_FT245RL);
109 // Setup data ft245rl communication functions.
110 fd->fd.read = ft245rl_read;
111 fd->fd.write = ft245rl_write;
114 while (FT245RL_DATA_RDY())