aboutsummaryrefslogtreecommitdiffstats
path: root/wirish/time.c
diff options
context:
space:
mode:
authorPerry Hung <iperry@alum.mit.edu>2010-08-04 08:52:30 -0400
committerPerry Hung <iperry@alum.mit.edu>2010-08-04 08:52:30 -0400
commitd2494611156c4ba477a1bbd1b07ba0cfc14b29e4 (patch)
tree48782014152efa392ac0689c4098e089da52c82c /wirish/time.c
parent2b7a1b40c96525cd4c6324f6e9d53845fb07a55f (diff)
downloadlibrambutan-d2494611156c4ba477a1bbd1b07ba0cfc14b29e4.tar.gz
librambutan-d2494611156c4ba477a1bbd1b07ba0cfc14b29e4.zip
Cleaned up wirish/time, some interrupt handling refactoring:
Fixed millis(), it was just wrong, before. Added micros(), not extensively tested. New implementation of delayMicroseconds(). Should be more consistent now. Added a handful of nvic routines to enable/disable interrupts. Cleaned up systick
Diffstat (limited to 'wirish/time.c')
-rw-r--r--wirish/time.c53
1 files changed, 14 insertions, 39 deletions
diff --git a/wirish/time.c b/wirish/time.c
index 69e962c..c0fd03e 100644
--- a/wirish/time.c
+++ b/wirish/time.c
@@ -23,8 +23,6 @@
* ****************************************************************************/
/**
- * @file time.c
- *
* @brief
*/
@@ -32,46 +30,23 @@
#include "systick.h"
#include "time.h"
-#define CYCLES_PER_MICROSECOND 72
-#define FUDGE 42
-
-extern volatile uint32 systick_timer_millis;
-
-uint32 millis() {
- unsigned long m;
- m = systick_timer_millis;
- return m;
-}
-
void delay(unsigned long ms)
{
- unsigned long start = millis();
-
- while (millis() - start <= ms)
- ;
+ uint32 i;
+ for (i = 0; i < ms; i++) {
+ delayMicroseconds(1000);
+ }
}
-
-
-#if 1
void delayMicroseconds(uint32 us) {
- uint32 target;
- uint32 last, cur, count;
- /* fudge factor hacky hack hack for function overhead */
- target = us * CYCLES_PER_MICROSECOND - FUDGE;
-
- /* Get current count */
- last = systick_get_count();
- cur = systick_get_count();
- count = last;
- while ((count-cur) <= target) {
- cur = systick_get_count();
-
- /* check for overflow */
- if (cur > last) {
- count += MAPLE_RELOAD_VAL;
- }
- last = cur;
- }
+ us *= 12;
+
+ /* fudge for function call overhead */
+ us--;
+ asm volatile(" mov r0, %[us] \n\t"
+ "1: subs r0, #1 \n\t"
+ " bhi 1b \n\t"
+ :
+ : [us] "r" (us)
+ : "r0");
}
-#endif