Merge branch 'master' of ssh://git.gag.com/scm/git/fw/altos
authorBdale Garbee <bdale@gag.com>
Tue, 26 Feb 2019 01:30:08 +0000 (18:30 -0700)
committerBdale Garbee <bdale@gag.com>
Tue, 26 Feb 2019 01:30:08 +0000 (18:30 -0700)
12 files changed:
src/attiny/ao_arch.h
src/attiny/ao_clock.c
src/kernel/ao.h
src/kernel/ao_led.h
src/lpc/ao_arch.h
src/lpc/ao_led_lpc.c
src/lpc/ao_timer_lpc.c
src/stm/ao_arch.h
src/stm/ao_led_stm.c
src/stm/ao_timer.c
src/stmf0/ao_arch.h
src/stmf0/ao_timer.c

index dfd41afe2ec90dba9d5decdc51f7f340101fc714..5550eb447e101f3fa724120bf634053ca1b28540 100644 (file)
 
 #define AO_LED_TYPE    uint8_t
 
+#ifndef AO_TICK_TYPE
+#define AO_TICK_TYPE   uint16_t
+#define AO_TICK_SIGNED int16_t
+#endif
+
 /* Various definitions to make GCC look more like SDCC */
 
 #define ao_arch_naked_declare  __attribute__((naked))
index d722d568d75da0e23e759b26231d3c185822bde9..2ac0500b217f307466fd8be143eae566969eac89 100644 (file)
@@ -28,7 +28,7 @@ ISR(TIMER1_COMPA_vect)
                ao_wakeup((void *) &ao_tick_count);
 }
 
-uint16_t
+AO_TICK_TYPE
 ao_time(void)
 {
        uint16_t        r;
index 910c1d8ed97c532c70da13957fd087f6ee06b84a..dddcd9cb5afd6d8a4079d96eacac2842933b466a 100644 (file)
@@ -100,8 +100,8 @@ extern AO_ROMCONFIG_SYMBOL uint32_t ao_radio_cal;
  */
 
 #ifndef AO_TICK_TYPE
-#define AO_TICK_TYPE   uint16_t
-#define AO_TICK_SIGNED int16_t
+#define AO_TICK_TYPE   uint32_t
+#define AO_TICK_SIGNED int32_t
 #endif
 
 extern volatile AO_TICK_TYPE ao_tick_count;
@@ -117,6 +117,10 @@ extern volatile AO_TICK_TYPE ao_tick_count;
 AO_TICK_TYPE
 ao_time(void);
 
+/* Returns the current time in ns */
+uint64_t
+ao_time_ns(void);
+
 /* Suspend the current task until ticks time has passed */
 void
 ao_delay(uint16_t ticks);
index 5d982ca6d1f0e7101467d072ce215678e8ae8793..b770381f7efb8aea3dcb379a5cb0981800788328 100644 (file)
@@ -43,7 +43,7 @@ ao_led_set(AO_LED_TYPE colors);
 
 /* Set all LEDs in 'mask' to the specified state */
 void
-ao_led_set_mask(uint8_t colors, uint8_t mask);
+ao_led_set_mask(AO_LED_TYPE colors, AO_LED_TYPE mask);
 
 /* Toggle the specified LEDs */
 void
@@ -51,7 +51,7 @@ ao_led_toggle(AO_LED_TYPE colors);
 
 /* Turn on the specified LEDs for the indicated interval */
 void
-ao_led_for(AO_LED_TYPE colors, uint16_t ticks);
+ao_led_for(AO_LED_TYPE colors, AO_TICK_TYPE ticks);
 
 /* Initialize the LEDs */
 void
index 7821839e12d200e87c350a9149fb23dee16cb591..93676b860ff6c9edfb79804805307f288fd67c75 100644 (file)
 
 #define AO_LED_TYPE    AO_PORT_TYPE
 
-#ifndef AO_TICK_TYPE
-#define AO_TICK_TYPE   uint16_t
-#define AO_TICK_SIGNED int16_t
-#endif
-
 /* Various definitions to make GCC look more like SDCC */
 
 #define ao_arch_naked_declare  __attribute__((naked))
index 3a2d4c9886986b72889c50a07c0d13a0ba937cde..46bf0495988dfa82446ab7a49cb8b43cd4cdbc15 100644 (file)
@@ -49,7 +49,7 @@ ao_led_toggle(AO_PORT_TYPE colors)
 }
 
 void
