ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
board_periph_riic_devices.c File Reference

RIIC bus registry, PI4IOE5V6408 expander, and OV5640 sensor models. More...

Include dependency graph for board_periph_riic_devices.c:

Go to the source code of this file.

Data Structures

struct  pi4ioe_state_t
 One PI4IOE5V6408 I/O expander on the modelled I2C bus. More...
struct  ov5640_state_t
 One OV5640 camera sensor on the SCCB bus. More...

Enumerations

enum  riic_device_const_t : uint32_t {
  k_riic_dev_max = 4U ,
  k_pi4ioe_addr_7b = 0x43U ,
  k_pi4ioe_reg_max = 0x10U ,
  k_pi4ioe_reg_devid = 0x01U ,
  k_pi4ioe_devid_val = 0xA0U
}
 Registry and PI4IOE5V6408 geometry. More...
enum  ov5640_const_t : uint16_t {
  k_ov5640_addr_7b = 0x3CU ,
  k_ov5640_reg_id_hi = 0x300AU ,
  k_ov5640_reg_id_lo = 0x300BU ,
  k_ov5640_reg_format = 0x4300U ,
  k_ov5640_reg_isp_mux = 0x501FU ,
  k_ov5640_reg_test = 0x503DU ,
  k_ov5640_id_hi = 0x56U ,
  k_ov5640_id_lo = 0x40U ,
  k_ov5640_ptr_bytes = 2U
}
 OV5640 SCCB sensor constants used by camera_capture. More...

Functions

static RA8_INTERNAL void internal_riic_device_register (riic_device_t device)
 Register one device in the first free bus slot.
static RA8_INTERNAL void internal_pi4ioe_write (void *ctx, uint8_t byte)
 Accept one controller byte for the PI4IOE5V6408.
static RA8_INTERNAL uint32_t internal_pi4ioe_read (void *ctx, uint8_t *buf, uint32_t max)
 Serve PI4IOE5V6408 register bytes to the controller.
static RA8_INTERNAL void internal_pi4ioe_stop (void *ctx)
 End a PI4IOE5V6408 transfer.
static RA8_INTERNAL void internal_ov5640_write (void *ctx, uint8_t byte)
 Accept pointer and configuration bytes for the OV5640.
static RA8_INTERNAL uint32_t internal_ov5640_read (void *ctx, uint8_t *buf, uint32_t max)
 Serve one verifier-visible OV5640 register byte.
static RA8_INTERNAL void internal_ov5640_stop (void *ctx)
 End an OV5640 SCCB transfer.
RA8_PRIV riic_device_tpriv_riic_device_find (uint8_t addr_7b)
 Find the registered RIIC device answering one 7-bit address.
RA8_PRIV void priv_riic_devices_reset (void)
 Reset and repopulate the board's RIIC device registry.
RA8_PRIV void priv_riic_devices_report (void)
 Report activity observed by the registered board devices.

Variables

static riic_device_t s_riic_dev [k_riic_dev_max]
 Fixed registry and board-device states.
static pi4ioe_state_t s_pi4ioe
static ov5640_state_t s_ov5640

Detailed Description

RIIC bus registry, PI4IOE5V6408 expander, and OV5640 sensor models.

Implements the fixed-capacity device side of the RIIC model. The controller resolves each address through this registry, while the device callbacks retain their own bounded register state and transfer cursors.

Since
0.1.0

Definition in file board_periph_riic_devices.c.

Enumeration Type Documentation

◆ ov5640_const_t

enum ov5640_const_t : uint16_t

OV5640 SCCB sensor constants used by camera_capture.

Enumerator
k_ov5640_addr_7b 

SCCB 7-bit address.

k_ov5640_reg_id_hi 

Chip-ID high-byte register.

k_ov5640_reg_id_lo 

Chip-ID low-byte register.

k_ov5640_reg_format 

DVP output pixel-format register.

