1 /* Copyright (C) 2012-2013, 2015 Czech Technical University in Prague
4 * - Michal Horn <hornmich@fel.cvut.cz>
6 * This document contains proprietary information belonging to Czech
7 * Technical University in Prague. Passing on and copying of this
8 * document, and communication of its contents is not permitted
9 * without prior written authorization.
14 * This file contains getter and setter functions for SPI port type.
17 //#include "hal_port_spi.h"
18 // Cannot include upper layer
19 //#include "drv_spi.h"
20 //#include "cmdproc.h"
24 /** Buffer for spi command to be sent */
25 uint8_t spi_port_buf_tx[PORT_BUF];
26 /** Buffer for spi response */
27 uint8_t spi_port_buf_rx[PORT_BUF];
31 * Transfer command through the spi
32 * @param[in] config Address of the SPI
33 * @param[in] num_bytes Number of bytes to be trasfered
34 * @param[in] commands SPI command to be sent
35 * @return spi response
37 uint32_t hal_spi_port_transfer_command(uint32_t *config, uint32_t num_bytes, const uint32_t *commands)
43 for (i = 0; i < num_bytes; i++)
44 spi_port_buf_tx[i] = commands[i];
46 ifc = spi_find_drv(NULL, config[0]);
50 if (!(ifc->flags & SPI_IFC_ON))
53 spi_transfer(ifc, config[1], num_bytes, spi_port_buf_tx, spi_port_buf_rx);
55 for (i = 0; i < num_bytes; i++)
56 ret |= spi_port_buf_rx[i] << i*8;