s32int sw_sleep(u32 seconds) { u64 current_ticks = 0,end_value = (seconds*10); /* we have a 1mhz clock. The current period of interrupts is one every * 100ms. We need to wait till we get seconds*10 interrupts. */ current_ticks = get_current_ticks(); while((get_current_ticks() - current_ticks) < end_value); return(0); }
s32int sw_usleep(u32 seconds) { u64 current_ticks = 0,end_value = seconds; /* we have a 1mhz clock. The current period of interrupts is one every * 100ms. We need to wait till we get seconds interrupts. In effect, we * do not do microseconds sleep, but milliseconds sleep */ current_ticks = get_current_ticks(); while((get_current_ticks() - current_ticks) < end_value); return(0); }
//------------------------------------------------------------------ // this function is called when the GPIO interrupt on P2 happens // used temporarily since there is no more P1 pins available. //------------------------------------------------------------------ void capture_p2_timing(UINT8 pin, CAPTURE_CCB* ccb, UINT16* time) { register UINT16 tick2; switch (ccb->state) { case CAP_LOW: // pulse is currently low, but got intr because it rises; ccb->tick1 = get_current_ticks(); set_p2_falling_edge(pin); ccb->state = CAP_HIGH; break; case CAP_HIGH: // pulse is currently high but got intr because it falls. // capture the timing now, and set the intr edge to raising edge. tick2 = get_current_ticks(); if (tick2 > ccb->tick1) { *time = tick2 - ccb->tick1; } else { *time = TMR_A_PERIOD - ccb->tick1 + tick2; } set_p2_rising_edge(pin); ccb->state = CAP_LOW; break; default: break; } }