1 /* Copyright (C) 2012-2013, 2015 Czech Technical University in Prague
3 * This document contains proprietary information belonging to Czech
4 * Technical University in Prague. Passing on and copying of this
5 * document, and communication of its contents is not permitted
6 * without prior written authorization.
12 #include "drv/spi_tms570.h"
14 static boolean_t spi_initialized = FALSE;
18 if (spi_initialized == TRUE)
20 spi_initialized = TRUE;
26 static int spi_transfer_callback(struct spi_drv *ifc, int code, struct spi_msg *msg)
34 * Send SPI message asynchronously
36 * This function is thread safe.
38 int spi_msg_rq_ins(spi_msg_t *msg)
40 spi_isr_lock_level_t saveif;
41 spi_drv_t *ifc = spi_tms570_get_iface(msg->dev);
44 spi_rq_queue_insert(ifc, msg);
45 spi_isr_unlock(saveif);
46 ifc->ctrl_fnc(ifc, SPI_CTRL_WAKE_RQ, NULL);
51 * Send SPI message synchronously
53 * This function is thread safe.
55 int spi_transfer(enum spi_device dev, int rq_len, const void *tx_buf, void *rx_buf)
61 spi_rq_queue_init_detached(&msg);
66 msg.callback = spi_transfer_callback;
69 if (spi_msg_rq_ins(&msg) < 0)
72 /* Wait for the request completion */
77 if (msg.flags & (SPI_MSG_FAIL | SPI_MSG_ABORT))
83 #define MIN(a,b) ((a) < (b) ? (a) : (b))
85 int8_t port_spi_set(const struct port_desc *port, void *values, size_t size)
89 assert(port->numchn == 1);
90 assert(size == port->bpch/8);
91 assert(size <= sizeof(rx));
93 spi_transfer(port->cfg.spi.dev, size, values, rx);
95 memcpy(values, rx, MIN(size, port->numchn * port->bpch/8));