Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


Loading

FreeRTOS Sempahore from ISR not working

Posted by ableeldhose on January 23, 2014

I need to make a data accusition device whose one task is to samples some GPIO's and record the GPIO status and send it to PC via UART to display in PC. The algorithm i chose was (please correct me since iam very novice in RTOS) to create a timer running at 1us and then poll the status of all GPIO needed. For that i used a timer in the freertos demo. And give a semaphore in the timer ISR which should call a task which do all the remaining job.

Don't know why but the code i edited dont work

My main() is

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 a dummy function i wrote just to try out if semaphore is working

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
  }
}

Timer ISR 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);
  }
}

When i put break point in the ISR handler it comes there but the GPIO is not toggling (which i placed in Task 1)

Iam a novice in RTOS so please pardon me if i missed any basic things in the code

I just need to give a semaphore from ISR handler


FreeRTOS Sempahore from ISR not working

Posted by edwards3 on January 23, 2014

I cant see anything wrong with your use of the FreeRTOS API. You dont need to test xHigherPriorityTaskWoken before callilng portENDSWITCHINGISR as the test is in the macro, but it wont cause you a problem.

But do you really want to do this at 1uS. That is too fast to use a queue in this way. At that speed you need to do the IO sampling inside the interrupt handling function, even then it is very fast. You will need to pack the sampled bits into larger data variables to send at that rate over a uart.


FreeRTOS Sempahore from ISR not working

Posted by ableeldhose on January 24, 2014

@Medwards I added one extra task Task1 which just blinks another LED1 using vTaskDelay. Another task Task2 which waits for the semaphore and toggles an LED2 when recieved semaphore.

When Semaphore is given from the Task1 everything works fine.

When that semaphore is given from ISR which occurs after 5 second Untill the xSemaphoreGiveFromISR is called the Task1 is working, but when it is called everything gets stuck and the code moves to a infinite loop in vAssertCalled(). So for 5 seconds LED1 will toggle and after that its does not.

When i commented that xSemaphoreGiveFromISR in the ISR then Task1 is working without any issue

I placed a breakpoint just below the xSemaphoreGiveFromISR and the control never reach that line. When the xSemaphoreGiveFromISR is commented then control reaches there.

I cant understand the issue since iam a starter in RTOS


FreeRTOS Sempahore from ISR not working

Posted by rtel on January 24, 2014

Each call to configASSERT() contains a condition that is tested to ensure the system status (variable values, hardware state, etc.) is valid. As vAssertCalled() is being called then a condition passed to configASSERT() has been found to be invalid - which is presumably why your application is not working.

Which call to configASSERT() is failing?

Regards.


FreeRTOS Sempahore from ISR not working

Posted by ableeldhose on January 24, 2014

The configAssert() call from the below #define is found to get stuck

 portASSERT_IF_INTERRUPT_PRIORITY_INVALID();

The #define expansion is

 #define portASSERT_IF_INTERRUPT_PRIORITY_INVALID() configASSERT( portCURRENT_INTERRUPT_PRIORITY <= configMAX_SYSCALL_INTERRUPT_PRIORITY )

After this function call everything gets stuck. No task is running after this


FreeRTOS Sempahore from ISR not working

Posted by davedoors on January 24, 2014

You must set the priority of the interrupt to below your configMAXSYSCALLINTERRUPT_PRIORITY setting. Read the Configuration section of the web page that details how to use the port. THe following page might help (or serve to confuse more) too http://www.freertos.org/RTOS-Cortex-M3-M4.html


FreeRTOS Sempahore from ISR not working

Posted by ableeldhose on January 24, 2014

@Dave Thanks man It works


[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]


Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Renesas

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner