diff options
author | bnewbold <bnewbold@robocracy.org> | 2010-08-31 17:39:46 -0400 |
---|---|---|
committer | bnewbold <bnewbold@robocracy.org> | 2010-08-31 17:39:46 -0400 |
commit | 02d7b08f0497096f21e41922e0efb54c4ef33bab (patch) | |
tree | a7e04293efcba70f37cffcd03c0fcc4c0be7858a /wirish/time.h | |
parent | b2dd49c3141d8a21a4e7c7ef51dee7329f847c30 (diff) | |
parent | e03d58f4dab4176514924baa3a1ff430bf5819b8 (diff) | |
download | librambutan-02d7b08f0497096f21e41922e0efb54c4ef33bab.tar.gz librambutan-02d7b08f0497096f21e41922e0efb54c4ef33bab.zip |
Merge maple-native changes into portable
This compiles for both maple and maple_native but is untested.
Diffstat (limited to 'wirish/time.h')
-rw-r--r-- | wirish/time.h | 50 |
1 files changed, 29 insertions, 21 deletions
diff --git a/wirish/time.h b/wirish/time.h index 9e5536b..33c04b4 100644 --- a/wirish/time.h +++ b/wirish/time.h @@ -23,8 +23,6 @@ * ****************************************************************************/ /** - * @file time.h - * * @brief */ @@ -34,32 +32,42 @@ #ifdef __cplusplus extern "C"{ #endif -/* Returns time since boot in milliseconds */ -uint32 millis(void); + +#include "nvic.h" +#include "systick.h" +#include "boards.h" + +#define US_PER_MS 1000 +#define MAPLE_RELOAD_VAL (CYCLES_PER_MICROSECOND * US_PER_MS) + +extern volatile uint32 systick_timer_millis; + +/* time in milliseconds since boot */ +static inline uint32 millis(void) { + return systick_timer_millis; +} /* Time in microseconds since boot */ -uint32 micros(void); +static inline uint32 micros(void) { + uint32 ms; + uint32 cycle_cnt; + uint32 res; -/* Delay for ms milliseconds */ -void delay(unsigned long ms); + nvic_globalirq_disable(); -/* Delay for us microseconds */ -void delayMicroseconds(uint32 us); + cycle_cnt = systick_get_count(); + ms = millis(); + + nvic_globalirq_enable(); -#if 0 -static inline void delay_us(uint32 us) { - us *= 12; - asm volatile("mov r0, %[us] \n\t" - "subs r0, #2 \n\t" -"1: \n\t" - "subs r0, r0, #1 \n\t" - "bne 1b" - : - : [us] "r" (us) - : "r0", "cc"); + res = (ms * US_PER_MS) + (MAPLE_RELOAD_VAL - cycle_cnt)/CYCLES_PER_MICROSECOND; + return res; } -#endif + +void delay(unsigned long ms); +void delayMicroseconds(uint32 us); + #ifdef __cplusplus } // extern "C" #endif |