1 |
786 |
skrzyp |
#ifndef CYGONCE_DEVS_SPI_CORTEXM_STM32_H
|
2 |
|
|
# define CYGONCE_DEVS_SPI_CORTEXM_STM32_H
|
3 |
|
|
//=============================================================================
|
4 |
|
|
//
|
5 |
|
|
// spi_a2fxxx.h
|
6 |
|
|
//
|
7 |
|
|
// Header definitions for Smartfusion Cortex-M3 SPI driver.
|
8 |
|
|
//
|
9 |
|
|
//=============================================================================
|
10 |
|
|
// ####ECOSGPLCOPYRIGHTBEGIN####
|
11 |
|
|
// -------------------------------------------
|
12 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
13 |
|
|
// Copyright (C) 2008, 2009, 2011 Free Software Foundation, Inc.
|
14 |
|
|
//
|
15 |
|
|
// eCos is free software; you can redistribute it and/or modify it under
|
16 |
|
|
// the terms of the GNU General Public License as published by the Free
|
17 |
|
|
// Software Foundation; either version 2 or (at your option) any later
|
18 |
|
|
// version.
|
19 |
|
|
//
|
20 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT
|
21 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
22 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
23 |
|
|
// for more details.
|
24 |
|
|
//
|
25 |
|
|
// You should have received a copy of the GNU General Public License
|
26 |
|
|
// along with eCos; if not, write to the Free Software Foundation, Inc.,
|
27 |
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
28 |
|
|
//
|
29 |
|
|
// As a special exception, if other files instantiate templates or use
|
30 |
|
|
// macros or inline functions from this file, or you compile this file
|
31 |
|
|
// and link it with other works to produce a work based on this file,
|
32 |
|
|
// this file does not by itself cause the resulting work to be covered by
|
33 |
|
|
// the GNU General Public License. However the source code for this file
|
34 |
|
|
// must still be made available in accordance with section (3) of the GNU
|
35 |
|
|
// General Public License v2.
|
36 |
|
|
//
|
37 |
|
|
// This exception does not invalidate any other reasons why a work based
|
38 |
|
|
// on this file might be covered by the GNU General Public License.
|
39 |
|
|
// -------------------------------------------
|
40 |
|
|
// ####ECOSGPLCOPYRIGHTEND####
|
41 |
|
|
//=============================================================================
|
42 |
|
|
//#####DESCRIPTIONBEGIN####
|
43 |
|
|
//
|
44 |
|
|
// Author(s): ccoutand, updated for Smartfusion Cortex-M3
|
45 |
|
|
// Original(s): Chris Holgate
|
46 |
|
|
// Date: 2011-04-25
|
47 |
|
|
// Purpose: Smartfusion Cortex-M3 SPI driver definitions.
|
48 |
|
|
// Description:
|
49 |
|
|
// Usage: #include <cyg/io/spi_a2fxxx.h>
|
50 |
|
|
//
|
51 |
|
|
//####DESCRIPTIONEND####
|
52 |
|
|
//
|
53 |
|
|
//=============================================================================
|
54 |
|
|
|
55 |
|
|
# include <pkgconf/hal.h>
|
56 |
|
|
# include <pkgconf/io_spi.h>
|
57 |
|
|
# include <pkgconf/devs_spi_cortexm_a2fxxx.h>
|
58 |
|
|
|
59 |
|
|
# include <cyg/infra/cyg_type.h>
|
60 |
|
|
# include <cyg/hal/drv_api.h>
|
61 |
|
|
# include <cyg/io/spi.h>
|
62 |
|
|
|
63 |
|
|
__externC cyg_uint32 a2fxxx_dma_ch_attach(cyg_uint8, cyg_ISR_t *, cyg_DSR_t *,
|
64 |
|
|
cyg_addrword_t);
|
65 |
|
|
|
66 |
|
|
typedef enum a2fxxx_spi_mode {
|
67 |
|
|
A2FXXX_SPI_MOTOROLA = 0x00,
|
68 |
|
|
A2FXXX_SPI_TI_SYNC_SERIAL = 0x01,
|
69 |
|
|
A2FXXX_SPI_NS_MICROWIRE = 0x02
|
70 |
|
|
} a2fxxx_spi_mode;
|
71 |
|
|
|
72 |
|
|
//-----------------------------------------------------------------------------
|
73 |
|
|
// Macro for defining a SPI device and attaching it to the appropriate bus.
|
74 |
|
|
//
|
75 |
|
|
// _name_ is the name of the SPI device. This will be used to reference a
|
76 |
|
|
// data structure of type cyg_spi_device which can be passed to the
|
77 |
|
|
// SPI driver API without needing a cast.
|
78 |
|
|
// _bus_ is the bus number to which this device is attached (1, 2 or 3).
|
79 |
|
|
// _csnum_ when _csgpio_ is set to false : is the chip select line used for
|
80 |
|
|
// this device, numbered from 0.
|
81 |
|
|
// when _csgpio_ is set to true : is the GPIO number used to drive the
|
82 |
|
|
// device chip select line.
|
83 |
|
|
// _csgpio_ when set to false, the device chip select line is controlled by the
|
84 |
|
|
// SPI controller.
|
85 |
|
|
// when set to true, the device chip select line is a GPIO of the processor
|
86 |
|
|
// control by the SPI driver.
|
87 |
|
|
// _proto_ is the SPI bus protocol:
|
88 |
|
|
// 0 -> Motorola SPI Protocol (_clpol_ and _clpha_ are valid in this mode)
|
89 |
|
|
// 1 -> National Semiconductor MICROWIRE Protocol
|
90 |
|
|
// 2 -> Texas Instruments (TI) Synchronous Serial Protocol
|
91 |
|
|
// _clpol_ is the SPI bus clock polarity used by the device. This must be
|
92 |
|
|
// set to 1 if a clock line pullup resistor is used and 0 if a
|
93 |
|
|
// clock line pulldown resistor is used.
|
94 |
|
|
// _clpha_ is the SPI bus clock phase used by the device.
|
95 |
|
|
// _brate_ is the SPI bus clock baud rate used by the device, measured in Hz.
|
96 |
|
|
// _csup_dly_ is the minimum delay between chip select assert and transfer
|
97 |
|
|
// start, measured in microseconds.
|
98 |
|
|
// _csdw_dly_ is the minimum delay between transfer end and chip select deassert,
|
99 |
|
|
// measured in microseconds.
|
100 |
|
|
// _trbt_dly_ is the minimum delay between consecutive transfers.
|
101 |
|
|
|
102 |
|
|
# define CYG_DEVS_SPI_CORTEXM_A2FXXX_DEVICE( \
|
103 |
|
|
_name_, _bus_, _csnum_, _csgpio_, _proto_, _clpol_, _clpha_, _brate_, _csup_dly_, _csdw_dly_, _trbt_dly_\
|
104 |
|
|
) \
|
105 |
|
|
cyg_spi_cortexm_a2fxxx_device_t _name_ ##_a2fxxx CYG_SPI_DEVICE_ON_BUS(_bus_) = { \
|
106 |
|
|
{ .spi_bus = (cyg_spi_bus*) &cyg_spi_a2fxxx_bus## _bus_ }, \
|
107 |
|
|
.dev_num = _csnum_, \
|
108 |
|
|
.cs_gpio = _csgpio_, \
|
109 |
|
|
.cs_gpio_n = _csnum_, \
|
110 |
|
|
.proto = _proto_, \
|
111 |
|
|
.cl_pol = _clpol_, \
|
112 |
|
|
.cl_pha = _clpha_, \
|
113 |
|
|
.cl_brate = _brate_, \
|
114 |
|
|
.cs_up_udly = _csup_dly_, \
|
115 |
|
|
.cs_dw_udly = _csdw_dly_, \
|
116 |
|
|
.tr_bt_udly = _trbt_dly_, \
|
117 |
|
|
.spi_cr_val = 0, \
|
118 |
|
|
}; \
|
119 |
|
|
extern cyg_spi_device _name_ __attribute__((alias ( #_name_ "_a2fxxx" )));
|
120 |
|
|
|
121 |
|
|
//-----------------------------------------------------------------------------
|
122 |
|
|
// A2FXXX SPI bus configuration and state.
|
123 |
|
|
|
124 |
|
|
typedef struct cyg_spi_cortexm_a2fxxx_bus_setup_s {
|
125 |
|
|
cyg_uint32 apb_freq; // Peripheral bus frequency (fp).
|
126 |
|
|
cyg_haladdress spi_reg_base; // Base address of SPI register block.
|
127 |
|
|
cyg_haladdress dma_reg_base; // Base address of DMA register block.
|
128 |
|
|
cyg_uint8 dma_tx_channel; // TX DMA channel for this bus.
|
129 |
|
|
cyg_uint8 dma_rx_channel; // RX DMA channel for this bus.
|
130 |
|
|
cyg_uint8 cs_gpio_num; // Number of chip selects for this bus.
|
131 |
|
|
const cyg_uint8 *cs_gpio_list; // List of GPIOs used as chip selects.
|
132 |
|
|
const cyg_uint8 *spi_gpio_list; // List of GPIOs used by the SPI interface.
|
133 |
|
|
cyg_bool dma_tx_pri; // Priority for DMA transmit.
|
134 |
|
|
cyg_bool dma_rx_pri; // Priority for DMA receive.
|
135 |
|
|
cyg_haladdress *rx_dma_null;
|
136 |
|
|
cyg_haladdress *tx_dma_null;
|
137 |
|
|
} cyg_spi_cortexm_a2fxxx_bus_setup_t;
|
138 |
|
|
|
139 |
|
|
typedef struct cyg_spi_cortexm_a2fxxx_bus_s {
|
140 |
|
|
// ---- Upper layer data ----
|
141 |
|
|
cyg_spi_bus spi_bus; // Upper layer SPI bus data.
|
142 |
|
|
|
143 |
|
|
// ---- Bus configuration constants ----
|
144 |
|
|
const cyg_spi_cortexm_a2fxxx_bus_setup_t *setup;
|
145 |
|
|
|
146 |
|
|
// ---- Driver state (private) ----
|
147 |
|
|
cyg_interrupt tx_intr_data; // DMA interrupt data (TX).
|
148 |
|
|
cyg_interrupt rx_intr_data; // DMA interrupt data (RX).
|
149 |
|
|
cyg_handle_t tx_intr_handle; // DMA interrupt handle (TX).
|
150 |
|
|
cyg_handle_t rx_intr_handle; // DMA interrupt handle (RX).
|
151 |
|
|
cyg_drv_mutex_t mutex; // Transfer mutex.
|
152 |
|
|
cyg_drv_cond_t condvar; // Transfer condition variable.
|
153 |
|
|
cyg_bool tx_dma_done; // Flags used to signal completion.
|
154 |
|
|
cyg_bool rx_dma_done; // Flags used to signal completion.
|
155 |
|
|
cyg_bool cs_up; // Chip select asserted flag.
|
156 |
|
|
|
157 |
|
|
} cyg_spi_cortexm_a2fxxx_bus_t;
|
158 |
|
|
|
159 |
|
|
//-----------------------------------------------------------------------------
|
160 |
|
|
// A2FXXX SPI device.
|
161 |
|
|
|
162 |
|
|
typedef struct cyg_spi_cortexm_a2fxxx_device_s {
|
163 |
|
|
// ---- Upper layer data ----
|
164 |
|
|
cyg_spi_device spi_device; // Upper layer SPI device data.
|
165 |
|
|
|
166 |
|
|
// ---- Device setup (user configurable) ----
|
167 |
|
|
cyg_uint8 dev_num; // Device number.
|
168 |
|
|
a2fxxx_spi_mode proto; // Protocol
|
169 |
|
|
cyg_bool cs_gpio; // True = use GPIO to control CS line
|
170 |
|
|
cyg_uint32 cs_gpio_n; // GPIO #
|
171 |
|
|
cyg_uint8 cl_pol; // Clock polarity (0 or 1).
|
172 |
|
|
cyg_uint8 cl_pha; // Clock phase (0 or 1).
|
173 |
|
|
cyg_uint32 cl_brate; // Clock baud rate.
|
174 |
|
|
cyg_uint16 cs_up_udly; // Minimum delay in us between CS up and transfer start.
|
175 |
|
|
cyg_uint16 cs_dw_udly; // Minimum delay in us between transfer end and CS down.
|
176 |
|
|
cyg_uint16 tr_bt_udly; // Minimum delay in us between two transfers.
|
177 |
|
|
|
178 |
|
|
// ---- Device state (private) ----
|
179 |
|
|
cyg_uint32 spi_cr_val; // SPI configuration register (initialised to 0).
|
180 |
|
|
|
181 |
|
|
} cyg_spi_cortexm_a2fxxx_device_t;
|
182 |
|
|
|
183 |
|
|
//-----------------------------------------------------------------------------
|
184 |
|
|
// Exported bus data structures.
|
185 |
|
|
|
186 |
|
|
# ifdef CYGHWR_DEVS_SPI_CORTEXM_A2FXXX_BUS1
|
187 |
|
|
externC cyg_spi_cortexm_a2fxxx_bus_t cyg_spi_a2fxxx_bus1;
|
188 |
|
|
# endif
|
189 |
|
|
|
190 |
|
|
# ifdef CYGHWR_DEVS_SPI_CORTEXM_A2FXXX_BUS2
|
191 |
|
|
externC cyg_spi_cortexm_a2fxxx_bus_t cyg_spi_a2fxxx_bus2;
|
192 |
|
|
# endif
|
193 |
|
|
|
194 |
|
|
//=============================================================================
|
195 |
|
|
#endif // CYGONCE_DEVS_SPI_CORTEXM_A2FXXX_H
|