seulater wrote:This may be of some help or not... I yanked this and snipped it from some of my older stuff. It uses the IRQ5, but it should give you an idea.
I have not tried using flags as Ridgeglider suggested, so i leave that up to you to determine what is best for you.
// Semaphores
OS_SEM Task1Wait;
//********************************************
//******************* IRQ 5 *******************
//********************************************
INTERRUPT(irq5_isr, 0x2500)
{
// Clear IRQ
sim.eport.epfr |=0x20;
//allow Task 1 to run
OSSemPost(&Task1Wait);
}
//*****************************************************
//********************* Task1 ***********************
//*****************************************************
void Task1( void *pd )
{
while(1)
{
// Wait here until we are signaled to run
OSSemPend(&Task1Wait,0);
// Set i/O pin low here for scope timing
// Can use J1[5].set(); & J1[5].clr(); but they are slower than direct access to pins
// if using this method dont forget to make them a output pin first.
sim.gpio.pclrr_feci2c = ~0x01
// Do what you have to here
iprintf("Task 1 Has Just been Called\r\n");
// Set i/O pin high here for scope timing
// Can use J1[5].set(); & J1[5].clr(); but they are slower than direct access to pins
// if using this method dont forget to make them a output pin first.
sim.gpio.ppdsdr_feci2c = 0x01;
// Now loop back and wait again for post signal.
// Just for habit use
OSTimeDly( 2 );
}
}
Just be careful if using semaphores, to call OSSemInit(&Task1Wait, 0) before the timer interrupt is enabled and before Task1 is Created.
Thanks guys - I'll try to keep my ISR short. Basically, I have to do the following:
- Wait for a UDP command to enable the system.
- When the system is enabled, poll 25 GPIO ports, load their state into the UDP buffer, and send it out 10 times per second.
- When the system is disabled, poll the pin status, update every 5+ seconds - easy enough to do.
So I thought that setting a timer to interrupt every 10th of a second, and having the ISR set a "send now" flag was probably my best option, especially since the general consensus is that we want the ISR to be short. Now, since my UDPReaderMain() has a send function too, I need to make sure the two sending routines don't conflict, so I figured I could do the following (assume variables are declared properly):
void UserMain (void * pd)
{
//initialize stuff, including timer
while(1)
{
if (run == true)
{//start timer - interrupt points to timerISR()}
else
{//stop timer}
// poll GPIO, add data to "buffer"
if (sendflag == true)
{
OSLock();
//send data
sendflag = false;
OSUnlock();
}
}
}
void timerISR(void)
{
sendflag = true;
}
Will this be sufficient to accomplish what I'm asking? Sorry, I cannot post code this time - too much sensitive information in it at this point. Thanks guys!!
Ok, so I'm still having an issue... I have no timer interrupt coded yet, but it appears that the OSLock feature is not working. It is set up like my previous post.