1. The ucos system generally runs in svc mode.
2. Two stacks need to be initialized: IRQ mode and SVCmode. Generally, the stack in IRQ mode is initialized first, because after the SVC stack is initialized, generally, we directly jump to _ main. In this way, our so-called User-mode code and ucos code run in svc. The advantage is that we can disable the service by operating cpsr, with no interruptions, thread switching is absent and can be used to protect shared data.
3. Scat file, the code is organized
RO (. Text,. constdata) |
RW (. Data) |
Zi (. BSS) |
Heap |
Stack (SVC) |
Stack (IRQ) |
The corresponding scat file is as follows:
SRAM_LOAD 0x00000000
{
SRAM_EXEC 0x00000000
{
Startup. o (RESET, + First)
* (+ RO, + RW, + ZI)
}
}
4. OSCtxSw () is called in SVC mode with both fiq and IRQ interrupts DISABLED. This function is called to switch the processor mode to SVC mode before being called.
5. To use the scat file, you must re-write the _ user_initial_stackheap function, which is unavailable in the original library. As long as we call the _ main function, we need the _ user_initial_stackheap function. After disassembly, we can see that _ main calls _ rt_entry and calls _ user_initial_stackheap and main functions in _ rt_entry.
6. Arm11 supports vector interrupt. You need to set the coprocessor as follows:
Mrc p15, 0, r0, c1, c0, 0
Orr r0, r0, #(1 <24)
Mcr p15, 0, r0, c1, c0, 0
7. to switch the system, there must be always interruptions. Therefore, two aspects are required: timer initialization and interrupt processing functions.
The code of the interrupt handler function is as follows:
TICKISR FUNCTION
STMFD sp !, {R0-r2}; Save working registers onto IRQ stack
SUB r2, lr, #4
MOV r0, sp
MRS r1, SPSR
ADD sp, sp, #12
MSR CPSR_c, #0xd3; Switch to SVC mode
STR r2, [sp, #-4]! ; Save task's context onto task's stack
STMFD sp !, {R3-r12, lr}
LDMFD r0 !, {R3-r5}; Move task's r0-r2 from IRQ stack to task's stack
STMFD sp !, {R3-r5}
STR r1, [sp, #-4]! ; Save task's CPSR
BL OSIntEnter; your y uC/OS-II of ISR
LDR r0, = OSIntNesting; if (OSIntNesting = 1)
LDRB r1, [r0]
CMP r1, #1
BNE % F0
LDR r0, = ostcbcur; ostcbcur-> ostcbstkptr = Sp
LDR R1, [R0]
STR sp, [R1]
0
LDR r0, = 0x0a80000c; clear interrupt source
MoV R1, #0
STR R1, [R0]
BL ostimetick; process system tick
BL osintexit; your y uC/OS-II of end of ISR
LDR r0, [sp], #4; Load task's context
MSR SPSR_cxsf, r0
LDMFD sp !, {R0-r12, lr, pc} ^; Run task
Endfunc
8. Scatter files are divided into loading and execution domains. One loading domain contains multiple execution domains.