Kinetis SDK v.1.3 API Reference Manual  Rev. 0
Freescale Semiconductor, Inc.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
fsl_dspi_hal.h File Reference
#include <stdint.h>
#include <stdbool.h>
#include "fsl_device_registers.h"

Data Structures

struct  dspi_data_format_config_t
 DSPI data format settings configuration structure. More...
 
struct  dspi_baud_rate_divisors_t
 DSPI baud rate divisors settings configuration structure. More...
 
struct  dspi_command_config_t
 DSPI command and data configuration structure. More...
 

Enumerations

enum  dspi_status_t {
  kStatus_DSPI_Success = 0,
  kStatus_DSPI_SlaveTxUnderrun,
  kStatus_DSPI_SlaveRxOverrun,
  kStatus_DSPI_Timeout,
  kStatus_DSPI_Busy,
  kStatus_DSPI_NoTransferInProgress,
  kStatus_DSPI_InvalidBitCount,
  kStatus_DSPI_InvalidInstanceNumber,
  kStatus_DSPI_OutOfRange,
  kStatus_DSPI_InvalidParameter,
  kStatus_DSPI_NonInit,
  kStatus_DSPI_Initialized,
  kStatus_DSPI_DMAChannelInvalid,
  kStatus_DSPI_Error,
  kStatus_DSPI_EdmaStcdUnaligned32Error
}
 Error codes for the DSPI driver. More...
 
enum  dspi_master_slave_mode_t {
  kDspiMaster = 1,
  kDspiSlave = 0
}
 DSPI master or slave configuration. More...
 
enum  dspi_clock_polarity_t {
  kDspiClockPolarity_ActiveHigh = 0,
  kDspiClockPolarity_ActiveLow = 1
}
 DSPI clock polarity configuration for a given CTAR. More...
 
enum  dspi_clock_phase_t {
  kDspiClockPhase_FirstEdge = 0,
  kDspiClockPhase_SecondEdge = 1
}
 DSPI clock phase configuration for a given CTAR. More...
 
enum  dspi_shift_direction_t {
  kDspiMsbFirst = 0,
  kDspiLsbFirst = 1
}
 DSPI data shifter direction options for a given CTAR. More...
 
enum  dspi_ctar_selection_t {
  kDspiCtar0 = 0,
  kDspiCtar1 = 1
}
 DSPI Clock and Transfer Attributes Register (CTAR) selection. More...
 
enum  dspi_pcs_polarity_config_t {
  kDspiPcs_ActiveHigh = 0,
  kDspiPcs_ActiveLow = 1
}
 DSPI Peripheral Chip Select (PCS) Polarity configuration. More...
 
enum  dspi_which_pcs_config_t {
  kDspiPcs0 = 1 << 0,
  kDspiPcs1 = 1 << 1,
  kDspiPcs2 = 1 << 2,
  kDspiPcs3 = 1 << 3,
  kDspiPcs4 = 1 << 4,
  kDspiPcs5 = 1 << 5
}
 DSPI Peripheral Chip Select (PCS) configuration (which PCS to configure) More...
 
enum  dspi_master_sample_point_t {
  kDspiSckToSin_0Clock = 0,
  kDspiSckToSin_1Clock = 1,
  kDspiSckToSin_2Clock = 2
}
 DSPI Sample Point: Controls when the DSPI master samples SIN in Modified Transfer Format. More...
 
enum  dspi_dma_or_int_mode_t {
  kDspiGenerateIntReq = 0,
  kDspiGenerateDmaReq = 1
}
 DSPI Tx FIFO Fill and Rx FIFO Drain DMA or Interrupt configuration. More...
 
