Exemple #1
0
unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout) {
	unsigned long long int _timeout, now_time, width = 0L;

	if(pin >= PINS || PIN86[pin].gpN == NOUSED) return 0x00;

	_timeout = ((unsigned long long int)timeout)*vx86_CpuCLK() + timer_GetClocks64();
	while(digitalRead(pin) == state)
		if(timer_GetClocks64() >= _timeout)
			return 0;
	while(digitalRead(pin) != state)
		if(timer_GetClocks64() >= _timeout)
			return 0;
	now_time = timer_GetClocks64();
	while(digitalRead(pin) == state)
		if(timer_GetClocks64() >= _timeout)
			return 0;
	width = timer_GetClocks64() - now_time;
	width = (unsigned long long int)(width * (1.0/vx86_CpuCLK()));

	return ((unsigned long)width); // unit is micro second
}
Exemple #2
0
// For 86Duino IDE, only use micros() after calling init()
unsigned long micros() {
	return (unsigned long) (timer_GetClocks64()/CLOCKS_PER_MICROSEC);
}