1 /*******************************************************************
2 Components for embedded applications builded for
3 laboratory and medical instruments firmware
5 spi_drv.h - SPI communication driver interface
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
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 *******************************************************************/
31 #define SPI_MSG_FINISHED 0x040
32 #define SPI_MSG_ABORT 0x020
33 #define SPI_MSG_FAIL 0x010
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 */
44 int (*callback)(struct spi_drv *ifc, int code, struct spi_msg_head *msg);
48 typedef int (spi_ctrl_fnc_t)(struct spi_drv *ifc, int ctrl, void *p);
52 typedef struct spi_drv {
55 ul_list_head_t rq_queue;
56 spi_msg_head_t *msg_act;
57 spi_ctrl_fnc_t *ctrl_fnc;
61 #define SPI_CTRL_WAKE_RQ 1
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);
70 #endif /* _SPI_IFC_H_ */