SDK4.0 This document shows Ameba SDK 4.0 APIs

- Main Page
- Modules
- Data Structures
- Files

Enumerator
SPI_EX
Ameba SDK » HAL

spi extended functions More...

## Ameba Common
enum | { SPI_SCLK_IDLE_LOW =0, SPI_SCLK_IDLE_HIGH =2 }
enum | { SPI_CS_TOGGLE_EVERY_FRAME =0, SPI_CS_TOGGLE_START_STOP =1 }
enum | { SPI_SCLK_TOGGLE_MIDDLE =0, SPI_SCLK_TOGGLE_START =1 }
enum | ChipSelect { CS_0 = 0, CS_1 = 1, CS_2 = 2, CS_3 = 3, CS_4 = 4, CS_5 = 5, CS_6 = 6, CS_7 = 7 }
enum | SpiIrq { SpiRxIrq, SpiTxIrq }
typedef void(* | spi_irq_handler) (uint32_t id, SpiIrq event)
void | spi_irq_hook (spi_t *obj, spi_irq_handler handler, uint32_t id)
| Set SPI interrupt handler if needed. More...
void | spi_bus_tx_done_irq_hook (spi_t *obj, spi_irq_handler handler, uint32_t id)
| Set SPI interrupt bus tx done handler if needed. More...
void | spi_slave_flush_fifo (spi_t *obj)
| Slave device to flush tx fifo. More...
int32_t | spi_slave_read_stream (spi_t *obj, char *rx_buffer, uint32_t length)
| slave recv target length data use interrupt mode. More...
int32_t | spi_slave_write_stream (spi_t *obj, char *tx_buffer, uint32_t length)
| slave send target length data use interrupt mode. More...
int32_t | spi_master_read_stream (spi_t *obj, char *rx_buffer, uint32_t length)
| master recv target length data use interrupt mode. More...
int32_t | spi_master_write_stream (spi_t *obj, char *tx_buffer, uint32_t length)
| master send target length data use interrupt mode. More...
int32_t | spi_master_write_read_stream (spi_t *obj, char *tx_buffer, char *rx_buffer, uint32_t length)
| master send & recv target length data use interrupt mode. More...
int32_t | spi_slave_read_stream_timeout (spi_t *obj, char *rx_buffer, uint32_t length, uint32_t timeout_ms)
| slave recv target length data use interrupt mode and timeout mechanism. More...
int32_t | spi_slave_read_stream_terminate (spi_t *obj, char *rx_buffer, uint32_t length)
| slave recv target length data use interrupt mode and stop if the spi bus is idle. More...
int32_t | spi_slave_read_stream_dma (spi_t *obj, char *rx_buffer, uint32_t length)
| slave recv target length data use DMA mode. More...
int32_t | spi_slave_write_stream_dma (spi_t *obj, char *tx_buffer, uint32_t length)
| slave send target length data use DMA mode. More...
int32_t | spi_master_write_read_stream_dma (spi_t *obj, char *tx_buffer, char *rx_buffer, uint32_t length)
| master send & recv target length data use DMA mode. More...
int32_t | spi_master_read_stream_dma (spi_t *obj, char *rx_buffer, uint32_t length)
| master recv target length data use DMA mode. More...
int32_t | spi_master_write_stream_dma (spi_t *obj, char *tx_buffer, uint32_t length)
| master send target length data use DMA mode. More...
int32_t | spi_slave_read_stream_dma_timeout (spi_t *obj, char *rx_buffer, uint32_t length, uint32_t timeout_ms)
| slave recv target length data use DMA mode and timeout mechanism. More...
int32_t | spi_slave_read_stream_dma_terminate (spi_t *obj, char *rx_buffer, uint32_t length)
| slave recv target length data use DMA mode and stop if the spi bus is idle. More...
#define | SPI_DMA_RX_EN (1<<0)
#define | SPI_DMA_TX_EN (1<<1)
#define | SPI_STATE_READY 0x00
#define | SPI_STATE_RX_BUSY (1<<1)
#define | SPI_STATE_TX_BUSY (1<<2)

## Detailed Description

spi extended functions

## Function Documentation

void spi_bus_tx_done_irq_hook | ( | spi_t * | obj,
|  | spi_irq_handler | handler,
|  | uint32_t | id
| ) |  |

Set SPI interrupt bus tx done handler if needed.

Parameters

  obj | spi object define in application software.
  handler | interrupt bus tx done callback function
  id | interrupt callback parameter

Return values

  none |

void spi_irq_hook | ( | spi_t * | obj,
|  | spi_irq_handler | handler,
|  | uint32_t | id
| ) |  |

Set SPI interrupt handler if needed.

Parameters

  obj | spi object define in application software.
  handler | interrupt callback function
  id | interrupt callback parameter

Return values

  none |

int32_t spi_master_read_stream | ( | spi_t * | obj,
|  | char * | rx_buffer,
|  | uint32_t | length
| ) |  |

master recv target length data use interrupt mode.

Parameters

  obj | spi master object define in application software.
  rx_buffer | buffer to save data read from SPI FIFO.
  length | number of data bytes to be read.

Return values

  | stream init status

int32_t spi_master_read_stream_dma | ( | spi_t * | obj,
|  | char * | rx_buffer,
|  | uint32_t | length
| ) |  |

master recv target length data use DMA mode.

