altos/lpc: Get 100Hz timer running
authorKeith Packard <keithp@keithp.com>
Thu, 18 Apr 2013 21:15:52 +0000 (16:15 -0500)
committerKeith Packard <keithp@keithp.com>
Fri, 17 May 2013 10:50:07 +0000 (03:50 -0700)
Use systick, which is built into the ARM core

Signed-off-by: Keith Packard <keithp@keithp.com>
src/lpc/ao_led_lpc.c
src/lpc/ao_timer_lpc.c
src/lpcxpresso/ao_demo.c

index 098dad6b8f58319126b61d9fbbbd148e5bbf0faa..7bef51ba25cdce0e07b05b0bae002395fc940d66 100644 (file)
@@ -22,13 +22,13 @@ __pdata uint16_t ao_led_enable;
 void
 ao_led_on(uint16_t colors)
 {
-       lpc_gpio.pin[LED_PORT] = 0xffffffff;
+       lpc_gpio.pin[LED_PORT] |= colors;
 }
 
 void
 ao_led_off(uint16_t colors)
 {
-       lpc_gpio.pin[LED_PORT] = 0;
+       lpc_gpio.pin[LED_PORT] &= ~colors;
 }
 
 void
@@ -44,6 +44,7 @@ ao_led_set(uint16_t colors)
 void
 ao_led_toggle(uint16_t colors)
 {
+       lpc_gpio.pin[LED_PORT] ^= colors;
 }
 
 void
index aa796acf9b0da1f2a7c84486a44e4ff8cfffd6bc..51e82525383fb381c7ba795f82197d338216b911 100644 (file)
@@ -61,7 +61,7 @@ ao_timer_set_adc_interval(uint8_t interval)
 }
 #endif
 
-#define SYSTICK_RELOAD ((AO_LPC_CLKOUT / 2) / 100 - 1)
+#define SYSTICK_RELOAD ((AO_LPC_SYSCLK / 2) / 100 - 1)
 
 /* Initialize our 100Hz clock */
 void
index bb8402f7d0c4d26dde43262b80b51e6ba4268c9d..56fef70635193840d59b0fa4f860b2a739d42071 100644 (file)
 
 #include "ao.h"
 
+struct ao_task demo_task;
+
+static void demo(void) {
+       for (;;) {
+               ao_delay(100);
+               ao_led_toggle(AO_LED_RED);
+       }
+}
+
 int
 main(void)
 {
@@ -24,13 +33,22 @@ main(void)
        ao_led_init(LEDS_AVAILABLE);
        ao_led_on(AO_LED_RED);
        ao_clock_init();
+       ao_timer_init();
+       
+       ao_task_init();
+
+       ao_add_task(&demo_task, demo, "demo");
+
+       ao_start_scheduler();
 
        for (;;) {
                ao_led_off(AO_LED_RED);
-               for (i = 0; i < 100000; i++)
-                       ao_arch_nop();
+               for (;;)
+                       if (ao_tick_count & 1)
+                               break;
                ao_led_on(AO_LED_RED);
-               for (i = 0; i < 100000; i++)
-                       ao_arch_nop();
+               for (;;)
+                       if (!(ao_tick_count & 1))
+                               break;
        }
 }