Skip to content

Commit

Permalink
Update I2C & PLIC tests to use new I2C driver
Browse files Browse the repository at this point in the history
After the I2C driver was updated to match the latest vendored in RTL,
and to make `blocking_write` actually blocking and check for success,
this updates the two relevant tests that interact with the driver so
that they continue testing the same functionality as before.
  • Loading branch information
AlexJones0 committed Oct 24, 2024
1 parent 6e1efae commit a6d1648
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
20 changes: 15 additions & 5 deletions sw/cheri/tests/i2c_tests.hh
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@ int i2c_rpi_hat_id_eeprom_test(I2cPtr i2c) {

// Send two 0x0000 byte addresses and skip the STOP condition.
const uint8_t addr[] = {0, 0};
i2c->blocking_write(RpiHatIdEepromAddr, addr, sizeof(addr), true);
if (!i2c->blocking_write(RpiHatIdEepromAddr, addr, sizeof(addr), true)) {
return ++failures; // If we can't write, then the read will block.
}

// Fill a read buffer with dummy data so that we see changes.
constexpr uint8_t DummyReadVal = 0x3D;
Expand Down Expand Up @@ -247,7 +249,9 @@ int i2c_rpi_hat_imu_whoami_test(I2cPtr i2c) {

// Send the address and skip the STOP condition.
const uint8_t addr[] = {RpiHatWhoAmIRegAddr};
i2c->blocking_write(RpiHatAccelGyroWhoAmIAddr, addr, sizeof(addr), true);
if (!i2c->blocking_write(RpiHatAccelGyroWhoAmIAddr, addr, sizeof(addr), true)) {
return ++failures; // If we can't write, then the read will block.
}

// Read from the `WHO_AM_I` register of the Accelerometer & Gyroscope,
// and check it matches the expected value.
Expand All @@ -257,7 +261,9 @@ int i2c_rpi_hat_imu_whoami_test(I2cPtr i2c) {
}

// Send one 0x0F byte address and skip the STOP condition.
i2c->blocking_write(RpiHatIdMagneticWhoAmIAddr, addr, sizeof(addr), true);
if (!i2c->blocking_write(RpiHatIdMagneticWhoAmIAddr, addr, sizeof(addr), true)) {
return ++failures; // If we can't write, then the read will block.
}

// Read from the `WHO_AM_I` register of the Magnetic Sensor, and check
// it matches the expected value.
Expand Down Expand Up @@ -287,15 +293,19 @@ int i2c_as6212_temperature_sense_test(I2cPtr i2c) {

// Read from the config register, and check the dummy data was modified.
uint8_t addr[] = {As6212ConfigRegAddr};
i2c->blocking_write(As6212Addr, addr, sizeof(addr), false);
if (!i2c->blocking_write(As6212Addr, addr, sizeof(addr), false)) {
return ++failures; // If we can't write, then the read will block.
}
uint8_t data[2] = {0xF0, 0x0F};
if (!i2c->blocking_read(As6212Addr, data, 2U) || data[0] == 0xF0) {
failures++;
}

// Read from the temperature register
addr[0] = As6212TempRegAddr;
i2c->blocking_write(As6212Addr, addr, sizeof(addr), false);
if (!i2c->blocking_write(As6212Addr, addr, sizeof(addr), false)) {
return ++failures; // If we can't write, then the read will block.
}
if (!i2c->blocking_read(As6212Addr, data, 2U)) {
failures++;
}
Expand Down
2 changes: 1 addition & 1 deletion sw/cheri/tests/plic_tests.hh
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ struct PlicTest {
};
static constexpr std::array<i2c_irq, 15> i2cMap = {{
{OpenTitanI2cInterrupt::ReceiveOverflow, true},
{OpenTitanI2cInterrupt::Nak, true},
{OpenTitanI2cInterrupt::SclInterference, true},
{OpenTitanI2cInterrupt::SdaInterference, true},
{OpenTitanI2cInterrupt::StretchTimeout, true},
Expand All @@ -97,6 +96,7 @@ struct PlicTest {
{OpenTitanI2cInterrupt::UnexpectedStop, true},
{OpenTitanI2cInterrupt::HostTimeout, true},

{OpenTitanI2cInterrupt::ControllerHalt, false},
{OpenTitanI2cInterrupt::TransmitStretch, false},
{OpenTitanI2cInterrupt::AcquiredFull, false},
{OpenTitanI2cInterrupt::TransmitThreshold, false},
Expand Down

0 comments on commit a6d1648

Please sign in to comment.