- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Is somebody else having problem with the gmtime() function after the PSoC Creator 3.1 upgrade? The code below is not completing as the gmtime() function is never returning. It used to work fine before the update...
#include <project.h> #include <time.h> /*! * Starts the Application. */ int main() { time_t seconds = 1420663532; struct tm *ts = gmtime(&seconds); return 0; }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It is always difficult to answer a question unless we see your whole project. Do a File >> Create Workspace Bundle >>
and attach the zip file.
Of course, it is also helpful to strip out non-relevant parts of the project. And we do understand that you do not want to share proprietary code.
Also, share what platform you are using PSoC 3 or PSoC5.
kind regards,
Jerry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Another question: how do you determine that the function doesn't return? There is no effective code after its call, so you might just run into the debugger not showing the next step. Try to do something meaningful afterwards (e.g. toggling a LED).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
More info about the problem:
I had the gmtime() call running in some place deep in my code. Using the debug I was able to determine that when the function was not returning. Actually, it got stuck into a call to a internal function called the mktm_r(). The code I sent is not my real code, its just to illustrate the problem. If you create a PSoC5 project and put that code in the main(), the issue will happen all the same.
Anyway, to anyone who is having the same problem, I've found a workaround. You just have to change the gmtime() function to the gmtime_r() function like the code below:
#include <project.h> #include <time.h> /*! * Starts the Application. */ int main() { time_t seconds = 1420663532; struct tm ts; gmtime_r(&seconds, &ts); return 0;}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you for sharing your solution. That's what this forum is about. Sharing our knowledge. I learned something from you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@hli, Could he have used the debugger's Step Into instead of Step Over to get inside the function? I did not actually try this code but I find that when I use (other projects) the Step Into or the equivalent function key, I can see what's going on inside the function.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Since the gmtime function is just available from a library, there is no source code available. So you cannot step into it while using the C code, you would need to step through the assembler code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
One change in Creator 3.1 that might cause this is the reduction of the default heap size. It was mentioned in another thread that the reduction from 256 to 128 bytes caused problems with printf().
Since gmtime() uses a shared memory structure, maybe its allocating heap memory on the first call? gmtime_r uses memory provided by the caller, so in your code thats memory from the stack. You can try to increase the heap and see whether it works now.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Additionally you could check where the program freezes. There is an infinite loop executed when any severe error occurs. Run the program and then stop execution in debugger. Have a look at the code and the call stack.
Bob