I created a small demo project for easy testing:
Two task: // Task 1 if (xTaskCreate(RTOSTask1, (signed char*) “[T1]”, configMINIMALSTACKSIZE*2, NULL, tskIDLEPRIORITY + 1, &hTask1) == errCOULDNOTALLOCATEREQUIREDMEMORY) { LREP(“rnCannot create Task 1.”); Display_Error(1000); } // Task 2 if (xTaskCreate(RTOSTask2, (signed char*) “[T2]”, configMINIMALSTACKSIZE*2, NULL, tskIDLEPRIORITY + 2, &hTask2) == errCOULDNOTALLOCATEREQUIREDMEMORY) { LREP(“rnCannot create Task 2.”); Display_Error(1000); }Implement of tasks: void RTOSTask1(void* pvParameter) { while(1) { if (xSemaphoreTake(hTask1Semaphore, portMAXDELAY) == pdTRUE) {
putchar1(‘1’); }
} } void RTOSTask2(void* pvParameter) { while(1) { if (xSemaphoreTake(hTask2Semaphore, portMAXDELAY) == pdTRUE) {
putchar1(‘2’); }
} } To let above two tasks running i use one Timer & one UART to give them Semaphores: void attribute((interrupt, auto_psv)) _T2Interrupt (void) {
_T2IF = 0;
static signed portBASE_TYPE xTaskWoken = pdFALSE;
xSemaphoreGiveFromISR(hTask1Semaphore, &xTaskWoken );
if( xTaskWoken != pdFALSE )
{
taskYIELD();
}
}
void attribute((interrupt, auto_psv)) _U1TXInterrupt()
{
_U1TXIF = 0;
putchar1('E');
}
void attribute((interrupt, auto_psv)) _U1RXInterrupt()
{
_U1RXIF = 0;
if(U1STAbits.URXDA == 1)
{
uint8 u8Recv = U1RXREG;
}
static signed portBASE_TYPE xTaskWoken;
xTaskWoken = pdFALSE;
xSemaphoreGiveFromISR(hTask2Semaphore, &xTaskWoken);
if( xTaskWoken != pdFALSE )
{
taskYIELD();
}
}
My Timer interrupts in every 100us, UART working at 230400 bps baudrate speed.
After running some second or minutes the program is crashed and the program jump to Traps: _AddressError or _StackError
I don’t know how this problem could happen. After a long investigating & testing i thought that the problem happen when the program running in & running out of the Interrupt service routine (ISR). It seems we need a couple of SAVECONTEXT() & RESTORECONTEXT() functions. but on PIC24 port there is no one like that. Please you kindly give me some advises for this problem Thank you all !