Initialize a channel

Informative

How upper-layer software brings the CAN driver and a channel up (and down). For the binding rules see CHI-CAN-MUST-01/CHI-CAN-MUST-02 in Can — Requirements; for signatures see API Reference.

Prerequisites

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

Bring the driver up

Can_Init(&CanConfig);        /* driver: UNINIT -> INIT; every channel -> STOPPED */

After Can_Init returns, the driver is in CAN_DRV_STATE_INIT and each channel is STOPPED — initialized but not yet on the bus. Interrupts are enabled only for events you configured as Interrupt.

Start and Stop a Channel

Can_SetChannelState(0u, CAN_CH_STATE_STARTED);   /* STOPPED -> STARTED: joins the bus */
/* ... transmit / receive ... */
Can_SetChannelState(0u, CAN_CH_STATE_STOPPED);   /* STARTED -> STOPPED: leaves the bus  */

A transition that the hardware confirms immediately is reported synchronously; one that needs status polling is confirmed later via CanIf_OnChannelState (see Concepts). Poll the channel state with Can_GetChannelState if you need to observe it.

Shutdown

/* Every channel must be STOPPED (not STARTED) before de-init. */
Can_DeInit();                /* driver: INIT -> UNINIT; every channel -> UNINIT */

See also

Common mistakes — starting a channel from the wrong state, or de-initializing while a channel is STARTED, raises a development error.

Concepts — the State transition sequence shows the init and Can_SetChannelState / Can_CyclicFunction handshake, including deferred completion.