Skip to content

[I2C, hal, SW] Restructured and refactored the functions#535

Open
KinzaQamar wants to merge 4 commits into
lowRISC:mainfrom
KinzaQamar:i2c_sw_modif
Open

[I2C, hal, SW] Restructured and refactored the functions#535
KinzaQamar wants to merge 4 commits into
lowRISC:mainfrom
KinzaQamar:i2c_sw_modif

Conversation

@KinzaQamar
Copy link
Copy Markdown
Contributor

@KinzaQamar KinzaQamar commented May 7, 2026

Taking the transfer checking part out from the i2c_read_byte() and i2c_write_byte() functions. It is needed when you want to controller wants to read / write multiple bytes.

Merge #545 first as a dependency on this PR

@KinzaQamar KinzaQamar marked this pull request as draft May 7, 2026 20:26
@KinzaQamar KinzaQamar force-pushed the i2c_sw_modif branch 8 times, most recently from c431f00 to a0269e1 Compare May 8, 2026 14:49
@KinzaQamar KinzaQamar marked this pull request as ready for review May 8, 2026 15:38
Comment thread sw/device/examples/i2c.c Outdated
Comment thread sw/device/lib/hal/i2c.c Outdated
@KinzaQamar KinzaQamar marked this pull request as draft May 11, 2026 19:33
@KinzaQamar KinzaQamar force-pushed the i2c_sw_modif branch 8 times, most recently from 49e9862 to ab7f1dc Compare May 12, 2026 12:20
@KinzaQamar KinzaQamar marked this pull request as ready for review May 12, 2026 12:20
Comment thread sw/device/lib/hal/i2c.c Outdated
Comment thread sw/device/lib/hal/i2c.c Outdated
Comment thread sw/device/lib/hal/i2c.c Outdated
@KinzaQamar KinzaQamar force-pushed the i2c_sw_modif branch 3 times, most recently from 79c9fa4 to bb82b9a Compare May 13, 2026 15:08
Taking the transfer checking part out from the i2c_read_byte()
and i2c_write_byte() functions. It is needed when you want to
controller wants to read / write multiple bytes.

Signed-off-by: Kinza Qamar <kqzaman@lowrisc.org>
This is suggested in programmer's guide.

As a precautionary step, reset the FMT fifo before sending any transfer

Signed-off-by: Kinza Qamar <kqzaman@lowrisc.org>
Signed-off-by: Kinza Qamar <kqzaman@lowrisc.org>
@KinzaQamar
Copy link
Copy Markdown
Contributor Author

KinzaQamar commented May 13, 2026

Tested examples/i2c.c on an FPGA server:

image

Comment thread sw/device/lib/hal/i2c.c
if (i == (num_wr_bytes - 1u)) {
fdata_reg.stop = 1u;
}
VOLATILE_WRITE(i2c->fdata, fdata_reg);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should check that the fifo is not full on every iteration, otherwise it would overflow when num_wr_bytes is large.

Copy link
Copy Markdown
Contributor Author

@KinzaQamar KinzaQamar May 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to be UVM agent receiving these bytes. It is capable of receiving any number of bytes.

I was thinking about checking FMTFULL before sending a transfer but since we always write 1 to fmtrst (which is going to reset the FMT FIFO), this is not needed. About checking RXFULL, this should be a test specific thing.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The UVM agent may be fast, but the i2c block itself might not be. If the processor writes data into the FMT FIFO faster than the I^2C hardware can transmit it, then all it takes is a sufficiently large data transfer for data to be lost when the processor eventually writes to an already-full FMT FIFO.

Comment thread sw/device/lib/hal/i2c.c Outdated
Comment thread sw/device/lib/hal/i2c.c Outdated
Signed-off-by: Kinza Qamar <kqzaman@lowrisc.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants