[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[MiNT] Aw: Re: [PATCH] Add udelay routine for ColdFire




> Gesendet: Donnerstag, 24. April 2014 um 13:30 Uhr
> Von: "David Gálvez" <dgalvez75@gmail.com>
> An: "mint@lists.fishpool.fi" <mint@lists.fishpool.fi>
> Betreff: Re: [MiNT] [PATCH] Add udelay routine for ColdFire
> > /*
> >  * wait for the specified number of us on slice timer 0.
> >  */
> > void udelay(uint32_t us)
> > {
> >     int32_t target = MCF_SLT_SCNT(0) - (us * (SYSCLK / 1000));
> >
> >     while (MCF_SLT_SCNT(0) - target > 0);
> > }
> >
> 
> A couple of questions about the code above:
> 
> - Where comes from the 1/1000 component in (SYSCLK / 1000)?

It's a straight copy of the BaS sources where SYSCLK is 132000 (for the Firebee) or 100000 (for the eval board).

> - If target variable is calculated just before the counter expires and
> then reloaded with the terminal count value again, Couldn't this
> situation give delays much greater than requested?
> 

No, I don't think so. As long as the timer value is defined as signed (as opposed to the original Freescale headers where it was an unsigned value IIRC), the "compare" value will "wrap around" (change sign) at the same time the timer value will do. The initial value of the timer is 0xffffffff (-1), it will decend to 
-2147483646 (0x80000000) and suddenly jump (wrap around) to 2147483647 (0x7fffffff). This doesn't do any harm, however, since your target value does the same jump (wraparound) when you substract your wait value from it.

> Another thing that must be taken into account with this approach are
> Evaluation Boards.
> FireTOS use STL 0 for system timer interrupt on EVBs.
> Also System bus frequency (SYSCLK in the code above) is 133 for the
> FireBee but looking at the FireTOS sources It seems that there are
> some EVB (548X??) which have a 100 MHz bus. So the kernel should
> figure out where is running on to give SYSCLK the correct value, or we
> should make this configurable and make a specific kernel for those
> boards.
> 
> 

Unfortunately, there is no (easy) way of determining the clock speed on the Coldfires. You could, however, readout the JTAG id (MCF_SIU_JTAGID) and determine the processor type. If you find a MCF548x, you can be sure you are at SYSCLK=100000 (or slower, but unlikely), if you find a MCF7474, you are probably on a Firebee with 132 MHz.