Initialize the driver

Informative

How to bring the SPI driver up and down. Binding rules: CHI-SPI-MUST-09 and CHI-SPI-MUST-10 in Spi — Requirements; signatures in API Reference.

Prerequisites

Before Spi_Init, another module must have configured the channel’s input clock, port pins, and interrupt controller. The SPI driver assumes these are ready (see Overview).

Bring the driver up

Spi_Init(NULL_PTR);          /* driver: UNINIT -> INIT; every channel -> IDLE */

configPtr must be NULL_PTR — the configuration variant is selected at build time, not passed at runtime. After Spi_Init returns, the driver is in SPI_DRV_STATE_INIT and each channel is in SPI_CH_STATE_IDLE. A target channel begins detecting chip-select activation. Interrupts are enabled only for channels configured as Interrupt.

Shut down

Spi_DeInit();                /* aborts any ongoing transaction; driver -> UNINIT */

Spi_DeInit immediately stops any ongoing transfer and de-initialises the hardware. Prefer to call it with the channel in SPI_CH_STATE_IDLE — aborting mid-transaction can leave a target in an undefined state. Poll the current state of a channel with Spi_GetChannelState if you need to observe it.

See also

Controller transactions and Target transactions — running transactions once a channel is initialized.