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

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



Am 23.04.2014 um 19:21 schrieb David Gálvez <dgalvez75@gmail.com>:

> Now the function udelay( ) compiled for ColdFire use the same routine
> as the 68000 CPU, it just loops so many times as the microseconds
> requested, of course this is for the faster CF CPU not enough and
> udelay( ) returns earlier than it should.
> 
> Code imported from Linux m68k-nommu.
> 
> Please Alan if it's OK for you commit.
> <udelay_20140423.diff>

Hi David,

really appreciate your Coldfire efforts, but this looks a bit overengineered to me. To my knowledge, all of the Coldfire MCUs (v4e) that are supported by TOS/MiNT have two slice timers that are free running with bus frequency on EmuTOS as well as on FireTOS which actually makes busy waiting microseconds much easier than your implementation:

/*
 * 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);
}

The Linux code is probably supposed to support all Coldfire versions including those that don’t have the SLT timers so I assume that is the reason its more general. Since we’ll probably never need to support earlier Coldfires (if possible at all), I assume we can safely use the simpler (and - due to cache effects - most likely more accurate) version?

Cheers,
Markus