Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training




Loading

ISR to take/give binary semaphore to pause task execution?

Posted by pugglewuggle on January 8, 2015

I'm trying to pause/run execution of a task based on toggling from an interrupt (push button). I thought using a binary semaphore for this would make sense so I created my ISR to use either SemaphoreGiveFromISR() and xSemaphoreTakeFromISR() based on the value of a flag, isRunning. Within the task's for loop I start with if(xSemaphoreTake(handle) == pdTRUE)........ and end with xSemaphoreGive(handle). This does not work... I can see that the give starts the task running but the take doesn't do anything (returns pdFALSE). I suspect this is because when the ISR runs the semaphore is actually held by the task and I interrupted the task in the middle of execution, therefore the ISR wouldn't be able to take it.

However, the task MUST finish its execution cycle (code within the for loop) completely or the hardware I'm working with will be left in an inconsistent state the next time the task was able to run. Because of this, even if the ISR were able to stop the task from running, it should only be able to stop it if all execution of the for loop has completed. I'm still trying to wrap my mind around this so any suggestions of a better way to do this or explanations would be great!


ISR to take/give binary semaphore to pause task execution?

Posted by richard_damon on January 8, 2015

You could have the task take the semaphore and then immediately give it back, thus the only point where the ISR couldn't pause the task is that small window.

The other option is just use the global variable isRunning, and if it is clear, pend on the semaphore, and if set just keep will. Then the ISR to stop the task clears isRunning, and to start running sets isRunning and gives the semaphore to restart the task if it is pending on it.


ISR to take/give binary semaphore to pause task execution?

Posted by pugglewuggle on January 8, 2015

Can you please explain the second part?


ISR to take/give binary semaphore to pause task execution?

Posted by richard_damon on January 9, 2015

Global variable run and semaphore seem.

ISR to stop running: run = 0;

ISR to resume running: run = 1; give seem;

Task at the top of the loop:

while(!run) wait for sema;


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




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

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

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

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

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists