# ARM9 No Task Switching

**URL:** <https://forums.freertos.org/t/arm9-no-task-switching/4241>\
**Category:** Kernel\
**Created:** [September 4, 2011, 6:18pm UTC](https://forums.freertos.org/t/arm9-no-task-switching/4241 "2011-09-04T18:18:28Z")\
**Posts on this page:** 4\
**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:** [September 4, 2011, 6:18pm UTC](https://forums.freertos.org/t/arm9-no-task-switching/4241/1 "2011-09-04T18:18:28Z")

</div>

**[imkaush](https://sourceforge.net/u/imkaush/)** wrote on [Sunday, September 04, 2011](https://sourceforge.net/p/freertos/discussion/382005/thread/bd3ffad6/#8767):

Hi all,

I am trying to port FreeRTOS on Samsung S3C2440 (ARM9) processor (FriendlyArm’s Mini2440 board) using ADS 1.2 IDE

I am able to start the scheduler but no task switching takes place.

If I configure AppTickHook enabled from FreeRTOSConfig.h, then it is the only task being executed.

If AppTickHook is disabled then only the demo task is executed…it does not suspend (using vTaskSuspend() api) nor does it get delayed (using VTaskDelay() api).

I am using RVDS/ARM7\_LPC21xx port files as reference

This is my assembly code for the SWI handler(in startup file), vPortYield and vPortYieldProcessor(both in portASM.s) which i think is the problem:

in startup.s:

```
 		MACRO
$HandlerLabel HANDLER $HandleLabel
$HandlerLabel
	sub	sp,sp,#4 ;decrement sp(to store jump address)
	stmfd	sp!,{r0} ;PUSH the work register to stack(lr does''t push because it return to original address)
	ldr r0,=$HandleLabel ;load the address of HandleXXX to r0
	ldr r0,[r0] ;load the contents(service routine start address) of HandleXXX
	str r0,[sp,#4] ;store the contents(ISR) of HandleXXX to stack
	ldmfd sp!,{r0,pc} ;POP the work register and pc(jump to ISR)
	MEND
....
b	HandlerSWI
....
HandlerSWI HANDLER HandleSWI
....
; Setup SWI handler
	ldr	r0,=HandleSWI
	ldr	r1,=vPortYieldProcessor
	str	r1,[r0]
....

```

In portASM.s:

```
....
vPortYield
	PRESERVE8
	SWI 0
....
vPortYieldProcessor
	PRESERVE8
	; Within an IRQ ISR the link register has an offset from the true return 
	; address, but an SWI ISR does not. Add the offset manually so the same 
	; ISR return code can be used in both cases.
	ADD	LR, LR, #4
	; Perform the context switch.
	portSAVE_CONTEXT ; Save current task context				
	LDR R0, =vTaskSwitchContext ; Get the address of the context switch function
	MOV LR, PC ; Store the return address
	BX	R0 ; Call the contedxt switch function
	portRESTORE_CONTEXT ; restore the context of the selected task

```

Thanks in advance for any help!!!

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [September 5, 2011, 7:15am UTC](https://forums.freertos.org/t/arm9-no-task-switching/4241/2 "2011-09-05T07:15:13Z")

</div>

**[davedoors](https://sourceforge.net/u/davedoors/)** wrote on [Monday, September 05, 2011](https://sourceforge.net/p/freertos/discussion/382005/thread/bd3ffad6/#8d06):

I don’t know how the interrupt controller works on your chip, but for chips with a vectored controller I would expect the vector table to look something like the code below. Note this is taken from an NXP example, so the IRQ interrupt will be different on your chip. The thing I notice about your code is the SWI handler is that it is not branching directly to FreeRTOS but branching indirectly through R0. I don’t know if this needs to work this way on your chip, but expect that will stop it working unless all interrupts do the exact same thing. See how it is different below.

```
Vectors LDR PC, Reset_Addr         
                LDR PC, Undef_Addr
                LDR PC, SWI_Addr
                LDR PC, PAbt_Addr
                LDR PC, DAbt_Addr
                NOP ; Reserved Vector 
                LDR PC, [PC, #-0x0FF0] ; Vector from VicVectAddr
                LDR PC, FIQ_Addr
Reset_Addr DCD Reset_Handler
Undef_Addr DCD Undef_Handler
SWI_Addr DCD vPortYieldProcessor
PAbt_Addr DCD PAbt_Handler
DAbt_Addr DCD DAbt_Handler
                DCD 0 ; Reserved Address 
IRQ_Addr DCD IRQ_Handler
FIQ_Addr DCD FIQ_Handler

```

Maybe your chip has a completely different interrupt flow though. In any case, I suggest setting configUSE\_PREEMPTION to 0 first, then have two tasks that yield to each other. Only when that is working add in the tick ISR. Then when that is working change configUSE\_PREEMPTION to 1 and see if it still works.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [September 5, 2011, 11:03am UTC](https://forums.freertos.org/t/arm9-no-task-switching/4241/3 "2011-09-05T11:03:45Z")

</div>

**[imkaush](https://sourceforge.net/u/imkaush/)** wrote on [Monday, September 05, 2011](https://sourceforge.net/p/freertos/discussion/382005/thread/bd3ffad6/#8040):

I have already tried this:

```
HandleSWI DCD vPortYieldProcessor

```

In this case, the task is executed once and the program is restarted.

I will try with configUSE\_PREEMPTION 0/1 as you suggested and get back……

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [September 5, 2011, 4:32pm UTC](https://forums.freertos.org/t/arm9-no-task-switching/4241/4 "2011-09-05T16:32:07Z")

</div>

**[imkaush](https://sourceforge.net/u/imkaush/)** wrote on [Monday, September 05, 2011](https://sourceforge.net/p/freertos/discussion/382005/thread/bd3ffad6/#f116):

Yes!!!

It’s working….here are the changes:

In startup.s :

```
//replaced...
b HandlerSWI
//with....
LDR PC, HandlerSWI
//replaced...
HandlerSWI HANDLER HandleSWI
//with....
SWI_Addr DCD vPortYieldProcessor
//removed...
; Setup SWI handler 
ldr r0,=HandleSWI 
ldr r1,=vPortYieldProcessor 
str r1,[r0]

```

In portASM.s:

```
//added "bx lr" to portYeild
vPortYield
	PRESERVE8
	SWI 0
	bx lr

```

Thanks a lot davedoors!!!! Kudos!
