From 6c94ce590dadf6e80a029828e65f676bf79e0537 Mon Sep 17 00:00:00 2001 From: Rob Purchase Date: Wed, 16 Jun 2010 21:03:57 +0000 Subject: [PATCH] Re-write the Telechips I2C delay routine in assembler to stop the compiler optimising it away. Tested with EABI and non-EABI compilers. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26872 a1c6a512-1295-4272-9138-f99709370657 --- firmware/target/arm/i2c-telechips.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/firmware/target/arm/i2c-telechips.c b/firmware/target/arm/i2c-telechips.c index 35f4cd41c5..511bbe8865 100644 --- a/firmware/target/arm/i2c-telechips.c +++ b/firmware/target/arm/i2c-telechips.c @@ -27,9 +27,10 @@ /* Delay loop based on CPU frequency (FREQ>>22 is 7..45 for 32MHz..192MHz) */ static inline void delay_loop(void) { - unsigned long x; - for (x = (unsigned)(FREQ>>22); x; x--) - asm volatile("nop"); + asm volatile (" mov %[freq], %[freq], asr#22 \n\t" + "1: subs %[freq], %[freq], #1 \n\t" + " bne 1b" + : : [freq] "r" (cpu_frequency) : "memory"); } #define DELAY delay_loop()