enum  dspi_status_and_interrupt_request_t {
  kDspiTxComplete = SPI_RSER_TCF_RE_SHIFT,
  kDspiTxAndRxStatus = SPI_SR_TXRXS_SHIFT,
  kDspiEndOfQueue = SPI_RSER_EOQF_RE_SHIFT,
  kDspiTxFifoUnderflow = SPI_RSER_TFUF_RE_SHIFT,
  kDspiTxFifoFillRequest = SPI_RSER_TFFF_RE_SHIFT,
  kDspiRxFifoOverflow = SPI_RSER_RFOF_RE_SHIFT,
  kDspiRxFifoDrainRequest = SPI_RSER_RFDF_RE_SHIFT
}
 DSPI status flags and interrupt request enable. More...
 
enum  dspi_delay_type_t {
  kDspiPcsToSck = 1,
  kDspiLastSckToPcs = 2,
  kDspiAfterTransfer = 3
}
 DSPI delay type selection. More...
 

Functions

Configuration
void DSPI_HAL_Init (SPI_Type *base)
 Restores the DSPI to reset the configuration. More...
 
static void DSPI_HAL_Enable (SPI_Type *base)
 Enables the DSPI peripheral and sets the MCR MDIS to 0. More...
 
static void DSPI_HAL_Disable (SPI_Type *base)
 Disables the DSPI peripheral, sets MCR MDIS to 1. More...
 
uint32_t DSPI_HAL_SetBaudRate (SPI_Type *base, dspi_ctar_selection_t whichCtar, uint32_t bitsPerSec, uint32_t sourceClockInHz)
 Sets the DSPI baud rate in bits per second. More...
 
void DSPI_HAL_SetBaudDivisors (SPI_Type *base, dspi_ctar_selection_t whichCtar, const dspi_baud_rate_divisors_t *divisors)
 Configures the baud rate divisors manually. More...
 
static void DSPI_HAL_SetMasterSlaveMode (SPI_Type *base, dspi_master_slave_mode_t mode)
 Configures the DSPI for master or slave. More...
 
static bool DSPI_HAL_IsMaster (SPI_Type *base)
 Returns whether the DSPI module is in master mode. More...
 
static void DSPI_HAL_SetContinuousSckCmd (SPI_Type *base, bool enable)
 Configures the DSPI for the continuous SCK operation. More...
 
static void DSPI_HAL_SetRxFifoOverwriteCmd (SPI_Type *base, bool enable)
 Configures the DSPI received FIFO overflow overwrite enable. More...
 
void DSPI_HAL_SetPcsPolarityMode (SPI_Type *base, dspi_which_pcs_config_t pcs, dspi_pcs_polarity_config_t activeLowOrHigh)
 Configures the DSPI peripheral chip select polarity. More...
 
void DSPI_HAL_SetFifoCmd (SPI_Type *base, bool enableTxFifo, bool enableRxFifo)
 Enables (or disables) the DSPI FIFOs. More...
 
void DSPI_HAL_SetFlushFifoCmd (SPI_Type *base, bool enableFlushTxFifo, bool enableFlushRxFifo)
 Flushes the DSPI FIFOs. More...
 
static void DSPI_HAL_SetDatainSamplepointMode (SPI_Type *base, dspi_master_sample_point_t samplePnt)
 Configures the time when the DSPI master samples SIN in the Modified Transfer Format. More...
 
static void DSPI_HAL_StartTransfer (SPI_Type *base)
 Starts the DSPI transfers, clears HALT bit in MCR. More...
 
static void DSPI_HAL_StopTransfer (SPI_Type *base)
 Stops (halts) DSPI transfers, sets HALT bit in MCR. More...
 
dspi_status_t DSPI_HAL_SetDataFormat (SPI_Type *base, dspi_ctar_selection_t whichCtar, const dspi_data_format_config_t *config)
 Configures the data format for a particular CTAR. More...
 
void DSPI_HAL_SetDelay (SPI_Type *base, dspi_ctar_selection_t whichCtar, uint32_t prescaler, uint32_t scaler, dspi_delay_type_t whichDelay)
 Manually configures the delay prescaler and scaler for a particular CTAR. More...
 
uint32_t DSPI_HAL_CalculateDelay (SPI_Type *base, dspi_ctar_selection_t whichCtar, dspi_delay_type_t whichDelay, uint32_t sourceClockInHz, uint32_t delayInNanoSec)
 Calculates the delay prescaler and scaler based on the desired delay input in nanoseconds. More...
 
