]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/blob - rpp/include/drv/spi.h
Still fixing the library...
[pes-rpp/rpp-lib.git] / rpp / include / drv / spi.h
1 #ifndef _SPI_DRV_H_
2 #define _SPI_DRV_H_
3
4 //#include "sys_common.h"
5 //#include "ul_list.h"
6 //#include "string.h"
7 //#include "cpu_def.h"
8 #include "drv/drv.h"
9
10 #define SPI_MSG_FINISHED 0x040
11 #define SPI_MSG_ABORT    0x020
12 #define SPI_MSG_FAIL     0x010
13
14 struct spi_drv;
15
16 typedef struct spi_msg_head {
17     uint16_t flags;     /* message flags */
18     uint16_t addr;      /* message destination address -- used as
19                     index into the "address translation table"*/
20
21     //uint16_t size_mode;   /* message frame len and mode */
22     uint16_t rq_len;    /* requested transfer length */
23     const uint8_t *tx_buf;  /* pointer to TX data */
24     uint8_t *rx_buf;    /* pointer to RX data */
25
26     ul_list_node_t node;
27     //struct spi_drv *ifc;  /* */
28     int (*callback) (struct spi_drv * ifc, int code, struct spi_msg_head * msg); /* Called when whole transfer is finished */
29     long private;       /* If set -- msg is processed by HW */
30 } spi_msg_head_t;
31
32
33
34 #define SPI_CTRL_WAKE_RQ 1
35 typedef int (spi_ctrl_fnc_t) (struct spi_drv * ifc, int ctrl, void *p);
36
37 #define SPI_IFC_ON 1
38 typedef struct spi_drv {
39     uint16_t flags;         /* Flags */
40     //uint16_t self_addr;
41     ul_list_head_t rq_queue;    /* Queue containing MSG requests to process */
42     spi_msg_head_t *msg_act;    /* MSG being actually processed */
43     spi_ctrl_fnc_t *ctrl_fnc;   /* Device dependent function responsible for sending data */
44     //long private;
45 } spi_drv_t;
46
47 UL_LIST_CUST_DEC(spi_rq_queue, spi_drv_t, spi_msg_head_t, rq_queue, node)
48
49 /* ------------------------------------------------------------------------- */
50
51 typedef unsigned long spi_isr_lock_level_t;
52 #define spi_isr_lock    save_and_cli
53 #define  spi_isr_unlock restore_flags
54
55 /* ------------------------------------------------------------------------- */
56 int spi_transfer(spi_drv_t *ifc, int addr, int rq_len, const void *tx_buf, void *rx_buf);
57 spi_drv_t *spi_find_drv(char *name, int number);
58 int spi_msg_rq_ins(spi_drv_t *ifc, spi_msg_head_t *msg);
59
60 #endif /* _SPI_DRV_H_ */