API Reference

Normative

The I2C driver API contract. A conformant driver MUST provide these types and functions with the behavior described. Function and type signatures are extracted from the driver headers with Doxygen/Breathe; only the interrupt handler is hand-framed, because its name is vendor-specific. Keywords per Requirement Keywords; behavioral rules in I2c — Requirements; error codes in Errors.

Data types at a glance

Type

Kind

Purpose

I2c_ConfigType

struct

Root configuration structure (build-time; I2c_Init takes NULL_PTR).

I2c_DirectionType

enum

Transfer direction (controller write / read).

I2c_ChannelStateType

enum

Channel state (UNINIT / IDLE / READY / BUSY).

I2c_ErrorType

enum

Transfer error reported via I2c_Callout_OnError (e.g. NACK).

API at a glance

Function

Group

Purpose

I2c_Init

Initialization and shutdown

Initialize the driver and every channel.

I2c_DeInit

Initialization and shutdown

Abort transfers and de-initialize the driver.

I2c_StartTxTransaction

Transactions

Start (controller) or stage (target) a write.

I2c_StartRxTransaction

Transactions

Start (controller) or stage (target) a read.

I2c_GetChannelState

Status and scheduling

Read a channel’s current state.

I2c_PollFunction

Status and scheduling

Service events for polled channels.

I2c_Interrupt

Status and scheduling

Driver interrupt service routine.

Callouts and expected interfaces at a glance

The functions the integrator MUST provide (CHI-I2C-MUST-21); see the Callouts group below. I2cDrv has no upper-layer interface stack, so it reports its events through callouts that the integrator implements in the generated I2c_Callout_Stubs.c (see The Callout Stub File).

Function

Kind

Purpose

I2c_Callout_OnReception

Callout

A read transaction completed.

I2c_Callout_OnTransmission

Callout

A write transaction completed.

I2c_Callout_OnError

Callout

A transfer error occurred (e.g. NACK).

I2c_Callout_OnAddress

Callout

Target mode: this channel’s address was matched.

LogM_Report

Common

Reports development / runtime errors with a log level.

<Mip>_EnterCriticalSection / <Mip>_ExitCriticalSection

Common (optional)

Bracket sections requiring exclusive access — see critical sections.

Data types
I2c_ConfigType
struct I2c_ConfigType

Configuration structure type.

Configuration variants are selected at build time; I2c_Init currently takes NULL_PTR. Available via: I2c.h

I2c_DirectionType
enum I2c_DirectionType

Specifies request direction.

Values:

enumerator I2C_DIR_CONTROLLER_WRITE = 0x00

Controller Mode node write request to a Target Node

enumerator I2C_DIR_CONTROLLER_READ = 0x01

Controller Mode node read request from a Target Node

Available via: I2c_DriverTypes.h

I2c_ChannelStateType
enum I2c_ChannelStateType

Specifies the I2cDrv internal state.

Values:

enumerator I2C_CH_STATE_UNINIT = 0x00

Not yet initialized

enumerator I2C_CH_STATE_IDLE = 0x01

No transaction request

enumerator I2C_CH_STATE_READY = 0x02

Controller Mode: All data has been transferred (before sending STOP condition or REPEATED_START condition) Target Mode: Address matched. Ready to setup TX/RX data.

enumerator I2C_CH_STATE_BUSY = 0x03

Transaction on-going

Available via: I2c_DriverTypes.h

I2c_ErrorType
enum I2c_ErrorType

Specifies error types which are reported via I2c_Callout_OnError.

Values:

enumerator I2C_ERR_NACK_RECEIVED

Received NACK during transaction. Reported via I2c_Callout_OnError.

Also note I2C_ADDR_UNSPECIFIED (the address a target passes to I2c_Start*Transaction). Available via: I2c_DriverTypes.h

Initialization and shutdown
I2c_Init
void I2c_Init(const I2c_ConfigType *configPtr)

Initializes the driver and HW.

Sync/Async:

Synchronous

Reentrancy:

Non reentrant

Service ID [hex]:

0x00

Development error(s):

Parameters:

configPtr[in] Pointer to the configuration structure. This parameter is intended for future extensions to support runtime-selectable configuration variants, which allow the selection and initialization of specific variants during runtime. As this functionality is not currently supported, a NULL_PTR SHALL be provided.

