]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/blob - rpp/include/drv/spi.h
Change license to MIT
[pes-rpp/rpp-lib.git] / rpp / include / drv / spi.h
1 /*
2  * Copyright (C) 2015 Czech Technical University in Prague
3  *
4  * Authors:
5  *     - Michal Sojka <sojkam1@fel.cvut.cz>
6  *
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
14  * conditions:
15  *
16  * The above copyright notice and this permission notice shall be
17  * included in all copies or substantial portions of the Software.
18  *
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.
27  *
28  * Abstract: Platform independent SPI API.
29  */
30
31 #ifndef _SPI_DRV_H_
32 #define _SPI_DRV_H_
33
34 #include "drv/port.h"
35 #include "drv/spi_def.h"
36 #include "ul/ul_list.h"
37
38 /* Flags */
39 #define SPI_MSG_FINISHED 0x040
40 #define SPI_MSG_ABORT    0x020
41 #define SPI_MSG_FAIL     0x010
42
43 #define SPI_CTRL_WAKE_RQ 1
44
45 struct spi_drv;
46
47 typedef struct spi_msg {
48         uint16_t flags;         // message flags
49         enum spi_device dev;    // message destination
50
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
55
56         ul_list_node_t node;
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
59 } spi_msg_t;
60
61 typedef int (spi_ctrl_fnc_t)(struct spi_drv *ifc, int ctrl, void *p);
62
63 typedef struct spi_drv {
64         uint16_t flags;         // Flags
65         //uint16_t self_addr;
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
69         //long private;
70 } spi_drv_t;
71
72 UL_LIST_CUST_DEC(spi_rq_queue, spi_drv_t, spi_msg_t, rq_queue, node)
73
74 int spi_init();
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);
78
79 #endif /* _SPI_DRV_H_ */