altos: Call ao_task_init before initializing any drivers
authorKeith Packard <keithp@keithp.com>
Sun, 24 Mar 2013 22:14:12 +0000 (15:14 -0700)
committerKeith Packard <keithp@keithp.com>
Wed, 8 May 2013 03:07:52 +0000 (20:07 -0700)
When using task queues, the sleep queues must be initialized before
any invocation of ao_wakeup or the OS will crash. Just make sure
ao_task_init is always invoked early in the task process to get that done.

Signed-off-by: Keith Packard <keithp@keithp.com>
21 files changed:
src/avr-demo/ao_demo.c
src/product/ao_teledongle.c
src/product/ao_telelaunch.c
src/product/ao_telemetrum.c
src/product/ao_telemini.c
src/product/ao_telenano.c
src/product/ao_telepyro.c
src/product/ao_telescience.c
src/product/ao_teleterra.c
src/product/ao_teleterra_0_2.c
src/product/ao_test.c
src/product/ao_tidongle.c
src/spiradio-v0.1/ao_spiradio.c
src/stm-demo/ao_demo.c
src/stm-flash/ao_stm_flash.c [new file with mode: 0644]
src/teleballoon-v1.1/ao_teleballoon.c
src/telebt-v1.0/ao_telebt.c
src/telefire-v0.1/ao_telefire.c
src/telelco-v0.1/ao_telelco.c
src/telescience-v0.2/ao_telescience.c
src/teleshield-v0.1/ao_teleshield.c

index 756dd0d4a506550b3c881d7c8b154a26ef5d0b59..e35babb3decc243a5ecb67640596e9837b91eac0 100644 (file)
@@ -34,6 +34,8 @@ main(void)
 {
        ao_clock_init();
 
+       ao_task_init();
+
        ao_serial_init();
 
        ao_led_init(LEDS_AVAILABLE);
index 25ebe73ea71b513732f0d9d789492bb877f3c60f..8bfd8b845e73052080a682e739a64153e2e32a27 100644 (file)
@@ -26,6 +26,8 @@ main(void)
        /* Turn on the LED until the system is stable */
        ao_led_init(LEDS_AVAILABLE);
        ao_led_on(AO_LED_RED);
+       ao_task_init();
+
        ao_timer_init();
        ao_cmd_init();
        ao_usb_init();
index b6e4bfc130c2b7243deb39e295e227618d1aa536..dde66090ddfca6d9b902768a82e3b86366b67dcd 100644 (file)
@@ -27,6 +27,8 @@ main(void)
        ao_led_init(LEDS_AVAILABLE);
        ao_led_on(AO_LED_RED);
 
+       ao_task_init();
+
        ao_timer_init();
        ao_adc_init();
        ao_beep_init();
index ea77f5afe83e55c5a5808fe50cb023ea194f48f2..221498d6aa19305cfb697d3699198d042590c56e 100644 (file)
@@ -42,6 +42,8 @@ main(void)
                while (P1_3 == 0)
                        ;
        }
+       ao_task_init();
+
        ao_timer_init();
        ao_adc_init();
        ao_beep_init();
index 21551ee902b2c59359d3c44441ca0ad653328712..a0d8e18af08c4baf34d71ac98710b4f09bdd403d 100644 (file)
@@ -46,6 +46,8 @@ main(void)
                        ;
        }
 
+       ao_task_init();
+
        ao_timer_init();
        ao_adc_init();
        ao_cmd_init();
index d91983d08c3ef70165d41db8d892327a2bdc2d1b..77750efda72f16273863bcf52f8ca148bb03da16 100644 (file)
@@ -28,6 +28,8 @@ main(void)
        ao_led_init(LEDS_AVAILABLE);
        ao_led_on(AO_LED_RED);
 
+       ao_task_init();
+
        ao_timer_init();
        ao_adc_init();
        ao_cmd_init();
index 79454fb7d75bcfa001549972db987af33bbea647..6f09be64e9aa7daa1094f5cf0476437a7f6efc87 100644 (file)
@@ -25,6 +25,8 @@ main(void)
        PORTE |= (1 << 6);
        DDRE |= (1 << 6);
 
+       ao_task_init();
+
        ao_avr_stdio_init();
        ao_timer_init();
        ao_cmd_init();