Returns:

None.

When to call: once, before any other I2C function, with the driver in I2C_DRV_STATE_UNINIT. configPtr MUST be NULL_PTR.

Effect: initialises the driver and hardware; leaves every channel in IDLE (a target channel begins accepting its configured address); enables interrupts for interrupt channels. Errors: see Errors. Available via: I2c.h

I2c_DeInit
void I2c_DeInit(void)

Abort on-going transaction and de-initialize I2C hardware. Typically used when micro controller will be switched to other state (e.g. low power mode) or recovery from I2C communication erroneous state.

Sync/Async:

Synchronous

Reentrancy:

Non reentrant

Service ID [hex]:

0x01

Parameters:

None

Returns:

None.

Effect: aborts any ongoing transaction and de-initialises the driver, returning it to I2C_DRV_STATE_UNINIT. Available via: I2c.h

Transactions
I2c_StartTxTransaction
Std_ReturnType I2c_StartTxTransaction(uint8 channelId, uint8 deviceAddr, const uint8 *txDataPtr, uint16 txDataLength)

For Controller Mode channel, initiates the transaction with the given data and deviceAddr. For Target Mode channel, setup TX data with the given data for Controller Node request.

Sync/Async:

Asynchronous

Reentrancy:

Conditionally reentrant (reentrant when called with different channelIds)

Service ID [hex]:

0x02

Development error(s):

Parameters:
  • channelId[in] ID of the I2C channel to be addressed.

  • deviceAddr[in]

    The Target Node device address. I2C_ADDR_UNSPECIFIED is set for the channel in Target Mode.

    Note: If the channel is the target node, I2cDrv should not check the deviceAddr parameter. Even if deviceAddr is not I2C_ADDR_UNSPECIFIED, I2cDrv will not log a development error.

  • txDataPtr[in] Buffer address for transmit data.

  • txDataLength[in] Specifies the buffer length. Must be > 0.

Return values:
  • E_OK – Request has been accepted.

  • E_NOT_OK – Development error occurred.

When to call: on an IDLE controller channel to start a write, or from I2c_Callout_OnAddress on a target channel (with I2C_ADDR_UNSPECIFIED) to stage the response. Returns: E_OK if accepted, else E_NOT_OK (development error). The caller MUST keep txDataPtr valid until completion. Errors: see Errors. Available via: I2c.h

I2c_StartRxTransaction
Std_ReturnType I2c_StartRxTransaction(uint8 channelId, uint8 deviceAddr, uint8 *rxDataPtr, uint16 rxDataLength)

For Controller Mode channel, initiates the transaction with the given data and deviceAddr. For Target Mode channel, setup RX with the given data for Controller Node request.

Sync/Async:

Asynchronous

Reentrancy:

Conditionally reentrant (reentrant when called with different channelIds)

Service ID [hex]:

0x03

Development error(s):

Parameters:
  • channelId[in] ID of the I2C channel to be addressed.

  • deviceAddr[in]

    The Target Node device address. I2C_ADDR_UNSPECIFIED is set for the channel in Target Mode.

    Note: If the channel is the target node, I2cDrv should not check the deviceAddr parameter. Even if deviceAddr is not I2C_ADDR_UNSPECIFIED, I2cDrv will not log a development error.

  • rxDataPtr[in] Buffer address for received data.

  • rxDataLength[in] Specifies the buffer length. Must be > 0.

Return values:
  • E_OK – Request has been accepted.

  • E_NOT_OK – Development error occurred.

When to call: on an IDLE controller channel to start a read, or from I2c_Callout_OnAddress on a target channel (with I2C_ADDR_UNSPECIFIED). The caller MUST keep rxDataPtr valid until completion. Errors: see Errors. Available via: I2c.h

Status and scheduling
I2c_GetChannelState
I2c_ChannelStateType I2c_GetChannelState(uint8 channelId)

Inform the channel is on transaction or not (Idle, Busy).

Sync/Async:

Synchronous

Reentrancy:

Reentrant

Service ID [hex]:

0x06

Development error(s):

Parameters:

channelId[in] ID of the I2C channel to be addressed.

Returns:

The state of the selected channel.

Effect: returns the current state of the channel. Errors: see Errors. Available via: I2c.h

I2c_PollFunction
void I2c_PollFunction(void)

Handle interrupt event with polling method.

Reentrancy:

Non reentrant

Service ID [hex]:

0x05

Parameters:

None

Returns:

None.

When to call: cyclically, for channels configured for polling. Handles the same events as I2c_Interrupt. May be empty if all channels are interrupt-driven. Available via: I2c.h

I2c_Interrupt
void I2c_Interrupt<vectorNr>[<VendorSpecificSuffix>](void)

Effect: the driver interrupt service routine; pumps transfer bytes and fires the completion / error / address callouts. Define it with the ISR() macro (see the general reference). Available via: I2c.h

Callouts the integrator provides

The driver calls these callouts to report events. The integrator MUST provide them (CHI-I2C-MUST-21) by filling in the matching user code block in I2c_Callout_Stubs.c (see The Callout Stub File); the prototypes are declared in I2c.h. LogM_Report and the critical-section services are documented in the general reference.

I2c_Callout_OnReception
void I2c_Callout_OnReception(uint8 channelId, uint16 length)

Indicates completion of RX transaction. This function will be called by I2c_Interrupt and I2c_PollFunction when the event is detected. For Controller Mode channel: If I2c_StartTxTransaction or I2c_StartRxTransaction is called at this interface, I2cDrv will sends START condition into the bus without sending STOP condition (REPEATED_START). If neither of the start transaction function is not called, then I2cDrv will send STOP condition.

Sync/Async:

Synchronous

Reentrancy:

Conditionally reentrant (reentrant when called with different channelIds)

Parameters:
  • channelId[in] ID of the I2C channel which informs the event.

  • length[in] Inform transferred buffer length. In Target Mode and if Controller Node sends more data than RX buffer length, the length is saturated to the buffer length and data more than the buffer length is ignored.

Returns:

None.

A read transaction completed; length bytes were received. Available via: I2c.h; implement it in I2c_Callout_Stubs.c.

I2c_Callout_OnTransmission
void I2c_Callout_OnTransmission(uint8 channelId, uint16 length)

Indicates completion of TX transaction. This function will be called by I2c_Interrupt and I2c_PollFunction when the event is detected. For Controller Mode channel: RESTRICTED Chiisai HAL I2C Driver Specification If I2c_StartTxTransaction or I2c_StartRxTransaction is called at this interface, I2cDrv will sends START condition into the bus without sending STOP condition (REPEATED_START). If neither of the start transaction function is not called, then I2cDrv will send STOP condition.

Sync/Async:

Synchronous

Reentrancy:

Conditionally reentrant (reentrant when called with different channelIds)

Parameters:
  • channelId[in] ID of the I2C channel which informs the event.

  • length[in] Specifies the transmitted data length. If the Controller Node has sent more data than fits in the Target Node’s buffer, the length is truncated at the buffer length.

Returns:

None.

A write transaction completed; length bytes were sent. Available via: I2c.h; implement it in I2c_Callout_Stubs.c.

I2c_Callout_OnError
void I2c_Callout_OnError(uint8 channelId, I2c_ErrorType error)

Indicates error occurrence during transaction. This function will be called by I2c_Interrupt and I2c_PollFunction when the event is detected.

Sync/Async:

Synchronous

Reentrancy:

Conditionally reentrant (reentrant when called with different channelIds)

Parameters:
  • channelId[in] ID of the I2C channel which informs the event.

  • error[in] Indicates the error kind.

Returns:

None.

A transfer error occurred (e.g. I2C_ERR_NACK_RECEIVED). Available via: I2c.h; implement it in I2c_Callout_Stubs.c.

I2c_Callout_OnAddress
void I2c_Callout_OnAddress(uint8 channelId, I2c_DirectionType direction)

Target Mode only. Indicates the reception of an address that is tied to the channel. This function will be called by I2c_Interrupt and I2c_PollFunction when the received address matches the Target Node channel.

Sync/Async:

Synchronous

Reentrancy:

Conditionally reentrant (reentrant when called with different channelIds)

Parameters:
  • channelId[in] ID of the I2C channel which informs the event.

  • direction[in] Indicates requested direction (read/write).

Returns:

None.

Target mode only: this channel’s address was matched; direction is the controller’s intent. Available via: I2c.h; implement it in I2c_Callout_Stubs.c.