diff options
-rw-r--r-- | firmware/target/arm/as3525/system-target.h | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/firmware/target/arm/as3525/system-target.h b/firmware/target/arm/as3525/system-target.h index d2cf99499d..ee46e7c7a5 100644 --- a/firmware/target/arm/as3525/system-target.h +++ b/firmware/target/arm/as3525/system-target.h | |||
@@ -62,7 +62,8 @@ extern int c200v2_variant; | |||
62 | static inline void udelay(unsigned usecs) __attribute__((always_inline)); | 62 | static inline void udelay(unsigned usecs) __attribute__((always_inline)); |
63 | static inline void udelay(unsigned usecs) | 63 | static inline void udelay(unsigned usecs) |
64 | { | 64 | { |
65 | int now, end; | 65 | unsigned now; |
66 | int end; | ||
66 | 67 | ||
67 | /** | 68 | /** |
68 | * we're limited to 1.5us multiplies due to the odd timer frequency (1.5MHz), | 69 | * we're limited to 1.5us multiplies due to the odd timer frequency (1.5MHz), |
@@ -94,9 +95,24 @@ static inline void udelay(unsigned usecs) | |||
94 | int delay = usecs * 2 / 3; /* us * 1.5 = us*timer_period */ | 95 | int delay = usecs * 2 / 3; /* us * 1.5 = us*timer_period */ |
95 | end = now - delay; | 96 | end = now - delay; |
96 | } | 97 | } |
98 | |||
99 | unsigned old; | ||
100 | |||
97 | /* underrun ? */ | 101 | /* underrun ? */ |
98 | if (end < 0) | 102 | if (end < 0) |
103 | { | ||
104 | do { | ||
105 | old = now; | ||
106 | now = TIMER2_VALUE; | ||
107 | } while(now <= old); /* if the new value is higher then we wrapped */ | ||
108 | |||
99 | end += TIMER_PERIOD; | 109 | end += TIMER_PERIOD; |
100 | while(TIMER2_VALUE != (unsigned)end); | 110 | } |
111 | |||
112 | do { | ||
113 | /* if timer wraps then we missed our end value */ | ||
114 | old = now; | ||
115 | now = TIMER2_VALUE; | ||
116 | } while(now > (unsigned)end && now <= old); | ||
101 | } | 117 | } |
102 | #endif /* SYSTEM_TARGET_H */ | 118 | #endif /* SYSTEM_TARGET_H */ |