[En-Nut-Discussion] Request for review: Simple FT245 device

Uwe Bonnes bon at elektron.ikp.physik.tu-darmstadt.de
Wed Apr 28 20:14:37 CEST 2010


Hello,

the FT245 and FT2232 may be used in a FIFO mode. When fully decoded, it only
needs one address on the bus and two pins. With ample FTxxx internal FIFO
buffer usage without ethernut internal buffers may be justified, like usage
without interrupts.

Appended patch is a modification of the null driver to use this FIFO mode. I
have done some rough tests on a demo board. Comments and inclusion
welcome.

Bye

-- 
Uwe Bonnes                bon at elektron.ikp.physik.tu-darmstadt.de

Institut fuer Kernphysik  Schlossgartenstrasse 9  64289 Darmstadt
--------- Tel. 06151 162516 -------- Fax. 06151 164321 ----------
Index: nut/conf/dev/dev.nut
===================================================================
--- nut/conf/dev/dev.nut	(Revision 2985)
+++ nut/conf/dev/dev.nut	(Arbeitskopie)
@@ -1842,6 +1842,50 @@
         sources = { "null.c" }
     },
     {
+        name = "nutdev_ft245",
+        brief = "FT245",
+        description = "Driver for memory mapped FT245.",
+        sources = { "ft245.c" },
+	options =
+	{
+	   {
+                macro = "FT245_FIFO",
+                brief = "Address of memory mapped FT245 FIF0",
+                description = "Address where to access the FT245 FIFO.\n\n"..
+                              "The FT2232test Board used A15=0",
+                file = "include/cfg/memory.h"
+            },
+	   {
+                macro = "FT245_TXE_PIN",
+                brief = "PORT where TXE is connected",
+                description = "Address where to access the FT245 FIFO.\n\n"..
+                              "The FT2232test Board used PortD7",
+                file = "include/cfg/memory.h"
+            },
+	   {
+                macro = "FT245_TXE_BIT",
+                brief = "BIT where TXE is connected",
+                description = "Address where to access the FT245 FIFO.\n\n"..
+                              "The FT2232test Board used PORTD7",
+                file = "include/cfg/memory.h"
+            },
+	   {
+                macro = "FT245_RXF_PIN",
+                brief = "PORT where RXF is connected",
+                description = "Address where to access the FT245 FIFO.\n\n"..
+                              "The FT2232test Board used PortD6",
+                file = "include/cfg/memory.h"
+            },
+	   {
+                macro = "FT245_RXF_BIT",
+                brief = "BIT where RXF is connected",
+                description = "Address where to access the FT245 FIFO.\n\n"..
+                              "The FT2232test Board used PORTD6",
+                file = "include/cfg/memory.h"
+            }
+	}	
+    },
+    {
         name = "nutdev_sc16is752",
         brief = "SC16IS752 Dual USART",
         description = "TWI driver for SC16IS752 dual USART chip. "..
Index: nut/dev/ft245.c
===================================================================
--- nut/dev/ft245.c	(Revision 0)
+++ nut/dev/ft245.c	(Revision 0)
@@ -0,0 +1,191 @@
+/*
+ * Copyright (C) 2009 Uwe Bonnes bon at elektron.ikp.physik.tu-darmstadt.de
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holders nor the names of
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY ETH ZURICH AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ETH ZURICH
+ * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+ * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * For additional information see http://www.ethernut.de/
+ *
+ */
+
+/* @file ft245.c - a nut/os device driver for FT245 type memory mapped devices
+ *
+ *
+ */
+
+#include <compiler.h>
+#include <stdlib.h>
+
+#include <sys/file.h>
+#include <sys/device.h>
+#include <dev/ft245.h>
+
+#define ft245_outb(val) (*(volatile uint8_t *)(FT245_FIFO) = (val))
+#define ft245_inb()  (*(volatile uint8_t *)(FT245_FIFO))
+/*!
+ * \addtogroup xgDevice
+ */
+/*@{*/
+
+/*!
+ * \brief Open UnixDev
+ *
+ * \return Pointer to a static NUTFILE structure.
+ */
+static NUTFILE *FT245Open(NUTDEVICE * dev, CONST char *name, int mode, int acc)
+{
+    NUTFILE *nf;
+
+    nf = malloc(sizeof(NUTFILE));
+
+    // enter data
+    nf->nf_next = 0;
+    nf->nf_dev = dev;
+
+    return nf;
+}
+
+
+/*!
+ * \brief Write bytes to FT245 FIFO
+ *
+ * \return Number of characters sent.
+ */
+static int FT245Write(NUTFILE * nf, CONST void *buffer, int len)
+{
+  int sent = 0;
+  while (sent <len)
+    {
+      CONST uint8_t *buf = ( CONST uint8_t*)buffer;
+      if(inp(FT245_TXE_PIN) & (1<<FT245_TXE_BIT))
+	break;
+      ft245_outb( buf[sent]);
+      sent++;
+    }
+  return sent;
+}
+#ifdef __HARVARD_ARCH__
+static int FT245WriteP(NUTFILE * nf, PGM_P buffer, int len)
+{
+  int sent = 0;
+  if(inp(FT245_TXE_PIN) & (1<<FT245_TXE_BIT))
+    return -1;
+  while (sent <len)
+    {
+      CONST uint8_t *buf = ( CONST uint8_t*)buffer;
+      if(inp(FT245_TXE_PIN) & (1<<FT245_TXE_BIT))
+	break;
+      ft245_outb( buf[sent++]);
+    }
+  return sent;
+}
+#endif
+
+
+
+ 
+/*!
+ * \brief Read bytes from FT245 FIFO
+ *
+ * \return Number of characters read.
+ */
+static int FT245Read(NUTFILE * nf, void *buffer, int len)
+{
+  int read = 0;
+    if (len == 0){
+        return 0;
+    }
+  while (read <len)
+    {
+      uint8_t *buf = (uint8_t *)buffer;
+      if(inp(FT245_RXF_PIN) & (1<<FT245_RXF_BIT))
+	break;
+      buf[read++] = ft245_inb();
+    }
+    return read;
+}
+
+/*! 
+ * \brief Close ...
+ *
+ * \return Always 0.
+ */
+static int FT245Close(NUTFILE * nf)
+{
+	if (nf)
+		free (nf);
+    return 0;
+}
+
+/*!
+ * \brief Perform control functions.
+ *
+ * This function is called by the ioctl() function of the C runtime
+ * library.
+ *
+ * \param dev  Identifies the device that receives the device-control
+ *             function.
+ * \param req  Requested control function. We do return ok for any function
+ * \param conf Points to a buffer that contains any data required for
+ *             the given control function or receives data from that
+ *             function.
+ * \return 0 on success, -1 otherwise.
+ *
+ */
+int FT245IOCTL(NUTDEVICE * dev, int req, void *conf)
+{
+    return 0;
+}
+
+/* ======================= Devices ======================== */
+/*!
+ * \brief Null device information structure.
+ */
+NUTDEVICE devFT245 = {
+    0,                          /*!< Pointer to next device. */
+    {'f', 't', '2', '4', '5', 0, 0, 0, 0},
+                                /*!< Unique device name. */
+    0,                          /*!< Type of device. */
+    0,                          /*!< Base address. */
+    0,                          /*!< First interrupt number. */
+    0,                          /*!< Interface control block. */
+
+    0,                          /*!< Driver control block. */
+    0,                          /*!< Driver initialization routine. */
+    
+    FT245IOCTL,                  /*!< Driver specific control function. */
+    FT245Read,
+    FT245Write,
+#ifdef __HARVARD_ARCH__
+    FT245WriteP,
+#endif
+    FT245Open,
+    FT245Close,
+    0
+};
+
+
+/*@}*/
Index: nut/dev/Makefile
===================================================================
--- nut/dev/Makefile	(Revision 2985)
+++ nut/dev/Makefile	(Arbeitskopie)
@@ -178,7 +178,7 @@
 

 SRCS = ihndlr.c can_dev.c usart.c null.c chat.c term.c netbuf.c ppp.c nvmem.c \

        twbbif.c mmcard.c x12rtc.c cy2239x.c npl.c nplmmc.c watchdog.c \

-       rtc.c ds1307rtc.c at49bv.c avrtarget.c sbbif0.c pcf8563.c \

+       rtc.c ds1307rtc.c at49bv.c avrtarget.c sbbif0.c pcf8563.c ft245.c \

        pca9555.c usart0sc16is752.c usartsc16is752.c spi_7seg.c led.c keys.c

 

 ifeq ($(DEVICE), AT91R40008)

Index: nut/include/dev/ft245.h
===================================================================
--- nut/include/dev/ft245.h	(Revision 0)
+++ nut/include/dev/ft245.h	(Revision 0)
@@ -0,0 +1,83 @@
+#ifndef _DEV_FT245_H_
+#define _DEV_FT245_H_
+
+
+/*
+ * Copyright (C) Uwe Bonnes bon at elektron.ikp.physik.tu-darmstadt.de
+ * Copyright (C) 2000-2004 by ETH Zurich
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holders nor the names of
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY ETH ZURICH AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ETH ZURICH
+ *  OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+ * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * For additional information see http://www.ethernut.de/
+ *
+ */
+
+/* ft245.h - a nut/os FT245 device driver
+ *
+ * 2009 Uwe Bonnes bon at elektron.ikp.physik.tu-darmstadt.de
+ * adapted from null.h
+ * 2005.05.21 Matthias Ringwald <matthias.ringwald at inf.ethz.ch>
+ *
+ */
+
+
+#include <sys/device.h>
+#include <stdio.h>
+
+#ifndef FT245_FIFO
+#define FT245_FIFO 0x3fff
+#endif
+
+#ifndef FT245_TXE_PIN
+#define FT245_TXE_PIN PIND
+#endif
+
+#ifndef FT245_TXE_BIT
+#define FT245_TXE_BIT  PORTD7
+#endif
+
+#ifndef FT245_RXF_PIN
+#define FT245_RXF_PIN PIND
+#endif
+
+#ifndef FT245_RXE_BIT
+#define FT245_RXF_BIT  PORTD6
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Available devices.
+ */
+extern NUTDEVICE devFT245;
+
+#ifdef __cplusplus
+}
+#endif
+#endif


More information about the En-Nut-Discussion mailing list