Quality RTOS & Embedded Software

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


Loading

How to call xTaskGetTickCount(); from isr?

Posted by Jaroslav Fojtik on May 15, 2008
Dears,

I have aattempted to call xTaskGetTickCount() inside ISR. It causes RTOS to crash after several successfull calls. I hope that reading a single value should not do this.

Jara

RE: How to call xTaskGetTickCount(); from isr?

Posted by Richard on May 15, 2008
It will crash because of the critical section used. You can:

1) Provide an new function xTaskGetTickCountFromISR() that does not use a critical section.
2) Remove the critical section if the tick count variable has a size that equals the word size of the architecture you are using.
3) Just make uxTickCount global.

Regards.

RE: How to call xTaskGetTickCount(); from isr

Posted by incrediball on May 18, 2008
I find your second suggestion interesting. This obviously works because incrementing the tick count variable is an atomic operation which cannot be interrupted. However, if this is a reasonable thing to do, why not optimize all the ports to do that?

RE: How to call xTaskGetTickCount(); from isr

Posted by ravaz on May 18, 2008
Incremnting a vairables is not an atomic operation because it's done in at least three instruction (load, increment and write back). Ovever the instruction xTaskGetTickCount is only reading the variable, and as said by richard if the processor as the same architecture size as the variable (ie both 32bits) this operation is atomic.

RE: How to call xTaskGetTickCount(); from isr

Posted by incrediball on May 21, 2008
Quite right. The early morning coffee hadn't fully worked when I wrote that. (Obviously the increment is not going to be interrupted either because it is done by the interrupt.) Anyway, my question is still much the same: if it is valid to read the tick counter (because the read operation is atomic), why not optimize all the relevant ports to do that?

RE: How to call xTaskGetTickCount(); from isr

Posted by Richard on May 21, 2008
The read is only atomic when the variable is the natural word size for the architecture. There is an option in FreeRTOS.org to use either 16bit or 32bit variables for the tick count (32bit giving you the ability to specify much longer block periods). An 8 or 16 bit device reading a 32bit tick count would not be atomic, hence the critical section.

Regards.

RE: How to call xTaskGetTickCount(); from isr

Posted by incrediball on May 22, 2008
I agree about the 8 and 16 bit devices, which is why I said "all the relevant ports". For all the 32 bit devices such as AT91SAM7, etc the critical section could be excluded (and in any other relevant places).

What actually happens if the variable is smaller than the natural word size? For example if the option to use 16 bit tick counts is used on the AT91SAM7, is that still atomic? It seems that 16 bit variables don't seem to be handled as well by the ARM and the compiler usually produces larger code.

RE: How to call xTaskGetTickCount(); from isr

Posted by Jaroslav Fojtik on May 23, 2008
Thank you very much for your reply. I suspected somethink like this. As far as 32 bit CPU has been used, critical section is not needed. I will prefer solution 1.

Jara


[ 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