pause function on the 5213

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

pause function on the 5213

2,156 Views
airswit
Contributor III
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!
Labels (1)
0 Kudos
2 Replies

828 Views
airswit
Contributor III
nothin, huh?! that sux...maybe i'll move to a pic!!
0 Kudos

828 Views
airswit
Contributor III
alright, so i think i've solved this problem...using relative counter values and just rolling a single counter over...here is the code i use:

//start the dma0 timer running! 1us resolution, rollover...
void setupWaitTimer()
{
MCF_DTIM_DTER(0) = MCF_DTIM_DTER_REF | MCF_DTIM_DTER_CAP;
MCF_DTIM_DTMR(0) = 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;
}



void my_pause(int usecs)
{
uint32 temp = 0;

temp = MCF_DTIM0_DTCN;

if((temp+usecs)
while(MCF_DTIM0_DTCN>(temp+usecs))
;
while(MCF_DTIM0_DTCN(temp+usecs))
;
}


and just call my_pause() to delay for a while!! seems to work pretty well!
0 Kudos