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] [September 2012 Threads] A thread won't run?Posted by kuku2010 on September 17, 2012 I have two threads, A is at priority 3, B is at 4, both calls to xTaskCreate return pdPass.
A runs fine, but B doesn't even get its first line executed even though it has higher priority
What are the possible reasons?
RE: A thread won't run?Posted by MEdwards on September 17, 2012 What is configMAX_PRIORITIES set to? If it is set to 4, then priorities 0 to 3 are valid. That means task B will get its priority capped to 3, and both tasks will have the same priority. Even then, you would expect the tasks to time slice. Can you create very simple tasks that do nothing but increment a variable then delay? For example volatile int var1 = 0, var2 = 0; void aTask(void) { while(1){ var1++ vTaskDelay( 20 ); } }
void aSecondTask(void) { while(1){ var2++ vTaskDelay( 20 ); } }
Create one at priority 3 and the other at 4 as before and see if both var1 and var2 get incremented.
RE: A thread won't run?Posted by kuku2010 on September 17, 2012 configMAX_PRIORITIES is 9, so that's not the problem
Even the simplest task exactly like yours will not run
RE: A thread won't run?Posted by Richard on September 18, 2012 Which microcontroller and compiler are you using?
Is your tick interrupt running?
Are interrupts disabled when the tasks are running?
Regards.
RE: A thread won't run?Posted by kuku2010 on September 18, 2012 AVR32
I think the problem is memory, if I lower the stack (from 1024 to 256), it seems to run, but I am surprised that it didn't complain when it failed to allocate 1024 byte stack
RE: A thread won't run?Posted by Richard on September 18, 2012 “AVR32” Unless you are using ES marked chips, please ensure to use the FreeRTOS code from the Atmel ASF (http://asf.atmel.com). “but I am surprised that it didn't complain when it failed to allocate 1024 byte stack” If you are using heap_1, heap_2 or heap_4.c then a failed allocation will return NULL, and if you have configASSERT() defined, the null will trigger an assert. In any case, the task won't get created. If you are using heap_3.c then what happens is determined by the compilers C library. If the library just lets the heap run into the stack, then you will get random and very hard to debug crashes! Regards.
RE: A thread won't run?Posted by kuku2010 on September 18, 2012 indeed heap_c.c is used.
How to switch to others? any bad side effect?
RE: A thread won't run?Posted by kuku2010 on September 18, 2012 i meant
heap_3.c is used
RE: A thread won't run?Posted by Richard Damon on September 19, 2012 heap_1.c is built on the assumption that memory requested of it will never be given back, and thus can use a very simple control model. Thus a program that uses heap_1.c should never delete a task, queue, semaphore, etc.
heap_2.c is built to allow for deletion of memory, but does not defragment or merge blocks. This means that limited deleting and then recreating tasks, queues, semaphores, etc can work, but unless you are careful to be asking for the same sizes each time, you may run into memory fragmentation issues over time.
heap_3.c uses the library's malloc and free to get memory, This can still have issues with memory fragmentation is certain extreme situations, but if a few basic conditions can be met, this can be largely minimized.
Many embedded coding guidelines prohibit or severely limit the use of dynamic memory allocations (like malloc/free) during the operation of an embedded system (it may be allowed at startup, but after that generally no critical operation should depend on dynamic memory allocation), but instead use preallocated and saved buffers, so the limitations of heap_1.c may not be as bad as it might seem. I find the biggest issue with using heap_1.c or heap_2.c is the need to explicitly declair how much memory to allocate to it vs the malloc heap and the main program stack. This is just another design point that needs to be evaluated.
To do the switch, you just need to change which file is included in your project, and to make sure that your config file defines the needed values.
RE: A thread won't run?Posted by kuku2010 on September 19, 2012 Since lwIP is also in the picture and I have no clue how their memory management regarding FreeRTOS, I guess I have to stick with heap_3.c
Indeed, now I am seeing "random and very hard to debug crashes! "
:(
RE: A thread won't run?Posted by kuku2010 on September 21, 2012 How do I find out the status of a thread to see if it is terminated, blocked, suspended, etc?
RE: A thread won't run?Posted by MEdwards on September 21, 2012 That is an interesting question. This is something I do, but only because I have knowledge of the internals of FreeRTOS. The state of a task is known by the list it is referenced from, and the list it is reference from is known by looking at the generic list item in the tasks tcb. It would be good if there was an API function to do that. Can you add that to the feature request list.
For now, look at the function vTaskList(), And how the function is implemented. vTaskList returns a table that tells you, along with other things, the state that each task is in. It is in text though, so you would have to parse the table.
RE: A thread won't run?Posted by Richard on September 22, 2012 “How do I find out the status of a thread to see if it is terminated, blocked, suspended, etc?” I just added eTaskStateGet() to the head revision in SVN. INCLUDE_eTaskStateGet must be set to 1 in FreeRTOSConfig.h for the function to be available. http://freertos.svn.sourceforge.net/viewvc/freertos/trunk/FreeRTOS/Source/tasks.c?revision=1779&view=markup http://freertos.svn.sourceforge.net/viewvc/freertos/trunk/FreeRTOS/Source/include/task.h?revision=1779&view=markup Regards.
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|