Mercurial > nand-ecoscentric
diff packages/hal/mips/arch/current/src/hal_misc.c @ 143:6b5f480c6929 ecos-sw-2000-12-08
Merge from eCos master repository on 2000-12-08-02:09:36-GMT
| author | jlarmour |
|---|---|
| date | Fri, 08 Dec 2000 03:30:06 +0000 |
| parents | eb9fd8c04db3 |
| children | 5e8f3b328bb3 |
line wrap: on
line diff
--- a/packages/hal/mips/arch/current/src/hal_misc.c +++ b/packages/hal/mips/arch/current/src/hal_misc.c @@ -339,6 +339,30 @@ cyg_uint32 hal_msbit_index(cyg_uint32 ma } /*------------------------------------------------------------------------*/ +/* Delay for some number of useconds. */ +void +hal_delay_us(int us) +{ + cyg_uint32 val1, val2; + int diff; + long ticks; + // Scale the desired number of microseconds to be a number of + // incrementer ticks + ticks = us * (CYGNUM_HAL_RTC_PERIOD * CYGNUM_HAL_RTC_DENOMINATOR) / 1000000; + + asm volatile("mfc0 %0,$9;" : "=r"(val1)); + while (ticks > 0) { + do { + asm volatile("mfc0 %0,$9;" : "=r"(val2)); + } while (val1 == val2); + diff = val2 - val1; + if (diff < 0) diff += CYGNUM_HAL_RTC_PERIOD; + ticks -= diff; + val1 = val2; + } +} + +/*------------------------------------------------------------------------*/ /* Idle thread action */ #include <cyg/infra/diag.h>
