File ns_spi.c
FileList > neuralSPOT > neuralspot > ns-spi > src > ns_spi.c
Go to the source code of this file
Generic SPI driver. More...
#include <string.h>
#include "ns_spi.h"
#include "am_bsp.h"
#include "am_mcu_apollo.h"
#include "am_util.h"
#include "ns_ambiqsuite_harness.h"
Public Attributes
Type | Name |
---|---|
const IRQn_Type | gc_iomIrq = = (IRQn_Type)(1 + IOMSTR0_IRQn) |
ns_spi_config_t | ns_spi_config |
uint32_t | ns_spi_tcb_command_buffer |
Public Functions
Type | Name |
---|---|
uint32_t | ns_spi_interface_init (ns_spi_config_t * cfg, uint32_t speed, am_hal_iom_spi_mode_e mode) Initialize the SPI interface. |
uint32_t | ns_spi_read (ns_spi_config_t * cfg, const void * buf, uint32_t bufLen, uint64_t reg, uint32_t regLen, uint32_t csPin) Read from a SPI device. The SPI device is selected by the csPin parameter. |
uint32_t | ns_spi_read_dma (ns_spi_config_t * cfg, const void * buf, uint32_t bufLen, uint64_t reg, uint32_t regLen, uint32_t csPin) Issure DMA read, the cfg->callback will be called when the transfer is complete. |
uint32_t | ns_spi_transfer (ns_spi_config_t * cfg, const void * txBuf, const void * rxBuf, uint32_t size, uint32_t csPin) Transfer data to/from a SPI device. The SPI device is selected by the csPin parameter. |
uint32_t | ns_spi_write (ns_spi_config_t * cfg, const void * buf, uint32_t bufLen, uint64_t reg, uint32_t regLen, uint32_t csPin) Write to a SPI device. The SPI device is selected by the csPin parameter. |
Public Static Functions
Type | Name |
---|---|
void | ns_spi_dma_read_complete_cb (void * pCallbackCtxt, uint32_t ui32TransactionStatus) |
Macros
Type | Name |
---|---|
define | NS_SPI_DMA_MAX_XFER_SIZE 4095 |
define | am_iom_isr (n) am_iomaster##n##_isr |
define | am_iom_isrx (n) am_iom_isr(n) |
define | iom_isr (void) am_iom_isrx(1) iom isr prototype |
Detailed Description
Author:
Adam Page
Version:
0.1
Date:
2022-08-26
Copyright:
Copyright (c) 2022
Public Attributes Documentation
variable gc_iomIrq
const IRQn_Type gc_iomIrq;
variable ns_spi_config
ns_spi_config_t ns_spi_config;
variable ns_spi_tcb_command_buffer
uint32_t ns_spi_tcb_command_buffer[NS_SPI_DMA_MAX_XFER_SIZE+1];
Public Functions Documentation
function ns_spi_interface_init
Initialize the SPI interface.
uint32_t ns_spi_interface_init (
ns_spi_config_t * cfg,
uint32_t speed,
am_hal_iom_spi_mode_e mode
)
Parameters:
cfg
SPI Configurationspeed
Bus speed in Hzmode
SPI mode (CPOL, CPHA)
Returns:
uint32_t
function ns_spi_read
Read from a SPI device. The SPI device is selected by the csPin parameter.
uint32_t ns_spi_read (
ns_spi_config_t * cfg,
const void * buf,
uint32_t bufLen,
uint64_t reg,
uint32_t regLen,
uint32_t csPin
)
Parameters:
cfg
SPI Configurationbuf
Buffer to read intobufLen
Buffer lengthreg
Register to read fromregLen
Register lengthcsPin
CS pin number
Returns:
uint32_t
function ns_spi_read_dma
Issure DMA read, the cfg->callback will be called when the transfer is complete.
uint32_t ns_spi_read_dma (
ns_spi_config_t * cfg,
const void * buf,
uint32_t bufLen,
uint64_t reg,
uint32_t regLen,
uint32_t csPin
)
Parameters:
cfg
buf
bufLen
reg
regLen
csPin
Returns:
uint32_t
function ns_spi_transfer
Transfer data to/from a SPI device. The SPI device is selected by the csPin parameter.
uint32_t ns_spi_transfer (
ns_spi_config_t * cfg,
const void * txBuf,
const void * rxBuf,
uint32_t size,
uint32_t csPin
)
Parameters:
cfg
SPI ConfigurationtxBuf
Transmit bufferrxBuf
Receive buffersize
Size of the transfercsPin
CS pin number
Returns:
uint32_t
function ns_spi_write
Write to a SPI device. The SPI device is selected by the csPin parameter.
uint32_t ns_spi_write (
ns_spi_config_t * cfg,
const void * buf,
uint32_t bufLen,
uint64_t reg,
uint32_t regLen,
uint32_t csPin
)
Parameters:
cfg
SPI Configurationbuf
Buffer to write frombufLen
Buffer lengthreg
Register to write toregLen
Register lengthcsPin
CS pin number
Returns:
uint32_t
Public Static Functions Documentation
function ns_spi_dma_read_complete_cb
static void ns_spi_dma_read_complete_cb (
void * pCallbackCtxt,
uint32_t ui32TransactionStatus
)
Macro Definition Documentation
define NS_SPI_DMA_MAX_XFER_SIZE
#define NS_SPI_DMA_MAX_XFER_SIZE 4095
define am_iom_isr
#define am_iom_isr (
n
) am_iomaster##n##_isr
define am_iom_isrx
#define am_iom_isrx (
n
) am_iom_isr(n)
define iom_isr
iom isr prototype
#define iom_isr (
void
) am_iom_isrx(1)
Take over the interrupt handler for whichever IOM is used.
IOM ISRs Take over correct IOM ISR.
The documentation for this class was generated from the following file neuralSPOT/neuralspot/ns-spi/src/ns_spi.c