]> rtime.felk.cvut.cz Git - sysless.git/blob - libs4c/spi/spi_drv.h
448f42af21866cbde4b19fb2aa926099b7411108
[sysless.git] / libs4c / spi / spi_drv.h
1 /*******************************************************************
2   Components for embedded applications builded for
3   laboratory and medical instruments firmware
4
5   spi_drv.h - SPI communication driver interface
6
7   Copyright holders and project originators
8     (C) 2001-2004 by Pavel Pisa pisa@cmp.felk.cvut.cz
9     (C) 2002-2004 by PiKRON Ltd. http://www.pikron.com
10
11  The COLAMI components can be used and copied under next licenses
12    - MPL - Mozilla Public License
13    - GPL - GNU Public License
14    - LGPL - Lesser GNU Public License
15    - and other licenses added by project originators
16  Code can be modified and re-distributed under any combination
17  of the above listed licenses. If contributor does not agree with
18  some of the licenses, he can delete appropriate line.
19  Warning, if you delete all lines, you are not allowed to
20  distribute code or build project.
21  *******************************************************************/
22
23 #ifndef _SPI_IFC_H_
24 #define _SPI_IFC_H_
25
26 #include <inttypes.h>
27 #include <ul_list.h>
28
29 struct spi_drv;
30
31 #define SPI_MSG_FINISHED 0x040
32 #define SPI_MSG_ABORT    0x020
33 #define SPI_MSG_FAIL     0x010
34
35 typedef struct spi_msg_head {
36     uint16_t flags;     /* message flags */
37     uint16_t addr;      /* message destination address */
38     uint16_t size_mode; /* message frame len and mode */
39     uint16_t rq_len;    /* requested transfer length */
40     const uint8_t *tx_buf;      /* pointer to TX data */
41     uint8_t *rx_buf;    /* pointer to RX data */
42     ul_list_node_t node;
43     struct spi_drv *ifc;
44     int (*callback)(struct spi_drv *ifc, int code, struct spi_msg_head *msg);
45     long private;
46   } spi_msg_head_t;
47
48 typedef int (spi_ctrl_fnc_t)(struct spi_drv *ifc, int ctrl, void *p);
49
50 #define SPI_IFC_ON 1
51
52 typedef struct spi_drv {
53     uint16_t flags;
54     uint16_t self_addr;
55     ul_list_head_t rq_queue;
56     spi_msg_head_t *msg_act;
57     spi_ctrl_fnc_t *ctrl_fnc;
58     long private;
59   } spi_drv_t;
60
61 #define SPI_CTRL_WAKE_RQ 1
62
63 spi_drv_t *spi_find_drv(char *name, int number);
64 int spi_msg_rq_ins(spi_drv_t *ifc, spi_msg_head_t *msg);
65 int spi_msg_rq_rem(spi_msg_head_t *msg);
66 int spi_flush_all(spi_drv_t *ifc);
67 int spi_transfer(spi_drv_t *ifc, int addr, int rq_len,
68                    const void *tx_buf, void *rx_buf);
69
70 #endif /* _SPI_IFC_H_ */