#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))
ao_wakeup((void *) &ao_tick_count);
}
-uint16_t
+AO_TICK_TYPE
ao_time(void)
{
uint16_t r;
*/
#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;
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);
/* 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
/* 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
#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))
}
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);
#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;
#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 */
}
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);
{
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
#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 */
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;