index d448d31854d888212378febdfa1c43d359552666..2888c2668df1f2fc198674df0b68b944f4980f8f 100644 (file)
@@ -28,6 +28,8 @@ main(void)
        PORTE |= (1 << 6);
        DDRE |= (1 << 6);
 
+       ao_task_init();
+
        ao_avr_stdio_init();
        ao_timer_init();
        ao_cmd_init();
index d696b914e88c845a70d1789424b7e2ec21553281..e739ae0b7af5948e4e46aef501912fc7a7fc617b 100644 (file)
@@ -26,6 +26,8 @@ main(void)
        /* Turn on the red LED until the system is stable */
        ao_led_init(AO_LED_RED|AO_LED_GREEN);
        ao_led_on(AO_LED_RED);
+       ao_task_init();
+
        ao_timer_init();
        ao_beep_init();
        ao_cmd_init();
index 68f0259646e478f87af0116ef6b63134ef977e62..4f7530f7b3a61b957531a067c9b85a043f6fb2d6 100644 (file)
@@ -23,6 +23,8 @@ main(void)
 {
        ao_clock_init();
 
+       ao_task_init();
+
        ao_timer_init();
        ao_beep_init();
        ao_cmd_init();
index 14c2eb75c41e2656996673a0cb29d4d4d4973c0f..273a73b51421c4b1f21325095bf9085b1f6e0214 100644 (file)
@@ -102,6 +102,8 @@ main(void)
 {
        ao_clock_init();
 
+       ao_task_init();
+
 //     ao_add_task(&blink_0_task, blink_0);
 //     ao_add_task(&blink_1_task, blink_1);
 //     ao_add_task(&wakeup_task, wakeup);
index cba0b12249a44757ea674d7500cd6e56785f1db8..b1a96bdd1cfcf3acd5c357302135a7782a1c1cdb 100644 (file)
@@ -27,6 +27,9 @@ main(void)
        /* Turn on the LED until the system is stable */
        ao_led_init(AO_LED_RED);
        ao_led_on(AO_LED_RED);
+
+       ao_task_init();
+
        ao_timer_init();
        ao_cmd_init();
        ao_usb_init();
index d3647cc78e373dc62f97e1a9c32de2ec6426fc23..de9ea7068aeed5c076abf6a479ac6367e4cf6145 100644 (file)
@@ -25,6 +25,8 @@ main(void)
 
        ao_led_init(LEDS_AVAILABLE);
 
+       ao_task_init();
+
        ao_serial_init();
        ao_timer_init();
        ao_cmd_init();
index b82cb73512711942778b36b4121c919ca033e676..9ee0be03098ff683ae27dde7afa6a207a12f9973 100644 (file)
@@ -183,6 +183,8 @@ main(void)
 {
        ao_clock_init();
        
+       ao_task_init();
+
        ao_serial_init();
        ao_timer_init();
        ao_dma_init();
diff --git a/src/stm-flash/ao_stm_flash.c b/src/stm-flash/ao_stm_flash.c
new file mode 100644 (file)
index 0000000..df466d8
--- /dev/null
@@ -0,0 +1,137 @@
+/*
+ * Copyright © 2011 Keith Packard <keithp@keithp.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+#include "ao.h"
+#include <ao_exti.h>
+#include <ao_boot.h>
+#include <ao_flash_stm.h>
+
+void
+ao_panic(uint8_t reason)
+{
+       for (;;);
+}
+
+void
+ao_application(void)
+{
+       ao_boot_reboot(AO_BOOT_APPLICATION_BASE);
+}
+
+static uint32_t
+ao_cmd_hex32(void)
+{
+       __pdata uint8_t r = ao_cmd_lex_error;
+       int8_t  n;
+       uint32_t v = 0;
+
+       ao_cmd_white();
+       for(;;) {
+               n = ao_cmd_hexchar(ao_cmd_lex_c);
+               if (n < 0)
+                       break;
+               v = (v << 4) | n;
+               r = ao_cmd_success;
+               ao_cmd_lex();
+       }
+       if (r != ao_cmd_success)
+               ao_cmd_status = r;
+       return v;
+}
+
+void
+ao_block_erase(void)
+{
+       uint32_t        addr = ao_cmd_hex32();
+       uint32_t        *p = (uint32_t *) addr;
+
+       ao_flash_erase_page(p);
+}
+
+void
+ao_block_write(void)
+{
+       uint32_t        addr = ao_cmd_hex32();
+       uint32_t        *p = (uint32_t *) addr;
+       union {
+               uint8_t         data8[256];
+               uint32_t        data32[64];
+       } u;
+       uint16_t        i;
+
+       if (addr < 0x08002000 || 0x08200000 <= addr) {
+               puts("Invalid address");
+               return;
+       }
+       for (i = 0; i < 256; i++)
+               u.data8[i] = i;
+       ao_flash_page(p, u.data32);
+}
+
+static void
+puthex(uint8_t c)
+{
+       c &= 0xf;
+       if (c < 10)
+               c += '0';
+       else
+               c += 'a' - 10;
+       putchar (c);
+}
+
+void
+ao_block_read(void)
+{
+       uint32_t        addr = ao_cmd_hex32();
+       uint8_t         *p = (uint8_t *) addr;
+       uint16_t        i;
+       uint8_t         c;
+
+       for (i = 0; i < 256; i++) {
+               c = *p++;
+               puthex(c);
+               puthex(c>>4);
+               if ((i & 0xf) == 0xf)
+                       putchar('\n');
+       }
+}
+
+__code struct ao_cmds ao_flash_cmds[] = {
+       { ao_application, "a\0Switch to application" },
+       { ao_block_erase, "e <addr>\0Erase block." },
+       { ao_block_write, "W <addr>\0Write block. 256 binary bytes follow newline" },
+       { ao_block_read, "R <addr>\0Read block. Returns 256 bytes" },
+       { 0, NULL },
+};
+
+int
+main(void)
+{
+       ao_clock_init();
+
+       ao_task_init();
+
+       ao_timer_init();
+//     ao_dma_init();
+       ao_cmd_init();
+//     ao_exti_init();
+       ao_usb_init();
+
+       ao_cmd_register(&ao_flash_cmds[0]);
+       ao_start_scheduler();
+       return 0;
+}
index c8bf7760f89741198753c5bd857b9323b698a9e0..867e98ab2fe26f9c23400d802b58de926e6be8de 100644 (file)
@@ -52,6 +52,8 @@ main(void)
                while (P1_3 == 0)
                        ;
        }
+       ao_task_init();
+
        ao_timer_init();
        ao_adc_init();
        ao_beep_init();
index 4a50a9d43b750deb6c4805c8930ea56131382f21..935cde7d173b19f12b27095ff419802726939d04 100644 (file)
@@ -25,6 +25,9 @@ main(void)
        /* Turn on the LED until the system is stable */
        ao_led_init(LEDS_AVAILABLE);
        ao_led_on(AO_LED_RED);
+
+       ao_task_init();
+
        ao_timer_init();
        ao_cmd_init();
        ao_usb_init();
index cc0f668fc6b6374c663df8e25c5326b1bb6de20d..afa09e20e2db339508b183fc0d56430ba255b915 100644 (file)
@@ -27,6 +27,8 @@ main(void)
 
        ao_led_init(LEDS_AVAILABLE);
 
+       ao_task_init();
+
        ao_timer_init();
        ao_adc_init();
        ao_beep_init();
index 080a140b74137b2eca08b699c57458629fda6da1..70665ec699622735e1d3b5f665ca1c84d2631871 100644 (file)
@@ -36,6 +36,8 @@ main(void)
        
        ao_led_init(LEDS_AVAILABLE);
        ao_led_on(AO_LED_GREEN);
+       ao_task_init();
+
        ao_timer_init();
 
        ao_spi_init();
index 2fb3186a57b6b4944da77b1245a12bbf4c46cd23..74eef8f48147659492e8ae873ae95538401db361 100644 (file)
@@ -29,9 +29,11 @@ main(void)
        ao_mpu_init();
 #endif
 
-       ao_task_init();
        ao_led_init(LEDS_AVAILABLE);
        ao_led_on(AO_LED_GREEN);
+
+       ao_task_init();
+
        ao_timer_init();
 
        ao_spi_init();
index 4c32817af214eb3cc624ea41f2b2589c71e6e757..d602f6464005c2e3708171b80082c4b883da9ce4 100644 (file)
@@ -29,6 +29,7 @@ main(void)
        /* Turn on the LED until the system is stable */
        ao_led_init(LEDS_AVAILABLE);
        ao_led_on(AO_LED_RED);
+       ao_task_init();
        ao_timer_init();
        ao_cmd_init();
        ao_spi_init();