00001
00038 #ifndef SPI_SPI_POLLED_H_INCLUDED
00039 #define SPI_SPI_POLLED_H_INCLUDED
00040
00041 #include <bitops.h>
00042 #include <board/spi.h>
00043
00051
00052 enum spi_polled_op_flags {
00053 SPI_OP_WRITE,
00054 SPI_OP_READ,
00055 SPI_OP_BUFFER,
00056 };
00057
00064 typedef void (*spi_start_func_t)(struct spi_master *spim, uint8_t tx_byte);
00065
00067 struct spi_master_polled {
00069 struct spi_master base;
00071 struct workqueue_task poll;
00073 spi_start_func_t start;
00075 uint8_t op;
00077 const uint8_t *write_data;
00079 uint8_t *read_data;
00080 #ifdef CONFIG_SPI_BUF_LIST_API
00081
00082 struct buffer *write_buffer;
00084 struct buffer *read_buffer;
00086 struct slist *write_buf_list;
00088 struct slist *read_buf_list;
00090 struct workqueue_task poll_next_buffer;
00091 #endif
00092 };
00093
00095 struct spi_device {
00097 struct board_spi_select sel;
00098 };
00099
00106 static inline struct spi_master_polled *spi_master_polled_of(
00107 struct spi_master *base)
00108 {
00109 return container_of(base, struct spi_master_polled, base);
00110 }
00111
00112 void spi_polled_start(struct spi_master *spim, uint8_t tx_byte,
00113 size_t residue);
00114
00123 static inline bool spi_polled_is_buffer_op(struct spi_master *spim)
00124 {
00125 #ifdef CONFIG_SPI_BUF_LIST_API
00126 struct spi_master_polled *spim_poll = spi_master_polled_of(spim);
00127
00128 return test_bit(SPI_OP_BUFFER, &spim_poll->op);
00129 #else
00130 return false;
00131 #endif
00132 }
00133
00139 static inline void spi_polled_sched_poll(struct spi_master *spim)
00140 {
00141 struct spi_master_polled *spim_poll = spi_master_polled_of(spim);
00142
00143 workqueue_add_task(&main_workqueue, &spim_poll->poll);
00144 }
00145
00146 void spi_polled_next_buffer(struct workqueue_task *task);
00147
00153 static inline void spi_polled_sched_next_buffer(struct spi_master *spim)
00154 {
00155 #ifdef CONFIG_SPI_BUF_LIST_API
00156 struct spi_master_polled *spim_poll = spi_master_polled_of(spim);
00157
00158 workqueue_add_task(&main_workqueue, &spim_poll->poll_next_buffer);
00159 #endif
00160 }
00161
00162 void spi_polled_write(struct spi_master *spim, const uint8_t *data,
00163 size_t len);
00164
00165 void spi_polled_read(struct spi_master *spim, uint8_t *data, size_t len);
00166
00167 void spi_polled_exchange(struct spi_master *spim, const uint8_t *write,
00168 uint8_t *read, size_t len);
00169
00170 void spi_polled_write_buf_list(struct spi_master *spim,
00171 struct slist *buf_list);
00172
00173 void spi_polled_read_buf_list(struct spi_master *spim, struct slist *buf_list);
00174
00175 void spi_polled_exchange_buf_list(struct spi_master *spim,
00176 struct slist *write_buf_list,
00177 struct slist *read_buf_list);
00178
00184 static inline void spi_polled_buf_list_init(struct spi_master *spim)
00185 {
00186 #ifdef CONFIG_SPI_BUF_LIST_API
00187 struct spi_master_polled *spim_poll = spi_master_polled_of(spim);
00188
00189 workqueue_task_init(&spim_poll->poll_next_buffer,
00190 spi_polled_next_buffer);
00191 #endif
00192 }
00193
00194 void spi_polled_master_init(struct spi_master *spim, workqueue_func_t poll,
00195 spi_start_func_t start);
00196
00198 #endif