Hi
Here is a small extract of code to do a single shot hardware timer delay in ms. It originates from the uTasker project. It is used in its normal context (this is a snippet from it) to control multiple global hardware timers [the DMA timers in the Coldfire are in fact very good and enable single delays of up to about 17min with us resolution]. They are also used for the in-built uNetwork protocol which allows distributed processing in a LAN based network - a fast network protocol is implemented with the hardware timer managing retransmissions after a few ms in case of message loss.
You may see something which you need to solve your problem.
Regards
Mark Butcher
www.uTasker.comNote the define for INTERRUPT_LEVEL_4 is 0x04 shifted by three to the left - the shift left sign got lost when posting!
#define DTIM3_VECTOR 0x56
#define INTERRUPT_LEVEL_4 (0x04 3)
#define INTERRUPT_PRIORITY_1 0x1
#define DTIM3_PIF_INT_L 0x00400000
#define MASK_ALL_INT 0x00000001
#define BUS_CLOCK (60000000)
#define DMA_TIM_EVENT_CAP 0x0001
#define DMA_TIM_EVENT_REF 0x0002
#define BUS_CLOCK_16 0x0004
#define DMA_TIM_RESTART 0x0008
#define ORRI 0x0010
#define ENABLE_DMA_TIMER 0x0001
static __interrupt__ void _hwtimer_interrupt(void)
{
DTRR3 = 0; // clear reference to indicate not in use
DTER0 = DMA_TIM_EVENT_REF; // reset interrupt request flag
// Do stuff here
// ..
}
// Start a single short hardware timer for a delay in ms units
//
externt void fnStartDelay(unsigned long ulMilliSeconds)
{
__VECTOR_RAM[DTIM3_VECTOR] = (unsigned long)_hwtimer_interrupt; // enter the interrupt routine
IC_ICR_0_22 = (INTERRUPT_LEVEL_4 | INTERRUPT_PRIORITY_1); // define interrupts level and priority
IC_IMRL_0 &= ~(DTIM3_PIF_INT_L | MASK_ALL_INT); // unmask interrupt source
DTRR3 = (ulMilliSeconds * ((BUS_CLOCK / 16 / 1000)); // set ms unit compare rate (max about 19 minutes)
DTER3 = (DMA_TIM_EVENT_CAP | DMA_TIM_EVENT_REF); // Clear possible events
DTMR3 = (BUS_CLOCK_16 | DMA_TIM_RESTART | ORRI | ENABLE_DMA_TIMER); // Bus clock / 16, enable interrupt and enable timer (again)
}
Message Edited by mjbcswitzerland on 2007-01-2512:50 PM