]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/blob - rpp/include/drv/spi_tms570.h
Make configuration of SPI devices target dependent
[pes-rpp/rpp-lib.git] / rpp / include / drv / spi_tms570.h
1 /**
2  *
3  * @file spi_resp_transl.h
4  *
5  * @copyright Copyright (C) 2012-2013, 2015 Czech Technical University in Prague
6  *
7  * @author Michal Horn <hornmich@fel.cvut.cz>
8  *
9  * This document contains proprietary information belonging to Czech
10  * Technical University in Prague. Passing on and copying of this
11  * document, and communication of its contents is not permitted
12  * without prior written authorization.
13  */
14
15 #ifndef _MYSPI_H_
16 #define _MYSPI_H_
17
18 //#include "sys_common.h"
19 //#include "drv_spi.h"
20 #include "ul/ul_list.h"
21 #include "types.h"
22 #include "sys/cpu_def.h"
23
24 #define SPI_IFC_ON 1
25 #define SPI_CTRL_WAKE_RQ 1
26
27 /* ------------------------------------------------------------------------- */
28
29 #define SPI_MSG_FINISHED 0x040
30 #define SPI_MSG_ABORT    0x020
31 #define SPI_MSG_FAIL     0x010
32
33 #define SPI_BR_FORMAT0  1000000 /**< Clock rate for data format 0 in Hz. */
34 #define SPI_BR_FORMAT1  1000000 /**< Clock rate for data format 0 in Hz. */
35 #define SPI_BR_FORMAT2  1000000 /**< Clock rate for data format 0 in Hz. */
36 #define SPI_BR_FORMAT3  1000000 /**< Clock rate for data format 0 in Hz. */
37
38
39 struct spi_drv;
40
41 typedef int (spi_ctrl_fnc_t)(struct spi_drv *ifc, int ctrl, void *p);
42
43 typedef struct spi_msg_head {
44         uint16_t flags;         // message flags
45         uint16_t addr;          // message destination address -- used as index into the "address translation table"*/
46
47         //uint16_t size_mode;   // message frame len and mode
48         uint16_t rq_len;        // requested transfer length
49         const uint8_t *tx_buf;  // pointer to TX data
50         uint8_t *rx_buf;        // pointer to RX data
51
52         ul_list_node_t node;
53         //struct spi_drv *ifc;
54         int (*callback)(struct spi_drv *ifc, int code, struct spi_msg_head *msg);    // Called when whole transfer is finished
55         long private;       // If set -- msg is processed by HW
56 } spi_msg_head_t;
57
58 typedef struct spi_drv {
59         uint16_t flags;         // Flags
60         //uint16_t self_addr;
61         ul_list_head_t rq_queue;    // Queue containing MSG requests to process
62         spi_msg_head_t *msg_act;    // MSG being actually processed
63         spi_ctrl_fnc_t *ctrl_fnc;   // Device dependent function responsible for sending data
64         //long private;
65 } spi_drv_t;
66
67 /* ------------------------------------------------------------------------- */
68
69 typedef unsigned long spi_isr_lock_level_t;
70 #define spi_isr_lock    save_and_cli
71 #define  spi_isr_unlock restore_flags
72
73 /* ------------------------------------------------------------------------- */
74
75 #define spi_compat_REG2     ((spiBASE_compat_t *)0xFFF7F600U)
76 #define spi_compat_REG4     ((spiBASE_compat_t *)0xFFF7FA00U)
77 #define mibspi_compat_REG1  ((spiBASE_compat_t *)0xFFF7F400U)
78 #define mibspi_compat_REG3  ((spiBASE_compat_t *)0xFFF7F800U)
79 #define mibspi_compat_REG5  ((spiBASE_compat_t *)0xFFF7FC00U)  /* NOT USED ON RPP BOARD */
80
81
82 #define SPI_FLG_TXINT_m     (1 << 9)
83 #define SPI_FLG_RXINT_m     (1 << 8)
84
85 #define SPI_INT0_TXINTENA_m (1 << 9)
86 #define SPI_INT0_RXINTENA_m (1 << 8)
87
88 #define SPI_DAT1_CSHOLD_m   (1 << 28)
89
90 /* Used as CSNR in DATA1 reg */
91 enum spiChipSelect {
92         SPI_CS_NONE = 0x00FF,
93         SPI_CS_0 =    0x00FE,
94         SPI_CS_1 =    0x00FD,
95         SPI_CS_2 =    0x00FB,
96         SPI_CS_3 =    0x00F7,
97         SPI_CS_4 =    0x00EF,
98         SPI_CS_5 =    0x00DF,
99         SPI_CS_6 =    0x00BF,
100         SPI_CS_7 =    0x007F,
101         SPI_CS_DMM0 = 0x0100,
102         SPI_CS_DMM1 = 0x0200,
103         SPI_CS_DMM2 = 0x0400
104 };
105
106
107
108 typedef volatile struct spiBase {
109         uint32_t GCR0;          /**< 0x0000: Global Control 0 */
110 #if ((__little_endian__ == 1) || (__LITTLE_ENDIAN__ == 1))
111         uint32_t GCR1 : 8U;       /**< 0x0007: Global Control 1 */
112         uint32_t PD : 1U;         /**< 0x0006: Power down bit */
113         uint32_t : 7U;
114         uint32_t LB : 1U;         /**< 0x0005: Loop back bit */
115         uint32_t : 7U;
116         uint32_t ENA : 1U;        /**< 0x0004: SPI Enable bit */
117         uint32_t : 7U;
118         uint32_t INT0 : 16U;      /**< 0x000A: Interrupt Enable bits */
119         uint32_t DMAREQEN : 1U;       /**< 0x0009: DMA Request enable */
120         uint32_t : 7U;
121         uint32_t ENAHIGHZ : 1U;       /**< 0x0008: Enable HIGHZ outputs */
122         uint32_t : 7U;
123 #else
124         uint32_t : 7U;
125         uint32_t ENA : 1U;        /**< 0x0004: SPI Enable bit */
126         uint32_t : 7U;
127         uint32_t LB : 1U;         /**< 0x0005: Loop back bit */
128         uint32_t : 7U;
129         uint32_t PD : 1U;         /**< 0x0006: Power down bit */
130         uint32_t GCR1 : 8U;       /**< 0x0007: Global Control 1 */
131         uint32_t : 7U;
132         uint32_t ENAHIGHZ : 1U;       /**< 0x0008: Enable HIGHZ outputs */
133         uint32_t : 7U;
134         uint32_t DMAREQEN : 1U;       /**< 0x0009: DMA Request enable */
135         uint32_t INT0 : 16U;      /**< 0x000A: Interrupt Enable bits */
136 #endif
137         uint32_t LVL;           /**< 0x000C: Interrupt Level */
138 #if ((__little_endian__ == 1) || (__LITTLE_ENDIAN__ == 1))
139         uint32_t FLG : 16U;       /**< 0x0012: Interrupt flags */
140         uint32_t : 8U;
141         uint32_t BUFINIT : 1U;        /**< 0x0010: Buffer initialization active flag */
142         uint32_t : 7U;
143 #else
144         uint32_t : 7U;
145         uint32_t BUFINIT : 1U;        /**< 0x0010: Buffer initialization active flag */
146         uint32_t : 8U;
147         uint32_t FLG : 16U;       /**< 0x0012: Interrupt flags */
148 #endif
149         uint32_t PCFUN;         /**< 0x0014: Function Pin Enable */
150         uint32_t PCDIR;         /**< 0x0018: Pin Direction */
151         uint32_t PCDIN;         /**< 0x001C: Pin Input Latch */
152         uint32_t PCDOUT;        /**< 0x0020: Pin Output Latch */
153         uint32_t PCSET;         /**< 0x0024: Output Pin Set */
154         uint32_t PCCLR;         /**< 0x0028: Output Pin Clr */
155         uint32_t PCPDR;         /**< 0x002C: Open Drain Output Enable */
156         uint32_t PCDIS;         /**< 0x0030: Pullup/Pulldown Disable */
157         uint32_t PCPSL;         /**< 0x0034: Pullup/Pulldown Selection */
158         uint32_t DAT0;          /**< 0x0038: Transmit Data */
159         uint32_t DAT1;          /**< 0x003C: Transmit Data with Format and Chip Select */
160         uint32_t BUF;           /**< 0x0040: Receive Buffer */
161         uint32_t EMU;           /**< 0x0044: Emulation Receive Buffer */
162         uint32_t DELAY;         /**< 0x0048: Delays */
163         uint32_t CSDEF;         /**< 0x004C: Default Chip Select */
164         uint32_t FMT0;          /**< 0x0050: Data Format 0 */
165         uint32_t FMT1;          /**< 0x0054: Data Format 1 */
166         uint32_t FMT2;          /**< 0x0058: Data Format 2 */
167         uint32_t FMT3;          /**< 0x005C: Data Format 3 */
168         uint32_t INTVECT0;      /**< 0x0060: Interrupt Vector 0 */
169         uint32_t INTVECT1;      /**< 0x0064: Interrupt Vector 1 */
170         uint32_t SRSEL;         /**< 0x0068: Slew Rate Select */
171
172         uint32_t PMCTRL;        /**< 0x006C: Parallel Mode Control */
173 #if ((__little_endian__ == 1) || (__LITTLE_ENDIAN__ == 1))
174         uint32_t MIBSPIE : 16U;       /**< 0x0072: MibSPI Enable */
175         uint32_t RAMACCESS : 16U;     /**< 0x0070: RX Ram Write Access Enable */
176 #else
177         uint32_t RAMACCESS : 16U;     /**< 0x0070: RX Ram Write Access Enable */
178         uint32_t MIBSPIE : 16U;       /**< 0x0072: MibSPI Enable */
179 #endif
180
181         uint32_t RESERVED[48U];     /**< 0x006C to 0x0130: Reserved */
182         uint32_t IOLPKTSTCR;        /**< 0x0134: IO loopback */
183 } spiBASE_compat_t;
184
185
186 /* SPI devices connected to SPI interface */
187 typedef struct spi_dev {
188         unsigned int cs;    /* Combination of CS (+GPIO CS) necessary to enable the device */
189         unsigned char dfsel;    /* Data word format */
190         unsigned char wdel; /* Enable the delay counter at the end of the current transaction */
191         unsigned char cshold;   /* Chip select hold mode */
192         unsigned int dlen;  /* Data len needed for one complete transfer */
193 } spi_dev_t;
194
195 /* SPI interface */
196 typedef struct spi_tms570_drv {
197         spi_drv_t spi_drv;
198         spiBASE_compat_t *spi;      /* Base Reg. for SPI device register array */
199         unsigned txcnt; /* No. of transfered bytes for msg_act */
200         unsigned rxcnt; /* No. of received bytes for msg_act */
201         spi_dev_t *spi_devs;    /* Pointer to table holding information about SPI devices bound to the interface */
202         uint32_t transfer_ctrl; /* Transfer configuration -- upper 16 bits of SPIDAT1 register */
203 } spi_tms570_drv_t;
204
205 //extern spi_tms570_drv_t spi_tms570_ifcs[4];
206 //extern spi_dev_t spi_devs[];
207 int spi_tms570_init(spi_tms570_drv_t *ifcs, int count);
208
209 spi_drv_t *spi_find_drv(char *name, int number);
210
211
212 #endif /* _MYSPI_H_ */