liteos-m 移植 M23内核
在用GD32L23X这颗MCU,发现库里面没有M23架构的,所以结合M4和M0移植了M23内核,没有移植接管中断的函数。记录一下以后备用
具体做法是复制M4内核,将los_dispatch.S内容替换为以下代码,工程不加载los_exc.S,不加载MPU相关。
/* * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. * Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright notice, this list * of conditions and the following disclaimer in the documentation and/or other materials * provided with the distribution. * * 3. Neither the name of the copyright holder nor the names of its contributors may be used * to endorse or promote products derived from this software without specific prior written * permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */.syntax unified.thumb.cpu cortex-m23
.equ OS_NVIC_INT_CTRL, 0xE000ED04.equ OS_NVIC_SYSPRI2, 0xE000ED20.equ OS_NVIC_PENDSV_PRI, 0xF0F00000.equ OS_NVIC_PENDSVSET, 0x10000000.equ OS_TASK_STATUS_RUNNING, 0x0010.equ OS_CONTROL_KERNEL_MODE, 0x2#if (LOSCFG_SECURE == 1).equ OS_CONTROL_USER_MODE, 0x3.equ OS_TASK_FLAG_USER_TASK, 0x0200#endif
.section .text
.macro SIGNAL_CONTEXT_RESTORE sub sp, sp, #8 mov r3, r12 str r3, [sp, #0] mov r3, lr str r3, [sp, #4] bl OsSignalTaskContextRestore
ldr r3, [sp, #0] mov r12, r3 ldr r3, [sp, #4] mov lr, r3 add sp, sp, #8
cmp r0, #0 mov r1, r0 bne SignalContextRestore.endm
.type HalStartToRun, %function .global HalStartToRunHalStartToRun: .fnstart .cantunwind
ldr r4, =OS_NVIC_SYSPRI2 ldr r5, =OS_NVIC_PENDSV_PRI str r5, [r4]
mov r0, #OS_CONTROL_KERNEL_MODE msr CONTROL, r0 isb
ldr r1, =g_losTask ldr r0, [r1, #4] ldr r3, [r0] adds r3, r3, #36 ldmfd r3!, {r0-r2} adds r3, r3, #4 ldmfd r3!, {r4-r7} msr psp, r3 subs r3, r3, #20 ldr r3, [r3]
mov lr, r5 cpsie i bx r6
.fnend
.type ArchIntLock, %function .global ArchIntLockArchIntLock: .fnstart .cantunwind
MRS R0, PRIMASK CPSID I BX LR .fnend
.type ArchIntUnLock, %function .global ArchIntUnLockArchIntUnLock: .fnstart .cantunwind
MRS R0, PRIMASK CPSIE I BX LR .fnend
.type ArchIntRestore, %function .global ArchIntRestoreArchIntRestore: .fnstart .cantunwind
MSR PRIMASK, R0 BX LR .fnend
.type ArchTaskSchedule, %function .global ArchTaskScheduleArchTaskSchedule: .fnstart .cantunwind
ldr r0, =OS_NVIC_INT_CTRL ldr r1, =OS_NVIC_PENDSVSET str r1, [r0] bx lr dsb isb .fnend
.type HalPendSV, %function .global HalPendSV .thumb_funcHalPendSV: .fnstart .cantunwind
mrs r12, PRIMASK cpsid I
HalTaskSwitch: SIGNAL_CONTEXT_RESTORE
sub sp, sp, #8 mov r3, r12 str r3, [sp, #0] mov r3, lr str r3, [sp, #4]
bl OsSchedTaskSwitch ldr r3, [sp, #0] mov r12, r3 ldr r3, [sp, #4] mov lr, r3 add sp, sp, #8
cmp r0, #0 mov r0, lr bne TaskContextSwitch msr PRIMASK, r12 bx lr
TaskContextSwitch: mov lr, r0 mrs r0, psp
SUBS R0, #36 STMIA R0!, {R4-R7} MOV R3, R8 MOV R4, R9 MOV R5, R10 MOV R6, R11 MOV R7, R12 STMIA R0!, {R3 - R7}
SUBS R0, #36
ldr r5, =g_losTask ldr r6, [r5] str r0, [r6]
ldr r0, [r5, #4] str r0, [r5] ldr r1, [r0]
SignalContextRestore:#if (LOSCFG_SECURE == 1) ldrh r7, [r0, #4] tst r7, #OS_TASK_FLAG_USER_TASK ite eq moveq r3, #OS_CONTROL_KERNEL_MODE movne r3, #OS_CONTROL_USER_MODE msr CONTROL, r3#endif
ADDS R1, #16 LDMFD R1!, {R3-R7} MOV R8, R3 MOV R9, R4 MOV R10, R5 MOV R11, R6 MOV R12, R7 SUBS R1, #36 LDMFD R1!, {R4-R7} ADDS R1, #20
msr psp, r1
msr PRIMASK, r12
bx lr .fnend
.global PendSV_Handler .set PendSV_Handler, HalPendSV
- 点赞
- 收藏
- 关注作者
评论(0)