willywortel wrote on Tuesday, March 31, 2009:
1////
When to use volatile? Is it better to use it always when making a variable global?
Do semaphore and queue’s variables need to be stated volatile?
2////
I’m working on the PIC32 platform, and the pic32 has multivector interrups.
Now in the datasheet they are mentioning that the right ipl (interrupt priority) should be mentioned in the function call (see below, this part: interrupt(ipl1) )
/* The timer 2 interrupt handler. */
void __attribute__( (interrupt(ipl0), vector(_TIMER_2_VECTOR))) vT2InterruptWrapper( void );
But what is the difference? I only see that ipl7 uses a special, dedicated, stack but for the rest, i don’t know.
I`m asking this for this second question:
This timer2 interrupt is used to count 10uS above max_syscall_priority. So if i`m correctly I may not use any FROM_ISR functions defined by the OS.
But, at sertain times I want that this timer2 calls some FROM_ISR functions. So i thought that i change the interrupt priority "on the fly" to a priority below max_syscall_priority (inside the timer2 ISR) so that the next timer2 ISR may call functions from the OS.
Is this safe to do? I need this timer for my modbus communications used in another task.
So i want to give a semaphore inside the timer2 after a specified time.
3////
Another thing that i’m having now is that the OS, with 6 task and ADC, RS232, timer2 fully interrupt based.
Is freezing after usually a day or so. But it happends only when I`m not using the debugger (RealIce),
only when I set the compiler to “release” the freezes happens. I checked to be sure that no optimizes
are set in the compiler so i think this cannot be the problem.
I don’t know where to search for. I`m pretty sure that it is not a stack problem since I use
an character display that continuesly displays the stack from all the tasks. I’ve never encountered a
stack that reached less than 100 in any of the tasks.
The only thing that i can think off is the predifined DMA functions from microchip
that
i need to calculate the CRC. I used it on this way:
taskENTER_CRITICAL();
for(crcIterationCalculation = 0; crcIterationCalculation != 4; crcIterationCalculation++)
{
mCrcSetSeed(0xffff); // re-seed the CRC generator to start from exactly the same conditions
res = DmaChnMemCrc(&localCalculatedCrc, &modbusFrame[0], (modbusFrameLength - 2), DMA_CHN, DMA_CHN_PRI2);
// if transfer succeed, break the loop
if (res == DMA_TXFER_OK){ break; };
}
taskEXIT_CRITICAL();
Is this OK to do?
4////
Is it safe to do the following in the RS232 interrupt that is below max_syscall_priority:
setError = 1;
and read it out in a task just like this:
if (setError == 1)
{
// code
}
where setError is a volatile portLONG variable
And vice versa (task sets setError, interrupt reads it out)
5///
Another question is about clearing interrupt flags. In a datasheet from the PIC32 they are mentioning to:
You should clear the interrupt request flag as soon as you enter the routine. Handlers
that service more than one interrupt request flag can copy the interrupt request flags into a local
variable, clear the IFS register, and then service the request.
In the demo I never see that this is done. Do I need to do it like mentioned in the datasheet or
doesn’t it really matter?
///