Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion Libraries/PeriphDrivers/Source/SYS/mxc_delay.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,19 @@ int MXC_Delay(uint32_t us)
CSR_SetPCER(1); // Enable counting of cycles
CSR_SetPCMR(3); // Turn on counter

// define a ticks num for a delay less than 1 us but long enough to prevent the PCCR
uint32_t num_ticks_half_us = MXC_SYS_RiscVClockRate() / 1000000 / 3;
Comment thread
lorne-maxim marked this conversation as resolved.
Comment thread
lorne-maxim marked this conversation as resolved.
volatile uint32_t counter;

while (CSR_GetPCCR() < ticks) {
// Wait for counter to reach the tick count.
// Wait about 1 us
// and re-check if the counter reaches the tick count or not.
// Need this waiting to prevent CPU bothers PCCR too much
// to avoid PCCR hardware cannot maintain the correct timing.
counter = 0;
while (counter < num_ticks_half_us) {
counter++;
}
}
return E_NO_ERROR;
}
Expand Down