On Mon, Nov 21, 2011 at 11:52:59PM +0100, Marek Vasut wrote: > > create mode 100644 arch/openrisc/lib/timer.c > > Timer support isn't a library function but a CPU function, so move it to 3/9. >
I never quite worked out where the timer functions belongs, some have them in interupts.c and some in their own file. Some have them cpu/ and some in lib/ > > + asm("l.nop 0x1"); /* Kill any simulation */ > > Simulation? Oh, it's an FPGA based CPU or what? > Well, yes, FPGAs are probably the most common case, but also ASIC implementations exists. The extra argument to the nop instruction is ignored by hardware, but have special meanings when ran in simulation. > > +int timer_init(void) > > +{ > > + /* Install timer exception handler */ > > + exception_install_handler(EXC_TIMER, timer_isr); > > + > > + /* Set up the timer for the first expiration. */ > > + timestamp = 0; > > + > > + mtspr(SPR_TTMR, SPR_TTMR_IE | SPR_TTMR_RT | > > + (TIMER_COUNTER_CYCLES & SPR_TTMR_TP)); > > + > > + /* Enable tick timer exception in supervisor register */ > > + mtspr(SPR_SR, mfspr(SPR_SR) | SPR_SR_TEE); > > + > > + return 0; > > +} > > + > > +void reset_timer(void) > > +{ > > + timestamp = 0; > > + > > + mtspr(SPR_TTMR, SPR_TTMR_IE | SPR_TTMR_RT | > > + (TIMER_COUNTER_CYCLES & SPR_TTMR_TP)); > > +} > > + > > +/* > > + * The timer value in ms is calculated by taking the > > + * value accumulated by full timer revolutions plus the value > > + * accumulated in this period > > + */ > > +ulong get_timer(ulong base) > > +{ > > + return timestamp + mfspr(SPR_TTCR)/TIMER_CYCLES_MS - base; > > +} > > + > > +void set_timer(ulong t) > > +{ > > + reset_timer(); > > + timestamp = t; > > +} > > + > > +void __udelay(ulong usec) > > +{ > > + ulong elapsed = 0; > > + ulong tick; > > + ulong last_tick; > > + > > + last_tick = mfspr(SPR_TTCR); > > + while ((elapsed / TIMER_CYCLES_US) < usec) { > > + tick = mfspr(SPR_TTCR); > > + if (tick >= last_tick) > > + elapsed += (tick - last_tick); > > + else > > + elapsed += TIMER_COUNTER_CYCLES - (last_tick - tick); > > + last_tick = tick; > > + } > > +} > > I'm not sure if this conforms with current timer api, can you cross-check > with > arch/arm/arm926ejs/mx28/timer.c ? That's the latest addition and should > conform. > In my opinion it seems to do the same thing as that, what exactly did you find non-conforming? Stefan _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot