34static const char*
s_tag =
"SMBUS";
37typedef enum : uint16_t {
46typedef enum : uint16_t {
111 uint8_t c = (uint8_t)(crc ^ b);
116 c = (uint8_t)(c << 1U);
124 if ((data ==
nullptr) || (len == 0U)) {
128 for (uint32_t i = 0U; i < len; ++i) {
144 ((uint32_t)rw_bit & 1U));
159 if (cfg->
bus.
read ==
nullptr) {
207 return s_state.bus.write(
s_state.bus.ctx, target_7b, buf, len,
true);
216 uint8_t buf[2] = {0U, 0U};
217 const uint32_t len =
s_state.pec_enabled ? 2U : 1U;
256 return s_state.bus.write(
s_state.bus.ctx, target_7b, buf, len,
true);
267 uint8_t rx[2] = {0U, 0U};
268 const uint32_t rxlen =
s_state.pec_enabled ? 2U : 1U;
311 for (uint8_t i = 0U; i < len; ++i) {
312 frame[fi++] = data[i];
317 for (uint32_t i = 0U; i < fi; ++i) {
322 return s_state.bus.write(
s_state.bus.ctx, target_7b, frame, fi,
true);
365 for (uint8_t i = 0U; i < count; ++i) {
413 const uint8_t count = rx[0];
418 for (uint8_t i = 0U; i < count; ++i) {
419 buf[i] = rx[1U + (uint32_t)i];
448 const uint32_t want = (uint32_t)cap + 1U + (
s_state.pec_enabled ? 1U : 0U);
483 if (
s_state.alert_fn !=
nullptr) {
486 const uint8_t status = (uint8_t)(ara & 1U);
static const char * s_tag
Logging / check tag.
Annotation-attribute framework macros for ra8-firmware.
#define RA8_ISR_SAFE
The function is callable from interrupt context.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
Validation and Error-Checking Macros for ra8-firmware.
#define RA8_CHECK_NULL_PTR(ptr, tag, message)
Reject nullptr pointer, returning k_ra8_err_null_ptr.
Error Code Definitions for ra8-firmware.
@ k_ra8_err_crc_mismatch
CRC mismatch detected on received data.
@ k_ra8_err_invalid_arg
Invalid function argument.
@ k_ra8_err_not_initialized
Module not initialized – _init() not yet called successfully.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
@ k_ra8_err_invalid_size
Invalid size parameter (too large, too small, or misaligned).
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Injected I2C-bus seam consumed by Ring-3 I2C device drivers.
Lightweight Logging Interface for ra8-firmware.
#define ra8_log_error(tag, message)
RA8 log error.
ra8_err_t ra8_smbus_write_byte_data(uint8_t target_7b, uint8_t cmd, uint8_t data)
Write Byte Data: register-indexed byte write (SMBus 3.2 sec 6.5.4).
uint8_t ra8_smbus_pec(const uint8_t *data, uint32_t len)
Compute CRC-8/SMBus over a buffer.
ra8_err_t ra8_smbus_init(const ra8_smbus_cfg_t *cfg)
Initialise the SMBus layer over the injected bus seam.
ra8_err_t ra8_smbus_alert_register_callback(ra8_smbus_alert_fn_t fn, void *ctx)
Register a callback fired when ra8_smbus_alert_dispatch successfully reads the Alert Response Address...
ra8_err_t ra8_smbus_send_byte(uint8_t target_7b, uint8_t data)
Send Byte transaction (SMBus 3.2 section 6.5.2).
ra8_err_t ra8_smbus_block_write(uint8_t target_7b, uint8_t cmd, const uint8_t *data, uint8_t len)
Block Write (SMBus 3.2 section 6.5.7).
ra8_err_t ra8_smbus_alert_dispatch(void)
Dispatch a single SMBALERT# event: read the ARA and fire the registered callback.
ra8_err_t ra8_smbus_block_read(uint8_t target_7b, uint8_t cmd, uint8_t *buf, uint8_t cap, uint8_t *out_len)
Block Read (SMBus 3.2 section 6.5.8).
ra8_err_t ra8_smbus_receive_byte(uint8_t target_7b, uint8_t *out_data)
Receive Byte transaction (SMBus 3.2 section 6.5.3).
static uint8_t internal_make_addr_byte(uint8_t target_7b, uint8_t rw_bit)
ra8_err_t ra8_smbus_deinit(void)
Tear the SMBus layer down and release the driver slot.
static uint8_t internal_pec_update(uint8_t crc, uint8_t b)
Update one byte into a running CRC-8/SMBus accumulator.
ra8_smbus_internal_t
Implementation constants.
@ k_ra8_smbus_pec_init
CRC-8 initial value.
@ k_ra8_smbus_byte_mask
8-bit narrowing mask.
@ k_ra8_smbus_addr_shift
7-bit -> 8-bit address shift.
@ k_ra8_smbus_pec_poly
CRC-8 polynomial (SMBus 3.2 5.4).
@ k_ra8_smbus_rw_write
R/W bit value for write.
@ k_ra8_smbus_msb_for_byte
MSB index for byte-loop pec calc.
@ k_ra8_smbus_pec_top_bit
Top bit mask used by pec loop.
@ k_ra8_smbus_rw_read
R/W bit value for read.
smbus_buf_size_t
SMBus scratch buffer sizes (max 255-byte payload + overhead).
@ k_smbus_frame_bytes
Smbus frame bytes.
@ k_smbus_rx_bytes
Smbus RX bytes.
static ra8_err_t internal_block_read_pec_check(uint8_t target_7b, uint8_t cmd, const uint8_t *buf, uint8_t count, uint8_t pec_rx)
Verify the PEC byte of a completed Block Read transfer.
static ra8_err_t internal_block_read_finish(uint8_t target_7b, uint8_t cmd, const uint8_t *rx, uint8_t cap, uint8_t *buf, uint8_t *out_len)
Unpack a completed Block Read transfer into the caller buffer.
ra8_err_t ra8_smbus_read_byte_data(uint8_t target_7b, uint8_t cmd, uint8_t *out_data)
Read Byte Data: register-indexed byte read (SMBus 3.2 sec 6.5.5).
SMBus 3.2 protocol layer over an injected I2C bus seam.
@ k_ra8_smbus_alert_addr_7b
Alert Response Address (ARA).
void(* ra8_smbus_alert_fn_t)(void *ctx, uint8_t target_7b, uint8_t status)
SMBALERT# notification callback.
Caller-filled I2C controller-transfer seam (write / read / write-then-read).
ra8_err_t(* read)(void *ctx, uint8_t addr, uint8_t *data, uint32_t len)
Controller read of len bytes from 7-bit address addr.
ra8_err_t(* transfer)(void *ctx, uint8_t addr, const uint8_t *wr, uint32_t wr_len, uint8_t *rd, uint32_t rd_len)
Combined write-then-RESTART-then-read in one transaction.
ra8_err_t(* write)(void *ctx, uint8_t addr, const uint8_t *data, uint32_t len, bool send_stop)
Controller write of len bytes to 7-bit address addr.
Configuration descriptor for ra8_smbus_init.
ra8_i2c_bus_ops_t bus
Injected I2C transfer seam (app-bound).
bool pec_enabled
Append + verify PEC on every xfer.
Module state: latched at init time.
ra8_i2c_bus_ops_t bus
Injected I2C transfer seam.
bool pec_enabled
Append + verify PEC byte.
void * alert_ctx
Context for alert_fn.
ra8_smbus_alert_fn_t alert_fn
SMBALERT# callback (or NULL).
bool initialized
Latched after a good init.