Skip to content

Commit

Permalink
[spi_device] Use macro ATOMIC_WAIT_FOR_INTERRUPT on tests
Browse files Browse the repository at this point in the history
Signed-off-by: Douglas Reis <[email protected]>
  • Loading branch information
engdoreis committed Feb 12, 2024
1 parent 77c5cd7 commit d2f315a
Showing 1 changed file with 2 additions and 17 deletions.
19 changes: 2 additions & 17 deletions sw/device/tests/spi_device_tpm_tx_rx_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,21 +136,6 @@ static void ack_spi_tpm_header_irq(dif_spi_device_handle_t *spi_device) {
&spi_device->dev, kDifSpiDeviceIrqTpmHeaderNotEmpty, kDifToggleEnabled));
}

// This routine is needed to make sure that an interrupt does not sneak in
// and jump execution away between the boolean check and the actual invocation
// of wait_for_interrupt.
static void atomic_wait_for_interrupt(void) {
while (true) {
irq_global_ctrl(false);
if (header_interrupt_received) {
break;
}
wait_for_interrupt();
irq_global_ctrl(true);
}
irq_global_ctrl(true);
}

bool test_main(void) {
CHECK_DIF_OK(dif_pinmux_init(
mmio_region_from_addr(TOP_EARLGREY_PINMUX_AON_BASE_ADDR), &pinmux));
Expand Down Expand Up @@ -195,7 +180,7 @@ bool test_main(void) {
LOG_INFO("Iteration %d", i);

// Wait for write interrupt.
atomic_wait_for_interrupt();
ATOMIC_WAIT_FOR_INTERRUPT(header_interrupt_received);

// Check what command we have received. Store it as expected variables
// and compare when the read command is issued.
Expand Down Expand Up @@ -223,7 +208,7 @@ bool test_main(void) {
LOG_INFO("SYNC: Waiting Read");
// Send the written data right back out for reads.
// Wait for read interrupt.
atomic_wait_for_interrupt();
ATOMIC_WAIT_FOR_INTERRUPT(header_interrupt_received);
// Send the written data right back out for reads.
CHECK_DIF_OK(dif_spi_device_tpm_write_data(&spi_device, num_bytes, buf));

Expand Down

0 comments on commit d2f315a

Please sign in to comment.