TT-System-Firmware APIs 19.13.99
Tenstorrent Firmware
Loading...
Searching...
No Matches
smbus_target.h File Reference
#include <stddef.h>
#include <stdint.h>
Include dependency graph for smbus_target.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  smbus_cmd_def
struct  smbus_cmd_registration
 Command registration entry for table-driven SMBus setup. More...

Macros

#define SMBUS_CMD_ENTRY(_cmd, _pec, _trans_type, _rcv, _send)
 Build a generic SMBus command registration entry.
#define SMBUS_CMD_HANDLER_FIELDS_WRITE(_func)
 Build handler-field initializers for WRITE direction.
#define SMBUS_CMD_HANDLER_FIELDS_READ(_func)
 Build handler-field initializers for READ direction.
#define SMBUS_CMD_GEN_ENTRY(_cmd, _pec, _dir, _kind, _func)
 Build an entry by direction and transaction-kind suffix.
#define SMBUS_CMD_BLOCK_RD_ENTRY(_cmd, _pec, _send)
 Build an entry for SMBus block-read command handling.
#define SMBUS_CMD_BLOCK_WR_ENTRY(_cmd, _pec, _rcv)
 Build an entry for SMBus block-write command handling.
#define SMBUS_CMD_READ_BYTE_ENTRY(_cmd, _pec, _send)
 Build an entry for SMBus read-byte command handling.
#define SMBUS_CMD_WRITE_BYTE_ENTRY(_cmd, _pec, _rcv)
 Build an entry for SMBus write-byte command handling.
#define SMBUS_CMD_READ_WORD_ENTRY(_cmd, _pec, _send)
 Build an entry for SMBus read-word command handling.
#define SMBUS_CMD_WRITE_WORD_ENTRY(_cmd, _pec, _rcv)
 Build an entry for SMBus write-word command handling.
#define SMBUS_CMD_BLOCK_WR_BLOCK_RD_ENTRY(_cmd, _pec, _rcv, _send)
 Build an entry for SMBus block-write-block-read command handling.

Typedefs

typedef int32_t(* smbus_rcv_handler) (const uint8_t *data, uint8_t size)
 Definition of a SMBUS receive handler.
typedef int32_t(* smbus_send_handler) (uint8_t *data, uint8_t *size)
 Definition of a SMBUS send handler.

Enumerations

enum  smbus_trans_type {
  SMBUS_TRANS_WRITE_BYTE ,
  SMBUS_TRANS_READ_BYTE ,
  SMBUS_TRANS_WRITE_WORD ,
  SMBUS_TRANS_READ_WORD ,
  SMBUS_TRANS_WRITE_BLOCK ,
  SMBUS_TRANS_READ_BLOCK ,
  SMBUS_TRANS_READ_WRITE_BLOCK
}
 A list of supported SMBUS transaction types. More...

Functions

int32_t smbus_target_register_cmd (const struct device *dev, uint8_t cmd_id, const struct smbus_cmd_def *smbus_cmd)
 Register the given command to the SMBUS target implementation.
int32_t smbus_target_register_cmds (const struct device *dev, const struct smbus_cmd_registration *cmds, size_t num_cmds)
 Register a table of commands to the SMBUS target implementation.
uint32_t smbus_target_get_error_count (const struct device *dev)
 Get total number of SMBUS target errors.

Macro Definition Documentation

◆ SMBUS_CMD_BLOCK_RD_ENTRY

#define SMBUS_CMD_BLOCK_RD_ENTRY ( _cmd,
_pec,
_send )
Value:
SMBUS_CMD_GEN_ENTRY(_cmd, _pec, READ, BLOCK, _send)
#define SMBUS_CMD_GEN_ENTRY(_cmd, _pec, _dir, _kind, _func)
Build an entry by direction and transaction-kind suffix.
Definition smbus_target.h:84

Build an entry for SMBus block-read command handling.

◆ SMBUS_CMD_BLOCK_WR_BLOCK_RD_ENTRY

#define SMBUS_CMD_BLOCK_WR_BLOCK_RD_ENTRY ( _cmd,
_pec,
_rcv,
_send )
Value:
@ SMBUS_TRANS_READ_WRITE_BLOCK
Definition smbus_target.h:23
#define SMBUS_CMD_ENTRY(_cmd, _pec, _trans_type, _rcv, _send)
Build a generic SMBus command registration entry.
Definition smbus_target.h:60

Build an entry for SMBus block-write-block-read command handling.

◆ SMBUS_CMD_BLOCK_WR_ENTRY

#define SMBUS_CMD_BLOCK_WR_ENTRY ( _cmd,
_pec,
_rcv )
Value:
SMBUS_CMD_GEN_ENTRY(_cmd, _pec, WRITE, BLOCK, _rcv)

Build an entry for SMBus block-write command handling.

◆ SMBUS_CMD_ENTRY

#define SMBUS_CMD_ENTRY ( _cmd,
_pec,
_trans_type,
_rcv,
_send )
Value:
{ \
.cmd = (_cmd), \
.def = {.pec = (_pec), \
.trans_type = (_trans_type), \
.rcv_handler = (_rcv), \
.send_handler = (_send)}, \
}

