5.8. SPI

5.8.1. Types

Base type

Type Name

Brief

enum

Spi_HwInstance

This type defines Channel Select Interface with in SPI(SPI instance)

enum

Spi_StatusType

This type defines a range of specific Driver status for SPI Handler/Driver.

enum

Spi_JobResultType

This type defines a range of specific Jobs status for SPI Handler/Driver.

enum

Spi_SeqResultType

This type defines a range of specific Sequences status for SPI Handler/Driver.

enum

Spi_HwUnitResultType

This type defines a range of specific HW unit status for SPI Handler/Driver.

enum

Spi_AsyncModeType

Specifies the asynchronous mechanism mode for SPI busses handled asynchronously in LEVEL 2.

enum

Spi_TransferType

Word transfer order - MSB first or LSB first.

enum

Spi_CsSelection

Spi Cs Selection - Chip select handling.

enum

Spi_ClkMode

SPI Clock Mode - sets the clock polarity and phase. Note: These values are a direct register mapping. So don’t change value.

enum

Spi_JobPriorityType

SPI Job Priority.

typedef uint8

Spi_DataBufferType

Type of application data buffer elements.

typedef uint32

Spi_CsGpioType

GPIO ID type.

typedef uint32

Spi_RegisterPtrType

type for the register pointer

typedef uint16

Spi_NumberOfDataType

Type for defining the number of data elements of the type Spi_DataBufferType to send and / or receive by Channel.

typedef uint8

Spi_ChannelType

Specifies the identification (ID) for a Channel.

typedef uint16

Spi_JobType

Specifies the identification (ID) for a Job.

typedef void(*)(void)

Spi_JobEndNotifyType

Typedef for job end notification function pointer.

typedef void(*)(void)

Spi_SeqEndNotifyType

Typedef for sequence end notification function pointer.

typedef uint8

Spi_SequenceType

Specifies the identification (ID) for a sequence of jobs.

typedef uint8

Spi_HWUnitType

Specifies the identification (ID) for a SPI Hardware micro controller peripheral (unit)

typedef uint8

Spi_DataDelayType

Spi_DataDelayType defines the number of SPI serial clock cycles delay between each word in FIFO mode.

5.8.1.1. enum Spi_HwInstance

Enumerator

Value

Description

SPI_UNIT_SPIA

SPIA instance.

SPI_UNIT_SPIB

SPIB instance.

SPI_UNIT_SPIC

SPIC instance.

SPI_UNIT_SPID

SPID instance.

SPI_UNIT_SPIE

SPIE instance.

Brief: This type defines Channel Select Interface with in SPI(SPI instance)

5.8.1.2. enum Spi_StatusType

Enumerator

Value

Description

SPI_UNINIT

0U

The SPI Handler/Driver is not initialized or not usable.

SPI_IDLE

1U

The SPI Handler/Driver is not currently transmitting any Job.

SPI_BUSY

2U

The SPI Handler/Driver is performing a SPI Job (transmit)

Brief: This type defines a range of specific Driver status for SPI Handler/Driver.

5.8.1.3. enum Spi_JobResultType

Enumerator

Value

Description

SPI_JOB_OK

0U

The last transmission of the Job has been finished successfully.

SPI_JOB_PENDING

1U

The SPI Handler/Driver is performing a SPI Job. The meaning of this status is equal to SPI_BUSY.

SPI_JOB_FAILED

2U

The last transmission of the Job has failed.

SPI_JOB_QUEUED

3U

An asynchronous transmit Job has been accepted, while actual transmission for this Job has not started yet.

Brief: This type defines a range of specific Jobs status for SPI Handler/Driver.

5.8.1.4. enum Spi_SeqResultType

Enumerator

Value

Description

SPI_SEQ_OK

0U

The last transmission of the Sequence has been finished successfully.

SPI_SEQ_PENDING

1U

The SPI Handler/Driver is performing a SPI Sequence. The meaning of this status is equal to SPI_BUSY.

