PDK API Guide for J721E
SPI Driver MCSPI API

Introduction

Multi-Channel SPI driver interface

Files

file  MCSPI.h
 Multi-Channel SPI driver interface.
 

Data Structures

struct  MCSPI_Params
 MCSPI Parameters. More...
 
struct  MCSPI_FxnTable
 The definition of a MCSPI function table that contains the required set of functions to control a specific MCSPI driver implementation. More...
 
struct  MCSPI_Config
 MCSPI Global configuration. More...
 

Functions

void MCSPI_close (MCSPI_Handle handle)
 Function to close a channel of a SPI peripheral specified by the MCSPI handle. More...
 
int32_t MCSPI_control (MCSPI_Handle handle, uint32_t cmd, void *arg)
 Function performs implementation specific features on a channel of a SPI peripheral specified by the MCSPI handle. More...
 
void MCSPI_init (void)
 This function initializes the MCSPI module. More...
 
MCSPI_Handle MCSPI_open (uint32_t idx, uint32_t channel, MCSPI_Params *params)
 This function opens a given channel of a given MCSPI peripheral. More...
 
void MCSPI_Params_init (MCSPI_Params *params)
 Function to initialize the MCSPI_Params struct to its defaults. More...
 
bool MCSPI_transfer (MCSPI_Handle handle, SPI_Transaction *spiTrans)
 Function to perform SPI transactions on a channel of a SPI peripheral specified by the MCSPI handle. More...
 
void MCSPI_transferCancel (MCSPI_Handle handle)
 Function to cancel SPI transactions on channel of a SPI peripheral specified by the MCSPI handle. More...
 

Typedefs

typedef struct MCSPI_Config_s * MCSPI_Handle
 A handle that is returned from a MCSPI_open() call. More...
 
typedef void(* MCSPI_CallbackFxn) (MCSPI_Handle handle, SPI_Transaction *transaction)
 The definition of a callback function used by the MCSPI driver when used in SPI_MODE_CALLBACK. More...
 
typedef void(* MCSPI_CloseFxn) (MCSPI_Handle handle)
 A function pointer to a driver specific implementation of MCSPI_close(). More...
 
typedef int32_t(* MCSPI_ControlFxn) (MCSPI_Handle handle, uint32_t cmd, const void *arg)
 A function pointer to a driver specific implementation of MCSPI_control(). More...
 
typedef void(* MCSPI_InitFxn) (MCSPI_Handle handle)
 A function pointer to a driver specific implementation of MCSPI_init(). More...
 
typedef MCSPI_Handle(* MCSPI_OpenFxn) (MCSPI_Handle handle, const MCSPI_Params *params)
 A function pointer to a driver specific implementation of MCSPI_open(). More...
 
typedef bool(* MCSPI_TransferFxn) (MCSPI_Handle handle, SPI_Transaction *transaction)
 A function pointer to a driver specific implementation of MCSPI_transfer(). More...
 
typedef void(* MCSPI_TransferCancelFxn) (MCSPI_Handle handle)
 A function pointer to a driver specific implementation of MCSPI_transferCancel(). More...
 
typedef MCSPI_Config MCSPI_config_list[MCSPI_MAX_NUM_INSTANCES][MCSPI_MAX_NUM_CHANNELS]
 

Macros

#define MCSPI_MAX_NUM_INSTANCES   (SPI_MAX_CONFIG_CNT)
 Max number of MCSPI peripheral instances. More...
 
#define MCSPI_MAX_NUM_CHANNELS   (4U)
 Max number of channels of a MCSPI peripheral instance. More...
 

Macro Definition Documentation

◆ MCSPI_MAX_NUM_INSTANCES

#define MCSPI_MAX_NUM_INSTANCES   (SPI_MAX_CONFIG_CNT)

Max number of MCSPI peripheral instances.

◆ MCSPI_MAX_NUM_CHANNELS

#define MCSPI_MAX_NUM_CHANNELS   (4U)

Max number of channels of a MCSPI peripheral instance.

Typedef Documentation

◆ MCSPI_Handle

typedef struct MCSPI_Config_s* MCSPI_Handle

A handle that is returned from a MCSPI_open() call.

◆ MCSPI_CallbackFxn

typedef void(* MCSPI_CallbackFxn) (MCSPI_Handle handle, SPI_Transaction *transaction)

The definition of a callback function used by the MCSPI driver when used in SPI_MODE_CALLBACK.

◆ MCSPI_CloseFxn

typedef void(* MCSPI_CloseFxn) (MCSPI_Handle handle)

A function pointer to a driver specific implementation of MCSPI_close().

◆ MCSPI_ControlFxn

typedef int32_t(* MCSPI_ControlFxn) (MCSPI_Handle handle, uint32_t cmd, const void *arg)

A function pointer to a driver specific implementation of MCSPI_control().

◆ MCSPI_InitFxn

typedef void(* MCSPI_InitFxn) (MCSPI_Handle handle)

A function pointer to a driver specific implementation of MCSPI_init().

