4#ifndef PROTOCORE_SMBUS_H
5#define PROTOCORE_SMBUS_H
36#define PROTOCORE_SMBUS_BLOCK_MAX 32
38#define PROTOCORE_SMBUS_WRITE 0u
40#define PROTOCORE_SMBUS_READ 1u
45 uint8_t (*addr_byte)(uint8_t *, uint8_t, uint8_t);
46 uint8_t (*pec_write)(uint8_t *, uint8_t,
const uint8_t *, size_t);
47 uint8_t (*pec_read)(uint8_t *, uint8_t,
const uint8_t *, size_t,
const uint8_t *, size_t);
53 proto_bool (*receive_byte)(uint8_t *, uint8_t, uint8_t *);
54 proto_bool (*write_byte)(uint8_t *, uint8_t, uint8_t, uint8_t);
55 proto_bool (*read_byte)(uint8_t *, uint8_t, uint8_t, uint8_t *);
56 proto_bool (*write_word)(uint8_t *, uint8_t, uint8_t, uint16_t);
57 proto_bool (*read_word)(uint8_t *, uint8_t, uint8_t, uint16_t *);
58 proto_bool (*write_block)(uint8_t *, uint8_t, uint8_t,
const uint8_t *, size_t);
59 proto_bool (*read_block)(uint8_t *, uint8_t, uint8_t, uint8_t *, size_t,
size_t *);
60 proto_bool (*process_call)(uint8_t *, uint8_t, uint8_t, uint16_t, uint16_t *);
61 proto_bool (*block_process_call)(uint8_t *, uint8_t, uint8_t,
const uint8_t *, size_t, uint8_t *, size_t,
size_t *);
64 receive_byte, write_byte, read_byte, write_word, read_word, write_block, read_block, process_call,
218 uint8_t *out,
size_t cap,
size_t *out_len);
#define PROTOCORE_NS_LAYOUT(T,...)
Pin every dispatch slot of a table that is nothing but function pointers.
#define PROTOCORE_NS
Storage for a dispatch table. The const is load bearing.
uint8_t protocore_smbus_pec_write(uint8_t *work, uint8_t addr, const uint8_t *payload, size_t len)
PEC over a write transaction: the write address byte, then len .
proto_bool protocore_smbus_write_byte(uint8_t *work, uint8_t addr, uint8_t cmd, uint8_t value)
Write byte: cmd then one data byte.
uint8_t protocore_smbus_addr_byte(uint8_t *work, uint8_t addr, uint8_t rw)
The address byte as it goes on the wire: the 7-bit address shifted .
proto_bool protocore_smbus_send_byte(uint8_t *work, uint8_t addr, uint8_t value)
Send byte: one byte with no command code in front of it.
proto_bool protocore_smbus_receive_byte(uint8_t *work, uint8_t addr, uint8_t *out)
Receive byte: one byte with no command code, from whatever the part .
proto_bool protocore_smbus_begin(uint8_t *work)
Bring up the shared I2C bus for SMBus traffic.
proto_bool protocore_smbus_write_block(uint8_t *work, uint8_t addr, uint8_t cmd, const uint8_t *buf, size_t len)
Block write: cmd, a count byte, then len payload bytes (at most .
void protocore_smbus_set_pec(uint8_t *work, proto_bool on)
Turn the Packet Error Code on or off for every transaction that .
proto_bool protocore_smbus_write_word(uint8_t *work, uint8_t addr, uint8_t cmd, uint16_t value)
Write word: cmd then two data bytes, low byte first.
PROTOCORE_NS SmbusNs Smbus PROTOCORE_UNUSED
Module namespace.
proto_bool protocore_smbus_process_call(uint8_t *work, uint8_t addr, uint8_t cmd, uint16_t value, uint16_t *out)
Process call: write a word to cmd and read a word back in the same .
proto_bool protocore_smbus_read_word(uint8_t *work, uint8_t addr, uint8_t cmd, uint16_t *out)
Read word: cmd, a repeated start, then two data bytes back, low .
proto_bool protocore_smbus_read_block(uint8_t *work, uint8_t addr, uint8_t cmd, uint8_t *out, size_t cap, size_t *len)
Block read: cmd, a repeated start, then a count byte and that many .
uint8_t * protocore_smbus_span(void)
The PROTOCORE_SMBUS_BORROW bytes this module's state lives in.
proto_bool protocore_smbus_pec_enabled(uint8_t *work)
Whether the Packet Error Code is on.
proto_bool protocore_smbus_block_process_call(uint8_t *work, uint8_t addr, uint8_t cmd, const uint8_t *buf, size_t len, uint8_t *out, size_t cap, size_t *out_len)
Block process call: write len bytes to cmd and read a block back in .
proto_bool protocore_smbus_read_byte(uint8_t *work, uint8_t addr, uint8_t cmd, uint8_t *out)
Read byte: cmd, a repeated start, then one data byte back.
proto_bool protocore_smbus_quick(uint8_t *work, uint8_t addr, uint8_t rw)
Quick command: address the part with rw and stop. The direction bit .
uint8_t protocore_smbus_pec_read(uint8_t *work, uint8_t addr, const uint8_t *sent, size_t slen, const uint8_t *got, size_t glen)
PEC over a read transaction, which covers both halves and the .
Dispatch table. Addressed by offset, so the layout is asserted below.
uint8_t(* addr_byte)(uint8_t *, uint8_t, uint8_t)
#define PROTOCORE_BEGIN_DECLS
Give a header's declarations C linkage, so their symbol names carry no parameter types.
_Bool proto_bool
The truth value.
#define PROTOCORE_END_DECLS