1 #ifndef CYGONCE_IO_SPI_H
2 #define CYGONCE_IO_SPI_H
4 //=============================================================================
8 // Generic API for accessing devices on an SPI bus
10 //=============================================================================
11 //####ECOSGPLCOPYRIGHTBEGIN####
12 // -------------------------------------------
13 // This file is part of eCos, the Embedded Configurable Operating System.
14 // Copyright (C) 2004 eCosCentric Limited
16 // eCos is free software; you can redistribute it and/or modify it under
17 // the terms of the GNU General Public License as published by the Free
18 // Software Foundation; either version 2 or (at your option) any later version.
20 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
21 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
22 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25 // You should have received a copy of the GNU General Public License along
26 // with eCos; if not, write to the Free Software Foundation, Inc.,
27 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
29 // As a special exception, if other files instantiate templates or use macros
30 // or inline functions from this file, or you compile this file and link it
31 // with other works to produce a work based on this file, this file does not
32 // by itself cause the resulting work to be covered by the GNU General Public
33 // License. However the source code for this file must still be made available
34 // in accordance with section (3) of the GNU General Public License.
36 // This exception does not invalidate any other reasons why a work based on
37 // this file might be covered by the GNU General Public License.
38 // -------------------------------------------
39 //####ECOSGPLCOPYRIGHTEND####
40 //=============================================================================
41 //####DESCRIPTIONBEGIN####
45 //####DESCRIPTIONEND####
46 //=============================================================================
48 #include <pkgconf/infra.h>
49 #include <cyg/infra/cyg_type.h>
50 #include <cyg/hal/drv_api.h>
51 #include <cyg/hal/hal_tables.h>
52 #include <cyg/hal/hal_io.h>
54 typedef struct cyg_spi_device {
55 struct cyg_spi_bus* spi_bus;
58 typedef struct cyg_spi_bus {
59 cyg_drv_mutex_t spi_lock;
60 #ifdef CYGDBG_USE_ASSERTS
61 cyg_spi_device* spi_current_device;
63 void (*spi_transaction_begin)(cyg_spi_device*);
64 void (*spi_transaction_transfer)(cyg_spi_device*, cyg_bool, cyg_uint32, const cyg_uint8*, cyg_uint8*, cyg_bool);
65 void (*spi_transaction_tick)(cyg_spi_device*, cyg_bool, cyg_uint32);
66 void (*spi_transaction_end)(cyg_spi_device*);
67 int (*spi_get_config)(cyg_spi_device*, cyg_uint32, void*, cyg_uint32*);
68 int (*spi_set_config)(cyg_spi_device*, cyg_uint32, const void*, cyg_uint32*);
71 #ifdef CYGDBG_USE_ASSERTS
72 # define CYG_SPI_BUS_COMMON_INIT(_bus_) \
74 cyg_drv_mutex_init( & ((_bus_)->spi_lock)); \
75 (_bus_)->spi_current_device = (cyg_spi_device*)0; \
78 # define CYG_SPI_BUS_COMMON_INIT(_bus_) \
80 cyg_drv_mutex_init( & ((_bus_)->spi_lock)); \
84 // All devices should be in a per-bus table
85 #define CYG_SPI_DEFINE_BUS_TABLE(_type_, _which_) \
86 CYG_HAL_TABLE_BEGIN(cyg_spi_bus_ ## _which_ ## _devs, spibus_ ## _which_); \
87 CYG_HAL_TABLE_END(cyg_spi_bus_ ## _which_ ## _devs_end, spibus_ ## _which_); \
88 extern _type_ cyg_spi_bus_## _which_ ## _devs[], cyg_spi_bus_## _which_ ## _devs_end
90 #define CYG_SPI_DEVICE_ON_BUS(_which_) CYG_HAL_TABLE_ENTRY( spibus_ ## _which_)
92 // Keys for use with the get_config() and set_config() operations.
93 #define CYG_IO_GET_CONFIG_SPI_CLOCKRATE 0x00000800
94 #define CYG_IO_SET_CONFIG_SPI_CLOCKRATE 0x00000880
96 // The simple I/O operations.
97 externC void cyg_spi_transfer(cyg_spi_device*, cyg_bool, cyg_uint32, const cyg_uint8*, cyg_uint8*);
98 externC void cyg_spi_tick(cyg_spi_device*, cyg_bool, cyg_uint32);
99 externC int cyg_spi_get_config(cyg_spi_device*, cyg_uint32, void*, cyg_uint32*);
100 externC int cyg_spi_set_config(cyg_spi_device*, cyg_uint32, const void*, cyg_uint32*);
102 // Support for more complicated transactions.
103 externC void cyg_spi_transaction_begin(cyg_spi_device*);
104 externC cyg_bool cyg_spi_transaction_begin_nb(cyg_spi_device*);
105 externC void cyg_spi_transaction_transfer(cyg_spi_device*, cyg_bool, cyg_uint32, const cyg_uint8*, cyg_uint8*, cyg_bool);
106 externC void cyg_spi_transaction_tick(cyg_spi_device*, cyg_bool, cyg_uint32);
107 externC void cyg_spi_transaction_end(cyg_spi_device*);
109 // Allow the HAL to export named devices, without introducing circular
110 // dependencies in the header files.
111 #ifdef HAL_SPI_EXPORTED_DEVICES
112 HAL_SPI_EXPORTED_DEVICES
115 //-----------------------------------------------------------------------------
116 #endif // ifndef CYGONCE_IO_SPI_H