altos: Add ao_task_minimize_latency to reduce IRQ delays
authorKeith Packard <keithp@keithp.com>
Sat, 1 Dec 2012 00:05:19 +0000 (16:05 -0800)
committerKeith Packard <keithp@keithp.com>
Sat, 1 Dec 2012 00:05:19 +0000 (16:05 -0800)
When set, this causes the task switching code to avoid blocking IRQs
while looking for an idle task as that can increase IRQ latencies
enough to drop characters at 115200 baud on the cc1111. Note that this
*also* eliminates the ability to use low power modes as we cannot know
at any point whether some interrupt has come along and woken a task.

Has no effect when using task queues as those require IRQs to be
blocked while looking at the queue. Shouldn't be a problem there
though as the check for no running tasks is very cheap.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/core/ao_task.c
src/core/ao_task.h

index 0411fbdd425921c42f26b68d5116f932bfc18d96..9cb074b5220a2c6279353d1b4ab5371be2dd5385 100644 (file)
@@ -305,6 +305,8 @@ ao_add_task(__xdata struct ao_task * task, void (*start)(void), __code char *nam
                );
 }
 
+__data uint8_t ao_task_minimize_latency;
+
 /* Task switching function. This must not use any stack variables */
 void
 ao_yield(void) ao_arch_naked_define
@@ -331,7 +333,12 @@ ao_yield(void) ao_arch_naked_define
        }
 
        ao_arch_isr_stack();
-       ao_arch_block_interrupts();
+#if !HAS_TASK_QUEUE
+       if (ao_task_minimize_latency)
+               ao_arch_release_interrupts();
+       else
+#endif
+               ao_arch_block_interrupts();
 
 #if AO_CHECK_STACK
        in_yield = 1;
@@ -374,7 +381,7 @@ ao_yield(void) ao_arch_naked_define
                                break;
 
                        /* Wait for interrupts when there's nothing ready */
-                       if (ao_cur_task_index == ao_last_task_index)
+                       if (ao_cur_task_index == ao_last_task_index && !ao_task_minimize_latency)
                                ao_arch_wait_interrupt();
                }
        }
index 049f69a7c2fb121d2dbdffd2564d7bb8f989fe4e..50bfb220f081571572bbaab82395c1d0e29b1813 100644 (file)
@@ -47,6 +47,7 @@ struct ao_task {
 extern __xdata struct ao_task * __xdata ao_tasks[AO_NUM_TASKS];
 extern __data uint8_t ao_num_tasks;
 extern __xdata struct ao_task *__data ao_cur_task;
+extern __data uint8_t ao_task_minimize_latency;        /* Reduce IRQ latency */
 
 /*
  ao_task.c