k_ov5640_reg_isp_mux 

ISP output format-mux register.

k_ov5640_reg_test 

ISP test-pattern register.

k_ov5640_id_hi 

Chip-ID high byte.

k_ov5640_id_lo 

Chip-ID low byte.

k_ov5640_ptr_bytes 

Big-endian register-pointer byte count.

Definition at line 38 of file board_periph_riic_devices.c.

◆ riic_device_const_t

enum riic_device_const_t : uint32_t

Registry and PI4IOE5V6408 geometry.

Enumerator
k_riic_dev_max 

Device-registry capacity.

k_pi4ioe_addr_7b 

EK-RA8D2 U15 default 7-bit address.

k_pi4ioe_reg_max 

Register-file size modelled (0x00..0x0F).

k_pi4ioe_reg_devid 

Device-id register.

k_pi4ioe_devid_val 

Device-id reset default.

Definition at line 17 of file board_periph_riic_devices.c.

Function Documentation

◆ internal_ov5640_read()

RA8_INTERNAL uint32_t internal_ov5640_read ( void * ctx,
uint8_t * buf,
uint32_t max )
static

Serve one verifier-visible OV5640 register byte.

Returns the fixed 0x5640 identity, a latched configuration byte, or zero for registers outside the deliberately modelled subset.

Parameters
[in,out]ctxSensor state registered with the SCCB callback.
[out]bufDestination receiving the selected register byte.
[in]maxCapacity of buf in bytes.
Returns
Number of bytes written to buf.
Return values
0max is zero; otherwise one byte is returned.
Precondition
ctx identifies the module-owned ov5640_state_t instance.
buf provides at least one writable byte when max is nonzero.
Postcondition
The destination contains the selected register value on success.
Identity-read accounting advances only for 0x300A or 0x300B.
Note
Configuration reads reflect the last accepted write.
Since
0.1.0

Definition at line 217 of file board_periph_riic_devices.c.

References ov5640_state_t::id_reads, k_ov5640_id_hi, k_ov5640_id_lo, k_ov5640_reg_format, k_ov5640_reg_id_hi, k_ov5640_reg_id_lo, k_ov5640_reg_isp_mux, k_ov5640_reg_test, RA8_INTERNAL, ov5640_state_t::reg_format, ov5640_state_t::reg_isp_mux, ov5640_state_t::reg_ptr, and ov5640_state_t::reg_test.

Referenced by priv_riic_devices_reset().

◆ internal_ov5640_stop()

RA8_INTERNAL void internal_ov5640_stop ( void * ctx)
static

End an OV5640 SCCB transfer.

Clears the two-byte pointer-capture count so the next transfer begins with a fresh big-endian register address.

Parameters
[in,out]ctxSensor state registered with the SCCB callback.
Precondition
ctx identifies the module-owned ov5640_state_t instance.
The callback follows a completed or aborted RIIC transfer.
Postcondition
The next two controller bytes form a new register pointer.
Latched configuration values and counters remain unchanged.
Note
The pointer value remains available across a repeated START.
Since
0.1.0

Definition at line 253 of file board_periph_riic_devices.c.

References RA8_INTERNAL.

Referenced by priv_riic_devices_reset().

◆ internal_ov5640_write()

RA8_INTERNAL void internal_ov5640_write ( void * ctx,
uint8_t byte )
static

Accept pointer and configuration bytes for the OV5640.

Captures the first two bytes as a big-endian register pointer and latches payload writes only for the verifier-visible configuration subset.

Parameters
[in,out]ctxSensor state registered with the SCCB callback.
[in]byteRegister-pointer or configuration byte from the controller.
Precondition
ctx identifies the module-owned ov5640_state_t instance.
The callback runs within an active RIIC transfer.
Postcondition
Pointer capture or one supported configuration register is updated.
Unsupported register writes affect only the activity counter.
Note
The model intentionally does not emulate analog camera behavior.
Since
0.1.0