SPI_SEQ_FAILED

2U

The last transmission of the Sequence has failed.

SPI_SEQ_CANCELLED

3U

The last transmission of the Sequence has been canceled by user.

Brief: This type defines a range of specific Sequences status for SPI Handler/Driver.

5.8.1.5. enum Spi_HwUnitResultType

Enumerator

Value

Description

SPI_HW_UNIT_OK

0U

HW unit result is ok.

SPI_HW_UNIT_PENDING

1U

HW unit result is pending.

SPI_HW_UNIT_FAILED

2U

HW unit result is failed.

Brief: This type defines a range of specific HW unit status for SPI Handler/Driver.

5.8.1.6. enum Spi_AsyncModeType

Enumerator

Value

Description

SPI_POLLING_MODE

0U

The asynchronous mechanism is ensured by polling, so interrupts related to SPI busses handled asynchronously are disabled.

SPI_INTERRUPT_MODE

1U

The asynchronous mechanism is ensured by interrupt, so interrupts related to SPI busses handled asynchronously are enabled.

Brief: Specifies the asynchronous mechanism mode for SPI busses handled asynchronously in LEVEL 2.

5.8.1.7. enum Spi_TransferType

Enumerator

Value

Description

SPI_MSB

0U

MSB is transferred first. Only this is supported.

SPI_LSB

1U

LSB is transferred first. This is not supported.

Brief: Word transfer order - MSB first or LSB first.

5.8.1.8. enum Spi_CsSelection

Enumerator

Value

Description

CS_VIA_GPIO

chip select is handled via general purpose IO by Spi driver

CS_VIA_PERIPHERAL_ENGINE

chip select is handled automatically by Peripheral HW engine

Brief: Spi Cs Selection - Chip select handling.

5.8.1.9. enum Spi_ClkMode

Enumerator

Value

Description

SPI_CLK_MODE_0

0x00U

SPI Clock Phase = 0 Polarity = 0.

SPI_CLK_MODE_1

0x01U

SPI Clock Phase = 1 Polarity = 0

SPI_CLK_MODE_2

0x02U

SPI Clock Phase = 0 Polarity = 1

SPI_CLK_MODE_3

0x03U

SPI Clock Phase = 1 Polarity = 1

Brief: SPI Clock Mode - sets the clock polarity and phase. Note: These values are a direct register mapping. So don’t change value.

5.8.1.10. enum Spi_JobPriorityType

Enumerator

Value

Description

SPI_JOB_PRIORITY_0

Job priority 0 - low.

SPI_JOB_PRIORITY_1

Job priority 1.

SPI_JOB_PRIORITY_2

Job priority 2.

SPI_JOB_PRIORITY_3

Job priority 3 - High.

Brief: SPI Job Priority.

5.8.1.11. typedef Spi_DataBufferType

typedef uint8 Spi_DataBufferType;

Brief: Type of application data buffer elements.

5.8.1.12. typedef Spi_CsGpioType

typedef uint32 Spi_CsGpioType;

Brief: GPIO ID type.

5.8.1.13. typedef Spi_RegisterPtrType

typedef uint32 Spi_RegisterPtrType;

Brief: type for the register pointer

5.8.1.14. typedef Spi_NumberOfDataType

typedef uint16 Spi_NumberOfDataType;

Brief: Type for defining the number of data elements of the type Spi_DataBufferType to send and / or receive by Channel.

5.8.1.15. typedef Spi_ChannelType

typedef uint8 Spi_ChannelType;

Brief: Specifies the identification (ID) for a Channel.

5.8.1.16. typedef Spi_JobType

typedef uint16 Spi_JobType;

Brief: Specifies the identification (ID) for a Job.

5.8.1.17. typedef Spi_JobEndNotifyType

typedef void(* Spi_JobEndNotifyType) (void);

Brief: Typedef for job end notification function pointer.

5.8.1.18. typedef Spi_SeqEndNotifyType

