# One of eleven tasks running for a while and stopped in version 7.6

**URL:** <https://forums.freertos.org/t/one-of-eleven-tasks-running-for-a-while-and-stopped-in-version-7-6/731>\
**Category:** Kernel\
**Created:** [May 5, 2014, 1:24pm UTC](https://forums.freertos.org/t/one-of-eleven-tasks-running-for-a-while-and-stopped-in-version-7-6/731 "2014-05-05T13:24:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [May 5, 2014, 1:24pm UTC](https://forums.freertos.org/t/one-of-eleven-tasks-running-for-a-while-and-stopped-in-version-7-6/731/1 "2014-05-05T13:24:16Z")

</div>

**[huzhiping](https://sourceforge.net/u/huzhiping/)** wrote on [Monday, May 05, 2014](https://sourceforge.net/p/freertos/discussion/382005/thread/2011328d/#94a7):

I used FreeRTOS 7.6 in My project and it uses 11 tasks, priorities are from 2, 3,…8, and all tasks are non-preemptive task. Most of the time the priority task 3 running for about 20~ 30 times, then stopped, but other tasks still running and no problem. Few times, priority task 7 stopped but priority task 3 and the rest of the tasks run fine. I used “#define configCHECK\_FOR\_STACK\_OVERFLOW 2” and it never hit the stack overflow hook function. so it seems not a stack issue.

Does anyone meet the same issue before? I am trying to debug the issue, not successfully yet.

Since the OS schedule runs fine, how can this is possible? Although each task is a “for ever loop”, but when I debug it, it never went into the task that stopped.

Does anyone know which list in the source is for all the tasks? I also used “pxCurrentTCB” watch the current task running.

Thanks for your help in advance!

Albert

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [May 5, 2014, 2:07pm UTC](https://forums.freertos.org/t/one-of-eleven-tasks-running-for-a-while-and-stopped-in-version-7-6/731/2 "2014-05-05T14:07:31Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Monday, May 05, 2014](https://sourceforge.net/p/freertos/discussion/382005/thread/2011328d/#d74b):

I’m afraid your question is too general in its nature to be able to offer more than a guess. Especially as you are the only person with the application code in front of you, and presumably the problem lies somewhere within the application, or the configuration of the kernel.

Which chip are you using (I really wish people would not leave out this vital information when posting: [http://www.freertos.org/FAQ-how-to-use-the-FreeRTOS-support-forum.html](http://www.freertos.org/FAQ-how-to-use-the-FreeRTOS-support-forum.html))  
Have you read through the points here: [http://www.freertos.org/FAQHelp.html](http://www.freertos.org/FAQHelp.html)

Regards.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [May 5, 2014, 4:04pm UTC](https://forums.freertos.org/t/one-of-eleven-tasks-running-for-a-while-and-stopped-in-version-7-6/731/3 "2014-05-05T16:04:45Z")

</div>

**[huzhiping](https://sourceforge.net/u/huzhiping/)** wrote on [Monday, May 05, 2014](https://sourceforge.net/p/freertos/discussion/382005/thread/2011328d/#b2b4):

Sorry for the information missing.

I am using v850 and GreenHills compiler.

I just want to get some suggestion to get the direction to debug. I knew somehting must be wrong, and hope it is in application.

some questions are that:

1. if the configuration of the kernel is wrong, the rest of the tasks will not run good. Stack also didn’t go to overflow.
2. if the RTOS is good, how can this task will stop after running for a while? even the low priority task can still be running. but it never hit the breakpoint of this task when it stopped.
3. this task didn’t purposely set to be deleted and suspended, and it sometimes still runs fine. if the application code has issue, it possibly make the memory or stack leaking and then cause reset, but seems it is not in this case. Can something cause this task to be suspended?

I attached the “FreeRTOSConfig.h”. And hope to get some suggestions.

Thanks.

Albert

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [May 5, 2014, 4:53pm UTC](https://forums.freertos.org/t/one-of-eleven-tasks-running-for-a-while-and-stopped-in-version-7-6/731/4 "2014-05-05T16:53:39Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Monday, May 05, 2014](https://sourceforge.net/p/freertos/discussion/382005/thread/2011328d/#91db):

Well there is no official V850 port for the Green Hills compiler, so I cannot vouch that the code kernel code is correct or not, or offer advice on how to configure it.

Can you cut down the code in the offending task to the absolute minimum that still exhibits this behaviour, then post the code here. When doing so please use the following link to convert the code into tidy html code as this forum software is (ironically) absolutely atrocious at displaying source code: [http://hilite.me/](http://hilite.me/)

Regards.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [May 5, 2014, 7:55pm UTC](https://forums.freertos.org/t/one-of-eleven-tasks-running-for-a-while-and-stopped-in-version-7-6/731/5 "2014-05-05T19:55:37Z")

</div>

**[huzhiping](https://sourceforge.net/u/huzhiping/)** wrote on [Monday, May 05, 2014](https://sourceforge.net/p/freertos/discussion/382005/thread/2011328d/#49de):

I think my porting code has issue. When I change the OS tasks to preemptive (by setting “#define configUSE\_PREEMPTION 1” in FreeRTOSConfig.h), all the tasks works fine, if changed back to non-preemptive, then the issue occurred.  
the following is my porting code for v850 and using GHS compiler.

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
#include \<df3580\_IRQ.h\>  
#include “FreeRTOSConfig.h”

* * *

## – Functions used by scheduler

.extern \_vTaskSwitchContex  
.extern \_xTaskIncrementTick

## – Variables used by scheduler

.extern \_pxCurrentTCB  
.extern \_usCriticalNesting

## – Functions implemented in this file

.global \_vPortYield  
.global \_vPortStart

* * *

## ------------- Basic Initialisation of the controller ------------- User modifiable section

.weak \_\_\_lowinit  
.text  
\_RESET:  
– Initialisation of the global pointer  
movhi hi(\_\_\_ghsbegin\_sdabase),zero,gp  
movea lo(\_\_\_ghsbegin\_sdabase),gp,gp

– Initialisation of the text pointer  
movhi hi(\_\_\_ghsbegin\_robase),zero,tp  
movea lo(\_\_\_ghsbegin\_robase),tp,tp

– Initialisation of the stack pointer  
movhi hi(\_\_\_ghsend\_stack-4),zero,sp  
movea lo(\_\_\_ghsend\_stack-4),sp,sp  
mov -4,r1  
and r1,sp

## – Jump to the HW Initialisation function jarl \_\_\_lowinit, lp – Jump to the Initialisation functions of the library, – from there to main() jr \_\_start

* * *

## ------------- Interrupt service routine of unused interrupts .global \_\_unused\_isr \_\_unused\_isr: br \_\_unused\_isr

* * *

## – portSAVE\_CONTEXT MACRO – Saves the context of the remaining general purpose registers – and the usCriticalNesting Value of the active Task onto the task stack – saves stack pointer to the TCB

## .macro portSAVE\_CONTEXT prepare {r20,r21,r22,r23,r24,r25,r26,r27,r28,r29,r30},19,sp – save general purpose registers st.w r19,72[ep] st.w r18,68[ep] st.w r17,64[ep] st.w r16,60[ep] st.w r15,56[ep] st.w r14,52[ep] st.w r13,48[ep] st.w r12,44[ep] st.w r11,40[ep] st.w r10,36[ep] st.w r9,32[ep] st.w r8,28[ep] st.w r7,24[ep] st.w r6,20[ep] st.w r5,16[ep] st.w r4,12[ep] st.w r2,8[ep] st.w r1,4[ep] movhi hi(\_usCriticalNesting),r0,r1 – save usCriticalNesting value to stack ld.w lo(\_usCriticalNesting)[r1],r2 sst.w r2,0[ep] movhi hi(\_pxCurrentTCB),r0,r1 – save SP to top of current TCB ld.w lo(\_pxCurrentTCB)[r1],r2 st.w sp,0[r2] .endm

* * *

## – portRESTORE\_CONTEXT MACRO – Gets stack pointer from the current TCB – Restores the context of the usCriticalNesting value and general purpose – registers of the selected task from the task stack

.macro portRESTORE\_CONTEXT  
movhi hi(\_pxCurrentTCB),r0,r1 – get Stackpointer address  
ld.w lo(\_pxCurrentTCB)[r1],sp  
mov sp,r1  
ld.w 0[r1],sp – load stackpointer  
mov sp,ep – set stack pointer to element pointer  
sld.w 0[ep],r1 – load usCriticalNesting value from stack  
movhi hi(\_usCriticalNesting),r0,r2  
st.w r1,lo(\_usCriticalNesting)[r2]  
ld.w 4[ep],r1 – restore general purpose registers  
ld.w 8[ep],r2  
ld.w 12[ep],r4  
ld.w 16[ep],r5  
ld.w 20[ep],r6  
ld.w 24[ep],r7  
ld.w 28[ep],r8  
ld.w 32[ep],r9  
ld.w 36[ep],r10  
ld.w 40[ep],r11  
ld.w 44[ep],r12  
ld.w 48[ep],r13  
ld.w 52[ep],r14  
ld.w 56[ep],r15  
ld.w 60[ep],r16  
ld.w 64[ep],r17  
ld.w 68[ep],r18  
ld.w 72[ep],r19

```
dispose 19,{r20,r21,r22,r23,r24,r25,r26,r27,r28,r29,r30}

```

## .endm

* * *

– Restore the context of the first task that is going to run.

– Input: NONE

– Call: CALL vPortStart

## – Output: NONE

## \_vPortStart: portRESTORE\_CONTEXT – Restore the context of whichever task the … ld.w 0[sp],lp ldsr lp,5 – restore PSW di ld.w 4[sp],lp – restore LP ld.w 8[sp],lp – restore LP add 0x0C,sp – set SP to right position ei jmp [lp]

* * *

– Port Yield function to check for a Task switch in the cooperative and  
– preemptive mode

– Input: NONE

– Call: CALL vPortYield

## – Output: NONE

\_vPortYield:

```
add -0x0C,sp -- prepare stack to save necessary values
st.w lp,8[sp] -- store LP to stack
stsr 0,r31
st.w lp,4[sp] -- store EIPC to stack
stsr 1,lp
st.w lp,0[sp] -- store EIPSW to stack
portSAVE_CONTEXT -- Save the context of the current task.
jarl _vTaskSwitchContext,lp -- Call the scheduler.
portRESTORE_CONTEXT -- Restore the context of whichever task the ...
            		            -- ... scheduler decided should run.
ld.w 0[sp],lp -- restore EIPSW from stack
ldsr lp,1
ld.w 4[sp],lp -- restore EIPC from stack
ldsr lp,0
ld.w 8[sp],lp -- restore LP from stack
add 0x0C,sp -- set SP to right position

reti

```

* * *

* * *

– Perform the necessary steps of the Tick Count Increment and Task Switch  
– depending on the chosen kernel configuration

– Input: NONE

– Call: ISR

## – Output: NONE

#if configUSE\_PREEMPTION == 1 /\* use preemptive kernel mode\*/

\_INTOSTM0:

```
add -0x0C,sp -- prepare stack to save necessary values
st.w lp,8[sp] -- store LP to stack
stsr 0,r31
st.w lp,4[sp] -- store EIPC to stack
stsr 1,lp
st.w lp,0[sp] -- store EIPSW to stack
portSAVE_CONTEXT -- Save the context of the current task.
jarl _xTaskIncrementTick,lp -- Call the timer tick function.
jarl _vTaskSwitchContext,lp -- Call the scheduler.
portRESTORE_CONTEXT -- Restore the context of whichever task the ...
            		            -- ... scheduler decided should run.
ld.w 0[sp],lp -- restore EIPSW from stack
ldsr lp,1
ld.w 4[sp],lp -- restore EIPC from stack
ldsr lp,0
ld.w 8[sp],lp -- restore LP from stack
add 0x0C,sp -- set SP to right position

reti

```

* * *

#else /\* use cooperative kernel mode\*/

\_INTOSTM0:

```
prepare {lp,ep},8,sp
sst.w r1,4[ep]
sst.w r5,0[ep]
jarl _xTaskIncrementTick,lp -- Call the timer tick function.
sld.w 0[ep],r5
sld.w 4[ep],r1
dispose 8,{lp,ep}

reti

```

#endif /\* configUSE\_PREEMPTION \*/

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

my FreeRTOSConfig.h as follows:

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
#ifndef FREERTOS\_CONFIG\_H  
#define FREERTOS\_CONFIG\_H

/\* only include in C files _/  
//#ifdef **IAR\_SYSTEMS\_ICC**  
// #pragma language=extended  
// #pragma system\_include  
// #include \<intrinsics.h\>  
//#endif /_ **IAR\_SYSTEMS\_ICC** \*/

/\* V850ES/Fx3 Memory Model

- 1 = Tiny data model
- 0 = Small/Large data model  
\*/  
#define configDATA\_MODE 0

/\*

- Application specific definitions.
- 
- These definitions should be adjusted for your particular hardware and
- application requirements.
- 
- THESE PARAMETERS ARE DESCRIBED WITHIN THE ‘CONFIGURATION’ SECTION OF THE
- FreeRTOS API DOCUMENTATION AVAILABLE ON THE [FreeRTOS.org](http://FreeRTOS.org) WEB SITE.  
\*/

#define configUSE\_PREEMPTION 0  
#define configUSE\_PORT\_OPTIMISED\_TASK\_SELECTION 0  
#define configUSE\_TICKLESS\_IDLE 0  
#define configCPU\_CLOCK\_HZ 20000000  
#define configTICK\_RATE\_HZ 1000  
#define configMAX\_PRIORITIES 9  
#define configMINIMAL\_STACK\_SIZE 75  
#define configTOTAL\_HEAP\_SIZE 10240  
#define configMAX\_TASK\_NAME\_LEN 22  
#define configUSE\_16\_BIT\_TICKS 0  
#define configIDLE\_SHOULD\_YIELD 0  
#define configUSE\_MUTEXES 0  
#define configUSE\_RECURSIVE\_MUTEXES 0  
#define configUSE\_COUNTING\_SEMAPHORES 0  
#define configUSE\_ALTERNATIVE\_API 0 /\* Deprecated! \*/  
#define configQUEUE\_REGISTRY\_SIZE 0  
#define configUSE\_QUEUE\_SETS 0  
#define configUSE\_TIME\_SLICING 0  
#define configUSE\_NEWLIB\_REENTRANT 0

/\* Hook function related definitions. \*/  
#define configUSE\_IDLE\_HOOK 0  
#define configUSE\_TICK\_HOOK 0  
#define configCHECK\_FOR\_STACK\_OVERFLOW 2  
#define configUSE\_MALLOC\_FAILED\_HOOK 0

/\* Run time and task stats gathering related definitions. \*/  
#define configGENERATE\_RUN\_TIME\_STATS 0  
#define configUSE\_TRACE\_FACILITY 0  
#define configUSE\_STATS\_FORMATTING\_FUNCTIONS 0

/\* Co-routine related definitions. \*/  
#define configUSE\_CO\_ROUTINES 0  
#define configMAX\_CO\_ROUTINE\_PRIORITIES 0

/\* Software timer related definitions. _/  
/_#define configUSE\_TIMERS 1  
#define configTIMER\_TASK\_PRIORITY 3  
#define configTIMER\_QUEUE\_LENGTH 10  
#define configTIMER\_TASK\_STACK\_DEPTH configMINIMAL\_STACK\_SIZE  
_/  
/_ Interrupt nesting behaviour configuration. \*/  
//#define configKERNEL\_INTERRUPT\_PRIORITY 1  
//#define configMAX\_SYSCALL\_INTERRUPT\_PRIORITY 3  
//#define configMAX\_API\_CALL\_INTERRUPT\_PRIORITY 7

/\* Define to trap errors during development. \*/  
//#define configASSERT (( x )) if(( x )== 0) vAssertCalled( **FILE** , **LINE** )

/\* FreeRTOS MPU specific definitions. \*/  
#define configINCLUDE\_APPLICATION\_DEFINED\_PRIVILEGED\_FUNCTIONS 0

/\* Optional functions - most linkers will remove unused functions anyway. \*/  
#define INCLUDE\_vTaskPrioritySet 0  
#define INCLUDE\_uxTaskPriorityGet 0  
#define INCLUDE\_vTaskDelete 1  
#define INCLUDE\_vTaskSuspend 0  
#define INCLUDE\_xResumeFromISR 0  
#define INCLUDE\_vTaskDelayUntil 0  
#define INCLUDE\_vTaskDelay 1  
#define INCLUDE\_xTaskGetSchedulerState 0  
#define INCLUDE\_xTaskGetCurrentTaskHandle 0

#define INCLUDE\_uxTaskGetStackHighWaterMark 0

#define INCLUDE\_xTaskGetIdleTaskHandle 0  
#define INCLUDE\_xTimerGetTimerDaemonTaskHandle 0  
#define INCLUDE\_pcTaskGetTaskName 0  
#define INCLUDE\_eTaskGetState 0

/\* A header file that defines trace macro can be included here. \*/

#endif /\* FREERTOS\_CONFIG\_H \*/

The difference between preemptive and non-preemptive is that in preemptive, each os tick, it call the OS scheduler, but non-preemptive not.

in my task application code as follows:

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
void vTask\_SYS\_EEPROM(void \*pvParameters)  
{  
for(;😉  
{  
EE\_WriteManager();

#ifndef RELEASE  
/\* Get the not used stack size of this task \*/  
EEPROMFreeStack = (unsigned portSHORT)uxTaskGetStackHighWaterMark( NULL );  
EEPROMFreeStackPercent = StackPercentage(EEPROMSTACK, EEPROMFreeStack);  
#endif

```
	/* relative 10 ms cycle time of this task */
	vTaskDelay(TASKTIME_10MS / portTICK_RATE_MS);

}

```

}

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

I doubt the function “vTaskDelay(10ms)” do something make the task lost.  
I have to use all my tasks to be non-preemptive.

In function “vTaskDelay(xx)” has the following code:

…  
…  
xAlreadyYielded = xTaskResumeAll();  
}

```
	/* Force a reschedule if xTaskResumeAll has not already done so, we may
	have put ourselves to sleep. */
	if( xAlreadyYielded == pdFALSE )
	{
		portYIELD_WITHIN_API();
	}

```

Theoretically when calling “portYIELD\_WITHIN\_API()”, it will call “\_vPortYield()” in the upper porting code and do OS reschedule (“trap0” is link to “\_vPortYield”), but it looks like not always occurred, or maybe “xAlreadyYielded != pdFALSE” in non-preemptive kernel mode.

Any suggestions?

Thanks a lot!

Albert
