Fix timer code for ARM systems: make sure that udelay() does not
reset timers so it's save to use udelay() in timeout code.
This commit is contained in:
parent
50712ba16e
commit
101e8dfa2a
|
@ -2,6 +2,9 @@
|
||||||
Changes for U-Boot 1.1.3:
|
Changes for U-Boot 1.1.3:
|
||||||
======================================================================
|
======================================================================
|
||||||
|
|
||||||
|
* Fix timer code for ARM systems: make sure that udelay() does not
|
||||||
|
reset timers so it's save to use udelay() in timeout code.
|
||||||
|
|
||||||
* Patch by Mathias Küster, 23 Nov 2004:
|
* Patch by Mathias Küster, 23 Nov 2004:
|
||||||
add udelay support for the mcf5282 cpu
|
add udelay support for the mcf5282 cpu
|
||||||
|
|
||||||
|
|
|
@ -254,6 +254,8 @@ ulong get_timer_masked (void)
|
||||||
void udelay_masked (unsigned long usec)
|
void udelay_masked (unsigned long usec)
|
||||||
{
|
{
|
||||||
ulong tmo;
|
ulong tmo;
|
||||||
|
ulong endtime;
|
||||||
|
signed long diff;
|
||||||
|
|
||||||
if (usec >= 1000) { /* if "big" number, spread normalization to seconds */
|
if (usec >= 1000) { /* if "big" number, spread normalization to seconds */
|
||||||
tmo = usec / 1000; /* start to normalize for usec to ticks per sec */
|
tmo = usec / 1000; /* start to normalize for usec to ticks per sec */
|
||||||
|
@ -263,9 +265,12 @@ void udelay_masked (unsigned long usec)
|
||||||
tmo = usec * CFG_HZ;
|
tmo = usec * CFG_HZ;
|
||||||
tmo /= (1000*1000);
|
tmo /= (1000*1000);
|
||||||
}
|
}
|
||||||
reset_timer_masked (); /* set "advancing" timestamp to 0, set lastinc vaule */
|
endtime = get_timer_masked () + tmo;
|
||||||
while (get_timer_masked () < tmo) /* wait for time stamp to overtake tick number.*/
|
|
||||||
/* NOP */;
|
do {
|
||||||
|
ulong now = get_timer_masked ();
|
||||||
|
diff = endtime - now;
|
||||||
|
} while (diff >= 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -358,15 +358,24 @@ ulong get_timer_masked (void)
|
||||||
void udelay_masked (unsigned long usec)
|
void udelay_masked (unsigned long usec)
|
||||||
{
|
{
|
||||||
ulong tmo;
|
ulong tmo;
|
||||||
|
ulong endtime;
|
||||||
|
signed long diff;
|
||||||
|
|
||||||
|
if (usec >= 1000) {
|
||||||
tmo = usec / 1000;
|
tmo = usec / 1000;
|
||||||
tmo *= CFG_HZ;
|
tmo *= CFG_HZ;
|
||||||
tmo /= 1000;
|
tmo /= 1000;
|
||||||
|
} else {
|
||||||
|
tmo = usec * CFG_HZ;
|
||||||
|
tmo /= (1000*1000);
|
||||||
|
}
|
||||||
|
|
||||||
reset_timer_masked ();
|
endtime = get_timer_masked () + tmo;
|
||||||
|
|
||||||
while (get_timer_masked () < tmo)
|
do {
|
||||||
/*NOP*/;
|
ulong now = get_timer_masked ();
|
||||||
|
diff = endtime - now;
|
||||||
|
} while (diff >= 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined(CONFIG_S3C4510B)
|
#elif defined(CONFIG_S3C4510B)
|
||||||
|
|
|
@ -81,10 +81,13 @@ ulong get_timer_masked (void)
|
||||||
|
|
||||||
void udelay_masked (unsigned long usec)
|
void udelay_masked (unsigned long usec)
|
||||||
{
|
{
|
||||||
ulong start = get_timer_masked();
|
ulong endtime = get_timer_masked() + usec;
|
||||||
|
signed long diff;
|
||||||
|
|
||||||
while (get_timer_masked () - start < usec )
|
do {
|
||||||
/*NOP*/;
|
ulong now = get_timer_masked ();
|
||||||
|
diff = endtime - now;
|
||||||
|
} while (diff >= 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void udelay (unsigned long usec)
|
void udelay (unsigned long usec)
|
||||||
|
|
|
@ -137,15 +137,24 @@ ulong get_timer_masked (void)
|
||||||
void udelay_masked (unsigned long usec)
|
void udelay_masked (unsigned long usec)
|
||||||
{
|
{
|
||||||
ulong tmo;
|
ulong tmo;
|
||||||
|
ulong endtime;
|
||||||
|
signed long diff;
|
||||||
|
|
||||||
|
if (usec >= 1000) {
|
||||||
tmo = usec / 1000;
|
tmo = usec / 1000;
|
||||||
tmo *= (timer_load_val * 100);
|
tmo *= (timer_load_val * 100);
|
||||||
tmo /= 1000;
|
tmo /= 1000;
|
||||||
|
} else {
|
||||||
|
tmo = usec * (timer_load_val * 100);
|
||||||
|
tmo /= (1000*1000);
|
||||||
|
}
|
||||||
|
|
||||||
reset_timer_masked ();
|
endtime = get_timer_masked () + tmo;
|
||||||
|
|
||||||
while (get_timer_masked () < tmo)
|
do {
|
||||||
/*NOP*/;
|
ulong now = get_timer_masked ();
|
||||||
|
diff = endtime - now;
|
||||||
|
} while (diff >= 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -275,6 +275,8 @@ void udelay_masked (unsigned long usec)
|
||||||
#else
|
#else
|
||||||
|
|
||||||
ulong tmo;
|
ulong tmo;
|
||||||
|
ulong endtime;
|
||||||
|
signed long diff;
|
||||||
|
|
||||||
if (usec >= 1000) { /* if "big" number, spread normalization to seconds */
|
if (usec >= 1000) { /* if "big" number, spread normalization to seconds */
|
||||||
tmo = usec / 1000; /* start to normalize for usec to ticks per sec */
|
tmo = usec / 1000; /* start to normalize for usec to ticks per sec */
|
||||||
|
@ -285,10 +287,12 @@ void udelay_masked (unsigned long usec)
|
||||||
tmo /= (1000*1000);
|
tmo /= (1000*1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
reset_timer_masked (); /* set "advancing" timestamp to 0, set lastdec vaule */
|
endtime = get_timer_masked () + tmo;
|
||||||
|
|
||||||
while (get_timer_masked () < tmo) /* wait for time stamp to overtake tick number.*/
|
do {
|
||||||
/*NOP*/;
|
ulong now = get_timer_masked ();
|
||||||
|
diff = endtime - now;
|
||||||
|
} while (diff >= 0);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -292,6 +292,8 @@ ulong get_timer_masked (void)
|
||||||
void udelay_masked (unsigned long usec)
|
void udelay_masked (unsigned long usec)
|
||||||
{
|
{
|
||||||
ulong tmo;
|
ulong tmo;
|
||||||
|
ulong endtime;
|
||||||
|
signed long diff;
|
||||||
|
|
||||||
if (usec >= 1000) { /* if "big" number, spread normalization to seconds */
|
if (usec >= 1000) { /* if "big" number, spread normalization to seconds */
|
||||||
tmo = usec / 1000; /* start to normalize for usec to ticks per sec */
|
tmo = usec / 1000; /* start to normalize for usec to ticks per sec */
|
||||||
|
@ -302,10 +304,12 @@ void udelay_masked (unsigned long usec)
|
||||||
tmo /= (1000*1000);
|
tmo /= (1000*1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
reset_timer_masked (); /* set "advancing" timestamp to 0, set lastdec vaule */
|
endtime = get_timer_masked () + tmo;
|
||||||
|
|
||||||
while (get_timer_masked () < tmo) /* wait for time stamp to overtake tick number.*/
|
do {
|
||||||
/*NOP*/;
|
ulong now = get_timer_masked ();
|
||||||
|
diff = endtime - now;
|
||||||
|
} while (diff >= 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -231,20 +231,19 @@ ulong get_timer_masked (void)
|
||||||
void udelay_masked (unsigned long usec)
|
void udelay_masked (unsigned long usec)
|
||||||
{
|
{
|
||||||
ulong tmo;
|
ulong tmo;
|
||||||
|
ulong endtime;
|
||||||
|
signed long diff;
|
||||||
|
|
||||||
#if 0 /* doesn't work for usec < 1000 */
|
|
||||||
tmo = usec / 1000;
|
|
||||||
tmo *= CFG_HZ_CLOCK;
|
|
||||||
#else
|
|
||||||
tmo = CFG_HZ_CLOCK / 1000;
|
tmo = CFG_HZ_CLOCK / 1000;
|
||||||
tmo *= usec;
|
tmo *= usec;
|
||||||
#endif
|
|
||||||
tmo /= 1000;
|
tmo /= 1000;
|
||||||
|
|
||||||
reset_timer_masked ();
|
endtime = get_timer_raw () + tmo;
|
||||||
|
|
||||||
while (get_timer_raw () < tmo)
|
do {
|
||||||
/*NOP*/;
|
ulong now = get_timer_raw ();
|
||||||
|
diff = endtime - now;
|
||||||
|
} while (diff >= 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -117,11 +117,11 @@ reset:
|
||||||
|
|
||||||
#ifdef CONFIG_INIT_CRITICAL
|
#ifdef CONFIG_INIT_CRITICAL
|
||||||
/* scratch stack */
|
/* scratch stack */
|
||||||
ldr r1, =0x00204000
|
/**** ldr r1, =0x00204000 ****/
|
||||||
/* Insure word alignment */
|
/* Insure word alignment */
|
||||||
bic r1, r1, #3
|
/**** bic r1, r1, #3 ****/
|
||||||
/* Init stack SYS */
|
/* Init stack SYS */
|
||||||
mov sp, r1
|
/**** mov sp, r1 ****/
|
||||||
/*
|
/*
|
||||||
* This does a lot more than just set up the memory, which
|
* This does a lot more than just set up the memory, which
|
||||||
* is why it's called lowlevelinit
|
* is why it's called lowlevelinit
|
||||||
|
|
|
@ -281,25 +281,29 @@ ulong get_timer_masked (void)
|
||||||
void udelay_masked (unsigned long usec)
|
void udelay_masked (unsigned long usec)
|
||||||
{
|
{
|
||||||
ulong tmo;
|
ulong tmo;
|
||||||
|
ulong endtime;
|
||||||
|
signed long diff;
|
||||||
|
|
||||||
/* normalize */
|
/* normalize */
|
||||||
if (usec >= 1000) {
|
if (usec >= 1000) {
|
||||||
tmo = usec / 1000;
|
tmo = usec / 1000;
|
||||||
tmo *= CFG_HZ;
|
tmo *= CFG_HZ;
|
||||||
tmo /= 1000;
|
tmo /= 1000;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if (usec > 1) {
|
if (usec > 1) {
|
||||||
tmo = usec * CFG_HZ;
|
tmo = usec * CFG_HZ;
|
||||||
tmo /= (1000*1000);
|
tmo /= (1000*1000);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
tmo = 1;
|
tmo = 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
reset_timer_masked ();
|
endtime = get_timer_masked () + tmo;
|
||||||
|
|
||||||
while (get_timer_masked () < tmo);
|
do {
|
||||||
|
ulong now = get_timer_masked ();
|
||||||
|
diff = endtime - now;
|
||||||
|
} while (diff >= 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -190,6 +190,8 @@ ulong get_timer_masked (void)
|
||||||
void udelay_masked (unsigned long usec)
|
void udelay_masked (unsigned long usec)
|
||||||
{
|
{
|
||||||
ulong tmo;
|
ulong tmo;
|
||||||
|
ulong endtime;
|
||||||
|
signed long diff;
|
||||||
|
|
||||||
if (usec >= 1000) {
|
if (usec >= 1000) {
|
||||||
tmo = usec / 1000;
|
tmo = usec / 1000;
|
||||||
|
@ -200,10 +202,12 @@ void udelay_masked (unsigned long usec)
|
||||||
tmo /= (1000*1000);
|
tmo /= (1000*1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
reset_timer_masked ();
|
endtime = get_timer_masked () + tmo;
|
||||||
|
|
||||||
while (tmo >= get_timer_masked ())
|
do {
|
||||||
/*NOP*/;
|
ulong now = get_timer_masked ();
|
||||||
|
diff = endtime - now;
|
||||||
|
} while (diff >= 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -219,15 +219,22 @@ ulong get_timer_masked (void)
|
||||||
void udelay_masked (unsigned long usec)
|
void udelay_masked (unsigned long usec)
|
||||||
{
|
{
|
||||||
ulong tmo;
|
ulong tmo;
|
||||||
|
ulong endtime;
|
||||||
|
signed long diff;
|
||||||
|
|
||||||
|
if (usec >= 1000) {
|
||||||
tmo = usec / 1000;
|
tmo = usec / 1000;
|
||||||
tmo *= CFG_HZ;
|
tmo *= CFG_HZ;
|
||||||
tmo /= 8;
|
tmo /= 8;
|
||||||
|
} else {
|
||||||
tmo += get_timer (0);
|
tmo = usec * CFG_HZ;
|
||||||
|
tmo /= (1000*8);
|
||||||
reset_timer_masked ();
|
}
|
||||||
|
|
||||||
while (get_timer_masked () < tmo)
|
endtime = get_timer(0) + tmo;
|
||||||
/*NOP*/;
|
|
||||||
|
do {
|
||||||
|
ulong now = get_timer_masked ();
|
||||||
|
diff = endtime - now;
|
||||||
|
} while (diff >= 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -206,15 +206,24 @@ ulong get_timer_masked (void)
|
||||||
void udelay_masked (unsigned long usec)
|
void udelay_masked (unsigned long usec)
|
||||||
{
|
{
|
||||||
ulong tmo;
|
ulong tmo;
|
||||||
|
ulong endtime;
|
||||||
|
signed long diff;
|
||||||
|
|
||||||
|
if (usec >= 1000) {
|
||||||
tmo = usec / 1000;
|
tmo = usec / 1000;
|
||||||
tmo *= CFG_HZ;
|
tmo *= CFG_HZ;
|
||||||
tmo /= 1000;
|
tmo /= 1000;
|
||||||
|
} else {
|
||||||
|
tmo = usec * CFG_HZ;
|
||||||
|
tmo /= (1000*1000);
|
||||||
|
}
|
||||||
|
|
||||||
reset_timer_masked ();
|
endtime = get_timer_masked () + tmo;
|
||||||
|
|
||||||
while (tmo >= get_timer_masked ())
|
do {
|
||||||
/*NOP*/;
|
ulong now = get_timer_masked ();
|
||||||
|
diff = endtime - now;
|
||||||
|
} while (diff >= 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
|
|
||||||
/* ARM asynchronous clock */
|
/* ARM asynchronous clock */
|
||||||
#define AT91C_MAIN_CLOCK 207360000 /* from 18.432 MHz crystal (18432000 / 4 * 45) */
|
#define AT91C_MAIN_CLOCK 207360000 /* from 18.432 MHz crystal (18432000 / 4 * 45) */
|
||||||
#define AT91C_MASTER_CLOCK 69120000 /* peripheral clock (AT91C_MASTER_CLOCK / 3) */
|
#define AT91C_MASTER_CLOCK (AT91C_MAIN_CLOCK/3) /* peripheral clock */
|
||||||
|
|
||||||
#define AT91_SLOW_CLOCK 32768 /* slow clock */
|
#define AT91_SLOW_CLOCK 32768 /* slow clock */
|
||||||
|
|
||||||
|
@ -203,7 +203,7 @@ struct bd_info_ext {
|
||||||
#endif /* __ASSEMBLY__ */
|
#endif /* __ASSEMBLY__ */
|
||||||
|
|
||||||
#define CFG_HZ 1000
|
#define CFG_HZ 1000
|
||||||
#define CFG_HZ_CLOCK AT91C_MASTER_CLOCK/2 /* AT91C_TC0_CMR is implicitly set to */
|
#define CFG_HZ_CLOCK (AT91C_MASTER_CLOCK/2) /* AT91C_TC0_CMR is implicitly set to */
|
||||||
/* AT91C_TC_TIMER_DIV1_CLOCK */
|
/* AT91C_TC_TIMER_DIV1_CLOCK */
|
||||||
|
|
||||||
#define CONFIG_STACKSIZE (32*1024) /* regular stack */
|
#define CONFIG_STACKSIZE (32*1024) /* regular stack */
|
||||||
|
|
Loading…
Reference in New Issue