summaryrefslogtreecommitdiff
path: root/ecos/packages/devs/spi/freescale/dspi
diff options
context:
space:
mode:
authorMichael Gielda <mgielda@antmicro.com>2014-04-03 14:53:04 +0200
committerMichael Gielda <mgielda@antmicro.com>2014-04-03 14:53:04 +0200
commitae1e4e08a1005a0c487f03ba189d7536e7fdcba6 (patch)
treef1c296f8a966a9a39876b0e98e16d9c5da1776dd /ecos/packages/devs/spi/freescale/dspi
parentf157da5337118d3c5cd464266796de4262ac9dbd (diff)
Added the OS files
Diffstat (limited to 'ecos/packages/devs/spi/freescale/dspi')
-rw-r--r--ecos/packages/devs/spi/freescale/dspi/current/ChangeLog79
-rw-r--r--ecos/packages/devs/spi/freescale/dspi/current/cdl/spi_freescale_dspi.cdl387
-rw-r--r--ecos/packages/devs/spi/freescale/dspi/current/include/spi_freescale_dspi.h207
-rw-r--r--ecos/packages/devs/spi/freescale/dspi/current/include/spi_freescale_dspi_buses.inl586
-rw-r--r--ecos/packages/devs/spi/freescale/dspi/current/include/spi_freescale_dspi_io.h292
-rw-r--r--ecos/packages/devs/spi/freescale/dspi/current/src/spi_freescale_dspi.c1190
-rw-r--r--ecos/packages/devs/spi/freescale/dspi/current/tests/spi_loopback.c285
7 files changed, 3026 insertions, 0 deletions
diff --git a/ecos/packages/devs/spi/freescale/dspi/current/ChangeLog b/ecos/packages/devs/spi/freescale/dspi/current/ChangeLog
new file mode 100644
index 0000000..ca08fc7
--- /dev/null
+++ b/ecos/packages/devs/spi/freescale/dspi/current/ChangeLog
@@ -0,0 +1,79 @@
+2013-07-09 Mike Jones <mjones@proclivis.com>
+
+ * src/spi_freescale_dspi.c: Fix: Kinetis DSPI infinite polling
+ [ Bugzilla 10011879 ]
+
+2013-05-08 Ilija Kocho <ilijak@siva.com.mk>
+
+ * src/spi_freescale_dspi.cdl: Add CYGINT_DEVS_SPI_DMA_USE
+ * src/spi_freescale_dspi.c: Fix: Disable DMA requests for transfers
+ that don't use DMA. [ Bugzilla 1001815 ]
+
+2013-04-01 Ilija Kocho <ilijak@siva.com.mk>
+
+ * include/spi_freescale_dspi.h, include/spi_freescale_busses.inl
+ * include/spi_freescale_dspi_io.h, src/spi_freescale_dspi.c:
+ Optimised receiving of messages that fit in FIFO. Add clock gating.
+ Fix race condition bug in dspi_transaction_end(). [ Bugzilla 1001815 ]
+
+2013-02-06 Stefan Singer <stefan.singer@freescale.com>
+ Ilija Kocho <ilijak@siva.com.mk>
+
+ * include/spi_freescale_dspi.h, include/spi_freescale_busses.inl
+ * include/spi_freescale_dspi_io.h, include/spi_freescale_dspi_bd.h,
+ * src/spi_freescale_dspi.c:
+ enhanced endianness support for devices with big and little endian
+ added support for MPC5xxx in addition to Kinetis
+ extended support for up to 8 DSPIs
+ (see Bugzilla 1001752).
+
+2012-12-28 Ilija Kocho <ilijak@siva.com.mk>
+
+ * cdl/spi_freescale_dspi.cdl, src/spi_freescale_dspi.c:
+ Tick-only now has option to beehive like other drivers
+ rather than RM (see Bugzilla 1001676).
+ Fixed bug with dropping CS. Chip select options consolidated in a for loop.
+
+ * tests/spi_loopback.c: New file. Add looback test.
+ [Bugzilla 1001719]
+
+2012-05-04 Ilija Kocho <ilijak@siva.com.mk>
+
+ * cdl/spi_freescale_dspi.cdl:
+ * include/spi_freescale_dspi_buses.inl
+ * src/spi_freescale_dspi.c:
+ Add: support for 32 channel eDMA, support for cached memory.
+ [Bugzilla 1001579]
+
+2012-01-06 Ilija Kocho <ilijak@siva.com.mk>
+
+ * cdl/spi_freescale_dspi.cdl:
+ * include/spi_freescale_dspi.h
+ * include/spi_freescale_dspi_io.h:
+ * include/spi_freescale_dspi_buses.inl
+ * src/spi_freescale_dspi.c:
+ New package -- Freescale DSPI SPI driver. [Bugzilla 1001450]
+
+//===========================================================================
+// ####GPLCOPYRIGHTBEGIN####
+// -------------------------------------------
+// This file is part of eCos, the Embedded Configurable Operating System.
+// Copyright (C) 2012 Free Software Foundation, Inc.
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 or (at your option) any
+// later version.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the
+// Free Software Foundation, Inc., 51 Franklin Street,
+// Fifth Floor, Boston, MA 02110-1301, USA.
+// -------------------------------------------
+// ####GPLCOPYRIGHTEND####
+//===========================================================================
diff --git a/ecos/packages/devs/spi/freescale/dspi/current/cdl/spi_freescale_dspi.cdl b/ecos/packages/devs/spi/freescale/dspi/current/cdl/spi_freescale_dspi.cdl
new file mode 100644
index 0000000..f1be8ba
--- /dev/null
+++ b/ecos/packages/devs/spi/freescale/dspi/current/cdl/spi_freescale_dspi.cdl
@@ -0,0 +1,387 @@
+##=============================================================================
+##
+## spi_freescale_dspi.cdl
+##
+## Freescale DSPI driver configuration options.
+##
+##=============================================================================
+## ####ECOSGPLCOPYRIGHTBEGIN####
+## -------------------------------------------
+## This file is part of eCos, the Embedded Configurable Operating System.
+## Copyright (C) 2011 Free Software Foundation, Inc.
+##
+## eCos is free software; you can redistribute it and/or modify it under
+## the terms of the GNU General Public License as published by the Free
+## Software Foundation; either version 2 or (at your option) any later
+## version.
+##
+## eCos is distributed in the hope that it will be useful, but WITHOUT
+## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+## for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with eCos; if not, write to the Free Software Foundation, Inc.,
+## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+##
+## As a special exception, if other files instantiate templates or use
+## macros or inline functions from this file, or you compile this file
+## and link it with other works to produce a work based on this file,
+## this file does not by itself cause the resulting work to be covered by
+## the GNU General Public License. However the source code for this file
+## must still be made available in accordance with section (3) of the GNU
+## General Public License v2.
+##
+## This exception does not invalidate any other reasons why a work based
+## on this file might be covered by the GNU General Public License.
+## -------------------------------------------
+## ####ECOSGPLCOPYRIGHTEND####
+##=============================================================================
+#######DESCRIPTIONBEGIN####
+##
+## Author(s): Ilija Kocho
+## Date: 2011-11-03
+## Purpose: Configure Freescale DSPI driver.
+##
+######DESCRIPTIONEND####
+##
+##=============================================================================
+
+cdl_package CYGPKG_DEVS_SPI_FREESCALE_DSPI {
+ display "Freescale DSPI driver"
+ description "
+ This package provides SPI driver support for the Freescale
+ microcontrollers that employ DSPI interface."
+
+ parent CYGPKG_IO_SPI
+ active_if CYGPKG_IO_SPI
+ requires CYGPKG_HAL_CORTEXM_KINETIS || CYGPKG_HAL_POWERPC_MPC5xxx
+
+ hardware
+ include_dir cyg/io
+ compile spi_freescale_dspi.c
+
+ cdl_option CYGHWR_DEVS_SPI_FREESCALE_DSPI_FIFO_SIZE {
+ display "DSPI FIFO size"
+ flavor data
+ default_value 4
+ legal_values { 4 5 6 7 8 }
+ }
+
+ cdl_component CYGHWR_DEVS_SPI_FREESCALE_DSPI_CTAR_NUM {
+ display "CTAR registers"
+ flavor data
+ calculated 2
+
+ description "DSPI can have from 2 to 8 CTAR registers that keep
+ transfer communication settings. In eCos CTAR0 is used for
+ all normal transfers while CTAR1 is used as auxiliary for
+ 'transaction end' (non)transfer."
+
+ cdl_component CYGHWR_DEVS_SPI_FREESCALEDSPI_DSPI_CTAR1_AUX {
+ display "CTAR1 Aux settings"
+ flavor none
+ no_define
+
+ cdl_component CYGHWR_DEVS_FREESCALEDSPI_DSPI_CTAR1_AUX_SPEED {
+ display "Nominal clock speed Hz"
+ flavor data
+ default_value 25000000
+
+ cdl_option CYGHWR_DEVS_FREESCALEDSPI_DSPI_CTAR1_AUX_USE_DBR {
+ display "Use double baud rate"
+ flavor bool
+ default_value 1
+ description "Double baud rate is a feature of Freescale DSPI
+ that may provide higher baud rates but duty the cycle may be
+ different than 50/50 depdent on scaler/prescaler setting
+ for achieved baud rate."
+ }
+ }
+
+ cdl_option CYGHWR_DEVS_FREESCALEDSPI_DSPI_CTAR1_AUX_CS_DELAY {
+ display "Nominal chip select delay (units)"
+ flavor data
+ legal_values { 1 to 1000 }
+ default_value 1
+ }
+
+ cdl_option CYGHWR_DEVS_FREESCALE_DSPI_DSPI_CTAR1_AUX_DELAY_UNIT {
+ display "Chip select delay unit (ns)"
+ flavor data
+ calculated 100
+ }
+ }
+ }
+
+ cdl_interface CYGINT_DEVS_SPI_DSPI_DMA_USE {
+ display "DSPI DMA use"
+ flavor data
+ description "Number of DMA channels used by DSPI buses."
+ }
+
+ for { set ::spibus 0 } { $::spibus < 8 } { incr ::spibus } {
+
+ cdl_interface CYGINT_DEVS_SPI_FREESCALE_DSPI[set ::spibus] {
+ display "Number of devices using DSPI bus [set ::spibus]"
+ }
+
+ cdl_component CYGHWR_DEVS_SPI_FREESCALE_DSPI[set ::spibus] {
+ display "Freescale DSPI bus [set ::spibus]"
+ description "Enable DSPI bus [set :: spibus]."
+ flavor bool
+ default_value CYGINT_DEVS_SPI_FREESCALE_DSPI[set ::spibus]
+ active_if CYGINT_DEVS_SPI_FREESCALE_DSPI[set ::spibus]
+
+ implements CYGINT_HAL_DMA
+ requires CYGPKG_HAL_FREESCALE_EDMA
+
+ cdl_component CYGHWR_DEVS_SPI_FREESCALE_DSPI[set ::spibus]_CS {
+ display "Chip-selects"
+ flavor none
+ no_define
+ cdl_option CYHGWR_DEVS_SPI_FREESCALE_DSPI[set ::spibus]_PCSS {
+ display "Chip-select Strobe enable"
+ flavor bool
+ default_value 0
+
+ requires CYHGWR_DEVS_SPI_FREESCALE_DSPI[set ::spibus]_PCSS == 1 \
+ implies CYGHWR_FREESCALE_DSPI[set ::spibus]_CS5 == 0
+ }
+
+ for { set ::spics 0 } { $::spics < 5 } { incr ::spics } {
+ cdl_interface CYGINT_FREESCALE_DSPI[set ::spibus]_CS[set ::spics] {
+ flavor bool
+ requires CYGHWR_FREESCALE_DSPI[set ::spibus]_CS[set ::spics] == 1
+ display "Use CS[set ::spics]"
+ }
+
+ cdl_component CYGHWR_FREESCALE_DSPI[set ::spibus]_CS[set ::spics] {
+ display "CS[set ::spics]"
+ flavor bool
+ default_value 0
+ cdl_option CYGHWR_FREESCALE_DSPI[set ::spibus]_CS[set ::spics]_IS {
+ display "CS[set ::spics] Inactive state Hi(1) Lo(0)"
+ flavor data
+ no_define
+ default_value { 1 }
+ legal_values { 0 1 }
+ }
+ }
+ }
+
+ cdl_component CYGHWR_DEVS_SPI_FREESCALE_DSPI[set ::spibus]_PCSIS {
+ display "Peripheral CS inactive states"
+ flavor data
+ calculated (0x0 + \
+ (get_data(CYGHWR_FREESCALE_DSPI[set ::spibus]_CS0_IS) == 1 ? 1 : 0) + \
+ (get_data(CYGHWR_FREESCALE_DSPI[set ::spibus]_CS1_IS) == 1 ? 2 : 0) + \
+ (get_data(CYGHWR_FREESCALE_DSPI[set ::spibus]_CS2_IS) == 1 ? 4 : 0) + \
+ (get_data(CYGHWR_FREESCALE_DSPI[set ::spibus]_CS3_IS) == 1 ? 8 : 0) + \
+ (get_data(CYGHWR_FREESCALE_DSPI[set ::spibus]_CS4_IS) == 1 ? 16 : 0) + \
+ (get_data(CYGHWR_FREESCALE_DSPI[set ::spibus]_CS5_IS) == 1 ? 32 : 0))
+ }
+ }
+
+ cdl_interface CYGINT_FREESCALE_DSPI[set ::spibus]_HAS_MASS {
+ description "SPI bus serves mass data device(s)."
+ }
+
+ cdl_option CYGNUM_DEVS_SPI_FREESCALE_DSPI[set ::spibus]_PUSHQUE_SIZE {
+ display "Queue buffer size"
+ description "
+ DSPI requires a command for every transfer so output
+ data must be re-packed in additional buffer prior to
+ being submitted to DMA.
+ If Queue capacity is same as DSPI FIFO size, the minimal
+ legal value, the DMA is not needed so no buffer memory
+ is allocated. Note: For every entry, byte (8 bit transfer)
+ or half word (16 bit transfer) a whole 32 bit word
+ is being allocated."
+
+ legal_values { CYGHWR_DEVS_SPI_FREESCALE_DSPI_FIFO_SIZE to 2048 }
+ flavor data
+ default_value CYGINT_FREESCALE_DSPI[set ::spibus]_HAS_MASS ? 128 : \
+ CYGHWR_DEVS_SPI_FREESCALE_DSPI_FIFO_SIZE
+ }
+
+ cdl_interface CYGINT_DEVS_SPI_DSPI[set ::spibus]_USES_DMA {
+ flavor bool
+ }
+
+ cdl_component CYGHWR_DEVS_SPI_FREESCALE_DSPI[set ::spibus]_TX_DMA_CHAN {
+ display "TX DMA channel"
+ flavor data
+ implements CYGINT_DEVS_SPI_DSPI_DMA_USE
+ implements CYGINT_DEVS_SPI_DSPI[set ::spibus]_USES_DMA
+
+ active_if CYGNUM_DEVS_SPI_FREESCALE_DSPI[set ::spibus]_PUSHQUE_SIZE > \
+ CYGHWR_DEVS_SPI_FREESCALE_DSPI_FIFO_SIZE
+ default_value 4 + [set ::spibus] * 2
+ legal_values { 0 to (CYGNUM_HAL_FREESCALE_EDMA_CHAN_NUM-1) }
+ description "DMA channel assigned to the trasmitter of SPI bus"
+
+ cdl_component CYGNUM_DEVS_SPI_FREESCALE_DSPI[set ::spibus]_TX_DMA_PRI {
+ display "Transmit DMA channel priority"
+ flavor data
+ legal_values { 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 255 }
+ default_value 255
+ description "
+ DMA can work in either round robin or preeptve arbitration
+ mode. In preemptive mode, DMA each channel has unique priority,
+ lower number meaning lower priority.
+ 255 is a phony meaning \"default channel priority\"."
+
+ cdl_option CYGNUM_DEVS_SPI_FREESCALE_DSPI[set ::spibus]_TX_DMA_ECP {
+ display "Enable channel preemption"
+ flavor data
+ legal_values { 0 1 }
+ default_value 0
+ }
+
+ cdl_option CYGNUM_DEVS_SPI_FREESCALE_DSPI[set ::spibus]_TX_DMA_DPA {
+ display "Disable preempt ability"
+ flavor data
+ legal_values { 0 1 }
+ default_value 0
+ }
+
+ }
+
+ cdl_option CYGOPT_DEVS_SPI_FREESCALE_DSPI[set ::spibus]_TCD_SECTION {
+ display "DMA TCD section"
+ flavor data
+ default_value CYGHWR_HAL_EDMA_TCD_SECTION
+
+ description "
+ Section in which will be DMA Transfer Control
+ Descriptors shall reside"
+ }
+ }
+
+ cdl_component CYGHWR_DEVS_SPI_FREESCALE_DSPI[set ::spibus]_RX_DMA_CHAN {
+ display "RX DMA channel"
+ flavor data
+ implements CYGINT_DEVS_SPI_DSPI_DMA_USE
+ implements CYGINT_DEVS_SPI_DSPI[set ::spibus]_USES_DMA
+
+ active_if CYGNUM_DEVS_SPI_FREESCALE_DSPI[set ::spibus]_PUSHQUE_SIZE > \
+ CYGHWR_DEVS_SPI_FREESCALE_DSPI_FIFO_SIZE
+ default_value 5 + [set ::spibus] * 2
+ legal_values { 0 to (CYGNUM_HAL_FREESCALE_EDMA_CHAN_NUM-1) }
+ description "DMA channel assigned to the receiver of SPI bus"
+
+ cdl_component CYGNUM_DEVS_SPI_FREESCALE_DSPI[set ::spibus]_RX_DMA_PRI {
+ display "Receive DMA channel priority"
+ flavor data
+ legal_values { 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 255 }
+ default_value 255
+ description "
+ DMA can work in either round robin or preeptve arbitration
+ mode. In preemptive mode, DMA each channel has unique priority,
+ lower number meaning lower priority.
+ 255 is a phony meaning \"default channel priority\"."
+
+ cdl_option CYGNUM_DEVS_SPI_FREESCALE_DSPI[set ::spibus]_RX_DMA_ECP {
+ display "Enable channel preemption"
+ flavor data
+ legal_values { 0 1 }
+ default_value 0
+ }
+
+ cdl_option CYGNUM_DEVS_SPI_FREESCALE_DSPI[set ::spibus]_RX_DMA_DPA {
+ display "Disable preempt ability"
+ flavor data
+ legal_values { 0 1 }
+ default_value 0
+ }
+ }
+ }
+
+ cdl_option CYGNUM_DEVS_SPI_FREESCALE_DSPI[set ::spibus]_ISR_PRI {
+ display "Interrupt priority"
+ flavor data
+ requires CYGNUM_DEVS_SPI_FREESCALE_DSPI[set ::spibus]_ISR_PRI_SP
+ calculated CYGNUM_DEVS_SPI_FREESCALE_DSPI[set ::spibus]_ISR_PRI_SP
+ description "Interrupt priority set-point is provided by HAL"
+ }
+ }
+ }
+
+ cdl_option CYGOPT_DEVS_SPI_FREESCALE_DSPI_TICK_ONLY_DROPS_CS {
+ display "Tick-only drops CS"
+ default_value 0
+
+ description "
+ eCos Reference Manual states that CS should drop prior to sending ticks,
+ but other drivers (so far) do not touch the CS. This option selects
+ between conformance with manual or compatibility with other drivers."
+ }
+
+ cdl_option CYGPKG_DEVS_SPI_FREESCALE_DSPI_DEBUG_LEVEL {
+ display "Driver debug output level"
+ flavor data
+ legal_values { 0 1 2 3 }
+ default_value 0
+ description "
+ This option specifies the level of debug data output by
+ the Freescale DSPI device driver. A value of 0 signifies
+ no debug data output; 1 signifies normal debug data
+ output; and 2 signifies maximum debug data output."
+ }
+
+
+ cdl_component CYGPKG_DEVS_SPI_FREESCALE_DSPI_OPTIONS {
+ display "Freescale DSPI driver build options"
+ flavor none
+ description "
+ Package specific build options including control over
+ compiler flags used only in building this package,
+ and details of which tests are built."
+
+ cdl_option CYGPKG_DEVS_SPI_FREESCALE_DSPI_CFLAGS_ADD {
+ display "Additional compiler flags"
+ flavor data
+ no_define
+ default_value { "" }
+ description "
+ This option modifies the set of compiler flags for
+ building the Freescale DSPI driver. These flags are used in addition
+ to the set of global flags."
+ }
+
+ cdl_option CYGPKG_DEVS_SPI_FREESCALE_DSPI_CFLAGS_REMOVE {
+ display "Suppressed compiler flags"
+ flavor data
+ no_define
+ default_value { "" }
+ description "
+ This option modifies the set of compiler flags for
+ building the Freescale DSPI driver. These flags are removed from
+ the set of global flags if present."
+ }
+
+ }
+
+ cdl_component CYGPKG_DEVS_SPI_FREESCALE_DSPI_TESTS {
+ display "Freescale DSPI tests"
+ flavor data
+ no_define
+ calculated { CYGBLD_DEVS_SPI_FREESCALE_DSPI_LOOPBACK_TEST ? "tests/spi_loopback" : "" }
+
+ cdl_option CYGBLD_DEVS_SPI_FREESCALE_DSPI_LOOPBACK_TEST {
+ display "Build Freescale DSPI loopback test"
+ flavor bool
+ no_define
+ default_value 0
+ requires { CYGHWR_DEVS_SPI_FREESCALE_DSPI0 ||
+ CYGHWR_DEVS_SPI_FREESCALE_DSPI1 ||
+ CYGHWR_DEVS_SPI_FREESCALE_DSPI2 }
+ description "
+ This option enables the building of the Freescale DSPI loopback test.
+ Refer to the comments in tests/loopback.c for details of how to
+ use this test."
+ }
+ }
+}
+# EOF spi_freescale_dspi.cdl
diff --git a/ecos/packages/devs/spi/freescale/dspi/current/include/spi_freescale_dspi.h b/ecos/packages/devs/spi/freescale/dspi/current/include/spi_freescale_dspi.h
new file mode 100644
index 0000000..f1fe610
--- /dev/null
+++ b/ecos/packages/devs/spi/freescale/dspi/current/include/spi_freescale_dspi.h
@@ -0,0 +1,207 @@
+#ifndef CYGONCE_DEVS_SPI_FREESCALE_DSPI_H
+#define CYGONCE_DEVS_SPI_FREESCALE_DSPI_H
+//=============================================================================
+//
+// spi_freescale_dspi.h
+//
+// Header definitions for Freescale DSPI driver.
+//
+//=============================================================================
+// ####ECOSGPLCOPYRIGHTBEGIN####
+// -------------------------------------------
+// This file is part of eCos, the Embedded Configurable Operating System.
+// Copyright (C) 2011 Free Software Foundation, Inc.
+//
+// eCos is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 2 or (at your option) any later
+// version.
+//
+// eCos is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with eCos; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// As a special exception, if other files instantiate templates or use
+// macros or inline functions from this file, or you compile this file
+// and link it with other works to produce a work based on this file,
+// this file does not by itself cause the resulting work to be covered by
+// the GNU General Public License. However the source code for this file
+// must still be made available in accordance with section (3) of the GNU
+// General Public License v2.
+//
+// This exception does not invalidate any other reasons why a work based
+// on this file might be covered by the GNU General Public License.
+// -------------------------------------------
+// ####ECOSGPLCOPYRIGHTEND####
+//=============================================================================
+//#####DESCRIPTIONBEGIN####
+//
+// Author(s): ilijak
+// Date: 2011-11-03
+// Purpose: Freescale DSPI driver definitions.
+// Description:
+// Usage: #include <cyg/io/spi_freescale_dspi.h>
+//
+//####DESCRIPTIONEND####
+//
+//=============================================================================
+
+#include <pkgconf/hal.h>
+#include <pkgconf/io_spi.h>
+#include <pkgconf/devs_spi_freescale_dspi.h>
+#include <pkgconf/hal_freescale_edma.h>
+
+#include <cyg/infra/cyg_type.h>
+#include <cyg/hal/drv_api.h>
+#include <cyg/io/spi.h>
+#include <cyg/hal/freescale_edma.h>
+#include <cyg/io/spi_freescale_dspi_io.h>
+
+//-----------------------------------------------------------------------------
+// Macro for defining a SPI device and attaching it to the appropriate bus.
+//
+// _name_ is the name of the SPI device. This will be used to reference a
+// data structure of type cyg_spi_device which can be passed to the
+// SPI driver API without needing a cast.
+// _bus_ is the bus number to which this device is attached (0, 1 or 2).
+// _csnum_ is the chip select line used for this device, numbered from 0.
+// _fmsz_ is set device SPI frame size (bits)
+// _clpol_ is the SPI bus clock polarity used by the device. This must be
+// set to 1 if clock inactive state is high, 0 if clock inactive
+// state is low.
+// _clpha_ is the SPI bus clock phase used by the device.
+// _brate_ is the SPI bus clock baud rate used by the device, measured in Hz.
+// _csup_dly_ is the minimum delay between chip select assert and transfer
+// start, measured in microseconds.
+// _csdw_dly_ is the minimum delay between transfer end and chip select deassert,
+// measured in delay units.
+// _trbt_dly_ is the minimum delay between consecutive transfers.
+// _dlu_ is delay unit in ns
+// _dbr_ is enabling double baud rate feature
+
+
+#define CYGNUM_DSPI_DELAY_UNIT(__val) (__val/10)
+
+#define CYG_SPI_BUS_NAME(_b_) cyg_spi_dspi_bus ## _b_
+
+#define CYG_DEVS_SPI_FREESCALE_DSPI_DEVICE( \
+ _name_, _bus_, _csnum_, _fmsz_, _clpol_, _clpha_, _brate_, _csup_dly_, _csdw_dly_, _trbt_dly_, _dlu_, _dbr_ \
+) \
+ cyg_spi_freescale_dspi_device_t _name_ ##_fs_dspi CYG_SPI_DEVICE_ON_BUS(_bus_) = { \
+{ .spi_bus = (cyg_spi_bus*) &CYG_SPI_BUS_NAME(_bus_) }, \
+ .dev_num = _csnum_, \
+ .clocking.bus_16bit = _fmsz_ > 8 ? 1 : 0, \
+ .clocking.frame_size = _fmsz_, \
+ .clocking.cl_pol = _clpol_, \
+ .clocking.cl_pha = _clpha_, \
+ .clocking.cl_brate = _brate_, \
+ .clocking.cs_up_udly = _csup_dly_, \
+ .clocking.cs_dw_udly = _csdw_dly_, \
+ .clocking.tr_bt_udly = _trbt_dly_, \
+ .clocking.dl_unit = CYGNUM_DSPI_DELAY_UNIT(_dlu_), \
+ .clocking.cl_dbr = _dbr_, \
+ .clocking.dspi_ctar = 0 \
+}; \
+extern cyg_spi_device _name_ __attribute__((alias ( #_name_ "_fs_dspi" )))
+
+enum { SPI_DMA_CHAN_TX_I, SPI_DMA_CHAN_RX_I };
+
+//-----------------------------------------------------------------------------
+// Freescale DSPI bus configuration and state.
+
+typedef struct cyg_spi_freescale_dspi_bus_setup_s
+{
+ cyghwr_devs_freescale_dspi_t* dspi_p; // Base address of SPI register block.
+ cyghwr_hal_freescale_dma_set_t* dma_set_p; // DMA configuration block.
+ cyg_vector_t intr_num; // DSPI interrupt vector
+ cyg_priority_t intr_prio; // Interrupt priority
+ cyg_uint32 mcr_opt ; // Module Configuratyon Register options
+ const cyg_uint32* spi_pin_list_p; // List of GPIOs used by the SPI interface.
+ const cyg_uint32* cs_pin_list_p; // List of GPIOs used as chip selects.
+ cyg_uint16 clk_gate; // Clock gate
+ cyg_uint8 cs_pin_num; // Number of chip selects for this bus.
+} cyg_spi_freescale_dspi_bus_setup_t;
+
+#define SPI_DMA_CHAN_I(__dma_set,__rt) (__dma_set->chan_p[SPI_DMA_CHAN_ ## __rt ## _I].dma_chan_i)
+
+typedef struct cyg_spi_freescale_dspi_bus_s
+{
+ // ---- Upper layer data ----
+ cyg_spi_bus spi_bus; // Upper layer SPI bus data.
+
+ // ---- Bus configuration constants ----
+ const cyg_spi_freescale_dspi_bus_setup_t* setup_p;
+ // ---- Driver state (private) ----
+ // DMA transfer control descriptors
+ const cyghwr_hal_freescale_edma_tcd_t* tx_dma_tcd_ini_p; // TCD init.
+ const cyghwr_hal_freescale_edma_tcd_t* rx_dma_tcd_ini_p; // data
+ volatile cyghwr_hal_freescale_edma_tcd_t* rx_dma_tcd_p; // DMA TCD (RX)
+ volatile cyghwr_hal_freescale_edma_tcd_t* tx_dma_tcd_p; // DMA TCD (TX)
+ volatile cyg_uint32* pushque_p; // Tx command queue
+ cyg_uint16 pushque_n; // Tx command buffer size
+ cyg_uint8 txfifo_n; // TxFIFO size
+ cyg_uint8 rxfifo_n; // RxFIFO size
+ cyg_interrupt intr_data; // Interrupt state
+ cyg_handle_t intr_handle; // Interrupt handle
+ cyg_drv_mutex_t transfer_mutex; // Transfer mutex.
+ cyg_drv_cond_t transfer_done; // Transfer condition variable.
+ cyg_uint32 clock_freq; // Clock provided by hal
+} cyg_spi_freescale_dspi_bus_t;
+
+//-----------------------------------------------------------------------------
+// Freescale DSPI device.
+
+typedef struct cyg_freescale_dspi_clocking_s {
+ cyg_uint32 dspi_ctar; // DSPI Clock and Transfer Attributes Rregister shadow.
+ cyg_uint32 cl_brate; // Clock baud rate.
+ cyg_uint8 bus_16bit; // Use 16 bit (1) or 8 bit (0) transfers.
+ cyg_uint8 cl_pol; // Clock polarity (0 or 1).
+ cyg_uint8 cl_pha; // Clock phase (0 or 1).
+ cyg_uint8 cl_dbr; // Use double baud-rate feature if needed
+ cyg_uint8 cs_up_udly; // Minimum delay in us/ns between CS up and transfer start.
+ cyg_uint8 cs_dw_udly; // Minimum delay in us/ns between transfer end and CS down.
+ cyg_uint8 tr_bt_udly; // Minimum delay in us/ns between two transfers.
+ cyg_uint8 dl_unit; // Delay unit (1/10 * ns)
+ cyg_uint8 lsb_first; // LSbit shifted first.
+ cyg_uint8 frame_size; // Device SPI frame size (bits).
+} cyg_freescale_dspi_clocking_t;;
+
+typedef struct cyg_spi_freescale_dspi_device_s
+{
+ // ---- Upper layer data ----
+ cyg_spi_device spi_device; // Upper layer SPI device data.
+
+ // ---- Device setup (user configurable) ----
+ cyg_freescale_dspi_clocking_t clocking;
+ cyg_uint8 dev_num; // Device SPI select.
+ cyg_uint8 chip_sel;
+ // ---- Device state (private) ----
+} cyg_spi_freescale_dspi_device_t;
+
+//-----------------------------------------------------------------------------
+// Exported bus data structures.
+
+#ifdef CYGHWR_DEVS_SPI_FREESCALE_DSPI0
+externC cyg_spi_freescale_dspi_bus_t cyg_spi_dspi_bus0;
+#endif
+
+#ifdef CYGHWR_DEVS_SPI_FREESCALE_DSPI1
+externC cyg_spi_freescale_dspi_bus_t cyg_spi_dspi_bus1;
+#endif
+
+#ifdef CYGHWR_DEVS_SPI_FREESCALE_DSPI2
+externC cyg_spi_freescale_dspi_bus_t cyg_spi_dspi_bus2;
+#endif
+
+__externC void cyghwr_devs_freescale_dspi_diag(cyg_spi_freescale_dspi_bus_t* spi_bus_p);
+__externC void cyghwr_devs_freescale_dspi_diag_array(char* name_p,
+ volatile cyg_uint32* fifo_p,
+ cyg_uint32 fifo_n);
+
+//=============================================================================
+#endif // CYGONCE_DEVS_SPI_FREESCALE_DSPI_H
diff --git a/ecos/packages/devs/spi/freescale/dspi/current/include/spi_freescale_dspi_buses.inl b/ecos/packages/devs/spi/freescale/dspi/current/include/spi_freescale_dspi_buses.inl
new file mode 100644
index 0000000..5fb16f2
--- /dev/null
+++ b/ecos/packages/devs/spi/freescale/dspi/current/include/spi_freescale_dspi_buses.inl
@@ -0,0 +1,586 @@
+#ifndef SPI_FREESCALE_DSPI_BUSES_INL
+#define SPI_FREESCALE_DSPI_BUSES_INL
+//=============================================================================
+//
+// spi_freescale_dspi_buses.inl
+//
+// SPI bus instantiation for Freescale DSPI
+//
+//=============================================================================
+// ####ECOSGPLCOPYRIGHTBEGIN####
+// -------------------------------------------
+// This file is part of eCos, the Embedded Configurable Operating System.
+// Copyright (C) 2011, 2013 Free Software Foundation, Inc.
+//
+// eCos is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 2 or (at your option) any later
+// version.
+//
+// eCos is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with eCos; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// As a special exception, if other files instantiate templates or use
+// macros or inline functions from this file, or you compile this file
+// and link it with other works to produce a work based on this file,
+// this file does not by itself cause the resulting work to be covered by
+// the GNU General Public License. However the source code for this file
+// must still be made available in accordance with section (3) of the GNU
+// General Public License v2.
+//
+// This exception does not invalidate any other reasons why a work based
+// on this file might be covered by the GNU General Public License.
+// -------------------------------------------
+// ####ECOSGPLCOPYRIGHTEND####
+//=============================================================================
+//#####DESCRIPTIONBEGIN####
+//
+// Author(s): ilijak
+// Date: 2011-11-09
+// Purpose: Freescale DSPI DSPI bus instantiation
+//
+//####DESCRIPTIONEND####
+//
+//=============================================================================
+
+#define PUSHQUE_ALIGN CYGBLD_ATTRIB_ALIGN(4)
+
+#define DSPI_DMA_BANDWIDTH FREESCALE_EDMA_CSR_BWC_0
+
+//-----------------------------------------------------------------------------
+// Instantiate the bus state data structures.
+
+// Some auxiliary macros
+
+#if (CYG_BYTEORDER == CYG_MSBFIRST) // AKA Big endian
+#define EDMA_TCD_SADDR(__bus) \
+ .saddr = (void *)(((unsigned int)&CYGADDR_IO_SPI_FREESCALE_DSPI ## __bus ## _P->popr) + 3)
+#else // AKA Little endian
+#define EDMA_TCD_SADDR(__bus) \
+ .saddr = (cyg_uint32 *)&CYGADDR_IO_SPI_FREESCALE_DSPI ## __bus ## _P->popr
+#endif
+
+#define DSPI_EDMA_CHAN_SET(__bus) \
+static volatile cyg_uint32 \
+dspi ## __bus ## _pushque[CYGNUM_DEVS_SPI_FREESCALE_DSPI ## __bus ## _PUSHQUE_SIZE+4] \
+PUSHQUE_ALIGN EDMA_RAM_BUF_SECTION; \
+ \
+static const cyghwr_hal_freescale_dma_chan_set_t dspi ## __bus ## _dma_chan[2] = \
+{ \
+ { \
+ .dma_src = FREESCALE_DMAMUX_SRC_SPI ## __bus ## _TX \
+ | FREESCALE_DMAMUX_CHCFG_ENBL_M, \
+ .dma_chan_i = CYGHWR_DEVS_SPI_FREESCALE_DSPI ## __bus ## _TX_DMA_CHAN, \
+ .dma_prio = CYGNUM_DEVS_SPI_FREESCALE_DSPI ## __bus ## _TX_DMA_PRI, \
+ }, \
+ { \
+ .dma_src = FREESCALE_DMAMUX_SRC_SPI ## __bus ## _RX \
+ | FREESCALE_DMAMUX_CHCFG_ENBL_M, \
+ .dma_chan_i = CYGHWR_DEVS_SPI_FREESCALE_DSPI ## __bus ## _RX_DMA_CHAN, \
+ .dma_prio = CYGNUM_DEVS_SPI_FREESCALE_DSPI ## __bus ## _RX_DMA_PRI, \
+ } \
+}; \
+ \
+static cyghwr_hal_freescale_dma_set_t dspi ## __bus ## _dma_set = { \
+ .chan_p = dspi ## __bus ## _dma_chan, \
+ .chan_n = 2 \
+}; \
+ \
+static const cyghwr_hal_freescale_edma_tcd_t dspi ## __bus ## _dma_tcd_tx_ini = \
+{ \
+ .saddr = (cyg_uint32 *) dspi ## __bus ## _pushque, \
+ .soff = 4, \
+ .attr = FREESCALE_EDMA_ATTR_SSIZE(FREESCALE_EDMA_ATTR_SIZE_32) | \
+ FREESCALE_EDMA_ATTR_DSIZE(FREESCALE_EDMA_ATTR_SIZE_32) | \
+ FREESCALE_EDMA_ATTR_SMOD(0) | \
+ FREESCALE_EDMA_ATTR_DMOD(0), \
+ .daddr = (cyg_uint32 *) \
+ &CYGADDR_IO_SPI_FREESCALE_DSPI ## __bus ## _P->pushr, \
+ .doff = 0, \
+ .nbytes.mlno = 4, \
+ .slast = 0, \
+ .citer.elinkno = 1, \
+ .dlast_sga.dlast = 0, \
+ .biter.elinkno = 1, \
+ .csr = DSPI_DMA_BANDWIDTH \
+}; \
+ \
+static const cyghwr_hal_freescale_edma_tcd_t dspi ## __bus ## _dma_tcd_rx_ini = \
+{ \
+ EDMA_TCD_SADDR(__bus), \
+ .soff = 0, \
+ .attr = FREESCALE_EDMA_ATTR_SSIZE(FREESCALE_EDMA_ATTR_SIZE_32) | \
+ FREESCALE_EDMA_ATTR_DSIZE(FREESCALE_EDMA_ATTR_SIZE_32) | \
+ FREESCALE_EDMA_ATTR_SMOD(0) | \
+ FREESCALE_EDMA_ATTR_DMOD(0), \
+ .daddr = NULL, \
+ .doff = 4, \
+ .nbytes.mlno = 4, \
+ .slast = 0, \
+ .citer.elinkno = 1, \
+ .dlast_sga.dlast = 0, \
+ .biter.elinkno = 1, \
+ .csr = DSPI_DMA_BANDWIDTH \
+}
+
+#define DSPI_EDMA_SET_P_YES(__bus) .dma_set_p = &dspi ## __bus ## _dma_set
+#define DSPI_EDMA_SET_P_NULL(__bus) .dma_set_p = NULL
+
+#define DSPI_EDMA_TCD_YES(__bus) \
+ .tx_dma_tcd_p = &CYGHWR_IO_FREESCALE_EDMA0_P-> \
+ tcd[CYGHWR_DEVS_SPI_FREESCALE_DSPI ## __bus ## _TX_DMA_CHAN], \
+ .rx_dma_tcd_p = &CYGHWR_IO_FREESCALE_EDMA0_P-> \
+ tcd[CYGHWR_DEVS_SPI_FREESCALE_DSPI ## __bus ## _RX_DMA_CHAN], \
+ .tx_dma_tcd_ini_p = &dspi ## __bus ## _dma_tcd_tx_ini, \
+ .rx_dma_tcd_ini_p = &dspi ## __bus ## _dma_tcd_rx_ini, \
+ .pushque_p = dspi ## __bus ## _pushque
+
+#define DSPI_EDMA_TCD_NULL(__bus) \
+ .tx_dma_tcd_p = NULL, \
+ .rx_dma_tcd_p = NULL, \
+ .tx_dma_tcd_ini_p = NULL, \
+ .rx_dma_tcd_ini_p = NULL, \
+ .pushque_p = NULL
+
+// End DSPI_EDMA
+
+#define DSPI_BUS_SETUP(__bus) \
+static const cyg_spi_freescale_dspi_bus_setup_t dspi ## __bus ## _setup = { \
+ .dspi_p = CYGADDR_IO_SPI_FREESCALE_DSPI ## __bus ## _P, \
+ .intr_num = CYGNUM_HAL_INTERRUPT_SPI ## __bus, \
+ .intr_prio = CYGNUM_DEVS_SPI_FREESCALE_DSPI ## __bus ## _ISR_PRI, \
+ .spi_pin_list_p = spi ## __bus ## _pins, \
+ .cs_pin_list_p = spi ## __bus ## _cs_pins, \
+ .clk_gate = CYGHWR_IO_FREESCALE_DSPI ## __bus ## _CLK, \
+ .cs_pin_num = sizeof(spi ## __bus ## _cs_pins)/ \
+ sizeof(spi ## __bus ## _cs_pins[0]), \
+ .mcr_opt = CYGHWR_FREESCALE_DSPI ## __bus ## _MCR_PCSSE | \
+ FREESCALE_DSPI_MCR_PCSIS( \
+ CYGHWR_DEVS_SPI_FREESCALE_DSPI ## __bus ## _PCSIS), \
+ DSPI ## __bus ## _EDMA_SET_P \
+}
+
+#define DSPI_BUS(__bus) \
+cyg_spi_freescale_dspi_bus_t cyg_spi_dspi_bus ## __bus = { \
+ .spi_bus.spi_transaction_begin = dspi_transaction_begin, \
+ .spi_bus.spi_transaction_transfer = dspi_transaction_transfer, \
+ .spi_bus.spi_transaction_tick = dspi_transaction_tick, \
+ .spi_bus.spi_transaction_end = dspi_transaction_end, \
+ .spi_bus.spi_get_config = dspi_get_config, \
+ .spi_bus.spi_set_config = dspi_set_config, \
+ .setup_p = &dspi ## __bus ## _setup, \
+ DSPI ## __bus ## _EDMA_TCD, \
+ .pushque_n = CYGNUM_DEVS_SPI_FREESCALE_DSPI ## __bus ## _PUSHQUE_SIZE, \
+ .txfifo_n = CYGHWR_DEVS_SPI_FREESCALE_DSPI_FIFO_SIZE, \
+ .rxfifo_n = CYGHWR_DEVS_SPI_FREESCALE_DSPI_FIFO_SIZE \
+}
+
+#define DSPI_BUS_PINS(__bus) \
+static const cyg_uint32 spi ## __bus ## _pins[] = { \
+ CYGHWR_IO_FREESCALE_SPI ## __bus ## _PIN_SIN, \
+ CYGHWR_IO_FREESCALE_SPI ## __bus ## _PIN_SOUT, \
+ CYGHWR_IO_FREESCALE_SPI ## __bus ## _PIN_SCK \
+}
+
+// DSPI BUS Instances =======================================================
+
+// DSPI BUS 0 ================================================================
+#ifdef CYGHWR_DEVS_SPI_FREESCALE_DSPI0
+
+#define CYGBLD_DSPI0_TCD_SECTION \
+ CYGBLD_ATTRIB_SECTION(CYGOPT_DEVS_SPI_FREESCALE_DSPI0_TCD_SECTION)
+
+#ifdef CYHGWR_DEVS_SPI_FREESCALE_DSPI0_PCSS
+#define CYGHWR_FREESCALE_DSPI0_MCR_PCSSE FREESCALE_DSPI_MCR_PCSSE_M
+#else
+#define CYGHWR_FREESCALE_DSPI0_MCR_PCSSE 0
+#endif
+
+// SPI chip select pins.
+static const cyg_uint32 spi0_cs_pins[] = {
+#ifdef CYGHWR_FREESCALE_DSPI0_CS0
+ CYGHWR_IO_FREESCALE_SPI0_PIN_CS0,
+#endif
+#ifdef CYGHWR_FREESCALE_DSPI0_CS1
+ CYGHWR_IO_FREESCALE_SPI0_PIN_CS1,
+#endif
+#ifdef CYGHWR_FREESCALE_DSPI0_CS2
+ CYGHWR_IO_FREESCALE_SPI0_PIN_CS2,
+#endif
+#ifdef CYGHWR_FREESCALE_DSPI0_CS3
+ CYGHWR_IO_FREESCALE_SPI0_PIN_CS3,
+#endif
+#ifdef CYGHWR_FREESCALE_DSPI0_CS4
+ CYGHWR_IO_FREESCALE_SPI0_PIN_CS4,
+#endif
+#ifdef CYGHWR_FREESCALE_DSPI0_CS5
+ CYGHWR_IO_FREESCALE_SPI0_PIN_CS5
+#endif
+};
+
+#ifdef CYGINT_DEVS_SPI_DSPI0_USES_DMA
+ DSPI_EDMA_CHAN_SET(0);
+# define DSPI0_EDMA_SET_P DSPI_EDMA_SET_P_YES(0)
+# define DSPI0_EDMA_TCD DSPI_EDMA_TCD_YES(0)
+#else
+# define DSPI0_EDMA_SET_P DSPI_EDMA_SET_P_NULL(0)
+# define DSPI0_EDMA_TCD DSPI_EDMA_TCD_NULL(0)
+#endif // CYGINT_DEVS_SPI_DSPI0_USES_DMA
+
+DSPI_BUS_PINS(0);
+DSPI_BUS_SETUP(0);
+DSPI_BUS(0);
+
+#endif // CYGHWR_DEVS_SPI_FREESCALE_DSPI0
+
+// DSPI BUS 1 ================================================================
+#ifdef CYGHWR_DEVS_SPI_FREESCALE_DSPI1
+
+#define CYGBLD_DSPI1_TCD_SECTION \
+ CYGBLD_ATTRIB_SECTION(CYGOPT_DEVS_SPI_FREESCALE_DSPI1_TCD_SECTION)
+
+#ifdef CYHGWR_DEVS_SPI_FREESCALE_DSPI1_PCSS
+#define CYGHWR_FREESCALE_DSPI1_MCR_PCSSE FREESCALE_DSPI_MCR_PCSSE_M
+#else
+#define CYGHWR_FREESCALE_DSPI1_MCR_PCSSE 0
+#endif
+
+// SPI chip select pins.
+static const cyg_uint32 spi1_cs_pins[] = {
+#ifdef CYGHWR_FREESCALE_DSPI1_CS0
+ CYGHWR_IO_FREESCALE_SPI1_PIN_CS0,
+#endif
+#ifdef CYGHWR_FREESCALE_DSPI1_CS1
+ CYGHWR_IO_FREESCALE_SPI1_PIN_CS1,
+#endif
+#ifdef CYGHWR_FREESCALE_DSPI1_CS2
+ CYGHWR_IO_FREESCALE_SPI1_PIN_CS2,
+#endif
+#ifdef CYGHWR_FREESCALE_DSPI1_CS3
+ CYGHWR_IO_FREESCALE_SPI1_PIN_CS3,
+#endif
+#ifdef CYGHWR_FREESCALE_DSPI1_CS4
+ CYGHWR_IO_FREESCALE_SPI1_PIN_CS4,
+#endif
+#ifdef CYGHWR_FREESCALE_DSPI1_CS5
+ CYGHWR_IO_FREESCALE_SPI1_PIN_CS5
+#endif
+};
+
+#ifdef CYGINT_DEVS_SPI_DSPI1_USES_DMA
+ DSPI_EDMA_CHAN_SET(1);
+# define DSPI1_EDMA_SET_P DSPI_EDMA_SET_P_YES(1)
+# define DSPI1_EDMA_TCD DSPI_EDMA_TCD_YES(1)
+#else
+# define DSPI1_EDMA_SET_P DSPI_EDMA_SET_P_NULL(1)
+# define DSPI1_EDMA_TCD DSPI_EDMA_TCD_NULL(1)
+#endif // CYGINT_DEVS_SPI_DSPI1_USES_DMA
+
+DSPI_BUS_PINS(1);
+DSPI_BUS_SETUP(1);
+DSPI_BUS(1);
+
+#endif // CYGHWR_DEVS_SPI_FREESCALE_DSPI1
+
+// DSPI BUS 2 ================================================================
+#ifdef CYGHWR_DEVS_SPI_FREESCALE_DSPI2
+
+#define CYGBLD_DSPI2_TCD_SECTION \
+ CYGBLD_ATTRIB_SECTION(CYGOPT_DEVS_SPI_FREESCALE_DSPI2_TCD_SECTION)
+
+#ifdef CYHGWR_DEVS_SPI_FREESCALE_DSPI2_PCSS
+#define CYGHWR_FREESCALE_DSPI2_MCR_PCSSE FREESCALE_DSPI_MCR_PCSSE_M
+#else
+#define CYGHWR_FREESCALE_DSPI2_MCR_PCSSE 0
+#endif
+
+// SPI chip select pins.
+static const cyg_uint32 spi2_cs_pins[] = {
+#ifdef CYGHWR_FREESCALE_DSPI2_CS0
+ CYGHWR_IO_FREESCALE_SPI2_PIN_CS0,
+#endif
+#ifdef CYGHWR_FREESCALE_DSPI2_CS1
+ CYGHWR_IO_FREESCALE_SPI2_PIN_CS1,
+#endif
+#ifdef CYGHWR_FREESCALE_DSPI2_CS2
+ CYGHWR_IO_FREESCALE_SPI2_PIN_CS2,
+#endif
+#ifdef CYGHWR_FREESCALE_DSPI2_CS3
+ CYGHWR_IO_FREESCALE_SPI2_PIN_CS3,
+#endif
+#ifdef CYGHWR_FREESCALE_DSPI2_CS4
+ CYGHWR_IO_FREESCALE_SPI2_PIN_CS4,
+#endif
+#ifdef CYGHWR_FREESCALE_DSPI2_CS5
+ CYGHWR_IO_FREESCALE_SPI2_PIN_CS5
+#endif
+};
+
+#ifdef CYGINT_DEVS_SPI_DSPI2_USES_DMA
+ DSPI_EDMA_CHAN_SET(2);
+# define DSPI2_EDMA_SET_P DSPI_EDMA_SET_P_YES(2)
+# define DSPI2_EDMA_TCD DSPI_EDMA_TCD_YES(2)
+#else
+# define DSPI2_EDMA_SET_P DSPI_EDMA_SET_P_NULL(2)
+# define DSPI2_EDMA_TCD DSPI_EDMA_TCD_NULL(2)
+#endif // CYGINT_DEVS_SPI_DSPI2_USES_DMA
+
+DSPI_BUS_PINS(2);
+DSPI_BUS_SETUP(2);
+DSPI_BUS(2);
+
+#endif // CYGHWR_DEVS_SPI_FREESCALE_DSPI2
+
+// DSPI BUS 3 ================================================================
+#ifdef CYGHWR_DEVS_SPI_FREESCALE_DSPI3
+
+#define CYGBLD_DSPI3_TCD_SECTION \
+ CYGBLD_ATTRIB_SECTION(CYGOPT_DEVS_SPI_FREESCALE_DSPI3_TCD_SECTION)
+
+#ifdef CYHGWR_DEVS_SPI_FREESCALE_DSPI3_PCSS
+#define CYGHWR_FREESCALE_DSPI3_MCR_PCSSE FREESCALE_DSPI_MCR_PCSSE_M
+#else
+#define CYGHWR_FREESCALE_DSPI3_MCR_PCSSE 0
+#endif
+
+// SPI chip select pins.
+static const cyg_uint32 spi3_cs_pins[] = {
+#ifdef CYGHWR_FREESCALE_DSPI3_CS0
+ CYGHWR_IO_FREESCALE_SPI3_PIN_CS0,
+#endif
+#ifdef CYGHWR_FREESCALE_DSPI3_CS1
+ CYGHWR_IO_FREESCALE_SPI3_PIN_CS1,
+#endif
+#ifdef CYGHWR_FREESCALE_DSPI3_CS2
+ CYGHWR_IO_FREESCALE_SPI3_PIN_CS2,
+#endif
+#ifdef CYGHWR_FREESCALE_DSPI3_CS3
+ CYGHWR_IO_FREESCALE_SPI3_PIN_CS3,
+#endif
+#ifdef CYGHWR_FREESCALE_DSPI3_CS4
+ CYGHWR_IO_FREESCALE_SPI3_PIN_CS4,
+#endif
+#ifdef CYGHWR_FREESCALE_DSPI3_CS5
+ CYGHWR_IO_FREESCALE_SPI3_PIN_CS5
+#endif
+};
+
+#ifdef CYGINT_DEVS_SPI_DSPI3_USES_DMA
+ DSPI_EDMA_CHAN_SET(3);
+# define DSPI3_EDMA_SET_P DSPI_EDMA_SET_P_YES(3)
+# define DSPI3_EDMA_TCD DSPI_EDMA_TCD_YES(3)
+#else
+# define DSPI3_EDMA_SET_P DSPI_EDMA_SET_P_NULL(3)
+# define DSPI3_EDMA_TCD DSPI_EDMA_TCD_NULL(3)
+#endif // CYGINT_DEVS_SPI_DSPI3_USES_DMA
+
+DSPI_BUS_PINS(3);
+DSPI_BUS_SETUP(3);
+DSPI_BUS(3);
+
+#endif // CYGHWR_DEVS_SPI_FREESCALE_DSPI3
+
+// DSPI BUS 4 ================================================================
+#ifdef CYGHWR_DEVS_SPI_FREESCALE_DSPI4
+
+#define CYGBLD_DSPI4_TCD_SECTION \
+ CYGBLD_ATTRIB_SECTION(CYGOPT_DEVS_SPI_FREESCALE_DSPI4_TCD_SECTION)
+
+#ifdef CYHGWR_DEVS_SPI_FREESCALE_DSPI4_PCSS
+#define CYGHWR_FREESCALE_DSPI4_MCR_PCSSE FREESCALE_DSPI_MCR_PCSSE_M
+#else
+#define CYGHWR_FREESCALE_DSPI4_MCR_PCSSE 0
+#endif
+
+// SPI chip select pins.
+static const cyg_uint32 spi4_cs_pins[] = {
+#ifdef CYGHWR_FREESCALE_DSPI4_CS0
+ CYGHWR_IO_FREESCALE_SPI4_PIN_CS0,
+#endif
+#ifdef CYGHWR_FREESCALE_DSPI4_CS1
+ CYGHWR_IO_FREESCALE_SPI4_PIN_CS1,
+#endif
+#ifdef CYGHWR_FREESCALE_DSPI4_CS2
+ CYGHWR_IO_FREESCALE_SPI4_PIN_CS2,
+#endif
+#ifdef CYGHWR_FREESCALE_DSPI4_CS3
+ CYGHWR_IO_FREESCALE_SPI4_PIN_CS3,
+#endif
+#ifdef CYGHWR_FREESCALE_DSPI4_CS4
+ CYGHWR_IO_FREESCALE_SPI4_PIN_CS4,
+#endif
+#ifdef CYGHWR_FREESCALE_DSPI4_CS5
+ CYGHWR_IO_FREESCALE_SPI4_PIN_CS5
+#endif
+};
+
+#ifdef CYGINT_DEVS_SPI_DSPI4_USES_DMA
+ DSPI_EDMA_CHAN_SET(4);
+# define DSPI4_EDMA_SET_P DSPI_EDMA_SET_P_YES(4)
+# define DSPI4_EDMA_TCD DSPI_EDMA_TCD_YES(4)
+#else
+# define DSPI4_EDMA_SET_P DSPI_EDMA_SET_P_NULL(4)
+# define DSPI4_EDMA_TCD DSPI_EDMA_TCD_NULL(4)
+#endif // CYGINT_DEVS_SPI_DSPI4_USES_DMA
+
+DSPI_BUS_PINS(4);
+DSPI_BUS_SETUP(4);
+DSPI_BUS(4);
+
+#endif // CYGHWR_DEVS_SPI_FREESCALE_DSPI4
+
+// DSPI BUS 5 ================================================================
+#ifdef CYGHWR_DEVS_SPI_FREESCALE_DSPI5
+
+#define CYGBLD_DSPI5_TCD_SECTION \
+ CYGBLD_ATTRIB_SECTION(CYGOPT_DEVS_SPI_FREESCALE_DSPI5_TCD_SECTION)
+
+#ifdef CYHGWR_DEVS_SPI_FREESCALE_DSPI5_PCSS
+#define CYGHWR_FREESCALE_DSPI5_MCR_PCSSE FREESCALE_DSPI_MCR_PCSSE_M
+#else
+#define CYGHWR_FREESCALE_DSPI5_MCR_PCSSE 0
+#endif
+
+// SPI chip select pins.
+static const cyg_uint32 spi5_cs_pins[] = {
+#ifdef CYGHWR_FREESCALE_DSPI5_CS0
+ CYGHWR_IO_FREESCALE_SPI5_PIN_CS0,
+#endif
+#ifdef CYGHWR_FREESCALE_DSPI5_CS1
+ CYGHWR_IO_FREESCALE_SPI5_PIN_CS1,
+#endif
+#ifdef CYGHWR_FREESCALE_DSPI5_CS2
+ CYGHWR_IO_FREESCALE_SPI5_PIN_CS2,
+#endif
+#ifdef CYGHWR_FREESCALE_DSPI5_CS3
+ CYGHWR_IO_FREESCALE_SPI5_PIN_CS3,
+#endif
+#ifdef CYGHWR_FREESCALE_DSPI5_CS4
+ CYGHWR_IO_FREESCALE_SPI5_PIN_CS4,
+#endif
+#ifdef CYGHWR_FREESCALE_DSPI5_CS5
+ CYGHWR_IO_FREESCALE_SPI5_PIN_CS5
+#endif
+};
+
+#ifdef CYGINT_DEVS_SPI_DSPI5_USES_DMA
+ DSPI_EDMA_CHAN_SET(5);
+# define DSPI5_EDMA_SET_P DSPI_EDMA_SET_P_YES(5)
+# define DSPI5_EDMA_TCD DSPI_EDMA_TCD_YES(5)
+#else
+# define DSPI5_EDMA_SET_P DSPI_EDMA_SET_P_NULL(5)
+# define DSPI5_EDMA_TCD DSPI_EDMA_TCD_NULL(5)
+#endif // CYGINT_DEVS_SPI_DSPI5_USES_DMA
+
+DSPI_BUS_PINS(5);
+DSPI_BUS_SETUP(5);
+DSPI_BUS(5);
+
+#endif // CYGHWR_DEVS_SPI_FREESCALE_DSPI5
+
+// DSPI BUS 6 ================================================================
+#ifdef CYGHWR_DEVS_SPI_FREESCALE_DSPI6
+
+#define CYGBLD_DSPI6_TCD_SECTION \
+ CYGBLD_ATTRIB_SECTION(CYGOPT_DEVS_SPI_FREESCALE_DSPI6_TCD_SECTION)
+
+#ifdef CYHGWR_DEVS_SPI_FREESCALE_DSPI6_PCSS
+#define CYGHWR_FREESCALE_DSPI6_MCR_PCSSE FREESCALE_DSPI_MCR_PCSSE_M
+#else
+#define CYGHWR_FREESCALE_DSPI6_MCR_PCSSE 0
+#endif
+
+// SPI chip select pins.
+static const cyg_uint32 spi6_cs_pins[] = {
+#ifdef CYGHWR_FREESCALE_DSPI6_CS0
+ CYGHWR_IO_FREESCALE_SPI6_PIN_CS0,
+#endif
+#ifdef CYGHWR_FREESCALE_DSPI6_CS1
+ CYGHWR_IO_FREESCALE_SPI6_PIN_CS1,
+#endif
+#ifdef CYGHWR_FREESCALE_DSPI6_CS2
+ CYGHWR_IO_FREESCALE_SPI6_PIN_CS2,
+#endif
+#ifdef CYGHWR_FREESCALE_DSPI6_CS3
+ CYGHWR_IO_FREESCALE_SPI6_PIN_CS3,
+#endif
+#ifdef CYGHWR_FREESCALE_DSPI6_CS4
+ CYGHWR_IO_FREESCALE_SPI6_PIN_CS4,
+#endif
+#ifdef CYGHWR_FREESCALE_DSPI6_CS5
+ CYGHWR_IO_FREESCALE_SPI6_PIN_CS5
+#endif
+};
+
+#ifdef CYGINT_DEVS_SPI_DSPI6_USES_DMA
+ DSPI_EDMA_CHAN_SET(6);
+# define DSPI6_EDMA_SET_P DSPI_EDMA_SET_P_YES(6)
+# define DSPI6_EDMA_TCD DSPI_EDMA_TCD_YES(6)
+#else
+# define DSPI6_EDMA_SET_P DSPI_EDMA_SET_P_NULL(6)
+# define DSPI6_EDMA_TCD DSPI_EDMA_TCD_NULL(6)
+#endif // CYGINT_DEVS_SPI_DSPI6_USES_DMA
+
+DSPI_BUS_PINS(6);
+DSPI_BUS_SETUP(6);
+DSPI_BUS(6);
+
+#endif // CYGHWR_DEVS_SPI_FREESCALE_DSPI6
+
+// DSPI BUS 7 ================================================================
+#ifdef CYGHWR_DEVS_SPI_FREESCALE_DSPI7
+
+#define CYGBLD_DSPI7_TCD_SECTION \
+ CYGBLD_ATTRIB_SECTION(CYGOPT_DEVS_SPI_FREESCALE_DSPI7_TCD_SECTION)
+
+#ifdef CYHGWR_DEVS_SPI_FREESCALE_DSPI7_PCSS
+#define CYGHWR_FREESCALE_DSPI7_MCR_PCSSE FREESCALE_DSPI_MCR_PCSSE_M
+#else
+#define CYGHWR_FREESCALE_DSPI7_MCR_PCSSE 0
+#endif
+
+// SPI chip select pins.
+static const cyg_uint32 spi7_cs_pins[] = {
+#ifdef CYGHWR_FREESCALE_DSPI7_CS0
+ CYGHWR_IO_FREESCALE_SPI7_PIN_CS0,
+#endif
+#ifdef CYGHWR_FREESCALE_DSPI7_CS1
+ CYGHWR_IO_FREESCALE_SPI7_PIN_CS1,
+#endif
+#ifdef CYGHWR_FREESCALE_DSPI7_CS2
+ CYGHWR_IO_FREESCALE_SPI7_PIN_CS2,
+#endif
+#ifdef CYGHWR_FREESCALE_DSPI7_CS3
+ CYGHWR_IO_FREESCALE_SPI7_PIN_CS3,
+#endif
+#ifdef CYGHWR_FREESCALE_DSPI7_CS4
+ CYGHWR_IO_FREESCALE_SPI7_PIN_CS4,
+#endif
+#ifdef CYGHWR_FREESCALE_DSPI7_CS5
+ CYGHWR_IO_FREESCALE_SPI7_PIN_CS5
+#endif
+};
+
+#ifdef CYGINT_DEVS_SPI_DSPI7_USES_DMA
+ DSPI_EDMA_CHAN_SET(7);
+# define DSPI7_EDMA_SET_P DSPI_EDMA_SET_P_YES(7)
+# define DSPI7_EDMA_TCD DSPI_EDMA_TCD_YES(7)
+#else
+# define DSPI7_EDMA_SET_P DSPI_EDMA_SET_P_NULL(7)
+# define DSPI7_EDMA_TCD DSPI_EDMA_TCD_NULL(7)
+#endif // CYGINT_DEVS_SPI_DSPI7_USES_DMA
+
+DSPI_BUS_PINS(7);
+DSPI_BUS_SETUP(7);
+DSPI_BUS(7);
+
+#endif // CYGHWR_DEVS_SPI_FREESCALE_DSPI7
+
+//=============================================================================
+#endif // SPI_FREESCALE_DSPI_BUSES_INL
diff --git a/ecos/packages/devs/spi/freescale/dspi/current/include/spi_freescale_dspi_io.h b/ecos/packages/devs/spi/freescale/dspi/current/include/spi_freescale_dspi_io.h
new file mode 100644
index 0000000..798160e
--- /dev/null
+++ b/ecos/packages/devs/spi/freescale/dspi/current/include/spi_freescale_dspi_io.h
@@ -0,0 +1,292 @@
+#ifndef CYGONCE_DEVS_SPI_FREESCALE_DSPI_IO_H
+#define CYGONCE_DEVS_SPI_FREESCALE_DSPI_IO_H
+//=============================================================================
+//
+// spi_freescale_dspi_io.h
+//
+// IO definitions for Freescale DSPI.
+//
+//=============================================================================
+// ####ECOSGPLCOPYRIGHTBEGIN####
+// -------------------------------------------
+// This file is part of eCos, the Embedded Configurable Operating System.
+// Copyright (C) 2011 Free Software Foundation, Inc.
+//
+// eCos is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 2 or (at your option) any later
+// version.
+//
+// eCos is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with eCos; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// As a special exception, if other files instantiate templates or use
+// macros or inline functions from this file, or you compile this file
+// and link it with other works to produce a work based on this file,
+// this file does not by itself cause the resulting work to be covered by
+// the GNU General Public License. However the source code for this file
+// must still be made available in accordance with section (3) of the GNU
+// General Public License v2.
+//
+// This exception does not invalidate any other reasons why a work based
+// on this file might be covered by the GNU General Public License.
+// -------------------------------------------
+// ####ECOSGPLCOPYRIGHTEND####
+//=============================================================================
+//#####DESCRIPTIONBEGIN####
+//
+// Author(s): ilijak
+// Date: 2011-11-03
+// Purpose: Freescale DSPI I/O definitions.
+// Description:
+// Usage: #include <cyg/io/spi_freescale_dspi_io.h>
+//
+//####DESCRIPTIONEND####
+//
+//=============================================================================
+
+
+// ----------------------------------------------------------------------------
+// DSPI
+
+typedef volatile struct cyghwr_devs_freescale_dspi_s {
+ cyg_uint32 mcr; // Module Configuration Register
+ cyg_uint32 reserved_0;
+ cyg_uint32 tcr; // Transfer Count Register
+ // Clock and Transfer Attributes Register
+ cyg_uint32 ctar[CYGHWR_DEVS_SPI_FREESCALE_DSPI_CTAR_NUM];
+#if CYGHWR_DEVS_SPI_FREESCALE_DSPI_CTAR_NUM < 8
+ cyg_uint32 reserved_1[8-CYGHWR_DEVS_SPI_FREESCALE_DSPI_CTAR_NUM];
+#endif
+ cyg_uint32 sr; // Status Register
+ cyg_uint32 rser; // DMA/IRQ Request Select and Enable Register
+ cyg_uint32 pushr; // TX FIFO PUSH Register
+ cyg_uint32 popr; // RX FIFO POP Register
+ // Transmit FIFO Registers
+ cyg_uint32 txfr[CYGHWR_DEVS_SPI_FREESCALE_DSPI_FIFO_SIZE];
+#if CYGHWR_DEVS_SPI_FREESCALE_DSPI_FIFO_SIZE < 16
+ cyg_uint32 reserved_2[16-CYGHWR_DEVS_SPI_FREESCALE_DSPI_FIFO_SIZE];
+#endif
+ // Receive FIFO Registers
+ cyg_uint32 rxfr[CYGHWR_DEVS_SPI_FREESCALE_DSPI_FIFO_SIZE];
+#if CYGHWR_DEVS_SPI_FREESCALE_DSPI_FIFO_SIZE < 16
+ cyg_uint32 reserved_3[16-CYGHWR_DEVS_SPI_FREESCALE_DSPI_FIFO_SIZE];
+#endif
+} cyghwr_devs_freescale_dspi_t;
+
+// MCR Bit Fields
+#define FREESCALE_DSPI_MCR_HALT_M 0x1
+#define FREESCALE_DSPI_MCR_HALT_S 0
+#define FREESCALE_DSPI_MCR_SMPL_PT_M 0x300
+#define FREESCALE_DSPI_MCR_SMPL_PT_S 8
+#define FREESCALE_DSPI_MCR_SMPL_PT(__val) \
+ VALUE_(FREESCALE_DSPI_MCR_SMPL_PT_S, __val)
+#define FREESCALE_DSPI_MCR_CLR_RXF_M 0x400
+#define FREESCALE_DSPI_MCR_CLR_RXF_S 10
+#define FREESCALE_DSPI_MCR_CLR_TXF_M 0x800
+#define FREESCALE_DSPI_MCR_CLR_TXF_S 11
+#define FREESCALE_DSPI_MCR_DIS_RXF_M 0x1000
+#define FREESCALE_DSPI_MCR_DIS_RXF_S 12
+#define FREESCALE_DSPI_MCR_DIS_TXF_M 0x2000
+#define FREESCALE_DSPI_MCR_DIS_TXF_S 13
+#define FREESCALE_DSPI_MCR_MDIS_M 0x4000
+#define FREESCALE_DSPI_MCR_MDIS_S 14
+#define FREESCALE_DSPI_MCR_DOZE_M 0x8000
+#define FREESCALE_DSPI_MCR_DOZE_S 15
+#define FREESCALE_DSPI_MCR_PCSIS_M 0x3F0000
+#define FREESCALE_DSPI_MCR_PCSIS_S 16
+#define FREESCALE_DSPI_MCR_PCSIS(__val) \
+ VALUE_(FREESCALE_DSPI_MCR_PCSIS_S, __val)
+#define FREESCALE_DSPI_MCR_ROOE_M 0x1000000
+#define FREESCALE_DSPI_MCR_ROOE_S 24
+#define FREESCALE_DSPI_MCR_PCSSE_M 0x2000000
+#define FREESCALE_DSPI_MCR_PCSSE_S 25
+#define FREESCALE_DSPI_MCR_MTFE_M 0x4000000
+#define FREESCALE_DSPI_MCR_MTFE_S 26
+#define FREESCALE_DSPI_MCR_FRZ_M 0x8000000
+#define FREESCALE_DSPI_MCR_FRZ_S 27
+#define FREESCALE_DSPI_MCR_DCONF_M 0x30000000
+#define FREESCALE_DSPI_MCR_DCONF_S 28
+#define FREESCALE_DSPI_MCR_DCONF(__val) \
+ VALUE_(FREESCALE_DSPI_MCR_DCONF_S, __val)
+#define FREESCALE_DSPI_MCR_CONT_SCKE_M 0x40000000
+#define FREESCALE_DSPI_MCR_CONT_SCKE_S 30
+#define FREESCALE_DSPI_MCR_MSTR_M 0x80000000
+#define FREESCALE_DSPI_MCR_MSTR_S 31
+// TCR Bit Fields
+#define FREESCALE_DSPI_TCR_DSPI_TCNT_M 0xFFFF0000
+#define FREESCALE_DSPI_TCR_DSPI_TCNT_S 16
+#define FREESCALE_DSPI_TCR_DSPI_TCNT(__val) \
+ VALUE_(FREESCALE_DSPI_TCR_DSPI_TCNT_S, __val)
+// CTAR Bit Fields
+#define FREESCALE_DSPI_CTAR_BR_M 0xF
+#define FREESCALE_DSPI_CTAR_BR_S 0
+#define FREESCALE_DSPI_CTAR_BR(__val) \
+ VALUE_(FREESCALE_DSPI_CTAR_BR_S, __val)
+#define FREESCALE_DSPI_CTAR_DT_M 0xF0
+#define FREESCALE_DSPI_CTAR_DT_S 4
+#define FREESCALE_DSPI_CTAR_DT(__val) \
+ VALUE_(FREESCALE_DSPI_CTAR_DT_S, __val)
+#define FREESCALE_DSPI_CTAR_ASC_M 0xF00
+#define FREESCALE_DSPI_CTAR_ASC_S 8
+#define FREESCALE_DSPI_CTAR_ASC(__val) \
+ VALUE_(FREESCALE_DSPI_CTAR_ASC_S, __val)
+#define FREESCALE_DSPI_CTAR_CSSCK_M 0xF000
+#define FREESCALE_DSPI_CTAR_CSSCK_S 12
+#define FREESCALE_DSPI_CTAR_CSSCK(__val) \
+ VALUE_(FREESCALE_DSPI_CTAR_CSSCK_S, __val)
+#define FREESCALE_DSPI_CTAR_PBR_M 0x30000
+#define FREESCALE_DSPI_CTAR_PBR_S 16
+#define FREESCALE_DSPI_CTAR_PBR(__val) \
+ VALUE_(FREESCALE_DSPI_CTAR_PBR_S, __val)
+#define FREESCALE_DSPI_CTAR_PDT_M 0xC0000
+#define FREESCALE_DSPI_CTAR_PDT_S 18
+#define FREESCALE_DSPI_CTAR_PDT(__val) \
+ VALUE_(FREESCALE_DSPI_CTAR_PDT_S, __val)
+#define FREESCALE_DSPI_CTAR_PASC_M 0x300000
+#define FREESCALE_DSPI_CTAR_PASC_S 20
+#define FREESCALE_DSPI_CTAR_PASC(__val) \
+ VALUE_(FREESCALE_DSPI_CTAR_PASC_S, __val)
+#define FREESCALE_DSPI_CTAR_PCSSCK_S 22
+#define FREESCALE_DSPI_CTAR_PCSSCK(__val) \
+ VALUE_(FREESCALE_DSPI_CTAR_PCSSCK_S, __val)
+#define FREESCALE_DSPI_CTAR_LSBFE_S 24
+#define FREESCALE_DSPI_CTAR_LSBFE_M 0x1000000
+
+#define FREESCALE_DSPI_CTAR_FMSZ_M 0x78000000
+#define FREESCALE_DSPI_CTAR_FMSZ_S 27
+#define FREESCALE_DSPI_CTAR_FMSZ(__val) \
+ VALUE_(FREESCALE_DSPI_CTAR_FMSZ_S, __val)
+#define FREESCALE_DSPI_CTAR_DBR_M 0x80000000
+#define FREESCALE_DSPI_CTAR_DBR_S 31
+// CTAR_SLAVE Bit Fields
+#define FREESCALE_DSPI_CTAR_SLAVE_CPHA_M 0x2000000
+#define FREESCALE_DSPI_CTAR_SLAVE_CPHA_S 25
+#define FREESCALE_DSPI_CTAR_SLAVE_CPOL_M 0x4000000
+#define FREESCALE_DSPI_CTAR_SLAVE_CPOL_S 26
+#define FREESCALE_DSPI_CTAR_SLAVE_FMSZ_M 0xF8000000
+#define FREESCALE_DSPI_CTAR_SLAVE_FMSZ_S 27
+#define FREESCALE_DSPI_CTAR_SLAVE_FMSZ(__val) \
+ VALUE_(FREESCALE_DSPI_CTAR_SLAVE_FMSZ_S, __val)
+// SR Bit Fields
+#define FREESCALE_DSPI_SR_POPNXTPTR_M 0xF
+#define FREESCALE_DSPI_SR_POPNXTPTR_S 0
+#define FREESCALE_DSPI_SR_POPNXTPTR(__val) \
+ VALUE_(FREESCALE_DSPI_SR_POPNXTPTR_S, __val)
+#define FREESCALE_DSPI_SR_RXCTR_M 0xF0
+#define FREESCALE_DSPI_SR_RXCTR_S 4
+#define FREESCALE_DSPI_SR_RXCTR(__val) \
+ VALUE_(FREESCALE_DSPI_SR_RXCTR_S, __val)
+#define FREESCALE_DSPI_SR_TXNXTPTR_M 0xF00
+#define FREESCALE_DSPI_SR_TXNXTPTR_S 8
+#define FREESCALE_DSPI_SR_TXNXTPTR(__val) \
+ VALUE_(FREESCALE_DSPI_SR_TXNXTPTR_S, __val)
+#define FREESCALE_DSPI_SR_TXCTR_M 0xF000
+#define FREESCALE_DSPI_SR_TXCTR_S 12
+#define FREESCALE_DSPI_SR_TXCTR(__val) \
+ VALUE_(FREESCALE_DSPI_SR_TXCTR_S, __val)
+#define FREESCALE_DSPI_SR_RFDF_M 0x20000
+#define FREESCALE_DSPI_SR_RFDF_S 17
+#define FREESCALE_DSPI_SR_RFOF_M 0x80000
+#define FREESCALE_DSPI_SR_RFOF_S 19
+#define FREESCALE_DSPI_SR_TFFF_M 0x2000000
+#define FREESCALE_DSPI_SR_TFFF_S 25
+#define FREESCALE_DSPI_SR_TFUF_M 0x8000000
+#define FREESCALE_DSPI_SR_TFUF_S 27
+#define FREESCALE_DSPI_SR_EOQF_M 0x10000000
+#define FREESCALE_DSPI_SR_EOQF_S 28
+#define FREESCALE_DSPI_SR_TXRXS_M 0x40000000
+#define FREESCALE_DSPI_SR_TXRXS_S 30
+#define FREESCALE_DSPI_SR_TCF_M 0x80000000
+#define FREESCALE_DSPI_SR_TCF_S 31
+
+#define FREESCALE_DSPI_CLEAR_FIFOS (FREESCALE_DSPI_SR_TFUF_M |\
+ FREESCALE_DSPI_SR_RFOF_M)
+
+// RSER Bit Fields
+#define FREESCALE_DSPI_RSER_RFDF_DIRS_M 0x10000
+#define FREESCALE_DSPI_RSER_RFDF_DIRS_S 16
+#define FREESCALE_DSPI_RSER_RFDF_RE_M 0x20000
+#define FREESCALE_DSPI_RSER_RFDF_RE_S 17
+#define FREESCALE_DSPI_RSER_RFOF_RE_M 0x80000
+#define FREESCALE_DSPI_RSER_RFOF_RE_S 19
+#define FREESCALE_DSPI_RSER_TFFF_DIRS_M 0x1000000
+#define FREESCALE_DSPI_RSER_TFFF_DIRS_S 24
+#define FREESCALE_DSPI_RSER_TFFF_RE_M 0x2000000
+#define FREESCALE_DSPI_RSER_TFFF_RE_S 25
+#define FREESCALE_DSPI_RSER_TFUF_RE_M 0x8000000
+#define FREESCALE_DSPI_RSER_TFUF_RE_S 27
+#define FREESCALE_DSPI_RSER_EOQF_RE_M 0x10000000
+#define FREESCALE_DSPI_RSER_EOQF_RE_S 28
+#define FREESCALE_DSPI_RSER_TCF_RE_M 0x80000000
+#define FREESCALE_DSPI_RSER_TCF_RE_S 31
+// PUSHR Bit Fields
+#define FREESCALE_DSPI_PUSHR_TXDATA_M 0xFFFF
+#define FREESCALE_DSPI_PUSHR_TXDATA_S 0
+#define FREESCALE_DSPI_PUSHR_TXDATA(__val) \
+ VALUE_(FREESCALE_DSPI_PUSHR_TXDATA_S, __val)
+#define FREESCALE_DSPI_PUSHR_PCS_M 0x3F0000
+#define FREESCALE_DSPI_PUSHR_PCS_S 16
+#define FREESCALE_DSPI_PUSHR_PCS(__val) VALUE_(FREESCALE_DSPI_PUSHR_PCS_S, __val)
+#define FREESCALE_DSPI_PUSHR_CTCNT_M 0x4000000
+#define FREESCALE_DSPI_PUSHR_CTCNT_S 26
+#define FREESCALE_DSPI_PUSHR_EOQ_M 0x8000000
+#define FREESCALE_DSPI_PUSHR_EOQ_S 27
+#define FREESCALE_DSPI_PUSHR_CTAS_M 0x70000000
+#define FREESCALE_DSPI_PUSHR_CTAS_S 28
+#define FREESCALE_DSPI_PUSHR_CTAS(__val) \
+ VALUE_(FREESCALE_DSPI_PUSHR_CTAS_S, __val)
+#define FREESCALE_DSPI_PUSHR_CONT_M 0x80000000
+#define FREESCALE_DSPI_PUSHR_CONT_S 31
+// PUSHR_SLAVE Bit Fields
+#define FREESCALE_DSPI_PUSHR_SLAVE_TXDATA_M 0xFFFFFFFF
+#define FREESCALE_DSPI_PUSHR_SLAVE_TXDATA_S 0
+#define FREESCALE_DSPI_PUSHR_SLAVE_TXDATA(__val) \
+VALUE_(FREESCALE_DSPI_PUSHR_SLAVE_TXDATA_S, __val)
+
+#define FREESCALE_DSPI_PUSHR_PCS_CLEAR(__val)\
+CYG_MACRO_START\
+ __val &= ~FREESCALE_DSPI_PUSHR_PCS_M; \
+CYG_MACRO_END
+
+// POPR Bit Fields
+#define FREESCALE_DSPI_POPR_RXDATA_M 0xFFFFFFFF
+#define FREESCALE_DSPI_POPR_RXDATA_S 0
+#define FREESCALE_DSPI_POPR_RXDATA(__val) \
+ VALUE_(FREESCALE_DSPI_POPR_RXDATA_S, __val)
+// TXFR Bit Fields
+#define FREESCALE_DSPI_TXFR_TXDATA_M 0xFFFF
+#define FREESCALE_DSPI_TXFR_TXDATA_S 0
+#define FREESCALE_DSPI_TXFR_TXCMD_TXDATA_M 0xFFFF0000
+#define FREESCALE_DSPI_TXFR_TXCMD_TXDATA_S 16
+#define FREESCALE_DSPI_TXFR_TXCMD_TXDATA(__fr,__val) \
+ VALUE_(FREESCALE_DSPI_TXFR##__fr##_TXCMD_TXDATA_S, __val)
+// RXFR Bit Fields
+#define FREESCALE_DSPI_RXFR_RXDATA_M 0xFFFFFFFF
+#define FREESCALE_DSPI_RXFR_RXDATA_S 0
+#define FREESCALE_DSPI_RXFR_RXDATA(__fr,__val) \
+ VALUE_(FREESCALE_DSPI_RXFR##_fr##_RXDATA_S, __val)
+
+// Borrow following macros from HAL
+
+// CYGADDR_IO_SPI_FREESCALE_DSPIx_P
+
+// CYGHWR_IO_CLOCK_ENABLE(__clkgate)
+// CYGHWR_IO_FREESCALE_DSPIx_CLK
+
+// CYGHWR_IO_FREESCALE_DSPI_PIN(__pin)
+
+// CYGHWR_IO_FREESCALE_SPIx_PIN_SIN
+// CYGHWR_IO_FREESCALE_SPIx_PIN_SOUT
+// CYGHWR_IO_FREESCALE_SPIx_PIN_SCK
+
+// CYGHWR_IO_FREESCALE_SPIx_PIN_CSn
+
+//=============================================================================
+#endif // CYGONCE_DEVS_SPI_FREESCALE_DSPI_IO_H
diff --git a/ecos/packages/devs/spi/freescale/dspi/current/src/spi_freescale_dspi.c b/ecos/packages/devs/spi/freescale/dspi/current/src/spi_freescale_dspi.c
new file mode 100644
index 0000000..b6842e1
--- /dev/null
+++ b/ecos/packages/devs/spi/freescale/dspi/current/src/spi_freescale_dspi.c
@@ -0,0 +1,1190 @@
+//=============================================================================
+//
+// spi_freescale_dspi.c
+//
+// SPI driver implementation for Freescale DSPI
+//
+//=============================================================================
+// ####ECOSGPLCOPYRIGHTBEGIN####
+// -------------------------------------------
+// This file is part of eCos, the Embedded Configurable Operating System.
+// Copyright (C) 2011, 2013 Free Software Foundation, Inc.
+//
+// eCos is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 2 or (at your option) any later
+// version.
+//
+// eCos is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with eCos; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// As a special exception, if other files instantiate templates or use
+// macros or inline functions from this file, or you compile this file
+// and link it with other works to produce a work based on this file,
+// this file does not by itself cause the resulting work to be covered by
+// the GNU General Public License. However the source code for this file
+// must still be made available in accordance with section (3) of the GNU
+// General Public License v2.
+//
+// This exception does not invalidate any other reasons why a work based
+// on this file might be covered by the GNU General Public License.
+// -------------------------------------------
+// ####ECOSGPLCOPYRIGHTEND####
+//=============================================================================
+//#####DESCRIPTIONBEGIN####
+//
+// Author(s): ilijak
+// Date: 2011-11-04
+// Purpose: Freescale DSPI SPI driver implementation
+//
+//####DESCRIPTIONEND####
+//
+//=============================================================================
+
+#include <pkgconf/hal.h>
+#include <string.h>
+#include <cyg/hal/hal_io.h>
+#include <cyg/hal/hal_if.h>
+#include <cyg/hal/hal_intr.h>
+#include <cyg/hal/drv_api.h>
+#include <cyg/hal/hal_cache.h>
+
+#include <cyg/infra/cyg_type.h>
+#include <cyg/infra/cyg_ass.h>
+#include <cyg/infra/diag.h>
+
+#include <cyg/io/spi.h>
+#include <cyg/hal/hal_endian.h>
+
+#include <pkgconf/devs_spi_freescale_dspi.h>
+#if defined(CYGHWR_DEVS_SPI_FREESCALE_DSPI0) || \
+ defined(CYGHWR_DEVS_SPI_FREESCALE_DSPI1) || \
+ defined(CYGHWR_DEVS_SPI_FREESCALE_DSPI2)
+
+#include <cyg/io/spi_freescale_dspi.h>
+
+
+#define DEBUG_SPI CYGPKG_DEVS_SPI_FREESCALE_DSPI_DEBUG_LEVEL
+
+#if DEBUG_SPI >= 3
+# define DEBUG3_PRINTF(args...) diag_printf(args)
+#else
+# define DEBUG3_PRINTF(args...)
+#endif
+
+#if DEBUG_SPI >= 2
+# define DEBUG2_PRINTF(args...) diag_printf(args)
+#else
+# define DEBUG2_PRINTF(args...)
+#endif
+
+#if DEBUG_SPI >= 1
+# define DEBUG1_PRINTF(args...) diag_printf(args)
+#else
+# define DEBUG1_PRINTF(args...)
+#endif
+
+# define DEBUG0_PRINTF(args...) diag_printf(args)
+
+#define PUSHR_NULL (0xFFFF)
+
+//-----------------------------------------------------------------------------
+// API function call forward references.
+
+static void dspi_transaction_begin (cyg_spi_device*);
+static void dspi_transaction_transfer (cyg_spi_device*, cyg_bool, cyg_uint32,
+ const cyg_uint8*, cyg_uint8*, cyg_bool);
+static void dspi_transaction_tick (cyg_spi_device*, cyg_bool, cyg_uint32);
+static void dspi_transaction_end (cyg_spi_device*);
+static int dspi_get_config (cyg_spi_device*, cyg_uint32,
+ void*, cyg_uint32*);
+static int dspi_set_config (cyg_spi_device*, cyg_uint32,
+ const void*, cyg_uint32*);
+
+//-----------------------------------------------------------------------------
+// Instantiate the bus state data structures.
+
+#include <cyg/io/spi_freescale_dspi_buses.inl>
+
+// Some hardware manipulation inline functions and macros
+
+static inline void dspi_disable(cyghwr_devs_freescale_dspi_t* dspi_p)
+{
+ dspi_p->mcr |= FREESCALE_DSPI_MCR_MDIS_M;
+}
+
+static inline void dspi_enable(cyghwr_devs_freescale_dspi_t* dspi_p)
+{
+ dspi_p->mcr &= ~FREESCALE_DSPI_MCR_MDIS_M;
+}
+
+static inline void dspi_halt(cyghwr_devs_freescale_dspi_t* dspi_p)
+{
+ dspi_p->mcr |= FREESCALE_DSPI_MCR_HALT_M;
+}
+
+static inline void dspi_tlah(cyghwr_devs_freescale_dspi_t* dspi_p)
+{
+ dspi_p->mcr &= ~FREESCALE_DSPI_MCR_HALT_M;
+}
+
+static inline void
+dspi_irq_enable(cyghwr_devs_freescale_dspi_t* dspi_p, cyg_uint32 irq_mask)
+{
+ dspi_p->rser |= irq_mask;
+}
+
+static inline void
+dspi_irq_disable(cyghwr_devs_freescale_dspi_t* dspi_p, cyg_uint32 irq_mask)
+{
+ dspi_p->rser &= ~irq_mask;
+}
+
+static inline void
+dspi_status_clear(cyghwr_devs_freescale_dspi_t* dspi_p, cyg_uint32 sr_mask)
+{
+ dspi_p->sr |= sr_mask;
+}
+
+static inline void
+dspi_fifo_clear(cyghwr_devs_freescale_dspi_t* dspi_p)
+{
+ dspi_p->mcr |= FREESCALE_DSPI_MCR_CLR_RXF_M | FREESCALE_DSPI_MCR_CLR_TXF_M;
+}
+
+static inline void
+dspi_fifo_drain(cyghwr_devs_freescale_dspi_t* dspi_p)
+{
+ dspi_p->sr |= FREESCALE_DSPI_SR_RFDF_M;
+}
+
+
+#define DSPI_IRQ_ENABLE(__dspi_p) \
+ dspi_irq_enable(__dspi_p, FREESCALE_DSPI_RSER_EOQF_RE_M)
+#define DSPI_IRQ_DISABLE(__dspi_p) \
+ dspi_irq_disable(__dspi_p, FREESCALE_DSPI_RSER_EOQF_RE_M)
+#define DSPI_EOQ_CLEAR(__dspi_p) \
+ dspi_status_clear(__dspi_p, FREESCALE_DSPI_SR_EOQF_M | \
+ FREESCALE_DSPI_SR_TCF_M | \
+ FREESCALE_DSPI_SR_RFDF_M)
+#define DSPI_TXRX_ENABLE(__dspi_p) \
+ dspi_status_clear(__dspi_p, FREESCALE_DSPI_SR_TXRXS_M)
+
+// Alternate clocking for spi_transaction_end()
+// Used to initialize CTAR1.
+static const cyg_freescale_dspi_clocking_t aux_clocking =
+{
+ .frame_size = 4,
+ .cl_pol = 0,
+ .cl_pha = 0,
+ .cl_brate = CYGHWR_DEVS_FREESCALEDSPI_DSPI_CTAR1_AUX_SPEED,
+ .cs_up_udly = CYGHWR_DEVS_FREESCALEDSPI_DSPI_CTAR1_AUX_CS_DELAY,
+ .cs_dw_udly = CYGHWR_DEVS_FREESCALEDSPI_DSPI_CTAR1_AUX_CS_DELAY,
+ .tr_bt_udly =CYGHWR_DEVS_FREESCALEDSPI_DSPI_CTAR1_AUX_CS_DELAY,
+ .dl_unit = CYGNUM_DSPI_DELAY_UNIT(
+ CYGHWR_DEVS_FREESCALE_DSPI_DSPI_CTAR1_AUX_DELAY_UNIT),
+ .cl_dbr = CYGHWR_DEVS_FREESCALEDSPI_DSPI_CTAR1_AUX_USE_DBR
+};
+
+//-----------------------------------------------------------------------------
+// Implement DSPI ISRs.
+
+// ISR for DSPI with DMA
+// Disable DSPI IRQ and Tx DMA channel and schedule DSR.
+static cyg_uint32 dspi_dma_ISR(cyg_vector_t vector, cyg_addrword_t data)
+{
+ cyg_spi_freescale_dspi_bus_t* dspi_bus_p =
+ (cyg_spi_freescale_dspi_bus_t*) data;
+ cyghwr_devs_freescale_dspi_t* dspi_p = dspi_bus_p->setup_p->dspi_p;
+ cyghwr_hal_freescale_dma_set_t *dma_set_p = dspi_bus_p->setup_p->dma_set_p;
+ cyghwr_hal_freescale_edma_t *edma_p;
+ edma_p = dma_set_p->edma_p;
+
+ cyg_drv_isr_lock();
+
+ // Disable the Tx DMA channel and DSPI IRQ.
+ hal_freescale_edma_erq_disable(edma_p, SPI_DMA_CHAN_I(dma_set_p, TX));
+ DSPI_IRQ_DISABLE(dspi_p);
+
+ cyg_drv_interrupt_acknowledge(vector);
+ cyg_drv_isr_unlock();
+ return (CYG_ISR_CALL_DSR | CYG_ISR_HANDLED);
+}
+
+// ISR for DSPI without DMA
+// Disable DSPI IRQ and schedule DSR.
+static cyg_uint32 dspi_nodma_ISR(cyg_vector_t vector, cyg_addrword_t data)
+{
+ cyg_spi_freescale_dspi_bus_t* dspi_bus_p =
+ (cyg_spi_freescale_dspi_bus_t*) data;
+ cyghwr_devs_freescale_dspi_t* dspi_p = dspi_bus_p->setup_p->dspi_p;
+
+ cyg_drv_isr_lock();
+
+ // Disable the DSPI IRQ.
+ DSPI_IRQ_DISABLE(dspi_p);
+
+ cyg_drv_interrupt_acknowledge(vector);
+ cyg_drv_isr_unlock();
+ return (CYG_ISR_CALL_DSR | CYG_ISR_HANDLED);
+}
+
+// DSPI DSR
+static void dspi_DSR(cyg_vector_t vector, cyg_ucount32 count, cyg_addrword_t data)
+{
+ cyg_spi_freescale_dspi_bus_t* dspi_bus = (cyg_spi_freescale_dspi_bus_t*) data;
+
+ cyg_drv_dsr_lock();
+ cyg_drv_cond_signal(&dspi_bus->transfer_done);
+ cyg_drv_dsr_unlock();
+}
+
+//-----------------------------------------------------------------------------
+// Calculate best fit CTAR baud rate setting (using some brute force).
+// Best fit is considered the highest frequency that is not highe than set point.
+
+static const cyg_uint16 ctar_br[16] = { 2/2, 4/2, 6/2, 8/2, 16/2, 32/2, 64/2,
+ 128/2, 256/2, 512/2, 1024/2, 2048/2, 4096/2, 8192/2, 16384/2, 32768/2 };
+static const cyg_uint8 ctar_pbr[4] = { 2, 3, 5, 7 };
+
+static const cyg_uint16 ctar_cssck[16] = { 2/2, 4/2, 8/2, 16/2, 32/2, 64/2,
+ 128/2, 256/2, 512/2, 1024/2, 2048/2, 4096/2, 8192/2, 16384/2, 32768/2,
+ 65536/2 };
+static const cyg_uint8 ctar_pcssck[4] = { 1, 3, 5, 7 };
+
+typedef struct ctar_br_s {
+ cyg_uint8 valid;
+ cyg_uint8 br;
+ cyg_uint8 dbr;
+ cyg_uint8 pbr;
+} ctar_br_t;
+
+static int dspi_ctar_brbf (const cyg_freescale_dspi_clocking_t* spi_cocking,
+ ctar_br_t* brs_p, const cyg_uint16* br_p,
+ const cyg_uint8* pbr_p, cyg_uint32* alt_brate,
+ cyg_uint32 sys_clk)
+{
+ cyg_uint32 pbr_i;
+ cyg_uint32 br_i;
+ cyg_uint32 dbr;
+ cyg_uint32 clk;
+ cyg_uint32 baud_bf = 0; // Best fit
+ cyg_uint32 baud_tmp;
+ cyg_uint32 baud_sp = alt_brate ? *alt_brate :
+ spi_cocking->cl_brate; // Set point
+
+ // Calculate the maximal viable bus speed.
+ clk = sys_clk;
+ // Desired baud rate very high, use DBR if allowed
+ dbr = (baud_sp > (clk / 4)) && spi_cocking->cl_dbr && (br_p == ctar_br);
+
+ for(pbr_i = 0; pbr_i < 3; pbr_i++) {
+ for(br_i = 0; br_i < 15; br_i++) {
+ if((baud_tmp = (clk * (1+dbr)) / (pbr_p[pbr_i] * (2*br_p[br_i])))
+ <= baud_sp)
+ {
+ if(baud_tmp > baud_bf) {
+ DEBUG3_PRINTF("DSPI Baud:"
+ " SP=%d pbr=0x%x br=0x%x dbr=%d Temp=%d (SysClk=%d)\n",
+ baud_sp, pbr_i, br_i, dbr, baud_tmp, clk);
+ brs_p->br = br_i;
+ brs_p->pbr = pbr_i;
+ brs_p->valid = 1;
+ baud_bf = baud_tmp;
+ if(baud_tmp == baud_sp)
+ goto baud_found;
+ }
+ }
+ }
+ }
+ if(!brs_p->valid) {
+ pbr_i = 3;
+ br_i = 15;
+ DEBUG1_PRINTF("DSPI Baud too low:"
+ " SP=%d pbr=0x%x br=0x%x Actual=%d (SysClk=%d)\n",
+ baud_sp, pbr_i, br_i,
+ (clk * (1+dbr)) / (pbr_p[pbr_i] * (2*br_p[br_i])), clk);
+ brs_p->br = br_i;
+ brs_p->pbr = pbr_i;
+
+ return -1;
+ } else {
+baud_found:
+ brs_p->dbr = dbr;
+ DEBUG1_PRINTF("DSPI Baud found:"
+ " SP=%d pbr=0x%x br=0x%x dbr=%d Actual=%dHz (%dns) (SysClk=%d)\n",
+ baud_sp, brs_p->pbr, brs_p->br, dbr, baud_bf, 1000000000/baud_bf, clk);
+
+ return 0;
+ }
+}
+
+// Set Clock and Transfer Attributes Register
+#define CYG_ASSERT_LOW_FREQ \
+ CYG_ASSERT (false, "Freescale DSPI: Cannot run bus as slowly as requested.")
+cyg_uint32
+dspi_calc_ctar(const cyg_freescale_dspi_clocking_t* spi_clocking, cyg_uint32 sys_clk)
+{
+ cyg_uint32 regval;
+ ctar_br_t brs;
+ cyg_uint32 delay_brate;
+
+ regval = FREESCALE_DSPI_CTAR_FMSZ(spi_clocking->frame_size - 1);
+ if(spi_clocking->cl_pol)
+ regval |= FREESCALE_DSPI_CTAR_SLAVE_CPOL_M;
+ if(spi_clocking->cl_pha)
+ regval |= FREESCALE_DSPI_CTAR_SLAVE_CPHA_M;
+ if(spi_clocking->lsb_first)
+ regval |= FREESCALE_DSPI_CTAR_LSBFE_M;
+
+ // Get divider bits
+ // Baud rate
+ brs.dbr = 0;
+ if (!dspi_ctar_brbf(spi_clocking, &brs, ctar_br, ctar_pbr, NULL, sys_clk))
+ {
+ regval |= FREESCALE_DSPI_CTAR_BR(brs.br) |
+ FREESCALE_DSPI_CTAR_PBR(brs.pbr) |
+ (brs.dbr ? FREESCALE_DSPI_CTAR_DBR_M : 0);
+ } else
+ CYG_ASSERT_LOW_FREQ;
+
+ delay_brate = 100000000 / (spi_clocking->dl_unit * spi_clocking->cs_up_udly);
+ if (!dspi_ctar_brbf(spi_clocking, &brs, ctar_cssck, ctar_pcssck,
+ &delay_brate, sys_clk))
+ {
+ regval |= FREESCALE_DSPI_CTAR_CSSCK(brs.br) |
+ FREESCALE_DSPI_CTAR_PCSSCK(brs.pbr);
+ } else
+ CYG_ASSERT_LOW_FREQ;
+
+ // Delay between clock and CS negation
+ delay_brate = 100000000 / (spi_clocking->dl_unit * spi_clocking->cs_dw_udly);
+ if (!dspi_ctar_brbf(spi_clocking, &brs, ctar_cssck, ctar_pcssck,
+ &delay_brate, sys_clk))
+ {
+ regval |= FREESCALE_DSPI_CTAR_ASC(brs.br) |
+ FREESCALE_DSPI_CTAR_PASC(brs.pbr);
+ } else
+ CYG_ASSERT_LOW_FREQ;
+
+ // Delay between clock and CS negation and assertion
+ delay_brate = 100000000 / (spi_clocking->dl_unit * spi_clocking->tr_bt_udly);
+ if (!dspi_ctar_brbf(spi_clocking, &brs, ctar_cssck, ctar_pcssck,
+ &delay_brate, sys_clk))
+ {
+ regval |= FREESCALE_DSPI_CTAR_DT(brs.br) |
+ FREESCALE_DSPI_CTAR_PDT(brs.pbr);
+ } else
+ CYG_ASSERT_LOW_FREQ;
+ return regval;
+}
+
+//----------------------------------------------------------------------------
+//Set up SPI bus pins
+
+static void dspi_pin_setup(const cyg_uint32* spi_pins_p,
+ const cyg_uint32* cs_pins_p, cyg_uint32 cs_pin_n)
+{
+ const cyg_uint32* pin_p;
+
+ for(pin_p = spi_pins_p;
+ pin_p < spi_pins_p + 3;
+ CYGHWR_IO_FREESCALE_DSPI_PIN(*pin_p++));
+
+ for(pin_p = cs_pins_p;
+ pin_p < cs_pins_p + cs_pin_n;
+ CYGHWR_IO_FREESCALE_DSPI_PIN(*pin_p++));
+}
+
+//-----------------------------------------------------------------------------
+// Set up a new SPI bus on initialisation.
+
+static void dspi_bus_setup(cyg_spi_freescale_dspi_bus_t* spi_bus_p)
+{
+ cyghwr_devs_freescale_dspi_t* dspi_p = spi_bus_p->setup_p->dspi_p;
+ cyghwr_hal_freescale_dma_set_t* dma_set_p;
+ cyghwr_hal_freescale_edma_t* edma_p;
+ cyg_uint32 dma_chan_i;
+
+ // Set up the clocking.
+ CYGHWR_IO_CLOCK_ENABLE(spi_bus_p->setup_p->clk_gate);
+ spi_bus_p->clock_freq = CYGHWR_IO_SPI_FREESCALE_DSPI_CLOCK;
+ DEBUG1_PRINTF("DSPI BUS %p: SysClk=%d\n", spi_bus_p, spi_bus_p->clock_freq);
+
+ // Set up the pins.
+ dspi_pin_setup(spi_bus_p->setup_p->spi_pin_list_p,
+ spi_bus_p->setup_p->cs_pin_list_p,
+ spi_bus_p->setup_p->cs_pin_num);
+
+ // Set up default SPI configuration.
+ dspi_p->mcr = spi_bus_p->setup_p->mcr_opt | FREESCALE_DSPI_MCR_MSTR_M |
+ FREESCALE_DSPI_MCR_CLR_RXF_M | FREESCALE_DSPI_MCR_CLR_TXF_M |
+ FREESCALE_DSPI_MCR_MDIS_M;
+
+ // Enable DSPI controller.
+ dspi_enable(dspi_p);
+
+ if((dma_set_p=spi_bus_p->setup_p->dma_set_p)) {
+ // Initialize DMA channels
+ hal_freescale_edma_init_chanset(dma_set_p);
+#if DEBUG_SPI >= 1
+ hal_freescale_edma_diag(dma_set_p, 0xffff);
+ cyghwr_devs_freescale_dspi_diag(spi_bus_p);
+#endif
+ // Set up DMA transfer control descriptors
+ edma_p = dma_set_p->edma_p;
+ dma_chan_i = dma_set_p->chan_p[SPI_DMA_CHAN_TX_I].dma_chan_i;
+ hal_freescale_edma_transfer_init(edma_p, dma_chan_i,
+ spi_bus_p->tx_dma_tcd_ini_p);
+#if DEBUG_SPI >= 1
+ hal_freescale_edma_transfer_diag(edma_p, dma_chan_i, true);
+#endif
+ dma_chan_i = dma_set_p->chan_p[SPI_DMA_CHAN_RX_I].dma_chan_i;
+ hal_freescale_edma_transfer_init(edma_p, dma_chan_i,
+ spi_bus_p->rx_dma_tcd_ini_p);
+#if DEBUG_SPI >= 1
+ hal_freescale_edma_transfer_diag(edma_p, dma_chan_i, true);
+#endif
+ }
+#if DEBUG_SPI >= 1
+ cyghwr_devs_freescale_dspi_diag(spi_bus_p);
+#endif
+ // Initialise the synchronisation primitivies.
+ cyg_drv_mutex_init (&spi_bus_p->transfer_mutex);
+ cyg_drv_cond_init (&spi_bus_p->transfer_done, &spi_bus_p->transfer_mutex);
+
+ // Hook up the ISR and DSR.
+ cyg_drv_interrupt_create (spi_bus_p->setup_p->intr_num,
+ spi_bus_p->setup_p->intr_prio,
+ (cyg_addrword_t) spi_bus_p,
+ dma_set_p ? dspi_dma_ISR : dspi_nodma_ISR,
+ dspi_DSR, &spi_bus_p->intr_handle,
+ &spi_bus_p->intr_data);
+ cyg_drv_interrupt_attach (spi_bus_p->intr_handle);
+
+ dspi_p->ctar[1] = dspi_calc_ctar(&aux_clocking, spi_bus_p->clock_freq);
+
+ // Call upper layer bus init.
+ CYG_SPI_BUS_COMMON_INIT(&spi_bus_p->spi_bus);
+}
+
+//-----------------------------------------------------------------------------
+// Set up Rx DMA channel
+static void
+rx_dma_channel_setup(cyghwr_hal_freescale_dma_set_t *dma_set_p,
+ cyg_uint8* data_buf, cyg_uint32 bus_16bit,
+ volatile cyghwr_hal_freescale_edma_tcd_t *tcd_p)
+{
+ cyg_uint32 step, sdsize;
+ static cyg_uint8 popr_sink;
+
+ // Set the correct transfer size.
+ if(bus_16bit) {
+ step = 2;
+ sdsize = FREESCALE_EDMA_ATTR_SIZE_16;
+ } else {
+ step = 1;
+ sdsize = FREESCALE_EDMA_ATTR_SIZE_8;
+ }
+ if(data_buf) {
+ tcd_p->doff = step;
+ tcd_p->daddr = data_buf;
+ } else {
+ tcd_p->doff = 0;
+ tcd_p->daddr = &popr_sink;
+ }
+ tcd_p->nbytes.mlno = step;
+ tcd_p->attr = FREESCALE_EDMA_ATTR_SSIZE(sdsize) |
+ FREESCALE_EDMA_ATTR_DSIZE(sdsize) |
+ FREESCALE_EDMA_ATTR_SMOD(0) |
+ FREESCALE_EDMA_ATTR_DMOD(0);
+#if DEBUG_SPI >= 3
+ hal_freescale_edma_tcd_diag(tcd_p, -1, "[DSPI Rx]");
+#endif
+}
+
+//----------------------------------------------------------------------------
+// Set up Tx FIFO queue
+// Set up Tx FIFO command queue
+// DSPI requires sending command for every transfer.
+// Used for transfers that fit within DSPI FIFO.
+
+#if DEBUG_SPI >= 2
+static const char debug_format[] = "BUFF %dbit %s: %p 0x%08x remain %d:\n";
+static const char debug_format1[] = "PUSHR 0x%08x %s: %p 0x%08x remain %d:\n";
+#endif
+
+static inline volatile cyg_uint32
+fifo_pushque_fill(cyg_spi_freescale_dspi_bus_t* dspi_bus, cyg_uint8*
+ data_p, cyg_uint32 count, cyg_bool bus_16bit, cyg_uint32 pushr,
+ cyg_bool drop_cs)
+{
+ cyghwr_devs_freescale_dspi_t* dspi_p = dspi_bus->setup_p->dspi_p;
+ cyg_uint32 txfifo_n = dspi_bus->txfifo_n;
+
+ if(data_p) {
+ if(!bus_16bit) {
+ for(; count > 1; count--) {
+ if(!(--txfifo_n)) {
+ dspi_p->pushr = pushr |= *data_p | FREESCALE_DSPI_PUSHR_EOQ_M;
+ count--;
+ DEBUG2_PRINTF(debug_format, 8, "FBK", data_p,
+ pushr | *data_p, count);
+ return count;
+ }
+ DEBUG3_PRINTF(debug_format, 8, "FAD", data_p,
+ pushr | *data_p, count-1);
+ dspi_p->pushr = pushr | *data_p++;
+ }
+ pushr |= *data_p;
+ } else {
+ cyg_uint16* data16_p = (cyg_uint16 *)data_p;
+ cyg_uint16 data_word;
+
+ for(; count > 2; count-=2) {
+ if(!(--txfifo_n)) {
+ dspi_p->pushr = pushr |= *data16_p | FREESCALE_DSPI_PUSHR_EOQ_M;
+ count-=2;
+ DEBUG2_PRINTF(debug_format, 16, "FBK", data_p,
+ pushr, count);
+ return count;
+ }
+ DEBUG3_PRINTF(debug_format, 16, "FAD", data16_p,
+ pushr | *data16_p, (count-1)*2);
+ data_word = *data16_p++;
+ dspi_p->pushr = pushr | data_word;
+ }
+ data_word = *data16_p;
+ pushr |= data_word;
+ }
+ } else {
+ pushr |= PUSHR_NULL;
+ for(; count > 1; count--) {
+ if(!(--txfifo_n)) {
+ dspi_p->pushr = pushr |= FREESCALE_DSPI_PUSHR_EOQ_M;
+ count--;
+ DEBUG2_PRINTF(debug_format, 0, "FBK", &dspi_p->pushr,
+ pushr, count);
+ return count;
+ }
+ dspi_p->pushr = pushr;
+ DEBUG3_PRINTF(debug_format, 0, "FAD", &dspi_p->pushr, pushr,
+ count-1);
+ }
+ }
+ if(drop_cs)
+ pushr &= ~FREESCALE_DSPI_PUSHR_CONT_M;
+ dspi_p->pushr = pushr |= FREESCALE_DSPI_PUSHR_EOQ_M;
+ DEBUG2_PRINTF(data_p ? debug_format : debug_format1, data_p ? (bus_16bit ? 16 :8) : pushr,
+ (drop_cs ? "FEN" : "FSG"), data_p /*&dspi_p->pushr*/, pushr, 0);
+ return 0;
+}
+
+//----------------------------------------------------------------------------
+// Set up Tx
+// Set up Tx DMA command queue
+// DSPI requires sending command for every transfer.
+// Used for transfers larger than DSPI FIFO
+
+static inline volatile cyg_uint32
+dma_pushque_fill(cyg_spi_freescale_dspi_bus_t* dspi_bus, cyg_uint8* data_p,
+ cyg_uint32 count, cyg_bool bus_16bit, cyg_uint32 pushr,
+ cyg_bool drop_cs)
+{
+ volatile cyg_uint32* pushque_p;
+ volatile cyg_uint32* pushque_end;
+
+ pushque_p = dspi_bus->pushque_p;
+ pushque_end = pushque_p + (dspi_bus->pushque_n - (bus_16bit ? 2 : 1));
+ pushque_p = dspi_bus->pushque_p;
+ if(data_p) {
+ if(!bus_16bit) {
+ do {
+ if(pushque_p == pushque_end) {
+ *pushque_p = pushr | *data_p | FREESCALE_DSPI_PUSHR_EOQ_M;
+ count--;
+
+ DEBUG2_PRINTF(debug_format, 8, "BRK", pushque_p,
+ pushque_p[0], count);
+ return count;
+ }
+ *pushque_p++ = pushr | *data_p++;
+ DEBUG3_PRINTF(debug_format, 8, "ADD", pushque_p-1,
+ pushque_p[-1], count-1);
+ } while(--count > 1);
+ pushr |= *data_p;
+ } else {
+ cyg_uint16* data16_p = (cyg_uint16 *)data_p;
+ cyg_uint16 data_word;
+ do {
+ if(pushque_p == pushque_end) {
+ data_word = *data16_p;
+ *pushque_p = pushr | data_word | FREESCALE_DSPI_PUSHR_EOQ_M;
+ count-=2;
+
+ DEBUG2_PRINTF(debug_format, 16, "BRK", pushque_p,
+ pushque_p[0], count);
+ return count;
+ }
+ data_word = *data16_p++;
+ *pushque_p++ = pushr | data_word;
+ DEBUG3_PRINTF(debug_format, 16, "ADD", pushque_p-1,
+ pushque_p[-1], count-2);
+ } while((count -= 2) > 2);
+ data_word = *data16_p;
+ pushr |= data_word;
+ }
+ } else {
+ pushr |= PUSHR_NULL;
+ do {
+ if(pushque_p == pushque_end) {
+ *pushque_p = pushr | FREESCALE_DSPI_PUSHR_EOQ_M;
+ count--;
+
+ DEBUG2_PRINTF(debug_format, 0, "BRK", pushque_p,
+ pushque_p[0], count);
+ return count;
+ }
+ *pushque_p++ = pushr;
+ DEBUG3_PRINTF(debug_format, 0, "ADD", pushque_p-1, pushque_p[-1],
+ count-1);
+ } while(--count > 1);
+ }
+ if(drop_cs) pushr &= ~FREESCALE_DSPI_PUSHR_CONT_M;
+ *pushque_p = pushr |= FREESCALE_DSPI_PUSHR_EOQ_M;
+ DEBUG2_PRINTF(debug_format, data_p ? (bus_16bit ? 16 :8) : 0,
+ (drop_cs ? "END" : "SGM"), pushque_p, pushque_p[0], 0);
+
+ return 0;
+}
+
+// Set up Tx DMA channel
+// Used for transfers larger than DSPI FIFO
+
+static inline cyg_uint32
+tx_dma_channel_setup(cyg_spi_freescale_dspi_bus_t* dspi_bus,
+ cyg_uint8* data_buf, cyg_uint32 count,
+ cyg_bool bus_16bit,
+ cyg_uint32 pushr, cyg_bool drop_cs)
+{
+ cyghwr_hal_freescale_dma_set_t *dma_set_p = dspi_bus->setup_p->dma_set_p;
+ cyghwr_hal_freescale_edma_t *edma_p = dma_set_p->edma_p;
+ volatile cyghwr_hal_freescale_edma_tcd_t *tcd_p;
+ cyg_uint32 remain=0;
+ cyg_uint32 dma_chan_i;
+
+ remain = dma_pushque_fill(dspi_bus, data_buf, count, bus_16bit, pushr, drop_cs);
+ dma_chan_i = SPI_DMA_CHAN_I(dma_set_p, TX);
+ tcd_p = &edma_p->tcd[dma_chan_i];
+ tcd_p->saddr = dspi_bus->pushque_p;
+ DEBUG2_PRINTF("DSPI: Tx channel setup\n");
+#if DEBUG_SPI >= 3
+ hal_freescale_edma_transfer_diag(edma_p, dma_chan_i, true);
+#endif
+ return remain;
+}
+
+//-----------------------------------------------------------------------------
+// Set SPI peripheral chip select.
+
+static inline cyg_uint32
+dspi_chip_select_set(cyg_int32 cs_i, cyg_bool pccse, cyg_bool assert)
+{
+ cyg_uint32 spi_pushr;
+
+ if(cs_i < 0) {
+ spi_pushr = 0;
+ } else {
+ if(pccse) {
+ spi_pushr = cs_i;
+ } else {
+ if(cs_i < 5) {
+ if(assert) {
+ cs_i = 1 << cs_i;
+ spi_pushr = FREESCALE_DSPI_PUSHR_PCS(cs_i);
+ } else
+ spi_pushr = 0;
+ } else {
+ CYG_ASSERT(1, "DSPI: Peripheral Chip Select out of range.\n");
+ spi_pushr = 1 << 5;
+ }
+ }
+ }
+ return spi_pushr;
+}
+
+//-----------------------------------------------------------------------------
+// Execute SPI transaction.
+
+static void spi_transaction_do (cyg_spi_device* device, cyg_bool tick_only,
+ cyg_bool polled, cyg_uint32 count,
+ const cyg_uint8* tx_data, cyg_uint8* rx_data,
+ cyg_bool drop_cs)
+{
+ cyg_spi_freescale_dspi_bus_t* dspi_bus =
+ (cyg_spi_freescale_dspi_bus_t*) device->spi_bus;
+ cyg_spi_freescale_dspi_device_t* dspi_device =
+ (cyg_spi_freescale_dspi_device_t*) device;
+ cyg_bool bus_16bit = dspi_device->clocking.bus_16bit;
+ cyghwr_devs_freescale_dspi_t* dspi_p = dspi_bus->setup_p->dspi_p;
+
+ cyghwr_hal_freescale_dma_set_t* dma_set_p;
+ cyghwr_hal_freescale_edma_t* edma_p = NULL;
+
+ cyg_uint32 count_down;
+ cyg_uint32 txfifo_n = dspi_bus->txfifo_n;
+ cyg_uint32 pushr;
+ cyg_uint32 pushque_n;
+ cyg_uint32 dma_chan_rx_i = 0;
+ cyg_uint32 dma_chan_tx_i = 0;
+ cyg_uint8* rx_data0;
+
+#if DEBUG_SPI >= 2
+ cyg_uint32 first_turn = 1;
+#endif
+
+ DEBUG2_PRINTF("DSPI: transaction: count=%d drop_cs=%d tick_only=%d\n",
+ count, drop_cs, tick_only);
+
+ // Set up peripheral CS field. DSPI automatically asserts and deasserts CS
+ pushr =
+#ifndef CYGOPT_DEVS_SPI_FREESCALE_DSPI_TICK_ONLY_DROPS_CS
+ // Compatibility option
+ // eCos Reference Manual states that CS should drop prior to sending
+ // ticks, but other SPI drivers do not touch the CS.
+ tick_only ? dspi_p->pushr & 0x87FF0000 :
+#endif
+ dspi_chip_select_set(
+#ifdef CYGOPT_DEVS_SPI_FREESCALE_DSPI_TICK_ONLY_DROPS_CS
+ // Compatibility option. See comment above.
+ tick_only ? -1 :
+#endif
+ dspi_device->dev_num,
+ dspi_p->mcr & FREESCALE_DSPI_MCR_PCSSE_M, true);
+ pushr |= FREESCALE_DSPI_PUSHR_CONT_M;
+
+ dspi_fifo_clear(dspi_p);
+
+ pushque_n = dspi_bus->pushque_n;
+ if(bus_16bit)
+ txfifo_n *= 2;
+
+ dma_set_p = dspi_bus->setup_p->dma_set_p;
+ if((count > txfifo_n) && dma_set_p) {
+ rx_data0 = rx_data;
+ edma_p = dma_set_p->edma_p;
+ // Set up the DMA channels.
+ dma_chan_rx_i = SPI_DMA_CHAN_I(dma_set_p, RX);
+ dma_chan_tx_i = SPI_DMA_CHAN_I(dma_set_p, TX);
+ rx_dma_channel_setup(dma_set_p, (cyg_uint8*) rx_data,
+ bus_16bit, &edma_p->tcd[dma_chan_rx_i]);
+ hal_freescale_edma_erq_enable(edma_p, dma_chan_rx_i);
+ dspi_irq_enable(dspi_p,
+ FREESCALE_DSPI_RSER_TFFF_RE_M |
+ FREESCALE_DSPI_RSER_RFDF_RE_M |
+ FREESCALE_DSPI_RSER_TFFF_DIRS_M |
+ FREESCALE_DSPI_RSER_RFDF_DIRS_M);
+ } else {
+ rx_data0 = NULL;
+ // If byte count fits in the FIFO don't bother with DMA.
+ if(dma_set_p) {
+ edma_p = dma_set_p->edma_p;
+ hal_freescale_edma_erq_disable(edma_p, SPI_DMA_CHAN_I(dma_set_p, RX));
+ }
+ dma_set_p = NULL;
+ dspi_irq_disable(dspi_p,
+ FREESCALE_DSPI_RSER_TFFF_RE_M |
+ FREESCALE_DSPI_RSER_RFDF_RE_M |
+ FREESCALE_DSPI_RSER_TFFF_DIRS_M |
+ FREESCALE_DSPI_RSER_RFDF_DIRS_M);
+ }
+
+ if(!polled)
+ cyg_drv_interrupt_unmask(dspi_bus->setup_p->intr_num);
+ count_down = count;
+ while(count_down) {
+#if DEBUG_SPI >= 2
+ if(first_turn) {
+ if(dspi_bus->pushque_p)
+ dspi_bus->pushque_p[0] |= FREESCALE_DSPI_PUSHR_CTCNT_M;
+ first_turn = 0;
+ }
+#endif
+ if(dma_set_p && (count_down > txfifo_n)) {
+ // Transfer size is larger than DSPI FIFO
+ // Use DMA Tx
+ count_down = tx_dma_channel_setup(dspi_bus, (cyg_uint8*) tx_data,
+ count_down, bus_16bit,
+ pushr, drop_cs);
+#if DEBUG_SPI >= 3
+ hal_freescale_edma_transfer_diag(edma_p, dma_chan_rx_i, true);
+#endif
+ // Enable the Tx DMA / SPI controller.
+ hal_freescale_edma_erq_enable(edma_p, dma_chan_tx_i);
+ DSPI_EOQ_CLEAR(dspi_p);
+ } else {
+ // Transfer size fits within DSPI FIFO
+ // No need for DMA Tx
+ DSPI_EOQ_CLEAR(dspi_p);
+ count_down = fifo_pushque_fill(dspi_bus, (cyg_uint8*) tx_data,
+ count_down, bus_16bit,
+ pushr, drop_cs);
+#if DEBUG_SPI >= 3
+ cyghwr_devs_freescale_dspi_diag(dspi_bus);
+#endif
+ }
+
+ if(polled) {
+ DEBUG2_PRINTF("DSPI Polled:\n");
+ // Busy-wait for DSPI/DMA (polling for completion).
+ while(!(dspi_p->sr & FREESCALE_DSPI_SR_EOQF_M));
+
+ if(dma_set_p) {
+ // Disable the Tx DMA channel on completion.
+ hal_freescale_edma_erq_disable(edma_p, dma_chan_tx_i);
+ }
+ } else {
+ // Wait for DSPI/DMA completion. (interrupt driven).
+ cyg_drv_mutex_lock(&dspi_bus->transfer_mutex);
+ cyg_drv_dsr_lock();
+
+ DSPI_IRQ_ENABLE(dspi_p);
+ DEBUG2_PRINTF("DSPI IRQ: Enabled\n");
+
+ // Sit back and wait for the ISR/DSRs to signal completion.
+ cyg_drv_cond_wait (&dspi_bus->transfer_done);
+
+ cyg_drv_dsr_unlock();
+ cyg_drv_mutex_unlock(&dspi_bus->transfer_mutex);
+ }
+
+ if(dma_set_p) {
+ // Make sure that Rx has been drained by DMA.
+ while((dspi_p->sr & FREESCALE_DSPI_SR_RFDF_M));
+ DEBUG2_PRINTF("Fifo Drained by DMA 0x%08x\n", dspi_p->sr);
+ if(count_down <= txfifo_n && count_down > 0) {
+ hal_freescale_edma_erq_disable(edma_p, dma_chan_rx_i);
+ dma_set_p = NULL;
+ }
+ } else {
+ // No DMA - "manually" drain Rx FIFO
+ DEBUG2_PRINTF("DSPI FIFO: 'Manually' drain Rx fifo rx_data=%p bus_16bit=%d\n",
+ rx_data, bus_16bit);
+#if DEBUG_SPI >= 3
+ cyghwr_devs_freescale_dspi_diag(dspi_bus);
+#endif
+ if(rx_data) {
+ if(bus_16bit) {
+ cyg_uint16* rx_data16 = (cyg_uint16*) rx_data;
+ while(dspi_p->sr & FREESCALE_DSPI_SR_RXCTR_M) {
+ DEBUG2_PRINTF(" Fifo Pull16 at %p\n", rx_data16);
+ *rx_data16++ = dspi_p->popr;
+ }
+ rx_data = (cyg_uint8*) rx_data16;
+ } else {
+ while(dspi_p->sr & FREESCALE_DSPI_SR_RXCTR_M) {
+ DEBUG2_PRINTF(" Fifo Pull at %p\n", rx_data);
+ *rx_data++ = dspi_p->popr;
+ }
+ }
+ }
+ dspi_fifo_drain(dspi_p);
+ }
+ dspi_fifo_clear(dspi_p);
+ // Prepare for next iteration
+ if(tx_data) {
+ tx_data += pushque_n;
+ if(bus_16bit)
+ tx_data += pushque_n;
+ }
+ }
+ if(rx_data0) {
+ // Rx buffer may be out of sync with cache.
+ DEBUG2_PRINTF("DSPI DMA: Flush cache %p len=%d\n", rx_data0, count);
+ HAL_DCACHE_INVALIDATE(rx_data0, count);
+ DEBUG2_PRINTF("DSPI DMA: Cache flushed\n");
+ }
+
+ if(!polled)
+ cyg_drv_interrupt_mask(dspi_bus->setup_p->intr_num);
+
+ dspi_device->chip_sel = !drop_cs;
+ DEBUG2_PRINTF("cyg_transaction_do() chip_sel = %d drop_cs = %d\n", dspi_device->chip_sel, drop_cs);
+}
+
+//-----------------------------------------------------------------------------
+// Initialise SPI interfaces on startup.
+
+static void CYGBLD_ATTRIB_C_INIT_PRI(CYG_INIT_BUS_SPI)
+dspi_spi_init(void)
+{
+#ifdef CYGHWR_DEVS_SPI_FREESCALE_DSPI0
+ dspi_bus_setup (&cyg_spi_dspi_bus0);
+#endif
+
+#ifdef CYGHWR_DEVS_SPI_FREESCALE_DSPI1
+ dspi_bus_setup (&cyg_spi_dspi_bus1);
+#endif
+
+#ifdef CYGHWR_DEVS_SPI_FREESCALE_DSPI2
+ dspi_bus_setup (&cyg_spi_dspi_bus2);
+#endif
+}
+
+
+//-----------------------------------------------------------------------------
+// Start a SPI transaction.
+
+static void dspi_transaction_begin(cyg_spi_device* device)
+{
+ cyg_spi_freescale_dspi_bus_t* dspi_bus =
+ (cyg_spi_freescale_dspi_bus_t*) device->spi_bus;
+ cyg_spi_freescale_dspi_device_t* dspi_device =
+ (cyg_spi_freescale_dspi_device_t*) device;
+
+ // On the first transaction, generate the values to be programmed into the
+ // SPI configuration registers for this device and cache them. This avoids
+ // having to recalculate the prescaler for every transaction.
+ if(!(dspi_device->clocking.dspi_ctar))
+ dspi_device->clocking.dspi_ctar = dspi_calc_ctar(&dspi_device->clocking,
+ dspi_bus->clock_freq);
+ // Set up the SPI controller.
+ dspi_bus->setup_p->dspi_p->ctar[0] = dspi_device->clocking.dspi_ctar;
+#if DEBUG_SPI >= 2
+ cyghwr_devs_freescale_dspi_diag(dspi_bus);
+#endif
+}
+
+//-----------------------------------------------------------------------------
+// Run a transaction transfer.
+
+static void dspi_transaction_transfer(cyg_spi_device* device, cyg_bool polled,
+ cyg_uint32 count,
+ const cyg_uint8* tx_data,
+ cyg_uint8* rx_data,
+ cyg_bool drop_cs)
+{
+ cyg_spi_freescale_dspi_device_t* dspi_device =
+ (cyg_spi_freescale_dspi_device_t*) device;
+
+ DEBUG2_PRINTF("Transaction rx_data = %p tx_data = %p count=%d\n", rx_data, tx_data, count);
+
+ // Check for unsupported transactions.
+ CYG_ASSERT (count > 0, "DSPI: Null transfer requested.");
+
+ // We check that the buffers are half-word aligned and that count is a
+ // multiple of two in order to carry out the 16-bit transfer.
+ if (dspi_device->clocking.bus_16bit) {
+ CYG_ASSERT (!(count & 1) && !((cyg_uint32) tx_data & 1) &&
+ !((cyg_uint32) rx_data & 1),
+ "DSPI: Misaligned data in 16-bit transfer.");
+ }
+ spi_transaction_do (device, false, polled, count, tx_data, rx_data, drop_cs);
+}
+
+//-----------------------------------------------------------------------------
+// Carry out a bus tick operation - this drops chip select then pushes the
+// required number of NULL frames onto the bus.
+
+static void dspi_transaction_tick(cyg_spi_device* device, cyg_bool polled,
+ cyg_uint32 count)
+{
+ cyg_spi_freescale_dspi_device_t* dspi_device =
+ (cyg_spi_freescale_dspi_device_t*) device;
+
+ // Check for unsupported transactions.
+ CYG_ASSERT (count > 0, "DSPI: Null transfer requested.");
+
+ // We check that count is a multiple of two in order
+ // to carry out the 16-bit transfer.
+ if (dspi_device->clocking.bus_16bit) {
+ CYG_ASSERT (!(count & 1),
+ "DSPI: Misaligned data in 16-bit transfer.");
+ }
+
+ // Perform null transfer
+ DEBUG2_PRINTF("cyg_transaction_tick()\n");
+ spi_transaction_do (device, true, polled, count, NULL, NULL, false);
+}
+
+//-----------------------------------------------------------------------------
+// Terminate a SPI transaction, disabling the SPI controller.
+
+static void dspi_transaction_end(cyg_spi_device* device)
+{
+ cyg_spi_freescale_dspi_bus_t* dspi_bus =
+ (cyg_spi_freescale_dspi_bus_t*) device->spi_bus;
+ cyg_spi_freescale_dspi_device_t* dspi_device =
+ (cyg_spi_freescale_dspi_device_t*) device;
+
+ const cyghwr_hal_freescale_dma_set_t *dma_set_p = dspi_bus->setup_p->dma_set_p;
+ cyghwr_hal_freescale_edma_t *edma_p;
+ cyghwr_devs_freescale_dspi_t* dspi_p = dspi_bus->setup_p->dspi_p;
+
+ DEBUG2_PRINTF("cyg_transaction_end() chip_sel = %d\n", dspi_device->chip_sel);
+ if(dma_set_p) {
+ edma_p = dma_set_p->edma_p;
+ hal_freescale_edma_erq_disable(edma_p, SPI_DMA_CHAN_I(dma_set_p, TX));
+ hal_freescale_edma_erq_disable(edma_p, SPI_DMA_CHAN_I(dma_set_p, RX));
+ }
+
+ if(dspi_device->chip_sel){
+ // Clear peripheral CS by executing a dummy 4 bit transfer.
+ dspi_p->pushr = PUSHR_NULL | FREESCALE_DSPI_PUSHR_EOQ_M |
+ FREESCALE_DSPI_PUSHR_CTAS(1);
+ while(!(dspi_p->sr & FREESCALE_DSPI_SR_EOQF_M));
+ DSPI_EOQ_CLEAR(dspi_p);
+ dspi_fifo_drain(dspi_p);
+ dspi_device->chip_sel = 0;
+ }
+}
+
+//-----------------------------------------------------------------------------
+// Get DSPI configuration parameter
+
+static int dspi_get_config (cyg_spi_device* device, cyg_uint32 key,
+ void* buf, cyg_uint32* len)
+{
+ cyg_spi_freescale_dspi_bus_t* dspi_bus =
+ (cyg_spi_freescale_dspi_bus_t*) device->spi_bus;
+ cyg_spi_freescale_dspi_device_t* dspi_device =
+ (cyg_spi_freescale_dspi_device_t*) device;
+ cyg_uint32* data_p = buf;
+
+ switch (key) {
+ case CYG_IO_GET_CONFIG_SPI_CLOCKRATE :
+ // Sanity check
+ if (NULL == len) {
+ CYG_ASSERT (false, "Freescale DSPI:"
+ " Null pointer as len argument for dspi_get_config().");
+ return -1;
+ } else if (sizeof(cyg_uint32) != *len) {
+ CYG_ASSERT (false, "Freescale DSPI:"
+ " Invalid length with dspi_get_config().");
+ return -1;
+ } else if (NULL == buf) {
+ CYG_ASSERT (false, "Freescale DSPI:"
+ " Null poiter as buf argument for dspi_get_config().");
+ return -1;
+ } else {
+ cyg_uint32 ctar, dbr, br, pbr;
+
+ ctar = dspi_device->clocking.dspi_ctar;
+ dbr = (ctar & FREESCALE_DSPI_CTAR_DBR_M) >>
+ FREESCALE_DSPI_CTAR_DBR_S;
+ br = (ctar & FREESCALE_DSPI_CTAR_BR_M) >>
+ FREESCALE_DSPI_CTAR_BR_S;
+ pbr = (ctar & FREESCALE_DSPI_CTAR_PBR_M) >>
+ FREESCALE_DSPI_CTAR_PBR_S;
+ *data_p = (dspi_bus->clock_freq * (1+dbr)) / (pbr * br);
+
+ DEBUG2_PRINTF("DSPI Get Config: baud = %d\n", *data_p);
+
+ return 0;
+ }
+
+ default :
+ break;
+ }
+ return -1;
+}
+
+//-----------------------------------------------------------------------------
+// Change some SPI device configuration parameters
+
+static int dspi_set_config(cyg_spi_device* device, cyg_uint32 key,
+ const void* buf, cyg_uint32* len)
+{
+ cyg_spi_freescale_dspi_device_t* dspi_device =
+ (cyg_spi_freescale_dspi_device_t*) device;
+ cyg_spi_freescale_dspi_bus_t* dspi_bus =
+ (cyg_spi_freescale_dspi_bus_t*) device->spi_bus;
+
+ cyg_uint32 regval;
+ ctar_br_t brs;
+
+ switch (key) {
+ case CYG_IO_SET_CONFIG_SPI_CLOCKRATE :
+ // Sanity check
+ if (NULL == len) {
+ CYG_ASSERT (false, "Freescale DSPI:"
+ " Null pointer as len argument for dspi_set_config().");
+ return -1;
+ } else if (sizeof(cyg_uint32) != *len) {
+ CYG_ASSERT (false, "Freescale DSPI:"
+ " Invalid length with dspi_set_config().");
+ return -1;
+ } else if (NULL == buf) {
+ CYG_ASSERT (false, "Freescale DSPI:"
+ " Null pointer as buf argument for dspi_set_config().");
+ return -1;
+ } else {
+ // Get divider bits
+ if (!dspi_ctar_brbf(&dspi_device->clocking, &brs,
+ ctar_br, ctar_pbr, (cyg_uint32 *)buf, dspi_bus->clock_freq))
+ {
+ // Update the cache of the configuration register settings.
+ regval = dspi_device->clocking.dspi_ctar;
+ regval &= ~(FREESCALE_DSPI_CTAR_BR_M |
+ FREESCALE_DSPI_CTAR_PBR_M);
+ regval |= FREESCALE_DSPI_CTAR_BR(brs.br) |
+ FREESCALE_DSPI_CTAR_PBR(brs.pbr);
+ dspi_device->clocking.dspi_ctar = regval;
+
+ return 0;
+
+ } else {
+ CYG_ASSERT (false, "Freescale DSPI:"
+ " Cannot run bus as slowly as requested.");
+ return -1;
+ }
+ }
+ default :
+ break;
+ }
+ return -1;
+}
+
+#if DEBUG_SPI
+//----------------------------------------------------------------------------
+// Print out a DSPI array state
+// Helper for cyghwr_devs_freescale_dspi_diag()
+
+void cyghwr_devs_freescale_dspi_diag_array(char* name_p,
+ volatile cyg_uint32* array_p,
+ cyg_uint32 array_n)
+{
+ diag_printf("%s %p[%u]: ", name_p, array_p, array_n);
+ for(; array_n; array_n--) {
+ diag_printf(" 0x%08x", *array_p++);
+ }
+ diag_printf("\n");
+}
+
+//----------------------------------------------------------------------------
+// Print out DSPI state
+
+void cyghwr_devs_freescale_dspi_diag(cyg_spi_freescale_dspi_bus_t* dspi_bus_p)
+{
+ cyghwr_devs_freescale_dspi_t* dspi_p = dspi_bus_p->setup_p->dspi_p;
+
+ diag_printf("DSPI %p\n", dspi_p);
+ diag_printf(" MCR = 0x%08x TCR = 0x%08x\n", dspi_p->mcr, dspi_p->tcr);
+ cyghwr_devs_freescale_dspi_diag_array(" CTAR", dspi_p->ctar,
+ CYGHWR_DEVS_SPI_FREESCALE_DSPI_CTAR_NUM);
+ diag_printf(" SR = 0x%08x RSER = 0x%08x PUSHR = 0x%08x POPR = 0x%08x\n",
+ dspi_p->sr, dspi_p->rser, dspi_p->pushr, dspi_p->popr);
+ cyghwr_devs_freescale_dspi_diag_array(" TXFR", dspi_p->txfr, dspi_bus_p->txfifo_n);
+ cyghwr_devs_freescale_dspi_diag_array(" RXFR", dspi_p->rxfr, dspi_bus_p->rxfifo_n);
+}
+#endif // DEBUG_SPI
+
+#endif // defined(CYGHWR_DEVS_SPI_FREESCALE_DSPIx)
+
+//=============================================================================
diff --git a/ecos/packages/devs/spi/freescale/dspi/current/tests/spi_loopback.c b/ecos/packages/devs/spi/freescale/dspi/current/tests/spi_loopback.c
new file mode 100644
index 0000000..6e70e0c
--- /dev/null
+++ b/ecos/packages/devs/spi/freescale/dspi/current/tests/spi_loopback.c
@@ -0,0 +1,285 @@
+//=============================================================================
+//
+// spi_loopback.c
+//
+// Standalone SPI loopback test.
+//
+//=============================================================================
+// ####ECOSGPLCOPYRIGHTBEGIN####
+// -------------------------------------------
+// This file is part of eCos, the Embedded Configurable Operating System.
+// Copyright (C) 2012 Free Software Foundation, Inc.
+//
+// eCos is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 2 or (at your option) any later
+// version.
+//
+// eCos is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with eCos; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// As a special exception, if other files instantiate templates or use
+// macros or inline functions from this file, or you compile this file
+// and link it with other works to produce a work based on this file,
+// this file does not by itself cause the resulting work to be covered by
+// the GNU General Public License. However the source code for this file
+// must still be made available in accordance with section (3) of the GNU
+// General Public License v2.
+//
+// This exception does not invalidate any other reasons why a work based
+// on this file might be covered by the GNU General Public License.
+// -------------------------------------------
+// ####ECOSGPLCOPYRIGHTEND####
+//=============================================================================
+//#####DESCRIPTIONBEGIN####
+//
+// Author(s): Ilija Kocho
+// Original: Chris Holgate
+// Date: 2012-12-27
+// Purpose: Freescale DSPI loopback test
+// Description: Standalone SPI loopback test.
+// Usage: Compile as a standalone application.
+//
+//####DESCRIPTIONEND####
+//
+//=============================================================================
+
+//=============================================================================
+// This is a quick loopback test for the Freescale DSPI SPI driver. It only checks
+// the data transfer functionality - chip select handling will require
+// testing with external devices. In order to run the test, the MOSI and
+// MISO pins for the test port need to be shorted together to provide an
+// external loopback. Don't do this on a bus which has external devices
+// attached unless you first make sure that none of them are connected to
+// the chip select used by the test harness.
+// The default port and chip select used for this test are SPI bus 1,
+// chip select 0. These can be changed by editing the loopback_device
+// data structure directly.
+// Note that this is intended to be run as a standalone test and not as part
+// of the standard board tests since it requires a hardware modification.
+//=============================================================================
+
+#include <cyg/infra/cyg_type.h>
+#include <cyg/infra/testcase.h> // Test macros
+
+#include <cyg/infra/cyg_ass.h> // Assertion macros
+#include <cyg/infra/diag.h> // Diagnostic output
+
+#include <cyg/hal/hal_arch.h> // CYGNUM_HAL_STACK_SIZE_TYPICAL
+#include <cyg/kernel/kapi.h>
+
+#include <cyg/io/spi.h> // Common SPI API
+#include <cyg/io/spi_freescale_dspi.h> // Freescale DSPI data structures
+
+#include <string.h>
+
+//---------------------------------------------------------------------------
+// Thread data structures.
+
+cyg_uint8 stack [CYGNUM_HAL_STACK_SIZE_TYPICAL];
+cyg_thread thread_data;
+cyg_handle_t thread_handle;
+
+externC cyg_spi_freescale_dspi_bus_t cyg_spi_dspi_bus1;
+
+//---------------------------------------------------------------------------
+// SPI loopback device driver data structures.
+
+CYG_DEVS_SPI_FREESCALE_DSPI_DEVICE(
+ loopback_device, // Device name
+ 1, //SPI bus
+ 0, // Dev num
+ 8, // Frame size
+ 0, // Clock pol
+ 0, // Clock phase
+ 6000000, // Clock speed
+ 1, // CS assert delay
+ 1, // CS negate delay
+ 1, // Delay between transfers
+ 1000, // Delay unit [ns]
+ 0 // Double baud rate
+);
+
+//---------------------------------------------------------------------------
+
+static int errors = 0;
+
+const char tx_data0[] = "0123456789a123456789b123456789c123456789d123456789e";
+const char tx_data1[] = "Performing extended API test first transaction..|";
+const char tx_data2[] = "Testing extended API for a second transaction!";
+
+char rx_data [256];
+char rx_data1 [256];
+char rx_data2 [256];
+
+static void memclr(char *dest_p, cyg_uint32 byte_n)
+{
+ while(byte_n--) {
+ *dest_p++ = 0;
+ }
+}
+
+
+//---------------------------------------------------------------------------
+// Run single loopback transaction using simple transfer API call.
+
+void run_test_tick (cyg_bool polled, cyg_uint32 count)
+{
+ diag_printf ("Test 0 : Tick (polled = %d).\n", polled ? 1 : 0);
+ cyg_spi_tick(&loopback_device, polled, count);
+ diag_printf (" Tick end\n");
+}
+
+void run_test_1 (cyg_bool polled, const char* tx_data_p, cyg_uint32 count)
+{
+ diag_printf ("Test 1 : Simple transfer test polled = %d, count=%d\n",
+ polled ? 1 : 0, count);
+ memclr(rx_data1, sizeof(rx_data1));
+ memclr(rx_data2, sizeof(rx_data1));
+ cyg_spi_transfer (&loopback_device, polled, count,
+ (const cyg_uint8*) tx_data_p, (cyg_uint8*) &rx_data[0]);
+ diag_printf (" Tx data : %s\n", tx_data_p);
+ diag_printf (" Rx data : %s 0x%02x\n", rx_data, rx_data[0]);
+
+ if (memcmp (tx_data_p, rx_data, count) != 0) {
+ errors++;
+ diag_printf("Simple transfer loopback failed - mismatched data.\n");
+ }
+}
+
+//---------------------------------------------------------------------------
+// Run two loopback transactions using extended transfer API.
+
+void run_test_2 (cyg_bool polled)
+{
+ diag_printf ("Test 2 : Extended API test (polled = %d).\n", polled ? 1 : 0);
+ memclr(rx_data1, sizeof(rx_data1));
+ memclr(rx_data2, sizeof(rx_data1));
+ cyg_spi_transaction_begin (&loopback_device);
+ cyg_spi_transaction_transfer (&loopback_device, polled, sizeof (tx_data1),
+ (const cyg_uint8*) &tx_data1[0], (cyg_uint8*) &rx_data1[0], false);
+ cyg_spi_transaction_transfer (&loopback_device, polled, sizeof (tx_data2),
+ (const cyg_uint8*) &tx_data2[0], (cyg_uint8*) &rx_data2[0], true);
+ cyg_spi_transaction_end (&loopback_device);
+
+ diag_printf (" Tx data 1 (%u Bytes): %s\n", sizeof(tx_data1), tx_data1);
+ diag_printf (" Rx data 1 : %s\n", rx_data1);
+ diag_printf (" Tx data 2 (%u Bytes): %s\n", sizeof(tx_data2), tx_data2);
+ diag_printf (" Rx data 2 : %s\n", rx_data2);
+ if (memcmp (tx_data1, rx_data1, sizeof (tx_data1)) != 0) {
+ errors++;
+ diag_printf("Simple transfer loopback failed - mismatched data (transfer 1).\n");
+ }
+ if (memcmp (tx_data2, rx_data2, sizeof (tx_data2)) != 0) {
+ errors++;
+ diag_printf("Simple transfer loopback failed - mismatched data (transfer 2).\n");
+ }
+}
+
+void run_test_3 (cyg_bool polled)
+{
+ diag_printf ("Test 3 : Extended API test (polled = %d).\n", polled ? 1 : 0);
+ memclr(rx_data1, sizeof(rx_data1));
+ memclr(rx_data2, sizeof(rx_data1));
+
+ cyg_spi_transaction_begin (&loopback_device);
+ cyg_spi_transaction_transfer (&loopback_device, polled, sizeof (tx_data1),
+ (const cyg_uint8*) &tx_data1[0], (cyg_uint8*) &rx_data1[0], false);
+ cyg_spi_transaction_transfer (&loopback_device, polled, sizeof (tx_data2),
+ (const cyg_uint8*) &tx_data2[0], (cyg_uint8*) &rx_data2[0], true);
+ cyg_spi_transaction_end (&loopback_device);
+ diag_printf (" Tx data 1 (%u Bytes): %s\n", sizeof(tx_data1), tx_data1);
+ diag_printf (" Rx data 31 : %s\n", rx_data1);
+ diag_printf (" Tx data 2 (%u Bytes): %s\n", sizeof(tx_data2), tx_data2);
+ diag_printf (" Rx data 32 : %s\n", rx_data2);
+
+ if (memcmp (tx_data1, rx_data1, sizeof (tx_data1)) != 0) {
+ errors++;
+ diag_printf("Simple transfer loopback failed - mismatched data (transfer 1).\n");
+ }
+ if (memcmp (tx_data2, rx_data2, sizeof (tx_data2)) != 0) {
+ errors++;
+ diag_printf("Simple transfer loopback failed - mismatched data (transfer 2).\n");
+ }
+}
+
+void run_test_4 (cyg_bool polled)
+{
+ diag_printf ("Test 4 : Extended API test NULL transfer (polled = %d).\n", polled ? 1 : 0);
+ memclr(rx_data1, sizeof(rx_data1));
+ memclr(rx_data2, sizeof(rx_data1));
+
+ cyg_spi_transaction_begin (&loopback_device);
+ cyg_spi_transaction_transfer (&loopback_device, polled, sizeof (tx_data1),
+ (const cyg_uint8*) NULL, NULL, true);
+ cyg_spi_transaction_end (&loopback_device);
+ diag_printf (" Tx data 41 (%u Bytes): %s\n", sizeof(tx_data1), tx_data1);
+ diag_printf (" Rx data 1 : %s\n", rx_data1);
+ diag_printf (" Tx data 42 (%u Bytes): %s\n", sizeof(tx_data2), tx_data2);
+ diag_printf (" Rx data 2 : %s\n", rx_data2);
+
+ if (memcmp (rx_data1, rx_data2, sizeof (tx_data1)) != 0) {
+ errors++;
+ diag_printf("Simple transfer loopback failed - mismatched data.\n");
+ errors++;
+ }
+}
+
+
+//---------------------------------------------------------------------------
+// Run all SPI interface loopback tests.
+
+
+void run_tests (void)
+{
+ bool polled = true;
+ diag_printf ("Running Freescale Kinetis/MPC5xxx DSPI driver loopback tests.\n");
+
+ diag_printf ("\nPolled\n");
+ run_test_tick (polled, 1024);
+ run_test_1 (polled, &tx_data0[3], 4);
+ run_test_2 (polled);
+ run_test_3 (polled);
+ run_test_4 (polled);
+
+ polled = false;
+ diag_printf ("\nInterrupt driven.\n");
+ run_test_tick (polled,2048);
+ run_test_1 (polled, &tx_data0[7], 10);
+ run_test_2 (polled);
+ run_test_3 (polled);
+ run_test_4 (polled);
+
+ if(errors)
+ CYG_TEST_FAIL("Errors detected");
+ else
+ CYG_TEST_PASS_FINISH ("Loopback tests ran OK");
+}
+
+//---------------------------------------------------------------------------
+// User startup - tests are run in their own thread.
+
+void cyg_user_start(void)
+{
+ CYG_TEST_INIT();
+ cyg_thread_create(
+ 10, // Arbitrary priority
+ (cyg_thread_entry_t*) run_tests, // Thread entry point
+ 0, //
+ "test_thread", // Thread name
+ &stack[0], // Stack
+ CYGNUM_HAL_STACK_SIZE_TYPICAL, // Stack size
+ &thread_handle, // Thread handle
+ &thread_data // Thread data structure
+ );
+ cyg_thread_resume(thread_handle);
+ cyg_scheduler_start();
+}
+
+//=============================================================================