ARM CortexM3

Hi, In ARM Cortex-M3 ti stellaris board, i observed that with out yielding the task another task is not getting scheduled.vportpend handler gets called only when we put the delay in the task which is yielding. With out keeping delay, the another task not at all scheduling.Why? How the vportSVC handler gets called every time tick,svc 0 gets called only once in the start first task. Please could you clarify me the above. Regards,

ARM CortexM3

What are the priorities of the tasks. If you don’t block the RTOS will only ever select tasks that have a higher or the same priority.

ARM CortexM3

Both the tasks have the same priority.I am not blocking any task.

ARM CortexM3

Can you post the outline of your tasks so we can see their structure? Or, better still, attach a C file as this forum will mess up all the source code formatting. Regards.

ARM CortexM3

Hi i attached my main.c file here.In this my task code contains the bloking calls using time dalay functions .If i don’t use time delay only onetask gets executed contineously with out enabling the premption. How the SVCHandler get called each time.Which part of the code is doing to call the SVC handler each time. Regards

ARM CortexM3

Below, i copied the code from Source/portable/GCC/ARM_CM3/port.c of FreerTOS source.I want to know that when and how the vportSVCHandler gets called, and at how frequently it is called. /———————————————————–/ void vPortSVCHandler( void ) { __asm volatile ( ” ldr r3, pxCurrentTCBConst2 n” /* Restore the context. / ” ldr r1, [r3] n” / Use pxCurrentTCBConst to get the pxCurrentTCB address. / ” ldr r0, [r1] n” / The first item in pxCurrentTCB is the task top of stack. / ” ldmia r0!, {r4-r11} n” / Pop the registers that are not automatically saved on exception entry and the critical nesting count. / ” msr psp, r0 n” / Restore the task stack pointer. / ” mov r0, #0 n” ” msr basepri, r0 n” ” orr r14, #0xd n” ” bx r14 n” ” n” ” .align 2 n” “pxCurrentTCBConst2: .word pxCurrentTCB n” ); } /———————————————————–*/ void vPortStartFirstTask( void ) { __asm volatile( ” ldr r0, =0xE000ED08 n” /* Use the NVIC offset register to locate the stack. / ” ldr r0, [r0] n” ” ldr r0, [r0] n” ” msr msp, r0 n” / Set the msp back to the start of the stack. / ” svc 0 n” / System call to start first task. */ ); } Regards,

ARM CortexM3

The SVC handler is called one time only to start the first task running (when vTaskStartScheduler() is called). I looked at your main.c and see you are calling printf() from your tasks. That is almost certainly your problem for a number of reasons. 1) You don’t have any mutual exclusion on the calls. 2) Depending on how they are implemented they are likely to take a very long time to execute compared to the time slice, and if they are using semi hosting they are also likely to stop the scheduler working. Replace the printf()s with simple volatile variable increments, let it run for a while, then pause in the debugger and check both variables are running. Regards.

ARM CortexM3

I observed that above statements are valid only when we enable the configUSE_PREEMPTION flag in FreeRTOSConfig.h In case of non premptive kernel only one task gets schedelued or both? in this case configUSE_PREEMPTION is 0. For each time slice completes how the same task gets scheduled?Please correct me if i am wrong. The above i observed on stellaris LM3s9B96 board.

ARM CortexM3

I observed that above statements are valid only when we enable the configUSE_PREEMPTION flag in FreeRTOSConfig.h
Which statement are you referring to? The SVC handler should only called once in all cases. Don’t confuse it with the PendSV handler, which gets called on each context switch. The behaviour when configUSE_PREEMPTION is set to 0 has recently been changed for the head revision in SVN. It will be released as V7.6.0 in a few days. This is the as yet unpublished note in the change history:
V7.6.0 changes some behaviour when the co-operative scheduler is used (when
configUSE_PREEMPTION is set to 0).  It is important to note that the
behaviour of the pre-emptive scheduler is unchanged - the following
description only applies when configUSE_PREEMPTION is set to 0:

WHEN configUSE_PREEMPTION IS SET TO 0 (which is in a small minority of
cases) a context switch will now only occur when a task places itself into
the Blocked state, or explicitly calls taskYIELD().  This differs from
previous versions, where a context switch would also occur when implicitly
moving a higher priority task out of the Blocked state.  For example,
previously, WHEN PREEMPTION WAS TURNED OFF, if task A unblocks task B by
writing to a queue, then the scheduler would switch to the higher priority
task.  Now, WHEN PREEMPTION IS TURNED OFF, if task A unblocks task B by
writing to a queue, task B will not start running until task A enters the
Blocked state or task A calls taskYIELD().  [If configUSE_PREEMPTION is not
set to 0, so the normal pre-emptive scheduler is being used, then task B
will start running immediately that it is moved out of the Blocked state].
Regards.

ARM CortexM3

I am using FreeRTOS V6.0.0 i am understanding, How the tasks are getting scheduled? Here i got struck every time time slice expires only the same task getting called and never another task getting scheduled. The other task getting a chence in two cases:
  1. When the task itself gone into blocked state, another task getting scheduled and this task itself enter into blocked state during this time another task gets scheduled.
In above case we are enabling the PendSVHandler interrupt when task enter into blocked state, and here saving context of the task, context switch and restoring happening in PendSVHandler. 2.When we enable the configUSE_PREMPTION flag under this, if the condition is true, we are enabling the PendSVHandler interrupt. My question is we are not enabling configUSE_PREMPTION flag and we are not using any api in side the task to block. How the scheduler giving a chence to execute the task contineously, at this moment which handler gets calling and how the only one task gets calling for every time slice. If the SVCHandler called only once, How my task gets executing for each time slice expiry? Please let me know the which part of the FreeRTOS code handling this.

ARM CortexM3

I’m not sure I understand what you are asking. If you have configUSE_PREEMPTION set to 0 and you are not using any API inside the task to block, then it is the correct behaviour for only one task to execute. That is what you have configured the kernel and written your application to do. Regards.

ARM CortexM3

I want to understand, How the same task context is restoring for the completion of each time slice, Which part of the FreeRTOS code handling this.

ARM CortexM3

When configUSE_PREEMPTION is set to 0 there is no time slice. All task context saves and restores are performed in the PendSV handler.

ARM CortexM3

If the configUSE_PREEMPTION is set to zero.We are not enabling the PendSVHandler interrupt.How the PendSVHandler gets called? We are enabling the PendSVHandler interrupt,if the configUSE_PREEMPTION flag is set.