summaryrefslogtreecommitdiff
path: root/firmware/target/arm/tms320dm320/system-dm320.c
diff options
context:
space:
mode:
authorTomasz Moń <desowin@gmail.com>2011-12-20 12:49:59 +0000
committerTomasz Moń <desowin@gmail.com>2011-12-20 12:49:59 +0000
commit4aec0012440ceeeee45913cfe5ce8869597db1f6 (patch)
treebc8a76bbb8343f65834ec7db91290f4f83ae9c01 /firmware/target/arm/tms320dm320/system-dm320.c
parent1a4aea3ad8920edd6c5fa4cb419a98f0d3c91fbf (diff)
downloadrockbox-4aec0012440ceeeee45913cfe5ce8869597db1f6.tar.gz
rockbox-4aec0012440ceeeee45913cfe5ce8869597db1f6.zip
TMS320DM320: Use TIMER1 (tick generator) to make udelay() precise.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31376 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/target/arm/tms320dm320/system-dm320.c')
-rw-r--r--firmware/target/arm/tms320dm320/system-dm320.c38
1 files changed, 31 insertions, 7 deletions
diff --git a/firmware/target/arm/tms320dm320/system-dm320.c b/firmware/target/arm/tms320dm320/system-dm320.c
index 267fbd46af..a2a9ec3661 100644
--- a/firmware/target/arm/tms320dm320/system-dm320.c
+++ b/firmware/target/arm/tms320dm320/system-dm320.c
@@ -412,14 +412,38 @@ void set_cpu_frequency(long frequency)
412} 412}
413#endif 413#endif
414 414
415/* This function is pretty crude. It is not acurate to a usec, but errors on
416 * longer.
417 */
418void udelay(int usec) { 415void udelay(int usec) {
419 volatile int temp=usec*(175000/200); 416 unsigned short count = IO_TIMER1_TMCNT;
420 417 unsigned short stop;
421 while(temp) { 418 unsigned short tmp = IO_TIMER1_TMDIV;
422 temp--; 419 int prev_tick = current_tick;
420
421 /*
422 * On Sansa Connect tick timer counts from 0 to 26999
423 * in this case stop will overflow only if usec > 10000
424 * such long delays shouldn't be blocking (use sleep() instead)
425 */
426 stop = count + usec*((tmp+1)/10000);
427 stop += (unsigned short)(((unsigned long)(usec)*((tmp%10000)+1))/10000);
428
429 /* stop values over tmdiv won't ever be reached */
430 if (stop > tmp)
431 {
432 stop -= tmp;
433 }
434
435 if (stop < count)
436 {
437 /* udelay will end after counter reset (tick) */
438 while ((((tmp = IO_TIMER1_TMCNT) < stop) &&
439 (current_tick != prev_tick)) ||
440 (current_tick == prev_tick)); /* ensure new tick */
441 }
442 else
443 {
444 /* udelay will end before counter reset (tick) */
445 while (((tmp = IO_TIMER1_TMCNT) < stop) &&
446 (current_tick == prev_tick));
423 } 447 }
424} 448}
425 449