Upgrading from V4.1.3 to V5.0.3 for dsPic
Posted by
dennis on December 30, 2008
I am trying to switch from V4.1.3 to V5.0.3 for dsPIC port. When I do so, I found the following code changes:
The code in V4.1.3 used to be:
#define portINTERRUPT_BITS( 0x00e0 )
#define portDISABLE_INTERRUPTS()SR |= portINTERRUPT_BITS
#define portENABLE_INTERRUPTS()SR &= ~portINTERRUPT_BITS
Now in V5.0.3, the code becomes:
#define portINTERRUPT_BITS( ( unsigned portSHORT ) configKERNEL_INTERRUPT_PRIORITY << ( unsigned portSHORT ) 5 )
#define portDISABLE_INTERRUPTS()SR |= portINTERRUPT_BITS
#define portENABLE_INTERRUPTS()SR &= ~portINTERRUPT_BITS
I don't quite understand why in V5.0.3, portINTERRUPT_BITS depends on configKERNEL_INTERRUPT_PRIORITY. In doing so, isn't it correct to say that: critical tasks are not be protected from interrupts whose priority is greater than configKERNEL_INTERRUPT_PRIORITY?
For example, if configKERNEL_INTERRUPT_PRIORITY = 0x01 (by default),
void
foo(void)
{
taskENTER_CRITICAL();
//do something
//do something //<-- may be interrupted by ISR
//do something224
taskEXIT_CRITICAL();
}
If I want to shield all interrupts, then I need to set portINTERRUPT_BITS to 0x07, and change the #32 in vPortYeild in portasm_dsPIC.S to #224, right?
Many thanks.
Dennis
RE: Upgrading from V4.1.3 to V5.0.3 for dsPic
Posted by
Dave on December 30, 2008
Take a look at the following links:
For configKERNEL_INTERRUPT_PRIORITY
http://www.freertos.org/a00110.html#kernel_priority
http://www.freertos.org/portpic24_dspic.html ("configuration and usage details section")
For converting to 5.x
http://www.freertos.org/upgrading.html
RE: Upgrading from V4.1.3 to V5.0.3 for dsPic
Posted by
dennis on January 5, 2009
Thank you for the information.
May I just confirm with you my understanding that:
A task critical section (taskENTER_CRITICAL(), taskEXIT_CRITICAL(), taskDISABLE_INTERRUPTS(), taskENABLE_INTERRUPTS()) can now be interrupted by interrupts that are set above the kernel interrupt priority.
And, if I really want to exclude all interrupts from a section of code, I need to create my own API such as:
#define portINTERRUPT_BITS ( 0x00e0 )
#define cli() SR |= portINTERRUPT_BITS
#define sti() SR &= ~portINTERRUPT_BITS
void
foo(void)
{
cli(); //clear interrupt
//do something
//do something //<-- may be interrupted by ISR
//do something
sti(); //set interrupt
}
RE: Upgrading from V4.1.3 to V5.0.3 for dsPic
Posted by
Dave on January 5, 2009
I'm not sure if the taskENABLE/DISABLE_INTERRUPTS() macros will completely disable and enable all interrupts or not, you will have to check their definition. Normally these macros are not used directly because they don't keep track of the nesting depth like the ENTER/EXIT_CRITICAL() macros do.
If you want all interrupts to be disabled all the time then set configMAX_SYSCALL_INTERRUPT_PRIORITY to be the highest priority there is. Otherwise, if the other macros don't do what you want, then you can declare your own as you say.