I already used FreeRTOS for some embedded projects for some year time and It worked really perfectly until now. Currently i'm facing a difficult problem related to using High Speed Interrupt in FreeRTOS porting to PIC24H, hope you all can help me to though this problem. Thanks in advance
I created a small demo project for easy testing:
Two task:
// Task 1
if (xTaskCreate(RTOSTask_1, (signed char) "[T1]", configMINIMAL_STACK_SIZE2, NULL, tskIDLE_PRIORITY + 1, &hTask1) == errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY)
{
  LREP("\r\nCannot create Task 1.");   
  Display_Error(1000);
}
// Task 2
if (xTaskCreate(RTOSTask_2, (signed char) "[T2]", configMINIMAL_STACK_SIZE2, NULL, tskIDLE_PRIORITY + 2, &hTask2) == errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY)
{
  LREP("\r\nCannot create Task 2."); 
  Display_Error(1000);  
}
Implementation of tasks:
void RTOSTask_1(void* pvParameter)
{ 
  while(1)
  {
    if (xSemaphoreTake(hTask1Semaphore, portMAX_DELAY) == pdTRUE)
    { 
      putchar1('1');
    } 
  }
}
void RTOSTask_2(void* pvParameter)
{
  while(1)
  {
    if (xSemaphoreTake(hTask2Semaphore, portMAX_DELAY) == 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 SAVE_CONTEXT() & RESTORE_CONTEXT() functions. but on PIC24 port there is no one like that.
Please you kindly give me some advises for this problem
Thank you all !
I already find out my problem, i think. The problem is introduced when the PIC24H gets in & gets out Interrupt Service Routines, here they are UART RX, TX, Timer Interrupts.
Currently i don't use the ISR like this:
void attribute((interrupt, auto_psv))
instead of it i created a mechanism myself with Assembly code:
__U1RXInterrupt: ; Push CPU registers in to Stack
    PUSH    SR          
PUSH    W0
PUSH    W1          
PUSH.D  W2
PUSH.D  W4
PUSH.D  W6
PUSH.D  W8
PUSH.D  W10
PUSH.D  W12
PUSH    W14
PUSH    RCOUNT
PUSH    TBLPAG
PUSH    CORCON
PUSH    PSVPAG
    ; Call my ISR
    call _UART1_RxISRHandler        
    ; Pop out CPU registers
POP PSVPAG
POP CORCON
POP TBLPAG
POP RCOUNT                  
POP W14
POP.D   W12
POP.D   W10
POP.D   W8
POP.D   W6
POP.D   W4
POP.D   W2
POP.D   W0
POP SR
retfie      
UART1_RxISRHandler is my implement of ISR. I do the same with TX, Timer interrupts.
The result is that my program run more smoothly, longer 1 hour (before the program crash after 1-5 minutes only). But at the end it still crash after running 1-2 hours. That means my approach is correct but still there is something wrong. May be i miss something with above code.
If you all have any ideal for this situation, please let me know.
Thanks
 
     
     
     
     
    