-ao_led_for(AO_PORT_TYPE colors, uint16_t ticks) 
+ao_led_for(AO_PORT_TYPE colors, AO_TICK_TYPE ticks) 
 {
        ao_led_on(colors);
        ao_delay(ticks);
index 8999c7acf1af925e67d17125320644f503811eae..62b16318107f74fc354783ab8520390ac54d524b 100644 (file)
 
 #include <ao.h>
 
+#define AO_SYSTICK     (AO_LPC_SYSCLK / 2)
+
 volatile AO_TICK_TYPE ao_tick_count;
 
-uint16_t
+AO_TICK_TYPE
 ao_time(void)
 {
        return ao_tick_count;
 }
 
+uint64_t
+ao_time_ns(void)
+{
+       AO_TICK_TYPE    before, after;
+       uint32_t        cvr;
+
+       do {
+               before = ao_tick_count;
+               cvr = lpc_systick.cvr;
+               after = ao_tick_count;
+       } while (before != after);
+
+       return (uint64_t) after * (1000000000ULL / AO_HERTZ) +
+               (uint64_t) cvr * (1000000000ULL / AO_SYSTICK);
+}
+
 #if AO_DATA_ALL
 volatile uint8_t       ao_data_interval = 1;
 volatile uint8_t       ao_data_count;
index c95c7cd5eda860ee26ca2421c8ab9c7bbbba26ea..e83b6bd2cfbf3e1dac4a7c2816703fcf1214ba08 100644 (file)
 #define AO_STACK_SIZE  512
 #endif
 
-#ifndef AO_TICK_TYPE
-#define AO_TICK_TYPE   uint16_t
-#define AO_TICK_SIGNED int16_t
-#endif
-
 #define AO_PORT_TYPE   uint16_t
 
 /* Various definitions to make GCC look more like SDCC */
index 7dcbb661b8a65899860d895025fa8639c99e22e8..ed4ec1610de3dde8e645725d851231a4b1051671 100644 (file)
@@ -87,7 +87,7 @@ ao_led_toggle(AO_LED_TYPE colors)
 }
 
 void
-ao_led_for(AO_LED_TYPE colors, AO_LED_TYPE ticks) 
+ao_led_for(AO_LED_TYPE colors, AO_TICK_TYPE ticks) 
 {
        ao_led_on(colors);
        ao_delay(ticks);
index 9e9436cfa685dae451ae27ff59b8c9af6b32be1c..d00deffab2161b80e0333f6524567deefdb87052 100644 (file)
@@ -36,6 +36,23 @@ ao_time(void)
 {
        return ao_tick_count;
 }
+
+uint64_t
+ao_time_ns(void)
+{
+       AO_TICK_TYPE    before, after;
+       uint32_t        cvr;
+
+       do {
+               before = ao_tick_count;
+               cvr = stm_systick.cvr;
+               after = ao_tick_count;
+       } while (before != after);
+
+       return (uint64_t) after * (1000000000ULL / AO_HERTZ) +
+               (uint64_t) cvr * (1000000000ULL / AO_SYSTICK);
+}
+
 #endif
 
 #if AO_DATA_ALL
index e5f7e1f7be2677e3130979855a044d0ff9241e35..d70a9110e91fa02ac481ced1e928fa1868b0ca6d 100644 (file)
 
 #define AO_LED_TYPE    uint16_t
 
-#ifndef AO_TICK_TYPE
-#define AO_TICK_TYPE   uint16_t
-#define AO_TICK_SIGNED int16_t
-#endif
-
 #define AO_PORT_TYPE   uint16_t
 
 /* Various definitions to make GCC look more like SDCC */
index 1def5f69f8e1c1d77d7a6a9d7344e4adcc1001fc..58e52995cf32f35cbb4146b092f60e6217771972 100644 (file)
@@ -35,6 +35,22 @@ ao_time(void)
        return ao_tick_count;
 }
 
+uint64_t
+ao_time_ns(void)
+{
+       AO_TICK_TYPE    before, after;
+       uint32_t        cvr;
+
+       do {
+               before = ao_tick_count;
+               cvr = stm_systick.cvr;
+               after = ao_tick_count;
+       } while (before != after);
+
+       return (uint64_t) after * (1000000000ULL / AO_HERTZ) +
+               (uint64_t) cvr * (1000000000ULL / AO_SYSTICK);
+}
+
 #if AO_DATA_ALL
 volatile uint8_t       ao_data_interval = 1;
 volatile uint8_t       ao_data_count;