Skip to content

[RFC] Use Opentitan DIF API #583

@engdoreis

Description

@engdoreis

Like the OpenTitan DIFs, the Mocha HAL drivers are not production-ready; they are intended strictly for testing and design verification.

Therefore, to avoid reinventing the wheel and prolonging discussions on PRs regarding the "best" interface, I suggest we copy the DIF functions from OpenTitan for all OpenTitan IPs and replace their MMIO calls with the auto-generated Mocha structs.

This will also reduce the effort of porting the OpenTitan top level tests to Mocha.

This is an example of a porting of a opentitan DIF function.

dif_result_t dif_spi_host_output_set_enabled(const dif_spi_host_t *spi_host,
                                             bool enabled) {
  if (spi_host == NULL) {
    return kDifBadArg;
  }

  uint32_t reg =
      mmio_region_read32(spi_host->base_addr, SPI_HOST_CONTROL_REG_OFFSET);
  mmio_region_write32(
      spi_host->base_addr, SPI_HOST_CONTROL_REG_OFFSET,
      bitfield_bit32_write(reg, SPI_HOST_CONTROL_OUTPUT_EN_BIT, enabled));

  return kDifOk;
}

Ported to Mocha:

mocha_result spi_host_output_set_enabled(spi_host_t spi_host, bool enabled) {
    spi_host_control reg = VOLATILE_READ(spi_host->control);
    reg.output_en = enabled;
    VOLATILE_WRITE(spi_host->control, reg);
    return kMochaOk;
}

This would make the review process easier. The reviewer would not need to question whether the API makes sense (since it's already well-tested), but would instead focus on ensuring that the implementation is correct for Mocha.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions