diff options
| author | Keith Packard <keithp@keithp.com> | 2015-02-13 23:51:10 -0800 | 
|---|---|---|
| committer | Keith Packard <keithp@keithp.com> | 2015-02-13 23:51:10 -0800 | 
| commit | f4c812bef76a2cd95f675cb27ea89059561ceec7 (patch) | |
| tree | 9244ec29ee751a3384f7a0249714d9109934df7c /src/kernel | |
| parent | 1445725b983134d5a967dee88ef997bf15d4a422 (diff) | |
altos: Replace ao_alarm/ao_clear_alarm with ao_sleep_for
Having arbitrary alarms firing in the middle of complicated device
logic makes no sense at all. Therefore only correct use of ao_alarm
and ao_clear_alarm was around a specific ao_sleep call, with correct
recovery in case the alarm fires.
This patch replaces all uses of ao_alarm/ao_sleep/ao_clear_alarm with
ao_sleep_for, a new function which takes the alarm timeout directly.
A few cases which weren't simply calling ao_sleep have been reworked
to pass the timeout value down to the place where sleep *is* being
called, and having that code deal with the return correctly.
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'src/kernel')
| -rw-r--r-- | src/kernel/ao_packet.h | 2 | ||||
| -rw-r--r-- | src/kernel/ao_pyro.c | 4 | ||||
| -rw-r--r-- | src/kernel/ao_serial.h | 8 | ||||
| -rw-r--r-- | src/kernel/ao_task.c | 20 | ||||
| -rw-r--r-- | src/kernel/ao_task.h | 10 | ||||
| -rw-r--r-- | src/kernel/ao_telemetry.c | 4 | 
6 files changed, 32 insertions, 16 deletions
| diff --git a/src/kernel/ao_packet.h b/src/kernel/ao_packet.h index b8426cf9..136609c3 100644 --- a/src/kernel/ao_packet.h +++ b/src/kernel/ao_packet.h @@ -54,7 +54,7 @@ void  ao_packet_send(void);  uint8_t -ao_packet_recv(void); +ao_packet_recv(uint16_t timeout);  void  ao_packet_flush(void); diff --git a/src/kernel/ao_pyro.c b/src/kernel/ao_pyro.c index 3044d565..43e73de4 100644 --- a/src/kernel/ao_pyro.c +++ b/src/kernel/ao_pyro.c @@ -375,9 +375,7 @@ ao_pyro(void)  		ao_sleep(&ao_flight_state);  	for (;;) { -		ao_alarm(AO_MS_TO_TICKS(100)); -		ao_sleep(&ao_pyro_wakeup); -		ao_clear_alarm(); +		ao_sleep_for(&ao_pyro_wakeup, AO_MS_TO_TICKS(100));  		if (ao_flight_state >= ao_flight_landed)  			break;  		any_waiting = ao_pyro_check(); diff --git a/src/kernel/ao_serial.h b/src/kernel/ao_serial.h index dbc9f8e4..e21643ac 100644 --- a/src/kernel/ao_serial.h +++ b/src/kernel/ao_serial.h @@ -35,7 +35,7 @@ int  _ao_serial0_pollchar(void);  uint8_t -_ao_serial0_sleep(void); +_ao_serial0_sleep_for(uint16_t timeout);  void  ao_serial0_putchar(char c); @@ -58,7 +58,7 @@ int  _ao_serial1_pollchar(void);  uint8_t -_ao_serial1_sleep(void); +_ao_serial1_sleep_for(uint16_t timeout);  void  ao_serial1_putchar(char c); @@ -81,7 +81,7 @@ int  _ao_serial2_pollchar(void);  uint8_t -_ao_serial2_sleep(void); +_ao_serial2_sleep_for(uint16_t timeout);  void  ao_serial2_putchar(char c); @@ -104,7 +104,7 @@ int  _ao_serial3_pollchar(void);  uint8_t -_ao_serial3_sleep(void); +_ao_serial3_sleep_for(uint16_t timeout);  void  ao_serial3_putchar(char c); diff --git a/src/kernel/ao_task.c b/src/kernel/ao_task.c index bafb4943..1ecdd7dd 100644 --- a/src/kernel/ao_task.c +++ b/src/kernel/ao_task.c @@ -450,7 +450,7 @@ ao_wakeup(__xdata void *wchan) __reentrant  	ao_check_stack();  } -void +static void  ao_alarm(uint16_t delay)  {  #if HAS_TASK_QUEUE @@ -468,7 +468,7 @@ ao_alarm(uint16_t delay)  #endif  } -void +static void  ao_clear_alarm(void)  {  #if HAS_TASK_QUEUE @@ -483,14 +483,24 @@ ao_clear_alarm(void)  #endif  } +uint8_t +ao_sleep_for(__xdata void *wchan, uint16_t timeout) +{ +	uint8_t	ret; +	if (timeout) +		ao_alarm(timeout); +	ret = ao_sleep(wchan); +	if (timeout) +		ao_clear_alarm(); +	return ret; +} +  static __xdata uint8_t ao_forever;  void  ao_delay(uint16_t ticks)  { -	ao_alarm(ticks); -	ao_sleep(&ao_forever); -	ao_clear_alarm(); +	ao_sleep_for(&ao_forever, ticks);  }  void diff --git a/src/kernel/ao_task.h b/src/kernel/ao_task.h index 9c56b480..c6bec0e3 100644 --- a/src/kernel/ao_task.h +++ b/src/kernel/ao_task.h @@ -68,10 +68,19 @@ extern __data uint8_t ao_task_minimize_latency;	/* Reduce IRQ latency */  uint8_t  ao_sleep(__xdata void *wchan); +/* Suspend the current task until wchan is awoken or the timeout + * expires. returns: + *  0 on normal wake + *  1 on alarm + */ +uint8_t +ao_sleep_for(__xdata void *wchan, uint16_t timeout); +  /* Wake all tasks sleeping on wchan */  void  ao_wakeup(__xdata void *wchan) __reentrant; +#if 0  /* set an alarm to go off in 'delay' ticks */  void  ao_alarm(uint16_t delay); @@ -79,6 +88,7 @@ ao_alarm(uint16_t delay);  /* Clear any pending alarm */  void  ao_clear_alarm(void); +#endif  /* Yield the processor to another task */  void diff --git a/src/kernel/ao_telemetry.c b/src/kernel/ao_telemetry.c index e2197f7a..854ac898 100644 --- a/src/kernel/ao_telemetry.c +++ b/src/kernel/ao_telemetry.c @@ -486,9 +486,7 @@ ao_telemetry(void)  #endif /* HAS_APRS */  			delay = time - ao_time();  			if (delay > 0) { -				ao_alarm(delay); -				ao_sleep(&telemetry); -				ao_clear_alarm(); +				ao_sleep_for(&telemetry, delay);  			}  		}  	} | 