Definition at line 180 of file board_periph_riic_devices.c.

References k_ov5640_ptr_bytes, k_ov5640_reg_format, k_ov5640_reg_isp_mux, k_ov5640_reg_test, ov5640_state_t::ptr_bytes, RA8_INTERNAL, ov5640_state_t::reg_format, ov5640_state_t::reg_isp_mux, ov5640_state_t::reg_ptr, ov5640_state_t::reg_test, and ov5640_state_t::writes.

Referenced by priv_riic_devices_reset().

◆ internal_pi4ioe_read()

RA8_INTERNAL uint32_t internal_pi4ioe_read ( void * ctx,
uint8_t * buf,
uint32_t max )
static

Serve PI4IOE5V6408 register bytes to the controller.

Copies at most the register-file capacity beginning at the active auto-incrementing pointer, wrapping each addressed register independently.

Parameters
[in,out]ctxExpander state registered with the bus callback.
[out]bufDestination receiving consecutive register bytes.
[in]maxCapacity of buf in bytes.
Returns
Number of bytes written to buf.
Return values
0max is zero; otherwise the smaller of max and the register file capacity.
Precondition
ctx identifies the module-owned pi4ioe_state_t instance.
buf provides at least max writable bytes when max is nonzero.
Postcondition
Exactly the returned number of destination bytes is initialized.
Expander register contents remain unchanged.
Note
A later STOP clears only the pointer-capture latch.
Since
0.1.0

Definition at line 136 of file board_periph_riic_devices.c.

References pi4ioe_state_t::file, k_pi4ioe_reg_max, RA8_INTERNAL, and pi4ioe_state_t::reg_ptr.

Referenced by priv_riic_devices_reset().

◆ internal_pi4ioe_stop()

RA8_INTERNAL void internal_pi4ioe_stop ( void * ctx)
static

End a PI4IOE5V6408 transfer.

Clears the pointer-capture latch so the first byte of the next transfer selects a new register.

Parameters
[in,out]ctxExpander state registered with the bus callback.
Precondition
ctx identifies the module-owned pi4ioe_state_t instance.
The callback follows a completed or aborted RIIC transfer.
Postcondition
The next controller byte is interpreted as a register pointer.
Register contents and counters remain unchanged.
Note
The active pointer value itself is retained until overwritten.
Since
0.1.0

Definition at line 162 of file board_periph_riic_devices.c.

References RA8_INTERNAL.

Referenced by priv_riic_devices_reset().

◆ internal_pi4ioe_write()

RA8_INTERNAL void internal_pi4ioe_write ( void * ctx,
uint8_t byte )
static

Accept one controller byte for the PI4IOE5V6408.

Treats the first byte as the register pointer and each following byte as register data, advancing the pointer after every payload byte.

Parameters
[in,out]ctxExpander state registered with the bus callback.
[in]byteRegister-pointer or payload byte from the controller.
Precondition
ctx identifies the module-owned pi4ioe_state_t instance.
The callback runs within an active RIIC transfer.
Postcondition
The pointer latch or one register shadow byte is updated.
No storage outside the expander state is modified.
Note
The register pointer wraps within the modelled 0x10-byte file.
Since
0.1.0

Definition at line 106 of file board_periph_riic_devices.c.

References pi4ioe_state_t::file, k_pi4ioe_reg_max, pi4ioe_state_t::ptr_set, RA8_INTERNAL, pi4ioe_state_t::reg_ptr, and pi4ioe_state_t::writes.

Referenced by priv_riic_devices_reset().

◆ internal_riic_device_register()

RA8_INTERNAL void internal_riic_device_register ( riic_device_t device)
static

Register one device in the first free bus slot.

Copies the supplied callback entry into fixed registry storage and leaves the registry unchanged when every slot is occupied.