typedef void(* Spi_SeqEndNotifyType) (void);

Brief: Typedef for sequence end notification function pointer.

5.8.1.19. typedef Spi_SequenceType

typedef uint8 Spi_SequenceType;

Brief: Specifies the identification (ID) for a sequence of jobs.

5.8.1.20. typedef Spi_HWUnitType

typedef uint8 Spi_HWUnitType;

Brief: Specifies the identification (ID) for a SPI Hardware micro controller peripheral (unit)

5.8.1.21. typedef Spi_DataDelayType

typedef uint8 Spi_DataDelayType;

Brief: Spi_DataDelayType defines the number of SPI serial clock cycles delay between each word in FIFO mode.

5.8.2. Structures

Name

Brief

Spi_ChannelConfigType

SPI Channel configuration structure.

Spi_ExternalDeviceConfigType

SPI external device specific configuration structure .

Spi_JobConfigType

SPI Job configuration structure.

Spi_SeqConfigType

SPI Sequence configuration structure.

Spi_HwUnitConfigType

SPI Hardware unit configuration structure.

Spi_ConfigType

SPI config structure.

5.8.3. Defines

Name

Brief

SPI_SW_MAJOR_VERSION

Driver Implementation Major Version.

SPI_SW_MINOR_VERSION

Driver Implementation Minor Version.

SPI_SW_PATCH_VERSION

Driver Implementation Patch Version.

SPI_AR_RELEASE_MAJOR_VERSION

AUTOSAR major version specification implemented by SPI Driver.

SPI_AR_RELEASE_MINOR_VERSION

AUTOSAR minor version specification implemented by SPI Driver.

SPI_AR_RELEASE_REVISION_VERSION

AUTOSAR patch version specification implemented by SPI Driver.

SPI_VENDOR_ID

Texas Instruments Vendor ID.

SPI_MODULE_ID

SPI Driver Module ID.

SPI_INSTANCE_ID

SPI Driver Instance ID.

SPI_IB

Buffer definitions IB - internal buffers.

SPI_EB

Buffer definitions EB - external buffers. Only this is supported.

SPI_IB_EB

Buffer definitions IB/EB - internal/external buffers.

SPI_E_PARAM_CHANNEL

SPI Error Codes. Error codes returned by SPI functions.

SPI_E_PARAM_JOB

API service called with wrong parameter.

SPI_E_PARAM_SEQ

API service called with wrong parameter.

SPI_E_PARAM_LENGTH

API service called with wrong parameter.

SPI_E_PARAM_UNIT

API service called with wrong parameter.

SPI_E_PARAM_POINTER

APIs called with a Null Pointer.

SPI_E_UNINIT

API service used without module initialization.

SPI_E_SEQ_PENDING

Services called in a wrong sequence.

SPI_E_SEQ_IN_PROCESS

Synchronous transmission service called at wrong time.

SPI_E_ALREADY_INITIALIZED

API Spi_Init service called while the SPI driver has already been initialized.

SPI_E_SEQ_TIMEOUT

sequence transmission failed with a timeout

SPI_SID_INIT

Spi_Init() API Service ID.

SPI_SID_DEINIT

Spi_DeInit() API Service ID.

SPI_SID_WRITE_IB

Spi_WriteIB() API Service ID.

SPI_SID_ASYNC_TRANSMIT

Spi_AsyncTransmit() API Service ID.

SPI_SID_READ_IB

Spi_ReadIB() API Service ID.

SPI_SID_SETUP_EB

Spi_SetupEB() API Service ID.

SPI_SID_GET_STATUS

Spi_GetStatus() API Service ID.

SPI_SID_GET_JOB_RESULT

Spi_GetJobResult() API Service ID.

SPI_SID_GET_SEQ_RESULT

Spi_GetSequenceResult() API Service ID.

SPI_SID_GET_VERSION_INFO

Spi_GetVersionInfo() API Service ID.

