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

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 ]    [ 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