summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomasz Moń <desowin@gmail.com>2011-12-21 21:11:38 +0000
committerTomasz Moń <desowin@gmail.com>2011-12-21 21:11:38 +0000
commitf805b5d361d8a0c64551e2f0305f53f9b9a59b00 (patch)
tree97e26df64b05c667cfa315730011e3c4394e46a2
parentb4ffcb5224a4dc8898cec9b1b9f8b413f540f36d (diff)
downloadrockbox-f805b5d361d8a0c64551e2f0305f53f9b9a59b00.tar.gz
rockbox-f805b5d361d8a0c64551e2f0305f53f9b9a59b00.zip
TMS320DM320: Ensure udelay() will not end before specified amount of time.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31398 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/target/arm/tms320dm320/system-dm320.c31
1 files changed, 27 insertions, 4 deletions
diff --git a/firmware/target/arm/tms320dm320/system-dm320.c b/firmware/target/arm/tms320dm320/system-dm320.c
index 12e0b6d03d..dc9c2060c6 100644
--- a/firmware/target/arm/tms320dm320/system-dm320.c
+++ b/firmware/target/arm/tms320dm320/system-dm320.c
@@ -413,13 +413,35 @@ void set_cpu_frequency(long frequency)
413#endif 413#endif
414 414
415/* 415/*
416 * Waits for specified amount of microseconds 416 * Waits for specified amount of microseconds (or longer, but NEVER less)
417 *
418 * Maximum supported usec value is 10000, use sleep() for longer delays.
417 */ 419 */
418void udelay(int usec) { 420void udelay(int usec) {
421 /*
422 * count and prev_tick must be initialized as soon as posible (right
423 * after function entry)
424 *
425 * count must be initialized before prev_count
426 */
419 unsigned short count = IO_TIMER1_TMCNT; 427 unsigned short count = IO_TIMER1_TMCNT;
428 long prev_tick = current_tick;
429
430 /* initialization time/sequence of these values is not critical */
420 unsigned short stop; 431 unsigned short stop;
421 unsigned short tmp = IO_TIMER1_TMDIV; 432 unsigned short tmp = IO_TIMER1_TMDIV;
422 int prev_tick = current_tick; 433
434 if (!irq_enabled())
435 {
436 /*
437 * Interrupts are disabled
438 *
439 * Clear TIMER1 interrupt to prevent returning from this fuction
440 * before specified amount of time has passed
441 * In worst case this makes udelay() take one tick longer
442 */
443 IO_INTC_IRQ0 = INTR_IRQ0_TMR1;
444 }
423 445
424 /* 446 /*
425 * On Sansa Connect tick timer counts from 0 to 26999 447 * On Sansa Connect tick timer counts from 0 to 26999
@@ -450,13 +472,14 @@ void udelay(int usec) {
450 /* udelay will end after counter reset (tick) */ 472 /* udelay will end after counter reset (tick) */
451 while ((IO_TIMER1_TMCNT < stop) || 473 while ((IO_TIMER1_TMCNT < stop) ||
452 ((current_tick == prev_tick) /* ensure new tick */ && 474 ((current_tick == prev_tick) /* ensure new tick */ &&
453 (IO_INTC_IRQ0 & (1 << 1)))); /* prevent lock */ 475 (IO_INTC_IRQ0 & INTR_IRQ0_TMR1))); /* prevent lock */
454 } 476 }
455 else 477 else
456 { 478 {
457 /* udelay will end before counter reset (tick) */ 479 /* udelay will end before counter reset (tick) */
458 while ((IO_TIMER1_TMCNT < stop) && 480 while ((IO_TIMER1_TMCNT < stop) &&
459 ((current_tick == prev_tick) && (IO_INTC_IRQ0 & (1 << 1)))); 481 ((current_tick == prev_tick) &&
482 (IO_INTC_IRQ0 & INTR_IRQ0_TMR1)));
460 } 483 }
461} 484}
462 485