FreeRTOS Support Archive
The FreeRTOS support forum is used to obtain active support directly from Real
Time Engineers Ltd. In return for using our top quality software and services for
free, we request you play fair and do your bit to help others too! Sign up
to receive notifications of new support topics then help where you can.
This is a read only archive of threads posted to the FreeRTOS support forum.
The archive is updated every week, so will not always contain the very latest posts.
Use these archive pages to search previous posts. Use the Live FreeRTOS Forum
link to reply to a post, or start a new support thread.
[FreeRTOS Home] [Live FreeRTOS Forum] [FAQ] [Archive Top] [May 2008 Threads] 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 isrPosted 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 isrPosted 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 isrPosted 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 isrPosted 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 isrPosted 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 isrPosted 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
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|