1 |
810 |
skrzyp |
#ifndef CYGONCE_DEVS_SPI_OPENCORES_SIMPLE_SPI_H
|
2 |
|
|
#define CYGONCE_DEVS_SPI_OPENCORES_SIMPLE_SPI_H
|
3 |
|
|
//=============================================================================
|
4 |
|
|
//
|
5 |
|
|
// spi_simple_spi.h
|
6 |
|
|
//
|
7 |
|
|
// Header definitions for simple_spi driver.
|
8 |
|
|
//
|
9 |
|
|
//=============================================================================
|
10 |
|
|
// ####ECOSGPLCOPYRIGHTBEGIN####
|
11 |
|
|
// -------------------------------------------
|
12 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
13 |
|
|
// Copyright (C) 2008, 2009 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): Piotr Skrzypek
|
45 |
|
|
// Date: 2012-05-14
|
46 |
|
|
//
|
47 |
|
|
//####DESCRIPTIONEND####
|
48 |
|
|
//
|
49 |
|
|
//=============================================================================
|
50 |
|
|
|
51 |
|
|
#include <pkgconf/hal.h>
|
52 |
|
|
#include <pkgconf/io_spi.h>
|
53 |
|
|
#include <pkgconf/devs_spi_opencores_simple_spi.h>
|
54 |
|
|
|
55 |
|
|
#include <cyg/infra/cyg_type.h>
|
56 |
|
|
#include <cyg/hal/drv_api.h>
|
57 |
|
|
#include <cyg/io/spi.h>
|
58 |
|
|
|
59 |
|
|
// Use this macro in your code to declare SPI devices.
|
60 |
|
|
//
|
61 |
|
|
// _name_ name of the handler variable that must be passed on each call
|
62 |
|
|
// to eCos SPI API
|
63 |
|
|
//
|
64 |
|
|
// _bus_ SPI bus number to which the device is attached;
|
65 |
|
|
// numbers start from zero
|
66 |
|
|
//
|
67 |
|
|
// _cs_ number of the chip select line on the bus;
|
68 |
|
|
// numbers start from zero
|
69 |
|
|
//
|
70 |
|
|
// _polarity_ SPI polarity
|
71 |
|
|
//
|
72 |
|
|
// _phase_ SPI phase
|
73 |
|
|
//
|
74 |
|
|
// _freq_ SCK frequency in Hertz
|
75 |
|
|
//
|
76 |
|
|
// _cs_to_tran_ minimum delay between chip select and transfer, in us
|
77 |
|
|
//
|
78 |
|
|
// _tran_to_cs_ minimum delay between transfer and chip deselect, in us
|
79 |
|
|
//
|
80 |
|
|
// _tran_to_tran_ minimum delay between transfers, in us
|
81 |
|
|
|
82 |
|
|
#define CYG_DEVS_SPI_OPENCORES_SIMPLE_SPI_DEVICE(_name_, \
|
83 |
|
|
_bus_, \
|
84 |
|
|
_cs_, \
|
85 |
|
|
_polarity_, \
|
86 |
|
|
_phase_, \
|
87 |
|
|
_freq_, \
|
88 |
|
|
_cs_to_tran_, \
|
89 |
|
|
_tran_to_cs_, \
|
90 |
|
|
_tran_to_tran_) \
|
91 |
|
|
\
|
92 |
|
|
cyg_spi_opencores_simple_spi_device_t _name_ ##_simple_spi CYG_SPI_DEVICE_ON_BUS(_bus_) = { \
|
93 |
|
|
.spi_device = { \
|
94 |
|
|
.spi_bus = (cyg_spi_bus*) &cyg_spi_simple_spi_bus[_bus_] \
|
95 |
|
|
}, \
|
96 |
|
|
.cs = _cs_, \
|
97 |
|
|
.polarity = _polarity_, \
|
98 |
|
|
.phase = _phase_, \
|
99 |
|
|
.freq = _freq_, \
|
100 |
|
|
.cs_to_tran = _cs_to_tran_, \
|
101 |
|
|
.tran_to_cs = _tran_to_cs_, \
|
102 |
|
|
.tran_to_tran = _tran_to_tran_, \
|
103 |
|
|
}; \
|
104 |
|
|
extern cyg_spi_device _name_ __attribute__((alias ( #_name_ "_simple_spi" )));
|
105 |
|
|
|
106 |
|
|
typedef struct {
|
107 |
|
|
// Upper layer
|
108 |
|
|
cyg_spi_device spi_device;
|
109 |
|
|
|
110 |
|
|
// Private data
|
111 |
|
|
cyg_uint8 cs;
|
112 |
|
|
cyg_uint8 polarity;
|
113 |
|
|
cyg_uint8 phase;
|
114 |
|
|
cyg_uint32 freq;
|
115 |
|
|
cyg_uint16 cs_to_tran;
|
116 |
|
|
cyg_uint16 tran_to_cs;
|
117 |
|
|
cyg_uint16 tran_to_tran;
|
118 |
|
|
|
119 |
|
|
} cyg_spi_opencores_simple_spi_device_t;
|
120 |
|
|
|
121 |
|
|
typedef struct {
|
122 |
|
|
// Upper layer callbacks
|
123 |
|
|
cyg_spi_bus spi_bus;
|
124 |
|
|
|
125 |
|
|
// Private data
|
126 |
|
|
cyg_uint32 base_addr;
|
127 |
|
|
|
128 |
|
|
cyg_interrupt int_data;
|
129 |
|
|
cyg_handle_t int_handle;
|
130 |
|
|
|
131 |
|
|
cyg_drv_mutex_t mutex;
|
132 |
|
|
cyg_drv_cond_t condvar;
|
133 |
|
|
|
134 |
|
|
// State data
|
135 |
|
|
cyg_bool cs_asserted;
|
136 |
|
|
|
137 |
|
|
} cyg_spi_opencores_simple_spi_bus_t;
|
138 |
|
|
|
139 |
|
|
externC cyg_spi_opencores_simple_spi_bus_t cyg_spi_simple_spi_bus[];
|
140 |
|
|
|
141 |
|
|
//=============================================================================
|
142 |
|
|
#endif // CYGONCE_DEVS_SPI_OPENCORES_SIMPLE_SPI_H
|