Code: Select all
void ToggleClock(int count, out port clk)
{
// Doing this part somewhat slowly has little effect on the overall throughput
//Clock idle low
timer t;
uint32_t time;
int i;
int clkState = 0;
const uint32_t clkHighPeriod = 5; // units of 10ns
const uint32_t clkLowPeriod = 50;
t :> time; // get the initial timer value
for(i = 2*count; i; i--) { // send 'count' clock toggles
select {
case t when timerafter(time) :> void: // perform periodic task
clkState = !clkState;
clk <: clkState;
time += (clkState? clkHighPeriod: clkLowPeriod);
break;
}
}
}
(I'm currently trying to improve the sc_sdcard code 4-bit mode to make more use of timed I/O, so it will be less of a CPU hog).