Trevor Switkowski

pause function on the 5213

Discussion created by Trevor Switkowski on Nov 7, 2006
Latest reply on Nov 17, 2006 by Trevor Switkowski
Hi everyone,

I was wondering if there is anyone that can help me with creating a delay function for the 5213 that can be used by several tasks, and be able to interrupt each other. I am in need of a single function that can be used to delay the system for a given number of microseconds. I have tried to create this by using the DMA timers (there is a function that freescale gave, but it only can be run by 1 function), and i modified it to check to see if the specific timer is in use, and if it is, skips to the next one. i was hoping this would work, but sometimes the system will hang within the my_pause() funciton, waiting for the timer to run over.

I cannot use different functions, really, either, because of the fact that any order of interrupts may trigger, so it would be impossible to assign each isr to use a different timer. also, i tried a while back to implement this using a queue (dynamic memory allocation) and 'semaphores', but that didn't work (though it worked on a windows machine, compiled with visual c++), so i am out of ideas.

Does anyone have anything that i might be able to use, or any hints as to where i can go with this?!

I have attached the code that i thought would work below:

void my_pause(int usecs)
{
uint8 i;
// Enable the DMA Timer 1
for(i=0 ; i < 4 ; i++)
{
if((MCF_DTIM_DTMR(i)&0x0006))
continue;
else
{
MCF_DTIM_DTRR(i) = (usecs - 1);
MCF_DTIM_DTER(i) = MCF_DTIM_DTER_REF;
MCF_DTIM_DTMR(i) = 0
| MCF_DTIM_DTMR_PS(sys_clk_khz / 1000)
| MCF_DTIM_DTMR_ORRI
| MCF_DTIM_DTMR_FRR
| MCF_DTIM_DTMR_CLK_DIV1
| MCF_DTIM_DTMR_RST;

while ( MCF_DTIM_DTMR(i) !=0 && (MCF_DTIM_DTER(i) & MCF_DTIM_DTER_REF) == 0)
{};

// Disable the timer
MCF_DTIM_DTMR(i) = 0;
break;
}
}
}


thanks in advance!

Outcomes