SPI_SID_SYNC_TRANSMIT

Spi_SyncTransmit() API Service ID.

SPI_SID_GET_HW_UNIT_STATUS

Spi_GetHWUnitStatus() API Service ID.

SPI_SID_CANCEL

Spi_Cancel() API Service ID.

SPI_SID_SET_ASYNC_MODE

Spi_SetAsyncMode() API Service ID.

SPI_SID_MAINFUNCTION_HANDLING

Spi_MainFunction_Handling() API Service ID.

5.8.4. Functions

Return type

Function Name

Brief

void

Spi_Init(const Spi_ConfigType * CfgPtr)

Service for SPI initialization.

Std_ReturnType

Spi_DeInit(void )

Service for SPI de-initialization.

Spi_StatusType

Spi_GetStatus(void )

Service returns the SPI Handler/Driver software module status.

Spi_JobResultType

Spi_GetJobResult(Spi_JobType Job)

Service returns the last transmission result of the specified Job.

Spi_SeqResultType

Spi_GetSequenceResult(Spi_SequenceType Sequence)

Service returns the last transmission result of the specified Sequence.

void

Spi_GetVersionInfo(Std_VersionInfoType * versioninfo)

Service to get the version information of the module.

Spi_StatusType

Spi_GetHWUnitStatus(Spi_HWUnitType HWUnit)

Service to get the status of the SPI hardware unit.

Std_ReturnType

Spi_WriteIB(Spi_ChannelType Channel, const Spi_DataBufferType * DataBufferPtr)

Service for writing one or more data to an IB SPI Handler/Driver Channel specified by parameter.

Std_ReturnType

Spi_ReadIB(Spi_ChannelType Channel, Spi_DataBufferType * DataBufferPointer)

Service for reading data from internal buffers.

Std_ReturnType

Spi_SetupEB(Spi_ChannelType Channel, const Spi_DataBufferType * SrcDataBufferPtr, Spi_DataBufferType * DesDataBufferPtr, Spi_NumberOfDataType Length)

Service to setup external buffer channels.

Std_ReturnType

Spi_AsyncTransmit(Spi_SequenceType Sequence)

Service to transmit data on the SPI bus.

void

Spi_Cancel(Spi_SequenceType Sequence)

Service to cancel on going sequence.

Std_ReturnType

Spi_SyncTransmit(Spi_SequenceType Sequence)

Service to transmit data on the SPI bus.

Std_ReturnType

Spi_SetAsyncMode(Spi_AsyncModeType Mode)

Service to set the asynchronous mechanism mode for SPI busses handled asynchronously.

void

Spi_MainFunction_Handling(void )

Spi_MainFunction_Handling: This function shall polls the SPI interrupts linked to HW Units.

5.8.4.1. function Spi_Init

void Spi_Init(
    const Spi_ConfigType * CfgPtr
)

Brief: Service for SPI initialization.

This service initializes all the configured Spi channels, jobs, sequences and SPI instances This will set the state of SPI driver to Initialized.

Parameters:

  • CfgPtr - Pointer to configuration set

Returns:

  • None

Return: None

Precondition: CfgPtr shall be null in Pre-Compile variant, Link-Time variant and shall not be NULL in Post-Build variant

Postcondition: None

5.8.4.2. function Spi_DeInit

Std_ReturnType Spi_DeInit(
    void 
)

Brief: Service for SPI de-initialization.

This service de-initializes all the configured Spi channels, jobs, sequences and SPI instances This will set the state of SPI driver to Un-Initialized.

Returns:

  • E_OK de-initialisation command has been accepted

  • E_NOT_OK de-initialisation command has not been accepted

Return: returns whether the de-init command is accepted or not.

Precondition: None

Postcondition: None

5.8.4.3. function Spi_GetStatus

Spi_StatusType Spi_GetStatus(
    void 
)

Brief: Service returns the SPI Handler/Driver software module status.

Service returns the SPI Handler/Driver software module status.

Returns:

  • SPI_UNINIT The SPI Handler/Driver is not initialized or not usable

  • SPI_IDLE : The SPI Handler/Driver is not currently transmitting any Job

  • SPI_BUSY : The SPI Handler/Driver is performing a SPI Job (transmit)

Return: returns SPI driver status

Precondition: None

Postcondition: None

5.8.4.4. function Spi_GetJobResult

Spi_JobResultType Spi_GetJobResult(
    Spi_JobType Job
)

Brief: Service returns the last transmission result of the specified Job.

Service is to get the result of a specified job(queued, pending, failed, success)

Parameters:

  • Job job Id

Returns:

  • SPI_JOB_OK The last transmission of the Job has been finished successfully

  • SPI_JOB_PENDING The SPI Handler/Driver is performing a SPI Job.

  • SPI_JOB_FAILED The last transmission of the Job has failed

  • SPI_JOB_QUEUED An asynchronous transmit Job has been accepted, while actual transmission for this Job has not started yet

Return: returns the status of a job

Precondition: None

Postcondition: None

5.8.4.5. function Spi_GetSequenceResult

Spi_SeqResultType Spi_GetSequenceResult(
    Spi_SequenceType Sequence
)

Brief: Service returns the last transmission result of the specified Sequence.

Service is to return the status of a specified sequence(cancelled, pending, failed, success).

Parameters:

  • Sequence sequence ID

Returns:

  • SPI_SEQ_OK The last transmission of the Sequence has been finished successfully

  • SPI_SEQ_PENDING The SPI Handler/Driver is performing a SPI Sequence. The meaning of this status is equal to SPI_BUSY

  • SPI_SEQ_FAILED The last transmission of the Sequence has failed

  • SPI_SEQ_CANCELLED The last transmission of the Sequence has been canceled by user

Return: returns the status of a sequence

Precondition: None

Postcondition: None

5.8.4.6. function Spi_GetVersionInfo

void Spi_GetVersionInfo(
    Std_VersionInfoType * versioninfo
)

Brief: Service to get the version information of the module.

This service writes the version information of this module into the data structure referenced by the parameter. If this parameter references NULL_PTR, a development error is reported to Det. This service is only available if the pre-compile configuration parameter SPI_VERSION_INFO_API is enabled.

Parameters:

  • versioninfo structure that contains the version information parameters.

Returns:

  • None

Return: None

Precondition: None

Postcondition: None

5.8.4.7. function Spi_GetHWUnitStatus

Spi_StatusType Spi_GetHWUnitStatus(
    Spi_HWUnitType HWUnit
)

Brief: Service to get the status of the SPI hardware unit.

This service returns the status of the specified SPI Hardware micro-controller peripheral.

Parameters:

  • HWUnit SPI Hardware micro-controller peripheral (unit) ID.

Returns:

  • SPI_UNINIT The SPI HW unit is not initialized or not usable

  • SPI_IDLE : The SPI HW unit is not currently transmitting any Job

  • SPI_BUSY : The SPI HW unit is performing a SPI Job (transmit)

Return: returns the status of the specified SPI HW unit

Precondition: None

Postcondition: None

5.8.4.8. function Spi_WriteIB

Std_ReturnType Spi_WriteIB(
    Spi_ChannelType Channel,
    const Spi_DataBufferType * DataBufferPtr
)

Brief: Service for writing one or more data to an IB SPI Handler/Driver Channel specified by parameter.

Service for writing one or more data to an IB SPI Handler/Driver Channel specified by parameter.

Parameters:

  • Channel Channel ID.

  • DataBufferPtr Pointer to source data buffer. If this pointer is null, it is assumed that the data to be transmitted is not relevant and the default transmit value of this channel will be used instead

Returns:

  • E_OK write command has been accepted

  • E_NOT_OK write command has not been accepted

Return: returns whether command has been accepted or rejected

Precondition: None

Postcondition: None

5.8.4.9. function Spi_ReadIB