◆ MCSPI_OpenFxn

typedef MCSPI_Handle(* MCSPI_OpenFxn) (MCSPI_Handle handle, const MCSPI_Params *params)

A function pointer to a driver specific implementation of MCSPI_open().

◆ MCSPI_TransferFxn

typedef bool(* MCSPI_TransferFxn) (MCSPI_Handle handle, SPI_Transaction *transaction)

A function pointer to a driver specific implementation of MCSPI_transfer().

◆ MCSPI_TransferCancelFxn

typedef void(* MCSPI_TransferCancelFxn) (MCSPI_Handle handle)

A function pointer to a driver specific implementation of MCSPI_transferCancel().

◆ MCSPI_config_list

Function Documentation

◆ MCSPI_close()

void MCSPI_close ( MCSPI_Handle  handle)

Function to close a channel of a SPI peripheral specified by the MCSPI handle.

Precondition
MCSPI_open() has to be called first.
Parameters
handleA MCSPI handle returned from MCSPI_open()
See also
MCSPI_open()

◆ MCSPI_control()

int32_t MCSPI_control ( MCSPI_Handle  handle,
uint32_t  cmd,
void *  arg 
)

Function performs implementation specific features on a channel of a SPI peripheral specified by the MCSPI handle.

Precondition
MCSPI_open() has to be called first.
Parameters
handleA MCSPI handle returned from MCSPI_open()
cmdA command value defined by the driver specific implementation
argAn optional R/W (read/write) argument that is accompanied with cmd
Returns
Implementation specific return codes. Negative values indicate unsuccessful operations.
See also
MCSPI_open()

◆ MCSPI_init()

void MCSPI_init ( void  )

This function initializes the MCSPI module.

Precondition
The MCSPI_config structure must exist and be persistent before this function can be called. This function must also be called before any other MCSPI driver APIs. This function call does not modify any peripheral registers.

◆ MCSPI_open()

MCSPI_Handle MCSPI_open ( uint32_t  idx,
uint32_t  channel,
MCSPI_Params params 
)

This function opens a given channel of a given MCSPI peripheral.

Precondition
MCSPI controller has been initialized using MCSPI_init()
Parameters
idxLogical peripheral number for the MCSPI indexed into the MCSPI_config table
channelChannel number of the SPI peripheral
paramsPointer to an parameter block, if NULL it will use default values. All the fields in this structure are RO (read-only).
Returns
A MCSPI_Handle on success or a NULL on an error or if it has been opened already.
See also
MCSPI_init()
MCSPI_close()

◆ MCSPI_Params_init()

void MCSPI_Params_init ( MCSPI_Params params)

Function to initialize the MCSPI_Params struct to its defaults.

Parameters
paramsAn pointer to MCSPI_Params structure for initialization

Defaults values are: transferMode = SPI_MODE_BLOCKING transferTimeout = SPI_WAIT_FOREVER transferCallbackFxn = NULL mode = SPI_MASTER bitRate = 1000000 (Hz) dataSize = 8 (bits) frameFormat = SPI_POL0_PHA0

◆ MCSPI_transfer()

bool MCSPI_transfer ( MCSPI_Handle  handle,
SPI_Transaction spiTrans 
)

Function to perform SPI transactions on a channel of a SPI peripheral specified by the MCSPI handle.

If the MCSPI is in SPI_MASTER mode, it will immediately start the transaction. If the MCSPI is in SPI_SLAVE mode, it prepares itself for a transaction with a SPI master.

In SPI_MODE_BLOCKING, MCSPI_transfer will block task execution until the transaction has completed.

In SPI_MODE_CALLBACK, MCSPI_transfer() does not block task execution and calls a MCSPI_CallbackFxn. This makes the MCSPI_tranfer() safe to be used within a Task, Swi, or Hwi context. The SPI_Transaction structure must stay persistent until the MCSPI_transfer function has completed!

Parameters
handleA MCSPI_Handle
spiTransA pointer to a SPI_Transaction. All of the fields within transaction except SPI_Transaction.count and SPI_Transaction.status are WO (write-only) unless otherwise noted in the driver implementations. If a transaction timeout has occured, SPI_Transaction.count will contain the number of frames that were transferred.
Returns
true if started successfully; else false
See also
MCSPI_open
MCSPI_transferCancel

◆ MCSPI_transferCancel()

void MCSPI_transferCancel ( MCSPI_Handle  handle)

Function to cancel SPI transactions on channel of a SPI peripheral specified by the MCSPI handle.

In SPI_MODE_BLOCKING, MCSPI_transferCancel has no effect.

In SPI_MODE_CALLBACK, MCSPI_transferCancel() will stop an MCSPI transfer if if one is in progress. If a transaction was in progress, its callback function will be called in context from which this API is called from. The MCSPI_CallbackFxn function can determine if the transaction was successful or not by reading the SPI_Status status value in the SPI_Transaction structure.

Parameters
handleA MCSPI_Handle
See also
MCSPI_open
MCSPI_transfer