FreeRTOS Sempahore from ISR not working

I need to create a device for collecting data, whose task is to sample some GPIO and record the status of the GPIO and send it to the PC via UART to display on the PC. The algorithm I chose was (please correct me since I am very new to RTOS) to create a timer running on 1us and then poll the status of all the necessary GPIOs. For this, I used the timer in the freertos demo. And give a semaphore in the ISR timer, which should trigger a task that performs the rest of the job.

I don’t know why, but the code I edited does not work

My main()

int main(void) {
  /* Prepare the hardware to run this demo. */
  prvSetupHardware();

  vSemaphoreCreateBinary(SemaphoreTask);
  if( SemaphoreTask != NULL )
  {
    xTaskCreate( SemaphoreTakeTask, "SemaphoreTakeTask", 240, NULL , 3, NULL );
    vTaskStartScheduler();
  }
  for(;;);
  return 0;
}

Task 1 is a dummy function that I wrote to try if the semaphore works

void SemaphoreTakeTask(void* parameter){
  vSetupTimerTest(10);                 // Timer initialization function in FreeRtos DEMO
  TRISEbits.TRISE6 = 0;                // Set the GPIO as Output
  xSemaphoreTake( SemaphoreTask, 0 );  // As mentioned in user guide just take the semaphore once to clear the semaphore at start
  for(;;){
    xSemaphoreTake( SemaphoreTask, portMAX_DELAY );
    LATEbits.LATE6 ^= 1;               // Toggle an IO to see whether its working
  }
}

ISR Timer Handler

void vT2InterruptHandler(void) {
  portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
  /* Clear the timer interrupt. */
  IFS0CLR = _IFS0_T2IF_MASK;
  xSemaphoreGiveFromISR(SemaphoreTask, &xHigherPriorityTaskWoken);
  if (xHigherPriorityTaskWoken != pdFALSE) {
    portEND_SWITCHING_ISR(xHigherPriorityTaskWoken);
  }
}

ISR, , GPIO ( 1)

Iam RTOS, , , -

ISR

, , xSemaphoreGiveFromISR. vAssertCalled

xSemaphoreTake() pdFALSE

+4
1

configMAX_SYSCALL_INTERRUPT_PRIORITY

, . SourceForge Forum

+3

Source: https://habr.com/ru/post/1523381/


All Articles