Std_ReturnType Spi_ReadIB(
    Spi_ChannelType Channel,
    Spi_DataBufferType * DataBufferPointer
)

Brief: Service for reading data from internal buffers.

Service for reading synchronously one or more data from an IB SPI Handler/Driver Channel specified by parameter.

Parameters:

  • Channel Channel ID

  • DataBufferPointer Pointer to destination data buffer in RAM

Returns:

  • E_OK read command has been accepted

  • E_NOT_OK read command has not been accepted

Return: returns whether command has been accepted or rejected

Precondition: None

Postcondition: None

5.8.4.10. function Spi_SetupEB

Std_ReturnType Spi_SetupEB(
    Spi_ChannelType Channel,
    const Spi_DataBufferType * SrcDataBufferPtr,
    Spi_DataBufferType * DesDataBufferPtr,
    Spi_NumberOfDataType Length
)

Brief: Service to setup external buffer channels.

Service to setup the buffers and the length of data for the EB SPI Handler/Driver Channel specified.

Parameters:

  • Channel Channel Id

  • SrcDataBufferPtr Pointer to source data buffer

  • Length Length (number of data elements) of the data to be transmitted from SrcDataBufferPtr and/or received from DesDataBufferPtr Min.: 1 Max.: Max of data specified at configuration for this channel

  • DesDataBufferPtr Pointer to destination data buffer in RAM.

Returns:

  • E_OK read command has been accepted

  • E_NOT_OK read command has not been accepted

Return: returns whether command has been accepted or rejected

Precondition: None

Postcondition: None

5.8.4.11. function Spi_AsyncTransmit

Std_ReturnType Spi_AsyncTransmit(
    Spi_SequenceType Sequence
)

Brief: Service to transmit data on the SPI bus.

Service is to transmit data on SPI bus if the sequence is valid and not pending

Parameters:

  • Sequence Sequence ID

Returns:

  • E_OK read command has been accepted

  • E_NOT_OK read command has not been accepted

Return: returns whether command has been accepted or rejected

Precondition: None

Postcondition: None

5.8.4.12. function Spi_Cancel

void Spi_Cancel(
    Spi_SequenceType Sequence
)

Brief: Service to cancel on going sequence.

Service cancels the specified on-going sequence transmission.

Parameters:

  • Sequence Sequence ID

Returns:

  • None

Return: None

Precondition: None

Postcondition: None

5.8.4.13. function Spi_SyncTransmit

Std_ReturnType Spi_SyncTransmit(
    Spi_SequenceType Sequence
)

Brief: Service to transmit data on the SPI bus.

Service is to transmit data on SPI bus synchronously

Parameters:

  • Sequence Sequence ID

Returns:

  • E_OK read command has been accepted

  • E_NOT_OK read command has not been accepted

Return: returns whether command has been accepted or rejected

Precondition: None

Postcondition: None

5.8.4.14. function Spi_SetAsyncMode

Std_ReturnType Spi_SetAsyncMode(
    Spi_AsyncModeType Mode
)

Brief: Service to set the asynchronous mechanism mode for SPI busses handled asynchronously.

Service to set the asynchronous mechanism mode for SPI busses handled asynchronously.

Parameters:

  • Mode New mode required

Returns:

  • E_OK read command has been accepted

  • E_NOT_OK read command has not been accepted

Return: returns whether command has been accepted or rejected

Precondition: None

Postcondition: None

5.8.4.15. function Spi_MainFunction_Handling

void Spi_MainFunction_Handling(
    void 
)

Brief: Spi_MainFunction_Handling: This function shall polls the SPI interrupts linked to HW Units.

This function shall polls the SPI interrupts linked to HW Units allocated to the transmission of SPI sequences to enable the evolution of transmission state machine

Returns:

  • E_OK read command has been accepted

  • E_NOT_OK read command has not been accepted

Return: returns whether command has been accepted or rejected

Precondition: None

Postcondition: None