📄 dspi.h
字号:
/*! * \file dspi.h * \brief Driver for the DSPI module * \version $Revision: 1.2 $ * \author Michael Norman */#ifndef _DSPI_H_#define _DSPI_H_#include "queue.h"/*******************************************************************//*! List of the valid chip-selects on this master */extern const uint8 dspi_valid_cs[];/*! Enumeration for SPI Modes */typedef enum spi_mode { SPI_MODE_0, /*!< CPOL = 0; CPHA = 0 */ SPI_MODE_1, /*!< CPOL = 0; CPHA = 1 */ SPI_MODE_2, /*!< CPOL = 1; CPHA = 0 */ SPI_MODE_3, /*!< CPOL = 1; CPHA = 1 */} SPI_MODE;/*! Enumeration for SPI first bit orientation */typedef enum spi_fbit { SPI_FBIT_MSB, SPI_FBIT_LSB,} SPI_FBIT;/*! * \struct spi_device * Structure that contains information about a device on the SPI bus */typedef struct spi_device{ int baud; /*!< Default baud rate */ SPI_MODE mode; /*!< CPOL and CPHA modes */ SPI_FBIT fbit; /*!< First bit orientation, MSB or LSB */ uint8 cs; /*!< Chip-select physically connected to */ uint8 cs_is; /*!< CS inactive state; 1 = high, 0 = low */ uint8 cs_muxed; /*!< Use multiplexed chip-select encoding? */ uint8 frame_size; /*!< Number of bits transferred per frame */ uint8 delay_csclk; /*!< CS assertion to first CLK delay (ns) */ uint8 delay_clkcs; /*!< Last CLK to CS deassertion delay (ns) */ uint8 delay_cscs; /*!< CS to CS inactive time (ns) */} SPI_DEVICE;/*! * \struct spi_msg_link * Structure that contains information about an individual link in a message * chain. A message chain is made up of one or more message links. */typedef struct spi_msg_link{ struct spi_msg_link *next; /*!< Pointer to next link in the chain */ void *tx_buf; /*!< Pointer to receive buffer (or NULL) */ void *rx_buf; /*!< Pointer to receive buffer (or NULL) */ int length; /*!< Length of transfer in bytes */} SPI_MSG_LINK;/*! * \struct spi_msg_chain * Structure that contains all the details about a chain of messages to be sent * across the SPI bus. A message chain is made up of one or more message links. */typedef struct spi_msg_chain{ QNODE node; SPI_DEVICE *device; /*!< SPI device being communicated with */ SPI_MSG_LINK *link; /*!< Pointer to message link */ int baud; /*!< Special baud rate for this message */ void (*callback)(struct spi_msg_chain *msg); /*! Completion callback */ uint8 use_dma; /*!< To use DMA (TRUE) or not (FALSE) */ vuint8 status; /*!< Status of this message */} SPI_MSG_CHAIN;/*! * \struct spi_driver_data * Structure that holds data about the current state of the driver */typedef struct spi_driver_data{ SPI_MSG_CHAIN *chain; /*!< Pointer to message in progress */ QUEUE queue; /*!< Message queue */ void *tx; /*!< Pointer to current tx position */ void *tx_end; /*!< Pointer to end of tx buffer */ void *rx; /*!< Pointer to current rx position */ void *rx_end; /*!< Pointer to end of rx buffer */ void *last; /*!< Pointer to last datum in the chain */ int status; /*!< Driver status */ /* Interrupt event counters */ int event_tc; /*!< Transfer complete */ int event_eoq; /*!< End of queue */ int event_tfu; /*!< Transmit FIFO underflow */ int event_tff; /*!< Transmit FIFO full */ int event_rfo; /*!< Receive FIFO overflow */ int event_rfd; /*!< Receive FIFO drain */} SPI_DRIVER_DATA; /* SPI Message status definitions */#define SPI_MSG_CHAIN_IDLE 0#define SPI_MSG_CHAIN_QUEUED 1#define SPI_MSG_CHAIN_RUNNING 2#define SPI_MSG_CHAIN_DONE 3/* SPI Driver status definitions */#define SPI_DRIVER_IDLE 0#define SPI_DRIVER_RUNNING 1/* Implementation specific define */#define SPI_FIFO_SIZE 16/* * Function prototypes */intspi_master_init(void);intspi_master_device_init (SPI_DEVICE *device);intspi_master_write(SPI_DEVICE *device, uint8 *tx_buf, int length);intspi_master_read(SPI_DEVICE *device, uint8 *rx_buf, int length);intspi_master_write_read(SPI_DEVICE *dev, uint8 *txb, uint8 *rxb, int length);intspi_master_transfer(SPI_MSG_CHAIN *msg, int sync);static intspi_master_enqueue(SPI_MSG_CHAIN *msg);__interrupt__void spi_master_irq_handler (void);static intspi_master_tx (void);static intspi_master_rx (void);/*******************************************************************/#endif /* _DSPI_H_ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -