How to gererate a single pulse depending on a state machne in C?

Viewed 151

I want to write a c code to generate a pulse but cant seem to wrap my head around the logic to implement it. I come from a strong Verilog background & know how to do this in verilog(look for a change of state using xor & use that pulse, stretch it over time if needed by registering it multiple times)

How should I do this in C? I want to do something like

while(1)
{
   switch(state)
   case 0: // generate single pulse
   case 1: // dont generate 
   case 2: // dont gererate
   case 3: // generate single pulse
   usleep(1000) // I want a 1ms pulse
}  

state is modified by a code running on FPGA, so it changes depending on some logic.
Cant seem to thing of a way to do that. Some guidance will be appreciated

3 Answers
Related