2 * Copyright (C) 2015 Czech Technical University in Prague
5 * - Michal Sojka <sojkam1@fel.cvut.cz>
7 * Permission is hereby granted, free of charge, to any person
8 * obtaining a copy of this software and associated documentation
9 * files (the "Software"), to deal in the Software without
10 * restriction, including without limitation the rights to use,
11 * copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following
16 * The above copyright notice and this permission notice shall be
17 * included in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
21 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
23 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26 * OTHER DEALINGS IN THE SOFTWARE.
28 * Abstract: Platform independent SPI API.
35 #include "drv/spi_def.h"
36 #include "ul/ul_list.h"
39 #define SPI_MSG_FINISHED 0x040
40 #define SPI_MSG_ABORT 0x020
41 #define SPI_MSG_FAIL 0x010
43 #define SPI_CTRL_WAKE_RQ 1
47 typedef struct spi_msg {
48 uint16_t flags; // message flags
49 enum spi_device dev; // message destination
51 //uint16_t size_mode; // message frame len and mode
52 uint16_t rq_len; // requested transfer length
53 const uint8_t *tx_buf; // pointer to TX data
54 uint8_t *rx_buf; // pointer to RX data
57 int (*callback)(struct spi_drv *ifc, int code, struct spi_msg *msg); // Called when whole transfer is finished
58 long private; // If set -- msg is processed by HW
61 typedef int (spi_ctrl_fnc_t)(struct spi_drv *ifc, int ctrl, void *p);
63 typedef struct spi_drv {
64 uint16_t flags; // Flags
66 ul_list_head_t rq_queue; // Queue containing MSG requests to process
67 spi_msg_t *msg_act; // MSG being actually processed
68 spi_ctrl_fnc_t *ctrl_fnc; // Device dependent function responsible for sending data
72 UL_LIST_CUST_DEC(spi_rq_queue, spi_drv_t, spi_msg_t, rq_queue, node)
75 int spi_transfer(enum spi_device dev, int rq_len, const void *tx_buf, void *rx_buf);
76 int spi_msg_rq_ins(spi_msg_t *msg);
77 int8_t port_spi_set(const struct port_desc *port, void *values, size_t size);
79 #endif /* _SPI_DRV_H_ */