static uint32_t DSPI_HAL_GetMasterPushrRegAddr (SPI_Type *base)
 Gets the DSPI master PUSHR data register address for DMA operation. More...
 
static uint32_t DSPI_HAL_GetSlavePushrRegAddr (SPI_Type *base)
 Gets the DSPI slave PUSHR data register address for DMA operation. More...
 
static uint32_t DSPI_HAL_GetPoprRegAddr (SPI_Type *base)
 Gets the DSPI POPR data register address for DMA operation. More...
 
Interrupts
void DSPI_HAL_SetTxFifoFillDmaIntMode (SPI_Type *base, dspi_dma_or_int_mode_t mode, bool enable)
 Configures the DSPI Tx FIFO fill request to generate DMA or interrupt requests. More...
 
void DSPI_HAL_SetRxFifoDrainDmaIntMode (SPI_Type *base, dspi_dma_or_int_mode_t mode, bool enable)
 Configures the DSPI Rx FIFO Drain request to generate DMA or interrupt requests. More...
 
void DSPI_HAL_SetIntMode (SPI_Type *base, dspi_status_and_interrupt_request_t interruptSrc, bool enable)
 Configures the DSPI interrupts. More...
 
static bool DSPI_HAL_GetIntMode (SPI_Type *base, dspi_status_and_interrupt_request_t interruptSrc)
 Gets DSPI interrupt configuration, returns if interrupt request is enabled or disabled. More...
 
Status
static bool DSPI_HAL_GetStatusFlag (SPI_Type *base, dspi_status_and_interrupt_request_t statusFlag)
 Gets the DSPI status flag state. More...
 
static void DSPI_HAL_ClearStatusFlag (SPI_Type *base, dspi_status_and_interrupt_request_t statusFlag)
 Clears the DSPI status flag. More...
 
Data transfer
static uint32_t DSPI_HAL_ReadData (SPI_Type *base)
 Reads data from the data buffer. More...
 
static void DSPI_HAL_WriteDataSlavemode (SPI_Type *base, uint32_t data)
 Writes data into the data buffer, slave mode. More...
 
void DSPI_HAL_WriteDataSlavemodeBlocking (SPI_Type *base, uint32_t data)
 Writes data into the data buffer, slave mode and waits till data was transmitted and return. More...
 
void DSPI_HAL_WriteDataMastermode (SPI_Type *base, dspi_command_config_t *command, uint16_t data)
 Writes data into the data buffer, master mode. More...
 
void DSPI_HAL_WriteDataMastermodeBlocking (SPI_Type *base, dspi_command_config_t *command, uint16_t data)
 Writes data into the data buffer, master mode and waits till complete to return. More...
 
static void DSPI_HAL_WriteCmdDataMastermode (SPI_Type *base, uint32_t data)
 Writes a 32-bit data word (16-bit command appended with 16-bit data) into the data buffer, master mode. More...
 
void DSPI_HAL_WriteCmdDataMastermodeBlocking (SPI_Type *base, uint32_t data)
 Writes a 32-bit data word (16-bit command appended with 16-bit data) into the data buffer, master mode and waits till complete to return. More...
 
static uint32_t DSPI_HAL_GetTransferCount (SPI_Type *base)
 Gets the transfer count. More...
 
static void DSPI_HAL_PresetTransferCount (SPI_Type *base, uint16_t presetValue)
 Pre-sets the transfer count. More...
 
uint32_t DSPI_HAL_GetFormattedCommand (SPI_Type *base, dspi_command_config_t *command)
 Returns the DSPI command word formatted to the PUSHR data register bit field. More...
 

Variables

static const uint32_t s_baudratePrescaler [] = { 2, 3, 5, 7 }
 
static const uint32_t s_baudrateScaler []
 
static const uint32_t s_delayPrescaler [] = { 1, 3, 5, 7 }
 
static const uint32_t s_delayScaler []