kosmos/source/firmware/kernel/driver/include/spi.h

76 lines
3.2 KiB
C
Raw Permalink Normal View History

2016-07-28 19:02:54 +00:00
//! \file spi.h
//! \author tkl
//! \date Feb 11, 2012
//! \brief Header file of the architecture independent spi driver.
#ifndef SPI_H_
#define SPI_H_
//-----------------------------------------------------------------------------
//! \brief Function pointer to the open function.
typedef int (*spi_fp_open_t)(const void *);
//-----------------------------------------------------------------------------
//! \brief Function pointer to the close function.
typedef int (*spi_fp_close_t)(const void *);
//-----------------------------------------------------------------------------
//! \brief Function pointer to the assert chip select function.
typedef void (*spi_fp_assert_cs_t)(const void *);
//-----------------------------------------------------------------------------
//! \brief Function pointer to the deassert chip select function.
typedef void (*spi_fp_deassert_cs_t)(const void *);
//-----------------------------------------------------------------------------
//! \brief Function pointer to the receive / transmit function.
typedef char (*spi_fp_rxtx_byte_t)(const void *, char);
//-----------------------------------------------------------------------------
//! \brief Contains the function pointer to access the spi driver.
struct spi_fp {
const spi_fp_open_t open; //!< Function pointer to the open function.
const spi_fp_close_t close; //!< Function pointer to the close function.
const spi_fp_assert_cs_t assert_cs; //!< Function pointer to the assert chip select function.
const spi_fp_deassert_cs_t deassert_cs; //!< Function pointer to the deassert chip select function.
const spi_fp_rxtx_byte_t rxtx_byte; //!< Function pointer to the receive / transmit function.
};
//-----------------------------------------------------------------------------
//! \brief Contains the architecture depended device and the access functions to the spi driver.
struct spi {
const void *arch_dep_device; //!< Architecture depended spi device (i.e. stm32f10x_spi_t).
const struct spi_fp *fp; //!< Function pointer for the spi driver access.
};
//-----------------------------------------------------------------------------
//! \brief Open spi device.
//! \param device The spi to open.
int spi_open(const struct spi *device);
//-----------------------------------------------------------------------------
//! \brief Close spi device.
//! \param device The spi to close.
//! \retval -1 in error case.
int spi_close(const struct spi *device);
//-----------------------------------------------------------------------------
//! \brief Assert the spi's chip select.
//! \param device The spi to assert.
//! \retval -1 in error case.
void spi_assert_cs(const struct spi * device);
//-----------------------------------------------------------------------------
//! \brief Deassert the spi'schip select.
//! \param device The spi to deassert.
//! \retval -1 in error case.
void spi_deassert_cs(const struct spi * device);
//-----------------------------------------------------------------------------
//! \brief rx/tx byte over spi.
//! \param device The spi to act on.
//! \param byte The data to transmit.
//! \return The received data
char spi_rxtx_byte(const struct spi * device, char byte);
#endif /* SPI_H_ */