diff options
| author | Keith Packard <keithp@keithp.com> | 2009-04-14 10:02:19 -0700 | 
|---|---|---|
| committer | Keith Packard <keithp@keithp.com> | 2009-04-14 10:02:19 -0700 | 
| commit | fb63262699d3a6fbf347d24efda8b01f75b7d0d3 (patch) | |
| tree | 16909e9dee01b2939dd66ff1b8e80a70c2aace0f /ao_timer.c | |
| parent | 7e4abf3a40c39d0ce4f466281bef9a464df85dd4 (diff) | |
Add comments, clean up white space, etc.
Various clean ups now that the basic code appears to work.
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'ao_timer.c')
| -rw-r--r-- | ao_timer.c | 46 | 
1 files changed, 22 insertions, 24 deletions
| @@ -17,32 +17,38 @@  #include "ao.h" -volatile __data uint16_t ao_time; +static volatile __data uint16_t ao_tick_count; -void ao_timer_isr(void) interrupt 9 +uint16_t ao_time(void)  { -	++ao_time; -	ao_adc_poll(); -	ao_wakeup(DATA_TO_XDATA(&ao_time)); +	volatile bit ea_save; +	__data uint16_t ret; +	 +	ea_save = EA; +	ret = ao_tick_count; +	EA = ea_save; +	return ret;  } -uint16_t ao_time_atomic(void) +void +ao_delay(uint16_t ticks)  { -	uint8_t ret1; -	uint16_t ret2; -	 -	for (;;) { -		ret1 = ao_time >> 8; -		ret2 = ao_time; -		if (ret1 == ((__xdata uint8_t *)(&ret2))[1]) -			break; -	} -	return ret2; +	uint16_t until = ao_time() + ticks; + +	while ((int16_t) (until - ao_time()) > 0) +		ao_sleep(DATA_TO_XDATA(&ao_tick_count));  }  #define T1_CLOCK_DIVISOR	8	/* 24e6/8 = 3e6 */  #define T1_SAMPLE_TIME		30000	/* 3e6/30000 = 100 */ +void ao_timer_isr(void) interrupt 9 +{ +	++ao_tick_count; +	ao_adc_poll(); +	ao_wakeup(DATA_TO_XDATA(&ao_tick_count)); +} +  void  ao_timer_init(void)  { @@ -71,11 +77,3 @@ ao_timer_init(void)  	T1CTL = T1CTL_MODE_MODULO | T1CTL_DIV_8;  } -void -ao_delay(uint16_t ticks) -{ -	uint16_t until = ao_time_atomic() + ticks; - -	while ((int16_t) (until - ao_time_atomic()) > 0) -		ao_sleep(DATA_TO_XDATA(&ao_time)); -} | 