Build a generic SMBus command registration entry.

◆ SMBUS_CMD_GEN_ENTRY

#define SMBUS_CMD_GEN_ENTRY ( _cmd,
_pec,
_dir,
_kind,
_func )
Value:
{ \
.cmd = (_cmd), \
.def = {.pec = (_pec), \
.trans_type = SMBUS_TRANS_##_dir##_##_kind, \
SMBUS_CMD_HANDLER_FIELDS_##_dir(_func)}, \
}

Build an entry by direction and transaction-kind suffix.

_dir must be READ or WRITE.

_kind must match a suffix from enum smbus_trans_type, e.g. BYTE, WORD, BLOCK.

◆ SMBUS_CMD_HANDLER_FIELDS_READ

#define SMBUS_CMD_HANDLER_FIELDS_READ ( _func)
Value:
.rcv_handler = NULL, .send_handler = (_func)
#define NULL
Definition avs.c:45

Build handler-field initializers for READ direction.

◆ SMBUS_CMD_HANDLER_FIELDS_WRITE

#define SMBUS_CMD_HANDLER_FIELDS_WRITE ( _func)
Value:
.rcv_handler = (_func), .send_handler = NULL

Build handler-field initializers for WRITE direction.

◆ SMBUS_CMD_READ_BYTE_ENTRY

#define SMBUS_CMD_READ_BYTE_ENTRY ( _cmd,
_pec,
_send )
Value:
SMBUS_CMD_GEN_ENTRY(_cmd, _pec, READ, BYTE, _send)

Build an entry for SMBus read-byte command handling.

◆ SMBUS_CMD_READ_WORD_ENTRY

#define SMBUS_CMD_READ_WORD_ENTRY ( _cmd,
_pec,
_send )
Value:
SMBUS_CMD_GEN_ENTRY(_cmd, _pec, READ, WORD, _send)

Build an entry for SMBus read-word command handling.

◆ SMBUS_CMD_WRITE_BYTE_ENTRY

#define SMBUS_CMD_WRITE_BYTE_ENTRY ( _cmd,
_pec,
_rcv )
Value:
SMBUS_CMD_GEN_ENTRY(_cmd, _pec, WRITE, BYTE, _rcv)

Build an entry for SMBus write-byte command handling.

◆ SMBUS_CMD_WRITE_WORD_ENTRY

#define SMBUS_CMD_WRITE_WORD_ENTRY ( _cmd,
_pec,
_rcv )
Value:
SMBUS_CMD_GEN_ENTRY(_cmd, _pec, WRITE, WORD, _rcv)

Build an entry for SMBus write-word command handling.

Typedef Documentation

◆ smbus_rcv_handler

typedef int32_t(* smbus_rcv_handler) (const uint8_t *data, uint8_t size)

Definition of a SMBUS receive handler.

This function is invoked when the SMBUS target has data from the I2C controller to relay to the application. SMBUS receive handlers shall return 0 on success, and any other value on failure.

◆ smbus_send_handler

typedef int32_t(* smbus_send_handler) (uint8_t *data, uint8_t *size)

Definition of a SMBUS send handler.

This function is invoked when the SMBUS target requests data from the application to send to the I2C controller. SMBUS send handlers shall return 0 on success, and any other value on failure.

Enumeration Type Documentation

◆ smbus_trans_type

A list of supported SMBUS transaction types.

Enumerator
SMBUS_TRANS_WRITE_BYTE 
SMBUS_TRANS_READ_BYTE 
SMBUS_TRANS_WRITE_WORD 
SMBUS_TRANS_READ_WORD 
SMBUS_TRANS_WRITE_BLOCK 
SMBUS_TRANS_READ_BLOCK 
SMBUS_TRANS_READ_WRITE_BLOCK 

Function Documentation

◆ smbus_target_get_error_count()

uint32_t smbus_target_get_error_count ( const struct device * dev)

Get total number of SMBUS target errors.

Parameters
devThe SMBUS target device instance.
Returns
Number of errors that went through the SMBUS ratelimited error macro.

◆ smbus_target_register_cmd()

int32_t smbus_target_register_cmd ( const struct device * dev,
uint8_t cmd_id,
const struct smbus_cmd_def * smbus_cmd )

Register the given command to the SMBUS target implementation.

Parameters
devThe device to register the command for.
cmd_idThe command ID to register the handler for.
smbus_cmdPointer to the smbus command to register. The memory must have persistent storage for the duration of the time the target remains registered to the I2C.

◆ smbus_target_register_cmds()

int32_t smbus_target_register_cmds ( const struct device * dev,
const struct smbus_cmd_registration * cmds,
size_t num_cmds )

Register a table of commands to the SMBUS target implementation.

Parameters
devThe device to register commands for.
cmdsPointer to command registration table.
num_cmdsNumber of entries in cmds.
Returns
0 on success, otherwise a negative error code.