ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_smbus.h
Go to the documentation of this file.
1
45
46#pragma once
47
48#ifdef __cplusplus
49extern "C" {
50#endif
51
52#include <stdint.h>
53
54#include "ra8_err.h"
55#include "ra8_i2c_bus_ops.h"
56
57/* =============================================================================
58 * Public types
59 * =============================================================================
60 */
61
77
91
101typedef void (*ra8_smbus_alert_fn_t)(void* ctx, uint8_t target_7b, uint8_t status);
102
103/* =============================================================================
104 * Lifecycle
105 * =============================================================================
106 */
107
133[[nodiscard]] ra8_err_t ra8_smbus_init(const ra8_smbus_cfg_t* cfg);
134
148[[nodiscard]] ra8_err_t ra8_smbus_deinit(void);
149
150/* =============================================================================
151 * Byte protocols (SMBus 3.2 sec 6.5.2 / 6.5.3 / 6.5.4 / 6.5.5)
152 * =============================================================================
153 */
154
180[[nodiscard]] ra8_err_t ra8_smbus_send_byte(uint8_t target_7b, uint8_t data);
181
206[[nodiscard]] ra8_err_t ra8_smbus_receive_byte(uint8_t target_7b, uint8_t* out_data);
207
230[[nodiscard]] ra8_err_t ra8_smbus_write_byte_data(uint8_t target_7b, uint8_t cmd, uint8_t data);
231
259[[nodiscard]] ra8_err_t ra8_smbus_read_byte_data(uint8_t target_7b, uint8_t cmd, uint8_t* out_data);
260
261/* =============================================================================
262 * Block protocols (SMBus 3.2 sec 6.5.7 / 6.5.8)
263 * =============================================================================
264 */
265
292[[nodiscard]] ra8_err_t
293ra8_smbus_block_write(uint8_t target_7b, uint8_t cmd, const uint8_t* data, uint8_t len);
294
325[[nodiscard]] ra8_err_t
326ra8_smbus_block_read(uint8_t target_7b, uint8_t cmd, uint8_t* buf, uint8_t cap, uint8_t* out_len);
327
328/* =============================================================================
329 * SMBALERT# / Host Notify (SMBus 3.2 sec 6.5.13)
330 * =============================================================================
331 */
332
358
385[[nodiscard]] ra8_err_t ra8_smbus_alert_dispatch(void);
386
387/* =============================================================================
388 * PEC helpers (exposed for unit tests)
389 * =============================================================================
390 */
391
416uint8_t ra8_smbus_pec(const uint8_t* data, uint32_t len);
417
418#ifdef __cplusplus
419}
420#endif
Error Code Definitions for ra8-firmware.
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Definition ra8_err.h:546
Injected I2C-bus seam consumed by Ring-3 I2C device drivers.
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).
Definition ra8_smbus.c:240
ra8_smbus_limits_t
Spec-mandated buffer ceilings.
Definition ra8_smbus.h:72
@ k_ra8_smbus_block_max
Max data bytes per block xfer.
Definition ra8_smbus.h:73
@ k_ra8_smbus_alert_addr_7b
Alert Response Address (ARA).
Definition ra8_smbus.h:75
@ k_ra8_smbus_frame_max
Max wire bytes incl.
Definition ra8_smbus.h:74
uint8_t ra8_smbus_pec(const uint8_t *data, uint32_t len)
Compute CRC-8/SMBus over a buffer.
Definition ra8_smbus.c:122
ra8_err_t ra8_smbus_init(const ra8_smbus_cfg_t *cfg)
Initialise the SMBus layer over the injected bus seam.
Definition ra8_smbus.c:152
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...
Definition ra8_smbus.c:461
ra8_err_t ra8_smbus_send_byte(uint8_t target_7b, uint8_t data)
Send Byte transaction (SMBus 3.2 section 6.5.2).
Definition ra8_smbus.c:191
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).
Definition ra8_smbus.c:294
void(* ra8_smbus_alert_fn_t)(void *ctx, uint8_t target_7b, uint8_t status)
SMBALERT# notification callback.
Definition ra8_smbus.h:101
ra8_err_t ra8_smbus_alert_dispatch(void)
Dispatch a single SMBALERT# event: read the ARA and fire the registered callback.
Definition ra8_smbus.c:472
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).
Definition ra8_smbus.c:433
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).
Definition ra8_smbus.c:210
ra8_err_t ra8_smbus_deinit(void)
Tear the SMBus layer down and release the driver slot.
Definition ra8_smbus.c:175
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).
Definition ra8_smbus.c:259
Caller-filled I2C controller-transfer seam (write / read / write-then-read).
Configuration descriptor for ra8_smbus_init.
Definition ra8_smbus.h:87
ra8_i2c_bus_ops_t bus
Injected I2C transfer seam (app-bound).
Definition ra8_smbus.h:88
bool pec_enabled
Append + verify PEC on every xfer.
Definition ra8_smbus.h:89