Parameters

  obj | spi master object define in application software.
  rx_buffer | buffer to save data read from SPI FIFO.
  length | number of data bytes to be read.

Return values

  | stream init status

Note
  : DMA or Interrupt mode can be used to TX dummy data

int32_t spi_master_write_read_stream | ( | spi_t * | obj,
|  | char * | tx_buffer,
|  | char * | rx_buffer,
|  | uint32_t | length
| ) |  |

master send & recv target length data use interrupt mode.

Parameters

  obj | spi master object define in application software.
  tx_buffer | buffer to be written to Tx FIFO.
  rx_buffer | buffer to save data read from SPI FIFO.
  length | number of data bytes to be send & recv.

Return values

  | stream init status

int32_t spi_master_write_read_stream_dma | ( | spi_t * | obj,
|  | char * | tx_buffer,
|  | char * | rx_buffer,
|  | uint32_t | length
| ) |  |

master send & recv target length data use DMA mode.

Parameters

  obj | spi master object define in application software.
  tx_buffer | buffer to be written to Tx FIFO.
  rx_buffer | buffer to save data read from SPI FIFO.
  length | number of data bytes to be send & recv.

Return values

  | stream init status

int32_t spi_master_write_stream | ( | spi_t * | obj,
|  | char * | tx_buffer,
|  | uint32_t | length
| ) |  |

master send target length data use interrupt mode.

Parameters

  obj | spi master object define in application software.
  tx_buffer | buffer to be written to Tx FIFO.
  length | number of data bytes to be send.

Return values

  | stream init status

int32_t spi_master_write_stream_dma | ( | spi_t * | obj,
|  | char * | tx_buffer,
|  | uint32_t | length
| ) |  |

master send target length data use DMA mode.

Parameters

  obj | spi master object define in application software.
  tx_buffer | buffer to be written to Tx FIFO.
  length | number of data bytes to be send.

Return values

  | stream init status

void spi_slave_flush_fifo | ( | spi_t * | obj | ) |

Slave device to flush tx fifo.

Parameters

  obj | spi slave object define in application software.

Note
  : It will discard all data in both tx fifo and rx fifo

int32_t spi_slave_read_stream | ( | spi_t * | obj,
|  | char * | rx_buffer,
|  | uint32_t | length
| ) |  |

slave recv target length data use interrupt mode.

Parameters

  obj | spi slave object define in application software.
  rx_buffer | buffer to save data read from SPI FIFO.
  length | number of data bytes to be read.

Return values

  | stream init status

int32_t spi_slave_read_stream_dma | ( | spi_t * | obj,
|  | char * | rx_buffer,
|  | uint32_t | length
| ) |  |

slave recv target length data use DMA mode.

Parameters

  obj | spi slave object define in application software.
  rx_buffer | buffer to save data read from SPI FIFO.
  length | number of data bytes to be read.

Return values

  | stream init status

int32_t spi_slave_read_stream_dma_terminate | ( | spi_t * | obj,
|  | char * | rx_buffer,
|  | uint32_t | length
| ) |  |

slave recv target length data use DMA mode and stop if the spi bus is idle.

Parameters

  obj | spi slave object define in application software.
  rx_buffer | buffer to save data read from SPI FIFO.
  length | number of data bytes to be read.

Return values

  | number of bytes read already

int32_t spi_slave_read_stream_dma_timeout | ( | spi_t * | obj,
|  | char * | rx_buffer,
|  | uint32_t | length,
|  | uint32_t | timeout_ms
| ) |  |

slave recv target length data use DMA mode and timeout mechanism.

Parameters

  obj | spi slave object define in application software.
  rx_buffer | buffer to save data read from SPI FIFO.
  length | number of data bytes to be read.
  timeout_ms | timeout waiting time.

Return values

  | number of bytes read already

int32_t spi_slave_read_stream_terminate | ( | spi_t * | obj,
|  | char * | rx_buffer,
|  | uint32_t | length
| ) |  |

slave recv target length data use interrupt mode and stop if the spi bus is idle.

Parameters

  obj | spi slave object define in application software.
  rx_buffer | buffer to save data read from SPI FIFO.
  length | number of data bytes to be read.

Return values

  | number of bytes read already

int32_t spi_slave_read_stream_timeout | ( | spi_t * | obj,
|  | char * | rx_buffer,
|  | uint32_t | length,
|  | uint32_t | timeout_ms
| ) |  |

slave recv target length data use interrupt mode and timeout mechanism.

Parameters

  obj | spi slave object define in application software.
  rx_buffer | buffer to save data read from SPI FIFO.
  length | number of data bytes to be read.
  timeout_ms | timeout waiting time.

Return values

  | number of bytes read already

int32_t spi_slave_write_stream | ( | spi_t * | obj,
|  | char * | tx_buffer,
|  | uint32_t | length
| ) |  |

slave send target length data use interrupt mode.

Parameters

  obj | spi slave object define in application software.
  tx_buffer | buffer to be written to Tx FIFO.
  length | number of data bytes to be send.

Return values

  | stream init status

int32_t spi_slave_write_stream_dma | ( | spi_t * | obj,
|  | char * | tx_buffer,
|  | uint32_t | length
| ) |  |

slave send target length data use DMA mode.

Parameters

  obj | spi slave object define in application software.
  tx_buffer | buffer to be written to Tx FIFO.
  length | number of data bytes to be send.

Return values

  | stream init status