Parameters
[in]deviceFully initialized device callback entry.
Precondition
device is marked present and carries callbacks valid for the run.
The call executes on the emulator's single owning thread.
Postcondition
At most one previously free registry slot is occupied.
Device callback context ownership remains with its defining model.
Note
Registry overflow deliberately drops the extra device.
Since
0.1.0

Definition at line 83 of file board_periph_riic_devices.c.

References k_riic_dev_max, RA8_INTERNAL, and s_riic_dev.

Referenced by priv_riic_devices_reset().

◆ priv_riic_device_find()

RA8_PRIV riic_device_t * priv_riic_device_find ( uint8_t addr_7b)

Find the registered RIIC device answering one 7-bit address.

Searches the fixed-capacity board-device registry without changing transfer state or acquiring storage.

Parameters
[in]addr_7bSeven-bit bus address to resolve.
Returns
Pointer to the matching registry entry, or nullptr when unclaimed.
Return values
nullptrNo registered device claims addr_7b; otherwise the returned pointer identifies the matching entry.
Precondition
addr_7b is limited to the seven-bit I2C address domain.
The RIIC device registry has been reset for the current emulator run.
Postcondition
The registry and all device states are unchanged.
Ownership of the returned module-owned entry remains with the model.
Note
The returned pointer stays valid until the next device reset.
Since
0.1.0

Definition at line 258 of file board_periph_riic_devices.c.

References k_riic_dev_max, RA8_PRIV, and s_riic_dev.

Referenced by internal_riic_address_phase(), internal_riic_close_transfer(), and internal_riic_icdrt_write().

◆ priv_riic_devices_report()

RA8_PRIV void priv_riic_devices_report ( void )

Report activity observed by the registered board devices.

Emits one diagnostic line for an active expander or camera model, including accepted writes and OV5640 identity-register reads.

Precondition
The injected emulator diagnostic sink is initialized.
The call executes on the emulator's single owning thread.
Postcondition
Device and registry state are unchanged.
Diagnostic output contains only devices with observed activity.
Note
Sink failures follow the emulator's existing diagnostic policy.
Since
0.1.0

Definition at line 291 of file board_periph_riic_devices.c.

References k_ov5640_addr_7b, k_pi4ioe_addr_7b, priv_emu_io_errf(), RA8_PRIV, s_ov5640, and s_pi4ioe.

Referenced by internal_riic_report().

◆ priv_riic_devices_reset()

RA8_PRIV void priv_riic_devices_reset ( void )

Reset and repopulate the board's RIIC device registry.

Clears all registry and device state, seeds the expander identity register, and installs the PI4IOE5V6408 and OV5640 callback entries.

Precondition
No RIIC device callback is executing during the reset.
The call executes on the emulator's single owning thread.
Postcondition
Only the two board devices occupy registry entries.
Both device models reflect their documented reset values.
Note
The operation uses only fixed-capacity module storage.
Since
0.1.0

Definition at line 268 of file board_periph_riic_devices.c.

References internal_ov5640_read(), internal_ov5640_stop(), internal_ov5640_write(), internal_pi4ioe_read(), internal_pi4ioe_stop(), internal_pi4ioe_write(), internal_riic_device_register(), k_ov5640_addr_7b, k_pi4ioe_addr_7b, k_pi4ioe_devid_val, k_pi4ioe_reg_devid, k_riic_dev_max, RA8_PRIV, s_ov5640, s_pi4ioe, and s_riic_dev.

Referenced by internal_riic_reset().

Variable Documentation

◆ s_ov5640

ov5640_state_t s_ov5640
static

◆ s_pi4ioe

pi4ioe_state_t s_pi4ioe
static

◆ s_riic_dev

riic_device_t s_riic_dev[k_riic_dev_max]
static

Fixed registry and board-device states.

Definition at line 67 of file board_periph_riic_devices.c.

Referenced by internal_riic_device_register(), priv_riic_device_find(), and priv_riic_devices_reset().