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] [August 2013 Threads] Global xSemaphoreHandle corruptedPosted by Fabien on August 8, 2013 Hi all,
I use xSemaphoreHandle as global variable in my program. Declaration is the next: xSemaphoreHandle xComSemaphore in main.c extern xSemaphoreHandle xComSemaphore in all other .c files.
I check its value when I create it: vSemaphoreCreateBinary( xComSemaphore); But in my interrupts file, when I check its value in next function xSemaphoreGiveFromISR(xComSemaphore, &xHigherPriorityTaskWoken ); I saw that the value was different from the one during creation.
For information, I don't use any Compiler optimization.
I know that xSemaphoreHandle is a pointer to a xQUEUE structure, but I don't understand why this value had change? Is it forbidden to use global variable for xSemaphoreHandle?
Thanks for your help.
RE: Global xSemaphoreHandle corruptedPosted by Richard on August 8, 2013 “Is it forbidden to use global variable for xSemaphoreHandle?” It is just a variable, like any other variable. The compiler has no knowledge of the kernel, so there is no way the kernel could impose any restriction on where or how the variable is defined. The rules for defining them are just the same as for defining any other C variable, and your extern declaration should not be a problem. I assume, as your program links, you have declared the variable at file scope, and not on the stack of a C function (which would be wrong, because when the function returns the stack is removed so the variable no longer exists). I would guess this is just a simple RAM corruption somewhere, maybe caused by an incorrect linker script, or a stack overflow, or something similar. Do you have stack overflow checking turned on? If you have a fancy CPU and debugger then you should be able to set a data watch point on the variable and have the debugger automatically break at the point where the variable is written to. Failing that, simply add the variable to a watch window, then step through the code until you find the value of the variable inexplicably changing to try and determine what is writing over it. Regards.
RE: Global xSemaphoreHandle corruptedPosted by Fabien on August 8, 2013 Hi Richard,
One more time, you help me a lot. I added a data watch point I saw that a I tried to write inside a array smaller than my index and overwrite the semaphore...
Thanks for your feedback. Fabien
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|