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.
39 * \author Francesco Sacchi <batt@develer.com>
42 #include "hw/hw_ft245rl.h"
45 #include <cfg/macros.h>
46 #include <cfg/debug.h>
47 #include <cfg/module.h>
49 #include <drv/timer.h>
59 * Read \a size bytes in buffer \a buf, from fid \a _fd.
61 static size_t ft245rl_read(struct KFile *_fd, void *_buf, size_t size)
63 Ft245rl *fd = FT245RL_CAST(_fd);
65 uint8_t *buf = (uint8_t *)_buf;
66 size_t total_read = 0;
70 while(!FT245RL_DATA_RDY())
73 *buf++ = FT245RL_GETDATA();
81 * Write \a size bytes from buffer \a buf, of fid \a _fd.
83 static size_t ft245rl_write(struct KFile *_fd, const void *_buf, size_t size)
85 Ft245rl *fd = FT245RL_CAST(_fd);
87 const uint8_t *buf = (const uint8_t *)_buf;
88 size_t total_write = 0;
92 while(!FT245RL_TX_ALLOWED())
95 FT245RL_SETDATA(*buf++);
103 * Ft245rl init function.
105 void ft245rl_init(Ft245rl *fd)
107 memset(fd, 0, sizeof(*fd));
108 DB(fd->fd._type = KFT_FT245RL);
110 // Setup data ft245rl communication functions.
111 fd->fd.read = ft245rl_read;
112 fd->fd.write = ft245rl_write;
115 while (FT245RL_DATA_RDY())