3 * @file spi_resp_transl.h
5 * @copyright Copyright (C) 2012-2013 Czech Technical University in Prague
7 * @author Michal Horn <hornmich@fel.cvut.cz>
13 //#include "sys_common.h"
14 //#include "drv_spi.h"
15 #include "ul/ul_list.h"
19 #define SPI_CTRL_WAKE_RQ 1
21 /* ------------------------------------------------------------------------- */
23 #define SPI_MSG_FINISHED 0x040
24 #define SPI_MSG_ABORT 0x020
25 #define SPI_MSG_FAIL 0x010
27 #define SPI_BR_FORMAT0 1000000 /**< Clock rate for data format 0 in Hz. */
28 #define SPI_BR_FORMAT1 1000000 /**< Clock rate for data format 0 in Hz. */
29 #define SPI_BR_FORMAT2 1000000 /**< Clock rate for data format 0 in Hz. */
30 #define SPI_BR_FORMAT3 1000000 /**< Clock rate for data format 0 in Hz. */
35 typedef int (spi_ctrl_fnc_t)(struct spi_drv *ifc, int ctrl, void *p);
37 typedef struct spi_msg_head {
38 uint16_t flags; // message flags
39 uint16_t addr; // message destination address -- used as index into the "address translation table"*/
41 //uint16_t size_mode; // message frame len and mode
42 uint16_t rq_len; // requested transfer length
43 const uint8_t *tx_buf; // pointer to TX data
44 uint8_t *rx_buf; // pointer to RX data
47 //struct spi_drv *ifc;
48 int (*callback)(struct spi_drv *ifc, int code, struct spi_msg_head *msg); // Called when whole transfer is finished
49 long private; // If set -- msg is processed by HW
52 typedef struct spi_drv {
53 uint16_t flags; // Flags
55 ul_list_head_t rq_queue; // Queue containing MSG requests to process
56 spi_msg_head_t *msg_act; // MSG being actually processed
57 spi_ctrl_fnc_t *ctrl_fnc; // Device dependent function responsible for sending data
61 /* ------------------------------------------------------------------------- */
63 typedef unsigned long spi_isr_lock_level_t;
64 #define spi_isr_lock save_and_cli
65 #define spi_isr_unlock restore_flags
67 /* ------------------------------------------------------------------------- */
69 #define spi_compat_REG2 ((spiBASE_compat_t *)0xFFF7F600U)
70 #define spi_compat_REG4 ((spiBASE_compat_t *)0xFFF7FA00U)
71 #define mibspi_compat_REG1 ((spiBASE_compat_t *)0xFFF7F400U)
72 #define mibspi_compat_REG3 ((spiBASE_compat_t *)0xFFF7F800U)
73 #define mibspi_compat_REG5 ((spiBASE_compat_t *)0xFFF7FC00U) /* NOT USED ON RPP BOARD */
76 #define SPI_FLG_TXINT_m (1 << 9)
77 #define SPI_FLG_RXINT_m (1 << 8)
79 #define SPI_INT0_TXINTENA_m (1 << 9)
80 #define SPI_INT0_RXINTENA_m (1 << 8)
82 #define SPI_DAT1_CSHOLD_m (1 << 28)
84 /* Used as CSNR in DATA1 reg */
102 typedef volatile struct spiBase {
103 uint32_t GCR0; /**< 0x0000: Global Control 0 */
104 #if ((__little_endian__ == 1) || (__LITTLE_ENDIAN__ == 1))
105 uint32_t GCR1 : 8U; /**< 0x0007: Global Control 1 */
106 uint32_t PD : 1U; /**< 0x0006: Power down bit */
108 uint32_t LB : 1U; /**< 0x0005: Loop back bit */
110 uint32_t ENA : 1U; /**< 0x0004: SPI Enable bit */
112 uint32_t INT0 : 16U; /**< 0x000A: Interrupt Enable bits */
113 uint32_t DMAREQEN : 1U; /**< 0x0009: DMA Request enable */
115 uint32_t ENAHIGHZ : 1U; /**< 0x0008: Enable HIGHZ outputs */
119 uint32_t ENA : 1U; /**< 0x0004: SPI Enable bit */
121 uint32_t LB : 1U; /**< 0x0005: Loop back bit */
123 uint32_t PD : 1U; /**< 0x0006: Power down bit */
124 uint32_t GCR1 : 8U; /**< 0x0007: Global Control 1 */
126 uint32_t ENAHIGHZ : 1U; /**< 0x0008: Enable HIGHZ outputs */
128 uint32_t DMAREQEN : 1U; /**< 0x0009: DMA Request enable */
129 uint32_t INT0 : 16U; /**< 0x000A: Interrupt Enable bits */
131 uint32_t LVL; /**< 0x000C: Interrupt Level */
132 #if ((__little_endian__ == 1) || (__LITTLE_ENDIAN__ == 1))
133 uint32_t FLG : 16U; /**< 0x0012: Interrupt flags */
135 uint32_t BUFINIT : 1U; /**< 0x0010: Buffer initialization active flag */
139 uint32_t BUFINIT : 1U; /**< 0x0010: Buffer initialization active flag */
141 uint32_t FLG : 16U; /**< 0x0012: Interrupt flags */
143 uint32_t PCFUN; /**< 0x0014: Function Pin Enable */
144 uint32_t PCDIR; /**< 0x0018: Pin Direction */
145 uint32_t PCDIN; /**< 0x001C: Pin Input Latch */
146 uint32_t PCDOUT; /**< 0x0020: Pin Output Latch */
147 uint32_t PCSET; /**< 0x0024: Output Pin Set */
148 uint32_t PCCLR; /**< 0x0028: Output Pin Clr */
149 uint32_t PCPDR; /**< 0x002C: Open Drain Output Enable */
150 uint32_t PCDIS; /**< 0x0030: Pullup/Pulldown Disable */
151 uint32_t PCPSL; /**< 0x0034: Pullup/Pulldown Selection */
152 uint32_t DAT0; /**< 0x0038: Transmit Data */
153 uint32_t DAT1; /**< 0x003C: Transmit Data with Format and Chip Select */
154 uint32_t BUF; /**< 0x0040: Receive Buffer */
155 uint32_t EMU; /**< 0x0044: Emulation Receive Buffer */
156 uint32_t DELAY; /**< 0x0048: Delays */
157 uint32_t CSDEF; /**< 0x004C: Default Chip Select */
158 uint32_t FMT0; /**< 0x0050: Data Format 0 */
159 uint32_t FMT1; /**< 0x0054: Data Format 1 */
160 uint32_t FMT2; /**< 0x0058: Data Format 2 */
161 uint32_t FMT3; /**< 0x005C: Data Format 3 */
162 uint32_t INTVECT0; /**< 0x0060: Interrupt Vector 0 */
163 uint32_t INTVECT1; /**< 0x0064: Interrupt Vector 1 */
164 uint32_t SRSEL; /**< 0x0068: Slew Rate Select */
166 uint32_t PMCTRL; /**< 0x006C: Parallel Mode Control */
167 #if ((__little_endian__ == 1) || (__LITTLE_ENDIAN__ == 1))
168 uint32_t MIBSPIE : 16U; /**< 0x0072: MibSPI Enable */
169 uint32_t RAMACCESS : 16U; /**< 0x0070: RX Ram Write Access Enable */
171 uint32_t RAMACCESS : 16U; /**< 0x0070: RX Ram Write Access Enable */
172 uint32_t MIBSPIE : 16U; /**< 0x0072: MibSPI Enable */
175 uint32_t RESERVED[48U]; /**< 0x006C to 0x0130: Reserved */
176 uint32_t IOLPKTSTCR; /**< 0x0134: IO loopback */
180 /* SPI devices connected to SPI interface */
181 typedef struct spi_dev {
182 unsigned int cs; /* Combination of CS (+GPIO CS) necessary to enable the device */
183 unsigned char dfsel; /* Data word format */
184 unsigned char wdel; /* Enable the delay counter at the end of the current transaction */
185 unsigned char cshold; /* Chip select hold mode */
186 unsigned int dlen; /* Data len needed for one complete transfer */
190 typedef struct spi_tms570_drv {
192 spiBASE_compat_t *spi; /* Base Reg. for SPI device register array */
193 unsigned txcnt; /* No. of transfered bytes for msg_act */
194 unsigned rxcnt; /* No. of received bytes for msg_act */
195 spi_dev_t *spi_devs; /* Pointer to table holding information about SPI devices bound to the interface */
196 uint32_t transfer_ctrl; /* Transfer configuration -- upper 16 bits of SPIDAT1 register */
199 //extern spi_tms570_drv_t spi_tms570_ifcs[4];
200 //extern spi_dev_t spi_devs[];
201 int spi_tms570_init(void);
203 spi_drv_t *spi_find_drv(char *name, int number);
206 #endif /* _MYSPI_H_ */