add OpenHarmony 1.0 baseline
This commit is contained in:
parent
757d8285e4
commit
dc16ffa8cb
|
@ -0,0 +1,13 @@
|
|||
### 该问题是怎么引起的?
|
||||
|
||||
|
||||
|
||||
### 重现步骤
|
||||
|
||||
|
||||
|
||||
### 报错信息
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
### 相关的Issue
|
||||
|
||||
|
||||
### 原因(目的、解决的问题等)
|
||||
|
||||
|
||||
### 描述(做了什么,变更了什么)
|
||||
|
||||
|
||||
### 测试用例(新增、改动、可能影响的功能)
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1 @@
|
|||
test
|
|
@ -0,0 +1,42 @@
|
|||
# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020, 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.
|
||||
|
||||
import("//build/lite/config/subsystem/lite_subsystem.gni")
|
||||
|
||||
lite_subsystem("kernel") {
|
||||
subsystem_components = [
|
||||
"//kernel/liteos_m/arch",
|
||||
"//kernel/liteos_m/components",
|
||||
"//kernel/liteos_m/kernel",
|
||||
]
|
||||
|
||||
if (LOSCFG_TEST) {
|
||||
subsystem_components += [ "//kernel/liteos_m/test" ]
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020, 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.
|
||||
|
||||
import("//build/lite/config/component/lite_component.gni")
|
||||
|
||||
source_set("m4") {
|
||||
|
||||
sources = [
|
||||
"arm/cortex-m/cortex-m4/los_dispatch_gcc.S",
|
||||
"arm/cortex-m/cortex-m4/los_hw_exc_gcc.S",
|
||||
"arm/cortex-m/cortex-m4/los_hw_sr_gcc.s",
|
||||
"arm/cortex-m/cortex-m4/los_exc.c",
|
||||
"arm/cortex-m/src/los_hw.c",
|
||||
"arm/cortex-m/src/los_hw_tick.c",
|
||||
"arm/cortex-m/src/los_hwi.c",
|
||||
]
|
||||
}
|
||||
|
||||
lite_component("arch") {
|
||||
features = [
|
||||
":m4"
|
||||
]
|
||||
|
||||
}
|
|
@ -0,0 +1,162 @@
|
|||
;
|
||||
; Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
; Copyright (c) 2020, 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.
|
||||
;
|
||||
|
||||
PRESERVE8
|
||||
|
||||
EXPORT LOS_IntLock
|
||||
EXPORT LOS_IntUnLock
|
||||
EXPORT LOS_IntRestore
|
||||
EXPORT LOS_StartToRun
|
||||
EXPORT osTaskSchedule
|
||||
EXPORT osPendSV
|
||||
|
||||
IMPORT g_losTask
|
||||
IMPORT g_taskSwitchHook
|
||||
IMPORT g_taskScheduled
|
||||
|
||||
OS_NVIC_INT_CTRL EQU 0xE000ED04
|
||||
OS_NVIC_SYSPRI2 EQU 0xE000ED20
|
||||
OS_NVIC_PENDSV_PRI EQU 0xF0F00000
|
||||
OS_NVIC_PENDSVSET EQU 0x10000000
|
||||
OS_TASK_STATUS_RUNNING EQU 0x0010
|
||||
|
||||
SECTION .text:CODE(2)
|
||||
THUMB
|
||||
REQUIRE8
|
||||
|
||||
LOS_StartToRun
|
||||
LDR R4, =OS_NVIC_SYSPRI2
|
||||
LDR R5, =OS_NVIC_PENDSV_PRI
|
||||
STR R5, [R4]
|
||||
|
||||
LDR R0, =g_taskScheduled
|
||||
MOV R1, #1
|
||||
STR R1, [R0]
|
||||
|
||||
MOV R0, #2
|
||||
MSR CONTROL, R0
|
||||
|
||||
|
||||
LDR R0, =g_losTask
|
||||
LDR R2, [R0, #4]
|
||||
LDR R0, =g_losTask
|
||||
STR R2, [R0]
|
||||
|
||||
LDR R3, =g_losTask
|
||||
LDR R0, [R3]
|
||||
LDRH R7, [R0 , #4]
|
||||
MOV R8, #OS_TASK_STATUS_RUNNING
|
||||
ORR R7, R7, R8
|
||||
STRH R7, [R0 , #4]
|
||||
|
||||
LDR R12, [R0]
|
||||
ADD R12, R12, #100
|
||||
|
||||
LDMFD R12!, {R0-R7}
|
||||
ADD R12, R12, #72
|
||||
MSR PSP, R12
|
||||
VPUSH S0;
|
||||
VPOP S0;
|
||||
|
||||
MOV LR, R5
|
||||
;MSR xPSR, R7
|
||||
|
||||
CPSIE I
|
||||
BX R6
|
||||
|
||||
|
||||
LOS_IntLock
|
||||
MRS R0, PRIMASK
|
||||
CPSID I
|
||||
BX LR
|
||||
|
||||
LOS_IntUnLock
|
||||
MRS R0, PRIMASK
|
||||
CPSIE I
|
||||
BX LR
|
||||
|
||||
LOS_IntRestore
|
||||
MSR PRIMASK, R0
|
||||
BX LR
|
||||
|
||||
osTaskSchedule
|
||||
LDR R0, =OS_NVIC_INT_CTRL
|
||||
LDR R1, =OS_NVIC_PENDSVSET
|
||||
STR R1, [R0]
|
||||
BX LR
|
||||
|
||||
osPendSV
|
||||
MRS R12, PRIMASK
|
||||
CPSID I
|
||||
|
||||
LDR R2, =g_taskSwitchHook
|
||||
LDR R2, [R2]
|
||||
CBZ R2, TaskSwitch
|
||||
PUSH {R12, LR}
|
||||
BLX R2
|
||||
POP {R12, LR}
|
||||
|
||||
TaskSwitch
|
||||
MRS R0, PSP
|
||||
|
||||
STMFD R0!, {R4-R12}
|
||||
VSTMDB R0!, {D8-D15}
|
||||
|
||||
LDR R5, =g_losTask
|
||||
LDR R6, [R5]
|
||||
STR R0, [R6]
|
||||
|
||||
|
||||
LDRH R7, [R6 , #4]
|
||||
MOV R8,#OS_TASK_STATUS_RUNNING
|
||||
BIC R7, R7, R8
|
||||
STRH R7, [R6 , #4]
|
||||
|
||||
|
||||
LDR R0, =g_losTask
|
||||
LDR R0, [R0, #4]
|
||||
STR R0, [R5]
|
||||
|
||||
|
||||
LDRH R7, [R0 , #4]
|
||||
MOV R8, #OS_TASK_STATUS_RUNNING
|
||||
ORR R7, R7, R8
|
||||
STRH R7, [R0 , #4]
|
||||
|
||||
LDR R1, [R0]
|
||||
VLDMIA R1!, {D8-D15}
|
||||
LDMFD R1!, {R4-R12}
|
||||
MSR PSP, R1
|
||||
|
||||
MSR PRIMASK, R12
|
||||
BX LR
|
||||
|
||||
END
|
|
@ -0,0 +1,287 @@
|
|||
;
|
||||
; Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
; Copyright (c) 2020, 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.
|
||||
;
|
||||
|
||||
PRESERVE8
|
||||
SECTION .text:CODE(2)
|
||||
THUMB
|
||||
|
||||
EXPORT OsExcNMI
|
||||
EXPORT OsExcHardFault
|
||||
EXPORT OsExcMemFault
|
||||
EXPORT OsExcBusFault
|
||||
EXPORT OsExcUsageFault
|
||||
EXPORT OsExcSvcCall
|
||||
|
||||
IMPORT OsExcHandleEntry
|
||||
IMPORT g_vuwLosFlag
|
||||
IMPORT g_uwCurNestCount
|
||||
IMPORT g_uwExcTbl
|
||||
IMPORT g_taskScheduled
|
||||
|
||||
OS_FLG_BGD_ACTIVE EQU 0x0002
|
||||
|
||||
OS_EXC_CAUSE_NMI EQU 16
|
||||
OS_EXC_CAUSE_HARDFAULT EQU 17
|
||||
|
||||
HF_DEBUGEVT EQU 20
|
||||
HF_VECTBL EQU 21
|
||||
|
||||
FLAG_ADDR_VALID EQU 0x10000
|
||||
FLAG_HWI_ACTIVE EQU 0x20000
|
||||
FLAG_NO_FLOAT EQU 0x10000000
|
||||
|
||||
OS_NVIC_FSR EQU 0xE000ED28 ;include BusFault/MemFault/UsageFault State Regeister
|
||||
OS_NVIC_HFSR EQU 0xE000ED2C ;HardFault State Regeister
|
||||
OS_NVIC_BFAR EQU 0xE000ED38
|
||||
OS_NVIC_MMAR EQU 0xE000ED34
|
||||
OS_NVIC_ACT_BASE EQU 0xE000E300
|
||||
OS_NVIC_SHCSRS EQU 0xE000ED24
|
||||
OS_NVIC_SHCSR_MASK EQU 0xC00
|
||||
|
||||
OsExcNMI
|
||||
MOV R0, #OS_EXC_CAUSE_NMI
|
||||
MOV R1, #0
|
||||
B osExcDispatch
|
||||
|
||||
OsExcHardFault
|
||||
MOV R0, #OS_EXC_CAUSE_HARDFAULT
|
||||
LDR R2, =OS_NVIC_HFSR
|
||||
LDR R2, [R2]
|
||||
|
||||
MOV R1, #HF_DEBUGEVT
|
||||
ORR R0, R0, R1, LSL #0x8
|
||||
TST R2, #0x80000000
|
||||
BNE osExcDispatch ; DEBUGEVT
|
||||
|
||||
AND R0, R0 , #0x000000FF
|
||||
MOV R1, #HF_VECTBL
|
||||
ORR R0, R0, R1, LSL #0x8
|
||||
TST R2, #0x00000002
|
||||
BNE osExcDispatch ; VECTBL
|
||||
|
||||
;if not DEBUGEVT and VECTBL then is FORCED
|
||||
AND R0, R0, #0x000000FF
|
||||
|
||||
LDR R2, =OS_NVIC_FSR
|
||||
LDR R2, [R2]
|
||||
|
||||
TST R2, #0x8000 ; BFARVALID
|
||||
BNE _HFBusFault ; BusFault
|
||||
|
||||
TST R2, #0x80 ; MMARVALID
|
||||
BNE _HFMemFault ; MemFault
|
||||
|
||||
MOV R12,#0
|
||||
B osHFExcCommonBMU
|
||||
|
||||
_HFBusFault
|
||||
LDR R1, =OS_NVIC_BFAR
|
||||
LDR R1, [R1]
|
||||
MOV R12, #FLAG_ADDR_VALID
|
||||
B osHFExcCommonBMU
|
||||
|
||||
_HFMemFault
|
||||
LDR R1, =OS_NVIC_MMAR
|
||||
LDR R1, [R1]
|
||||
MOV R12, #FLAG_ADDR_VALID
|
||||
|
||||
osHFExcCommonBMU
|
||||
CLZ R2, R2
|
||||
LDR R3, =g_uwExcTbl
|
||||
ADD R3, R3, R2
|
||||
LDRB R2, [R3]
|
||||
ORR R0, R0, R2, LSL #0x8
|
||||
ORR R0, R0 ,R12
|
||||
B osExcDispatch
|
||||
|
||||
OsExcSvcCall
|
||||
TST LR, #0x4
|
||||
ITE EQ
|
||||
MRSEQ R0, MSP
|
||||
MRSNE R0, PSP
|
||||
LDR R1, [R0,#24]
|
||||
LDRB R0, [R1,#-2]
|
||||
MOV R1, #0
|
||||
B osExcDispatch
|
||||
|
||||
OsExcBusFault
|
||||
LDR R0, =OS_NVIC_FSR
|
||||
LDR R0, [R0]
|
||||
|
||||
TST R0, #0x8000 ; BFARVALID
|
||||
BEQ _ExcBusNoADDR
|
||||
LDR R1, =OS_NVIC_BFAR
|
||||
LDR R1, [R1]
|
||||
MOV R12, #FLAG_ADDR_VALID
|
||||
AND R0, R0, #0x1F00
|
||||
|
||||
B osExcCommonBMU
|
||||
|
||||
_ExcBusNoADDR
|
||||
MOV R12,#0
|
||||
B osExcCommonBMU
|
||||
|
||||
OsExcMemFault
|
||||
LDR R0, =OS_NVIC_FSR
|
||||
LDR R0, [R0]
|
||||
|
||||
TST R0, #0x80 ; MMARVALID
|
||||
BEQ _ExcMemNoADDR
|
||||
LDR R1, =OS_NVIC_MMAR
|
||||
LDR R1, [R1]
|
||||
MOV R12, #FLAG_ADDR_VALID
|
||||
AND R0, R0, #0x1B
|
||||
|
||||
B osExcCommonBMU
|
||||
|
||||
_ExcMemNoADDR
|
||||
MOV R12,#0
|
||||
B osExcCommonBMU
|
||||
|
||||
OsExcUsageFault
|
||||
LDR R0, =OS_NVIC_FSR
|
||||
LDR R0, [R0]
|
||||
|
||||
MOV R1, #0x030F
|
||||
LSL R1, R1, #16
|
||||
AND R0, R0, R1
|
||||
MOV R12, #0
|
||||
|
||||
osExcCommonBMU
|
||||
CLZ R0, R0
|
||||
LDR R3, =g_uwExcTbl
|
||||
ADD R3, R3, R0
|
||||
LDRB R0, [R3]
|
||||
ORR R0, R0, R12
|
||||
|
||||
; R0 -- EXCCAUSE(bit 16 is 1 if EXCADDR valid), R1 -- EXCADDR
|
||||
osExcDispatch
|
||||
LDR R2, =OS_NVIC_ACT_BASE
|
||||
MOV R12, #8 ; R12 is hwi check loop counter
|
||||
|
||||
_hwiActiveCheck
|
||||
LDR R3, [R2] ; R3 store active hwi register when exc
|
||||
CMP R3, #0
|
||||
BEQ _hwiActiveCheckNext
|
||||
|
||||
; exc occured in IRQ
|
||||
ORR R0, R0, #FLAG_HWI_ACTIVE
|
||||
RBIT R2, R3
|
||||
CLZ R2, R2
|
||||
AND R12, R12, #1
|
||||
ADD R2, R2, R12, LSL #5 ; calculate R2 (hwi number) as uwPid
|
||||
|
||||
_ExcInMSP
|
||||
CMP LR, #0XFFFFFFED
|
||||
BNE _NoFloatInMsp
|
||||
ADD R3, R13, #104
|
||||
PUSH {R3}
|
||||
MRS R12, PRIMASK ; store message-->exc: disable int?
|
||||
PUSH {R4-R12} ; store message-->exc: {R4-R12}
|
||||
VPUSH {D8-D15}
|
||||
B _handleEntry
|
||||
|
||||
_NoFloatInMsp
|
||||
ADD R3, R13, #32
|
||||
PUSH {R3} ; save IRQ SP ; store message-->exc: MSP(R13)
|
||||
|
||||
MRS R12, PRIMASK ; store message-->exc: disable int?
|
||||
PUSH {R4-R12} ; store message-->exc: {R4-R12}
|
||||
ORR R0, R0, #FLAG_NO_FLOAT
|
||||
B _handleEntry
|
||||
|
||||
_hwiActiveCheckNext
|
||||
ADD R2, R2, #4 ; next NVIC ACT ADDR
|
||||
SUBS R12, R12, #1
|
||||
BNE _hwiActiveCheck
|
||||
|
||||
;/*NMI interrupt excption*/
|
||||
LDR R2, =OS_NVIC_SHCSRS
|
||||
LDRH R2,[R2]
|
||||
LDR R3,=OS_NVIC_SHCSR_MASK
|
||||
AND R2, R2,R3
|
||||
CMP R2,#0
|
||||
BNE _ExcInMSP
|
||||
; exc occured in Task or Init or exc
|
||||
; reserved for register info from task stack
|
||||
|
||||
LDR R2, =g_taskScheduled
|
||||
LDR R2, [R2]
|
||||
TST R2, #1 ; OS_FLG_BGD_ACTIVE
|
||||
BEQ _ExcInMSP ; if exc occured in Init then branch
|
||||
|
||||
|
||||
CMP LR, #0xFFFFFFED ;auto push floating registers
|
||||
BNE _NoFloatInPsp
|
||||
|
||||
; exc occured in Task
|
||||
MOV R2, R13
|
||||
SUB R13, #96 ; add 8 Bytes reg(for STMFD)
|
||||
|
||||
MRS R3, PSP
|
||||
ADD R12, R3, #104
|
||||
PUSH {R12} ; save task SP
|
||||
|
||||
MRS R12, PRIMASK
|
||||
PUSH {R4-R12}
|
||||
VPUSH {D8-D15}
|
||||
|
||||
; copy auto saved task register
|
||||
|
||||
LDMFD R3!, {R4-R11} ; R4-R11 store PSP reg(auto push when exc in task)
|
||||
VLDMIA R3!, {D8-D15}
|
||||
VSTMDB R2!, {D8-D15}
|
||||
STMFD R2!, {R4-R11}
|
||||
B _handleEntry
|
||||
|
||||
_NoFloatInPsp
|
||||
MOV R2, R13 ;no auto push floating registers
|
||||
SUB R13, #32 ; add 8 Bytes reg(for STMFD)
|
||||
|
||||
MRS R3, PSP
|
||||
ADD R12, R3, #32
|
||||
PUSH {R12} ; save task SP
|
||||
|
||||
MRS R12, PRIMASK
|
||||
PUSH {R4-R12}
|
||||
|
||||
LDMFD R3, {R4-R11} ; R4-R11 store PSP reg(auto push when exc in task)
|
||||
STMFD R2!, {R4-R11}
|
||||
ORR R0, R0, #FLAG_NO_FLOAT
|
||||
|
||||
_handleEntry
|
||||
MOV R3, R13 ; R13:the 4th param
|
||||
CPSID I
|
||||
CPSID F
|
||||
B OsExcHandleEntry
|
||||
|
||||
NOP
|
||||
END
|
|
@ -0,0 +1,199 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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
|
||||
.arch armv7e-m
|
||||
.thumb
|
||||
.fpu vfpv4
|
||||
//;.arch_extension sec
|
||||
|
||||
|
||||
|
||||
.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
|
||||
|
||||
.section .text
|
||||
.thumb
|
||||
|
||||
.type LOS_StartToRun, %function
|
||||
.global LOS_StartToRun
|
||||
|
||||
LOS_StartToRun:
|
||||
.fnstart
|
||||
.cantunwind
|
||||
|
||||
ldr r4, =OS_NVIC_SYSPRI2
|
||||
ldr r5, =OS_NVIC_PENDSV_PRI
|
||||
str r5, [r4]
|
||||
|
||||
ldr r0, =g_taskScheduled
|
||||
mov r1, #1
|
||||
str r1, [r0]
|
||||
|
||||
mov r0, #2
|
||||
msr CONTROL, r0
|
||||
|
||||
|
||||
ldr r0, =g_losTask
|
||||
ldr r2, [r0, #4]
|
||||
ldr r0, =g_losTask
|
||||
str r2, [r0]
|
||||
|
||||
ldr r3, =g_losTask
|
||||
ldr r0, [r3]
|
||||
ldrh r7, [r0 , #4]
|
||||
mov r8, #OS_TASK_STATUS_RUNNING
|
||||
orr r7, r7, r8
|
||||
strh r7, [r0 , #4]
|
||||
|
||||
ldr r12, [r0]
|
||||
add r12, r12, #100
|
||||
|
||||
ldmfd r12!, {r0-r7}
|
||||
add r12, r12, #72
|
||||
msr psp, r12
|
||||
vpush {S0}
|
||||
vpop {S0}
|
||||
mov lr, r5
|
||||
//MSR xPSR, R7
|
||||
|
||||
cpsie I
|
||||
bx r6
|
||||
|
||||
.fnend
|
||||
|
||||
|
||||
.type LOS_IntLock, %function
|
||||
.global LOS_IntLock
|
||||
LOS_IntLock:
|
||||
.fnstart
|
||||
.cantunwind
|
||||
|
||||
MRS R0, PRIMASK
|
||||
CPSID I
|
||||
BX LR
|
||||
.fnend
|
||||
|
||||
.type LOS_IntUnLock, %function
|
||||
.global LOS_IntUnLock
|
||||
LOS_IntUnLock:
|
||||
.fnstart
|
||||
.cantunwind
|
||||
|
||||
MRS R0, PRIMASK
|
||||
CPSIE I
|
||||
BX LR
|
||||
.fnend
|
||||
|
||||
.type LOS_IntRestore, %function
|
||||
.global LOS_IntRestore
|
||||
LOS_IntRestore:
|
||||
.fnstart
|
||||
.cantunwind
|
||||
|
||||
MSR PRIMASK, R0
|
||||
BX LR
|
||||
.fnend
|
||||
|
||||
.type osTaskSchedule, %function
|
||||
.global osTaskSchedule
|
||||
osTaskSchedule:
|
||||
.fnstart
|
||||
.cantunwind
|
||||
|
||||
ldr r0, =OS_NVIC_INT_CTRL
|
||||
ldr r1, =OS_NVIC_PENDSVSET
|
||||
str r1, [r0]
|
||||
bx lr
|
||||
.fnend
|
||||
|
||||
|
||||
|
||||
|
||||
.type osPendSV, %function
|
||||
.global osPendSV
|
||||
osPendSV:
|
||||
.fnstart
|
||||
.cantunwind
|
||||
|
||||
mrs r12, PRIMASK
|
||||
cpsid I
|
||||
|
||||
ldr r2, =g_taskSwitchHook
|
||||
ldr r2, [r2]
|
||||
cbz r2, TaskSwitch
|
||||
push {r12, lr}
|
||||
blx r2
|
||||
pop {r12, lr}
|
||||
|
||||
TaskSwitch:
|
||||
|
||||
mrs r0, psp
|
||||
|
||||
stmfd r0!, {r4-r12}
|
||||
|
||||
vstmdb r0!, {d8-d15}
|
||||
ldr r5, =g_losTask
|
||||
ldr r6, [r5]
|
||||
str r0, [r6]
|
||||
|
||||
|
||||
ldrh r7, [r6 , #4]
|
||||
mov r8,#OS_TASK_STATUS_RUNNING
|
||||
bic r7, r7, r8
|
||||
strh r7, [r6 , #4]
|
||||
|
||||
|
||||
ldr r0, =g_losTask
|
||||
ldr r0, [r0, #4]
|
||||
str r0, [r5]
|
||||
|
||||
|
||||
ldrh r7, [r0 , #4]
|
||||
mov r8, #OS_TASK_STATUS_RUNNING
|
||||
orr r7, r7, r8
|
||||
strh r7, [r0 , #4]
|
||||
|
||||
ldr r1, [r0]
|
||||
|
||||
vldmia r1!, {d8-d15}
|
||||
ldmfd r1!, {r4-r12}
|
||||
msr psp, r1
|
||||
|
||||
msr PRIMASK, r12
|
||||
|
||||
|
||||
bx lr
|
||||
.fnend
|
||||
|
|
@ -0,0 +1,379 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#include "los_exc_pri.h"
|
||||
#include "los_memcheck_pri.h"
|
||||
#ifdef LOSCFG_LIB_LIBC
|
||||
#include "string.h"
|
||||
#endif
|
||||
#include "securec.h"
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define EXC_INT_STATUS_LEN OS_NVIC_INT_ENABLE_SIZE + OS_NVIC_INT_PEND_SIZE + OS_NVIC_INT_ACT_SIZE + \
|
||||
OS_NVIC_INT_PRI_SIZE + OS_NVIC_EXCPRI_SIZE + OS_NVIC_SHCSR_SIZE + OS_NVIC_INT_CTRL_SIZE
|
||||
#define TASK_ARRAY_INIT_VALUE 0xff
|
||||
#define FAULT_STATUS_REG_BIT 32
|
||||
#define OS_NVIC_INT_CTRL_SIZE 4
|
||||
#define OS_NVIC_SHCSR_SIZE 4
|
||||
#define USGFAULT (1 << 18)
|
||||
#define BUSFAULT (1 << 17)
|
||||
#define MEMFAULT (1 << 16)
|
||||
#define DIV0FAULT (1 << 4)
|
||||
#define CORE_TYPE_CORTEX_M4 2
|
||||
#define HARDFAULT_IRQN (-13)
|
||||
static VOID *g_excContent;
|
||||
UINT32 g_curNestCount = 0;
|
||||
ExcInfo g_excInfo;
|
||||
|
||||
__attribute__((noinline)) VOID LOS_Panic(const CHAR *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap,fmt);
|
||||
PRINT_ERR(fmt, ap);
|
||||
va_end(ap);
|
||||
asm volatile ("swi 0");
|
||||
}
|
||||
|
||||
UINT8 g_uwExcTbl[FAULT_STATUS_REG_BIT] = {
|
||||
0, 0, 0, 0, 0, 0, OS_EXC_UF_DIVBYZERO, OS_EXC_UF_UNALIGNED,
|
||||
0, 0, 0, 0, OS_EXC_UF_NOCP, OS_EXC_UF_INVPC, OS_EXC_UF_INVSTATE, OS_EXC_UF_UNDEFINSTR,
|
||||
0, 0, 0, OS_EXC_BF_STKERR, OS_EXC_BF_UNSTKERR, OS_EXC_BF_IMPRECISERR, OS_EXC_BF_PRECISERR, OS_EXC_BF_IBUSERR,
|
||||
0, 0, 0, OS_EXC_MF_MSTKERR, OS_EXC_MF_MUNSTKERR, 0, OS_EXC_MF_DACCVIOL, OS_EXC_MF_IACCVIOL
|
||||
};
|
||||
UINT32 g_excArraySize = 0;
|
||||
ExcInfoArray g_excArray[OS_EXC_TYPE_MAX - 1];
|
||||
|
||||
UINT32 g_LR_regs = 0;
|
||||
UINT32 g_PC_regs = 0;
|
||||
|
||||
LITE_OS_SEC_TEXT_INIT VOID OsExcInfoDisplay(ExcInfo *exc)
|
||||
{
|
||||
PRINT_INFO("Phase = 0x%x\n", exc->phase);
|
||||
PRINT_INFO("Type = 0x%x\n", exc->type);
|
||||
PRINT_INFO("FaultAddr = 0x%x\n", exc->faultAddr);
|
||||
PRINT_INFO("ThrdPid = 0x%x\n", exc->thrdPid);
|
||||
PRINT_INFO("R0 = 0x%x\n", exc->context->uwR0);
|
||||
PRINT_INFO("R1 = 0x%x\n", exc->context->uwR1);
|
||||
PRINT_INFO("R2 = 0x%x\n", exc->context->uwR2);
|
||||
PRINT_INFO("R3 = 0x%x\n", exc->context->uwR3);
|
||||
PRINT_INFO("R4 = 0x%x\n", exc->context->uwR4);
|
||||
PRINT_INFO("R5 = 0x%x\n", exc->context->uwR5);
|
||||
PRINT_INFO("R6 = 0x%x\n", exc->context->uwR6);
|
||||
PRINT_INFO("R7 = 0x%x\n", exc->context->uwR7);
|
||||
PRINT_INFO("R8 = 0x%x\n", exc->context->uwR8);
|
||||
PRINT_INFO("R9 = 0x%x\n", exc->context->uwR9);
|
||||
PRINT_INFO("R10 = 0x%x\n", exc->context->uwR10);
|
||||
PRINT_INFO("R11 = 0x%x\n", exc->context->uwR11);
|
||||
PRINT_INFO("R12 = 0x%x\n", exc->context->uwR12);
|
||||
PRINT_INFO("PriMask = 0x%x\n", exc->context->uwPriMask);
|
||||
PRINT_INFO("SP = 0x%x\n", exc->context->uwSP);
|
||||
PRINT_INFO("LR = 0x%x\n", exc->context->uwLR);
|
||||
PRINT_INFO("PC = 0x%x\n", exc->context->uwPC);
|
||||
PRINT_INFO("xPSR = 0x%x\n", exc->context->uwxPSR);
|
||||
|
||||
g_LR_regs = exc->context->uwLR;
|
||||
g_PC_regs = exc->context->uwPC;
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : OsExcHandleEntry
|
||||
Description : EXC模块的处理分发函数
|
||||
Input : excType
|
||||
: faultAddr
|
||||
: pid
|
||||
: excBufAddr --- EXC寄存器信息的首地址
|
||||
Output : None
|
||||
Return : None
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT VOID OsExcHandleEntry(UINT32 excType, UINT32 faultAddr, UINT32 pid,
|
||||
EXC_CONTEXT_S *excBufAddr)
|
||||
{
|
||||
UINT16 tmpFlag = (excType >> 16) & OS_NULL_SHORT; // 为2在中断中,为1 faultAddr有效
|
||||
g_curNestCount++;
|
||||
g_vuwIntCount++;
|
||||
g_excInfo.nestCnt = g_curNestCount;
|
||||
|
||||
g_excInfo.type = excType & OS_NULL_SHORT;
|
||||
g_excContent = (UINT32 *)g_aucTaskArray;
|
||||
|
||||
if (tmpFlag & OS_EXC_FLAG_FAULTADDR_VALID) {
|
||||
g_excInfo.faultAddr = faultAddr;
|
||||
} else {
|
||||
g_excInfo.faultAddr = OS_EXC_IMPRECISE_ACCESS_ADDR;
|
||||
}
|
||||
|
||||
if (g_losTask.runTask != NULL) {
|
||||
if (tmpFlag & OS_EXC_FLAG_IN_HWI) {
|
||||
g_excInfo.phase = OS_EXC_IN_HWI;
|
||||
g_excInfo.thrdPid = pid;
|
||||
} else {
|
||||
g_excInfo.phase = OS_EXC_IN_TASK;
|
||||
g_excInfo.thrdPid = g_losTask.runTask->taskID;
|
||||
}
|
||||
} else {
|
||||
g_excInfo.phase = OS_EXC_IN_INIT;
|
||||
g_excInfo.thrdPid = OS_NULL_INT;
|
||||
}
|
||||
|
||||
if (excType & OS_EXC_FLAG_NO_FLOAT) {
|
||||
g_excInfo.context = (EXC_CONTEXT_S *)((CHAR *)excBufAddr - LOS_OFF_SET_OF(EXC_CONTEXT_S, uwR4));
|
||||
} else {
|
||||
g_excInfo.context = excBufAddr;
|
||||
}
|
||||
|
||||
OsExcSave2DDR();
|
||||
|
||||
OsExcInfoDisplay(&g_excInfo);
|
||||
|
||||
LOS_Reboot();
|
||||
}
|
||||
static VOID OsExcSaveIntStatus()
|
||||
{
|
||||
UINT32 ret;
|
||||
UINT32 failCnt = 0;
|
||||
*((UINT32 *)g_excContent) = OS_EXC_TYPE_NVIC;
|
||||
g_excContent = (UINT8 *)g_excContent + sizeof(UINT32);
|
||||
|
||||
// = OS_NVIC_INT_ENABLE_SIZE + OS_NVIC_INT_PEND_SIZE + OS_NVIC_INT_ACT_SIZE + OS_NVIC_INT_PRI_SIZE + 12 + 4 + 4
|
||||
*((UINT32 *)g_excContent) = EXC_INT_STATUS_LEN;
|
||||
g_excContent = (UINT8 *)g_excContent + sizeof(UINT32);
|
||||
/* 保存中断ENABLE寄存器组 */
|
||||
ret = memcpy_s(g_excContent, MAX_EXC_MEM_SIZE, (const VOID *)OS_NVIC_SETENA_BASE, OS_NVIC_INT_ENABLE_SIZE);
|
||||
g_excContent = (UINT8 *)g_excContent + OS_NVIC_INT_ENABLE_SIZE;
|
||||
failCnt += (ret == EOK) ? 0 : 1;
|
||||
|
||||
/* 保存中断PEND寄存器组 */
|
||||
ret = memcpy_s(g_excContent, MAX_EXC_MEM_SIZE, (const VOID *)OS_NVIC_SETPEND_BASE, OS_NVIC_INT_PEND_SIZE);
|
||||
g_excContent = (UINT8 *)g_excContent + OS_NVIC_INT_PEND_SIZE;
|
||||
failCnt += (ret == EOK) ? 0 : 1;
|
||||
|
||||
/* 保存中断ACTIVE寄存器组 */
|
||||
ret = memcpy_s(g_excContent, MAX_EXC_MEM_SIZE, (const VOID *)OS_NVIC_INT_ACT_BASE, OS_NVIC_INT_ACT_SIZE);
|
||||
g_excContent = (UINT8 *)g_excContent + OS_NVIC_INT_ACT_SIZE;
|
||||
failCnt += (ret == EOK) ? 0 : 1;
|
||||
|
||||
/* 保存中断优先级寄存器组 */
|
||||
ret = memcpy_s(g_excContent, MAX_EXC_MEM_SIZE, (const VOID *)OS_NVIC_PRI_BASE, OS_NVIC_INT_PRI_SIZE);
|
||||
g_excContent = (UINT8 *)g_excContent + OS_NVIC_INT_PRI_SIZE;
|
||||
failCnt += (ret == EOK) ? 0 : 1;
|
||||
|
||||
/* 系统异常优先级寄存器组 */
|
||||
ret = memcpy_s(g_excContent, MAX_EXC_MEM_SIZE, (const VOID *)OS_NVIC_EXCPRI_BASE, OS_NVIC_EXCPRI_SIZE);
|
||||
g_excContent = (UINT8 *)g_excContent + OS_NVIC_EXCPRI_SIZE;
|
||||
failCnt += (ret == EOK) ? 0 : 1;
|
||||
|
||||
/* 保存系统Handler控制及状态寄存器SHCSR */
|
||||
ret = memcpy_s(g_excContent, MAX_EXC_MEM_SIZE, (const VOID *)OS_NVIC_SHCSR, OS_NVIC_SHCSR_SIZE);
|
||||
g_excContent = (UINT8 *)g_excContent + sizeof(UINT32);
|
||||
failCnt += (ret == EOK) ? 0 : 1;
|
||||
|
||||
/* 保存中断控制及状态寄存器ICSR */
|
||||
ret = memcpy_s(g_excContent, MAX_EXC_MEM_SIZE, (const VOID *)OS_NVIC_INT_CTRL, OS_NVIC_INT_CTRL_SIZE);
|
||||
g_excContent = (UINT8 *)g_excContent + sizeof(UINT32);
|
||||
failCnt += (ret == EOK) ? 0 : 1;
|
||||
|
||||
if (failCnt != 0) {
|
||||
PRINT_ERR("OsExcSaveIntStatus copy register info failed, cnt:%d\n", failCnt);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
VOID OsExcRegister(ExcInfoType type, EXC_INFO_SAVE_CALLBACK func, VOID *arg)
|
||||
{
|
||||
ExcInfoArray *excInfo = NULL;
|
||||
if ((type == 0) || (type >= OS_EXC_TYPE_MAX) || (func == NULL)) {
|
||||
PRINT_ERR("OsExcRegister ERROR!\n");
|
||||
return;
|
||||
}
|
||||
excInfo = &(g_excArray[type - 1]);
|
||||
excInfo->uwType = type;
|
||||
excInfo->pFnExcInfoCb = func;
|
||||
excInfo->pArg = arg;
|
||||
excInfo->uwValid = TRUE;
|
||||
}
|
||||
|
||||
static VOID OsExcSaveSysInfo(ExcInfoType type, EXC_INFO_SAVE_CALLBACK func, UINT32 loop, UINT32 length, UINT32 index)
|
||||
{
|
||||
UINT32 ret;
|
||||
UINT32 buffer[OS_EXC_MAX_BUF_LEN];
|
||||
|
||||
*((UINT32 *)g_excContent) = type;
|
||||
g_excContent = (UINT8 *)g_excContent + sizeof(UINT32);
|
||||
*((UINT32 *)g_excContent) = length * (loop - index);
|
||||
g_excContent = (UINT8 *)g_excContent + sizeof(UINT32);
|
||||
|
||||
for (; index < loop; index++) {
|
||||
(VOID)memset_s(buffer, sizeof(UINT32) * OS_EXC_MAX_BUF_LEN, 0, sizeof(UINT32) * OS_EXC_MAX_BUF_LEN);
|
||||
ret = func(index, (VOID *)buffer);
|
||||
if (ret == LOS_OK) {
|
||||
if (memcpy_s(g_excContent, MAX_EXC_MEM_SIZE, (VOID *)buffer, length) != EOK) {
|
||||
PRINT_ERR("OsExcSaveSysInfo copy buffer failed\n");
|
||||
return;
|
||||
}
|
||||
g_excContent = (UINT8 *)g_excContent + length;
|
||||
} else {
|
||||
g_excContent = (UINT8 *)g_excContent + length;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static VOID OsExcSaveInfo(ExcInfoType type, EXC_INFO_SAVE_CALLBACK func, VOID *arg)
|
||||
{
|
||||
UINT32 length;
|
||||
UINT32 index;
|
||||
UINT32 loop;
|
||||
UINT32 taskSwitchCount = 0;
|
||||
TaskSwitchInfo *taskSwitchInfo = NULL;
|
||||
|
||||
if (arg == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case OS_EXC_TYPE_TSK: /* save task info */
|
||||
length = sizeof(TSK_INFO_S);
|
||||
loop = *(UINT32 *)arg;
|
||||
index = 0;
|
||||
break;
|
||||
|
||||
case OS_EXC_TYPE_QUE: /* save queue info */
|
||||
length = sizeof(QUEUE_INFO_S);
|
||||
loop = *(UINT32 *)arg + 1;
|
||||
index = 1;
|
||||
break;
|
||||
|
||||
case OS_EXC_TYPE_NVIC:
|
||||
(VOID)func(0, 0);
|
||||
goto END;
|
||||
|
||||
case OS_EXC_TYPE_TSK_SWITCH: /* save task switch info */
|
||||
// not necessary, just for macro int library
|
||||
taskSwitchInfo = arg;
|
||||
taskSwitchCount = taskSwitchInfo->cntInfo.maxCnt;
|
||||
length = sizeof(UINT32) + sizeof(CHAR) * LOS_TASK_NAMELEN;
|
||||
if (taskSwitchInfo->cntInfo.isFull) {
|
||||
index = taskSwitchInfo->idx;
|
||||
loop = index + taskSwitchCount;
|
||||
} else {
|
||||
index = 0;
|
||||
loop = taskSwitchInfo->idx;
|
||||
}
|
||||
break;
|
||||
|
||||
case OS_EXC_TYPE_MEM: /* save mem info */
|
||||
length = sizeof(MEM_INFO_S);
|
||||
loop = *(UINT32 *)arg;
|
||||
index = 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
goto END;
|
||||
}
|
||||
OsExcSaveSysInfo(type, (EXC_INFO_SAVE_CALLBACK)func, loop, length, index);
|
||||
END:
|
||||
return;
|
||||
}
|
||||
|
||||
static VOID OsExcSave2DDR(VOID)
|
||||
{
|
||||
UINT32 index = 0;
|
||||
UINT32 ret;
|
||||
UINT32 failCnt = 0;
|
||||
|
||||
ret = memset_s(g_aucTaskArray, MAX_EXC_MEM_SIZE, TASK_ARRAY_INIT_VALUE, g_excArraySize);
|
||||
if (ret != EOK) {
|
||||
PRINT_ERR("memset failed\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/* define core type */
|
||||
*((UINT32 *)g_excContent) = CORE_TYPE_CORTEX_M4; // 1 is cortex-M3, 2 is cortex-M4
|
||||
g_excContent = (UINT8 *)g_excContent + sizeof(UINT32);
|
||||
|
||||
/* save exception info */
|
||||
*((UINT32 *)g_excContent) = OS_EXC_TYPE_CONTEXT;
|
||||
g_excContent = (UINT8 *)g_excContent + sizeof(UINT32);
|
||||
*((UINT32 *)g_excContent) = sizeof(ExcInfo) - sizeof(UINT32) + sizeof(EXC_CONTEXT_S);
|
||||
|
||||
g_excContent = (UINT8 *)g_excContent + sizeof(UINT32);
|
||||
ret = memcpy_s((VOID *)g_excContent, MAX_EXC_MEM_SIZE, (VOID *)&g_excInfo, sizeof(ExcInfo) - sizeof(UINT32));
|
||||
g_excContent = (UINT8 *)g_excContent + sizeof(ExcInfo) - sizeof(UINT32);
|
||||
failCnt += (ret == EOK) ? 0 : 1;
|
||||
|
||||
ret = memcpy_s((VOID *)g_excContent, MAX_EXC_MEM_SIZE, g_excInfo.context, sizeof(EXC_CONTEXT_S));
|
||||
g_excContent = (UINT8 *)g_excContent + sizeof(EXC_CONTEXT_S);
|
||||
failCnt += (ret == EOK) ? 0 : 1;
|
||||
|
||||
if (failCnt != 0) {
|
||||
PRINT_ERR("OsExcSave2DDR copy exc info failed, cnt:%d\n", failCnt);
|
||||
}
|
||||
|
||||
for (index = 0; index < (OS_EXC_TYPE_MAX - 1); index++) {
|
||||
if (g_excArray[index].uwValid == FALSE) {
|
||||
continue;
|
||||
}
|
||||
OsExcSaveInfo(g_excArray[index].uwType, g_excArray[index].pFnExcInfoCb, g_excArray[index].pArg);
|
||||
}
|
||||
*((UINT32 *)g_excContent) = OS_EXC_TYPE_MAX;
|
||||
g_excContent = (UINT8 *)g_excContent + sizeof(UINT32);
|
||||
return;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_INIT VOID OsExcInit(UINT32 arraySize)
|
||||
{
|
||||
g_hwiForm[HARDFAULT_IRQN + OS_SYS_VECTOR_CNT] = OsExcHardFault;
|
||||
g_hwiForm[NonMaskableInt_IRQn + OS_SYS_VECTOR_CNT] = OsExcNMI;
|
||||
g_hwiForm[MemoryManagement_IRQn + OS_SYS_VECTOR_CNT] = OsExcMemFault;
|
||||
g_hwiForm[BusFault_IRQn + OS_SYS_VECTOR_CNT] = OsExcBusFault;
|
||||
g_hwiForm[UsageFault_IRQn + OS_SYS_VECTOR_CNT] = OsExcUsageFault;
|
||||
g_hwiForm[SVCall_IRQn + OS_SYS_VECTOR_CNT] = OsExcSvcCall;
|
||||
/* Enable USGFAULT, BUSFAULT, MEMFAULT */
|
||||
*(volatile UINT32 *)OS_NVIC_SHCSR |= (USGFAULT | BUSFAULT | MEMFAULT);
|
||||
/* Enable DIV 0 and unaligned exception */ // 因为文件系统存在非对齐操作,故此异常暂不接管
|
||||
|
||||
*(volatile UINT32 *)OS_NVIC_CCR |= DIV0FAULT;
|
||||
g_excArraySize = arraySize;
|
||||
|
||||
OsExcRegister(OS_EXC_TYPE_NVIC, (EXC_INFO_SAVE_CALLBACK)OsExcSaveIntStatus, NULL);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
|
@ -0,0 +1,98 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef _LOS_EXC_PRI_H
|
||||
#define _LOS_EXC_PRI_H
|
||||
|
||||
#include "los_exc.h"
|
||||
#include "los_sys_pri.h"
|
||||
#ifdef LOSCFG_LIB_LIBC
|
||||
#include "string.h"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
typedef enum {
|
||||
OS_EXC_TYPE_CONTEXT = 0,
|
||||
OS_EXC_TYPE_TSK = 1,
|
||||
OS_EXC_TYPE_QUE = 2,
|
||||
OS_EXC_TYPE_NVIC = 3,
|
||||
OS_EXC_TYPE_TSK_SWITCH = 4,
|
||||
OS_EXC_TYPE_MEM = 5,
|
||||
OS_EXC_TYPE_MAX = 6
|
||||
} ExcInfoType;
|
||||
|
||||
typedef struct tagExcInfoCallBackArray {
|
||||
ExcInfoType uwType;
|
||||
UINT32 uwValid;
|
||||
EXC_INFO_SAVE_CALLBACK pFnExcInfoCb;
|
||||
VOID* pArg;
|
||||
} ExcInfoArray;
|
||||
|
||||
|
||||
|
||||
#define MAX_SCENE_INFO_SIZE (8 + sizeof(ExcInfo) - 4 + sizeof(EXC_CONTEXT_S))
|
||||
#define MAX_TSK_INFO_SIZE (8 + sizeof(TSK_INFO_S) * (LOSCFG_BASE_CORE_TSK_LIMIT + 1))
|
||||
#define MAX_INT_INFO_SIZE (8 + 0x164)
|
||||
|
||||
#if (LOSCFG_BASE_IPC_QUEUE == YES)
|
||||
#define MAX_QUEUE_INFO_SIZE (8 + sizeof(QUEUE_INFO_S) * LOSCFG_BASE_IPC_QUEUE_LIMIT)
|
||||
#else
|
||||
#define MAX_QUEUE_INFO_SIZE (0)
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_BASE_CORE_EXC_TSK_SWITCH == YES)
|
||||
#define MAX_SWITCH_INFO_SIZE (8 + (sizeof(UINT32) + sizeof(CHAR) * LOS_TASK_NAMELEN) * OS_TASK_SWITCH_INFO_COUNT)
|
||||
#else
|
||||
#define MAX_SWITCH_INFO_SIZE (0)
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_BASE_MEM_NODE_INTEGRITY_CHECK == YES)
|
||||
#define MAX_MEM_INFO_SIZE (8 + sizeof(MEM_INFO_S) * OS_SYS_MEM_NUM)
|
||||
#else
|
||||
#define MAX_MEM_INFO_SIZE (0)
|
||||
#endif
|
||||
|
||||
#define MAX_EXC_MEM_SIZE ( 4 + MAX_SCENE_INFO_SIZE + MAX_TSK_INFO_SIZE + MAX_QUEUE_INFO_SIZE + MAX_INT_INFO_SIZE + MAX_SWITCH_INFO_SIZE + MAX_MEM_INFO_SIZE + 4)
|
||||
|
||||
VOID OsExcRegister(ExcInfoType type, EXC_INFO_SAVE_CALLBACK func, VOID *arg);
|
||||
VOID LOS_Reboot(VOID);
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif
|
|
@ -0,0 +1,384 @@
|
|||
;
|
||||
; Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
; Copyright (c) 2020, 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
|
||||
.arch armv7e-m
|
||||
.thumb
|
||||
.fpu vfpv4
|
||||
.section .text
|
||||
|
||||
|
||||
.global OsExcNMI
|
||||
.global OsExcHardFault
|
||||
.global OsExcMemFault
|
||||
.global OsExcBusFault
|
||||
.global OsExcUsageFault
|
||||
.global OsExcSvcCall
|
||||
|
||||
.extern OsExcHandleEntry
|
||||
.extern g_vuwLosFlag
|
||||
.extern g_uwCurNestCount
|
||||
.extern g_uwExcTbl
|
||||
.extern g_taskScheduled
|
||||
|
||||
.equ OS_FLG_BGD_ACTIVE, 0x0002
|
||||
|
||||
.equ OS_EXC_CAUSE_NMI, 16
|
||||
.equ OS_EXC_CAUSE_HARDFAULT, 17
|
||||
|
||||
.equ HF_DEBUGEVT, 20
|
||||
.equ HF_VECTBL, 21
|
||||
|
||||
.equ FLAG_ADDR_VALID, 0x10000
|
||||
.equ FLAG_HWI_ACTIVE, 0x20000
|
||||
.equ FLAG_NO_FLOAT, 0x10000000
|
||||
|
||||
.equ OS_NVIC_FSR , 0xE000ED28 //include BusFault/MemFault/UsageFault State Regeister
|
||||
.equ OS_NVIC_HFSR , 0xE000ED2C //HardFault State Regeister
|
||||
.equ OS_NVIC_BFAR , 0xE000ED38
|
||||
.equ OS_NVIC_MMAR , 0xE000ED34
|
||||
.equ OS_NVIC_ACT_BASE , 0xE000E300
|
||||
.equ OS_NVIC_SHCSRS , 0xE000ED24
|
||||
.equ OS_NVIC_SHCSR_MASK , 0xC00
|
||||
|
||||
.type OsExcNMI, %function
|
||||
.global OsExcNMI
|
||||
OsExcNMI:
|
||||
.fnstart
|
||||
.cantunwind
|
||||
MOV R0, #OS_EXC_CAUSE_NMI
|
||||
MOV R1, #0
|
||||
B osExcDispatch
|
||||
.fnend
|
||||
|
||||
.type OsExcHardFault, %function
|
||||
.global OsExcHardFault
|
||||
OsExcHardFault:
|
||||
.fnstart
|
||||
.cantunwind
|
||||
MOV R0, #OS_EXC_CAUSE_HARDFAULT
|
||||
LDR R2, =OS_NVIC_HFSR
|
||||
LDR R2, [R2]
|
||||
|
||||
MOV R1, #HF_DEBUGEVT
|
||||
ORR R0, R0, R1, LSL #0x8
|
||||
TST R2, #0x80000000
|
||||
BNE osExcDispatch // DEBUGEVT
|
||||
|
||||
AND R0, #0x000000FF
|
||||
MOV R1, #HF_VECTBL
|
||||
ORR R0, R0, R1, LSL #0x8
|
||||
TST R2, #0x00000002
|
||||
BNE osExcDispatch // VECTBL
|
||||
|
||||
//if not DEBUGEVT and VECTBL then is FORCED
|
||||
AND R0, #0x000000FF
|
||||
|
||||
LDR R2, =OS_NVIC_FSR
|
||||
LDR R2, [R2]
|
||||
|
||||
TST R2, #0x8000 // BFARVALID
|
||||
BNE _HFBusFault // BusFault
|
||||
|
||||
TST R2, #0x80 // MMARVALID
|
||||
BNE _HFMemFault // MemFault
|
||||
|
||||
MOV R12,#0
|
||||
B osHFExcCommonBMU
|
||||
.fnend
|
||||
|
||||
.type _HFBusFault, %function
|
||||
|
||||
_HFBusFault:
|
||||
.fnstart
|
||||
.cantunwind
|
||||
LDR R1, =OS_NVIC_BFAR
|
||||
LDR R1, [R1]
|
||||
MOV R12, #FLAG_ADDR_VALID
|
||||
B osHFExcCommonBMU
|
||||
.fnend
|
||||
|
||||
.type _HFMemFault, %function
|
||||
|
||||
_HFMemFault:
|
||||
.fnstart
|
||||
.cantunwind
|
||||
LDR R1, =OS_NVIC_MMAR
|
||||
LDR R1, [R1]
|
||||
MOV R12, #FLAG_ADDR_VALID
|
||||
.fnend
|
||||
|
||||
.type osHFExcCommonBMU, %function
|
||||
.global osHFExcCommonBMU
|
||||
osHFExcCommonBMU:
|
||||
.fnstart
|
||||
.cantunwind
|
||||
CLZ R2, R2
|
||||
LDR R3, =g_uwExcTbl
|
||||
ADD R3, R3, R2
|
||||
LDRB R2, [R3]
|
||||
ORR R0, R0, R2, LSL #0x8
|
||||
ORR R0, R12
|
||||
B osExcDispatch
|
||||
.fnend
|
||||
|
||||
.type OsExcSvcCall, %function
|
||||
.global OsExcSvcCall
|
||||
OsExcSvcCall:
|
||||
.fnstart
|
||||
.cantunwind
|
||||
TST LR, #0x4
|
||||
ITE EQ
|
||||
MRSEQ R0, MSP
|
||||
MRSNE R0, PSP
|
||||
LDR R1, [R0,#24]
|
||||
LDRB R0, [R1,#-2]
|
||||
MOV R1, #0
|
||||
B osExcDispatch
|
||||
.fnend
|
||||
|
||||
.type OsExcBusFault, %function
|
||||
.global OsExcBusFault
|
||||
OsExcBusFault:
|
||||
.fnstart
|
||||
.cantunwind
|
||||
LDR R0, =OS_NVIC_FSR
|
||||
LDR R0, [R0]
|
||||
|
||||
TST R0, #0x8000 // BFARVALID
|
||||
BEQ _ExcBusNoADDR
|
||||
LDR R1, =OS_NVIC_BFAR
|
||||
LDR R1, [R1]
|
||||
MOV R12, #FLAG_ADDR_VALID
|
||||
AND R0, #0x1F00
|
||||
|
||||
B osExcCommonBMU
|
||||
.fnend
|
||||
|
||||
.type _ExcBusNoADDR, %function
|
||||
.global _ExcBusNoADDR
|
||||
_ExcBusNoADDR:
|
||||
.fnstart
|
||||
.cantunwind
|
||||
MOV R12,#0
|
||||
B osExcCommonBMU
|
||||
.fnend
|
||||
|
||||
.type OsExcMemFault, %function
|
||||
.global OsExcMemFault
|
||||
OsExcMemFault:
|
||||
.fnstart
|
||||
.cantunwind
|
||||
LDR R0, =OS_NVIC_FSR
|
||||
LDR R0, [R0]
|
||||
|
||||
TST R0, #0x80 // MMARVALID
|
||||
BEQ _ExcMemNoADDR
|
||||
LDR R1, =OS_NVIC_MMAR
|
||||
LDR R1, [R1]
|
||||
MOV R12, #FLAG_ADDR_VALID
|
||||
AND R0, #0x1B
|
||||
|
||||
B osExcCommonBMU
|
||||
.fnend
|
||||
|
||||
.type _ExcMemNoADDR, %function
|
||||
.global _ExcMemNoADDR
|
||||
_ExcMemNoADDR:
|
||||
.fnstart
|
||||
.cantunwind
|
||||
MOV R12,#0
|
||||
B osExcCommonBMU
|
||||
.fnend
|
||||
|
||||
.type OsExcUsageFault, %function
|
||||
.global OsExcUsageFault
|
||||
OsExcUsageFault:
|
||||
.fnstart
|
||||
.cantunwind
|
||||
LDR R0, =OS_NVIC_FSR
|
||||
LDR R0, [R0]
|
||||
|
||||
LDR R1, =#0x030F
|
||||
LSL R1, #16
|
||||
AND R0, R1
|
||||
MOV R12, #0
|
||||
.fnend
|
||||
|
||||
.type osExcCommonBMU, %function
|
||||
.global osExcCommonBMU
|
||||
osExcCommonBMU:
|
||||
.fnstart
|
||||
.cantunwind
|
||||
CLZ R0, R0
|
||||
LDR R3, =g_uwExcTbl
|
||||
ADD R3, R3, R0
|
||||
LDRB R0, [R3]
|
||||
ORR R0, R0, R12
|
||||
.fnend
|
||||
// R0 -- EXCCAUSE(bit 16 is 1 if EXCADDR valid), R1 -- EXCADDR
|
||||
|
||||
.type osExcDispatch, %function
|
||||
.global osExcDispatch
|
||||
osExcDispatch:
|
||||
.fnstart
|
||||
.cantunwind
|
||||
LDR R2, =OS_NVIC_ACT_BASE
|
||||
MOV R12, #8 // R12 is hwi check loop counter
|
||||
.fnend
|
||||
|
||||
.type _hwiActiveCheck, %function
|
||||
.global _hwiActiveCheck
|
||||
_hwiActiveCheck:
|
||||
.fnstart
|
||||
.cantunwind
|
||||
LDR R3, [R2] // R3 store active hwi register when exc
|
||||
CMP R3, #0
|
||||
BEQ _hwiActiveCheckNext
|
||||
|
||||
// exc occured in IRQ
|
||||
ORR R0, #FLAG_HWI_ACTIVE
|
||||
RBIT R2, R3
|
||||
CLZ R2, R2
|
||||
AND R12, #1
|
||||
ADD R2, R2, R12, LSL #5 // calculate R2 (hwi number) as uwPid
|
||||
.fnend
|
||||
|
||||
.type _ExcInMSP, %function
|
||||
.global _ExcInMSP
|
||||
_ExcInMSP:
|
||||
.fnstart
|
||||
.cantunwind
|
||||
CMP LR, #0XFFFFFFED
|
||||
BNE _NoFloatInMsp
|
||||
ADD R3, R13, #104
|
||||
PUSH {R3}
|
||||
MRS R12, PRIMASK // store message-->exc: disable int?
|
||||
PUSH {R4-R12} // store message-->exc: {R4-R12}
|
||||
VPUSH {D8-D15}
|
||||
B _handleEntry
|
||||
.fnend
|
||||
|
||||
.type _NoFloatInMsp, %function
|
||||
.global _NoFloatInMsp
|
||||
_NoFloatInMsp:
|
||||
.fnstart
|
||||
.cantunwind
|
||||
ADD R3, R13, #32
|
||||
PUSH {R3} // save IRQ SP // store message-->exc: MSP(R13)
|
||||
|
||||
MRS R12, PRIMASK // store message-->exc: disable int?
|
||||
PUSH {R4-R12} // store message-->exc: {R4-R12}
|
||||
ORR R0, R0, #FLAG_NO_FLOAT
|
||||
B _handleEntry
|
||||
.fnend
|
||||
|
||||
.type _hwiActiveCheckNext, %function
|
||||
.global _hwiActiveCheckNext
|
||||
_hwiActiveCheckNext:
|
||||
.fnstart
|
||||
.cantunwind
|
||||
ADD R2, #4 // next NVIC ACT ADDR
|
||||
SUBS R12, #1
|
||||
BNE _hwiActiveCheck
|
||||
|
||||
/*NMI interrupt excption*/
|
||||
LDR R2, =OS_NVIC_SHCSRS
|
||||
LDRH R2,[R2]
|
||||
LDR R3,=OS_NVIC_SHCSR_MASK
|
||||
AND R2, R2,R3
|
||||
CMP R2,#0
|
||||
BNE _ExcInMSP
|
||||
// exc occured in Task or Init or exc
|
||||
// reserved for register info from task stack
|
||||
|
||||
LDR R2, =g_taskScheduled
|
||||
LDR R2, [R2]
|
||||
TST R2, #1 // OS_FLG_BGD_ACTIVE
|
||||
BEQ _ExcInMSP // if exc occured in Init then branch
|
||||
|
||||
|
||||
CMP LR, #0xFFFFFFED //auto push floating registers
|
||||
BNE _NoFloatInPsp
|
||||
|
||||
// exc occured in Task
|
||||
MOV R2, R13
|
||||
SUB R13, #96 // add 8 Bytes reg(for STMFD)
|
||||
|
||||
MRS R3, PSP
|
||||
ADD R12, R3, #104
|
||||
PUSH {R12} // save task SP
|
||||
|
||||
MRS R12, PRIMASK
|
||||
PUSH {R4-R12}
|
||||
VPUSH {D8-D15}
|
||||
|
||||
// copy auto saved task register
|
||||
|
||||
LDMFD R3!, {R4-R11} // R4-R11 store PSP reg(auto push when exc in task)
|
||||
VLDMIA R3!, {D8-D15}
|
||||
VSTMDB R2!, {D8-D15}
|
||||
STMFD R2!, {R4-R11}
|
||||
B _handleEntry
|
||||
.fnend
|
||||
|
||||
.type _NoFloatInPsp, %function
|
||||
.global _NoFloatInPsp
|
||||
_NoFloatInPsp:
|
||||
.fnstart
|
||||
.cantunwind
|
||||
MOV R2, R13 //no auto push floating registers
|
||||
SUB R13, #32 // add 8 Bytes reg(for STMFD)
|
||||
|
||||
MRS R3, PSP
|
||||
ADD R12, R3, #32
|
||||
PUSH {R12} // save task SP
|
||||
|
||||
MRS R12, PRIMASK
|
||||
PUSH {R4-R12}
|
||||
|
||||
LDMFD R3, {R4-R11} // R4-R11 store PSP reg(auto push when exc in task)
|
||||
STMFD R2!, {R4-R11}
|
||||
ORR R0, R0, #FLAG_NO_FLOAT
|
||||
.fnend
|
||||
|
||||
.type _handleEntry, %function
|
||||
.global _handleEntry
|
||||
_handleEntry:
|
||||
.fnstart
|
||||
.cantunwind
|
||||
MOV R3, R13 // R13:the 4th param
|
||||
CPSID I
|
||||
CPSID F
|
||||
B OsExcHandleEntry
|
||||
|
||||
NOP
|
||||
.fnend
|
|
@ -0,0 +1,131 @@
|
|||
;
|
||||
; Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
; Copyright (c) 2020, 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
|
||||
.arch armv7e-m
|
||||
.thumb
|
||||
.fpu vfpv4
|
||||
|
||||
|
||||
.extern g_saveSRContext
|
||||
.extern g_saveAR
|
||||
.extern g_losTask
|
||||
|
||||
.global OsSRSaveRegister
|
||||
.global OsSRRestoreRegister
|
||||
|
||||
.section .text
|
||||
.thumb
|
||||
|
||||
.type OsSRSaveRegister, %function
|
||||
.global OsSRSaveRegister
|
||||
OsSRSaveRegister:
|
||||
.fnstart
|
||||
.cantunwind
|
||||
PUSH {R2}
|
||||
LDR R2, =g_saveAR
|
||||
STR R0, [R2]
|
||||
STR R1, [R2, #4]
|
||||
POP {R2}
|
||||
|
||||
MRS R0, PSP
|
||||
|
||||
VSTMDB R0!, {D0-D7}
|
||||
VMRS R1, FPSCR
|
||||
STMFD R0!, {R1} //FPSCR
|
||||
STMFD R0!, {R1} //NO_NAME
|
||||
|
||||
MRS R1, PSR
|
||||
ORR R1, R1, #0x01000000
|
||||
STMFD R0!, {R1}
|
||||
|
||||
MOV R1, LR
|
||||
STMFD R0!, {R1} // ;PC
|
||||
STMFD R0!, {R1} // ;LR
|
||||
|
||||
STMFD R0!, {R12}
|
||||
|
||||
MOV R12, R0
|
||||
|
||||
LDR R0, =g_saveAR
|
||||
LDR R0, [R0]
|
||||
LDR R1, =g_saveAR
|
||||
LDR R1, [R1, #4]
|
||||
|
||||
STMFD R12!, {R0-R3}
|
||||
STMFD R12!, {R4-R11}
|
||||
VSTMDB R12!, {D8-D15}
|
||||
|
||||
MRS R0, CONTROL
|
||||
STMFD R12!, {R0}
|
||||
|
||||
MRS R0, MSP
|
||||
STMFD R12!, {R0}
|
||||
|
||||
LDR R1, =g_losTask
|
||||
LDR R1, [R1]
|
||||
STR R12, [R1]
|
||||
|
||||
MSR PSP, R12
|
||||
BX LR
|
||||
.fnend
|
||||
|
||||
.type OsSRSaveRegister, %function
|
||||
.global OsSRSaveRegister
|
||||
OsSRRestoreRegister:
|
||||
.fnstart
|
||||
.cantunwind
|
||||
MRS R0, MSP
|
||||
ADD R0, R0, #8
|
||||
MSR MSP, R0
|
||||
|
||||
LDR R0, =g_losTask
|
||||
LDR R0, [R0]
|
||||
LDR R12, [R0]
|
||||
|
||||
LDR R0, =g_saveSRContext
|
||||
ADD R0, R0, #120
|
||||
MSR PSP, R0
|
||||
|
||||
LDMFD R12!,{R0}
|
||||
MSR MSP, R0
|
||||
|
||||
LDMFD R12!,{R0}
|
||||
MSR CONTROL, R0
|
||||
|
||||
VLDMIA R12!,{D8-D15}
|
||||
LDMFD R12!,{R4-R11}
|
||||
|
||||
MSR PSP, R12
|
||||
MOV LR, #0xFFFFFFED
|
||||
BX LR
|
||||
|
||||
.fnend
|
|
@ -0,0 +1,363 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef _LOS_EXC_H
|
||||
#define _LOS_EXC_H
|
||||
|
||||
#include "los_hwi.h"
|
||||
#include "los_task_pri.h"
|
||||
#include "los_queue.h"
|
||||
#include "los_memcheck.h"
|
||||
#include "los_sys_pri.h"
|
||||
#ifdef LOSCFG_LIB_LIBC
|
||||
#include "string.h"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
|
||||
#define OS_EXC_IN_INIT 0
|
||||
#define OS_EXC_IN_TASK 1
|
||||
#define OS_EXC_IN_HWI 2
|
||||
|
||||
#define OS_EXC_MAX_BUF_LEN 25
|
||||
#define OS_EXC_MAX_NEST_DEPTH 1
|
||||
|
||||
#define OS_NVIC_SHCSR 0xE000ED24
|
||||
#define OS_NVIC_CCR 0xE000ED14
|
||||
|
||||
#define OS_NVIC_INT_ENABLE_SIZE 0x20
|
||||
#define OS_NVIC_INT_PRI_SIZE 0xF0
|
||||
#define OS_NVIC_EXCPRI_SIZE 0xC
|
||||
|
||||
#define OS_NVIC_INT_PEND_SIZE OS_NVIC_INT_ACT_SIZE
|
||||
#define OS_NVIC_INT_ACT_SIZE OS_NVIC_INT_ENABLE_SIZE
|
||||
|
||||
#define OS_EXC_FLAG_NO_FLOAT 0x10000000
|
||||
#define OS_EXC_FLAG_FAULTADDR_VALID 0x01
|
||||
#define OS_EXC_FLAG_IN_HWI 0x02
|
||||
|
||||
#define OS_EXC_IMPRECISE_ACCESS_ADDR 0xABABABAB
|
||||
|
||||
/**
|
||||
*@ingroup los_exc
|
||||
* the struct of register files
|
||||
*
|
||||
* description: the register files that saved when exception triggered
|
||||
*
|
||||
* notes:the following register with prefix 'uw' correspond to the registers in the cpu data sheet.
|
||||
*/
|
||||
typedef struct tagExcContext {
|
||||
//handler save
|
||||
#if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
|
||||
(defined (__FPU_USED ) && (__FPU_USED == 1U)) )
|
||||
UINT32 S16;
|
||||
UINT32 S17;
|
||||
UINT32 S18;
|
||||
UINT32 S19;
|
||||
UINT32 S20;
|
||||
UINT32 S21;
|
||||
UINT32 S22;
|
||||
UINT32 S23;
|
||||
UINT32 S24;
|
||||
UINT32 S25;
|
||||
UINT32 S26;
|
||||
UINT32 S27;
|
||||
UINT32 S28;
|
||||
UINT32 S29;
|
||||
UINT32 S30;
|
||||
UINT32 S31;
|
||||
#endif
|
||||
UINT32 uwR4;
|
||||
UINT32 uwR5;
|
||||
UINT32 uwR6;
|
||||
UINT32 uwR7;
|
||||
UINT32 uwR8;
|
||||
UINT32 uwR9;
|
||||
UINT32 uwR10;
|
||||
UINT32 uwR11;
|
||||
UINT32 uwPriMask;
|
||||
//auto save
|
||||
UINT32 uwSP;
|
||||
UINT32 uwR0;
|
||||
UINT32 uwR1;
|
||||
UINT32 uwR2;
|
||||
UINT32 uwR3;
|
||||
UINT32 uwR12;
|
||||
UINT32 uwLR;
|
||||
UINT32 uwPC;
|
||||
UINT32 uwxPSR;
|
||||
#if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
|
||||
(defined (__FPU_USED) && (__FPU_USED== 1U)))
|
||||
UINT32 S0;
|
||||
UINT32 S1;
|
||||
UINT32 S2;
|
||||
UINT32 S3;
|
||||
UINT32 S4;
|
||||
UINT32 S5;
|
||||
UINT32 S6;
|
||||
UINT32 S7;
|
||||
UINT32 S8;
|
||||
UINT32 S9;
|
||||
UINT32 S10;
|
||||
UINT32 S11;
|
||||
UINT32 S12;
|
||||
UINT32 S13;
|
||||
UINT32 S14;
|
||||
UINT32 S15;
|
||||
UINT32 FPSCR;
|
||||
UINT32 NO_NAME;
|
||||
#endif
|
||||
}EXC_CONTEXT_S;
|
||||
|
||||
typedef UINT32 (*EXC_INFO_SAVE_CALLBACK)(UINT32, VOID*);
|
||||
typedef VOID (*EXC_PROC_FUNC)(UINT32, EXC_CONTEXT_S *);
|
||||
VOID OsExcHandleEntry(UINT32 excType, UINT32 faultAddr, UINT32 pid, EXC_CONTEXT_S *excBufAddr);
|
||||
|
||||
/**
|
||||
* @ingroup los_hwi
|
||||
* @brief: Exception initialization.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to configure the exception function vector table.
|
||||
*
|
||||
* @attention:
|
||||
* <ul><li>None.</li></ul>
|
||||
*
|
||||
*@param uwArraySize [IN] Memory size of exception.
|
||||
*
|
||||
* @retval: None
|
||||
* @par Dependency:
|
||||
* <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
VOID OsExcInit(UINT32 uwArraySize);
|
||||
|
||||
extern VOID OsExcNMI(VOID);
|
||||
extern VOID OsExcHardFault(VOID);
|
||||
extern VOID OsExcMemFault(VOID);
|
||||
extern VOID OsExcBusFault(VOID);
|
||||
extern VOID OsExcUsageFault(VOID);
|
||||
extern VOID OsExcSvcCall(VOID);
|
||||
extern VOID OsBackTrace(VOID);
|
||||
extern UINT8 g_aucTaskArray[];
|
||||
|
||||
/**
|
||||
*@ingroup los_exc
|
||||
*@brief Kernel panic function.
|
||||
*
|
||||
*@par Description:
|
||||
*Stack function that prints kernel panics.
|
||||
*@attention After this function is called and stack information is printed, the system will fail to respond.
|
||||
*@attention The input parameter can be NULL.
|
||||
*@param fmt [IN] Type #char* : variadic argument.
|
||||
*
|
||||
*@retval #None.
|
||||
*
|
||||
*@par Dependency:
|
||||
*los_exc.h: the header file that contains the API declaration.
|
||||
*@see None.
|
||||
*/
|
||||
VOID LOS_Panic(const CHAR *fmt, ...);
|
||||
|
||||
/**
|
||||
*@ingroup los_exc
|
||||
*Cortex-M3异常具体类型:总线状态寄存器入栈时发生错误
|
||||
*/
|
||||
#define OS_EXC_BF_STKERR 1
|
||||
|
||||
/**
|
||||
*@ingroup los_exc
|
||||
*Cortex-M3异常具体类型:总线状态寄存器出栈时发生错误
|
||||
*/
|
||||
#define OS_EXC_BF_UNSTKERR 2
|
||||
|
||||
/**
|
||||
*@ingroup los_exc
|
||||
*Cortex-M3异常具体类型:总线状态寄存器不精确的数据访问违例
|
||||
*/
|
||||
#define OS_EXC_BF_IMPRECISERR 3
|
||||
|
||||
/**
|
||||
*@ingroup los_exc
|
||||
*Cortex-M3异常具体类型:总线状态寄存器精确的数据访问违例
|
||||
*/
|
||||
#define OS_EXC_BF_PRECISERR 4
|
||||
|
||||
/**
|
||||
*@ingroup los_exc
|
||||
*Cortex-M3异常具体类型:总线状态寄存器取指时的访问违例
|
||||
*/
|
||||
#define OS_EXC_BF_IBUSERR 5
|
||||
|
||||
/**
|
||||
*@ingroup los_exc
|
||||
*Cortex-M3异常具体类型:存储器管理状态寄存器入栈时发生错误
|
||||
*/
|
||||
#define OS_EXC_MF_MSTKERR 6
|
||||
|
||||
/**
|
||||
*@ingroup los_exc
|
||||
*Cortex-M3异常具体类型:存储器管理状态寄存器出栈时发生错误
|
||||
*/
|
||||
#define OS_EXC_MF_MUNSTKERR 7
|
||||
|
||||
/**
|
||||
*@ingroup los_exc
|
||||
*Cortex-M3异常具体类型:存储器管理状态寄存器数据访问违例
|
||||
*/
|
||||
#define OS_EXC_MF_DACCVIOL 8
|
||||
|
||||
/**
|
||||
*@ingroup los_exc
|
||||
*Cortex-M3异常具体类型:存储器管理状态寄存器取指访问违例
|
||||
*/
|
||||
#define OS_EXC_MF_IACCVIOL 9
|
||||
|
||||
|
||||
/**
|
||||
*@ingroup los_exc
|
||||
*Cortex-M3异常具体类型:用法错误,表示除法运算时除数为零
|
||||
*/
|
||||
#define OS_EXC_UF_DIVBYZERO 10
|
||||
|
||||
/**
|
||||
*@ingroup los_exc
|
||||
*Cortex-M3异常具体类型:用法错误,未对齐访问导致的错误
|
||||
*/
|
||||
#define OS_EXC_UF_UNALIGNED 11
|
||||
|
||||
/**
|
||||
*@ingroup los_exc
|
||||
*Cortex-M3异常具体类型:用法错误,试图执行协处理器相关指令
|
||||
*/
|
||||
#define OS_EXC_UF_NOCP 12
|
||||
|
||||
/**
|
||||
*@ingroup los_exc
|
||||
*Cortex-M3异常具体类型:用法错误,在异常返回时试图非法地加载EXC_RETURN到PC
|
||||
*/
|
||||
#define OS_EXC_UF_INVPC 13
|
||||
|
||||
/**
|
||||
*@ingroup los_exc
|
||||
*Cortex-M3异常具体类型:用法错误,试图切入ARM状态
|
||||
*/
|
||||
#define OS_EXC_UF_INVSTATE 14
|
||||
|
||||
/**
|
||||
*@ingroup los_exc
|
||||
*Cortex-M3异常具体类型:用法错误,执行的指令其编码是未定义的——解码不能
|
||||
*/
|
||||
#define OS_EXC_UF_UNDEFINSTR 15
|
||||
|
||||
/**
|
||||
*@ingroup los_exc
|
||||
*Cortex-M3异常具体类型:NMI中断
|
||||
*/
|
||||
|
||||
#define OS_EXC_CAUSE_NMI 16
|
||||
|
||||
/**
|
||||
*@ingroup los_exc
|
||||
*Cortex-M3异常具体类型:硬fault
|
||||
*/
|
||||
#define OS_EXC_CAUSE_HARDFAULT 17
|
||||
|
||||
/**
|
||||
*@ingroup los_exc
|
||||
*Cortex-M3异常具体类型:任务处理函数退出
|
||||
*/
|
||||
#define OS_EXC_CAUSE_TASK_EXIT 18
|
||||
|
||||
/**
|
||||
*@ingroup los_exc
|
||||
*Cortex-M3异常具体类型:致命错误
|
||||
*/
|
||||
#define OS_EXC_CAUSE_FATAL_ERR 19
|
||||
|
||||
/**
|
||||
*@ingroup los_exc
|
||||
*Cortex-M3异常具体类型:调试事件导致的硬fault
|
||||
*/
|
||||
#define OS_EXC_CAUSE_DEBUGEVT 20
|
||||
|
||||
/**
|
||||
*@ingroup los_exc
|
||||
*Cortex-M3异常具体类型:取向量时发生的硬fault
|
||||
*/
|
||||
#define OS_EXC_CAUSE_VECTBL 21
|
||||
|
||||
/**
|
||||
*@ingroup los_exc
|
||||
* 异常信息结构体
|
||||
*
|
||||
* 描述:M4平台下的异常触发时保存的异常信息
|
||||
*
|
||||
*/
|
||||
typedef struct tagExcInfo {
|
||||
/**< 异常发生阶段: 0表示异常发生在初始化中,1表示异常发生在任务中,2表示异常发生在中断中 */
|
||||
UINT16 phase;
|
||||
/**< 异常类型,出异常时对照上面列出的1-19号 */
|
||||
UINT16 type;
|
||||
/**< 若为精确地址访问错误表示异常发生时的错误访问地址 */
|
||||
UINT32 faultAddr;
|
||||
/**< 在中断中发生异常,表示中断号。在任务中发生异常,表示任务id,如果发生在初始化中,则为0xffffffff */
|
||||
UINT32 thrdPid;
|
||||
/**< 异常嵌套个数,目前仅支持第一次进入异常时执行注册的钩子函数 */
|
||||
UINT16 nestCnt;
|
||||
/**< 保留 */
|
||||
UINT16 reserved;
|
||||
/**< 自动压栈浮点寄存器的异常发生时刻的硬件上下文 */
|
||||
EXC_CONTEXT_S * context;
|
||||
} ExcInfo;
|
||||
|
||||
extern UINT32 g_curNestCount;
|
||||
extern UINT32 g_vuwIntCount;
|
||||
|
||||
static VOID OsExcSave2DDR(VOID);
|
||||
VOID OsExcInfoDisplay(ExcInfo *exc);
|
||||
|
||||
|
||||
extern TaskSwitchInfo g_taskSwitchInfo;
|
||||
extern UINT8 g_uwExcTbl[32];
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
|
||||
#endif /* _LOS_EXC_H */
|
||||
|
|
@ -0,0 +1,233 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup los_hw hardware
|
||||
* @ingroup kernel
|
||||
*/
|
||||
|
||||
#ifndef _LOS_HW_H
|
||||
#define _LOS_HW_H
|
||||
|
||||
#include "los_base.h"
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/* *
|
||||
* @ingroup los_hw
|
||||
* The initialization value of stack space.
|
||||
*/
|
||||
#define EMPTY_STACK 0xCACA
|
||||
|
||||
/* *
|
||||
* @ingroup los_hw
|
||||
* Trigger a task.
|
||||
*/
|
||||
#define OsTaskTrap() __asm(" TRAP #31")
|
||||
|
||||
/* *
|
||||
* @ingroup los_hw
|
||||
* Check task schedule.
|
||||
*/
|
||||
#define LOS_CHECK_SCHEDULE ((!g_losTaskLock))
|
||||
|
||||
/* *
|
||||
* @ingroup los_hw
|
||||
* Define the type of a task context control block.
|
||||
*/
|
||||
typedef struct tagTskContext {
|
||||
#if ((defined(__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
|
||||
(defined(__FPU_USED) && (__FPU_USED == 1U)))
|
||||
UINT32 S16;
|
||||
UINT32 S17;
|
||||
UINT32 S18;
|
||||
UINT32 S19;
|
||||
UINT32 S20;
|
||||
UINT32 S21;
|
||||
UINT32 S22;
|
||||
UINT32 S23;
|
||||
UINT32 S24;
|
||||
UINT32 S25;
|
||||
UINT32 S26;
|
||||
UINT32 S27;
|
||||
UINT32 S28;
|
||||
UINT32 S29;
|
||||
UINT32 S30;
|
||||
UINT32 S31;
|
||||
#endif
|
||||
UINT32 uwR4;
|
||||
UINT32 uwR5;
|
||||
UINT32 uwR6;
|
||||
UINT32 uwR7;
|
||||
UINT32 uwR8;
|
||||
UINT32 uwR9;
|
||||
UINT32 uwR10;
|
||||
UINT32 uwR11;
|
||||
UINT32 uwPriMask;
|
||||
UINT32 uwR0;
|
||||
UINT32 uwR1;
|
||||
UINT32 uwR2;
|
||||
UINT32 uwR3;
|
||||
UINT32 uwR12;
|
||||
UINT32 uwLR;
|
||||
UINT32 uwPC;
|
||||
UINT32 uwxPSR;
|
||||
#if ((defined(__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
|
||||
(defined(__FPU_USED) && (__FPU_USED == 1U)))
|
||||
UINT32 S0;
|
||||
UINT32 S1;
|
||||
UINT32 S2;
|
||||
UINT32 S3;
|
||||
UINT32 S4;
|
||||
UINT32 S5;
|
||||
UINT32 S6;
|
||||
UINT32 S7;
|
||||
UINT32 S8;
|
||||
UINT32 S9;
|
||||
UINT32 S10;
|
||||
UINT32 S11;
|
||||
UINT32 S12;
|
||||
UINT32 S13;
|
||||
UINT32 S14;
|
||||
UINT32 S15;
|
||||
UINT32 FPSCR;
|
||||
UINT32 NO_NAME;
|
||||
#endif
|
||||
} TaskContext;
|
||||
|
||||
/* *
|
||||
* @ingroup los_hw
|
||||
* @brief: Task stack initialization.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to initialize the task stack.
|
||||
*
|
||||
* @attention:
|
||||
* <ul><li>None.</li></ul>
|
||||
*
|
||||
* @param taskID [IN] Type#UINT32: TaskID.
|
||||
* @param stackSize [IN] Type#UINT32: Total size of the stack.
|
||||
* @param topStack [IN] Type#VOID *: Top of task's stack.
|
||||
*
|
||||
* @retval: context Type#TaskContext *.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_hw.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern VOID *OsTskStackInit(UINT32 taskID, UINT32 stackSize, VOID *topStack);
|
||||
|
||||
/* *
|
||||
* @ingroup los_hw
|
||||
* @brief: Task scheduling Function.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to scheduling task.
|
||||
*
|
||||
* @attention:
|
||||
* <ul><li>None.</li></ul>
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval: None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_hw.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern VOID OsSchedule(VOID);
|
||||
|
||||
/* *
|
||||
* @ingroup los_hw
|
||||
* @brief: Function to determine whether task scheduling is required.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to Judge and entry task scheduling.
|
||||
*
|
||||
* @attention:
|
||||
* <ul><li>None.</li></ul>
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval: None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_hw.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern VOID LOS_Schedule(VOID);
|
||||
|
||||
/**
|
||||
* @ingroup los_hw
|
||||
* @brief: Function to task exit.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to exit task.
|
||||
*
|
||||
* @attention:
|
||||
* <ul><li>None.</li></ul>
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval: None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_hw.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
LITE_OS_SEC_TEXT_MINOR VOID OsTaskExit(VOID);
|
||||
|
||||
/* *
|
||||
* @ingroup los_hw
|
||||
* @brief: The M3 wait interrupt instruction.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to make CPU enter to power-save mode.
|
||||
*
|
||||
* @attention:
|
||||
* <ul><li>None.</li></ul>
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval: None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_hw.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern VOID OsEnterSleep(VOID);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_HW_H */
|
||||
|
|
@ -0,0 +1,720 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup los_hwi Hardware interrupt
|
||||
* @ingroup kernel
|
||||
*/
|
||||
#ifndef _LOS_HWI_H
|
||||
#define _LOS_HWI_H
|
||||
|
||||
#include "los_base.h"
|
||||
#include "los_sys.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Maximum number of used hardware interrupts.
|
||||
*/
|
||||
#ifndef OS_HWI_MAX_NUM
|
||||
#define OS_HWI_MAX_NUM LOSCFG_PLATFORM_HWI_LIMIT
|
||||
#endif
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Highest priority of a hardware interrupt.
|
||||
*/
|
||||
#ifndef OS_HWI_PRIO_HIGHEST
|
||||
#define OS_HWI_PRIO_HIGHEST 0
|
||||
#endif
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Lowest priority of a hardware interrupt.
|
||||
*/
|
||||
#ifndef OS_HWI_PRIO_LOWEST
|
||||
#define OS_HWI_PRIO_LOWEST 7
|
||||
#endif
|
||||
|
||||
/* *
|
||||
* @ingroup los_config
|
||||
* Configuration item for interrupt with argument
|
||||
*/
|
||||
#ifndef OS_HWI_WITH_ARG
|
||||
#define OS_HWI_WITH_ARG NO
|
||||
#endif
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Define the type of a hardware interrupt number.
|
||||
*/
|
||||
typedef UINT32 HWI_HANDLE_T;
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Define the type of a hardware interrupt priority.
|
||||
*/
|
||||
typedef UINT16 HWI_PRIOR_T;
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Define the type of hardware interrupt mode configurations.
|
||||
*/
|
||||
typedef UINT16 HWI_MODE_T;
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Define the type of the parameter used for the hardware interrupt creation function. The function of this parameter varies among platforms.
|
||||
*/
|
||||
typedef UINT32 HWI_ARG_T;
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Define the type of a hardware interrupt handling function.
|
||||
*/
|
||||
#if (OS_HWI_WITH_ARG == YES)
|
||||
|
||||
typedef VOID (*HWI_PROC_FUNC)(VOID *parm);
|
||||
typedef struct {
|
||||
HWI_PROC_FUNC pfnHandler;
|
||||
VOID *pParm;
|
||||
} HWI_SLAVE_FUNC;
|
||||
|
||||
#else
|
||||
|
||||
typedef VOID (*HWI_PROC_FUNC)(void);
|
||||
|
||||
#endif
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Define the type of a hardware interrupt vector table function.
|
||||
*/
|
||||
typedef VOID (**HWI_VECTOR_FUNC)(void);
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Count of interrupts.
|
||||
*/
|
||||
extern UINT32 g_vuwIntCount;
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* An interrupt is active.
|
||||
*/
|
||||
#define OS_INT_ACTIVE (g_vuwIntCount > 0)
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* An interrupt is inactive.
|
||||
*/
|
||||
#define OS_INT_INACTIVE (!(OS_INT_ACTIVE))
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Count of M-Core system interrupt vector.
|
||||
*/
|
||||
#define OS_SYS_VECTOR_CNT 16
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Count of M-Core interrupt vector.
|
||||
*/
|
||||
#define OS_VECTOR_CNT (OS_SYS_VECTOR_CNT + OS_HWI_MAX_NUM)
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* AIRCR register priority group parameter .
|
||||
*/
|
||||
#define OS_NVIC_AIRCR_PRIGROUP 7
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Boot interrupt vector table.
|
||||
*/
|
||||
extern UINT32 _BootVectors[];
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Hardware interrupt error code: Invalid interrupt number.
|
||||
*
|
||||
* Value: 0x02000900
|
||||
*
|
||||
* Solution: Ensure that the interrupt number is valid. The value range of the interrupt number applicable for a Cortex-A7 platform is [OS_USER_HWI_MIN,OS_USER_HWI_MAX].
|
||||
*/
|
||||
#define OS_ERRNO_HWI_NUM_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x00)
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Hardware interrupt error code: Null hardware interrupt handling function.
|
||||
*
|
||||
* Value: 0x02000901
|
||||
*
|
||||
* Solution: Pass in a valid non-null hardware interrupt handling function.
|
||||
*/
|
||||
#define OS_ERRNO_HWI_PROC_FUNC_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x01)
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Hardware interrupt error code: Insufficient interrupt resources for hardware interrupt creation.
|
||||
*
|
||||
* Value: 0x02000902
|
||||
*
|
||||
* Solution: Increase the configured maximum number of supported hardware interrupts.
|
||||
*/
|
||||
#define OS_ERRNO_HWI_CB_UNAVAILABLE LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x02)
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Hardware interrupt error code: Insufficient memory for hardware interrupt initialization.
|
||||
*
|
||||
* Value: 0x02000903
|
||||
*
|
||||
* Solution: Expand the configured memory.
|
||||
*/
|
||||
#define OS_ERRNO_HWI_NO_MEMORY LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x03)
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Hardware interrupt error code: The interrupt has already been created.
|
||||
*
|
||||
* Value: 0x02000904
|
||||
*
|
||||
* Solution: Check whether the interrupt specified by the passed-in interrupt number has already been created.
|
||||
*/
|
||||
#define OS_ERRNO_HWI_ALREADY_CREATED LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x04)
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Hardware interrupt error code: Invalid interrupt priority.
|
||||
*
|
||||
* Value: 0x02000905
|
||||
*
|
||||
* Solution: Ensure that the interrupt priority is valid. The value range of the interrupt priority applicable for a Cortex-A7 platform is [0,15].
|
||||
*/
|
||||
#define OS_ERRNO_HWI_PRIO_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x05)
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Hardware interrupt error code: Incorrect interrupt creation mode.
|
||||
*
|
||||
* Value: 0x02000906
|
||||
*
|
||||
* Solution: The interrupt creation mode can be only set to OS_HWI_MODE_COMM or OS_HWI_MODE_FAST of which the value can be 0 or 1.
|
||||
*/
|
||||
#define OS_ERRNO_HWI_MODE_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x06)
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Hardware interrupt error code: The interrupt has already been created as a fast interrupt.
|
||||
*
|
||||
* Value: 0x02000907
|
||||
*
|
||||
* Solution: Check whether the interrupt specified by the passed-in interrupt number has already been created.
|
||||
*/
|
||||
#define OS_ERRNO_HWI_FASTMODE_ALREADY_CREATED LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x07)
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* SysTick control and status register.
|
||||
*/
|
||||
#define OS_SYSTICK_CONTROL_REG 0xE000E010
|
||||
|
||||
/* *
|
||||
* @ingroup los_hw
|
||||
* SysTick current value register.
|
||||
*/
|
||||
#define OS_SYSTICK_CURRENT_REG 0xE000E018
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Interrupt Priority-Level Registers.
|
||||
*/
|
||||
#define OS_NVIC_PRI_BASE 0xE000E400
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Interrupt enable register for 0-31.
|
||||
*/
|
||||
#define OS_NVIC_SETENA_BASE 0xE000E100
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* interrupt pending register.
|
||||
*/
|
||||
#define OS_NVIC_SETPEND_BASE 0xE000E200
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Interrupt active register.
|
||||
*/
|
||||
#define OS_NVIC_INT_ACT_BASE 0xE000E300
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Interrupt disable register for 0-31.
|
||||
*/
|
||||
#define OS_NVIC_CLRENA_BASE 0xE000E180
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Interrupt control and status register.
|
||||
*/
|
||||
#define OS_NVIC_INT_CTRL 0xE000ED04
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Vector table offset register.
|
||||
*/
|
||||
#define OS_NVIC_VTOR 0xE000ED08
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Application interrupt and reset control register
|
||||
*/
|
||||
#define OS_NVIC_AIRCR 0xE000ED0C
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* System exception priority register.
|
||||
*/
|
||||
#define OS_NVIC_EXCPRI_BASE 0xE000ED18
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Interrupt No. 1 :reset.
|
||||
*/
|
||||
#define OS_EXC_RESET 1
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Interrupt No. 2 :Non-Maskable Interrupt.
|
||||
*/
|
||||
#define OS_EXC_NMI 2
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Interrupt No. 3 :(hard)fault.
|
||||
*/
|
||||
#define OS_EXC_HARD_FAULT 3
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Interrupt No. 4 :MemManage fault.
|
||||
*/
|
||||
#define OS_EXC_MPU_FAULT 4
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Interrupt No. 5 :Bus fault.
|
||||
*/
|
||||
#define OS_EXC_BUS_FAULT 5
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Interrupt No. 6 :Usage fault.
|
||||
*/
|
||||
#define OS_EXC_USAGE_FAULT 6
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Interrupt No. 11 :SVCall.
|
||||
*/
|
||||
#define OS_EXC_SVC_CALL 11
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Interrupt No. 12 :Debug monitor.
|
||||
*/
|
||||
#define OS_EXC_DBG_MONITOR 12
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Interrupt No. 14 :PendSV.
|
||||
*/
|
||||
#define OS_EXC_PEND_SV 14
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Interrupt No. 15 :SysTick.
|
||||
*/
|
||||
#define OS_EXC_SYS_TICK 15
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* hardware interrupt form mapping handling function array.
|
||||
*/
|
||||
extern HWI_PROC_FUNC g_hwiForm[OS_VECTOR_CNT];
|
||||
|
||||
#if (OS_HWI_WITH_ARG == YES)
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* hardware interrupt Slave form mapping handling function array.
|
||||
*/
|
||||
extern HWI_SLAVE_FUNC g_hwiSlaveForm[OS_VECTOR_CNT];
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Set interrupt vector table.
|
||||
*/
|
||||
#define OsSetVectonr(num, vector, arg) \
|
||||
do { \
|
||||
g_hwiForm[num + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)OsInterrupt; \
|
||||
g_hwiSlaveForm[num + OS_SYS_VECTOR_CNT].pfnHandler = vector; \
|
||||
g_hwiSlaveForm[num + OS_SYS_VECTOR_CNT].pParm = (VOID *)arg; \
|
||||
} while(0)
|
||||
#else
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* hardware interrupt Slave form mapping handling function array.
|
||||
*/
|
||||
extern HWI_PROC_FUNC g_hwiSlaveForm[OS_VECTOR_CNT];
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Set interrupt vector table.
|
||||
*/
|
||||
#define OsSetVector(num, vector) \
|
||||
do { \
|
||||
g_hwiForm[num + OS_SYS_VECTOR_CNT] = OsInterrupt; \
|
||||
g_hwiSlaveForm[num + OS_SYS_VECTOR_CNT] = vector; \
|
||||
} while(0)
|
||||
#endif
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* @brief Create a hardware interrupt.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to configure a hardware interrupt and register a hardware interrupt handling function.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The hardware interrupt module is usable only when the configuration item for hardware interrupt tailoring is enabled.</li>
|
||||
* <li>Hardware interrupt number value range: [OS_USER_HWI_MIN,OS_USER_HWI_MAX]. The value range applicable for a Cortex-A7 platform is [32,95].</li>
|
||||
* <li>OS_HWI_MAX_NUM specifies the maximum number of interrupts that can be created.</li>
|
||||
* <li>Before executing an interrupt on a platform, refer to the chip manual of the platform.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param hwiNum [IN] Type#HWI_HANDLE_T: hardware interrupt number. The value range applicable for a Cortex-A7 platform is [32,95].
|
||||
* @param hwiPrio [IN] Type#HWI_PRIOR_T: hardware interrupt priority. Ignore this parameter temporarily.
|
||||
* @param mode [IN] Type#HWI_MODE_T: hardware interrupt mode. Ignore this parameter temporarily.
|
||||
* @param handler [IN] Type#HWI_PROC_FUNC: interrupt handler used when a hardware interrupt is triggered.
|
||||
* @param arg [IN] Type#HWI_ARG_T: input parameter of the interrupt handler used when a hardware interrupt is triggered.
|
||||
*
|
||||
* @retval #OS_ERRNO_HWI_PROC_FUNC_NULL 0x02000901: Null hardware interrupt handling function.
|
||||
* @retval #OS_ERRNO_HWI_NUM_INVALID 0x02000900: Invalid interrupt number.
|
||||
* @retval #OS_ERRNO_HWI_NO_MEMORY 0x02000903: Insufficient memory for hardware interrupt creation.
|
||||
* @retval #OS_ERRNO_HWI_ALREADY_CREATED 0x02000904: The interrupt handler being created has already been created.
|
||||
* @retval #LOS_OK 0 : The interrupt is successfully created.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern UINT32 LOS_HwiCreate(HWI_HANDLE_T hwiNum,
|
||||
HWI_PRIOR_T hwiPrio,
|
||||
HWI_MODE_T mode,
|
||||
HWI_PROC_FUNC handler,
|
||||
HWI_ARG_T arg);
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* @brief: Hardware interrupt entry function.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used as all hardware interrupt handling function entry.
|
||||
*
|
||||
* @attention:
|
||||
* <ul><li>None.</li></ul>
|
||||
*
|
||||
* @param:None.
|
||||
*
|
||||
* @retval:None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern VOID OsInterrupt(VOID);
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* @brief: Get a interrupt number.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to get the current interrupt number.
|
||||
*
|
||||
* @attention:
|
||||
* <ul><li>None.</li></ul>
|
||||
*
|
||||
* @param: None.
|
||||
*
|
||||
* @retval: Interrupt Indexes number.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern UINT32 OsIntNumGet(VOID);
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* @brief: Default vector handling function.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to configure interrupt for null function.
|
||||
*
|
||||
* @attention:
|
||||
* <ul><li>None.</li></ul>
|
||||
*
|
||||
* @param:None.
|
||||
*
|
||||
* @retval:None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_hwi.h: the header file that contains the API declaration.</li
|
||||
></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern VOID OsHwiDefaultHandler(VOID);
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* @brief: Reset the vector table.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to reset the vector table.
|
||||
*
|
||||
* @attention:
|
||||
* <ul><li>None.</li></ul>
|
||||
*
|
||||
* @param:None.
|
||||
*
|
||||
* @retval:None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern VOID Reset_Handler(VOID);
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* @brief: Pended System Call.
|
||||
*
|
||||
* @par Description:
|
||||
* PendSV can be pended and is useful for an OS to pend an exception
|
||||
* so that an action can be performed after other important tasks are completed.
|
||||
*
|
||||
* @attention:
|
||||
* <ul><li>None.</li></ul>
|
||||
*
|
||||
* @param:None.
|
||||
*
|
||||
* @retval:None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern VOID osPendSV(VOID);
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* @brief Enable all interrupts.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to enable all IRQ and FIQ interrupts in the CPSR.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval CPSR value obtained after all interrupts are enabled.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_IntRestore
|
||||
*/
|
||||
extern UINTPTR LOS_IntUnLock(VOID);
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* @brief Disable all interrupts.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to disable all IRQ and FIQ interrupts in the CPSR.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval CPSR value obtained before all interrupts are disabled.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_IntRestore
|
||||
*/
|
||||
extern UINTPTR LOS_IntLock(VOID);
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* @brief Restore interrupts.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to restore the CPSR value obtained before all interrupts are disabled.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>This API can be called only after all interrupts are disabled, and the input parameter value should be the value returned by calling the all interrupt disabling API.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param intSave [IN] CPSR value obtained before all interrupts are disabled.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_IntLock
|
||||
*/
|
||||
extern VOID LOS_IntRestore(UINTPTR intSave);
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* @brief Get value from xPSR register.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to Get value from xPSR register.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param cntHi [IN] CpuTick High 4 byte
|
||||
* @param cntLo [IN] CpuTick Low 4 byte
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_IntRestore
|
||||
*/
|
||||
extern VOID LOS_GetCpuCycle(UINT32 *cntHi, UINT32 *cntLo);
|
||||
|
||||
#if (LOSCFG_KERNEL_TICKLESS == YES)
|
||||
/**
|
||||
* @ingroup los_hwi
|
||||
* @brief reconfig systick, and clear SysTick_IRQn.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to reconfig systick, and clear SysTick_IRQn.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param cyclesPerTick [IN] Cycles Per Tick
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_IntRestore
|
||||
*/
|
||||
extern VOID LOS_SysTickReload(UINT32 cyclesPerTick);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_hwi
|
||||
* @brief Get System cycle count.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to Get System cycle count.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval: The value of the system cycle count.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_IntRestore
|
||||
*/
|
||||
extern VOID LOS_GetCpuCycle(UINT32 *puwCntHi, UINT32 *puwCntLo);
|
||||
extern VOID LOS_GetSystickCycle(UINT32 *puwCntHi, UINT32 *puwCntLo);
|
||||
|
||||
extern UINT32 LOS_SysTickCurrCycleGet(VOID);
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* @brief Delete hardware interrupt.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to delete hardware interrupt.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The hardware interrupt module is usable only when the configuration item for hardware interrupt tailoring is enabled.</li>
|
||||
* <li>Hardware interrupt number value range: [OS_USER_HWI_MIN,OS_USER_HWI_MAX]. The value range applicable for a Cortex-A7 platform is [32,95].</li>
|
||||
* <li>OS_HWI_MAX_NUM specifies the maximum number of interrupts that can be created.</li>
|
||||
* <li>Before executing an interrupt on a platform, refer to the chip manual of the platform.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param hwiNum [IN] Type#HWI_HANDLE_T: hardware interrupt number. The value range applicable for a Cortex-A7 platform is [32,95].
|
||||
*
|
||||
* @retval #OS_ERRNO_HWI_NUM_INVALID 0x02000900: Invalid interrupt number.
|
||||
* @retval #LOS_OK 0 : The interrupt is successfully delete.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern UINT32 LOS_HwiDelete(HWI_HANDLE_T hwiNum);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_HWI_H */
|
||||
|
|
@ -0,0 +1,194 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#include "los_base.h"
|
||||
#include "los_task_pri.h"
|
||||
#include "los_hw.h"
|
||||
#include "los_priqueue_pri.h"
|
||||
#include "securec.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : OsSchedule
|
||||
Description : task scheduling
|
||||
Input : None
|
||||
Output : None
|
||||
Return : None
|
||||
**************************************************************************** */
|
||||
VOID OsSchedule(VOID)
|
||||
{
|
||||
osTaskSchedule();
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : LOS_Schedule
|
||||
Description : Function to determine whether task scheduling is required.
|
||||
Input : None
|
||||
Output : None
|
||||
Return : None
|
||||
**************************************************************************** */
|
||||
VOID LOS_Schedule(VOID)
|
||||
{
|
||||
UINTPTR intSave;
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
|
||||
/* Find the highest task */
|
||||
g_losTask.newTask = LOS_DL_LIST_ENTRY(OsPriqueueTop(), LosTaskCB, pendList);
|
||||
|
||||
/* In case that running is not highest then reschedule */
|
||||
if (g_losTask.runTask != g_losTask.newTask) {
|
||||
if (!g_losTaskLock) {
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
osTaskSchedule();
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
LOS_IntRestore(intSave);
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : OsTaskExit
|
||||
Description : Task exit function
|
||||
Input : None
|
||||
Output : None
|
||||
Return : None
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_MINOR VOID OsTaskExit(VOID)
|
||||
{
|
||||
__disable_irq();
|
||||
while (1) {}
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : OsTskStackInit
|
||||
Description : Task stack initialization function
|
||||
Input : taskID --- TaskID
|
||||
stackSize --- Total size of the stack
|
||||
topStack --- Top of task's stack
|
||||
Output : None
|
||||
Return : Context pointer
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT VOID *OsTskStackInit(UINT32 taskID, UINT32 stackSize, VOID *topStack)
|
||||
{
|
||||
TaskContext *context = NULL;
|
||||
errno_t result;
|
||||
|
||||
/* initialize the task stack, write magic num to stack top */
|
||||
result = memset_s(topStack, stackSize, (INT32)(OS_TASK_STACK_INIT & 0xFF), stackSize);
|
||||
if (result != EOK) {
|
||||
printf("memset_s is failed:%s[%d]\r\n", __FUNCTION__, __LINE__);
|
||||
}
|
||||
*((UINT32 *)(topStack)) = OS_TASK_MAGIC_WORD;
|
||||
|
||||
context = (TaskContext *)(((UINTPTR)topStack + stackSize) - sizeof(TaskContext));
|
||||
|
||||
#if ((defined(__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
|
||||
(defined(__FPU_USED) && (__FPU_USED == 1U)))
|
||||
context->S16 = 0xAA000010;
|
||||
context->S17 = 0xAA000011;
|
||||
context->S18 = 0xAA000012;
|
||||
context->S19 = 0xAA000013;
|
||||
context->S20 = 0xAA000014;
|
||||
context->S21 = 0xAA000015;
|
||||
context->S22 = 0xAA000016;
|
||||
context->S23 = 0xAA000017;
|
||||
context->S24 = 0xAA000018;
|
||||
context->S25 = 0xAA000019;
|
||||
context->S26 = 0xAA00001A;
|
||||
context->S27 = 0xAA00001B;
|
||||
context->S28 = 0xAA00001C;
|
||||
context->S29 = 0xAA00001D;
|
||||
context->S30 = 0xAA00001E;
|
||||
context->S31 = 0xAA00001F;
|
||||
context->S0 = 0xAA000000;
|
||||
context->S1 = 0xAA000001;
|
||||
context->S2 = 0xAA000002;
|
||||
context->S3 = 0xAA000003;
|
||||
context->S4 = 0xAA000004;
|
||||
context->S5 = 0xAA000005;
|
||||
context->S6 = 0xAA000006;
|
||||
context->S7 = 0xAA000007;
|
||||
context->S8 = 0xAA000008;
|
||||
context->S9 = 0xAA000009;
|
||||
context->S10 = 0xAA00000A;
|
||||
context->S11 = 0xAA00000B;
|
||||
context->S12 = 0xAA00000C;
|
||||
context->S13 = 0xAA00000D;
|
||||
context->S14 = 0xAA00000E;
|
||||
context->S15 = 0xAA00000F;
|
||||
context->FPSCR = 0x00000000;
|
||||
context->NO_NAME = 0xAA000011;
|
||||
#endif
|
||||
|
||||
context->uwR4 = 0x04040404L;
|
||||
context->uwR5 = 0x05050505L;
|
||||
context->uwR6 = 0x06060606L;
|
||||
context->uwR7 = 0x07070707L;
|
||||
context->uwR8 = 0x08080808L;
|
||||
context->uwR9 = 0x09090909L;
|
||||
context->uwR10 = 0x10101010L;
|
||||
context->uwR11 = 0x11111111L;
|
||||
context->uwPriMask = 0;
|
||||
context->uwR0 = taskID;
|
||||
context->uwR1 = 0x01010101L;
|
||||
context->uwR2 = 0x02020202L;
|
||||
context->uwR3 = 0x03030303L;
|
||||
context->uwR12 = 0x12121212L;
|
||||
context->uwLR = (UINT32)(UINTPTR)OsTaskExit;
|
||||
context->uwPC = (UINT32)(UINTPTR)OsTaskEntry;
|
||||
context->uwxPSR = 0x01000000L;
|
||||
|
||||
return (VOID *)context;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_INIT VOID OsEnterSleep(VOID)
|
||||
{
|
||||
__DSB();
|
||||
__WFI();
|
||||
__ISB();
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
|
|
@ -0,0 +1,210 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#include "los_tick_pri.h"
|
||||
#include "los_base.h"
|
||||
#include "los_task_pri.h"
|
||||
#include "los_swtmr.h"
|
||||
#include "los_hwi.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
|
||||
#define TICK_CHECK 0x4000000
|
||||
#define CYCLE_CHECK 0xFFFFFFFFU
|
||||
#define SHIFT_32_BIT 32
|
||||
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : OsTickStart
|
||||
Description : Configure Tick Interrupt Start
|
||||
Input : none
|
||||
output : none
|
||||
return : LOS_OK - Success , or LOS_ERRNO_TICK_CFG_INVALID - failed
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 OsTickStart(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
|
||||
if ((OS_SYS_CLOCK == 0) ||
|
||||
(LOSCFG_BASE_CORE_TICK_PER_SECOND == 0) ||
|
||||
(LOSCFG_BASE_CORE_TICK_PER_SECOND > OS_SYS_CLOCK)) {
|
||||
return LOS_ERRNO_TICK_CFG_INVALID;
|
||||
}
|
||||
|
||||
#if (OS_HWI_WITH_ARG == YES)
|
||||
OsSetVector(SysTick_IRQn, (HWI_PROC_FUNC)OsTickHandler, NULL);
|
||||
#else
|
||||
OsSetVector(SysTick_IRQn, OsTickHandler);
|
||||
#endif
|
||||
|
||||
g_cyclesPerTick = OS_SYS_CLOCK / LOSCFG_BASE_CORE_TICK_PER_SECOND;
|
||||
g_ullTickCount = 0;
|
||||
|
||||
ret = SysTick_Config(g_cyclesPerTick);
|
||||
if (ret == 1) {
|
||||
return LOS_ERRNO_TICK_PER_SEC_TOO_SMALL;
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
#if (LOSCFG_KERNEL_TICKLESS == YES)
|
||||
/* ****************************************************************************
|
||||
Function : LOS_SysTickReload
|
||||
Description : reconfig systick, and clear SysTick_IRQn
|
||||
Input : cyclesPerTick --- cycles Per Tick
|
||||
output : none
|
||||
return : none
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_MINOR VOID LOS_SysTickReload(UINT32 cyclesPerTick)
|
||||
{
|
||||
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
|
||||
NVIC_ClearPendingIRQ(SysTick_IRQn);
|
||||
SysTick->LOAD = (UINT32)(cyclesPerTick - 1UL); /* set reload register */
|
||||
SysTick->VAL = 0UL; /* Load the SysTick Counter Value */
|
||||
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : LOS_SysTickCurrCycleGet
|
||||
Description : Get System cycle count
|
||||
Input : none
|
||||
output : none
|
||||
return : hwCycle --- the system cycle count
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_SysTickCurrCycleGet(VOID)
|
||||
{
|
||||
UINT32 hwCycle;
|
||||
UINTPTR intSave;
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
hwCycle = SysTick->VAL;
|
||||
|
||||
/* tick has come, but may interrupt environment, not counting the Tick interrupt response, to do +1 */
|
||||
if ((SCB->ICSR & TICK_CHECK) != 0) {
|
||||
hwCycle = SysTick->VAL;
|
||||
hwCycle += g_cyclesPerTick;
|
||||
}
|
||||
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return hwCycle;
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : LOS_GetCpuCycle
|
||||
Description : Get System cycle count
|
||||
Input : none
|
||||
output : cntHi --- CpuTick High 4 byte
|
||||
cntLo --- CpuTick Low 4 byte
|
||||
return : none
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_MINOR VOID LOS_GetCpuCycle(UINT32 *cntHi, UINT32 *cntLo)
|
||||
{
|
||||
UINT64 swTick;
|
||||
UINT64 cycle;
|
||||
UINT32 hwCycle;
|
||||
UINTPTR intSave;
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
|
||||
swTick = g_ullTickCount;
|
||||
hwCycle = SysTick->VAL;
|
||||
|
||||
/* tick has come, but may interrupt environment, not counting the Tick interrupt response, to do +1 */
|
||||
if ((SCB->ICSR & TICK_CHECK) != 0) {
|
||||
hwCycle = SysTick->VAL;
|
||||
swTick++;
|
||||
}
|
||||
|
||||
cycle = (((swTick) * g_cyclesPerTick) + (g_cyclesPerTick - hwCycle));
|
||||
|
||||
*cntHi = cycle >> SHIFT_32_BIT;
|
||||
*cntLo = cycle & CYCLE_CHECK;
|
||||
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : LOS_GetSystickCycle
|
||||
Description : Get Sys tick cycle count
|
||||
Input : none
|
||||
output : cntHi --- SysTick count High 4 byte
|
||||
cntLo --- SysTick count Low 4 byte
|
||||
return : none
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_MINOR VOID LOS_GetSystickCycle(UINT32 *cntHi, UINT32 *cntLo)
|
||||
{
|
||||
UINT64 swTick;
|
||||
UINT64 cycle;
|
||||
UINT32 hwCycle;
|
||||
UINTPTR intSave;
|
||||
UINT32 systickLoad;
|
||||
UINT32 systickCur;
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
|
||||
swTick = g_ullTickCount;
|
||||
|
||||
systickLoad = SysTick->LOAD;
|
||||
systickCur = SysTick->VAL;
|
||||
if (systickLoad < systickCur) {
|
||||
LOS_IntRestore(intSave);
|
||||
return;
|
||||
}
|
||||
hwCycle = systickLoad - systickCur;
|
||||
|
||||
/* tick has come, but may interrupt environment, not counting the Tick interrupt response, to do +1 */
|
||||
if ((SCB->ICSR & TICK_CHECK) != 0) {
|
||||
hwCycle = systickLoad - systickCur;
|
||||
swTick++;
|
||||
}
|
||||
|
||||
cycle = hwCycle + swTick * systickLoad;
|
||||
*cntHi = cycle >> SHIFT_32_BIT;
|
||||
*cntLo = cycle & CYCLE_CHECK;
|
||||
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return;
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
|
@ -0,0 +1,254 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#include "los_hwi.h"
|
||||
#include "los_sr.h"
|
||||
|
||||
#if (LOSCFG_KERNEL_TICKLESS == YES)
|
||||
#include "los_tickless_pri.h"
|
||||
#endif
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*lint -save -e40 -e522 -e533*/
|
||||
__weak VOID SysTickHandler(VOID)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
UINT32 g_vuwIntCount = 0;
|
||||
/*lint -restore*/
|
||||
#ifdef __ICCARM__
|
||||
#pragma location = ".data.vector"
|
||||
#elif defined(__CC_ARM) || defined(__GNUC__)
|
||||
LITE_OS_SEC_VEC
|
||||
#endif
|
||||
|
||||
HWI_PROC_FUNC g_hwiForm[OS_VECTOR_CNT] = {
|
||||
(HWI_PROC_FUNC)0, // [0] Top of Stack
|
||||
(HWI_PROC_FUNC)Reset_Handler, // [1] reset
|
||||
(HWI_PROC_FUNC)OsHwiDefaultHandler, // [2] NMI Handler
|
||||
(HWI_PROC_FUNC)OsHwiDefaultHandler, // [3] Hard Fault Handler
|
||||
(HWI_PROC_FUNC)OsHwiDefaultHandler, // [4] MPU Fault Handler
|
||||
(HWI_PROC_FUNC)OsHwiDefaultHandler, // [5] Bus Fault Handler
|
||||
(HWI_PROC_FUNC)OsHwiDefaultHandler, // [6] Usage Fault Handler
|
||||
(HWI_PROC_FUNC)0, // [7] Reserved
|
||||
(HWI_PROC_FUNC)0, // [8] Reserved
|
||||
(HWI_PROC_FUNC)0, // [9] Reserved
|
||||
(HWI_PROC_FUNC)0, // [10] Reserved
|
||||
(HWI_PROC_FUNC)OsHwiDefaultHandler, // [11] SVCall Handler
|
||||
(HWI_PROC_FUNC)OsHwiDefaultHandler, // [12] Debug Monitor Handler
|
||||
(HWI_PROC_FUNC)0, // [13] Reserved
|
||||
(HWI_PROC_FUNC)osPendSV, // [14] PendSV Handler
|
||||
(HWI_PROC_FUNC)SysTickHandler, // [15] SysTick Handler
|
||||
};
|
||||
#if (OS_HWI_WITH_ARG == YES)
|
||||
HWI_SLAVE_FUNC g_hwiSlaveForm[OS_VECTOR_CNT] = {{ (HWI_PROC_FUNC)0, (HWI_ARG_T)0 }};
|
||||
#else
|
||||
HWI_PROC_FUNC g_hwiSlaveForm[OS_VECTOR_CNT] = {0};
|
||||
#endif
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : OsIntNumGet
|
||||
Description : Get a interrupt number
|
||||
Input : None
|
||||
Output : None
|
||||
Return : Interrupt Indexes number
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_MINOR UINT32 OsIntNumGet(VOID)
|
||||
{
|
||||
return __get_IPSR();
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : OsHwiDefaultHandler
|
||||
Description : default handler of the hardware interrupt
|
||||
Input : None
|
||||
Output : None
|
||||
Return : None
|
||||
**************************************************************************** */
|
||||
/*lint -e529*/
|
||||
LITE_OS_SEC_TEXT_MINOR VOID OsHwiDefaultHandler(VOID)
|
||||
{
|
||||
UINT32 irqNum = OsIntNumGet();
|
||||
PRINT_ERR("%s irqnum:%d\n", __FUNCTION__, irqNum);
|
||||
while (1) {}
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : OsInterrupt
|
||||
Description : Hardware interrupt entry function
|
||||
Input : None
|
||||
Output : None
|
||||
Return : None
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT VOID OsInterrupt(VOID)
|
||||
{
|
||||
UINT32 hwiIndex;
|
||||
UINT32 intSave;
|
||||
|
||||
#if (LOSCFG_KERNEL_RUNSTOP == YES)
|
||||
SCB->SCR &= (UINT32) ~((UINT32)SCB_SCR_SLEEPDEEP_Msk);
|
||||
#endif
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
|
||||
g_vuwIntCount++;
|
||||
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
hwiIndex = OsIntNumGet();
|
||||
#if (LOSCFG_KERNEL_TICKLESS == YES)
|
||||
osUpdateKernelTickCount(hwiIndex);
|
||||
#endif
|
||||
|
||||
#if (OS_HWI_WITH_ARG == YES)
|
||||
if (g_hwiSlaveForm[hwiIndex].pfnHandler != 0) {
|
||||
g_hwiSlaveForm[hwiIndex].pfnHandler((VOID *)g_hwiSlaveForm[hwiIndex].pParm);
|
||||
}
|
||||
#else
|
||||
if (g_hwiSlaveForm[hwiIndex] != 0) {
|
||||
g_hwiSlaveForm[hwiIndex]();
|
||||
}
|
||||
#endif
|
||||
intSave = LOS_IntLock();
|
||||
g_vuwIntCount--;
|
||||
LOS_IntRestore(intSave);
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : OsHwiInit
|
||||
Description : initialization of the hardware interrupt
|
||||
Input : None
|
||||
Output : None
|
||||
Return : None
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT VOID OsHwiInit()
|
||||
{
|
||||
UINT32 index;
|
||||
|
||||
for (index = OS_SYS_VECTOR_CNT; index < OS_VECTOR_CNT; index++) {
|
||||
g_hwiForm[index] = (HWI_PROC_FUNC)OsHwiDefaultHandler;
|
||||
}
|
||||
|
||||
/* Interrupt vector table location */
|
||||
SCB->VTOR = (UINT32)(UINTPTR)g_hwiForm;
|
||||
#if (__CORTEX_M >= 0x03U) /* only for Cortex-M3 and above */
|
||||
NVIC_SetPriorityGrouping(OS_NVIC_AIRCR_PRIGROUP);
|
||||
#endif
|
||||
|
||||
return;
|
||||
}
|
||||
/* ****************************************************************************
|
||||
Function : LOS_HwiCreate
|
||||
Description : create hardware interrupt
|
||||
Input : hwiNum --- hwi num to create
|
||||
hwiPrio --- priority of the hwi
|
||||
mode --- unused
|
||||
handler --- hwi handler
|
||||
arg --- param of the hwi handler
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 LOS_HwiCreate(HWI_HANDLE_T hwiNum,
|
||||
HWI_PRIOR_T hwiPrio,
|
||||
HWI_MODE_T mode,
|
||||
HWI_PROC_FUNC handler,
|
||||
HWI_ARG_T arg)
|
||||
{
|
||||
UINTPTR intSave;
|
||||
|
||||
if (handler == NULL) {
|
||||
return OS_ERRNO_HWI_PROC_FUNC_NULL;
|
||||
}
|
||||
|
||||
if (hwiNum >= OS_HWI_MAX_NUM) {
|
||||
return OS_ERRNO_HWI_NUM_INVALID;
|
||||
}
|
||||
|
||||
if (g_hwiForm[hwiNum + OS_SYS_VECTOR_CNT] != (HWI_PROC_FUNC)OsHwiDefaultHandler) {
|
||||
return OS_ERRNO_HWI_ALREADY_CREATED;
|
||||
}
|
||||
|
||||
if (hwiPrio > OS_HWI_PRIO_LOWEST) {
|
||||
return OS_ERRNO_HWI_PRIO_INVALID;
|
||||
}
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
#if (OS_HWI_WITH_ARG == YES)
|
||||
OsSetVector(hwiNum, handler, arg);
|
||||
#else
|
||||
OsSetVector(hwiNum, handler);
|
||||
#endif
|
||||
NVIC_EnableIRQ((IRQn_Type)hwiNum);
|
||||
NVIC_SetPriority((IRQn_Type)hwiNum, hwiPrio);
|
||||
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : LOS_HwiDelete
|
||||
Description : Delete hardware interrupt
|
||||
Input : hwiNum --- hwi num to delete
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 LOS_HwiDelete(HWI_HANDLE_T hwiNum)
|
||||
{
|
||||
UINT32 intSave;
|
||||
|
||||
if (hwiNum >= OS_HWI_MAX_NUM) {
|
||||
return OS_ERRNO_HWI_NUM_INVALID;
|
||||
}
|
||||
|
||||
NVIC_DisableIRQ((IRQn_Type)hwiNum);
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
|
||||
g_hwiForm[hwiNum + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)OsHwiDefaultHandler;
|
||||
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
|
|
@ -0,0 +1,83 @@
|
|||
# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020, 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.
|
||||
|
||||
import("//build/lite/config/component/lite_component.gni")
|
||||
|
||||
source_set("sec") {
|
||||
|
||||
sources = [
|
||||
"cmsis/cmsis_liteos.c",
|
||||
"../../../third_party/bounds_checking_function/src/fscanf_s.c",
|
||||
"../../../third_party/bounds_checking_function/src/fwscanf_s.c",
|
||||
"../../../third_party/bounds_checking_function/src/gets_s.c",
|
||||
"../../../third_party/bounds_checking_function/src/memcpy_s.c",
|
||||
"../../../third_party/bounds_checking_function/src/memmove_s.c",
|
||||
"../../../third_party/bounds_checking_function/src/memset_s.c",
|
||||
"../../../third_party/bounds_checking_function/src/scanf_s.c",
|
||||
"../../../third_party/bounds_checking_function/src/securecutil.c",
|
||||
"../../../third_party/bounds_checking_function/src/secureinput_a.c",
|
||||
"../../../third_party/bounds_checking_function/src/secureinput_w.c",
|
||||
"../../../third_party/bounds_checking_function/src/secureprintoutput_a.c",
|
||||
"../../../third_party/bounds_checking_function/src/secureprintoutput_w.c",
|
||||
"../../../third_party/bounds_checking_function/src/snprintf_s.c",
|
||||
"../../../third_party/bounds_checking_function/src/sprintf_s.c",
|
||||
"../../../third_party/bounds_checking_function/src/sscanf_s.c",
|
||||
"../../../third_party/bounds_checking_function/src/strcat_s.c",
|
||||
"../../../third_party/bounds_checking_function/src/strcpy_s.c",
|
||||
"../../../third_party/bounds_checking_function/src/strncat_s.c",
|
||||
"../../../third_party/bounds_checking_function/src/strncpy_s.c",
|
||||
"../../../third_party/bounds_checking_function/src/strtok_s.c",
|
||||
"../../../third_party/bounds_checking_function/src/swprintf_s.c",
|
||||
"../../../third_party/bounds_checking_function/src/swscanf_s.c",
|
||||
"../../../third_party/bounds_checking_function/src/vfscanf_s.c",
|
||||
"../../../third_party/bounds_checking_function/src/vfwscanf_s.c",
|
||||
"../../../third_party/bounds_checking_function/src/vscanf_s.c",
|
||||
"../../../third_party/bounds_checking_function/src/vsnprintf_s.c",
|
||||
"../../../third_party/bounds_checking_function/src/vsprintf_s.c",
|
||||
"../../../third_party/bounds_checking_function/src/vsscanf_s.c",
|
||||
"../../../third_party/bounds_checking_function/src/vswprintf_s.c",
|
||||
"../../../third_party/bounds_checking_function/src/vswscanf_s.c",
|
||||
"../../../third_party/bounds_checking_function/src/vwscanf_s.c",
|
||||
"../../../third_party/bounds_checking_function/src/wcscat_s.c",
|
||||
"../../../third_party/bounds_checking_function/src/wcscpy_s.c",
|
||||
"../../../third_party/bounds_checking_function/src/wcsncat_s.c",
|
||||
"../../../third_party/bounds_checking_function/src/wcsncpy_s.c",
|
||||
"../../../third_party/bounds_checking_function/src/wcstok_s.c",
|
||||
"../../../third_party/bounds_checking_function/src/wmemcpy_s.c",
|
||||
"../../../third_party/bounds_checking_function/src/wmemmove_s.c",
|
||||
"../../../third_party/bounds_checking_function/src/wscanf_s.c",
|
||||
]
|
||||
}
|
||||
|
||||
lite_component("components") {
|
||||
features = [
|
||||
":sec"
|
||||
]
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1 @@
|
|||
../../../../../third_party/cmsis/CMSIS/RTOS2/Include/cmsis_os2.h
|
|
@ -0,0 +1,47 @@
|
|||
# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020, 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.
|
||||
|
||||
import("//build/lite/config/component/lite_component.gni")
|
||||
|
||||
static_library("cmsis") {
|
||||
sources = [
|
||||
"cmsis_liteos.c"
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
"//kernel/liteos_m/components/cmsis",
|
||||
"//third_party/bounds_checking_function/include",
|
||||
]
|
||||
|
||||
defines = [
|
||||
"LITEOS_WIFI_IOT_VERSION",
|
||||
]
|
||||
|
||||
cflags = [ "-Wno-error" ]
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#include "los_config.h"
|
||||
|
||||
#if (CMSIS_OS_VER == 1)
|
||||
#include "1.0/cmsis_liteos1.c"
|
||||
#elif (CMSIS_OS_VER == 2)
|
||||
#include "2.0/cmsis_liteos2.c"
|
||||
#endif
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#include "los_config.h"
|
||||
|
||||
#if (CMSIS_OS_VER == 1)
|
||||
#error "cmsis version 1.0 is not supported now!"
|
||||
#elif (CMSIS_OS_VER == 2)
|
||||
#include "2.0/cmsis_os2.h"
|
||||
#endif
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef HOS_CMSIS_ADP_H
|
||||
#define HOS_CMSIS_ADP_H
|
||||
|
||||
#include "cmsis_os.h"
|
||||
#include "hos_types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
typedef struct {
|
||||
osSemaphoreAttr_t attr;
|
||||
uint32 maxCount;
|
||||
uint32 initialCount;
|
||||
} SemaphoreEx;
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif
|
|
@ -0,0 +1,47 @@
|
|||
# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020, 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.
|
||||
|
||||
import("//build/lite/config/component/lite_component.gni")
|
||||
|
||||
static_library("kal") {
|
||||
sources = [
|
||||
"src/kal.c",
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
"//kernel/liteos_m/components/kal/include",
|
||||
"//third_party/bounds_checking_function/include",
|
||||
]
|
||||
|
||||
defines = [
|
||||
"LITEOS_WIFI_IOT_VERSION",
|
||||
]
|
||||
|
||||
cflags = [ "-Werror" ]
|
||||
}
|
|
@ -0,0 +1,182 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup KAL
|
||||
* @{
|
||||
*
|
||||
* @brief Defines the kernel adaptation layer (KAL), which provides compatible interfaces across L0 and L1 systems.
|
||||
*
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
#ifndef KAL_H_
|
||||
#define KAL_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Indicates the maximum length of a thread name.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#define KAL_TASK_NAME_LEN 32
|
||||
|
||||
typedef void (*KalTimerProc)(void *arg);
|
||||
typedef void *KalTimerId;
|
||||
|
||||
typedef enum {
|
||||
KAL_TIMER_ONCE = 0, // /< One-shot timer.
|
||||
KAL_TIMER_PERIODIC = 1 // /< Repeating timer.
|
||||
} KalTimerType;
|
||||
|
||||
typedef enum {
|
||||
KAL_OK = 0,
|
||||
KAL_ERR_PARA = 1,
|
||||
KAL_ERR_INNER = 2,
|
||||
KAL_ERR_TIMER_STATE = 0x100,
|
||||
} KalErrCode;
|
||||
|
||||
/**
|
||||
* @brief Describes a thread.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
typedef struct {
|
||||
/** Thread name */
|
||||
char name[KAL_TASK_NAME_LEN];
|
||||
/** Thread ID */
|
||||
unsigned int id;
|
||||
/** Thread status */
|
||||
unsigned short status;
|
||||
/** Thread priority */
|
||||
unsigned short priority;
|
||||
/** Thread semaphore */
|
||||
void *taskSem;
|
||||
/** Thread mutex */
|
||||
void *taskMutex;
|
||||
/** Thread event */
|
||||
unsigned int eventStru[3];
|
||||
/** Thread event mask */
|
||||
unsigned int eventMask;
|
||||
/** Thread stack size */
|
||||
unsigned int stackSize;
|
||||
/** Thread stack top */
|
||||
unsigned int topOfStack;
|
||||
/** Thread stack bottom */
|
||||
unsigned int bottomOfStack;
|
||||
/** Thread current mstatus */
|
||||
unsigned int mstatus;
|
||||
/** Thread current mepc */
|
||||
unsigned int mepc;
|
||||
/** Thread current tp */
|
||||
unsigned int tp;
|
||||
/** Thread current ra */
|
||||
unsigned int ra;
|
||||
/** Thread stack pointer */
|
||||
unsigned int sp;
|
||||
/** Current stack space usage */
|
||||
unsigned int currUsed;
|
||||
/** Peak stack space usage */
|
||||
unsigned int peakUsed;
|
||||
/** Thread stack overflow flag */
|
||||
unsigned int overflowFlag;
|
||||
} ThreadInfo;
|
||||
|
||||
typedef struct {
|
||||
/**< Total space of the memory pool. */
|
||||
unsigned int total;
|
||||
/**< Used space of the memory pool. */
|
||||
unsigned int used;
|
||||
/**< Free space of the memory pool. */
|
||||
unsigned int free;
|
||||
/**< Number of free nodes in the memory pool. */
|
||||
unsigned int freeNodeNum;
|
||||
/**< Number of used nodes in the memory pool. */
|
||||
unsigned int usedNodeNum;
|
||||
/**< Maximum size of the node in the free space of the memory pool. */
|
||||
unsigned int maxFreeNodeSize;
|
||||
/**< Number of memory application failures. */
|
||||
unsigned int mallocFailCount;
|
||||
/**< Peak memory usage of the memory pool. */
|
||||
unsigned int peekSize;
|
||||
/**< Total space of the little memory pool. */
|
||||
unsigned int totalLmp;
|
||||
/**< Used space of the little memory pool. */
|
||||
unsigned int usedLmp;
|
||||
/**< Free space of the little memory pool. */
|
||||
unsigned int freeLmp;
|
||||
} MemInfo;
|
||||
|
||||
/**
|
||||
* @brief Obtains thread information.
|
||||
*
|
||||
* @param threadId Indicates the thread ID.
|
||||
* @param info Indicates the pointer to the buffer for storing the obtained thread information.
|
||||
* @return Returns <b>0</b> if the thread information is obtained; returns a negative value otherwise.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
unsigned int KalThreadGetInfo(unsigned int threadId, ThreadInfo *info);
|
||||
|
||||
/**
|
||||
* @brief Delays a thread.
|
||||
*
|
||||
* The delay unit is microsecond. The actual delay precision can reach only the tick level.
|
||||
*
|
||||
* @param us Indicates the number of microseconds to delay. The actual delay precision is one tick.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
void KalDelayUs(unsigned int us);
|
||||
KalTimerId KalTimerCreate(KalTimerProc func, KalTimerType type, void *arg, unsigned int ticks);
|
||||
KalErrCode KalTimerStart(KalTimerId timerId);
|
||||
KalErrCode KalTimerChange(KalTimerId timerId, unsigned int ticks);
|
||||
KalErrCode KalTimerStop(KalTimerId timerId);
|
||||
KalErrCode KalTimerDelete(KalTimerId timerId);
|
||||
unsigned int KalTimerIsRunning(KalTimerId timerId);
|
||||
unsigned int KalTickToMs(unsigned int ticks);
|
||||
unsigned int KalMsToTick(unsigned int millisec);
|
||||
KalErrCode KalGetMemInfo(MemInfo *pmemInfo);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // KAL_H_
|
||||
|
||||
/* * @} */
|
|
@ -0,0 +1,220 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#include "securec.h"
|
||||
#include "hi_mem.h"
|
||||
#include "los_task.h"
|
||||
#include "los_swtmr.h"
|
||||
#include "los_swtmr_pri.h"
|
||||
#include "los_hwi.h"
|
||||
#include "kal.h"
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define NULL 0L
|
||||
#else
|
||||
#ifndef NULL
|
||||
#define NULL ((void *)0)
|
||||
#endif
|
||||
#endif
|
||||
#define MS_PER_SECOND 1000
|
||||
|
||||
unsigned int KalThreadGetInfo(unsigned int threadId, ThreadInfo *info)
|
||||
{
|
||||
unsigned int ret;
|
||||
if (info == NULL) {
|
||||
return -1;
|
||||
}
|
||||
(void)memset_s(info, sizeof(ThreadInfo), 0, sizeof(ThreadInfo));
|
||||
TSK_INFO_S *losTaskInfo = (TSK_INFO_S *)malloc(sizeof(TSK_INFO_S));
|
||||
if (losTaskInfo == NULL) {
|
||||
return -1;
|
||||
}
|
||||
(void)memset_s(losTaskInfo, sizeof(TSK_INFO_S), 0, sizeof(TSK_INFO_S));
|
||||
ret = LOS_TaskInfoGet(threadId, losTaskInfo);
|
||||
if (ret == LOS_OK) {
|
||||
info->id = losTaskInfo->uwTaskID;
|
||||
info->status = losTaskInfo->usTaskStatus;
|
||||
info->priority = losTaskInfo->usTaskPrio;
|
||||
info->taskSem = losTaskInfo->pTaskSem;
|
||||
info->taskMutex = losTaskInfo->pTaskMux;
|
||||
info->eventMask = losTaskInfo->uwEventMask;
|
||||
info->stackSize = losTaskInfo->uwStackSize;
|
||||
info->topOfStack = losTaskInfo->uwTopOfStack;
|
||||
info->bottomOfStack = losTaskInfo->uwBottomOfStack;
|
||||
info->mstatus = losTaskInfo->mstatus;
|
||||
info->mepc = losTaskInfo->mepc;
|
||||
info->tp = losTaskInfo->tp;
|
||||
info->ra = losTaskInfo->ra;
|
||||
info->sp = losTaskInfo->uwSP;
|
||||
info->currUsed = losTaskInfo->uwCurrUsed;
|
||||
info->peakUsed = losTaskInfo->uwPeakUsed;
|
||||
info->overflowFlag = losTaskInfo->bOvf;
|
||||
ret = memcpy_s(info->name, sizeof(info->name), losTaskInfo->acName, sizeof(info->name) - 1);
|
||||
}
|
||||
free(losTaskInfo);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void KalDelayUs(unsigned int us)
|
||||
{
|
||||
unsigned int ticks;
|
||||
if (us == 0) {
|
||||
return;
|
||||
}
|
||||
ticks = LOS_MS2Tick(us / MS_PER_SECOND);
|
||||
(void)LOS_TaskDelay(ticks);
|
||||
}
|
||||
|
||||
KalTimerId KalTimerCreate(KalTimerProc func, KalTimerType type, void *arg, unsigned int ticks)
|
||||
{
|
||||
UINT16 swtmrId;
|
||||
UINT8 mode;
|
||||
if ((OS_INT_ACTIVE) || (NULL == func) || ((KAL_TIMER_ONCE != type) && (KAL_TIMER_PERIODIC != type))) {
|
||||
return (KalTimerId)NULL;
|
||||
}
|
||||
if (KAL_TIMER_ONCE == type) {
|
||||
mode = LOS_SWTMR_MODE_NO_SELFDELETE;
|
||||
} else {
|
||||
mode = LOS_SWTMR_MODE_PERIOD;
|
||||
}
|
||||
#if (LOSCFG_BASE_CORE_SWTMR_ALIGN == YES)
|
||||
if (LOS_OK != LOS_SwtmrCreate(ticks, mode, (SWTMR_PROC_FUNC)func, &swtmrId, (UINT32)(UINTPTR)arg,
|
||||
osTimerRousesAllow, osTimerAlignIgnore)) {
|
||||
return (KalTimerId)NULL;
|
||||
}
|
||||
#else
|
||||
if (LOS_OK != LOS_SwtmrCreate(ticks, mode, (SWTMR_PROC_FUNC)func, &swtmrId, (UINT32)(UINTPTR)arg)) {
|
||||
return (KalTimerId)NULL;
|
||||
}
|
||||
#endif
|
||||
return (KalTimerId)OS_SWT_FROM_SID(swtmrId);
|
||||
}
|
||||
KalErrCode KalTransRetCode(unsigned int ret)
|
||||
{
|
||||
if (LOS_OK == ret) {
|
||||
return KAL_OK;
|
||||
} else if (LOS_ERRNO_SWTMR_ID_INVALID == ret) {
|
||||
return KAL_ERR_PARA;
|
||||
} else {
|
||||
return KAL_ERR_INNER;
|
||||
}
|
||||
}
|
||||
KalErrCode KalTimerStart(KalTimerId timerId)
|
||||
{
|
||||
UINT32 ret;
|
||||
SWTMR_CTRL_S *swtmr = NULL;
|
||||
if (NULL == timerId) {
|
||||
return KAL_ERR_PARA;
|
||||
}
|
||||
swtmr = (SWTMR_CTRL_S *)timerId;
|
||||
|
||||
ret = LOS_SwtmrStart(swtmr->usTimerID);
|
||||
return KalTransRetCode(ret);
|
||||
}
|
||||
// support change while not running.
|
||||
KalErrCode KalTimerChange(KalTimerId timerId, unsigned int ticks)
|
||||
{
|
||||
SWTMR_CTRL_S *swtmr = NULL;
|
||||
if ((0 == ticks) || (NULL == timerId)) {
|
||||
return KAL_ERR_PARA;
|
||||
}
|
||||
swtmr = (SWTMR_CTRL_S *)timerId;
|
||||
if (OS_SWTMR_STATUS_TICKING == swtmr->ucState) {
|
||||
return KAL_ERR_TIMER_STATE;
|
||||
}
|
||||
swtmr->uwInterval = ticks;
|
||||
return KAL_OK;
|
||||
}
|
||||
KalErrCode KalTimerStop(KalTimerId timerId)
|
||||
{
|
||||
UINT32 ret;
|
||||
SWTMR_CTRL_S *swtmr = NULL;
|
||||
if (NULL == timerId) {
|
||||
return KAL_ERR_PARA;
|
||||
}
|
||||
swtmr = (SWTMR_CTRL_S *)timerId;
|
||||
ret = LOS_SwtmrStop(swtmr->usTimerID);
|
||||
return KalTransRetCode(ret);
|
||||
}
|
||||
|
||||
KalErrCode KalTimerDelete(KalTimerId timerId)
|
||||
{
|
||||
UINT32 ret;
|
||||
SWTMR_CTRL_S *swtmr = NULL;
|
||||
if (NULL == timerId) {
|
||||
return KAL_ERR_PARA;
|
||||
}
|
||||
swtmr = (SWTMR_CTRL_S *)timerId;
|
||||
ret = LOS_SwtmrDelete(swtmr->usTimerID);
|
||||
return KalTransRetCode(ret);
|
||||
}
|
||||
unsigned int KalTimerIsRunning(KalTimerId timerId)
|
||||
{
|
||||
if ((OS_INT_ACTIVE) || (NULL == timerId)) {
|
||||
return 0;
|
||||
}
|
||||
return (OS_SWTMR_STATUS_TICKING == ((SWTMR_CTRL_S *)timerId)->ucState);
|
||||
}
|
||||
|
||||
unsigned int KalTickToMs(unsigned int ticks)
|
||||
{
|
||||
return LOS_Tick2MS(ticks);
|
||||
}
|
||||
unsigned int KalMsToTick(unsigned int millisec)
|
||||
{
|
||||
return LOS_MS2Tick(millisec);
|
||||
}
|
||||
|
||||
KalErrCode KalGetMemInfo(MemInfo *pmemInfo)
|
||||
{
|
||||
hi_mdm_mem_info hiMemInfo;
|
||||
hi_u32 hiRet;
|
||||
if (NULL == pmemInfo) {
|
||||
return KAL_ERR_PARA;
|
||||
}
|
||||
hiRet = hi_mem_get_sys_info(&hiMemInfo);
|
||||
if (hiRet != 0) {
|
||||
return KAL_ERR_INNER;
|
||||
}
|
||||
pmemInfo->total = hiMemInfo.total;
|
||||
pmemInfo->used = hiMemInfo.used;
|
||||
pmemInfo->free = hiMemInfo.free;
|
||||
pmemInfo->freeNodeNum = hiMemInfo.free_node_num;
|
||||
pmemInfo->usedNodeNum = hiMemInfo.used_node_num;
|
||||
pmemInfo->maxFreeNodeSize = hiMemInfo.max_free_node_size;
|
||||
pmemInfo->mallocFailCount = hiMemInfo.malloc_fail_count;
|
||||
pmemInfo->peekSize = hiMemInfo.peek_size;
|
||||
pmemInfo->totalLmp = hiMemInfo.total_lmp;
|
||||
pmemInfo->usedLmp = hiMemInfo.used_lmp;
|
||||
pmemInfo->freeLmp = hiMemInfo.free_lmp;
|
||||
return KAL_OK;
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020, 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.
|
||||
|
||||
import("//build/lite/config/component/lite_component.gni")
|
||||
|
||||
source_set("init") {
|
||||
|
||||
sources = [
|
||||
"los_init.c",
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
"include",
|
||||
]
|
||||
}
|
||||
|
||||
lite_component("kernel") {
|
||||
features = [
|
||||
":init",
|
||||
"base",
|
||||
"extended:cpup"
|
||||
]
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020, 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.
|
||||
|
||||
static_library("base") {
|
||||
|
||||
sources = [
|
||||
"core/los_priqueue.c",
|
||||
"core/los_swtmr.c",
|
||||
"core/los_sys.c",
|
||||
"core/los_task.c",
|
||||
"core/los_tick.c",
|
||||
"core/los_timeslice.c",
|
||||
"ipc/los_event.c",
|
||||
"ipc/los_mux.c",
|
||||
"ipc/los_queue.c",
|
||||
"ipc/los_sem.c",
|
||||
"mem/bestfit/los_membox.c",
|
||||
"mem/bestfit/los_memcheck.c",
|
||||
"mem/bestfit/los_memory.c",
|
||||
"mem/bestfit/los_memstat.c",
|
||||
"mem/bestfit/los_multipledlinkhead.c",
|
||||
"mem/common/los_slab.c",
|
||||
"mem/common/los_slabmem.c",
|
||||
"misc/los_misc.c",
|
||||
"om/los_err.c",
|
||||
]
|
||||
}
|
|
@ -0,0 +1,113 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#include "los_priqueue_pri.h"
|
||||
#include "los_base_pri.h"
|
||||
#include "los_task_pri.h"
|
||||
#include "los_memory.h"
|
||||
#include "los_compiler.h"
|
||||
|
||||
LITE_OS_SEC_BSS LOS_DL_LIST *g_losPriorityQueueList = NULL;
|
||||
static LITE_OS_SEC_BSS UINT32 g_priqueueBitmap = 0;
|
||||
|
||||
#define PRIQUEUE_PRIOR0_BIT (UINT32)0x80000000
|
||||
|
||||
UINT32 OsPriqueueInit(VOID)
|
||||
{
|
||||
UINT32 priority;
|
||||
UINT32 size = OS_PRIORITY_QUEUE_PRIORITYNUM * sizeof(LOS_DL_LIST);
|
||||
|
||||
g_losPriorityQueueList = (LOS_DL_LIST *)LOS_MemAlloc(m_aucSysMem0, size);
|
||||
if (g_losPriorityQueueList == NULL) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
for (priority = 0; priority < OS_PRIORITY_QUEUE_PRIORITYNUM; ++priority) {
|
||||
LOS_ListInit(&g_losPriorityQueueList[priority]);
|
||||
}
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID OsPriqueueEnqueue(LOS_DL_LIST *priqueueItem, UINT32 priority)
|
||||
{
|
||||
if (LOS_ListEmpty(&g_losPriorityQueueList[priority])) {
|
||||
g_priqueueBitmap |= (PRIQUEUE_PRIOR0_BIT >> priority);
|
||||
}
|
||||
|
||||
LOS_ListTailInsert(&g_losPriorityQueueList[priority], priqueueItem);
|
||||
}
|
||||
|
||||
VOID OsPriqueueDequeue(LOS_DL_LIST *priqueueItem)
|
||||
{
|
||||
LosTaskCB *runningTask = NULL;
|
||||
LOS_ListDelete(priqueueItem);
|
||||
|
||||
runningTask = LOS_DL_LIST_ENTRY(priqueueItem, LosTaskCB, pendList);
|
||||
if (LOS_ListEmpty(&g_losPriorityQueueList[runningTask->priority])) {
|
||||
g_priqueueBitmap &= ~(PRIQUEUE_PRIOR0_BIT >> runningTask->priority);
|
||||
}
|
||||
}
|
||||
|
||||
LOS_DL_LIST *OsPriqueueTop(VOID)
|
||||
{
|
||||
UINT32 priority;
|
||||
|
||||
if (g_priqueueBitmap != 0) {
|
||||
priority = CLZ(g_priqueueBitmap);
|
||||
return LOS_DL_LIST_FIRST(&g_losPriorityQueueList[priority]);
|
||||
}
|
||||
|
||||
return (LOS_DL_LIST *)NULL;
|
||||
}
|
||||
|
||||
UINT32 OsPriqueueSize(UINT32 priority)
|
||||
{
|
||||
UINT32 itemCnt = 0;
|
||||
LOS_DL_LIST *curPQNode = (LOS_DL_LIST *)NULL;
|
||||
|
||||
LOS_DL_LIST_FOR_EACH(curPQNode, &g_losPriorityQueueList[priority]) {
|
||||
++itemCnt;
|
||||
}
|
||||
|
||||
return itemCnt;
|
||||
}
|
||||
|
||||
UINT32 OsPriqueueTotalSize(VOID)
|
||||
{
|
||||
UINT32 priority;
|
||||
UINT32 totalSize = 0;
|
||||
|
||||
for (priority = 0; priority < OS_PRIORITY_QUEUE_PRIORITYNUM; ++priority) {
|
||||
totalSize += OsPriqueueSize(priority);
|
||||
}
|
||||
|
||||
return totalSize;
|
||||
}
|
|
@ -0,0 +1,860 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#include "string.h"
|
||||
#include "securec.h"
|
||||
#include "los_swtmr_pri.h"
|
||||
#include "los_base_pri.h"
|
||||
#include "los_sys.h"
|
||||
#include "los_membox_pri.h"
|
||||
#include "los_memory_pri.h"
|
||||
#include "los_queue_pri.h"
|
||||
#include "los_task_pri.h"
|
||||
#include "los_hwi.h"
|
||||
#if (LOSCFG_PLATFORM_EXC == YES)
|
||||
#include "los_exc.h"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#if (LOSCFG_BASE_CORE_SWTMR == YES)
|
||||
|
||||
LITE_OS_SEC_BSS UINT32 g_swtmrHandlerQueue; /* Software Timer timeout queue ID */
|
||||
LITE_OS_SEC_BSS SWTMR_CTRL_S *g_swtmrCBArray = NULL; /* first address in Timer memory space */
|
||||
LITE_OS_SEC_BSS SWTMR_CTRL_S *g_swtmrFreeList = NULL; /* Free list of Softwaer Timer */
|
||||
LITE_OS_SEC_BSS SWTMR_CTRL_S *g_swtmrSortList = NULL; /* The software timer count list */
|
||||
|
||||
#if (LOSCFG_BASE_CORE_SWTMR_ALIGN == YES)
|
||||
typedef struct SwtmrAlignDataStr {
|
||||
UINT32 times : 24;
|
||||
UINT32 : 5;
|
||||
UINT32 canMultiple : 1;
|
||||
UINT32 canAlign : 1;
|
||||
UINT32 isAligned : 1;
|
||||
} SwtmrAlignData;
|
||||
LITE_OS_SEC_BSS SwtmrAlignData g_swtmrAlignID[LOSCFG_BASE_CORE_SWTMR_LIMIT] = {0}; /* store swtmr align */
|
||||
static UINT32 g_swtimerRousesTime = 0; /* suspend time */
|
||||
static SWTMR_CTRL_S *g_swtmrRouses = NULL; /* first swtmr that can wake up */
|
||||
static SWTMR_CTRL_S *g_swtmrRousesPrev = NULL;
|
||||
#endif
|
||||
|
||||
#define SWTMR_MAX_RUNNING_TICKS 2
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
Function : OsSwtmrTask
|
||||
Description : Swtmr task main loop, handle time-out timer.
|
||||
Input : None
|
||||
Output : None
|
||||
Return : None
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT VOID OsSwtmrTask(VOID)
|
||||
{
|
||||
SwtmrHandlerItem swtmrHandle;
|
||||
UINT32 readSzie;
|
||||
UINT32 ret;
|
||||
UINT64 tick;
|
||||
readSzie = sizeof(SwtmrHandlerItem);
|
||||
for (;;) {
|
||||
ret = LOS_QueueReadCopy(g_swtmrHandlerQueue, &swtmrHandle, &readSzie, LOS_WAIT_FOREVER);
|
||||
if ((ret == LOS_OK) && (readSzie == sizeof(SwtmrHandlerItem))) {
|
||||
if (swtmrHandle.handler == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
tick = LOS_TickCountGet();
|
||||
swtmrHandle.handler(swtmrHandle.arg);
|
||||
tick = LOS_TickCountGet() - tick;
|
||||
|
||||
if (tick >= SWTMR_MAX_RUNNING_TICKS) {
|
||||
PRINT_WARN("timer_handler(%p) cost too many ms(%d)\n",
|
||||
swtmrHandle.handler,
|
||||
(UINT32)((tick * OS_SYS_MS_PER_SECOND) / LOSCFG_BASE_CORE_TICK_PER_SECOND));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : OsSwtmrTaskCreate
|
||||
Description : Create Software Timer
|
||||
Input : None
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 OsSwtmrTaskCreate(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
TSK_INIT_PARAM_S swtmrTask;
|
||||
|
||||
// Ignore the return code when matching CSEC rule 6.6(4).
|
||||
(VOID)memset_s(&swtmrTask, sizeof(TSK_INIT_PARAM_S), 0, sizeof(TSK_INIT_PARAM_S));
|
||||
|
||||
swtmrTask.pfnTaskEntry = (TSK_ENTRY_FUNC)OsSwtmrTask;
|
||||
swtmrTask.uwStackSize = LOSCFG_BASE_CORE_TSK_SWTMR_STACK_SIZE;
|
||||
swtmrTask.pcName = "Swt_Task";
|
||||
swtmrTask.usTaskPrio = 0;
|
||||
ret = LOS_TaskCreate(&g_swtmrTaskID, &swtmrTask);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : OsSwtmrInit
|
||||
Description : Initializes Software Timer
|
||||
Input : None
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 OsSwtmrInit(VOID)
|
||||
{
|
||||
UINT32 size;
|
||||
UINT16 index;
|
||||
UINT32 ret;
|
||||
SWTMR_CTRL_S *swtmr = NULL;
|
||||
SWTMR_CTRL_S *temp = NULL;
|
||||
|
||||
#if (LOSCFG_BASE_CORE_SWTMR_ALIGN == YES)
|
||||
// Ignore the return code when matching CSEC rule 6.6(1).
|
||||
(VOID)memset_s((VOID *)g_swtmrAlignID, sizeof(SwtmrAlignData) * LOSCFG_BASE_CORE_SWTMR_LIMIT,
|
||||
0, sizeof(SwtmrAlignData) * LOSCFG_BASE_CORE_SWTMR_LIMIT);
|
||||
#endif
|
||||
|
||||
g_swtmrSortList = (SWTMR_CTRL_S *)NULL;
|
||||
size = sizeof(SWTMR_CTRL_S) * LOSCFG_BASE_CORE_SWTMR_LIMIT;
|
||||
swtmr = (SWTMR_CTRL_S *)LOS_MemAlloc(m_aucSysMem0, size);
|
||||
if (swtmr == NULL) {
|
||||
return LOS_ERRNO_SWTMR_NO_MEMORY;
|
||||
}
|
||||
// Ignore the return code when matching CSEC rule 6.6(3).
|
||||
(VOID)memset_s((VOID *)swtmr, size, 0, size);
|
||||
g_swtmrCBArray = swtmr;
|
||||
g_swtmrFreeList = swtmr;
|
||||
swtmr->usTimerID = 0;
|
||||
temp = swtmr;
|
||||
swtmr++;
|
||||
for (index = 1; index < LOSCFG_BASE_CORE_SWTMR_LIMIT; index++, swtmr++) {
|
||||
swtmr->usTimerID = index;
|
||||
temp->pstNext = swtmr;
|
||||
temp = swtmr;
|
||||
}
|
||||
|
||||
ret = LOS_QueueCreate((CHAR *)NULL, OS_SWTMR_HANDLE_QUEUE_SIZE,
|
||||
&g_swtmrHandlerQueue, 0, sizeof(SwtmrHandlerItem));
|
||||
if (ret != LOS_OK) {
|
||||
(VOID)LOS_MemFree(m_aucSysMem0, swtmr);
|
||||
return LOS_ERRNO_SWTMR_QUEUE_CREATE_FAILED;
|
||||
}
|
||||
|
||||
ret = OsSwtmrTaskCreate();
|
||||
if (ret != LOS_OK) {
|
||||
(VOID)LOS_MemFree(m_aucSysMem0, swtmr);
|
||||
return LOS_ERRNO_SWTMR_TASK_CREATE_FAILED;
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
#if (LOSCFG_BASE_CORE_SWTMR_ALIGN == YES)
|
||||
STATIC_INLINE UINT32 OsSwtmrCalcAlignCount(UINT32 interval, UINT16 timerId)
|
||||
{
|
||||
SWTMR_CTRL_S *cur = g_swtmrSortList;
|
||||
UINT32 count = 0;
|
||||
if (interval == 0) {
|
||||
return interval;
|
||||
}
|
||||
while (cur != NULL) {
|
||||
count += cur->uwCount;
|
||||
if (cur->usTimerID == timerId) {
|
||||
return (interval - (cur->uwInterval - count) % interval);
|
||||
}
|
||||
cur = cur->pstNext;
|
||||
}
|
||||
return interval;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT SWTMR_CTRL_S* OsSwtmrFindAlignPos(SWTMR_CTRL_S *swtmr)
|
||||
{
|
||||
SWTMR_CTRL_S *intPos = (SWTMR_CTRL_S *)NULL;
|
||||
SWTMR_CTRL_S *cur = (SWTMR_CTRL_S *)NULL;
|
||||
SWTMR_CTRL_S *minInLarge = (SWTMR_CTRL_S *)NULL;
|
||||
SWTMR_CTRL_S *maxInLitte = (SWTMR_CTRL_S *)NULL;
|
||||
UINT32 currSwtmrTimes, swtmrTimes;
|
||||
SwtmrAlignData swtmrAlgInfo, currSwtmrAlgInfo;
|
||||
UINT32 minInLargeVal = OS_NULL_INT;
|
||||
UINT32 maxInLitteval = OS_NULL_INT;
|
||||
|
||||
currSwtmrAlgInfo = g_swtmrAlignID[swtmr->usTimerID % LOSCFG_BASE_CORE_SWTMR_LIMIT];
|
||||
currSwtmrTimes = currSwtmrAlgInfo.times;
|
||||
cur = g_swtmrSortList;
|
||||
while (cur != NULL) {
|
||||
swtmrAlgInfo = g_swtmrAlignID[cur->usTimerID % LOSCFG_BASE_CORE_SWTMR_LIMIT];
|
||||
if ((swtmrAlgInfo.isAligned == 0) || (swtmrAlgInfo.canAlign == 0)) { // swtmr not start
|
||||
goto CONTINUE_NEXT_NODE;
|
||||
}
|
||||
// find same interval timer, directly return
|
||||
if (cur->uwInterval == swtmr->uwInterval) {
|
||||
swtmr->uwCount = 0;
|
||||
return cur;
|
||||
}
|
||||
|
||||
if ((currSwtmrAlgInfo.canMultiple != 1) || (swtmrAlgInfo.times == 0)) {
|
||||
goto CONTINUE_NEXT_NODE;
|
||||
}
|
||||
swtmrTimes = swtmrAlgInfo.times;
|
||||
if (currSwtmrTimes == 0) {
|
||||
return NULL;
|
||||
}
|
||||
if ((swtmrTimes >= currSwtmrTimes) && ((swtmrTimes % currSwtmrTimes) == 0)) {
|
||||
if (minInLargeVal > (swtmrTimes / currSwtmrTimes)) {
|
||||
minInLargeVal = swtmrTimes / currSwtmrTimes;
|
||||
minInLarge = cur;
|
||||
}
|
||||
} else if ((swtmrTimes < currSwtmrTimes) && ((currSwtmrTimes % swtmrTimes) == 0)) {
|
||||
if (maxInLitteval > (currSwtmrTimes / swtmrTimes)) {
|
||||
maxInLitteval = currSwtmrTimes / swtmrTimes;
|
||||
maxInLitte = cur;
|
||||
}
|
||||
}
|
||||
CONTINUE_NEXT_NODE:
|
||||
|
||||
cur = cur->pstNext;
|
||||
}
|
||||
if (minInLarge != NULL) {
|
||||
swtmr->uwCount = OsSwtmrCalcAlignCount(swtmr->uwInterval, minInLarge->usTimerID);
|
||||
} else if (maxInLitte != NULL) {
|
||||
swtmr->uwCount = 0;
|
||||
intPos = maxInLitte;
|
||||
}
|
||||
return intPos;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*****************************************************************************
|
||||
Function : OsSwtmrStart
|
||||
Description : Start Software Timer
|
||||
Input : swtmr ---------- Need to start Software Timer
|
||||
Output : None
|
||||
Return : None
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT VOID OsSwtmrStart(SWTMR_CTRL_S *swtmr)
|
||||
{
|
||||
SWTMR_CTRL_S *prev = (SWTMR_CTRL_S *)NULL;
|
||||
SWTMR_CTRL_S *cur = (SWTMR_CTRL_S *)NULL;
|
||||
|
||||
swtmr->uwCount = swtmr->uwInterval;
|
||||
|
||||
#if (LOSCFG_BASE_CORE_SWTMR_ALIGN == YES)
|
||||
if ((g_swtmrAlignID[swtmr->usTimerID % LOSCFG_BASE_CORE_SWTMR_LIMIT].canAlign == 1) &&
|
||||
(g_swtmrAlignID[swtmr->usTimerID % LOSCFG_BASE_CORE_SWTMR_LIMIT].isAligned == 0)) {
|
||||
g_swtmrAlignID[swtmr->usTimerID % LOSCFG_BASE_CORE_SWTMR_LIMIT].isAligned = 1;
|
||||
prev = OsSwtmrFindAlignPos(swtmr);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (prev == NULL) {
|
||||
cur = g_swtmrSortList;
|
||||
while (cur != NULL) {
|
||||
if (cur->uwCount > swtmr->uwCount) {
|
||||
break;
|
||||
}
|
||||
|
||||
swtmr->uwCount -= cur->uwCount;
|
||||
prev = cur;
|
||||
cur = cur->pstNext;
|
||||
}
|
||||
}
|
||||
|
||||
swtmr->pstNext = ((prev == NULL) ? g_swtmrSortList : prev->pstNext);
|
||||
if (swtmr->pstNext != NULL) {
|
||||
swtmr->pstNext->uwCount -= swtmr->uwCount;
|
||||
}
|
||||
(prev == NULL) ? (g_swtmrSortList = swtmr) : (prev->pstNext = swtmr);
|
||||
swtmr->ucState = OS_SWTMR_STATUS_TICKING;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : OsSwtmrDelete
|
||||
Description : Delete Software Timer
|
||||
Input : swtmr --- Need to delete Software Timer, When using, Ensure that it can't be NULL.
|
||||
Output : None
|
||||
Return : None
|
||||
*****************************************************************************/
|
||||
STATIC_INLINE VOID OsSwtmrDelete(SWTMR_CTRL_S *swtmr)
|
||||
{
|
||||
/* insert to free list */
|
||||
swtmr->pstNext = g_swtmrFreeList;
|
||||
g_swtmrFreeList = swtmr;
|
||||
swtmr->ucState = OS_SWTMR_STATUS_UNUSED;
|
||||
|
||||
#if (LOSCFG_BASE_CORE_SWTMR_ALIGN == YES)
|
||||
(VOID)memset_s((VOID *)&g_swtmrAlignID[swtmr->usTimerID % LOSCFG_BASE_CORE_SWTMR_LIMIT],
|
||||
sizeof(SwtmrAlignData), 0, sizeof(SwtmrAlignData));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
LITE_OS_SEC_TEXT VOID OsSwtmrStop(const SWTMR_CTRL_S *swtmr)
|
||||
{
|
||||
SWTMR_CTRL_S *prev = (SWTMR_CTRL_S *)NULL;
|
||||
SWTMR_CTRL_S *cur = (SWTMR_CTRL_S *)NULL;
|
||||
|
||||
if (!g_swtmrSortList) {
|
||||
return;
|
||||
}
|
||||
|
||||
cur = g_swtmrSortList;
|
||||
|
||||
while (cur != swtmr) {
|
||||
prev = cur;
|
||||
cur = cur->pstNext;
|
||||
}
|
||||
|
||||
if (cur->pstNext != NULL) {
|
||||
cur->pstNext->uwCount += cur->uwCount;
|
||||
}
|
||||
|
||||
if (prev == NULL) {
|
||||
g_swtmrSortList = cur->pstNext;
|
||||
} else {
|
||||
prev->pstNext = cur->pstNext;
|
||||
}
|
||||
|
||||
cur->pstNext = (SWTMR_CTRL_S *)NULL;
|
||||
cur->ucState = OS_SWTMR_STATUS_CREATED;
|
||||
|
||||
#if (LOSCFG_BASE_CORE_SWTMR_ALIGN == YES)
|
||||
g_swtmrAlignID[swtmr->usTimerID % LOSCFG_BASE_CORE_SWTMR_LIMIT].isAligned = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : OsSwtmrTimeoutHandle
|
||||
Description : Software Timer time out handler
|
||||
Input : None
|
||||
Output : None
|
||||
Return : None
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT static VOID OsSwtmrTimeoutHandle(VOID)
|
||||
{
|
||||
SWTMR_CTRL_S *swtmr = g_swtmrSortList;
|
||||
SwtmrHandlerItem swtmrHandler;
|
||||
|
||||
while ((swtmr != NULL) && (swtmr->uwCount == 0)) {
|
||||
g_swtmrSortList = swtmr->pstNext;
|
||||
swtmrHandler.handler = swtmr->pfnHandler;
|
||||
swtmrHandler.arg = swtmr->uwArg;
|
||||
(VOID)LOS_QueueWriteCopy(g_swtmrHandlerQueue, &swtmrHandler, sizeof(SwtmrHandlerItem), LOS_NO_WAIT);
|
||||
if (swtmr->ucMode == LOS_SWTMR_MODE_ONCE) {
|
||||
OsSwtmrDelete(swtmr);
|
||||
if (swtmr->usTimerID < (OS_SWTMR_MAX_TIMERID - LOSCFG_BASE_CORE_SWTMR_LIMIT)) {
|
||||
swtmr->usTimerID += LOSCFG_BASE_CORE_SWTMR_LIMIT;
|
||||
} else {
|
||||
swtmr->usTimerID %= LOSCFG_BASE_CORE_SWTMR_LIMIT;
|
||||
}
|
||||
} else if (swtmr->ucMode == LOS_SWTMR_MODE_PERIOD) {
|
||||
OsSwtmrStart(swtmr);
|
||||
} else if (swtmr->ucMode == LOS_SWTMR_MODE_NO_SELFDELETE) {
|
||||
swtmr->ucState = OS_SWTMR_STATUS_CREATED;
|
||||
}
|
||||
|
||||
swtmr = g_swtmrSortList;
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : OsSwtmrScan
|
||||
Description : Tick interrupt interface module of Software Timer
|
||||
Input : None
|
||||
Output : None
|
||||
Return : LOS_OK on success
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT UINT32 OsSwtmrScan(VOID)
|
||||
{
|
||||
if (g_swtmrSortList != NULL) {
|
||||
if (--(g_swtmrSortList->uwCount) == 0) {
|
||||
OsSwtmrTimeoutHandle();
|
||||
}
|
||||
}
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : OsSwtmrGetNextTimeout
|
||||
Description : Get next timeout
|
||||
Input : None
|
||||
Output : None
|
||||
Return : Count of the Timer list
|
||||
*****************************************************************************/
|
||||
#if (LOSCFG_BASE_CORE_SWTMR_ALIGN == YES)
|
||||
LITE_OS_SEC_TEXT UINT32 OsSwtmrGetNextTimeout(VOID)
|
||||
{
|
||||
SWTMR_CTRL_S *cur = NULL;
|
||||
UINT32 tmpTime = 0;
|
||||
UINT32 sleepTime = OS_NULL_INT;
|
||||
|
||||
cur = g_swtmrSortList;
|
||||
|
||||
// find first timer can wakeup the system
|
||||
while (cur != NULL) {
|
||||
if (cur->ucRouses == OS_SWTMR_ROUSES_ALLOW) {
|
||||
g_swtmrRouses = cur;
|
||||
break;
|
||||
}
|
||||
|
||||
tmpTime += cur->uwCount;
|
||||
g_swtmrRousesPrev = cur;
|
||||
cur = cur->pstNext;
|
||||
}
|
||||
|
||||
if (cur != NULL) {
|
||||
sleepTime = cur->uwCount + tmpTime;
|
||||
g_swtimerRousesTime = sleepTime;
|
||||
}
|
||||
|
||||
return sleepTime;
|
||||
}
|
||||
#else
|
||||
LITE_OS_SEC_TEXT UINT32 OsSwtmrGetNextTimeout(VOID)
|
||||
{
|
||||
if (g_swtmrSortList == NULL) {
|
||||
return OS_NULL_INT;
|
||||
}
|
||||
return g_swtmrSortList->uwCount;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*****************************************************************************
|
||||
Function : OsSwtimerInsert
|
||||
Description : Insert a list of swtmr
|
||||
Input : **head, *swtmr
|
||||
Output : **head, *swtmr
|
||||
Return : None
|
||||
*****************************************************************************/
|
||||
#if (LOSCFG_BASE_CORE_SWTMR_ALIGN == YES)
|
||||
VOID OsSwtimerInsert(SWTMR_CTRL_S **head, SWTMR_CTRL_S *swtmr)
|
||||
{
|
||||
SWTMR_CTRL_S *prev = NULL;
|
||||
SWTMR_CTRL_S *nextTmp = swtmr->pstNext;
|
||||
SWTMR_CTRL_S *cur = *head;
|
||||
|
||||
while (swtmr != NULL) {
|
||||
while (cur != NULL) {
|
||||
if (cur->uwCount > swtmr->uwCount) {
|
||||
break;
|
||||
}
|
||||
|
||||
swtmr->uwCount -= cur->uwCount;
|
||||
prev = cur;
|
||||
cur = cur->pstNext;
|
||||
}
|
||||
swtmr->pstNext = cur;
|
||||
|
||||
if (cur != NULL) {
|
||||
cur->uwCount -= swtmr->uwCount;
|
||||
}
|
||||
if (prev == NULL) {
|
||||
*head = swtmr;
|
||||
} else {
|
||||
prev->pstNext = swtmr;
|
||||
}
|
||||
|
||||
prev = swtmr;
|
||||
swtmr = nextTmp;
|
||||
nextTmp = nextTmp->pstNext;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
/*****************************************************************************
|
||||
Function : OsSwtmrAdjust
|
||||
Description : Adjust Software Timer list
|
||||
Input : sleepTime
|
||||
Output : None
|
||||
Return : None
|
||||
*****************************************************************************/
|
||||
#if (LOSCFG_BASE_CORE_SWTMR_ALIGN == YES)
|
||||
LITE_OS_SEC_TEXT VOID OsSwtmrAdjust(UINT32 sleepTime)
|
||||
{
|
||||
SWTMR_CTRL_S *cur = NULL;
|
||||
|
||||
if (g_swtmrRouses == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (sleepTime > g_swtimerRousesTime) {
|
||||
sleepTime = g_swtimerRousesTime;
|
||||
}
|
||||
|
||||
if (sleepTime <= g_swtmrRouses->uwCount) {
|
||||
g_swtmrRouses->uwCount -= sleepTime;
|
||||
} else {
|
||||
g_swtmrRouses->uwCount = g_swtimerRousesTime - sleepTime;
|
||||
|
||||
if (g_swtmrRousesPrev != NULL) {
|
||||
g_swtmrRousesPrev->pstNext = NULL;
|
||||
cur = g_swtmrSortList;
|
||||
OsSwtimerInsert(&g_swtmrRouses, cur);
|
||||
g_swtmrSortList = g_swtmrRouses;
|
||||
}
|
||||
}
|
||||
if (g_swtmrSortList->uwCount == 0) {
|
||||
OsSwtmrTimeoutHandle();
|
||||
}
|
||||
|
||||
g_swtmrRouses = NULL;
|
||||
g_swtmrRousesPrev = NULL;
|
||||
}
|
||||
#else
|
||||
LITE_OS_SEC_TEXT VOID OsSwtmrAdjust(UINT32 sleepTime)
|
||||
{
|
||||
UINT32 tmpSleepTime = sleepTime;
|
||||
|
||||
if (g_swtmrSortList == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (tmpSleepTime > g_swtmrSortList->uwCount) {
|
||||
tmpSleepTime = g_swtmrSortList->uwCount;
|
||||
}
|
||||
|
||||
g_swtmrSortList->uwCount -= tmpSleepTime;
|
||||
|
||||
if (g_swtmrSortList->uwCount == 0) {
|
||||
OsSwtmrTimeoutHandle();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
LITE_OS_SEC_TEXT UINT32 OsSwtmrTimeGet(const SWTMR_CTRL_S *swtmr)
|
||||
{
|
||||
SWTMR_CTRL_S *cur = (SWTMR_CTRL_S *)NULL;
|
||||
UINT32 tick = 0;
|
||||
|
||||
cur = g_swtmrSortList;
|
||||
while (1) {
|
||||
if (cur == NULL) {
|
||||
break;
|
||||
}
|
||||
tick += cur->uwCount;
|
||||
if (cur == swtmr) {
|
||||
break;
|
||||
}
|
||||
|
||||
cur = cur->pstNext;
|
||||
}
|
||||
|
||||
return tick;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : LOS_SwtmrCreate
|
||||
Description : Create software timer
|
||||
Input : interval
|
||||
mode
|
||||
handler
|
||||
arg
|
||||
Output : swtmrId
|
||||
Return : LOS_OK on success or error code on failure
|
||||
*****************************************************************************/
|
||||
#if (LOSCFG_BASE_CORE_SWTMR_ALIGN == YES)
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 LOS_SwtmrCreate(UINT32 interval,
|
||||
UINT8 mode,
|
||||
SWTMR_PROC_FUNC handler,
|
||||
UINT16 *swtmrId,
|
||||
UINT32 arg,
|
||||
UINT8 rouses,
|
||||
UINT8 sensitive)
|
||||
#else
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 LOS_SwtmrCreate(UINT32 interval,
|
||||
UINT8 mode,
|
||||
SWTMR_PROC_FUNC handler,
|
||||
UINT16 *swtmrId,
|
||||
UINT32 arg)
|
||||
#endif
|
||||
{
|
||||
SWTMR_CTRL_S *swtmr = NULL;
|
||||
UINTPTR intSave;
|
||||
|
||||
if (interval == 0) {
|
||||
return LOS_ERRNO_SWTMR_INTERVAL_NOT_SUITED;
|
||||
}
|
||||
|
||||
if ((mode != LOS_SWTMR_MODE_ONCE) &&
|
||||
(mode != LOS_SWTMR_MODE_PERIOD) &&
|
||||
(mode != LOS_SWTMR_MODE_NO_SELFDELETE)) {
|
||||
return LOS_ERRNO_SWTMR_MODE_INVALID;
|
||||
}
|
||||
|
||||
if (handler == NULL) {
|
||||
return LOS_ERRNO_SWTMR_PTR_NULL;
|
||||
}
|
||||
|
||||
if (swtmrId == NULL) {
|
||||
return LOS_ERRNO_SWTMR_RET_PTR_NULL;
|
||||
}
|
||||
|
||||
#if (LOSCFG_BASE_CORE_SWTMR_ALIGN == YES)
|
||||
if ((rouses != OS_SWTMR_ROUSES_IGNORE) && (rouses != OS_SWTMR_ROUSES_ALLOW)) {
|
||||
return OS_ERRNO_SWTMR_ROUSES_INVALID;
|
||||
}
|
||||
|
||||
if ((sensitive != OS_SWTMR_ALIGN_INSENSITIVE) && (sensitive != OS_SWTMR_ALIGN_SENSITIVE)) {
|
||||
return OS_ERRNO_SWTMR_ALIGN_INVALID;
|
||||
}
|
||||
#endif
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
if (g_swtmrFreeList == NULL) {
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_ERRNO_SWTMR_MAXSIZE;
|
||||
}
|
||||
|
||||
swtmr = g_swtmrFreeList;
|
||||
g_swtmrFreeList = swtmr->pstNext;
|
||||
LOS_IntRestore(intSave);
|
||||
swtmr->pfnHandler = handler;
|
||||
swtmr->ucMode = mode;
|
||||
swtmr->uwInterval = interval;
|
||||
swtmr->pstNext = (SWTMR_CTRL_S *)NULL;
|
||||
swtmr->uwCount = 0;
|
||||
swtmr->uwArg = arg;
|
||||
#if (LOSCFG_BASE_CORE_SWTMR_ALIGN == YES)
|
||||
swtmr->ucRouses = rouses;
|
||||
swtmr->ucSensitive = sensitive;
|
||||
#endif
|
||||
swtmr->ucState = OS_SWTMR_STATUS_CREATED;
|
||||
*swtmrId = swtmr->usTimerID;
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : LOS_SwtmrStart
|
||||
Description : Start software timer
|
||||
Input : swtmrId ------- Software timer ID
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT UINT32 LOS_SwtmrStart(UINT16 swtmrId)
|
||||
{
|
||||
SWTMR_CTRL_S *swtmr = NULL;
|
||||
UINTPTR intSave;
|
||||
#if (LOSCFG_BASE_CORE_SWTMR_ALIGN == YES)
|
||||
UINT32 times;
|
||||
UINT32 swtmrAlignIdIndex = 0;
|
||||
#endif
|
||||
UINT32 ret = LOS_OK;
|
||||
UINT16 swtmrCbId;
|
||||
|
||||
if (swtmrId >= OS_SWTMR_MAX_TIMERID) {
|
||||
return LOS_ERRNO_SWTMR_ID_INVALID;
|
||||
}
|
||||
intSave = LOS_IntLock();
|
||||
swtmrCbId = swtmrId % LOSCFG_BASE_CORE_SWTMR_LIMIT;
|
||||
swtmr = g_swtmrCBArray + swtmrCbId;
|
||||
if (swtmr->usTimerID != swtmrId) {
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_ERRNO_SWTMR_ID_INVALID;
|
||||
}
|
||||
|
||||
#if (LOSCFG_BASE_CORE_SWTMR_ALIGN == YES)
|
||||
if ((swtmr->ucSensitive == OS_SWTMR_ALIGN_INSENSITIVE) && (swtmr->ucMode == LOS_SWTMR_MODE_PERIOD)) {
|
||||
swtmrAlignIdIndex = swtmr->usTimerID % LOSCFG_BASE_CORE_SWTMR_LIMIT;
|
||||
g_swtmrAlignID[swtmrAlignIdIndex].canAlign = 1;
|
||||
if ((swtmr->uwInterval % LOS_COMMON_DIVISOR) == 0) {
|
||||
g_swtmrAlignID[swtmrAlignIdIndex].canMultiple = 1;
|
||||
times = swtmr->uwInterval / (LOS_COMMON_DIVISOR);
|
||||
g_swtmrAlignID[swtmrAlignIdIndex].times = times;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
switch (swtmr->ucState) {
|
||||
case OS_SWTMR_STATUS_UNUSED:
|
||||
ret = LOS_ERRNO_SWTMR_NOT_CREATED;
|
||||
break;
|
||||
case OS_SWTMR_STATUS_TICKING:
|
||||
OsSwtmrStop(swtmr);
|
||||
/* fall through */
|
||||
case OS_SWTMR_STATUS_CREATED:
|
||||
OsSwtmrStart(swtmr);
|
||||
break;
|
||||
default:
|
||||
ret = LOS_ERRNO_SWTMR_STATUS_INVALID;
|
||||
break;
|
||||
}
|
||||
|
||||
LOS_IntRestore(intSave);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : LOS_SwtmrStop
|
||||
Description : Stop software timer
|
||||
Input : swtmrId ------- Software timer ID
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT UINT32 LOS_SwtmrStop(UINT16 swtmrId)
|
||||
{
|
||||
SWTMR_CTRL_S *swtmr = NULL;
|
||||
UINTPTR intSave;
|
||||
UINT16 swtmrCbId;
|
||||
UINT32 ret = LOS_OK;
|
||||
|
||||
if (swtmrId >= OS_SWTMR_MAX_TIMERID) {
|
||||
return LOS_ERRNO_SWTMR_ID_INVALID;
|
||||
}
|
||||
intSave = LOS_IntLock();
|
||||
swtmrCbId = swtmrId % LOSCFG_BASE_CORE_SWTMR_LIMIT;
|
||||
swtmr = g_swtmrCBArray + swtmrCbId;
|
||||
if (swtmr->usTimerID != swtmrId) {
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_ERRNO_SWTMR_ID_INVALID;
|
||||
}
|
||||
|
||||
switch (swtmr->ucState) {
|
||||
case OS_SWTMR_STATUS_UNUSED:
|
||||
ret = LOS_ERRNO_SWTMR_NOT_CREATED;
|
||||
break;
|
||||
case OS_SWTMR_STATUS_CREATED:
|
||||
ret = LOS_ERRNO_SWTMR_NOT_STARTED;
|
||||
break;
|
||||
case OS_SWTMR_STATUS_TICKING:
|
||||
OsSwtmrStop(swtmr);
|
||||
break;
|
||||
default:
|
||||
ret = LOS_ERRNO_SWTMR_STATUS_INVALID;
|
||||
break;
|
||||
}
|
||||
|
||||
LOS_IntRestore(intSave);
|
||||
return ret;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT UINT32 LOS_SwtmrTimeGet(UINT16 swtmrId, UINT32 *tick)
|
||||
{
|
||||
SWTMR_CTRL_S *swtmr = NULL;
|
||||
UINTPTR intSave;
|
||||
UINT32 ret = LOS_OK;
|
||||
UINT16 swtmrCbId;
|
||||
|
||||
if (swtmrId >= OS_SWTMR_MAX_TIMERID) {
|
||||
return LOS_ERRNO_SWTMR_ID_INVALID;
|
||||
}
|
||||
|
||||
if (tick == NULL) {
|
||||
return LOS_ERRNO_SWTMR_TICK_PTR_NULL;
|
||||
}
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
swtmrCbId = swtmrId % LOSCFG_BASE_CORE_SWTMR_LIMIT;
|
||||
swtmr = g_swtmrCBArray + swtmrCbId;
|
||||
|
||||
if (swtmr->usTimerID != swtmrId) {
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_ERRNO_SWTMR_ID_INVALID;
|
||||
}
|
||||
switch (swtmr->ucState) {
|
||||
case OS_SWTMR_STATUS_UNUSED:
|
||||
ret = LOS_ERRNO_SWTMR_NOT_CREATED;
|
||||
break;
|
||||
case OS_SWTMR_STATUS_CREATED:
|
||||
ret = LOS_ERRNO_SWTMR_NOT_STARTED;
|
||||
break;
|
||||
case OS_SWTMR_STATUS_TICKING:
|
||||
*tick = OsSwtmrTimeGet(swtmr);
|
||||
break;
|
||||
default:
|
||||
ret = LOS_ERRNO_SWTMR_STATUS_INVALID;
|
||||
break;
|
||||
}
|
||||
LOS_IntRestore(intSave);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : LOS_SwtmrDelete
|
||||
Description : Delete software timer
|
||||
Input : swtmrId ------- Software timer ID
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT UINT32 LOS_SwtmrDelete(UINT16 swtmrId)
|
||||
{
|
||||
SWTMR_CTRL_S *swtmr = NULL;
|
||||
UINTPTR intSave;
|
||||
UINT32 ret = LOS_OK;
|
||||
UINT16 swtmrCbId;
|
||||
|
||||
if (swtmrId >= OS_SWTMR_MAX_TIMERID) {
|
||||
return LOS_ERRNO_SWTMR_ID_INVALID;
|
||||
}
|
||||
intSave = LOS_IntLock();
|
||||
swtmrCbId = swtmrId % LOSCFG_BASE_CORE_SWTMR_LIMIT;
|
||||
swtmr = g_swtmrCBArray + swtmrCbId;
|
||||
if (swtmr->usTimerID != swtmrId) {
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_ERRNO_SWTMR_ID_INVALID;
|
||||
}
|
||||
|
||||
switch (swtmr->ucState) {
|
||||
case OS_SWTMR_STATUS_UNUSED:
|
||||
ret = LOS_ERRNO_SWTMR_NOT_CREATED;
|
||||
break;
|
||||
case OS_SWTMR_STATUS_TICKING:
|
||||
OsSwtmrStop(swtmr);
|
||||
/* fall through */
|
||||
case OS_SWTMR_STATUS_CREATED:
|
||||
OsSwtmrDelete(swtmr);
|
||||
break;
|
||||
default:
|
||||
ret = LOS_ERRNO_SWTMR_STATUS_INVALID;
|
||||
break;
|
||||
}
|
||||
|
||||
LOS_IntRestore(intSave);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* (LOSCFG_BASE_CORE_SWTMR == YES) */
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
|
@ -0,0 +1,159 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#include "los_sys_pri.h"
|
||||
#include "los_tick_pri.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*****************************************************************************
|
||||
Function : LOS_TickCountGet
|
||||
Description : get current tick
|
||||
Input : None
|
||||
Output : None
|
||||
Return : current tick
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_MINOR UINT64 LOS_TickCountGet(VOID)
|
||||
{
|
||||
return g_ullTickCount;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : LOS_CyclePerTickGet
|
||||
Description : Get System cycle number corresponding to each tick
|
||||
Input : None
|
||||
Output : None
|
||||
Return : cycle number corresponding to each tick
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_CyclePerTickGet(VOID)
|
||||
{
|
||||
return g_cyclesPerTick;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : LOS_MS2Tick
|
||||
Description : milliseconds convert to Tick
|
||||
Input : millisec ---------- milliseconds
|
||||
Output : None
|
||||
Return : Tick
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_MS2Tick(UINT32 millisec)
|
||||
{
|
||||
if (millisec == OS_NULL_INT) {
|
||||
return OS_NULL_INT;
|
||||
}
|
||||
|
||||
return ((UINT64)millisec * LOSCFG_BASE_CORE_TICK_PER_SECOND) / OS_SYS_MS_PER_SECOND;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : LOS_Tick2MS
|
||||
Description : Tick convert to milliseconds
|
||||
Input : ticks ---------- ticks
|
||||
Output : None
|
||||
Return : milliseconds
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_Tick2MS(UINT32 ticks)
|
||||
{
|
||||
return ((UINT64)ticks * OS_SYS_MS_PER_SECOND) / LOSCFG_BASE_CORE_TICK_PER_SECOND;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : OsCpuTick2MS
|
||||
Description : cycle convert to milliseconds
|
||||
Input : cpuTick ---------- cycle
|
||||
Output : msHi ---------- High 32 milliseconds
|
||||
msLo ---------- Low 32 milliseconds
|
||||
Return : LOS_OK on success ,or error code on failure
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 OsCpuTick2MS(CpuTick *cpuTick, UINT32 *msHi, UINT32 *msLo)
|
||||
{
|
||||
UINT64 tmpCpuTick;
|
||||
DOUBLE temp;
|
||||
|
||||
if ((cpuTick == NULL) || (msHi == NULL) || (msLo == NULL)) {
|
||||
return LOS_ERRNO_SYS_PTR_NULL;
|
||||
}
|
||||
|
||||
if (g_sysClock == 0) {
|
||||
return LOS_ERRNO_SYS_CLOCK_INVALID;
|
||||
}
|
||||
tmpCpuTick = ((UINT64)cpuTick->cntHi << OS_SYS_MV_32_BIT) | cpuTick->cntLo;
|
||||
temp = tmpCpuTick / ((DOUBLE)g_sysClock / OS_SYS_MS_PER_SECOND);
|
||||
|
||||
tmpCpuTick = (UINT64)temp;
|
||||
|
||||
*msLo = (UINT32)tmpCpuTick;
|
||||
*msHi = (UINT32)(tmpCpuTick >> OS_SYS_MV_32_BIT);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : OsCpuTick2US
|
||||
Description : cycle convert to Microsecond
|
||||
Input : cpuTick ---------- cycle
|
||||
Output : usHi ---------- High 32 Microsecond
|
||||
usLo ---------- Low 32 Microsecond
|
||||
Return : LOS_OK on success ,or error code on failure
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 OsCpuTick2US(CpuTick *cpuTick, UINT32 *usHi, UINT32 *usLo)
|
||||
{
|
||||
UINT64 tmpCpuTick;
|
||||
DOUBLE temp;
|
||||
|
||||
if ((cpuTick == NULL) || (usHi == NULL) || (usLo == NULL)) {
|
||||
return LOS_ERRNO_SYS_PTR_NULL;
|
||||
}
|
||||
|
||||
if (g_sysClock == 0) {
|
||||
return LOS_ERRNO_SYS_CLOCK_INVALID;
|
||||
}
|
||||
tmpCpuTick = ((UINT64)cpuTick->cntHi << OS_SYS_MV_32_BIT) | cpuTick->cntLo;
|
||||
temp = tmpCpuTick / ((DOUBLE)g_sysClock / OS_SYS_US_PER_SECOND);
|
||||
|
||||
tmpCpuTick = (UINT64)temp;
|
||||
|
||||
*usLo = (UINT32)tmpCpuTick;
|
||||
*usHi = (UINT32)(tmpCpuTick >> OS_SYS_MV_32_BIT);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,117 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#include "los_tick_pri.h"
|
||||
#include "los_base_pri.h"
|
||||
#include "los_swtmr_pri.h"
|
||||
#include "los_task_pri.h"
|
||||
#include "los_timeslice_pri.h"
|
||||
#if (LOSCFG_KERNEL_TICKLESS == YES)
|
||||
#include "los_tickless_pri.h"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
LITE_OS_SEC_BSS UINT64 g_ullTickCount;
|
||||
LITE_OS_SEC_BSS UINT32 g_ticksPerSec;
|
||||
LITE_OS_SEC_BSS UINT32 g_uwCyclePerSec;
|
||||
LITE_OS_SEC_BSS UINT32 g_cyclesPerTick;
|
||||
LITE_OS_SEC_BSS UINT32 g_sysClock;
|
||||
|
||||
#if (LOSCFG_BASE_CORE_TICK_HW_TIME == YES)
|
||||
extern VOID platform_tick_handler(VOID);
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_KERNEL_TICKLESS == YES)
|
||||
LITE_OS_SEC_TEXT VOID OsTickHandlerLoop(UINT32 elapseTicks)
|
||||
{
|
||||
UINT32 index;
|
||||
|
||||
for (index = 0; index < elapseTicks; index++) {
|
||||
#if (LOSCFG_BASE_CORE_TICK_HW_TIME == YES)
|
||||
platform_tick_handler();
|
||||
#endif
|
||||
|
||||
g_ullTickCount++;
|
||||
|
||||
#if (LOSCFG_BASE_CORE_TIMESLICE == YES)
|
||||
OsTimesliceCheck();
|
||||
#endif
|
||||
OsTaskScan(); // task timeout scan
|
||||
#if (LOSCFG_BASE_CORE_SWTMR == YES)
|
||||
(VOID)OsSwtmrScan();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
LITE_OS_SEC_TEXT VOID OsTickHandler(VOID)
|
||||
{
|
||||
#if (LOSCFG_KERNEL_TICKLESS == YES)
|
||||
if (g_reloadSysTickFlag) {
|
||||
LOS_SysTickReload(g_cyclesPerTick);
|
||||
g_reloadSysTickFlag = 0;
|
||||
}
|
||||
g_tickIrqFlag = g_ticklessFlag;
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_BASE_CORE_TICK_HW_TIME == YES)
|
||||
platform_tick_handler();
|
||||
#endif
|
||||
|
||||
g_ullTickCount++;
|
||||
|
||||
#if (LOSCFG_BASE_CORE_TIMESLICE == YES)
|
||||
OsTimesliceCheck();
|
||||
#endif
|
||||
|
||||
OsTaskScan(); // task timeout scan
|
||||
|
||||
#if (LOSCFG_BASE_CORE_SWTMR == YES)
|
||||
(VOID)OsSwtmrScan();
|
||||
#endif
|
||||
}
|
||||
|
||||
UINT32 LOS_SysClockGet(VOID)
|
||||
{
|
||||
return g_sysClock;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#include "los_sys_pri.h"
|
||||
#include "los_task_pri.h"
|
||||
#include "los_tick_pri.h"
|
||||
#include "los_typedef_pri.h"
|
||||
#include "los_timeslice_pri.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#if (LOSCFG_BASE_CORE_TIMESLICE == YES)
|
||||
LITE_OS_SEC_BSS OsTaskRobin g_taskTimeSlice;
|
||||
|
||||
/*****************************************************************************
|
||||
Function : OsTimesliceInit
|
||||
Description : Initialztion Timeslice
|
||||
Input : None
|
||||
Output : None
|
||||
Return : None
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_INIT VOID OsTimesliceInit(VOID)
|
||||
{
|
||||
g_taskTimeSlice.task = (LosTaskCB *)NULL;
|
||||
g_taskTimeSlice.tout = LOSCFG_BASE_CORE_TIMESLICE_TIMEOUT;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : OsTimesliceCheck
|
||||
Description : check Timeslice
|
||||
Input : None
|
||||
Output : None
|
||||
Return : None
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT VOID OsTimesliceCheck(VOID)
|
||||
{
|
||||
if (g_taskTimeSlice.task != g_losTask.runTask) {
|
||||
g_taskTimeSlice.task = g_losTask.runTask;
|
||||
g_taskTimeSlice.time = ((UINT16)g_ullTickCount + g_taskTimeSlice.tout) - 1;
|
||||
}
|
||||
|
||||
if (g_taskTimeSlice.time == (UINT16)g_ullTickCount) {
|
||||
g_taskTimeSlice.task = (LosTaskCB *)NULL;
|
||||
if (LOS_TaskYield() != LOS_OK) {
|
||||
PRINT_INFO("%s, %d\n", __FUNCTION__, __LINE__);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef _LOS_BASE_PRI_H
|
||||
#define _LOS_BASE_PRI_H
|
||||
|
||||
#include "los_base.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @ingroup los_base
|
||||
* Define the CPU Tick structure.
|
||||
*/
|
||||
typedef struct tagCpuTick {
|
||||
UINT32 cntHi; /* < Upper 32 bits of the tick value */
|
||||
UINT32 cntLo; /* < Lower 32 bits of the tick value */
|
||||
} CpuTick;
|
||||
|
||||
#define OS_GOTO_ERREND() \
|
||||
do { \
|
||||
goto LOS_ERREND; \
|
||||
} while (0)
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_BASE_PRI_H */
|
|
@ -0,0 +1,132 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef _LOS_ERR_PRI_H
|
||||
#define _LOS_ERR_PRI_H
|
||||
|
||||
#include "los_err.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
|
||||
/**
|
||||
* @ingroup los_err
|
||||
* Define the error magic word.
|
||||
*/
|
||||
#define OS_ERR_MAGIC_WORD 0xa1b2c3f8
|
||||
|
||||
/**
|
||||
* @ingroup los_err
|
||||
* @brief Error handling macro capable of returning error codes.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to call the error handling function by using an error code and return the same error code.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param errNo [IN] Error code.
|
||||
*
|
||||
* @retval errNo
|
||||
* @par Dependency:
|
||||
* <ul><li>los_err_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
#define OS_RETURN_ERROR(errNo) \
|
||||
do { \
|
||||
(VOID)LOS_ErrHandle("os_unspecific_file", OS_ERR_MAGIC_WORD, errNo, 0, NULL); \
|
||||
return (errNo); \
|
||||
} while (0)
|
||||
|
||||
/**
|
||||
* @ingroup los_err
|
||||
* @brief Error handling macro capable of returning error codes.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to call the error handling function by using an error code and the line number of the erroneous line,
|
||||
and return the same error code.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param errLine [IN] Line number of the erroneous line.
|
||||
* @param errNo [IN] Error code.
|
||||
*
|
||||
* @retval errNo
|
||||
* @par Dependency:
|
||||
* <ul><li>los_err_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
#define OS_RETURN_ERROR_P2(errLine, errNo) \
|
||||
do { \
|
||||
(VOID)LOS_ErrHandle("os_unspecific_file", errLine, errNo, 0, NULL); \
|
||||
return (errNo); \
|
||||
} while (0)
|
||||
|
||||
/**
|
||||
* @ingroup los_err
|
||||
* @brief Macro for jumping to error handler.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to call the error handling function by using an error code.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param errorNo [IN] Error code.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_err_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
#define OS_GOTO_ERR_HANDLER(errorNo) \
|
||||
do { \
|
||||
errNo = (errorNo); \
|
||||
errLine = OS_ERR_MAGIC_WORD; \
|
||||
goto ERR_HANDLER; \
|
||||
} while (0)
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_ERR_PRI_H */
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef _LOS_EVENT_PRI_H
|
||||
#define _LOS_EVENT_PRI_H
|
||||
|
||||
#include "los_event.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
extern UINT32 OsEventReadOnce(PEVENT_CB_S eventCB, UINT32 eventMask, UINT32 mode, UINT32 timeOut);
|
||||
extern UINT32 OsEventWriteOnce(PEVENT_CB_S eventCB, UINT32 events);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_EVENT_PRI_H */
|
|
@ -0,0 +1,159 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup los_heap Heap
|
||||
* @ingroup kernel
|
||||
*/
|
||||
|
||||
#ifndef _LOS_HEAP_PRI_H
|
||||
#define _LOS_HEAP_PRI_H
|
||||
|
||||
#include "los_heap.h"
|
||||
#include "los_slab_pri.h"
|
||||
#include "los_memstat_pri.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct tagLosHeapStatus {
|
||||
UINT32 totalSize;
|
||||
UINT32 usedSize;
|
||||
UINT32 freeSize;
|
||||
UINT32 allocCount;
|
||||
UINT32 freeCount;
|
||||
} LosHeapStatus;
|
||||
|
||||
struct LosHeapManager {
|
||||
struct LOS_HEAP_NODE *head;
|
||||
struct LOS_HEAP_NODE *tail;
|
||||
UINT32 size;
|
||||
#if (LOSCFG_MEM_MUL_POOL == YES)
|
||||
VOID *nextPool;
|
||||
#endif
|
||||
#if (LOSCFG_KERNEL_MEM_SLAB == YES)
|
||||
struct LosSlabControlHeader slabCtrlHdr;
|
||||
#endif
|
||||
#if (LOSCFG_KERNEL_MEM_STATISTICS == YES)
|
||||
TaskMemUsedInfo memStats[LOSCFG_BASE_CORE_TSK_LIMIT + 2];
|
||||
#endif
|
||||
};
|
||||
|
||||
/**
|
||||
* @ingroup los_heap
|
||||
* @brief Look up the next memory node according to one memory node in the memory block list.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to look up the next memory node according to one memory node in the memory block list.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
* @param heapMan [IN] Type #LosHeapManager * Pointer to the manager,to distinguish heap.
|
||||
* @param node [IN] Type #LOS_HEAP_NODE * Size of memory in bytes to allocate.
|
||||
*
|
||||
* @retval LOS_HEAP_NODE * Pointer to next memory node.
|
||||
*
|
||||
* @par Dependency:
|
||||
* <ul><li>los_heap_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern struct LOS_HEAP_NODE* OsHeapPrvGetNext(struct LosHeapManager *heapMan, struct LOS_HEAP_NODE* node);
|
||||
|
||||
/**
|
||||
* @ingroup los_heap
|
||||
* @brief Obtain the heap information.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to obtain the heap information.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
* @param pool [IN] Type #VOID * A pointer pointed to the heap memory pool.
|
||||
*
|
||||
* @retval None.
|
||||
*
|
||||
* @par Dependency:
|
||||
* <ul><li>los_heap_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern VOID OsAlarmHeapInfo(VOID *pool);
|
||||
|
||||
/**
|
||||
* @ingroup los_heap
|
||||
* @brief Obtain the heap status.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to obtain the heap status.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
* @param pool [IN] Type #VOID * A pointer pointed to the heap memory pool.
|
||||
* @param status [OUT] Type #LosHeapStatus * Heap status.
|
||||
*
|
||||
* @retval UINT32 Get status result.
|
||||
*
|
||||
* @par Dependency:
|
||||
* <ul><li>los_heap_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern UINT32 OsHeapStatisticsGet(VOID *pool, LosHeapStatus *status);
|
||||
|
||||
/**
|
||||
* @ingroup los_heap
|
||||
* @brief Get the max free block size.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to Get the max free block size.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
* @param pool [IN] Type #VOID * A pointer pointed to the heap memory pool.
|
||||
*
|
||||
* @retval UINT32 Max free block size.
|
||||
*
|
||||
* @par Dependency:
|
||||
* <ul><li>los_heap_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern UINT32 OsHeapGetMaxFreeBlkSize(VOID *pool);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef _LOS_MEMBOX_PRI_H
|
||||
#define _LOS_MEMBOX_PRI_H
|
||||
|
||||
#include "los_membox.h"
|
||||
|
||||
#define OS_MEMBOX_NEXT(addr, blkSize) (LOS_MEMBOX_NODE *)((UINT8 *)(addr) + (blkSize))
|
||||
|
||||
#ifdef LOS_MEMBOX_CHECK
|
||||
#define OS_MEMBOX_MAGIC 0xa55a5aa5
|
||||
#define OS_MEMBOX_SET_MAGIC(addr) (*((UINT32 *)(addr)) = OS_MEMBOX_MAGIC)
|
||||
#define OS_MEMBOX_CHECK_MAGIC(addr) ((*((UINT32 *)(addr)) == OS_MEMBOX_MAGIC) ? LOS_OK : LOS_NOK)
|
||||
#else
|
||||
#define OS_MEMBOX_SET_MAGIC(addr)
|
||||
#define OS_MEMBOX_CHECK_MAGIC(addr) LOS_OK
|
||||
#endif
|
||||
|
||||
#define OS_MEMBOX_USER_ADDR(addr) ((VOID *)((UINT8 *)(addr) + LOS_MEMBOX_MAGIC_SIZE))
|
||||
#define OS_MEMBOX_NODE_ADDR(addr) ((LOS_MEMBOX_NODE *)((UINT8 *)(addr) - LOS_MEMBOX_MAGIC_SIZE))
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_MEMBOX_PRI_H */
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef _LOS_MEMCHECK_PRI_H
|
||||
#define _LOS_MEMCHECK_PRI_H
|
||||
|
||||
#include "los_memcheck.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
|
||||
/**
|
||||
* @ingroup los_memboxcheck
|
||||
* @brief Update the information of the memory.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to update the information of the memory.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param pool [IN/OUT] Type #VOID * Memory pool number.
|
||||
* @param size [IN] Type #UINT32 Memory size.
|
||||
* @param type [IN] Type #UINT32 Memory mang type.
|
||||
*
|
||||
* @retval UINT32 Updateinformation result.
|
||||
* @par Dependency:
|
||||
* <ul>
|
||||
* <li>los_memboxcheck_pri.h: the header file that contains the API declaration.</li>
|
||||
* </ul>
|
||||
* @see None.
|
||||
*/
|
||||
UINT32 OsMemInfoUpdate(VOID *pool, UINT32 size, UINT32 type);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
|
||||
#endif /* _LOS_MEMCHECK_PRI_H */
|
|
@ -0,0 +1,179 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef _LOS_MEMORY_PRI_H
|
||||
#define _LOS_MEMORY_PRI_H
|
||||
|
||||
#include "los_memory.h"
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define OS_MEM_ENABLE_MEM_STATISTICS
|
||||
|
||||
/*
|
||||
* memcheck error code: the stack have not inited
|
||||
* Value: 0x02000100
|
||||
* Solution: do memcheck must after stack mem init
|
||||
*/
|
||||
#define OS_ERRNO_MEMCHECK_NOT_INIT LOS_ERRNO_OS_ERROR(LOS_MOD_MEM, 0x0)
|
||||
|
||||
/*
|
||||
* memcheck error code: the pPtr is NULL
|
||||
* Value: 0x02000101
|
||||
* Solution: don't give a NULL parameter
|
||||
*/
|
||||
#define OS_ERRNO_MEMCHECK_PARA_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_MEM, 0x1)
|
||||
|
||||
/*
|
||||
* memcheck error code: the pPtr addr not in the suit range
|
||||
* Value: 0x02000102
|
||||
* Solution: check pPtr and comfirm it included by stack
|
||||
*/
|
||||
#define OS_ERRNO_MEMCHECK_OUTSIDE LOS_ERRNO_OS_ERROR(LOS_MOD_MEM, 0x2)
|
||||
|
||||
/*
|
||||
* memcheck error code: can't find the ctrl node
|
||||
* Value: 0x02000103
|
||||
* Solution: confirm the pPtr if this node has been freed or has not been alloced
|
||||
*/
|
||||
#define OS_ERRNO_MEMCHECK_NO_HEAD LOS_ERRNO_OS_ERROR(LOS_MOD_MEM, 0x3)
|
||||
|
||||
/*
|
||||
* memcheck error code: the para level is wrong
|
||||
* Value: 0x02000104
|
||||
* Solution: checkout the memcheck level by the func "OS_GetMemCheck_Level"
|
||||
*/
|
||||
#define OS_ERRNO_MEMCHECK_WRONG_LEVEL LOS_ERRNO_OS_ERROR(LOS_MOD_MEM, 0x4)
|
||||
|
||||
/*
|
||||
* memcheck error code: memcheck func not open
|
||||
* Value: 0x02000105
|
||||
* Solution: enable memcheck by the func "OS_SetMemCheck_Level"
|
||||
*/
|
||||
#define OS_ERRNO_MEMCHECK_DISABLED LOS_ERRNO_OS_ERROR(LOS_MOD_MEM, 0x5)
|
||||
|
||||
/**
|
||||
* @ingroup los_memory
|
||||
* @brief Initialization the memory system.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to initialization the memory system.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval UINT32 Initialization result.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_memory_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern UINT32 OsMemSystemInit(VOID);
|
||||
|
||||
/**
|
||||
* @ingroup los_memory
|
||||
* Memory linked list node structure
|
||||
*/
|
||||
typedef struct tagLosMemDynNode {
|
||||
LOS_DL_LIST freeNodeInfo; /**< Free memory node */
|
||||
struct tagLosMemDynNode *preNode; /**< Pointer to the previous memory node */
|
||||
UINT32 sizeAndFlag; /**< Size and flag of the current node(the highest bit
|
||||
represents a flag, and the rest bits specify the size) */
|
||||
} LosMemDynNode;
|
||||
|
||||
#define OS_MEM_TASKID_SET(node, ID) \
|
||||
do { \
|
||||
UINTPTR tmp = (UINTPTR)(((LosMemDynNode *)(node))->freeNodeInfo.pstNext); \
|
||||
tmp = tmp & 0xffff0000; \
|
||||
tmp |= (ID); \
|
||||
((LosMemDynNode *)(node))->freeNodeInfo.pstNext = (LOS_DL_LIST *)(tmp); \
|
||||
} while (0)
|
||||
|
||||
#define OS_MEM_TASKID_GET(node) ((UINT32)(UINTPTR)(((LosMemDynNode *)(node))->freeNodeInfo.pstNext) & 0xffff)
|
||||
|
||||
#define OS_MEM_MODID_SET(node, ID) \
|
||||
do { \
|
||||
UINTPTR tmp = (UINTPTR)(((LosMemDynNode *)(node))->freeNodeInfo.pstNext); \
|
||||
tmp = tmp & 0xffff; \
|
||||
tmp |= (ID) << 16; \
|
||||
((LosMemDynNode *)(node))->freeNodeInfo.pstNext = (LOS_DL_LIST *)(tmp); \
|
||||
} while (0)
|
||||
|
||||
#define OS_MEM_MODID_GET(node) ((UINT32)(((LosMemDynNode *)(node))->freeNodeInfo.pstNext) >> 16)
|
||||
|
||||
#define OS_MEM_NODE_HEAD_SIZE sizeof(LosMemDynNode)
|
||||
#define OS_MEM_MIN_POOL_SIZE (OS_DLNK_HEAD_SIZE + (2 * OS_MEM_NODE_HEAD_SIZE) + sizeof(LOS_MEM_POOL_INFO))
|
||||
#define OS_MEM_ALIGN_SIZE 4
|
||||
#define OS_MEM_NODE_USED_FLAG 0x80000000
|
||||
#define OS_MEM_NODE_ALIGNED_FLAG 0x40000000
|
||||
#define OS_MEM_NODE_ALIGN_SIZE 64
|
||||
#define OS_MEM_NODE_NUM 2
|
||||
#define OS_MEM_NODE_DATA_SIZE 4
|
||||
#define OS_MEM_NODE_COUNT_NUM 8
|
||||
#define OS_MULTI_DLNK_SIZE (OS_MAX_MULTI_DLNK_LOG2 - OS_MIN_MULTI_DLNK_LOG2)
|
||||
|
||||
#define OS_MEM_NODE_GET_ALIGNED_FLAG(sizeAndFlag) ((sizeAndFlag) & OS_MEM_NODE_ALIGNED_FLAG)
|
||||
#define OS_MEM_NODE_SET_ALIGNED_FLAG(sizeAndFlag) ((sizeAndFlag) = ((sizeAndFlag) | OS_MEM_NODE_ALIGNED_FLAG))
|
||||
#define OS_MEM_NODE_GET_ALIGNED_GAPSIZE(sizeAndFlag) ((sizeAndFlag) & (~OS_MEM_NODE_ALIGNED_FLAG))
|
||||
#define OS_MEM_NODE_GET_USED_FLAG(sizeAndFlag) ((sizeAndFlag) & OS_MEM_NODE_USED_FLAG)
|
||||
#define OS_MEM_NODE_SET_USED_FLAG(sizeAndFlag) ((sizeAndFlag) = ((sizeAndFlag) | OS_MEM_NODE_USED_FLAG))
|
||||
#define OS_MEM_NODE_GET_SIZE(sizeAndFlag) ((sizeAndFlag) & (~OS_MEM_NODE_USED_FLAG))
|
||||
#define OS_MEM_IS_NODE_NEXT_EXIST(node, poolInfo) (((UINT32)(node) + (node)->sizeAndFlag) < \
|
||||
((UINT32)(poolInfo) + (poolInfo)->uwPoolSize))
|
||||
#define OS_MEM_HEAD(pool, size) OS_DLNK_HEAD(OS_MEM_HEAD_ADDR(pool), size)
|
||||
#define OS_MEM_HEAD_ADDR(pool) ((VOID *)((UINT32)(UINTPTR)(pool) + sizeof(LOS_MEM_POOL_INFO)))
|
||||
#define OS_MEM_NEXT_NODE(node) ((LosMemDynNode *)((UINT8 *)(node) + \
|
||||
OS_MEM_NODE_GET_SIZE((node)->sizeAndFlag)))
|
||||
#define OS_MEM_FIRST_NODE(pool) ((LosMemDynNode *)((UINT8 *)OS_MEM_HEAD_ADDR(pool) + OS_DLNK_HEAD_SIZE))
|
||||
#define OS_MEM_END_NODE(pool, size) ((LosMemDynNode *)(((UINT8 *)(pool) + (size)) - OS_MEM_NODE_HEAD_SIZE))
|
||||
#define OS_MEM_MIDDLE_ADDR_OPEN_END(startAddr, middleAddr, endAddr) \
|
||||
(((UINT8 *)(startAddr) <= (UINT8 *)(middleAddr)) && ((UINT8 *)(middleAddr) < (UINT8 *)(endAddr)))
|
||||
#define OS_MEM_MIDDLE_ADDR(startAddr, middleAddr, endAddr) (((UINT8 *)(startAddr) <= (UINT8 *)(middleAddr)) && \
|
||||
((UINT8 *)(middleAddr) <= (UINT8 *)(endAddr)))
|
||||
#define OS_MEM_SET_MAGIC(value) (value) = (LOS_DL_LIST *)(UINTPTR)((UINT32)(UINTPTR)(&(value)) ^ 0xffffffff)
|
||||
#define OS_MEM_MAGIC_VALID(value) ((((UINT32)(UINTPTR)(value)) ^ ((UINT32)(UINTPTR)(&(value)))) == 0xffffffff)
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_MEMORY_PRI_H */
|
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef _LOS_MEMSTAT_PRI_H
|
||||
#define _LOS_MEMSTAT_PRI_H
|
||||
|
||||
#include "los_typedef.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#if (LOSCFG_MEMORY_BESTFIT == YES)
|
||||
|
||||
extern VOID OsTaskMemUsedInc(UINT32 usedSize, UINT32 taskID);
|
||||
extern VOID OsTaskMemUsedDec(UINT32 usedSize, UINT32 taskID);
|
||||
extern UINT32 OsTaskMemUsage(UINT32 taskID);
|
||||
extern VOID OsTaskMemClear(UINT32 taskID);
|
||||
|
||||
#ifdef OS_MEM_ENABLE_MEM_STATISTICS
|
||||
#define OS_MEM_ADD_USED(usedSize, taskID) OsTaskMemUsedInc(usedSize, taskID)
|
||||
#define OS_MEM_REDUCE_USED(usedSize, taskID) OsTaskMemUsedDec(usedSize, taskID)
|
||||
#define OS_MEM_CLEAR(taskID) OsTaskMemClear(taskID)
|
||||
#else
|
||||
#define OS_MEM_ADD_USED(usedSize, taskID)
|
||||
#define OS_MEM_REDUCE_USED(usedSize, taskID)
|
||||
#define OS_MEM_CLEAR(taskID)
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
#if (LOSCFG_KERNEL_MEM_STATISTICS == YES)
|
||||
typedef struct {
|
||||
UINT32 memUsed;
|
||||
UINT32 memPeak;
|
||||
} TaskMemUsedInfo;
|
||||
|
||||
extern VOID OsTaskMemStatInit(TaskMemUsedInfo *memStats);
|
||||
extern VOID OsTaskMemUsedInc(TaskMemUsedInfo *memStats, UINT32 usedSize, UINT32 taskID);
|
||||
extern VOID OsTaskMemUsedDec(TaskMemUsedInfo *memStats, UINT32 usedSize, UINT32 taskID);
|
||||
extern UINT32 OsTaskMemUsage(TaskMemUsedInfo *memStats, UINT32 taskID);
|
||||
extern VOID OsTaskMemClear(TaskMemUsedInfo *memStats, UINT32 taskID);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_MEMSTAT_PRI_H */
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef _LOS_MULTIPLE_DLINK_HEAD_PRI_H
|
||||
#define _LOS_MULTIPLE_DLINK_HEAD_PRI_H
|
||||
|
||||
#include "los_list.h"
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define OS_MAX_MULTI_DLNK_LOG2 30
|
||||
#define OS_MIN_MULTI_DLNK_LOG2 4
|
||||
#define OS_MULTI_DLNK_NUM ((OS_MAX_MULTI_DLNK_LOG2 - OS_MIN_MULTI_DLNK_LOG2) + 1)
|
||||
#define OS_DLNK_HEAD_SIZE OS_MULTI_DLNK_HEAD_SIZE
|
||||
#define OS_DLNK_INIT_HEAD OsDLnkInitMultiHead
|
||||
#define OS_DLNK_HEAD OsDLnkMultiHead
|
||||
#define OS_DLNK_NEXT_HEAD OsDLnkNextMultiHead
|
||||
#define OS_DLNK_FIRST_HEAD OsDLnkFirstMultiHead
|
||||
#define OS_MULTI_DLNK_HEAD_SIZE sizeof(LosMultipleDlinkHead)
|
||||
|
||||
typedef struct {
|
||||
LOS_DL_LIST listHead[OS_MULTI_DLNK_NUM];
|
||||
} LosMultipleDlinkHead;
|
||||
|
||||
STATIC_INLINE LOS_DL_LIST *OsDLnkNextMultiHead(VOID *headAddr, LOS_DL_LIST *listHead)
|
||||
{
|
||||
LosMultipleDlinkHead *head = (LosMultipleDlinkHead *)headAddr;
|
||||
|
||||
return (&(head->listHead[OS_MULTI_DLNK_NUM - 1]) == listHead) ? NULL : (listHead + 1);
|
||||
}
|
||||
|
||||
STATIC_INLINE LOS_DL_LIST *OsDLnkFirstMultiHead(VOID *headAddr)
|
||||
{
|
||||
return (LOS_DL_LIST *)headAddr;
|
||||
}
|
||||
|
||||
extern VOID OsDLnkInitMultiHead(VOID *headAddr);
|
||||
extern LOS_DL_LIST *OsDLnkMultiHead(VOID *headAddr, UINT32 size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_MULTIPLE_DLINK_HEAD_PRI_H */
|
|
@ -0,0 +1,110 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef _LOS_MUX_PRI_H
|
||||
#define _LOS_MUX_PRI_H
|
||||
|
||||
#include "los_task_pri.h"
|
||||
|
||||
#include "los_mux.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @ingroup los_mux
|
||||
* Mutex object.
|
||||
*/
|
||||
typedef struct {
|
||||
UINT8 muxStat; /**< State OS_MUX_UNUSED,OS_MUX_USED */
|
||||
UINT16 muxCount; /**< Times of locking a mutex */
|
||||
UINT32 muxID; /**< Handle ID */
|
||||
LOS_DL_LIST muxList; /**< Mutex linked list */
|
||||
LosTaskCB *owner; /**< The current thread that is locking a mutex */
|
||||
UINT16 priority; /**< Priority of the thread that is locking a mutex */
|
||||
} LosMuxCB;
|
||||
|
||||
/**
|
||||
* @ingroup los_mux
|
||||
* Mutex state: not in use.
|
||||
*/
|
||||
#define OS_MUX_UNUSED 0
|
||||
|
||||
/**
|
||||
* @ingroup los_mux
|
||||
* Mutex state: in use.
|
||||
*/
|
||||
#define OS_MUX_USED 1
|
||||
|
||||
extern LosMuxCB *g_allMux;
|
||||
|
||||
/**
|
||||
* @ingroup los_mux
|
||||
* Obtain the pointer to a mutex object of the mutex that has a specified handle.
|
||||
*/
|
||||
#define GET_MUX(muxid) (((LosMuxCB *)g_allMux) + (muxid))
|
||||
|
||||
/**
|
||||
* @ingroup los_mux
|
||||
* @brief Initializes the mutex.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to initializes the mutex.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval UINT32 Initialization result.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_mux_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_MuxDelete
|
||||
*/
|
||||
extern UINT32 OsMuxInit(VOID);
|
||||
|
||||
/**
|
||||
* @ingroup los_mux
|
||||
* Obtain the pointer to the linked list in the mutex pointed to by a specified pointer.
|
||||
*/
|
||||
#define GET_MUX_LIST(ptr) LOS_DL_LIST_ENTRY(ptr, LosMuxCB, muxList)
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_MUX_PRI_H */
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef _LOS_PRINTF_PRI_H
|
||||
#define _LOS_PRINTF_PRI_H
|
||||
|
||||
#include "los_printf.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
|
||||
VOID _dprintf(const CHAR *fmt, va_list ap);
|
||||
INT32 __dprintf(const CHAR *fmt, va_list ap, VOID (*uart_fputc)(UINT32 n, VOID *cookie), CHAR *cookie);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_PRINTF_PRI_H */
|
|
@ -0,0 +1,171 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef _LOS_PRIQUEUE_PRI_H
|
||||
#define _LOS_PRIQUEUE_PRI_H
|
||||
|
||||
#include "los_list.h"
|
||||
#include "los_typedef.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define OS_PRIORITY_QUEUE_PRIORITYNUM 32
|
||||
|
||||
/**
|
||||
* @ingroup los_priqueue
|
||||
* @brief Initialize the priority queue.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to initialize the priority queue.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
* @param none.
|
||||
*
|
||||
* @retval LOS_OK on success .
|
||||
* @retval LOS_NOK on failure.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_priqueue_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see none.
|
||||
*/
|
||||
extern UINT32 OsPriqueueInit(VOID);
|
||||
|
||||
/**
|
||||
* @ingroup los_priqueue
|
||||
* @brief Insert a item to the priority queue.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to insert a item to the priority queue according to the priority of this item.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>Param priqueueItem must point to valid memory.</li>
|
||||
* <li>Param priority rang is [0, OS_PRIORITY_QUEUE_PRIORITYNUM),included 0 and not included
|
||||
LOS_PRIORITY_QUEUE_PRIORITYNUM.</li>
|
||||
* </ul>
|
||||
* @param priqueueItem [IN] The node of item to be inserted.
|
||||
* @param priority [IN] Priority of the item be inserted.
|
||||
*
|
||||
* @retval none.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_priqueue_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see OsPriqueueDequeue.
|
||||
*/
|
||||
extern VOID OsPriqueueEnqueue(LOS_DL_LIST *priqueueItem, UINT32 priority);
|
||||
|
||||
/**
|
||||
* @ingroup los_priqueue
|
||||
* @brief Delete a item from the priority queue.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to delete a item from the priority queue.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>Param priqueueItem must point to valid memory.</li>
|
||||
* </ul>
|
||||
* @param priqueueItem [IN] The node of item to be deleted.
|
||||
*
|
||||
* @retval none.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_priqueue_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see OsPriqueueEnqueue.
|
||||
*/
|
||||
extern VOID OsPriqueueDequeue(LOS_DL_LIST *priqueueItem);
|
||||
|
||||
/**
|
||||
* @ingroup los_priqueue
|
||||
* @brief Obtain the item with highest priority.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to obtain the item with highest priority in the priority queue.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
* @param none.
|
||||
*
|
||||
* @retval NULL : The priority queue is empty.
|
||||
* @retval item node : The node of the item with highest priority.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_priqueue_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see none.
|
||||
*/
|
||||
extern LOS_DL_LIST *OsPriqueueTop(VOID);
|
||||
|
||||
/**
|
||||
* @ingroup los_priqueue
|
||||
* @brief Obtain the number of items with the specified priority.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to obtain the number of items with the specified priority.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>Param priority rang is [0, OS_PRIORITY_QUEUE_PRIORITYNUM),included 0 and not included
|
||||
LOS_PRIORITY_QUEUE_PRIORITYNUM.</li>
|
||||
* </ul>
|
||||
* @param priority [IN] Obtain the number of items with the specified priority of priority.
|
||||
*
|
||||
* @retval The number of items :The number of items with the specified priority.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_priqueue_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see none.
|
||||
*/
|
||||
extern UINT32 OsPriqueueSize(UINT32 priority);
|
||||
|
||||
/**
|
||||
* @ingroup los_priqueue
|
||||
* @brief Obtain the total number of items in the priority queue.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to obtain the number of items in the priority queue.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @retval The number of items: The total number of items in the priority queue.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_priqueue_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see none.
|
||||
*/
|
||||
extern UINT32 OsPriqueueTotalSize(VOID);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_PRIQUEUE_PRI_H */
|
|
@ -0,0 +1,234 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef _LOS_QUEUE_PRI_H
|
||||
#define _LOS_QUEUE_PRI_H
|
||||
|
||||
#include "los_queue.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
typedef enum {
|
||||
OS_QUEUE_READ,
|
||||
OS_QUEUE_WRITE
|
||||
} QueueReadWrite;
|
||||
|
||||
typedef enum {
|
||||
OS_QUEUE_HEAD,
|
||||
OS_QUEUE_TAIL
|
||||
} QueueHeadTail;
|
||||
|
||||
typedef enum {
|
||||
OS_QUEUE_NOT_POINT,
|
||||
OS_QUEUE_POINT
|
||||
} QueuePointOrNot;
|
||||
|
||||
#define OS_QUEUE_OPERATE_TYPE(ReadOrWrite, HeadOrTail, PointOrNot) \
|
||||
(((UINT32)(PointOrNot) << 2) | ((UINT32)(HeadOrTail) << 1) | (ReadOrWrite))
|
||||
#define OS_QUEUE_READ_WRITE_GET(type) ((type) & (0x01))
|
||||
#define OS_QUEUE_READ_HEAD (OS_QUEUE_READ | (OS_QUEUE_HEAD << 1))
|
||||
#define OS_QUEUE_READ_TAIL (OS_QUEUE_READ | (OS_QUEUE_TAIL << 1))
|
||||
#define OS_QUEUE_WRITE_HEAD (OS_QUEUE_WRITE | (OS_QUEUE_HEAD << 1))
|
||||
#define OS_QUEUE_WRITE_TAIL (OS_QUEUE_WRITE | (OS_QUEUE_TAIL << 1))
|
||||
#define OS_QUEUE_OPERATE_GET(type) ((type) & (0x03))
|
||||
#define OS_QUEUE_IS_POINT(type) ((type) & (0x04))
|
||||
#define OS_QUEUE_IS_READ(type) (OS_QUEUE_READ_WRITE_GET(type) == OS_QUEUE_READ)
|
||||
#define OS_QUEUE_IS_WRITE(type) (OS_QUEUE_READ_WRITE_GET(type) == OS_QUEUE_WRITE)
|
||||
#define OS_READWRITE_LEN 2
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue information block structure
|
||||
*/
|
||||
typedef struct {
|
||||
UINT8 *queue; /**< Pointer to a queue handle */
|
||||
UINT16 queueState; /**< Queue state */
|
||||
UINT16 queueLen; /**< Queue length */
|
||||
UINT16 queueSize; /**< Node size */
|
||||
UINT16 queueID; /**< queueID */
|
||||
UINT16 queueHead; /**< Node head */
|
||||
UINT16 queueTail; /**< Node tail */
|
||||
UINT16 readWriteableCnt[OS_READWRITE_LEN]; /**< Count of readable or writable resources, 0:readable, 1:writable */
|
||||
LOS_DL_LIST readWriteList[OS_READWRITE_LEN]; /**< Pointer to the linked list to be read or written,
|
||||
0:readlist, 1:writelist */
|
||||
LOS_DL_LIST memList; /**< Pointer to the memory linked list */
|
||||
} LosQueueCB;
|
||||
|
||||
/* queue state */
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Message queue state: not in use.
|
||||
*/
|
||||
#define OS_QUEUE_UNUSED 0
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Message queue state: used.
|
||||
*/
|
||||
#define OS_QUEUE_INUSED 1
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Not in use.
|
||||
*/
|
||||
#define OS_QUEUE_WAIT_FOR_POOL 1
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Normal message queue.
|
||||
*/
|
||||
#define OS_QUEUE_NORMAL 0
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue information control block
|
||||
*/
|
||||
extern LosQueueCB *g_allQueue;
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Obtain a handle of the queue that has a specified ID.
|
||||
*/
|
||||
#define GET_QUEUE_HANDLE(QueueID) (((LosQueueCB *)g_allQueue) + (QueueID))
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Obtain the head node in a queue doubly linked list.
|
||||
*/
|
||||
#define GET_QUEUE_LIST(ptr) LOS_DL_LIST_ENTRY(ptr, LosQueueCB, readWriteList[OS_QUEUE_WRITE])
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* @brief Alloc a stationary memory for a mail.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to alloc a stationary memory for a mail according to queueID.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>Do not alloc memory in unblocking modes such as interrupt.</li>
|
||||
* <li>This API cannot be called before the Huawei LiteOS is initialized.</li>
|
||||
* <li>The argument timeOut is a relative time.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param queueID [IN] Queue ID. The value range is [1,LOSCFG_BASE_IPC_QUEUE_LIMIT].
|
||||
* @param mailPool [IN] The memory poll that stores the mail.
|
||||
* @param timeOut [IN] Expiry time. The value range is [0,LOS_WAIT_FOREVER].
|
||||
*
|
||||
* @retval #NULL The memory allocation is failed.
|
||||
* @retval #mem The address of alloc memory.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_queue_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see OsQueueMailFree
|
||||
*/
|
||||
extern VOID *OsQueueMailAlloc(UINT32 queueID, VOID *mailPool, UINT32 timeOut);
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* @brief Free a stationary memory of a mail.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to free a stationary memory for a mail according to queueID.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>This API cannot be called before the Huawei LiteOS is initialized.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param queueID [IN] Queue ID. The value range is [1,LOSCFG_BASE_IPC_QUEUE_LIMIT].
|
||||
* @param mailPool [IN] The mail memory poll address.
|
||||
* @param mailMem [IN] The mail memory block address.
|
||||
*
|
||||
* @retval #LOS_OK 0x00000000: The memory free successfully.
|
||||
* @retval #OS_ERRNO_QUEUE_MAIL_HANDLE_INVALID 0x02000619: The handle of the queue passed-in when the memory for
|
||||
the queue is being freed is invalid.
|
||||
* @retval #OS_ERRNO_QUEUE_MAIL_PTR_INVALID 0x0200061a: The pointer to the memory to be freed is null.
|
||||
* @retval #OS_ERRNO_QUEUE_MAIL_FREE_ERROR 0x0200061b: The memory for the queue fails to be freed.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_queue_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see OsQueueMailAlloc
|
||||
*/
|
||||
extern UINT32 OsQueueMailFree(UINT32 queueID, VOID *mailPool, VOID *mailMem);
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* @brief Initialization queue.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to initialization queue.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval UINT32 Initialization result.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_queue_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern UINT32 OsQueueInit(VOID);
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* @brief Handle when read or write queue.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to handle when read or write queue.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param queueID [IN] Queue id.
|
||||
* @param operateType [IN] Operate type
|
||||
* @param bufferAddr [IN] Buffer address.
|
||||
* @param bufferSize [IN] Buffer size.
|
||||
* @param timeOut [IN] Timeout.
|
||||
*
|
||||
* @retval UINT32 Handle result.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_queue_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern UINT32 OsQueueOperate(UINT32 queueID, UINT32 operateType, VOID *bufferAddr, UINT32 *bufferSize,
|
||||
UINT32 timeOut);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_QUEUE_PRI_H */
|
|
@ -0,0 +1,134 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef _LOS_SEM_PRI_H
|
||||
#define _LOS_SEM_PRI_H
|
||||
|
||||
#include "los_sem.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
enum LosSemMaxCount {
|
||||
OS_SEM_COUNTING_MAX_COUNT = 0xFFFF, /**< Max count of counting semaphores */
|
||||
OS_SEM_BINARY_MAX_COUNT = 1 /**< Max count of binary semaphores */
|
||||
};
|
||||
|
||||
/**
|
||||
* @ingroup los_sem
|
||||
* Semaphore control structure.
|
||||
*/
|
||||
typedef struct {
|
||||
UINT16 semStat; /**< Semaphore state */
|
||||
UINT16 semCount; /**< Number of available semaphores */
|
||||
UINT16 maxSemCount; /**< Max number of available semaphores */
|
||||
UINT16 semID; /**< Semaphore control structure ID */
|
||||
LOS_DL_LIST semList; /**< Queue of tasks that are waiting on a semaphore */
|
||||
} LosSemCB;
|
||||
|
||||
/**
|
||||
* @ingroup los_sem
|
||||
* The semaphore is not in use.
|
||||
*
|
||||
*/
|
||||
#define OS_SEM_UNUSED 0
|
||||
/**
|
||||
* @ingroup los_sem
|
||||
* The semaphore is used.
|
||||
*
|
||||
*/
|
||||
#define OS_SEM_USED 1
|
||||
/**
|
||||
* @ingroup los_sem
|
||||
* Obtain the head node in a semaphore doubly linked list.
|
||||
*
|
||||
*/
|
||||
#define GET_SEM_LIST(ptr) LOS_DL_LIST_ENTRY(ptr, LosSemCB, semList)
|
||||
extern LosSemCB *g_allSem;
|
||||
/**
|
||||
* @ingroup los_sem
|
||||
* Obtain a semaphore ID.
|
||||
*
|
||||
*/
|
||||
#define GET_SEM(semid) (((LosSemCB *)g_allSem) + (semid))
|
||||
|
||||
/**
|
||||
* @ingroup los_sem
|
||||
* @brief Initialize the Semaphore doubly linked list.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to initialize the Semaphore doubly linked list.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval UINT32 Initialization result.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_sem_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern UINT32 OsSemInit(VOID);
|
||||
|
||||
/**
|
||||
* @ingroup los_sem
|
||||
* @brief Create Semaphore.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to create Semaphore.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param count [IN]Type #UINT16 Semaphore count.
|
||||
* @param maxCount [IN]Type #UINT16 Max semaphore count.
|
||||
* @param semHandle [OUT]Type #UINT32 * Index of semaphore.
|
||||
*
|
||||
* @retval UINT32 Create result.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_sem_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
UINT32 OsSemCreate(UINT16 count, UINT16 maxCount, UINT32 *semHandle);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_SEM_PRI_H */
|
|
@ -0,0 +1,687 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup los_slab Slab
|
||||
* @ingroup kernel
|
||||
*/
|
||||
|
||||
#ifndef _LOS_SLAB_PRI_H
|
||||
#define _LOS_SLAB_PRI_H
|
||||
|
||||
#include "los_base.h"
|
||||
#include "los_slab.h"
|
||||
#include <los_typedef.h>
|
||||
|
||||
typedef struct tagLosSlabStatus {
|
||||
UINT32 totalSize;
|
||||
UINT32 usedSize;
|
||||
UINT32 freeSize;
|
||||
UINT32 allocCount;
|
||||
UINT32 freeCount;
|
||||
} LosSlabStatus;
|
||||
|
||||
typedef struct tagOsSlabBlockNode {
|
||||
UINT16 magic;
|
||||
UINT8 blkSz;
|
||||
UINT8 recordId;
|
||||
} OsSlabBlockNode;
|
||||
|
||||
struct AtomicBitset {
|
||||
UINT32 numBits;
|
||||
UINT32 words[0];
|
||||
};
|
||||
|
||||
typedef struct tagOsSlabAllocator {
|
||||
UINT32 itemSz;
|
||||
UINT8 *dataChunks;
|
||||
struct AtomicBitset *bitset;
|
||||
} OsSlabAllocator;
|
||||
|
||||
typedef struct tagOsSlabMem {
|
||||
UINT32 blkSz;
|
||||
UINT32 blkCnt;
|
||||
UINT32 blkUsedCnt;
|
||||
OsSlabAllocator *alloc;
|
||||
} OsSlabMem;
|
||||
|
||||
struct LosSlabControlHeader {
|
||||
OsSlabMem slabClass[SLAB_MEM_COUNT];
|
||||
};
|
||||
|
||||
#define OS_SLAB_MAGIC 0xdede
|
||||
#define OS_SLAB_BLOCK_HEAD_GET(ptr) ((OsSlabBlockNode *)(VOID *)((UINT8 *)(ptr) - \
|
||||
sizeof(OsSlabBlockNode)))
|
||||
#define OS_SLAB_BLOCK_MAGIC_SET(slabNode) (((OsSlabBlockNode *)(slabNode))->magic = (UINT16)OS_SLAB_MAGIC)
|
||||
#define OS_SLAB_BLOCK_MAGIC_GET(slabNode) (((OsSlabBlockNode *)(slabNode))->magic)
|
||||
#define OS_SLAB_BLOCK_SIZE_SET(slabNode, size) (((OsSlabBlockNode *)(slabNode))->blkSz = (size))
|
||||
#define OS_SLAB_BLOCK_SIZE_GET(slabNode) (((OsSlabBlockNode *)(slabNode))->blkSz)
|
||||
#define OS_SLAB_BLOCK_ID_SET(slabNode, id) (((OsSlabBlockNode *)(slabNode))->recordId = (id))
|
||||
#define OS_SLAB_BLOCK_ID_GET(slabNode) (((OsSlabBlockNode *)(slabNode))->recordId)
|
||||
#define OS_ALLOC_FROM_SLAB_CHECK(slabNode) (((OsSlabBlockNode *)(slabNode))->magic == (UINT16)OS_SLAB_MAGIC)
|
||||
|
||||
#define ATOMIC_BITSET_SZ(numbits) (sizeof(struct AtomicBitset) + ((numbits) + 31) / 8)
|
||||
|
||||
/**
|
||||
* @ingroup los_slab
|
||||
* @brief Initialization atomic bitset.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to initialization atomic bitset.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param set [IN/OUT] Type #AtomicBitset * Atomic bitset.
|
||||
* @param numBits [IN] Type #UINT32 Bits number.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_slab_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see OsSlabAllocatorDestroy
|
||||
*/
|
||||
VOID OsAtomicBitsetInit(struct AtomicBitset *set, UINT32 numBits);
|
||||
|
||||
/**
|
||||
* @ingroup los_slab
|
||||
* @brief Get atomic bitset number.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to get atomic bitset number.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param set [IN] Type #AtomicBitset * Atomic bitset.
|
||||
*
|
||||
* @retval UINT32 Atomic bitset number.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_slab_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see OsSlabAllocatorDestroy
|
||||
*/
|
||||
UINT32 OsAtomicBitsetGetNumBits(const struct AtomicBitset *set);
|
||||
|
||||
/**
|
||||
* @ingroup los_slab
|
||||
* @brief Get atomic bitset bit.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to get atomic bitset bit.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param set [IN] Type #AtomicBitset * Atomic bitset.
|
||||
* @param num [IN] Type #UINT32 Bit number.
|
||||
*
|
||||
* @retval BOOL success or failed
|
||||
* @par Dependency:
|
||||
* <ul><li>los_slab_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see OsSlabAllocatorDestroy
|
||||
*/
|
||||
BOOL OsAtomicBitsetGetBit(const struct AtomicBitset *set, UINT32 num);
|
||||
|
||||
/**
|
||||
* @ingroup los_slab
|
||||
* @brief Clear the atomic bitset bit.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to clear the atomic bitset bit.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param set [IN] Type #AtomicBitset * Atomic bitset.
|
||||
* @param num [IN] Type #UINT32 Bit number.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_slab_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see OsSlabAllocatorDestroy
|
||||
*/
|
||||
VOID OsAtomicBitsetClearBit(struct AtomicBitset *set, UINT32 num);
|
||||
|
||||
/**
|
||||
* @ingroup los_slab
|
||||
* @brief Clear and set the atomic bitset bit.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to clear and set the atomic bitset bit.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param set [IN] Type #AtomicBitset * Atomic bitset.
|
||||
*
|
||||
* @retval INT32 The address of the first available bit.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_slab_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see OsSlabAllocatorDestroy
|
||||
*/
|
||||
INT32 OsAtomicBitsetFindClearAndSet(struct AtomicBitset *set);
|
||||
|
||||
/**
|
||||
* @ingroup los_slab
|
||||
* @brief Change the order of the output idx of OsAtomicBitsetFindClearAndSet to order of natural numbers.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to change the order of the output idx of OsAtomicBitsetFindClearAndSet to order of natural numbers.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param bitset [IN] Type #AtomicBitset * Atomic bitset.
|
||||
* @param index [IN] Type #INT32 index.
|
||||
*
|
||||
* @retval INT32 Index to natural numbers.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_slab_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see OsSlabAllocatorDestroy
|
||||
*/
|
||||
INT32 OsAtomicBitsetIdxChgToNatural(struct AtomicBitset *bitset, INT32 index);
|
||||
|
||||
/**
|
||||
* @ingroup los_slab
|
||||
* @brief Judgment the atomic bitset is empty.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to judgment the atomic bitset is empty.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param bitset [IN] Type #AtomicBitset * Atomic bitset.
|
||||
*
|
||||
* @retval BOOL Judgment result.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_slab_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see OsSlabAllocatorDestroy
|
||||
*/
|
||||
BOOL OsAtomicBitsetEmpty(struct AtomicBitset *bitset);
|
||||
|
||||
// thread/interrupt safe. allocations will not fail if space exists. even in interrupts.
|
||||
// itemAlign over 4 will not be guaranteed since the heap does not hand out chunks with that kind of alignment
|
||||
/**
|
||||
* @ingroup los_slab
|
||||
* @brief create a new slab allocator.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to create a new slab allocator.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param pool [IN] Pointer to the memory pool that contains the memory block to be allocated.
|
||||
* @param itemSz [IN] The size of one slab page.
|
||||
* @param itemAlign [IN] Type alignment, 4 byte-aligned, 8 byte-aligned, etc.
|
||||
* @param numItems [IN] The number of slab page.
|
||||
*
|
||||
* @retval #OS_SLAB_ALLOCATOR* The address of slab allocator.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_slab_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see OsSlabAllocatorDestroy
|
||||
*/
|
||||
OsSlabAllocator *OsSlabAllocatorNew(VOID *pool, UINT32 itemSz, UINT32 itemAlign, UINT32 numItems);
|
||||
|
||||
/**
|
||||
* @ingroup los_slab
|
||||
* @brief Destroy a slab allocator.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to Destroy a slab allocator.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param pool [IN] Pointer to the memory pool that contains the memory block to be allocated.
|
||||
* @param allocator [IN] a slab allocator.
|
||||
*
|
||||
* @retval #VOID
|
||||
* @par Dependency:
|
||||
* <ul><li>los_slab_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see OsSlabAllocatorNew
|
||||
*/
|
||||
VOID OsSlabAllocatorDestroy(VOID *pool, OsSlabAllocator *allocator);
|
||||
|
||||
/**
|
||||
* @ingroup los_slab
|
||||
* @brief Allocate a slab page form allocator.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to allocate a slab page form allocator.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param allocator [IN] a slab allocator.
|
||||
*
|
||||
* @retval #VOID* return a slab page.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_slab_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see OsSlabAllocatorFree
|
||||
*/
|
||||
VOID* OsSlabAllocatorAlloc(OsSlabAllocator *allocator);
|
||||
|
||||
/**
|
||||
* @ingroup los_slab
|
||||
* @brief Free a slab page.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to free a slab page.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param allocator [IN] a slab allocator.
|
||||
* @param ptr [IN] a slab page.
|
||||
*
|
||||
* @retval #FALSE Failed to free a slab page.
|
||||
* @retval #TRUE Succees to free a slab page.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_slab_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_SlabAllocatorAlloc
|
||||
*/
|
||||
BOOL OsSlabAllocatorFree(OsSlabAllocator *allocator, VOID* ptr);
|
||||
|
||||
/**
|
||||
* @ingroup los_slab
|
||||
* @brief Get a slab page index with judgment.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to get a slab page index with judgment.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param allocator [IN] a slab allocator.
|
||||
* @param idx [IN] index
|
||||
*
|
||||
* @retval VOID *
|
||||
* @par Dependency:
|
||||
* <ul><li>los_slab_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
/* -> pointer or NULL if that slot is empty may be not int-safe. YMMV */
|
||||
VOID* OsSlabAllocatorGetNth(OsSlabAllocator *allocator, UINT32 idx);
|
||||
|
||||
/**
|
||||
* @ingroup los_slab
|
||||
* @brief Get a slab page index without judgment.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to get a slab page index without judgment.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param allocator [IN] a slab allocator.
|
||||
* @param idx [IN] index
|
||||
*
|
||||
* @retval VOID *
|
||||
* @par Dependency:
|
||||
* <ul><li>los_slab_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
VOID* OsSlabAllocatorGetIdxP(OsSlabAllocator *allocator, UINT32 idx);
|
||||
|
||||
/**
|
||||
* @ingroup los_slab
|
||||
* @brief Get the index of slab page in slab allocator.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to get the index of slab page in slab allocator.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param allocator [IN] a slab allocator.
|
||||
* @param ptr [IN] a slab page.
|
||||
*
|
||||
* @retval #-1 Illegal index .
|
||||
* @retval #UINT32 Succees to get index.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_slab_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
UINT32 OsSlabAllocatorGetIndex(OsSlabAllocator *allocator, VOID *ptr);
|
||||
|
||||
/**
|
||||
* @ingroup los_slab
|
||||
* @brief Get the number of slab page.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to get the number of slab page.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param allocator [IN] a slab allocator.
|
||||
*
|
||||
* @retval #UINT32 Succees to get the number of slab page.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_slab_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
UINT32 OsSlabAllocatorGetNumItems(OsSlabAllocator *allocator);
|
||||
|
||||
/**
|
||||
* @ingroup los_slab
|
||||
* @brief Check the slab allocator.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to check the slab allocator.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param allocator [IN] a slab allocator.
|
||||
*
|
||||
* @retval #FALSE The slab allocator is already used.
|
||||
* @retval #TRUE The slab allocator is not used.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_slab_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
BOOL OsSlabAllocatorEmpty(OsSlabAllocator *allocator);
|
||||
|
||||
/**
|
||||
* @ingroup los_slab
|
||||
* @brief Get the used number of slab page in slab allocator.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to get the used number of slab page in slab allocator.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param allocator [IN] a slab allocator.
|
||||
*
|
||||
* @retval #UINT32 The used number of slab page in slab allocator.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_slab_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
UINT32 OsSlabAllocatorGetUsedItemCnt(OsSlabAllocator *allocator);
|
||||
|
||||
/**
|
||||
* @ingroup los_slab
|
||||
* @brief Get the info of slab allocator.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to get the info of slab allocator.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param allocator [IN] a slab allocator.
|
||||
* @param itemSize [OUT] a slab page size.
|
||||
* @param itemCnt [OUT] a slab page num.
|
||||
* @param curUsage [OUT] a used number of slab page.
|
||||
*
|
||||
* @retval #VOID
|
||||
* @par Dependency:
|
||||
* <ul><li>los_slab_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
VOID OsSlabAllocatorGetSlabInfo(OsSlabAllocator *allocator, UINT32 *itemSize, UINT32 *itemCnt, UINT32 *curUsage);
|
||||
|
||||
/**
|
||||
* @ingroup los_slab
|
||||
* @brief init slab allocator.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to init slab allocator.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param pool [IN] Pointer to the memory pool that contains the memory block to be allocated.
|
||||
*
|
||||
* @retval BOOL
|
||||
* @par Dependency:
|
||||
* <ul><li>los_slab_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
extern BOOL OsSlabMemInit(VOID *pool);
|
||||
|
||||
/**
|
||||
* @ingroup los_slab
|
||||
* @brief alloc mem by slab allocator.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to alloc mem by slab allocator.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param pool [IN] Pointer to the memory pool that contains the memory block to be allocated.
|
||||
* @param sz [IN] Size of mem to alloc
|
||||
*
|
||||
* @retval VOID * The address of alloced mem or NULL.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_slab_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
extern VOID *OsSlabMemAlloc(VOID *pool, UINT32 sz);
|
||||
|
||||
/**
|
||||
* @ingroup los_slab
|
||||
* @brief free mem by slab allocator.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to free mem by slab allocator.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param pool [IN] Pointer to the memory pool that contains the memory block to be allocated.
|
||||
* @param ptr [IN] Pointer to the memory that to be free
|
||||
*
|
||||
* @retval BOOL success or failed
|
||||
* @par Dependency:
|
||||
* <ul><li>los_slab_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
extern BOOL OsSlabMemFree(VOID *pool, VOID *ptr);
|
||||
|
||||
/**
|
||||
* @ingroup los_slab
|
||||
* @brief deinit slab allocator.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to deinit slab allocator.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param pool [IN] Pointer to the memory pool that contains the memory block to be allocated.
|
||||
*
|
||||
* @retval VOID
|
||||
* @par Dependency:
|
||||
* <ul><li>los_slab_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
extern VOID OsSlabMemDeinit(VOID *pool);
|
||||
|
||||
/**
|
||||
* @ingroup los_slab
|
||||
* @brief Check slab allocator.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to check slab allocator.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param allocator [IN] a slab allocator.
|
||||
* @param ptr [IN] Slab node.
|
||||
*
|
||||
* @retval VOID
|
||||
* @par Dependency:
|
||||
* <ul><li>los_slab_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern BOOL OsSlabAllocatorCheck(OsSlabAllocator *allocator, VOID *ptr);
|
||||
|
||||
/**
|
||||
* @ingroup los_slab
|
||||
* @brief Get SlabCtrlHdr.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to get SlabCtrlHdr.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param pool [IN] Pointer to the memory pool that contains the memory block to be allocated.
|
||||
*
|
||||
* @retval VOID
|
||||
* @par Dependency:
|
||||
* <ul><li>los_slab_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern VOID *OsSlabCtrlHdrGet(const VOID *pool);
|
||||
|
||||
/**
|
||||
* @ingroup los_slab
|
||||
* @brief Check the slab memory.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to check the slab memory.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param pool [IN] Pointer to the memory pool that contains the memory block to be allocated.
|
||||
* @param ptr [IN] Slab block head.
|
||||
*
|
||||
* @retval UINT32 block size.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_slab_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern UINT32 OsSlabMemCheck(VOID *pool, VOID *ptr);
|
||||
|
||||
/**
|
||||
* @ingroup los_slab
|
||||
* @brief Get the slab status.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to get the slab status.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param pool [IN] Pointer to the memory pool that contains the memory block to be allocated.
|
||||
* @param status [IN/OUT] Slab block status.
|
||||
*
|
||||
* @retval UINT32 Get status result.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_slab_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern UINT32 OsSlabStatisticsGet(VOID *pool, LosSlabStatus *status);
|
||||
|
||||
/**
|
||||
* @ingroup los_slab
|
||||
* @brief Get the max free block size.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to get the max free block size.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param pool [IN] Pointer to the memory pool that contains the memory block to be allocated.
|
||||
*
|
||||
* @retval UINT32 Max free block size.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_slab_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern UINT32 OsSlabGetMaxFreeBlkSize(VOID *pool);
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,163 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef _LOS_SWTMR_PRI_H
|
||||
#define _LOS_SWTMR_PRI_H
|
||||
|
||||
#include "los_swtmr.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* Software timer state
|
||||
*/
|
||||
enum SwtmrState {
|
||||
OS_SWTMR_STATUS_UNUSED, /**< The software timer is not used. */
|
||||
OS_SWTMR_STATUS_CREATED, /**< The software timer is created. */
|
||||
OS_SWTMR_STATUS_TICKING /**< The software timer is timing. */
|
||||
};
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* Structure of the callback function that handles software timer timeout
|
||||
*/
|
||||
typedef struct {
|
||||
SWTMR_PROC_FUNC handler; /**< Callback function that handles software timer timeout */
|
||||
UINT32 arg; /**< Parameter passed in when the callback function
|
||||
that handles software timer timeout is called */
|
||||
} SwtmrHandlerItem;
|
||||
|
||||
extern SWTMR_CTRL_S *g_swtmrCBArray;
|
||||
|
||||
#define OS_SWT_FROM_SID(swtmrId) ((SWTMR_CTRL_S *)g_swtmrCBArray + ((swtmrId) % LOSCFG_BASE_CORE_SWTMR_LIMIT))
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* @brief Scan a software timer.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to scan a software timer when a Tick interrupt occurs and determine whether the software timer
|
||||
expires.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_swtmr_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_SwtmrStop
|
||||
*/
|
||||
extern UINT32 OsSwtmrScan(VOID);
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* @brief Initialization software timer.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to initialization software.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_swtmr_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern UINT32 OsSwtmrInit(VOID);
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* @brief Get next timeout.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to get next timeout.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_swtmr_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern UINT32 OsSwtmrGetNextTimeout(VOID);
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* @brief Adjust software timer list.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to adjust software timer list.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param sleepTime [IN] UINT32 Sleep time.
|
||||
*
|
||||
* @retval UINT32 Sleep time.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_swtmr_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern VOID OsSwtmrAdjust(UINT32 sleepTime);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_SWTMR_PRI_H */
|
|
@ -0,0 +1,183 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef _LOS_SYS_PRI_H
|
||||
#define _LOS_SYS_PRI_H
|
||||
|
||||
#include "los_base_pri.h"
|
||||
#include "los_tick_pri.h"
|
||||
#include "los_sys.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @ingroup los_sys
|
||||
* Number of operable bits of a 32-bit operand
|
||||
*/
|
||||
#define OS_SYS_MV_32_BIT 32
|
||||
|
||||
/**
|
||||
* @ingroup los_sys
|
||||
* Number of milliseconds in one second.
|
||||
*/
|
||||
#define OS_SYS_MS_PER_SECOND 1000
|
||||
|
||||
/**
|
||||
* @ingroup los_sys
|
||||
* Number of microseconds in one second.
|
||||
*/
|
||||
#define OS_SYS_US_PER_SECOND 1000000
|
||||
|
||||
/**
|
||||
* @ingroup los_sys
|
||||
* The maximum length of name.
|
||||
*/
|
||||
#define OS_SYS_APPVER_NAME_MAX 64
|
||||
|
||||
/**
|
||||
* @ingroup los_sys
|
||||
* The magic word.
|
||||
*/
|
||||
#define OS_SYS_MAGIC_WORD 0xAAAAAAAA
|
||||
|
||||
/**
|
||||
* @ingroup los_sys
|
||||
* The initialization value of stack space.
|
||||
*/
|
||||
#define OS_SYS_EMPTY_STACK 0xCACACACA
|
||||
|
||||
/**
|
||||
* @ingroup los_sys
|
||||
* @brief Convert cycles to milliseconds.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to convert cycles to milliseconds.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param cpuTick [IN] Number of CPU cycles.
|
||||
* @param msHi [OUT] Upper 32 bits of the number of milliseconds.
|
||||
* @param msLo [OUT] Lower 32 bits of the number of milliseconds.
|
||||
*
|
||||
* @retval #LOS_ERRNO_SYS_PTR_NULL 0x02000011: Invalid parameter.
|
||||
* @retval #LOS_OK 0: Cycles are successfully converted to microseconds.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_sys_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern UINT32 OsCpuTick2MS(CpuTick *cpuTick, UINT32 *msHi, UINT32 *msLo);
|
||||
|
||||
/**
|
||||
* @ingroup los_sys
|
||||
* @brief Convert cycles to microseconds.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to convert cycles to microseconds.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param cpuTick [IN] Number of CPU cycles.
|
||||
* @param usHi [OUT] Upper 32 bits of the number of microseconds.
|
||||
* @param usLo [OUT] Lower 32 bits of the number of microseconds.
|
||||
*
|
||||
* @retval #LOS_ERRNO_SYS_PTR_NULL 0x02000011: Invalid parameter.
|
||||
* @retval #LOS_OK 0: Cycles are successfully converted to microseconds.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_sys_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern UINT32 OsCpuTick2US(CpuTick *cpuTick, UINT32 *usHi, UINT32 *usLo);
|
||||
|
||||
/**
|
||||
* @ingroup los_sys
|
||||
* @brief Convert cycles to milliseconds.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to convert cycles to milliseconds.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param cycle [IN] Number of cycles.
|
||||
*
|
||||
* @retval Number of milliseconds obtained through the conversion. Cycles are successfully converted to milliseconds.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_sys_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
STATIC_INLINE UINT64 OsCycle2MS(UINT64 cycle)
|
||||
{
|
||||
return (UINT64)((cycle / (g_sysClock / OS_SYS_MS_PER_SECOND)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup los_sys
|
||||
* @brief Convert cycles to microseconds.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to convert cycles to microseconds.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param cycle [IN] Number of cycles.
|
||||
*
|
||||
* @retval Number of microseconds obtained through the conversion. Cycles are successfully converted to microseconds.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_sys_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
STATIC_INLINE UINT64 OsCycle2US(UINT64 cycle)
|
||||
{
|
||||
UINT64 tmp = g_sysClock / OS_SYS_US_PER_SECOND;
|
||||
if (tmp == 0) {
|
||||
return 0;
|
||||
}
|
||||
return (UINT64)(cycle / tmp);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_SYS_PRI_H */
|
|
@ -0,0 +1,711 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef _LOS_TASK_PRI_H
|
||||
#define _LOS_TASK_PRI_H
|
||||
|
||||
#include "los_task.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
* Null task ID
|
||||
*
|
||||
*/
|
||||
#define OS_TASK_ERRORID 0xFFFFFFFF
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
* Define a usable task priority.
|
||||
*
|
||||
* Highest task priority.
|
||||
*/
|
||||
#define OS_TASK_PRIORITY_HIGHEST 0
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
* Define a usable task priority.
|
||||
*
|
||||
* Lowest task priority.
|
||||
*/
|
||||
#define OS_TASK_PRIORITY_LOWEST 31
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
* Flag that indicates the task or task control block status.
|
||||
*
|
||||
* The task control block is unused.
|
||||
*/
|
||||
#define OS_TASK_STATUS_UNUSED 0x0001
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
* Flag that indicates the task or task control block status.
|
||||
*
|
||||
* The task is suspended.
|
||||
*/
|
||||
#define OS_TASK_STATUS_SUSPEND 0x0002
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
* Flag that indicates the task or task control block status.
|
||||
*
|
||||
* The task is ready.
|
||||
*/
|
||||
#define OS_TASK_STATUS_READY 0x0004
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
* Flag that indicates the task or task control block status.
|
||||
*
|
||||
* The task is blocked.
|
||||
*/
|
||||
#define OS_TASK_STATUS_PEND 0x0008
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
* Flag that indicates the task or task control block status.
|
||||
*
|
||||
* The task is running.
|
||||
*/
|
||||
#define OS_TASK_STATUS_RUNNING 0x0010
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
* Flag that indicates the task or task control block status.
|
||||
*
|
||||
* The task is delayed.
|
||||
*/
|
||||
#define OS_TASK_STATUS_DELAY 0x0020
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
* Flag that indicates the task or task control block status.
|
||||
*
|
||||
* The time for waiting for an event to occur expires.
|
||||
*/
|
||||
#define OS_TASK_STATUS_TIMEOUT 0x0040
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
* Flag that indicates the task or task control block status.
|
||||
*
|
||||
* The task is waiting for an event to occur.
|
||||
*/
|
||||
#define OS_TASK_STATUS_EVENT 0x0400
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
* Flag that indicates the task or task control block status.
|
||||
*
|
||||
* The task is reading an event.
|
||||
*/
|
||||
#define OS_TASK_STATUS_EVENT_READ 0x0800
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
* Flag that indicates the task or task control block status.
|
||||
*
|
||||
* A software timer is waiting for an event to occur.
|
||||
*/
|
||||
#define OS_TASK_STATUS_SWTMR_WAIT 0x1000
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
* Flag that indicates the task or task control block status.
|
||||
*
|
||||
* The task is blocked on a queue.
|
||||
*/
|
||||
#define OS_TASK_STATUS_PEND_QUEUE 0x2000
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
* Flag that indicates the task is in userspace.
|
||||
*
|
||||
* The task is a user task.
|
||||
*/
|
||||
#define OS_TASK_STATUS_USERSPACE 0x8000
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
* Boundary on which the stack size is aligned.
|
||||
*
|
||||
*/
|
||||
#define OS_TASK_STACK_SIZE_ALIGN 16
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
* Boundary on which the stack address is aligned.
|
||||
*
|
||||
*/
|
||||
#define OS_TASK_STACK_ADDR_ALIGN 8
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
* Task stack top magic number.
|
||||
*
|
||||
*/
|
||||
#define OS_TASK_MAGIC_WORD 0xCCCCCCCC
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
* Initial task stack value.
|
||||
*
|
||||
*/
|
||||
#define OS_TASK_STACK_INIT 0xCACACACA
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
* Number of usable task priorities.
|
||||
*/
|
||||
#define OS_TSK_PRINUM ((OS_TASK_PRIORITY_LOWEST - OS_TASK_PRIORITY_HIGHEST) + 1)
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
* @brief the num of delayed tasks bucket
|
||||
*/
|
||||
#define OS_TSK_SORTLINK_LEN 32
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
* @brief the bit width occupied by the delayed ticks of task
|
||||
*/
|
||||
#define OS_TSK_SORTLINK_LOGLEN 5
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
* @brief the mask of delayed tasks bucket id.
|
||||
*/
|
||||
#define OS_TSK_SORTLINK_MASK (OS_TSK_SORTLINK_LEN - 1)
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
* @brief the max task count for switch.
|
||||
*/
|
||||
#define OS_TASK_SWITCH_INFO_COUNT 0xA
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
* @brief Check whether a task ID is valid.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to check whether a task ID, excluding the idle task ID, is valid.
|
||||
* @attention None.
|
||||
*
|
||||
* @param taskID [IN] Task ID.
|
||||
*
|
||||
* @retval 0 or 1. One indicates that the task ID is invalid, whereas zero indicates that the task ID is valid.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_task_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
#define OS_TSK_GET_INDEX(taskID) (taskID)
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
* @brief Obtain the pointer to a task control block.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to obtain the pointer to a task control block using a corresponding parameter.
|
||||
* @attention None.
|
||||
*
|
||||
* @param ptr [IN] Parameter used for obtaining the task control block.
|
||||
*
|
||||
* @retval Pointer to the task control block.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_task_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
#define OS_TCB_FROM_PENDLIST(ptr) LOS_DL_LIST_ENTRY(ptr, LosTaskCB, pendList)
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
* @brief Obtain the pointer to a task control block.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to obtain the pointer to a task control block that has a specified task ID.
|
||||
* @attention None.
|
||||
*
|
||||
* @param taskID [IN] task ID.
|
||||
*
|
||||
* @retval Pointer to the task control block.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_task_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
#define OS_TCB_FROM_TID(taskID) (((LosTaskCB *)g_taskCBArray) + (taskID))
|
||||
#define OS_IDLE_TASK_ENTRY ((TSK_ENTRY_FUNC)OsIdleTask)
|
||||
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
* Define the task control block structure.
|
||||
*/
|
||||
typedef struct {
|
||||
VOID *stackPointer; /**< Task stack pointer */
|
||||
UINT16 taskStatus;
|
||||
UINT16 priority;
|
||||
UINT32 stackSize; /**< Task stack size */
|
||||
UINT32 topOfStack; /**< Task stack top */
|
||||
UINT32 taskID; /**< Task ID */
|
||||
TSK_ENTRY_FUNC taskEntry; /**< Task entrance function */
|
||||
VOID *taskSem; /**< Task-held semaphore */
|
||||
VOID *taskMux; /**< Task-held mutex */
|
||||
UINT32 arg; /**< Parameter */
|
||||
CHAR *taskName; /**< Task name */
|
||||
LOS_DL_LIST pendList;
|
||||
LOS_DL_LIST timerList;
|
||||
UINT32 idxRollNum;
|
||||
EVENT_CB_S event;
|
||||
UINT32 eventMask; /**< Event mask */
|
||||
UINT32 eventMode; /**< Event mode */
|
||||
VOID *msg; /**< Memory allocated to queues */
|
||||
} LosTaskCB;
|
||||
|
||||
typedef struct {
|
||||
LosTaskCB *runTask;
|
||||
LosTaskCB *newTask;
|
||||
} LosTask;
|
||||
|
||||
typedef struct {
|
||||
LOS_DL_LIST *sortLink;
|
||||
UINT16 cursor;
|
||||
UINT16 unused;
|
||||
} TaskSortLinkAttr;
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
* Time slice structure.
|
||||
*/
|
||||
typedef struct TaskTimeSlice {
|
||||
LosTaskCB *task; /**< Current running task */
|
||||
UINT16 time; /**< Expiration time point */
|
||||
UINT16 tout; /**< Expiration duration */
|
||||
} OsTaskRobin;
|
||||
|
||||
typedef struct {
|
||||
UINT8 maxCnt : 7; // bits [6:0] store count of task switch info
|
||||
UINT8 isFull : 1; // bit [7] store isfull status
|
||||
} TaskCountInfo;
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
* Task switch information structure.
|
||||
*
|
||||
*/
|
||||
typedef struct {
|
||||
UINT8 idx;
|
||||
TaskCountInfo cntInfo;
|
||||
UINT16 pid[OS_TASK_SWITCH_INFO_COUNT];
|
||||
CHAR name[OS_TASK_SWITCH_INFO_COUNT][LOS_TASK_NAMELEN];
|
||||
}TaskSwitchInfo;
|
||||
|
||||
|
||||
extern LosTask g_losTask;
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
* Task lock flag.
|
||||
*
|
||||
*/
|
||||
extern UINT16 g_losTaskLock;
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
* Maximum number of tasks.
|
||||
*
|
||||
*/
|
||||
extern UINT32 g_taskMaxNum;
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
* Idle task ID.
|
||||
*
|
||||
*/
|
||||
extern UINT32 g_idleTaskID;
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
* Software timer task ID.
|
||||
*
|
||||
*/
|
||||
extern UINT32 g_swtmrTaskID;
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
* Starting address of a task.
|
||||
*
|
||||
*/
|
||||
extern LosTaskCB *g_taskCBArray;
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
* Free task linked list.
|
||||
*
|
||||
*/
|
||||
extern LOS_DL_LIST g_losFreeTask;
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
* Circular linked list that stores tasks that are deleted automatically.
|
||||
*
|
||||
*/
|
||||
extern LOS_DL_LIST g_taskRecyleList;
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
* @brief the block status of task
|
||||
*/
|
||||
extern VOID OsTaskSchedule(VOID);
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
* @brief Modify the priority of task.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to modify the priority of task.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The taskCB should be a correct pointer to task control block structure.</li>
|
||||
* <li>the priority should be in [0, OS_TASK_PRIORITY_LOWEST].</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param taskCB [IN] Type #LosTaskCB * pointer to task control block structure.
|
||||
* @param priority [IN] Type #UINT16 the priority of task.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_task_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
extern VOID OsTaskPriModify(LosTaskCB *taskCB, UINT16 priority);
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
* @brief Scan a task.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to scan a task.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_task_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
extern VOID OsTaskScan(VOID);
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
* @brief Initialization a task.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to initialization a task.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval UINT32 Initialization result.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_task_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
extern UINT32 OsTaskInit(VOID);
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
* @brief Create idle task.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to create idle task.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval UINT32 Create result.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_task_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
extern UINT32 OsIdleTaskCreate(VOID);
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
* @brief Check task switch.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to check task switch.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_task_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
extern VOID OsTaskSwitchCheck(VOID);
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
* @brief TaskMonInit.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to taskMonInit.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_task_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
extern VOID OsTaskMonInit(VOID);
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
* @brief Task entry.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to task entry.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param taskID [IN] Type #UINT32 task id.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_task_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
extern VOID OsTaskEntry(UINT32 taskID);
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
* @brief pend running task to pendlist
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to pend task to pendlist and add to sorted delay list.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The pstList should be a vaild pointer to pendlist.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param list [IN] Type #LOS_DL_LIST * pointer to list which running task will be pended.
|
||||
* @param taskStatus [IN] Type #UINT32 Task Status.
|
||||
* @param timeOut [IN] Type #UINT32 Expiry time. The value range is [0,LOS_WAIT_FOREVER].
|
||||
*
|
||||
* @retval LOS_OK wait success
|
||||
* @retval LOS_NOK pend out
|
||||
* @par Dependency:
|
||||
* <ul><li>los_task_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see OsTaskWake
|
||||
*/
|
||||
extern VOID OsTaskWait(LOS_DL_LIST *list, UINT32 taskStatus, UINT32 timeOut);
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
* @brief delete task from pendlist.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to delete task from pendlist and also add to the priqueue.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The pstList should be a vaild pointer to pend list.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param resumedTask [IN] Type #LosTaskCB * pointer to the task which will be add to priqueue.
|
||||
* @param taskStatus [IN] Type #UINT32 Task Status.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_task_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see OsTaskWait
|
||||
*/
|
||||
extern VOID OsTaskWake(LosTaskCB *resumedTask, UINT32 taskStatus);
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
* @brief Get the task water line.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to get the task water line.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param taskID [IN] Type #UINT32 task id.
|
||||
*
|
||||
* @retval UINT32 Task water line.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_task_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern UINT32 OsGetTaskWaterLine(UINT32 taskID);
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
* @brief Convert task status to string.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to convert task status to string.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param taskStatus [IN] Type #UINT16 task status.
|
||||
*
|
||||
* @retval UINT8 * String.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_task_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern UINT8 *OsConvertTskStatus(UINT16 taskStatus);
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
* @brief Add task to sorted delay list.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to add task to sorted delay list.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The taskCB should be a correct pointer to task control block structure.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param taskCB [IN] Type #LosTaskCB * pointer to task control block structure.
|
||||
* @param timeout [IN] Type #UINT32 wait time, ticks.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_task_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see OsTimerListDelete
|
||||
*/
|
||||
extern VOID OsTaskAdd2TimerList(LosTaskCB *taskCB, UINT32 timeout);
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
* @brief delete task from sorted delay list.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to delete task from sorted delay list.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The taskCB should be a correct pointer to task control block structure.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param taskCB [IN] Type #LosTaskCB * pointer to task control block structure.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_task_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see OsTaskAdd2TimerList
|
||||
*/
|
||||
extern VOID OsTimerListDelete(LosTaskCB *taskCB);
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
* @brief Get all task information.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to get all task information.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval UINT32 All task information.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_task_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern UINT32 OsGetAllTskInfo(VOID);
|
||||
|
||||
|
||||
extern VOID *OsTskUserStackInit(VOID* stackPtr, VOID* userSP, UINT32 userStackSize);
|
||||
|
||||
extern VOID *OsTskStackInit(UINT32 taskID, UINT32 stackSize, VOID *topStack);
|
||||
|
||||
extern VOID OsSchedule(VOID);
|
||||
|
||||
extern VOID osTaskSchedule(VOID);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_TASK_PRI_H */
|
|
@ -0,0 +1,126 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef _LOS_TICK_PRI_H
|
||||
#define _LOS_TICK_PRI_H
|
||||
|
||||
#include "los_tick.h"
|
||||
#include "los_config.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @ingroup los_tick
|
||||
* Count of Ticks
|
||||
*/
|
||||
extern UINT64 g_ullTickCount;
|
||||
|
||||
/**
|
||||
* @ingroup los_tick
|
||||
* Ticks per second
|
||||
*/
|
||||
extern UINT32 g_ticksPerSec;
|
||||
|
||||
/**
|
||||
* @ingroup los_tick
|
||||
* Cycles per Second
|
||||
*/
|
||||
extern UINT32 g_uwCyclePerSec;
|
||||
|
||||
/**
|
||||
* @ingroup los_tick
|
||||
* Cycles per Tick
|
||||
*/
|
||||
extern UINT32 g_cyclesPerTick;
|
||||
|
||||
/**
|
||||
* @ingroup los_tick
|
||||
* System Clock
|
||||
*/
|
||||
extern UINT32 g_sysClock;
|
||||
/**
|
||||
* @ingroup los_tick
|
||||
* @brief Handle the system tick timeout.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is called when the system tick timeout and triggers the interrupt.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param none.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_tick_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern VOID OsTickHandler(VOID);
|
||||
|
||||
#if (LOSCFG_KERNEL_TICKLESS == YES)
|
||||
LITE_OS_SEC_TEXT VOID OsTickHandlerLoop(UINT32 elapseTicks);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_tick
|
||||
* @brief tick modul init.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is called when the system initializating.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param systemClock [IN] Type #UINT32 SystemClock.
|
||||
* @param tickPerSecond [IN] Type #UINT32 TickPerSecond.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_tick_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern UINT32 OsTickInit(UINT32 systemClock, UINT32 tickPerSecond);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_TICK_PRI_H */
|
|
@ -0,0 +1,99 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup los_timeslice Timeslice
|
||||
* @ingroup kernel
|
||||
*/
|
||||
|
||||
#ifndef _LOS_TIMESLICE_PRI_H
|
||||
#define _LOS_TIMESLICE_PRI_H
|
||||
|
||||
#include "los_typedef.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @ingroup los_timeslice
|
||||
* @brief Initialize time slices.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to initialize time slices that defines the cycle of time slices according to
|
||||
LOSCFG_BASE_CORE_TIMESLICE_TIMEOUT.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_timeslice_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern VOID OsTimesliceInit(VOID);
|
||||
|
||||
/**
|
||||
* @ingroup los_timeslice
|
||||
* @brief Check time slices.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to check time slices. If the number of Ticks equals to the time for task switch, tasks are switched. Otherwise, the Tick counting continues.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_timeslice_pri.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern VOID OsTimesliceCheck(VOID);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_TIMESLICE_PRI_H */
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef _LOS_TYPEDEF_PRI_H
|
||||
#define _LOS_TYPEDEF_PRI_H
|
||||
|
||||
#include "los_typedef.h"
|
||||
|
||||
#endif /* _LOS_TYPEDEF_PRI_H */
|
|
@ -0,0 +1,223 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#include "los_event_pri.h"
|
||||
#include "los_priqueue_pri.h"
|
||||
#include "los_task_pri.h"
|
||||
#include "los_hw.h"
|
||||
#include "los_hwi.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 LOS_EventInit(PEVENT_CB_S eventCB)
|
||||
{
|
||||
if (eventCB == NULL) {
|
||||
return LOS_ERRNO_EVENT_PTR_NULL;
|
||||
}
|
||||
eventCB->uwEventID = 0;
|
||||
LOS_ListInit(&eventCB->stEventList);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT UINT32 LOS_EventPoll(UINT32 *eventID, UINT32 eventMask, UINT32 mode)
|
||||
{
|
||||
UINT32 ret = 0;
|
||||
UINTPTR intSave;
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
if (mode & LOS_WAITMODE_OR) {
|
||||
if ((*eventID & eventMask) != 0) {
|
||||
ret = *eventID & eventMask;
|
||||
}
|
||||
} else {
|
||||
if ((eventMask != 0) && (eventMask == (*eventID & eventMask))) {
|
||||
ret = *eventID & eventMask;
|
||||
}
|
||||
}
|
||||
if (ret && (mode & LOS_WAITMODE_CLR)) {
|
||||
*eventID = *eventID & ~(ret);
|
||||
}
|
||||
LOS_IntRestore(intSave);
|
||||
return ret;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT STATIC_INLINE UINT32 OsEventReadParamCheck(PEVENT_CB_S eventCB, UINT32 eventMask, UINT32 mode)
|
||||
{
|
||||
if (eventCB == NULL) {
|
||||
return LOS_ERRNO_EVENT_PTR_NULL;
|
||||
}
|
||||
if ((eventCB->stEventList.pstNext == NULL) || (eventCB->stEventList.pstPrev == NULL)) {
|
||||
return LOS_ERRNO_EVENT_NOT_INITIALIZED;
|
||||
}
|
||||
if (eventMask == 0) {
|
||||
return LOS_ERRNO_EVENT_EVENTMASK_INVALID;
|
||||
}
|
||||
if (eventMask & LOS_ERRTYPE_ERROR) {
|
||||
return LOS_ERRNO_EVENT_SETBIT_INVALID;
|
||||
}
|
||||
if (((mode & LOS_WAITMODE_OR) && (mode & LOS_WAITMODE_AND)) ||
|
||||
(mode & ~(LOS_WAITMODE_OR | LOS_WAITMODE_AND | LOS_WAITMODE_CLR)) ||
|
||||
!(mode & (LOS_WAITMODE_OR | LOS_WAITMODE_AND))) {
|
||||
return LOS_ERRNO_EVENT_FLAGS_INVALID;
|
||||
}
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT UINT32 LOS_EventRead(PEVENT_CB_S eventCB, UINT32 eventMask, UINT32 mode, UINT32 timeOut)
|
||||
{
|
||||
UINT32 ret;
|
||||
UINTPTR intSave;
|
||||
LosTaskCB *runTsk = NULL;
|
||||
|
||||
ret = OsEventReadParamCheck(eventCB, eventMask, mode);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (OS_INT_ACTIVE) {
|
||||
return LOS_ERRNO_EVENT_READ_IN_INTERRUPT;
|
||||
}
|
||||
intSave = LOS_IntLock();
|
||||
ret = LOS_EventPoll(&(eventCB->uwEventID), eventMask, mode);
|
||||
if (ret == 0) {
|
||||
if (timeOut == 0) {
|
||||
LOS_IntRestore(intSave);
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (g_losTaskLock) {
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_ERRNO_EVENT_READ_IN_LOCK;
|
||||
}
|
||||
runTsk = g_losTask.runTask;
|
||||
runTsk->eventMask = eventMask;
|
||||
runTsk->eventMode = mode;
|
||||
OsTaskWait(&eventCB->stEventList, OS_TASK_STATUS_PEND, timeOut);
|
||||
LOS_IntRestore(intSave);
|
||||
LOS_Schedule();
|
||||
|
||||
if (runTsk->taskStatus & OS_TASK_STATUS_TIMEOUT) {
|
||||
intSave = LOS_IntLock();
|
||||
runTsk->taskStatus &= (~OS_TASK_STATUS_TIMEOUT);
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_ERRNO_EVENT_READ_TIMEOUT;
|
||||
}
|
||||
intSave = LOS_IntLock();
|
||||
ret = LOS_EventPoll(&eventCB->uwEventID, eventMask, mode);
|
||||
LOS_IntRestore(intSave);
|
||||
} else {
|
||||
LOS_IntRestore(intSave);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT UINT32 LOS_EventWrite(PEVENT_CB_S eventCB, UINT32 events)
|
||||
{
|
||||
LosTaskCB *resumedTask = NULL;
|
||||
LosTaskCB *nextTask = (LosTaskCB *)NULL;
|
||||
UINTPTR intSave;
|
||||
UINT8 exitFlag = 0;
|
||||
if (eventCB == NULL) {
|
||||
return LOS_ERRNO_EVENT_PTR_NULL;
|
||||
}
|
||||
if ((eventCB->stEventList.pstNext == NULL) || (eventCB->stEventList.pstPrev == NULL)) {
|
||||
return LOS_ERRNO_EVENT_NOT_INITIALIZED;
|
||||
}
|
||||
if (events & LOS_ERRTYPE_ERROR) {
|
||||
return LOS_ERRNO_EVENT_SETBIT_INVALID;
|
||||
}
|
||||
intSave = LOS_IntLock();
|
||||
eventCB->uwEventID |= events;
|
||||
if (!LOS_ListEmpty(&eventCB->stEventList)) {
|
||||
for (resumedTask = LOS_DL_LIST_ENTRY((&eventCB->stEventList)->pstNext, LosTaskCB, pendList);
|
||||
&resumedTask->pendList != (&eventCB->stEventList);) {
|
||||
nextTask = LOS_DL_LIST_ENTRY(resumedTask->pendList.pstNext, LosTaskCB, pendList);
|
||||
|
||||
if (((resumedTask->eventMode & LOS_WAITMODE_OR) && (resumedTask->eventMask & events) != 0) ||
|
||||
((resumedTask->eventMode & LOS_WAITMODE_AND) &&
|
||||
((resumedTask->eventMask & eventCB->uwEventID) == resumedTask->eventMask))) {
|
||||
exitFlag = 1;
|
||||
|
||||
OsTaskWake(resumedTask, OS_TASK_STATUS_PEND);
|
||||
}
|
||||
resumedTask = nextTask;
|
||||
}
|
||||
|
||||
if (exitFlag == 1) {
|
||||
LOS_IntRestore(intSave);
|
||||
LOS_Schedule();
|
||||
return LOS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 LOS_EventDestroy(PEVENT_CB_S eventCB)
|
||||
{
|
||||
UINTPTR intSave;
|
||||
if (eventCB == NULL) {
|
||||
return LOS_ERRNO_EVENT_PTR_NULL;
|
||||
}
|
||||
intSave = LOS_IntLock();
|
||||
|
||||
if (!LOS_ListEmpty(&eventCB->stEventList)) {
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_ERRNO_EVENT_SHOULD_NOT_DESTORY;
|
||||
}
|
||||
eventCB->stEventList.pstNext = (LOS_DL_LIST *)NULL;
|
||||
eventCB->stEventList.pstPrev = (LOS_DL_LIST *)NULL;
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_EventClear(PEVENT_CB_S eventCB, UINT32 events)
|
||||
{
|
||||
UINTPTR intSave;
|
||||
if (eventCB == NULL) {
|
||||
return LOS_ERRNO_EVENT_PTR_NULL;
|
||||
}
|
||||
intSave = LOS_IntLock();
|
||||
eventCB->uwEventID &= events;
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
|
@ -0,0 +1,318 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#include "los_mux_pri.h"
|
||||
#include "los_err_pri.h"
|
||||
#include "los_memory_pri.h"
|
||||
#include "los_priqueue_pri.h"
|
||||
#include "los_task_pri.h"
|
||||
#if (LOSCFG_PLATFORM_EXC == YES)
|
||||
#include "los_exc.h"
|
||||
#endif
|
||||
#include "los_hw.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#if (LOSCFG_BASE_IPC_MUX == YES)
|
||||
|
||||
LITE_OS_SEC_BSS LosMuxCB* g_allMux = NULL;
|
||||
LITE_OS_SEC_DATA_INIT LOS_DL_LIST g_unusedMuxList;
|
||||
|
||||
/*****************************************************************************
|
||||
Funtion : OsMuxInit
|
||||
Description : Initializes the mutex
|
||||
Input : None
|
||||
Output : None
|
||||
Return : LOS_OK on success ,or error code on failure
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 OsMuxInit(VOID)
|
||||
{
|
||||
LosMuxCB *muxNode = NULL;
|
||||
UINT32 index;
|
||||
|
||||
LOS_ListInit(&g_unusedMuxList);
|
||||
|
||||
if (LOSCFG_BASE_IPC_MUX_LIMIT == 0) {
|
||||
return LOS_ERRNO_MUX_MAXNUM_ZERO;
|
||||
}
|
||||
|
||||
g_allMux = (LosMuxCB *)LOS_MemAlloc(m_aucSysMem0, (LOSCFG_BASE_IPC_MUX_LIMIT * sizeof(LosMuxCB)));
|
||||
if (g_allMux == NULL) {
|
||||
return LOS_ERRNO_MUX_NO_MEMORY;
|
||||
}
|
||||
|
||||
for (index = 0; index < LOSCFG_BASE_IPC_MUX_LIMIT; index++) {
|
||||
muxNode = ((LosMuxCB *)g_allMux) + index;
|
||||
muxNode->muxID = index;
|
||||
muxNode->muxStat = OS_MUX_UNUSED;
|
||||
LOS_ListTailInsert(&g_unusedMuxList, &muxNode->muxList);
|
||||
}
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : LOS_MuxCreate
|
||||
Description : Create a mutex
|
||||
Input : None
|
||||
Output : muxHandle ------ Mutex operation handle
|
||||
Return : LOS_OK on success ,or error code on failure
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 LOS_MuxCreate(UINT32 *muxHandle)
|
||||
{
|
||||
UINT32 intSave;
|
||||
LosMuxCB *muxCreated = NULL;
|
||||
LOS_DL_LIST *unusedMux = NULL;
|
||||
UINT32 errNo;
|
||||
UINT32 errLine;
|
||||
|
||||
if (muxHandle == NULL) {
|
||||
return LOS_ERRNO_MUX_PTR_NULL;
|
||||
}
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
if (LOS_ListEmpty(&g_unusedMuxList)) {
|
||||
LOS_IntRestore(intSave);
|
||||
OS_GOTO_ERR_HANDLER(LOS_ERRNO_MUX_ALL_BUSY);
|
||||
}
|
||||
|
||||
unusedMux = LOS_DL_LIST_FIRST(&(g_unusedMuxList));
|
||||
LOS_ListDelete(unusedMux);
|
||||
muxCreated = (GET_MUX_LIST(unusedMux));
|
||||
muxCreated->muxCount = 0;
|
||||
muxCreated->muxStat = OS_MUX_USED;
|
||||
muxCreated->priority = 0;
|
||||
muxCreated->owner = (LosTaskCB *)NULL;
|
||||
LOS_ListInit(&muxCreated->muxList);
|
||||
*muxHandle = (UINT32)muxCreated->muxID;
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_OK;
|
||||
ERR_HANDLER:
|
||||
OS_RETURN_ERROR_P2(errLine, errNo);
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : LOS_MuxDelete
|
||||
Description : Delete a mutex
|
||||
Input : muxHandle ------Mutex operation handle
|
||||
Output : None
|
||||
Return : LOS_OK on success ,or error code on failure
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 LOS_MuxDelete(UINT32 muxHandle)
|
||||
{
|
||||
UINT32 intSave;
|
||||
LosMuxCB *muxDeleted = NULL;
|
||||
UINT32 errNo;
|
||||
UINT32 errLine;
|
||||
|
||||
if (muxHandle >= (UINT32)LOSCFG_BASE_IPC_MUX_LIMIT) {
|
||||
OS_GOTO_ERR_HANDLER(LOS_ERRNO_MUX_INVALID);
|
||||
}
|
||||
|
||||
muxDeleted = GET_MUX(muxHandle);
|
||||
intSave = LOS_IntLock();
|
||||
if (muxDeleted->muxStat == OS_MUX_UNUSED) {
|
||||
LOS_IntRestore(intSave);
|
||||
OS_GOTO_ERR_HANDLER(LOS_ERRNO_MUX_INVALID);
|
||||
}
|
||||
|
||||
if ((!LOS_ListEmpty(&muxDeleted->muxList)) || muxDeleted->muxCount) {
|
||||
LOS_IntRestore(intSave);
|
||||
OS_GOTO_ERR_HANDLER(LOS_ERRNO_MUX_PENDED);
|
||||
}
|
||||
|
||||
LOS_ListAdd(&g_unusedMuxList, &muxDeleted->muxList);
|
||||
muxDeleted->muxStat = OS_MUX_UNUSED;
|
||||
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return LOS_OK;
|
||||
ERR_HANDLER:
|
||||
OS_RETURN_ERROR_P2(errLine, errNo);
|
||||
}
|
||||
|
||||
STATIC_INLINE UINT32 OsMuxValidCheck(LosMuxCB *muxPended)
|
||||
{
|
||||
if (muxPended->muxStat == OS_MUX_UNUSED) {
|
||||
return LOS_ERRNO_MUX_INVALID;
|
||||
}
|
||||
|
||||
if (OS_INT_ACTIVE) {
|
||||
return LOS_ERRNO_MUX_PEND_INTERR;
|
||||
}
|
||||
|
||||
if (g_losTaskLock) {
|
||||
PRINT_ERR("!!!LOS_ERRNO_MUX_PEND_IN_LOCK!!!\n");
|
||||
#if (LOSCFG_PLATFORM_EXC == YES)
|
||||
OsBackTrace();
|
||||
#endif
|
||||
return LOS_ERRNO_MUX_PEND_IN_LOCK;
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : LOS_MuxPend
|
||||
Description : Specify the mutex P operation
|
||||
Input : muxHandle ------ Mutex operation handleone
|
||||
: timeOut ------- waiting time
|
||||
Output : None
|
||||
Return : LOS_OK on success ,or error code on failure
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT UINT32 LOS_MuxPend(UINT32 muxHandle, UINT32 timeout)
|
||||
{
|
||||
UINT32 intSave;
|
||||
LosMuxCB *muxPended = NULL;
|
||||
UINT32 retErr;
|
||||
LosTaskCB *runningTask = NULL;
|
||||
|
||||
if (muxHandle >= (UINT32)LOSCFG_BASE_IPC_MUX_LIMIT) {
|
||||
OS_RETURN_ERROR(LOS_ERRNO_MUX_INVALID);
|
||||
}
|
||||
|
||||
muxPended = GET_MUX(muxHandle);
|
||||
intSave = LOS_IntLock();
|
||||
retErr = OsMuxValidCheck(muxPended);
|
||||
if (retErr) {
|
||||
goto ERROR_MUX_PEND;
|
||||
}
|
||||
|
||||
runningTask = (LosTaskCB *)g_losTask.runTask;
|
||||
if (muxPended->muxCount == 0) {
|
||||
muxPended->muxCount++;
|
||||
muxPended->owner = runningTask;
|
||||
muxPended->priority = runningTask->priority;
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
if (muxPended->owner == runningTask) {
|
||||
muxPended->muxCount++;
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
if (!timeout) {
|
||||
retErr = LOS_ERRNO_MUX_UNAVAILABLE;
|
||||
goto ERROR_MUX_PEND;
|
||||
}
|
||||
|
||||
runningTask->taskMux = (VOID *)muxPended;
|
||||
|
||||
if (muxPended->owner->priority > runningTask->priority) {
|
||||
OsTaskPriModify(muxPended->owner, runningTask->priority);
|
||||
}
|
||||
|
||||
OsTaskWait(&muxPended->muxList, OS_TASK_STATUS_PEND, timeout);
|
||||
|
||||
LOS_IntRestore(intSave);
|
||||
LOS_Schedule();
|
||||
|
||||
if (runningTask->taskStatus & OS_TASK_STATUS_TIMEOUT) {
|
||||
intSave = LOS_IntLock();
|
||||
runningTask->taskStatus &= (~OS_TASK_STATUS_TIMEOUT);
|
||||
retErr = LOS_ERRNO_MUX_TIMEOUT;
|
||||
goto ERROR_MUX_PEND;
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
|
||||
ERROR_MUX_PEND:
|
||||
LOS_IntRestore(intSave);
|
||||
OS_RETURN_ERROR(retErr);
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : LOS_MuxPost
|
||||
Description : Specify the mutex V operation,
|
||||
Input : muxHandle ------ Mutex operation handle
|
||||
Output : None
|
||||
Return : LOS_OK on success ,or error code on failure
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT UINT32 LOS_MuxPost(UINT32 muxHandle)
|
||||
{
|
||||
UINT32 intSave;
|
||||
LosMuxCB *muxPosted = GET_MUX(muxHandle);
|
||||
LosTaskCB *resumedTask = NULL;
|
||||
LosTaskCB *runningTask = NULL;
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
|
||||
if ((muxHandle >= (UINT32)LOSCFG_BASE_IPC_MUX_LIMIT) ||
|
||||
(muxPosted->muxStat == OS_MUX_UNUSED)) {
|
||||
LOS_IntRestore(intSave);
|
||||
OS_RETURN_ERROR(LOS_ERRNO_MUX_INVALID);
|
||||
}
|
||||
|
||||
runningTask = (LosTaskCB *)g_losTask.runTask;
|
||||
if ((muxPosted->muxCount == 0) || (muxPosted->owner != runningTask)) {
|
||||
LOS_IntRestore(intSave);
|
||||
OS_RETURN_ERROR(LOS_ERRNO_MUX_INVALID);
|
||||
}
|
||||
|
||||
if (--(muxPosted->muxCount) != 0) {
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
if ((muxPosted->owner->priority) != muxPosted->priority) {
|
||||
OsTaskPriModify(muxPosted->owner, muxPosted->priority);
|
||||
}
|
||||
|
||||
if (!LOS_ListEmpty(&muxPosted->muxList)) {
|
||||
resumedTask = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&(muxPosted->muxList)));
|
||||
|
||||
muxPosted->muxCount = 1;
|
||||
muxPosted->owner = resumedTask;
|
||||
muxPosted->priority = resumedTask->priority;
|
||||
resumedTask->taskMux = NULL;
|
||||
|
||||
OsTaskWake(resumedTask, OS_TASK_STATUS_PEND);
|
||||
|
||||
LOS_IntRestore(intSave);
|
||||
LOS_Schedule();
|
||||
} else {
|
||||
LOS_IntRestore(intSave);
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
#endif /* (LOSCFG_BASE_IPC_MUX == YES) */
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
|
@ -0,0 +1,680 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#include "string.h"
|
||||
#include "securec.h"
|
||||
#include "los_queue_pri.h"
|
||||
#include "los_membox_pri.h"
|
||||
#include "los_memory_pri.h"
|
||||
#include "los_priqueue_pri.h"
|
||||
#include "los_task_pri.h"
|
||||
#if (LOSCFG_PLATFORM_EXC == YES)
|
||||
#include "los_exc_pri.h"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#if (LOSCFG_BASE_IPC_QUEUE == YES)
|
||||
|
||||
LITE_OS_SEC_BSS LosQueueCB *g_allQueue = NULL ;
|
||||
LITE_OS_SEC_BSS LOS_DL_LIST g_freeQueueList;
|
||||
#if (LOSCFG_PLATFORM_EXC == YES)
|
||||
LITE_OS_SEC_BSS UINT32 g_excQueueMaxNum;
|
||||
#endif
|
||||
|
||||
/**************************************************************************
|
||||
Function : OsQueueInit
|
||||
Description : queue initial
|
||||
Input : None
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
**************************************************************************/
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 OsQueueInit(VOID)
|
||||
{
|
||||
LosQueueCB *queueNode = NULL;
|
||||
UINT16 index;
|
||||
|
||||
if (LOSCFG_BASE_IPC_QUEUE_LIMIT == 0) {
|
||||
return LOS_ERRNO_QUEUE_MAXNUM_ZERO;
|
||||
}
|
||||
|
||||
g_allQueue = (LosQueueCB *)LOS_MemAlloc(m_aucSysMem0, LOSCFG_BASE_IPC_QUEUE_LIMIT * sizeof(LosQueueCB));
|
||||
if (g_allQueue == NULL) {
|
||||
return LOS_ERRNO_QUEUE_NO_MEMORY;
|
||||
}
|
||||
|
||||
(VOID)memset_s(g_allQueue, LOSCFG_BASE_IPC_QUEUE_LIMIT * sizeof(LosQueueCB),
|
||||
0, LOSCFG_BASE_IPC_QUEUE_LIMIT * sizeof(LosQueueCB));
|
||||
|
||||
LOS_ListInit(&g_freeQueueList);
|
||||
for (index = 0; index < LOSCFG_BASE_IPC_QUEUE_LIMIT; index++) {
|
||||
queueNode = ((LosQueueCB *)g_allQueue) + index;
|
||||
queueNode->queueID = index;
|
||||
LOS_ListTailInsert(&g_freeQueueList, &queueNode->readWriteList[OS_QUEUE_WRITE]);
|
||||
}
|
||||
|
||||
#if (LOSCFG_PLATFORM_EXC == YES)
|
||||
g_excQueueMaxNum = LOSCFG_BASE_IPC_QUEUE_LIMIT;
|
||||
OsExcRegister(OS_EXC_TYPE_QUE, (EXC_INFO_SAVE_CALLBACK)LOS_QueueInfoGet, &g_excQueueMaxNum);
|
||||
#endif
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : LOS_QueueCreate
|
||||
Description : Create a queue
|
||||
Input : queueName --- Queue name, less than 4 characters
|
||||
: len --- Queue lenth
|
||||
: flags --- Queue type, FIFO or PRIO
|
||||
: maxMsgSize --- Maximum message size in byte
|
||||
Output : queueID --- Queue ID
|
||||
Return : LOS_OK on success or error code on failure
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 LOS_QueueCreate(CHAR *queueName,
|
||||
UINT16 len,
|
||||
UINT32 *queueID,
|
||||
UINT32 flags,
|
||||
UINT16 maxMsgSize)
|
||||
{
|
||||
LosQueueCB *queueCB = NULL;
|
||||
UINTPTR intSave;
|
||||
LOS_DL_LIST *unusedQueue = NULL;
|
||||
UINT8 *queue = NULL;
|
||||
UINT16 msgSize;
|
||||
|
||||
(VOID)queueName;
|
||||
(VOID)flags;
|
||||
|
||||
if (queueID == NULL) {
|
||||
return LOS_ERRNO_QUEUE_CREAT_PTR_NULL;
|
||||
}
|
||||
|
||||
if (maxMsgSize > (OS_NULL_SHORT - sizeof(UINT32))) {
|
||||
return LOS_ERRNO_QUEUE_SIZE_TOO_BIG;
|
||||
}
|
||||
|
||||
if ((len == 0) || (maxMsgSize == 0)) {
|
||||
return LOS_ERRNO_QUEUE_PARA_ISZERO;
|
||||
}
|
||||
msgSize = maxMsgSize + sizeof(UINT32);
|
||||
|
||||
/* Memory allocation is time-consuming, to shorten the time of disable interrupt,
|
||||
move the memory allocation to here. */
|
||||
queue = (UINT8 *)LOS_MemAlloc(m_aucSysMem0, len * msgSize);
|
||||
if (queue == NULL) {
|
||||
return LOS_ERRNO_QUEUE_CREATE_NO_MEMORY;
|
||||
}
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
if (LOS_ListEmpty(&g_freeQueueList)) {
|
||||
LOS_IntRestore(intSave);
|
||||
(VOID)LOS_MemFree(m_aucSysMem0, queue);
|
||||
return LOS_ERRNO_QUEUE_CB_UNAVAILABLE;
|
||||
}
|
||||
|
||||
unusedQueue = LOS_DL_LIST_FIRST(&(g_freeQueueList));
|
||||
LOS_ListDelete(unusedQueue);
|
||||
queueCB = (GET_QUEUE_LIST(unusedQueue));
|
||||
queueCB->queueLen = len;
|
||||
queueCB->queueSize = msgSize;
|
||||
queueCB->queue = queue;
|
||||
queueCB->queueState = OS_QUEUE_INUSED;
|
||||
queueCB->readWriteableCnt[OS_QUEUE_READ] = 0;
|
||||
queueCB->readWriteableCnt[OS_QUEUE_WRITE] = len;
|
||||
queueCB->queueHead = 0;
|
||||
queueCB->queueTail = 0;
|
||||
LOS_ListInit(&queueCB->readWriteList[OS_QUEUE_READ]);
|
||||
LOS_ListInit(&queueCB->readWriteList[OS_QUEUE_WRITE]);
|
||||
LOS_ListInit(&queueCB->memList);
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
*queueID = queueCB->queueID;
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
static INLINE LITE_OS_SEC_TEXT UINT32 OsQueueReadParameterCheck(UINT32 queueID, VOID *bufferAddr,
|
||||
UINT32 *bufferSize, UINT32 timeOut)
|
||||
{
|
||||
if (queueID >= LOSCFG_BASE_IPC_QUEUE_LIMIT) {
|
||||
return LOS_ERRNO_QUEUE_INVALID;
|
||||
}
|
||||
if ((bufferAddr == NULL) || (bufferSize == NULL)) {
|
||||
return LOS_ERRNO_QUEUE_READ_PTR_NULL;
|
||||
}
|
||||
|
||||
if (*bufferSize == 0) {
|
||||
return LOS_ERRNO_QUEUE_READSIZE_ISZERO;
|
||||
}
|
||||
|
||||
if (timeOut != LOS_NO_WAIT) {
|
||||
if (OS_INT_ACTIVE) {
|
||||
return LOS_ERRNO_QUEUE_READ_IN_INTERRUPT;
|
||||
}
|
||||
}
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
static INLINE LITE_OS_SEC_TEXT UINT32 OsQueueWriteParameterCheck(UINT32 queueID, VOID *bufferAddr,
|
||||
UINT32 *bufferSize, UINT32 timeOut)
|
||||
{
|
||||
if (queueID >= LOSCFG_BASE_IPC_QUEUE_LIMIT) {
|
||||
return LOS_ERRNO_QUEUE_INVALID;
|
||||
}
|
||||
|
||||
if (bufferAddr == NULL) {
|
||||
return LOS_ERRNO_QUEUE_WRITE_PTR_NULL;
|
||||
}
|
||||
|
||||
if (*bufferSize == 0) {
|
||||
return LOS_ERRNO_QUEUE_WRITESIZE_ISZERO;
|
||||
}
|
||||
|
||||
if (timeOut != LOS_NO_WAIT) {
|
||||
if (OS_INT_ACTIVE) {
|
||||
return LOS_ERRNO_QUEUE_WRITE_IN_INTERRUPT;
|
||||
}
|
||||
}
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
static INLINE VOID OsQueueBufferOperate(LosQueueCB *queueCB, UINT32 operateType,
|
||||
VOID *bufferAddr, UINT32 *bufferSize)
|
||||
{
|
||||
UINT8 *queueNode = NULL;
|
||||
UINT32 msgDataSize;
|
||||
UINT16 queuePosion;
|
||||
errno_t rc;
|
||||
|
||||
/* get the queue position */
|
||||
switch (OS_QUEUE_OPERATE_GET(operateType)) {
|
||||
case OS_QUEUE_READ_HEAD:
|
||||
queuePosion = queueCB->queueHead;
|
||||
((queueCB->queueHead + 1) == queueCB->queueLen) ? (queueCB->queueHead = 0) : (queueCB->queueHead++);
|
||||
break;
|
||||
|
||||
case OS_QUEUE_WRITE_HEAD:
|
||||
(queueCB->queueHead == 0) ? (queueCB->queueHead = (queueCB->queueLen - 1)) : (--queueCB->queueHead);
|
||||
queuePosion = queueCB->queueHead;
|
||||
break;
|
||||
|
||||
case OS_QUEUE_WRITE_TAIL:
|
||||
queuePosion = queueCB->queueTail;
|
||||
((queueCB->queueTail + 1) == queueCB->queueLen) ? (queueCB->queueTail = 0) : (queueCB->queueTail++);
|
||||
break;
|
||||
|
||||
default:
|
||||
PRINT_ERR("invalid queue operate type!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
queueNode = &(queueCB->queue[(queuePosion * (queueCB->queueSize))]);
|
||||
|
||||
if (OS_QUEUE_IS_POINT(operateType)) {
|
||||
if (OS_QUEUE_IS_READ(operateType)) {
|
||||
*(UINT32 *)bufferAddr = *(UINT32 *)(VOID *)queueNode;
|
||||
} else {
|
||||
*(UINT32 *)(VOID *)queueNode = *(UINT32 *)bufferAddr; // change to pp when calling OsQueueOperate
|
||||
}
|
||||
} else {
|
||||
if (OS_QUEUE_IS_READ(operateType)) {
|
||||
msgDataSize = *((UINT32 *)(UINTPTR)((queueNode + queueCB->queueSize) - sizeof(UINT32)));
|
||||
rc = memcpy_s((VOID *)bufferAddr, *bufferSize, (VOID *)queueNode, msgDataSize);
|
||||
if (rc != EOK) {
|
||||
PRINT_ERR("%s[%d] memcpy failed, error type = %u\n", __FUNCTION__, __LINE__, rc);
|
||||
return;
|
||||
}
|
||||
|
||||
*bufferSize = msgDataSize;
|
||||
} else {
|
||||
*((UINT32 *)(UINTPTR)((queueNode + queueCB->queueSize) - sizeof(UINT32))) = *bufferSize;
|
||||
rc = memcpy_s((VOID *)queueNode, queueCB->queueSize, (VOID *)bufferAddr, *bufferSize);
|
||||
if (rc != EOK) {
|
||||
PRINT_ERR("%s[%d] memcpy failed, error type = %u\n", __FUNCTION__, __LINE__, rc);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static INLINE UINT32 OsQueueOperateParamCheck(const LosQueueCB *queueCB, UINT32 operateType, const UINT32 *bufferSize)
|
||||
{
|
||||
if (queueCB->queueState == OS_QUEUE_UNUSED) {
|
||||
return LOS_ERRNO_QUEUE_NOT_CREATE;
|
||||
}
|
||||
|
||||
if (OS_QUEUE_IS_READ(operateType) && (*bufferSize < (queueCB->queueSize - sizeof(UINT32)))) {
|
||||
return LOS_ERRNO_QUEUE_READ_SIZE_TOO_SMALL;
|
||||
} else if (OS_QUEUE_IS_WRITE(operateType) && (*bufferSize > (queueCB->queueSize - sizeof(UINT32)))) {
|
||||
return LOS_ERRNO_QUEUE_WRITE_SIZE_TOO_BIG;
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
UINT32 OsQueueOperate(UINT32 queueID, UINT32 operateType, VOID *bufferAddr, UINT32 *bufferSize, UINT32 timeOut)
|
||||
{
|
||||
LosQueueCB *queueCB = NULL;
|
||||
LosTaskCB *runTsk = NULL;
|
||||
LosTaskCB *resumedTask = NULL;
|
||||
UINT32 ret;
|
||||
UINT32 readWrite = OS_QUEUE_READ_WRITE_GET(operateType);
|
||||
UINT32 readWriteTmp = !readWrite;
|
||||
|
||||
UINTPTR intSave = LOS_IntLock();
|
||||
|
||||
queueCB = (LosQueueCB *)GET_QUEUE_HANDLE(queueID);
|
||||
ret = OsQueueOperateParamCheck(queueCB, operateType, bufferSize);
|
||||
if (ret != LOS_OK) {
|
||||
goto QUEUE_END;
|
||||
}
|
||||
|
||||
if (queueCB->readWriteableCnt[readWrite] == 0) {
|
||||
if (timeOut == LOS_NO_WAIT) {
|
||||
ret = OS_QUEUE_IS_READ(operateType) ? LOS_ERRNO_QUEUE_ISEMPTY : LOS_ERRNO_QUEUE_ISFULL;
|
||||
goto QUEUE_END;
|
||||
}
|
||||
|
||||
if (g_losTaskLock) {
|
||||
ret = LOS_ERRNO_QUEUE_PEND_IN_LOCK;
|
||||
goto QUEUE_END;
|
||||
}
|
||||
|
||||
runTsk = (LosTaskCB *)g_losTask.runTask;
|
||||
OsTaskWait(&queueCB->readWriteList[readWrite], OS_TASK_STATUS_PEND_QUEUE, timeOut);
|
||||
LOS_IntRestore(intSave);
|
||||
LOS_Schedule();
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
if (runTsk->taskStatus & OS_TASK_STATUS_TIMEOUT) {
|
||||
runTsk->taskStatus &= (~OS_TASK_STATUS_TIMEOUT);
|
||||
ret = LOS_ERRNO_QUEUE_TIMEOUT;
|
||||
goto QUEUE_END;
|
||||
}
|
||||
} else {
|
||||
queueCB->readWriteableCnt[readWrite]--;
|
||||
}
|
||||
|
||||
OsQueueBufferOperate(queueCB, operateType, bufferAddr, bufferSize);
|
||||
|
||||
|
||||
if (!LOS_ListEmpty(&queueCB->readWriteList[readWriteTmp])) {
|
||||
resumedTask = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&queueCB->readWriteList[readWriteTmp]));
|
||||
OsTaskWake(resumedTask, OS_TASK_STATUS_PEND_QUEUE);
|
||||
LOS_IntRestore(intSave);
|
||||
LOS_Schedule();
|
||||
return LOS_OK;
|
||||
} else {
|
||||
queueCB->readWriteableCnt[readWriteTmp]++;
|
||||
}
|
||||
|
||||
QUEUE_END:
|
||||
LOS_IntRestore(intSave);
|
||||
return ret;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT UINT32 LOS_QueueReadCopy(UINT32 queueID,
|
||||
VOID *bufferAddr,
|
||||
UINT32 *bufferSize,
|
||||
UINT32 timeOut)
|
||||
{
|
||||
UINT32 ret;
|
||||
UINT32 operateType;
|
||||
|
||||
ret = OsQueueReadParameterCheck(queueID, bufferAddr, bufferSize, timeOut);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
operateType = OS_QUEUE_OPERATE_TYPE(OS_QUEUE_READ, OS_QUEUE_HEAD, OS_QUEUE_NOT_POINT);
|
||||
return OsQueueOperate(queueID, operateType, bufferAddr, bufferSize, timeOut);
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT UINT32 LOS_QueueWriteHeadCopy(UINT32 queueID,
|
||||
VOID *bufferAddr,
|
||||
UINT32 bufferSize,
|
||||
UINT32 timeOut)
|
||||
{
|
||||
UINT32 ret;
|
||||
UINT32 operateType;
|
||||
|
||||
ret = OsQueueWriteParameterCheck(queueID, bufferAddr, &bufferSize, timeOut);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
operateType = OS_QUEUE_OPERATE_TYPE(OS_QUEUE_WRITE, OS_QUEUE_HEAD, OS_QUEUE_NOT_POINT);
|
||||
return OsQueueOperate(queueID, operateType, bufferAddr, &bufferSize, timeOut);
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT UINT32 LOS_QueueWriteCopy(UINT32 queueID,
|
||||
VOID *bufferAddr,
|
||||
UINT32 bufferSize,
|
||||
UINT32 timeOut)
|
||||
{
|
||||
UINT32 ret;
|
||||
UINT32 operateType;
|
||||
|
||||
ret = OsQueueWriteParameterCheck(queueID, bufferAddr, &bufferSize, timeOut);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
operateType = OS_QUEUE_OPERATE_TYPE(OS_QUEUE_WRITE, OS_QUEUE_TAIL, OS_QUEUE_NOT_POINT);
|
||||
return OsQueueOperate(queueID, operateType, bufferAddr, &bufferSize, timeOut);
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT UINT32 LOS_QueueRead(UINT32 queueID, VOID *bufferAddr, UINT32 bufferSize, UINT32 timeOut)
|
||||
{
|
||||
UINT32 ret;
|
||||
UINT32 operateType;
|
||||
|
||||
ret = OsQueueReadParameterCheck(queueID, bufferAddr, &bufferSize, timeOut);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
operateType = OS_QUEUE_OPERATE_TYPE(OS_QUEUE_READ, OS_QUEUE_HEAD, OS_QUEUE_POINT);
|
||||
return OsQueueOperate(queueID, operateType, bufferAddr, &bufferSize, timeOut);
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT UINT32 LOS_QueueWrite(UINT32 queueID, VOID *bufferAddr, UINT32 bufferSize, UINT32 timeOut)
|
||||
{
|
||||
UINT32 ret;
|
||||
UINT32 operateType;
|
||||
UINT32 size = sizeof(UINT32 *);
|
||||
(VOID)bufferSize;
|
||||
|
||||
ret = OsQueueWriteParameterCheck(queueID, bufferAddr, &size, timeOut);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
operateType = OS_QUEUE_OPERATE_TYPE(OS_QUEUE_WRITE, OS_QUEUE_TAIL, OS_QUEUE_POINT);
|
||||
return OsQueueOperate(queueID, operateType, &bufferAddr, &size, timeOut);
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT UINT32 LOS_QueueWriteHead(UINT32 queueID,
|
||||
VOID *bufferAddr,
|
||||
UINT32 bufferSize,
|
||||
UINT32 timeOut)
|
||||
{
|
||||
UINT32 size = sizeof(UINT32 *);
|
||||
(VOID)bufferSize;
|
||||
|
||||
if (bufferAddr == NULL) {
|
||||
return LOS_ERRNO_QUEUE_WRITE_PTR_NULL;
|
||||
}
|
||||
|
||||
return LOS_QueueWriteHeadCopy(queueID, &bufferAddr, size, timeOut);
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : OsQueueMailAlloc
|
||||
Description : Mail allocate memory
|
||||
Input : queueID --- QueueID
|
||||
: mailPool --- MailPool
|
||||
: timeOut --- TimeOut
|
||||
Output : None
|
||||
Return : mem:pointer if success otherwise NULL
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT VOID *OsQueueMailAlloc(UINT32 queueID, VOID *mailPool, UINT32 timeOut)
|
||||
{
|
||||
VOID *mem = (VOID *)NULL;
|
||||
UINTPTR intSave;
|
||||
LosQueueCB *queueCB = (LosQueueCB *)NULL;
|
||||
LosTaskCB *runTsk = (LosTaskCB *)NULL;
|
||||
|
||||
if (queueID >= LOSCFG_BASE_IPC_QUEUE_LIMIT) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (mailPool == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (timeOut != LOS_NO_WAIT) {
|
||||
if (OS_INT_ACTIVE) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
queueCB = GET_QUEUE_HANDLE(queueID);
|
||||
if (queueCB->queueState == OS_QUEUE_UNUSED) {
|
||||
goto END;
|
||||
}
|
||||
|
||||
mem = LOS_MemboxAlloc(mailPool);
|
||||
if (mem == NULL) {
|
||||
if (timeOut == LOS_NO_WAIT) {
|
||||
goto END;
|
||||
}
|
||||
|
||||
runTsk = (LosTaskCB *)g_losTask.runTask;
|
||||
OsTaskWait(&queueCB->memList, OS_TASK_STATUS_PEND_QUEUE, timeOut);
|
||||
LOS_IntRestore(intSave);
|
||||
LOS_Schedule();
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
if (runTsk->taskStatus & OS_TASK_STATUS_TIMEOUT) {
|
||||
runTsk->taskStatus &= (~OS_TASK_STATUS_TIMEOUT);
|
||||
goto END;
|
||||
} else {
|
||||
/* When enters the current branch, means the current task already got a available membox,
|
||||
* so the runTsk->msg can not be NULL.
|
||||
*/
|
||||
mem = runTsk->msg;
|
||||
runTsk->msg = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
END:
|
||||
LOS_IntRestore(intSave);
|
||||
return mem;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : OsQueueMailFree
|
||||
Description : Mail free memory
|
||||
Input : queueID --- QueueID
|
||||
: mailPool --- MailPool
|
||||
: mailMem --- MailMem
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT UINT32 OsQueueMailFree(UINT32 queueID, VOID *mailPool, VOID *mailMem)
|
||||
{
|
||||
VOID *mem = (VOID *)NULL;
|
||||
UINTPTR intSave;
|
||||
LosQueueCB *queueCB = (LosQueueCB *)NULL;
|
||||
LosTaskCB *resumedTask = (LosTaskCB *)NULL;
|
||||
|
||||
if (queueID >= LOSCFG_BASE_IPC_QUEUE_LIMIT) {
|
||||
return LOS_ERRNO_QUEUE_MAIL_HANDLE_INVALID;
|
||||
}
|
||||
|
||||
if (mailPool == NULL) {
|
||||
return LOS_ERRNO_QUEUE_MAIL_PTR_INVALID;
|
||||
}
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
|
||||
if (LOS_MemboxFree(mailPool, mailMem)) {
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_ERRNO_QUEUE_MAIL_FREE_ERROR;
|
||||
}
|
||||
|
||||
queueCB = GET_QUEUE_HANDLE(queueID);
|
||||
if (queueCB->queueState == OS_QUEUE_UNUSED) {
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_ERRNO_QUEUE_NOT_CREATE;
|
||||
}
|
||||
|
||||
if (!LOS_ListEmpty(&queueCB->memList)) {
|
||||
resumedTask = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&queueCB->memList));
|
||||
OsTaskWake(resumedTask, OS_TASK_STATUS_PEND_QUEUE);
|
||||
mem = LOS_MemboxAlloc(mailPool);
|
||||
if (mem == NULL) {
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_ERRNO_QUEUE_NO_MEMORY;
|
||||
}
|
||||
resumedTask->msg = mem;
|
||||
LOS_IntRestore(intSave);
|
||||
LOS_Schedule();
|
||||
} else {
|
||||
LOS_IntRestore(intSave);
|
||||
}
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : LOS_QueueDelete
|
||||
Description : Delete a queue
|
||||
Input : queueID --- QueueID
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 LOS_QueueDelete(UINT32 queueID)
|
||||
{
|
||||
LosQueueCB *queueCB = NULL;
|
||||
UINT8 *queue = NULL;
|
||||
UINTPTR intSave;
|
||||
UINT32 ret;
|
||||
|
||||
if (queueID >= LOSCFG_BASE_IPC_QUEUE_LIMIT) {
|
||||
return LOS_ERRNO_QUEUE_NOT_FOUND;
|
||||
}
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
queueCB = (LosQueueCB *)GET_QUEUE_HANDLE(queueID);
|
||||
if (queueCB->queueState == OS_QUEUE_UNUSED) {
|
||||
ret = LOS_ERRNO_QUEUE_NOT_CREATE;
|
||||
goto QUEUE_END;
|
||||
}
|
||||
|
||||
if (!LOS_ListEmpty(&queueCB->readWriteList[OS_QUEUE_READ])) {
|
||||
ret = LOS_ERRNO_QUEUE_IN_TSKUSE;
|
||||
goto QUEUE_END;
|
||||
}
|
||||
|
||||
if (!LOS_ListEmpty(&queueCB->readWriteList[OS_QUEUE_WRITE])) {
|
||||
ret = LOS_ERRNO_QUEUE_IN_TSKUSE;
|
||||
goto QUEUE_END;
|
||||
}
|
||||
|
||||
if (!LOS_ListEmpty(&queueCB->memList)) {
|
||||
ret = LOS_ERRNO_QUEUE_IN_TSKUSE;
|
||||
goto QUEUE_END;
|
||||
}
|
||||
|
||||
if ((queueCB->readWriteableCnt[OS_QUEUE_WRITE] + queueCB->readWriteableCnt[OS_QUEUE_READ]) !=
|
||||
queueCB->queueLen) {
|
||||
ret = LOS_ERRNO_QUEUE_IN_TSKWRITE;
|
||||
goto QUEUE_END;
|
||||
}
|
||||
|
||||
queue = queueCB->queue;
|
||||
queueCB->queue = (UINT8 *)NULL;
|
||||
queueCB->queueState = OS_QUEUE_UNUSED;
|
||||
LOS_ListAdd(&g_freeQueueList, &queueCB->readWriteList[OS_QUEUE_WRITE]);
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
ret = LOS_MemFree(m_aucSysMem0, (VOID *)queue);
|
||||
return ret;
|
||||
|
||||
QUEUE_END:
|
||||
LOS_IntRestore(intSave);
|
||||
return ret;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_QueueInfoGet(UINT32 queueID, QUEUE_INFO_S *queueInfo)
|
||||
{
|
||||
UINTPTR intSave;
|
||||
UINT32 ret = LOS_OK;
|
||||
LosQueueCB *queueCB = NULL;
|
||||
LosTaskCB *tskCB = NULL;
|
||||
|
||||
if (queueInfo == NULL) {
|
||||
return LOS_ERRNO_QUEUE_PTR_NULL;
|
||||
}
|
||||
|
||||
if (queueID >= LOSCFG_BASE_IPC_QUEUE_LIMIT) {
|
||||
return LOS_ERRNO_QUEUE_INVALID;
|
||||
}
|
||||
|
||||
(VOID)memset_s((VOID *)queueInfo, sizeof(QUEUE_INFO_S), 0, sizeof(QUEUE_INFO_S));
|
||||
intSave = LOS_IntLock();
|
||||
|
||||
queueCB = (LosQueueCB *)GET_QUEUE_HANDLE(queueID);
|
||||
|
||||
if (queueCB->queueState == OS_QUEUE_UNUSED) {
|
||||
ret = LOS_ERRNO_QUEUE_NOT_CREATE;
|
||||
goto QUEUE_END;
|
||||
}
|
||||
|
||||
queueInfo->queueID = queueID;
|
||||
queueInfo->queueLen = queueCB->queueLen;
|
||||
queueInfo->queueSize = queueCB->queueSize;
|
||||
queueInfo->queueHead = queueCB->queueHead;
|
||||
queueInfo->queueTail = queueCB->queueTail;
|
||||
queueInfo->readableCnt = queueCB->readWriteableCnt[OS_QUEUE_READ];
|
||||
queueInfo->writableCnt = queueCB->readWriteableCnt[OS_QUEUE_WRITE];
|
||||
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY(tskCB, &queueCB->readWriteList[OS_QUEUE_READ], LosTaskCB, pendList) {
|
||||
queueInfo->waitReadTask |= (1 << tskCB->taskID);
|
||||
}
|
||||
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY(tskCB, &queueCB->readWriteList[OS_QUEUE_WRITE], LosTaskCB, pendList) {
|
||||
queueInfo->waitWriteTask |= (1 << tskCB->taskID);
|
||||
}
|
||||
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY(tskCB, &queueCB->memList, LosTaskCB, pendList) {
|
||||
queueInfo->waitMemTask |= (1 << tskCB->taskID);
|
||||
}
|
||||
|
||||
QUEUE_END:
|
||||
LOS_IntRestore(intSave);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* (LOSCFG_BASE_IPC_QUEUE == YES) */
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
|
@ -0,0 +1,327 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#include "los_sem_pri.h"
|
||||
#include "los_base_pri.h"
|
||||
#include "los_err_pri.h"
|
||||
#include "los_memory_pri.h"
|
||||
#include "los_priqueue_pri.h"
|
||||
#include "los_sys_pri.h"
|
||||
#include "los_task_pri.h"
|
||||
#if (LOSCFG_PLATFORM_EXC == YES)
|
||||
#include "los_exc.h"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#if (LOSCFG_BASE_IPC_SEM == YES)
|
||||
|
||||
LITE_OS_SEC_DATA_INIT LOS_DL_LIST g_unusedSemList;
|
||||
LITE_OS_SEC_BSS LosSemCB *g_allSem = NULL;
|
||||
|
||||
/*****************************************************************************
|
||||
Function : OsSemInit
|
||||
Description : Initialize the Semaphore doubly linked list
|
||||
Input : None
|
||||
Output : None
|
||||
Return : LOS_OK on success, or error code on failure
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 OsSemInit(VOID)
|
||||
{
|
||||
LosSemCB *semNode = NULL;
|
||||
UINT16 index;
|
||||
|
||||
LOS_ListInit(&g_unusedSemList);
|
||||
|
||||
if (LOSCFG_BASE_IPC_SEM_LIMIT == 0) {
|
||||
return LOS_ERRNO_SEM_MAXNUM_ZERO;
|
||||
}
|
||||
|
||||
g_allSem = (LosSemCB *)LOS_MemAlloc(m_aucSysMem0, (LOSCFG_BASE_IPC_SEM_LIMIT * sizeof(LosSemCB)));
|
||||
if (g_allSem == NULL) {
|
||||
return LOS_ERRNO_SEM_NO_MEMORY;
|
||||
}
|
||||
|
||||
/* Connect all the ECBs in a doubly linked list. */
|
||||
for (index = 0; index < LOSCFG_BASE_IPC_SEM_LIMIT; index++) {
|
||||
semNode = ((LosSemCB *)g_allSem) + index;
|
||||
semNode->semID = index;
|
||||
semNode->semStat = OS_SEM_UNUSED;
|
||||
LOS_ListTailInsert(&g_unusedSemList, &semNode->semList);
|
||||
}
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : OsSemCreate
|
||||
Description : create the Semaphore
|
||||
Input : count --- Semaphore count
|
||||
: maxCount --- Max semaphore count for check
|
||||
Output : semHandle --- Index of semaphore
|
||||
Return : LOS_OK on success, or error code on failure
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 OsSemCreate(UINT16 count, UINT16 maxCount, UINT32 *semHandle)
|
||||
{
|
||||
UINT32 intSave;
|
||||
LosSemCB *semCreated = NULL;
|
||||
LOS_DL_LIST *unusedSem = NULL;
|
||||
UINT32 errNo;
|
||||
UINT32 errLine;
|
||||
|
||||
if (semHandle == NULL) {
|
||||
return LOS_ERRNO_SEM_PTR_NULL;
|
||||
}
|
||||
|
||||
if (count > maxCount) {
|
||||
OS_GOTO_ERR_HANDLER(LOS_ERRNO_SEM_OVERFLOW);
|
||||
}
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
|
||||
if (LOS_ListEmpty(&g_unusedSemList)) {
|
||||
LOS_IntRestore(intSave);
|
||||
OS_GOTO_ERR_HANDLER(LOS_ERRNO_SEM_ALL_BUSY);
|
||||
}
|
||||
|
||||
unusedSem = LOS_DL_LIST_FIRST(&(g_unusedSemList));
|
||||
LOS_ListDelete(unusedSem);
|
||||
semCreated = (GET_SEM_LIST(unusedSem));
|
||||
semCreated->semCount = count;
|
||||
semCreated->semStat = OS_SEM_USED;
|
||||
semCreated->maxSemCount = maxCount;
|
||||
LOS_ListInit(&semCreated->semList);
|
||||
*semHandle = (UINT32)semCreated->semID;
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_OK;
|
||||
|
||||
ERR_HANDLER:
|
||||
OS_RETURN_ERROR_P2(errLine, errNo);
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : LOS_SemCreate
|
||||
Description : Create a semaphore
|
||||
Input : count--------- semaphore count
|
||||
Output : semHandle-----Index of semaphore
|
||||
Return : LOS_OK on success, or error code on failure
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 LOS_SemCreate(UINT16 count, UINT32 *semHandle)
|
||||
{
|
||||
return OsSemCreate(count, OS_SEM_COUNTING_MAX_COUNT, semHandle);
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : LOS_BinarySemCreate
|
||||
Description : Create a binary semaphore
|
||||
Input : count--------- semaphore count
|
||||
Output : semHandle-----Index of semaphore
|
||||
Return : LOS_OK on success, or error code on failure
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 LOS_BinarySemCreate(UINT16 count, UINT32 *semHandle)
|
||||
{
|
||||
return OsSemCreate(count, OS_SEM_BINARY_MAX_COUNT, semHandle);
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : LOS_SemDelete
|
||||
Description : Delete a semaphore
|
||||
Input : semHandle--------- semaphore operation handle
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 LOS_SemDelete(UINT32 semHandle)
|
||||
{
|
||||
UINT32 intSave;
|
||||
LosSemCB *semDeleted = NULL;
|
||||
UINT32 errNo;
|
||||
UINT32 errLine;
|
||||
|
||||
if (semHandle >= (UINT32)LOSCFG_BASE_IPC_SEM_LIMIT) {
|
||||
OS_GOTO_ERR_HANDLER(LOS_ERRNO_SEM_INVALID);
|
||||
}
|
||||
|
||||
semDeleted = GET_SEM(semHandle);
|
||||
intSave = LOS_IntLock();
|
||||
if (semDeleted->semStat == OS_SEM_UNUSED) {
|
||||
LOS_IntRestore(intSave);
|
||||
OS_GOTO_ERR_HANDLER(LOS_ERRNO_SEM_INVALID);
|
||||
}
|
||||
|
||||
if (!LOS_ListEmpty(&semDeleted->semList)) {
|
||||
LOS_IntRestore(intSave);
|
||||
OS_GOTO_ERR_HANDLER(LOS_ERRNO_SEM_PENDED);
|
||||
}
|
||||
|
||||
LOS_ListAdd(&g_unusedSemList, &semDeleted->semList);
|
||||
semDeleted->semStat = OS_SEM_UNUSED;
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_OK;
|
||||
ERR_HANDLER:
|
||||
OS_RETURN_ERROR_P2(errLine, errNo);
|
||||
}
|
||||
|
||||
STATIC_INLINE UINT32 OsSemValidCheck(LosSemCB *semPended)
|
||||
{
|
||||
if (semPended->semStat == OS_SEM_UNUSED) {
|
||||
return LOS_ERRNO_SEM_INVALID;
|
||||
}
|
||||
|
||||
if (OS_INT_ACTIVE) {
|
||||
PRINT_ERR("!!!LOS_ERRNO_SEM_PEND_INTERR!!!\n");
|
||||
#if (LOSCFG_PLATFORM_EXC == YES)
|
||||
OsBackTrace();
|
||||
#endif
|
||||
return LOS_ERRNO_SEM_PEND_INTERR;
|
||||
}
|
||||
|
||||
if (g_losTaskLock) {
|
||||
PRINT_ERR("!!!LOS_ERRNO_SEM_PEND_IN_LOCK!!!\n");
|
||||
#if (LOSCFG_PLATFORM_EXC == YES)
|
||||
OsBackTrace();
|
||||
#endif
|
||||
return LOS_ERRNO_SEM_PEND_IN_LOCK;
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : LOS_SemPend
|
||||
Description : Specified semaphore P operation
|
||||
Input : semHandle --------- semaphore operation handle
|
||||
: timeout --------- waitting time
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT UINT32 LOS_SemPend(UINT32 semHandle, UINT32 timeout)
|
||||
{
|
||||
UINT32 intSave;
|
||||
LosSemCB *semPended = NULL;
|
||||
UINT32 retErr;
|
||||
LosTaskCB *runningTask = NULL;
|
||||
|
||||
if (semHandle >= (UINT32)LOSCFG_BASE_IPC_SEM_LIMIT) {
|
||||
OS_RETURN_ERROR(LOS_ERRNO_SEM_INVALID);
|
||||
}
|
||||
|
||||
semPended = GET_SEM(semHandle);
|
||||
intSave = LOS_IntLock();
|
||||
|
||||
retErr = OsSemValidCheck(semPended);
|
||||
if (retErr) {
|
||||
goto ERROR_SEM_PEND;
|
||||
}
|
||||
|
||||
if (semPended->semCount > 0) {
|
||||
semPended->semCount--;
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
if (!timeout) {
|
||||
retErr = LOS_ERRNO_SEM_UNAVAILABLE;
|
||||
goto ERROR_SEM_PEND;
|
||||
}
|
||||
|
||||
runningTask = (LosTaskCB *)g_losTask.runTask;
|
||||
runningTask->taskSem = (VOID *)semPended;
|
||||
OsTaskWait(&semPended->semList, OS_TASK_STATUS_PEND, timeout);
|
||||
LOS_IntRestore(intSave);
|
||||
LOS_Schedule();
|
||||
|
||||
if (runningTask->taskStatus & OS_TASK_STATUS_TIMEOUT) {
|
||||
intSave = LOS_IntLock();
|
||||
runningTask->taskStatus &= (~OS_TASK_STATUS_TIMEOUT);
|
||||
retErr = LOS_ERRNO_SEM_TIMEOUT;
|
||||
goto ERROR_SEM_PEND;
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
|
||||
ERROR_SEM_PEND:
|
||||
LOS_IntRestore(intSave);
|
||||
OS_RETURN_ERROR(retErr);
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : LOS_SemPost
|
||||
Description : Specified semaphore V operation
|
||||
Input : semHandle--------- semaphore operation handle
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT UINT32 LOS_SemPost(UINT32 semHandle)
|
||||
{
|
||||
UINT32 intSave;
|
||||
LosSemCB *semPosted = GET_SEM(semHandle);
|
||||
LosTaskCB *resumedTask = NULL;
|
||||
|
||||
if (semHandle >= LOSCFG_BASE_IPC_SEM_LIMIT) {
|
||||
return LOS_ERRNO_SEM_INVALID;
|
||||
}
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
|
||||
if (semPosted->semStat == OS_SEM_UNUSED) {
|
||||
LOS_IntRestore(intSave);
|
||||
OS_RETURN_ERROR(LOS_ERRNO_SEM_INVALID);
|
||||
}
|
||||
|
||||
if (semPosted->maxSemCount == semPosted->semCount) {
|
||||
LOS_IntRestore(intSave);
|
||||
OS_RETURN_ERROR(LOS_ERRNO_SEM_OVERFLOW);
|
||||
}
|
||||
if (!LOS_ListEmpty(&semPosted->semList)) {
|
||||
resumedTask = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&(semPosted->semList)));
|
||||
resumedTask->taskSem = NULL;
|
||||
OsTaskWake(resumedTask, OS_TASK_STATUS_PEND);
|
||||
|
||||
LOS_IntRestore(intSave);
|
||||
LOS_Schedule();
|
||||
} else {
|
||||
semPosted->semCount++;
|
||||
LOS_IntRestore(intSave);
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
#endif /* (LOSCFG_BASE_IPC_SEM == YES) */
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
|
@ -0,0 +1,202 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include "securec.h"
|
||||
#include "los_hwi.h"
|
||||
#include "los_typedef.h"
|
||||
#include "los_membox.h"
|
||||
#include "los_memory.h"
|
||||
#include "los_memcheck_pri.h"
|
||||
|
||||
#if (LOSCFG_PLATFORM_EXC == YES) || (LOSCFG_BASE_MEM_NODE_INTEGRITY_CHECK == YES)
|
||||
UINT8 g_memMang[MEM_INFO_SIZE];
|
||||
#endif
|
||||
|
||||
UINT32 LOS_MemboxInit(VOID *boxMem, UINT32 boxSize, UINT32 blkSize)
|
||||
{
|
||||
UINTPTR intSave;
|
||||
#ifdef LOS_MEMBOX_CHECK
|
||||
UINT32 *memCount = (UINT32 *)g_memMang;
|
||||
MEM_INFO *memInfo = (MEM_INFO *)(g_memMang + sizeof(UINT32));
|
||||
UINT8 loop;
|
||||
#endif
|
||||
|
||||
if (boxMem == NULL) {
|
||||
return OS_ERROR;
|
||||
}
|
||||
|
||||
/* Initialize memory block system, returns 0 if OK, 1 if fails. */
|
||||
if (blkSize == 0) {
|
||||
return OS_ERROR;
|
||||
}
|
||||
if (boxSize == 0) {
|
||||
return OS_ERROR;
|
||||
}
|
||||
|
||||
#ifdef LOS_MEMBOX_CHECK
|
||||
intSave = LOS_IntLock();
|
||||
for (loop = 0; loop < *memCount; loop++) {
|
||||
if (memInfo->uwStartAddr == (UINTPTR)boxMem) {
|
||||
(*memCount)--;
|
||||
break;
|
||||
}
|
||||
memInfo++;
|
||||
}
|
||||
if (*memCount < OS_SYS_MEM_NUM) {
|
||||
memInfo->uwType = MEM_MANG_MEMBOX;
|
||||
memInfo->uwStartAddr = (UINTPTR)boxMem;
|
||||
memInfo->uwSize = boxSize;
|
||||
UINT32 allocSize = boxSize / blkSize * sizeof(VOID *);
|
||||
VOID *ptr = LOS_MemAlloc(m_aucSysMem0, allocSize);
|
||||
if (ptr == NULL) {
|
||||
PRINT_ERR("LOS_MemAlloc return fail!\n");
|
||||
return LOS_NOK;
|
||||
} else {
|
||||
UINT32 ret = memset_s(ptr, allocSize, 0, allocSize);
|
||||
if (ret != LOS_OK) {
|
||||
(VOID)LOS_MemFree(m_aucSysMem0, ptr);
|
||||
PRINT_ERR("memset return fail!\n");
|
||||
return LOS_NOK;
|
||||
}
|
||||
}
|
||||
memInfo->blkAddrArray = ptr;
|
||||
(*memCount)++;
|
||||
}
|
||||
LOS_IntRestore(intSave);
|
||||
#endif
|
||||
|
||||
/* Create a Memory structure. */
|
||||
intSave = LOS_IntLock();
|
||||
((OS_MEMBOX_S_P)boxMem)->uwMaxBlk = boxSize / blkSize;
|
||||
((OS_MEMBOX_S_P)boxMem)->uwBlkSize = blkSize;
|
||||
((OS_MEMBOX_S_P)boxMem)->uwBlkCnt = 0;
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/* --------------------------- LOS_MemboxAlloc ---------------------------------- */
|
||||
VOID *LOS_MemboxAlloc(VOID *boxMem)
|
||||
{
|
||||
VOID *ret = NULL;
|
||||
UINTPTR intSave;
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
if (((OS_MEMBOX_S_P)boxMem)->uwBlkCnt < ((OS_MEMBOX_S_P)boxMem)->uwMaxBlk) {
|
||||
ret = LOS_MemAlloc(m_aucSysMem0, ((OS_MEMBOX_S_P)boxMem)->uwBlkSize);
|
||||
if (ret != NULL) {
|
||||
((OS_MEMBOX_S_P)boxMem)->uwBlkCnt++;
|
||||
#ifdef LOS_MEMBOX_CHECK
|
||||
UINT32 *memCount = (UINT32 *)g_memMang;
|
||||
MEM_INFO *memInfo = (MEM_INFO *)(VOID *)(g_memMang + sizeof(UINT32));
|
||||
UINT8 loop;
|
||||
UINT8 idx;
|
||||
for (loop = 0; loop < *memCount; loop++) {
|
||||
if (memInfo->uwStartAddr == (UINTPTR)boxMem) {
|
||||
if (memInfo->blkAddrArray != NULL) {
|
||||
for (idx = 0; idx < ((OS_MEMBOX_S_P)boxMem)->uwMaxBlk; idx++) {
|
||||
if (((VOID **)(memInfo->blkAddrArray))[idx] == NULL) {
|
||||
((VOID **)(memInfo->blkAddrArray))[idx] = ret;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
memInfo++;
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
PRINT_ERR("LOS_AllocMem return fail!\n");
|
||||
}
|
||||
}
|
||||
LOS_IntRestore(intSave);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* --------------------------- LOS_MemboxFree ---------------------------------- */
|
||||
UINT32 LOS_MemboxFree(const VOID *boxMem, VOID *box)
|
||||
{
|
||||
UINT32 freeRes;
|
||||
UINTPTR intSave;
|
||||
|
||||
freeRes = LOS_MemFree(m_aucSysMem0, box);
|
||||
if (freeRes == LOS_OK) {
|
||||
intSave = LOS_IntLock();
|
||||
if (((OS_MEMBOX_S_P)boxMem)->uwBlkCnt) {
|
||||
((OS_MEMBOX_S_P)boxMem)->uwBlkCnt--;
|
||||
#ifdef LOS_MEMBOX_CHECK
|
||||
UINT32 *memCount = (UINT32 *)g_memMang;
|
||||
MEM_INFO *memInfo = (MEM_INFO *)(VOID *)(g_memMang + sizeof(UINT32));
|
||||
UINT8 loop;
|
||||
UINT8 idx;
|
||||
for (loop = 0; loop < *memCount; loop++) {
|
||||
if (memInfo->uwStartAddr == (UINTPTR)boxMem) {
|
||||
if (memInfo->blkAddrArray != NULL) {
|
||||
for (idx = 0; idx < ((OS_MEMBOX_S_P)boxMem)->uwMaxBlk; idx++) {
|
||||
if (((VOID **)(memInfo->blkAddrArray))[idx] == box) {
|
||||
((VOID **)(memInfo->blkAddrArray))[idx] = NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
memInfo++;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
LOS_IntRestore(intSave);
|
||||
}
|
||||
return freeRes;
|
||||
}
|
||||
|
||||
/* --------------------------- LOS_MemboxClr ---------------------------------- */
|
||||
VOID LOS_MemboxClr(const VOID *boxMem, VOID *box)
|
||||
{
|
||||
// Ignore the return code when matching CSEC rule 6.6(2).
|
||||
(VOID)memset_s(box, ((OS_MEMBOX_S_P)boxMem)->uwBlkSize, 0, ((OS_MEMBOX_S_P)boxMem)->uwBlkSize);
|
||||
}
|
||||
|
||||
UINT32 LOS_MemboxStatisticsGet(const VOID *boxMem, UINT32 *maxBlk, UINT32 *blkCnt, UINT32 *blkSize)
|
||||
{
|
||||
if ((boxMem == NULL) || (maxBlk == NULL) || (blkCnt == NULL) || (blkSize == NULL)) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
*maxBlk = ((OS_MEMBOX_S_P)boxMem)->uwMaxBlk;
|
||||
*blkCnt = ((OS_MEMBOX_S_P)boxMem)->uwBlkCnt;
|
||||
*blkSize = ((OS_MEMBOX_S_P)boxMem)->uwBlkSize;
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
|
@ -0,0 +1,138 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#include "los_memcheck.h"
|
||||
#include "los_memory_pri.h"
|
||||
#include "los_membox_pri.h"
|
||||
#include "los_multipledlinkhead_pri.h"
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
|
||||
#if LOSCFG_PLATFORM_EXC == YES
|
||||
extern UINT8 g_memMang[MEM_INFO_SIZE];
|
||||
/*****************************************************************************
|
||||
Function : LOS_MemExcInfoGet
|
||||
Description : Get the information of the exc memory
|
||||
Input : uwMemNum
|
||||
Output : pstMemExcInfo
|
||||
Return : return 0
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_MemExcInfoGet(UINT32 memNum, MEM_INFO_S *memExcInfo)
|
||||
{
|
||||
UINT32 idx = 0;
|
||||
UINT32 maxBlk = 0;
|
||||
UINT32 blkCnt = 0;
|
||||
UINT32 blkSize = 0;
|
||||
MEM_INFO *memInfo = NULL;
|
||||
LosMemDynNode *pstTmpNode = (LosMemDynNode *)NULL;
|
||||
LOS_MEM_POOL_INFO *pPool = (LOS_MEM_POOL_INFO *)NULL;
|
||||
LOS_MEM_POOL_INFO *pstPoolInfo = (LOS_MEM_POOL_INFO *)NULL;
|
||||
UINT8 *pEndPool = NULL;
|
||||
|
||||
if (memNum >= *(UINT32 *)g_memMang || memExcInfo == NULL) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
memInfo = (MEM_INFO *)(VOID *)(g_memMang + sizeof(UINT32)) + memNum;
|
||||
memExcInfo->uwType = memInfo->uwType;
|
||||
memExcInfo->uwStartAddr = memInfo->uwStartAddr;
|
||||
memExcInfo->uwSize = memInfo->uwSize;
|
||||
memExcInfo->uwFree = 0;
|
||||
memExcInfo->uwBlockSize = 0;
|
||||
memExcInfo->uwErrorAddr = 0;
|
||||
memExcInfo->uwErrorLen = 0;
|
||||
memExcInfo->uwErrorOwner = 0;
|
||||
|
||||
if (memInfo->uwType == MEM_MANG_MEMBOX) {
|
||||
(VOID)LOS_MemboxStatisticsGet((VOID *)(memInfo->uwStartAddr), &maxBlk, &blkCnt, &blkSize);
|
||||
memExcInfo->uwBlockSize = blkSize;
|
||||
memExcInfo->uwSize = maxBlk; // Block num
|
||||
memExcInfo->uwFree = maxBlk - blkCnt;
|
||||
pPool = (LOS_MEM_POOL_INFO *)m_aucSysMem0;
|
||||
pstPoolInfo = pPool;
|
||||
pEndPool = (UINT8 *)pPool + pstPoolInfo->uwPoolSize;
|
||||
while (memInfo->blkAddrArray != NULL && idx < maxBlk) {
|
||||
char *tmpPtr = ((char **)(memInfo->blkAddrArray))[idx];
|
||||
if (tmpPtr != NULL) {
|
||||
pstTmpNode = (LosMemDynNode *)(tmpPtr - OS_MEM_NODE_HEAD_SIZE);
|
||||
if (!OS_MEM_MAGIC_VALID(pstTmpNode->freeNodeInfo.pstPrev)) {
|
||||
goto errout;
|
||||
}
|
||||
}
|
||||
idx++;
|
||||
}
|
||||
} else if (memInfo->uwType == MEM_MANG_MEMORY) {
|
||||
memExcInfo->uwFree = memInfo->uwSize - LOS_MemTotalUsedGet((VOID *)(memInfo->uwStartAddr)) - OS_DLNK_HEAD_SIZE
|
||||
- LOS_MemFreeBlksGet((VOID *)(memInfo->uwStartAddr)) * OS_MEM_NODE_HEAD_SIZE - sizeof(LOS_MEM_POOL_INFO);
|
||||
|
||||
memExcInfo->uwBlockSize = 0;
|
||||
pPool = (LOS_MEM_POOL_INFO *)memInfo->uwStartAddr;
|
||||
if (pPool == NULL) {
|
||||
return LOS_OK;
|
||||
}
|
||||
pstPoolInfo = pPool;
|
||||
pEndPool = (UINT8 *)pPool + pstPoolInfo->uwPoolSize;
|
||||
|
||||
for (pstTmpNode = (LosMemDynNode *)OS_MEM_FIRST_NODE(pPool); pstTmpNode < (LosMemDynNode *)OS_MEM_END_NODE(pPool, pstPoolInfo->uwPoolSize);
|
||||
pstTmpNode = (LosMemDynNode *)OS_MEM_NEXT_NODE(pstTmpNode)) {
|
||||
memExcInfo->uwBlockSize++;
|
||||
if (OS_MEM_NODE_GET_USED_FLAG(pstTmpNode->sizeAndFlag)) {
|
||||
if (!OS_MEM_MAGIC_VALID(pstTmpNode->freeNodeInfo.pstPrev)) {
|
||||
goto errout;
|
||||
}
|
||||
}
|
||||
else { //is free node, check free node range
|
||||
if (!OS_MEM_MIDDLE_ADDR_OPEN_END(pPool, pstTmpNode->freeNodeInfo.pstPrev, pEndPool)) {
|
||||
goto errout;
|
||||
}
|
||||
if (!OS_MEM_MIDDLE_ADDR_OPEN_END(pPool, pstTmpNode->freeNodeInfo.pstNext, pEndPool)) {
|
||||
goto errout;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return LOS_OK;
|
||||
errout:
|
||||
memExcInfo->uwErrorAddr = (UINT32)(UINTPTR)((char*)pstTmpNode + OS_MEM_NODE_HEAD_SIZE);
|
||||
memExcInfo->uwErrorLen = (UINT32)OS_MEM_NODE_GET_SIZE(pstTmpNode->sizeAndFlag) - OS_MEM_NODE_HEAD_SIZE;
|
||||
memExcInfo->uwErrorOwner = (UINT32)(UINTPTR)(pstTmpNode->freeNodeInfo.pstNext);
|
||||
return LOS_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#include "los_memstat_pri.h"
|
||||
#include "los_task_pri.h"
|
||||
#include "los_config.h"
|
||||
|
||||
typedef struct {
|
||||
UINT32 memUsed;
|
||||
} TskMemUsedInfo;
|
||||
|
||||
LITE_OS_SEC_BSS_MINOR TskMemUsedInfo g_tskMemUsedInfo[LOSCFG_BASE_CORE_TSK_LIMIT + 1];
|
||||
|
||||
LITE_OS_SEC_TEXT_MINOR VOID OsTaskMemUsedInc(UINT32 usedSize, UINT32 taskID)
|
||||
{
|
||||
if (taskID > LOSCFG_BASE_CORE_TSK_LIMIT) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (OS_INT_ACTIVE) {
|
||||
return;
|
||||
}
|
||||
g_tskMemUsedInfo[taskID].memUsed += usedSize;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_MINOR VOID OsTaskMemUsedDec(UINT32 usedSize, UINT32 taskID)
|
||||
{
|
||||
if (taskID > LOSCFG_BASE_CORE_TSK_LIMIT) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (OS_INT_ACTIVE) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (g_tskMemUsedInfo[taskID].memUsed < usedSize) {
|
||||
PRINT_INFO("mem used of current task '%s':0x%x, decrease size:0x%x\n",
|
||||
g_losTask.runTask->taskName, g_tskMemUsedInfo[taskID].memUsed, usedSize);
|
||||
return;
|
||||
}
|
||||
|
||||
g_tskMemUsedInfo[taskID].memUsed -= usedSize;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_MINOR UINT32 OsTaskMemUsage(UINT32 taskId)
|
||||
{
|
||||
if ((UINT32)taskId > LOSCFG_BASE_CORE_TSK_LIMIT) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
return g_tskMemUsedInfo[(UINT32)taskId].memUsed;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_MINOR VOID OsTaskMemClear(UINT32 taskID)
|
||||
{
|
||||
if (taskID > LOSCFG_BASE_CORE_TSK_LIMIT) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (g_tskMemUsedInfo[taskID].memUsed != 0) {
|
||||
PRINT_INFO("mem used of task '%s' is:0x%x, not zero when task being deleted\n",
|
||||
g_losTask.runTask->taskName, g_tskMemUsedInfo[taskID].memUsed);
|
||||
}
|
||||
g_tskMemUsedInfo[taskID].memUsed = 0;
|
||||
return;
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#include "los_multipledlinkhead_pri.h"
|
||||
#include "los_compiler.h"
|
||||
|
||||
#define OS_BITS_PER_BYTE 8
|
||||
STATIC_INLINE UINT32 OsLog2(UINT32 size)
|
||||
{
|
||||
return size ? ((sizeof(size) * OS_BITS_PER_BYTE) - CLZ(size) - 1) : 0;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_INIT VOID OsDLnkInitMultiHead(VOID *headAddr)
|
||||
{
|
||||
LosMultipleDlinkHead *head = (LosMultipleDlinkHead *)headAddr;
|
||||
LOS_DL_LIST *listHead = head->listHead;
|
||||
UINT32 idx;
|
||||
|
||||
for (idx = 0; idx < OS_MULTI_DLNK_NUM; ++idx, ++listHead) {
|
||||
LOS_ListInit(listHead);
|
||||
}
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_MINOR LOS_DL_LIST *OsDLnkMultiHead(VOID *headAddr, UINT32 size)
|
||||
{
|
||||
LosMultipleDlinkHead *head = (LosMultipleDlinkHead *)headAddr;
|
||||
UINT32 idx = OsLog2(size);
|
||||
|
||||
if (idx > OS_MAX_MULTI_DLNK_LOG2) {
|
||||
return (LOS_DL_LIST *)NULL;
|
||||
}
|
||||
|
||||
if (idx <= OS_MIN_MULTI_DLNK_LOG2) {
|
||||
idx = OS_MIN_MULTI_DLNK_LOG2;
|
||||
}
|
||||
|
||||
return head->listHead + (idx - OS_MIN_MULTI_DLNK_LOG2);
|
||||
}
|
|
@ -0,0 +1,390 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include "securec.h"
|
||||
#include "los_slab_pri.h"
|
||||
#include "los_heap_pri.h"
|
||||
|
||||
#define LOW_BITS_MASK 31
|
||||
#define NUM_BITS_IN_ONE_BYTE 32
|
||||
#define NUMBITS_TO_NUMBYTES(numBits) (((numBits) + LOW_BITS_MASK) / 8)
|
||||
|
||||
VOID OsAtomicBitsetInit(struct AtomicBitset *set, UINT32 numBits)
|
||||
{
|
||||
set->numBits = numBits;
|
||||
// Ignore the return code when matching CSEC rule 6.6(2).
|
||||
(VOID)memset_s(set->words, NUMBITS_TO_NUMBYTES(numBits), 0, NUMBITS_TO_NUMBYTES(numBits));
|
||||
// mark all high bits so that OsAtomicBitsetFindClearAndSet() is simpler
|
||||
if (numBits & LOW_BITS_MASK) {
|
||||
set->words[numBits / NUM_BITS_IN_ONE_BYTE] =
|
||||
((UINT32)((INT32) - 1LL)) << (numBits & LOW_BITS_MASK);
|
||||
}
|
||||
}
|
||||
|
||||
inline UINT32 OsAtomicBitsetGetNumBits(const struct AtomicBitset *set)
|
||||
{
|
||||
return set->numBits;
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
Function : OsAtomicBitsetGetBit
|
||||
Description : get the specified bit in set
|
||||
Input : set --- pointer to the bitset
|
||||
num --- the num to fetch
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
**************************************************************************/
|
||||
BOOL OsAtomicBitsetGetBit(const struct AtomicBitset *set, UINT32 num)
|
||||
{
|
||||
/* any value is as good as the next */
|
||||
if (num >= set->numBits) {
|
||||
return FALSE;
|
||||
}
|
||||
return !!((set->words[num / NUM_BITS_IN_ONE_BYTE]) & (1UL << (num & LOW_BITS_MASK)));
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
Function : OsAtomicBitsetClearBit
|
||||
Description : clear the specified bit in set
|
||||
Input : set --- pointer to the bitset
|
||||
num --- the num to clear
|
||||
Output : None
|
||||
Return : None
|
||||
**************************************************************************/
|
||||
VOID OsAtomicBitsetClearBit(struct AtomicBitset *set, UINT32 num)
|
||||
{
|
||||
UINT32 *wordPtr = set->words + (num / NUM_BITS_IN_ONE_BYTE);
|
||||
|
||||
if (num >= set->numBits) {
|
||||
return;
|
||||
}
|
||||
(*wordPtr) &= ~(1UL << (num & LOW_BITS_MASK));
|
||||
}
|
||||
|
||||
/* find from the high bit to high bit return the address of the first available bit */
|
||||
INT32 OsAtomicBitsetFindClearAndSet(struct AtomicBitset *set)
|
||||
{
|
||||
UINT32 idx;
|
||||
UINT32 numWords = (set->numBits + LOW_BITS_MASK) / NUM_BITS_IN_ONE_BYTE;
|
||||
UINT32 *wordPtr = set->words;
|
||||
UINT32 tmpWord;
|
||||
INT32 count = 0;
|
||||
|
||||
for (idx = 0; idx < numWords; idx++, wordPtr++) {
|
||||
if (*wordPtr == 0xFFFFFFFF) {
|
||||
continue;
|
||||
}
|
||||
|
||||
tmpWord = ~(*wordPtr);
|
||||
|
||||
while (tmpWord) {
|
||||
tmpWord = tmpWord >> 1UL;
|
||||
count++;
|
||||
}
|
||||
|
||||
*wordPtr |= (1UL << (count - 1));
|
||||
|
||||
return (INT32)(idx * NUM_BITS_IN_ONE_BYTE + count - 1);
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* change the order of the output idx of OsAtomicBitsetFindClearAndSet to order of natural numbers */
|
||||
INT32 OsAtomicBitsetIdxChgToNatural(struct AtomicBitset *bitset, INT32 index)
|
||||
{
|
||||
UINT32 ret;
|
||||
UINT32 bit;
|
||||
if (index < 0) {
|
||||
return index;
|
||||
}
|
||||
bit = LOW_BITS_MASK + (index & ~LOW_BITS_MASK);
|
||||
if (bit > bitset->numBits - 1) {
|
||||
bit = bitset->numBits - 1;
|
||||
}
|
||||
ret = bit - (index & LOW_BITS_MASK);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
Function : OsAtomicBitsetEmpty
|
||||
Description : check whether bitset is empty
|
||||
Input : bitset --- pointer to the bitset
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
**************************************************************************/
|
||||
BOOL OsAtomicBitsetEmpty(struct AtomicBitset *bitset)
|
||||
{
|
||||
UINT32 idx = 0;
|
||||
for (idx = 0; idx < (bitset->numBits / NUM_BITS_IN_ONE_BYTE);) {
|
||||
if (bitset->words[idx] != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
idx++;
|
||||
}
|
||||
if (bitset->numBits & LOW_BITS_MASK) {
|
||||
if (bitset->words[idx] & ~(0xFFFFFFFF << (bitset->numBits & LOW_BITS_MASK))) {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
Function : OsSlabAllocatorNew
|
||||
Description : create a new allocator
|
||||
Input : pool --- pointer to the pool
|
||||
itemSz --- alloc size
|
||||
itemAlign --- aligned size
|
||||
numItems --- item num
|
||||
Output : None
|
||||
Return : the pointer to a new allocator
|
||||
**************************************************************************/
|
||||
OsSlabAllocator* OsSlabAllocatorNew(VOID *pool, UINT32 itemSz, UINT32 itemAlign, UINT32 numItems)
|
||||
{
|
||||
OsSlabAllocator *allocator = NULL;
|
||||
UINT32 bitSetSz;
|
||||
UINT32 dataSz;
|
||||
UINT32 itemSize;
|
||||
|
||||
/* calculate size */
|
||||
bitSetSz = ATOMIC_BITSET_SZ(numItems);
|
||||
|
||||
bitSetSz = (bitSetSz + itemAlign - 1) & (~(itemAlign - 1));
|
||||
itemSize = (itemSz + itemAlign - 1) & (~(itemAlign - 1));
|
||||
dataSz = itemSize * numItems;
|
||||
|
||||
allocator = (OsSlabAllocator*)LOS_HeapAlloc(pool, sizeof(OsSlabAllocator) + bitSetSz + dataSz);
|
||||
|
||||
if (allocator != NULL) {
|
||||
allocator->itemSz = itemSize;
|
||||
|
||||
allocator->bitset = (struct AtomicBitset *)(VOID *)((UINT8*)allocator + sizeof(OsSlabAllocator));
|
||||
allocator->dataChunks = ((UINT8*)allocator->bitset) + bitSetSz;
|
||||
OsAtomicBitsetInit(allocator->bitset, numItems);
|
||||
}
|
||||
|
||||
return allocator;
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
Function : OsSlabAllocatorDestroy
|
||||
Description : free the specified allocator
|
||||
Input : pool --- pointer to the pool
|
||||
allocator --- pointer to the allocator
|
||||
Output : None
|
||||
Return : None
|
||||
**************************************************************************/
|
||||
VOID OsSlabAllocatorDestroy(VOID *pool, OsSlabAllocator *allocator)
|
||||
{
|
||||
(VOID)LOS_HeapFree(pool, allocator);
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
Function : OsSlabAllocatorAlloc
|
||||
Description : alloc one bit from the specified allocator
|
||||
Input : allocator --- pointer to the allocator
|
||||
Output : None
|
||||
Return : NULL on failure or one bit from the specified allocator
|
||||
**************************************************************************/
|
||||
VOID* OsSlabAllocatorAlloc(OsSlabAllocator *allocator)
|
||||
{
|
||||
INT32 itemIdx = OsAtomicBitsetFindClearAndSet(allocator->bitset);
|
||||
if (itemIdx < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return allocator->dataChunks + allocator->itemSz * itemIdx;
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
Function : OsSlabAllocatorFree
|
||||
Description : free the specified bit in the specified allocator
|
||||
Input : allocator --- pointer to the allocator
|
||||
ptr --- pointer to the mem chunk to be freed
|
||||
Output : None
|
||||
Return : TRUE or FALSE
|
||||
**************************************************************************/
|
||||
BOOL OsSlabAllocatorFree(OsSlabAllocator *allocator, VOID* ptr)
|
||||
{
|
||||
UINT8 *ptrTmp = (UINT8*)ptr;
|
||||
UINT32 itemOffset = ptrTmp - allocator->dataChunks;
|
||||
UINT32 itemIdx = itemOffset / allocator->itemSz;
|
||||
|
||||
// check for invalid inputs
|
||||
if ((itemOffset % allocator->itemSz) || (itemIdx >= OsAtomicBitsetGetNumBits(allocator->bitset)) ||
|
||||
!(OsAtomicBitsetGetBit(allocator->bitset, itemIdx))) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
OsAtomicBitsetClearBit(allocator->bitset, itemIdx);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
Function : OsSlabAllocatorGetNth
|
||||
Description : get the specified data chunk from the allocator
|
||||
Input : allocator --- pointer to the allocator
|
||||
idx --- chunk num
|
||||
Output : None
|
||||
Return : NULL on failure or specified data chunk on success
|
||||
**************************************************************************/
|
||||
VOID* OsSlabAllocatorGetNth(OsSlabAllocator *allocator, UINT32 idx)
|
||||
{
|
||||
if (!OsAtomicBitsetGetBit(allocator->bitset, idx)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return allocator->dataChunks + allocator->itemSz * idx;
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
Function : OsSlabAllocatorGetIdxP
|
||||
Description : get the specified dataChunk from the specified allocator
|
||||
Input : allocator --- pointer to the allocator
|
||||
idx --- chunk num
|
||||
Output : None
|
||||
Return : the specified data Chunk from the specified allocator
|
||||
**************************************************************************/
|
||||
VOID* OsSlabAllocatorGetIdxP(OsSlabAllocator *allocator, UINT32 idx)
|
||||
{
|
||||
return allocator->dataChunks + allocator->itemSz * idx;
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
Function : OsSlabAllocatorGetIndex
|
||||
Description : get item index from the specified allocator
|
||||
Input : allocator --- pointer to the allocator
|
||||
ptr --- pointer to the mem chunk to get index
|
||||
Output : None
|
||||
Return : the item index from the specified allocator
|
||||
**************************************************************************/
|
||||
UINT32 OsSlabAllocatorGetIndex(OsSlabAllocator *allocator, VOID* ptr)
|
||||
{
|
||||
UINT8 *ptrTmp = (UINT8*)ptr;
|
||||
UINT32 itemOffset = ptrTmp - allocator->dataChunks;
|
||||
UINT32 itemIdx = itemOffset / allocator->itemSz;
|
||||
|
||||
if ((itemOffset % allocator->itemSz) ||
|
||||
(itemIdx >= OsAtomicBitsetGetNumBits(allocator->bitset)) ||
|
||||
!(OsAtomicBitsetGetBit(allocator->bitset, itemIdx))) {
|
||||
return (UINT32)(-1);
|
||||
}
|
||||
|
||||
return itemIdx;
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
Function : OsSlabAllocatorGetNumItems
|
||||
Description : get num bits of the specified allocator
|
||||
Input : allocator --- pointer to the allocator
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
**************************************************************************/
|
||||
UINT32 OsSlabAllocatorGetNumItems(OsSlabAllocator *allocator)
|
||||
{
|
||||
return OsAtomicBitsetGetNumBits(allocator->bitset);
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
Function : OsSlabAllocatorEmpty
|
||||
Description : check whether the allocator is empty
|
||||
Input : allocator --- pointer to the allocator
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
**************************************************************************/
|
||||
BOOL OsSlabAllocatorEmpty(OsSlabAllocator *allocator)
|
||||
{
|
||||
return OsAtomicBitsetEmpty(allocator->bitset);
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
Function : OsSlabAllocatorGetUsedItemCnt
|
||||
Description : get used num of the specified allocator
|
||||
Input : allocator --- pointer to the allocator
|
||||
Output : None
|
||||
Return : used num of the specifiedd allocator
|
||||
**************************************************************************/
|
||||
UINT32 OsSlabAllocatorGetUsedItemCnt(OsSlabAllocator *allocator)
|
||||
{
|
||||
UINT32 used;
|
||||
UINT32 idx;
|
||||
struct AtomicBitset *bitset = allocator->bitset;
|
||||
for (used = 0, idx = 0; idx < bitset->numBits; idx++) {
|
||||
if (OsAtomicBitsetGetBit(bitset, idx)) {
|
||||
used++;
|
||||
}
|
||||
}
|
||||
return used;
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
Function : OsSlabAllocatorGetSlabInfo
|
||||
Description : get slab info from the specified allocator
|
||||
Input : allocator --- pointer to the allocator
|
||||
Output : pitemSz --- item size
|
||||
itemCnt --- item count
|
||||
curUsage --- current usage
|
||||
Return : None
|
||||
**************************************************************************/
|
||||
VOID OsSlabAllocatorGetSlabInfo(OsSlabAllocator *allocator, UINT32 *pitemSz, UINT32 *itemCnt, UINT32 *curUsage)
|
||||
{
|
||||
*pitemSz = allocator->itemSz;
|
||||
*itemCnt = OsAtomicBitsetGetNumBits(allocator->bitset);
|
||||
*curUsage = OsSlabAllocatorGetUsedItemCnt(allocator);
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
Function : OsSlabAllocatorCheck
|
||||
Description : check whether ptr is in allocator
|
||||
Input : allocator --- pointer to the allocator
|
||||
ptr --- pointer to the mem chunk to check
|
||||
Output : None
|
||||
Return : TRUE or FALSE
|
||||
**************************************************************************/
|
||||
BOOL OsSlabAllocatorCheck(OsSlabAllocator *allocator, VOID* ptr)
|
||||
{
|
||||
UINT8 *ptrTmp = (UINT8*)ptr;
|
||||
UINT32 itemOffset = ptrTmp - allocator->dataChunks;
|
||||
UINT32 itemIdx = itemOffset / allocator->itemSz;
|
||||
|
||||
// check for invalid inputs
|
||||
if ((itemOffset % allocator->itemSz) || (itemIdx >= OsAtomicBitsetGetNumBits(allocator->bitset)) ||
|
||||
!(OsAtomicBitsetGetBit(allocator->bitset, itemIdx))) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
@ -0,0 +1,307 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#define _LOS_SLAB_MEM_C_
|
||||
#include <los_printf.h>
|
||||
#include <los_hwi.h>
|
||||
#include <los_slab_pri.h>
|
||||
|
||||
VOID *OsSlabBlockHeadFill(OsSlabBlockNode *slabNode, UINT32 blkSz)
|
||||
{
|
||||
OS_SLAB_BLOCK_MAGIC_SET(slabNode);
|
||||
OS_SLAB_BLOCK_SIZE_SET(slabNode, blkSz);
|
||||
OS_SLAB_BLOCK_ID_SET(slabNode, 0); // now undefine how to use ID
|
||||
return (VOID *)(slabNode + 1);
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : OsSlabMemInit
|
||||
Description : To initialize the slab memory management
|
||||
Input : None
|
||||
Output : None
|
||||
Return : TRUE --- initialize OK, FALSE --- initialize false
|
||||
*****************************************************************************/
|
||||
BOOL OsSlabMemInit(VOID *pool)
|
||||
{
|
||||
struct LosSlabControlHeader *slabMemHead = OsSlabCtrlHdrGet(pool);
|
||||
UINT32 idx = 0;
|
||||
UINT32 tmp = 0;
|
||||
UINT32 blkSz = 0;
|
||||
UINT32 blkCnt = 0;
|
||||
|
||||
for (idx = 0; idx < SLAB_MEM_COUNT; idx++) {
|
||||
blkSz = (SLAB_MEM_CALSS_STEP_SIZE << idx);
|
||||
blkCnt = SLAB_MEM_ALLOCATOR_SIZE / blkSz;
|
||||
slabMemHead->slabClass[idx].blkSz = blkSz;
|
||||
slabMemHead->slabClass[idx].blkCnt = blkCnt;
|
||||
slabMemHead->slabClass[idx].blkUsedCnt = 0;
|
||||
if (slabMemHead->slabClass[idx].alloc != NULL) {
|
||||
PRINT_WARN("SlabMemAllocator[%d] inited before\n", idx);
|
||||
tmp++;
|
||||
} else {
|
||||
slabMemHead->slabClass[idx].alloc =
|
||||
OsSlabAllocatorNew(pool, blkSz + sizeof(OsSlabBlockNode), (UINT32)sizeof(VOID *), blkCnt);
|
||||
}
|
||||
}
|
||||
|
||||
return ((tmp == 0) ? TRUE : FALSE);
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : OsSlabMemAlloc
|
||||
Description : To alloc memory block
|
||||
Input : pool --- pointer to the memory pool
|
||||
size --- size of the memory we want to alloc
|
||||
Output : None
|
||||
Return : pointer :the address of the memory we alloced
|
||||
*****************************************************************************/
|
||||
VOID *OsSlabMemAlloc(VOID *pool, UINT32 size)
|
||||
{
|
||||
VOID *ret = NULL;
|
||||
UINTPTR intSave;
|
||||
struct LosSlabControlHeader *slabMem = OsSlabCtrlHdrGet(pool);
|
||||
OsSlabMem *slabAlloc = NULL;
|
||||
UINT32 idx;
|
||||
|
||||
if (size > (SLAB_MEM_CALSS_STEP_SIZE << (SLAB_MEM_COUNT - 1))) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (idx = 0; idx < SLAB_MEM_COUNT; idx++) {
|
||||
if (size <= slabMem->slabClass[idx].blkSz) {
|
||||
intSave = LOS_IntLock();
|
||||
|
||||
if (slabMem->slabClass[idx].blkUsedCnt >= slabMem->slabClass[idx].blkCnt) {
|
||||
LOS_IntRestore(intSave);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (slabMem->slabClass[idx].alloc == NULL) {
|
||||
LOS_IntRestore(intSave);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
slabAlloc = &(slabMem->slabClass[idx]);
|
||||
ret = OsSlabAllocatorAlloc(slabAlloc->alloc);
|
||||
if (ret != NULL) {
|
||||
/* alloc success */
|
||||
ret = OsSlabBlockHeadFill((OsSlabBlockNode *)ret, slabMem->slabClass[idx].blkSz);
|
||||
slabMem->slabClass[idx].blkUsedCnt++;
|
||||
}
|
||||
|
||||
LOS_IntRestore(intSave);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : OsSlabMemFree
|
||||
Description : To free the memory block
|
||||
Input : pool --- Pointer to the memory pool that contains the memory block to be allocated
|
||||
ptr --- the pointer of heap memory we want to free
|
||||
Output : None
|
||||
Return : TRUE:success FALSE:error
|
||||
*****************************************************************************/
|
||||
BOOL OsSlabMemFree(VOID *pool, VOID* ptr)
|
||||
{
|
||||
UINTPTR intSave;
|
||||
struct LosSlabControlHeader *slabMem = OsSlabCtrlHdrGet(pool);
|
||||
BOOL ret = FALSE;
|
||||
OsSlabMem *slabAlloc = NULL;
|
||||
UINT32 idx;
|
||||
OsSlabBlockNode *slabNode = OS_SLAB_BLOCK_HEAD_GET(ptr);
|
||||
|
||||
if (!OS_ALLOC_FROM_SLAB_CHECK(slabNode)) {
|
||||
return FALSE;
|
||||
}
|
||||
for (idx = 0; idx < SLAB_MEM_COUNT; idx++) {
|
||||
if (slabMem->slabClass[idx].blkSz >= OS_SLAB_BLOCK_SIZE_GET(slabNode)) {
|
||||
intSave = LOS_IntLock();
|
||||
|
||||
slabAlloc = &(slabMem->slabClass[idx]);
|
||||
if (TRUE == OsSlabAllocatorFree(slabAlloc->alloc, slabNode)) {
|
||||
ret = TRUE;
|
||||
slabMem->slabClass[idx].blkUsedCnt--;
|
||||
}
|
||||
|
||||
LOS_IntRestore(intSave);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : OsSlabMemDeinit
|
||||
Description : deinitialize the slab memory ,set back to the original status
|
||||
Input : pool --- Pointer to the memory pool
|
||||
Output : None
|
||||
Return : None
|
||||
*****************************************************************************/
|
||||
VOID OsSlabMemDeinit(VOID *pool)
|
||||
{
|
||||
UINT32 idx;
|
||||
struct LosSlabControlHeader *slabMem = NULL;
|
||||
OsSlabMem *slabAlloc = NULL;
|
||||
UINT32 blkSz;
|
||||
UINT32 blkCnt;
|
||||
|
||||
if (pool == NULL) {
|
||||
return ;
|
||||
}
|
||||
slabMem = OsSlabCtrlHdrGet(pool);
|
||||
|
||||
for (idx = 0; idx < SLAB_MEM_COUNT; idx++) {
|
||||
blkSz = (SLAB_MEM_CALSS_STEP_SIZE << idx);
|
||||
blkCnt = SLAB_MEM_ALLOCATOR_SIZE / blkSz;
|
||||
slabMem->slabClass[idx].blkSz = blkSz;
|
||||
slabMem->slabClass[idx].blkCnt = blkCnt;
|
||||
if (slabMem->slabClass[idx].alloc != NULL) {
|
||||
slabAlloc = &(slabMem->slabClass[idx]);
|
||||
OsSlabAllocatorDestroy(pool, slabAlloc->alloc);
|
||||
slabMem->slabClass[idx].alloc = NULL;
|
||||
}
|
||||
}
|
||||
return ;
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
Function : OsSlabMemCheck
|
||||
Description : check slab memory
|
||||
Input : pool --- pointer to the memory pool
|
||||
ptr --- pointer to the memory chunk
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
**************************************************************************/
|
||||
UINT32 OsSlabMemCheck(VOID *pool, VOID* ptr)
|
||||
{
|
||||
UINTPTR intSave;
|
||||
struct LosSlabControlHeader *slabMem = OsSlabCtrlHdrGet(pool);
|
||||
UINT32 retBlkSz = (UINT32)-1;
|
||||
OsSlabMem *slabAlloc = NULL;
|
||||
UINT32 idx;
|
||||
OsSlabBlockNode *slabNode = OS_SLAB_BLOCK_HEAD_GET(ptr);
|
||||
|
||||
if ((!OS_ALLOC_FROM_SLAB_CHECK(slabNode)) ||
|
||||
slabMem->slabClass[SLAB_MEM_COUNT - 1].blkSz > (OS_SLAB_BLOCK_SIZE_GET(slabNode))) {
|
||||
return retBlkSz;
|
||||
}
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
for (idx = 0; idx < SLAB_MEM_COUNT; idx++) {
|
||||
slabAlloc = &(slabMem->slabClass[idx]);
|
||||
if (OsSlabAllocatorCheck(slabAlloc->alloc, slabNode) == TRUE) {
|
||||
retBlkSz = slabMem->slabClass[idx].blkSz;
|
||||
}
|
||||
}
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return retBlkSz;
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
Function : OsSlabStatisticsGet
|
||||
Description : collect slab statistics
|
||||
Input : pool --- pointer to the memory pool
|
||||
Output : status --- memory pool statistics
|
||||
Return : LOS_OK on success or error code on failure
|
||||
**************************************************************************/
|
||||
UINT32 OsSlabStatisticsGet(VOID *pool, LosSlabStatus *status)
|
||||
{
|
||||
struct LosSlabControlHeader *slabMem = NULL;
|
||||
OsSlabMem *slabAlloc = NULL;
|
||||
UINT32 itemSz = 0;
|
||||
UINT32 itemCnt = 0;
|
||||
UINT32 curUsage = 0;
|
||||
UINT32 totalUsage = 0;
|
||||
UINT32 totalMem = 0;
|
||||
UINT32 totalAllocCount = 0;
|
||||
UINT32 totalFreeCount = 0;
|
||||
UINT32 idx;
|
||||
|
||||
if ((status == NULL) || (pool == NULL)) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
slabMem = OsSlabCtrlHdrGet(pool);
|
||||
|
||||
for (idx = 0; idx < SLAB_MEM_COUNT; idx++) {
|
||||
slabAlloc = &(slabMem->slabClass[idx]);
|
||||
|
||||
OsSlabAllocatorGetSlabInfo(slabAlloc->alloc, &itemSz, &itemCnt, &curUsage);
|
||||
totalUsage += (curUsage * itemSz);
|
||||
totalMem += (itemCnt * itemSz);
|
||||
totalAllocCount += slabMem->slabClass[idx].blkUsedCnt;
|
||||
totalFreeCount += slabMem->slabClass[idx].blkCnt - slabMem->slabClass[idx].blkUsedCnt;
|
||||
}
|
||||
|
||||
if (totalMem < totalUsage) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
status->totalSize = totalMem;
|
||||
status->usedSize = totalUsage;
|
||||
status->freeSize = status->totalSize - status->usedSize;
|
||||
status->allocCount = totalAllocCount;
|
||||
status->freeCount = totalFreeCount;
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
Function : OsSlabGetMaxFreeBlkSize
|
||||
Description : get max free block size
|
||||
Input : pool --- pointer to the memory pool
|
||||
Output : None
|
||||
Return : max free block size
|
||||
**************************************************************************/
|
||||
UINT32 OsSlabGetMaxFreeBlkSize(VOID *pool)
|
||||
{
|
||||
struct LosSlabControlHeader *slabMem = OsSlabCtrlHdrGet(pool);
|
||||
OsSlabMem *slabAlloc = NULL;
|
||||
UINT32 itemSz = 0;
|
||||
UINT32 itemCnt = 0;
|
||||
UINT32 curUsage = 0;
|
||||
int idx;
|
||||
|
||||
for (idx = SLAB_MEM_COUNT - 1; idx >= 0; idx--) {
|
||||
slabAlloc = &(slabMem->slabClass[idx]);
|
||||
if (slabAlloc->alloc) {
|
||||
OsSlabAllocatorGetSlabInfo(slabAlloc->alloc, &itemSz, &itemCnt, &curUsage);
|
||||
if (curUsage != itemCnt) {
|
||||
return itemSz;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#include "los_base_pri.h"
|
||||
#include "los_sys_pri.h"
|
||||
#include "los_task_pri.h"
|
||||
#include "los_hwi.h"
|
||||
|
||||
LITE_OS_SEC_TEXT UINT32 LOS_Align(UINT32 addr, UINT32 boundary)
|
||||
{
|
||||
if ((addr + (boundary - 1)) > addr) {
|
||||
return (addr + (boundary - 1)) & ~(boundary - 1);
|
||||
} else {
|
||||
return addr & ~(boundary - 1);
|
||||
}
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_MINOR VOID LOS_Msleep(UINT32 mSecs)
|
||||
{
|
||||
UINT32 interval;
|
||||
|
||||
if (OS_INT_ACTIVE) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mSecs == 0) {
|
||||
interval = 0;
|
||||
} else {
|
||||
interval = LOS_MS2Tick(mSecs);
|
||||
if (interval == 0) {
|
||||
interval = 1;
|
||||
}
|
||||
}
|
||||
|
||||
(VOID)LOS_TaskDelay(interval);
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#include "los_err_pri.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
LITE_OS_SEC_BSS UserErrFunc g_userErrFunc;
|
||||
|
||||
/*****************************************************************************
|
||||
Function : LOS_ErrHandle
|
||||
Description : Error handle
|
||||
Input : fileName -- file name
|
||||
lineNo -- error line number
|
||||
errorNo -- user defined error number
|
||||
paraLen -- length of pPara
|
||||
para -- user description of error
|
||||
Output : None
|
||||
Return : LOS_OK always
|
||||
Other : None
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 LOS_ErrHandle(CHAR *fileName,
|
||||
UINT32 lineNo,
|
||||
UINT32 errorNo,
|
||||
UINT32 paraLen,
|
||||
VOID *para)
|
||||
{
|
||||
|
||||
if (g_userErrFunc.pfnHook != NULL) {
|
||||
g_userErrFunc.pfnHook(fileName, lineNo, errorNo, paraLen, para);
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
|
@ -0,0 +1,40 @@
|
|||
# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020, 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.
|
||||
|
||||
static_library("cpup") {
|
||||
|
||||
sources = [
|
||||
"cpup/los_cpup.c",
|
||||
"cppsupport/los_cppsupport.c"
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
"include"
|
||||
]
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#include "los_cppsupport.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
typedef VOID (*InitFunc)(VOID);
|
||||
|
||||
INT32 LOS_CppSystemInit(UINTPTR initArrayStart, UINTPTR initArrayEnd)
|
||||
{
|
||||
UINTPTR *start;
|
||||
InitFunc initFunc = NULL;
|
||||
|
||||
for (start = (UINTPTR *)initArrayStart; start < (UINTPTR *)initArrayEnd; start++){
|
||||
initFunc = (InitFunc)(*start);
|
||||
initFunc();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
|
@ -0,0 +1,541 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#include "string.h"
|
||||
#include "securec.h"
|
||||
#include "los_cpup_pri.h"
|
||||
#include "los_task_pri.h"
|
||||
#include "los_memory_pri.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#if (LOSCFG_BASE_CORE_CPUP == YES)
|
||||
|
||||
/**
|
||||
* @ingroup los_cpup
|
||||
* CPU usage-type macro: used for tasks.
|
||||
*/
|
||||
#define OS_THREAD_TYPE_TASK 0
|
||||
|
||||
/**
|
||||
* @ingroup los_cpup
|
||||
* CPU usage-type macro: used for hardware interrupts.
|
||||
*/
|
||||
#define OS_THREAD_TYPE_HWI 1
|
||||
|
||||
LITE_OS_SEC_BSS UINT16 g_cpupInitFlg = 0;
|
||||
LITE_OS_SEC_BSS OsCpupCB *g_cpup = NULL;
|
||||
LITE_OS_SEC_BSS UINT64 g_lastRecordTime;
|
||||
LITE_OS_SEC_BSS UINT16 g_hisPos; /* <current Sampling point of historyTime */
|
||||
extern VOID LOS_GetCpuCycle(UINT32 *cntHi, UINT32 *cntLo);
|
||||
#define OS_CPUP_RECORD_PERIOD (g_sysClock)
|
||||
/*****************************************************************************
|
||||
Function : OsCpupInit
|
||||
Description: initialization of CPUP
|
||||
Input : None
|
||||
Return : LOS_OK or Error Information
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 OsCpupInit()
|
||||
{
|
||||
UINT32 size;
|
||||
|
||||
size = g_taskMaxNum * sizeof(OsCpupCB);
|
||||
g_cpup = (OsCpupCB *)LOS_MemAlloc(m_aucSysMem0, size);
|
||||
|
||||
if (g_cpup == NULL) {
|
||||
return LOS_ERRNO_CPUP_NO_MEMORY;
|
||||
}
|
||||
|
||||
// Ignore the return code when matching CSEC rule 6.6(3).
|
||||
(VOID)memset_s(g_cpup, size, 0, size);
|
||||
g_cpupInitFlg = 1;
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : OsGetCpuCycle
|
||||
Description: get current cycles count
|
||||
Input : None
|
||||
Return : current cycles count
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_MINOR UINT64 OsGetCpuCycle(VOID)
|
||||
{
|
||||
UINT32 high = 0;
|
||||
UINT32 low = 0;
|
||||
LOS_GetCpuCycle(&high, &low);
|
||||
return (((UINT64)high << 32) + low); // 32 means bits of word
|
||||
}
|
||||
/*****************************************************************************
|
||||
Function : OsTskCycleStart
|
||||
Description: start task to get cycles count in current task begining
|
||||
Input : None
|
||||
Return : None
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_MINOR VOID OsTskCycleStart(VOID)
|
||||
{
|
||||
UINT32 taskID;
|
||||
|
||||
if (g_cpupInitFlg == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
taskID = g_losTask.newTask->taskID;
|
||||
g_cpup[taskID].cpupID = taskID;
|
||||
g_cpup[taskID].startTime = OsGetCpuCycle();
|
||||
|
||||
return;
|
||||
}
|
||||
/*****************************************************************************
|
||||
Function : OsTskCycleEnd
|
||||
Description: quit task and get cycle count
|
||||
Input : None
|
||||
Return : None
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_MINOR VOID OsTskCycleEnd(VOID)
|
||||
{
|
||||
UINT32 taskID;
|
||||
UINT64 cpuCycle;
|
||||
|
||||
if (g_cpupInitFlg == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
taskID = g_losTask.runTask->taskID;
|
||||
|
||||
if (g_cpup[taskID].startTime == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
cpuCycle = OsGetCpuCycle();
|
||||
|
||||
if (cpuCycle < g_cpup[taskID].startTime) {
|
||||
cpuCycle += g_cyclesPerTick;
|
||||
}
|
||||
|
||||
g_cpup[taskID].allTime += (cpuCycle - g_cpup[taskID].startTime);
|
||||
g_cpup[taskID].startTime = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
/*****************************************************************************
|
||||
Function : OsTskCycleEndStart
|
||||
Description: start task to get cycles count in current task ending
|
||||
Input : None
|
||||
Return : None
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_MINOR VOID OsTskCycleEndStart(VOID)
|
||||
{
|
||||
UINT32 taskID;
|
||||
UINT64 cpuCycle;
|
||||
UINT16 loopNum;
|
||||
|
||||
if (g_cpupInitFlg == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
taskID = g_losTask.runTask->taskID;
|
||||
cpuCycle = OsGetCpuCycle();
|
||||
|
||||
if (g_cpup[taskID].startTime != 0) {
|
||||
if (cpuCycle < g_cpup[taskID].startTime) {
|
||||
cpuCycle += g_cyclesPerTick;
|
||||
}
|
||||
|
||||
g_cpup[taskID].allTime += (cpuCycle - g_cpup[taskID].startTime);
|
||||
g_cpup[taskID].startTime = 0;
|
||||
}
|
||||
|
||||
taskID = g_losTask.newTask->taskID;
|
||||
g_cpup[taskID].cpupID = taskID;
|
||||
g_cpup[taskID].startTime = cpuCycle;
|
||||
|
||||
if ((cpuCycle - g_lastRecordTime) > OS_CPUP_RECORD_PERIOD) {
|
||||
g_lastRecordTime = cpuCycle;
|
||||
|
||||
for (loopNum = 0; loopNum < g_taskMaxNum; loopNum++) {
|
||||
g_cpup[loopNum].historyTime[g_hisPos] = g_cpup[loopNum].allTime;
|
||||
}
|
||||
|
||||
if (g_hisPos == (OS_CPUP_HISTORY_RECORD_NUM - 1)) {
|
||||
g_hisPos = 0;
|
||||
} else {
|
||||
g_hisPos++;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_MINOR static inline UINT16 OsGetPrePos(UINT16 curPos)
|
||||
{
|
||||
return (curPos == 0) ? (OS_CPUP_HISTORY_RECORD_NUM - 1) : (curPos - 1);
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_MINOR static VOID OsGetPositions(UINT16 mode, UINT16* curPosAddr, UINT16* prePosAddr)
|
||||
{
|
||||
UINT16 curPos;
|
||||
UINT16 prePos = 0;
|
||||
|
||||
curPos = g_hisPos;
|
||||
|
||||
if (mode == CPUP_IN_1S) {
|
||||
curPos = OsGetPrePos(curPos);
|
||||
prePos = OsGetPrePos(curPos);
|
||||
} else if (mode == CPUP_LESS_THAN_1S) {
|
||||
curPos = OsGetPrePos(curPos);
|
||||
}
|
||||
|
||||
*curPosAddr = curPos;
|
||||
*prePosAddr = prePos;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : LOS_SysCpuUsage
|
||||
Description: get current CPU usage
|
||||
Input : None
|
||||
Return : cpupRet:current CPU usage
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_SysCpuUsage(VOID)
|
||||
{
|
||||
UINT64 cpuCycleAll = 0;
|
||||
UINT32 cpupRet = 0;
|
||||
UINT16 loopNum;
|
||||
UINTPTR intSave;
|
||||
|
||||
if (g_cpupInitFlg == 0) {
|
||||
return LOS_ERRNO_CPUP_NO_INIT;
|
||||
}
|
||||
|
||||
// get end time of current task
|
||||
intSave = LOS_IntLock();
|
||||
OsTskCycleEnd();
|
||||
|
||||
for (loopNum = 0; loopNum < g_taskMaxNum; loopNum++) {
|
||||
cpuCycleAll += g_cpup[loopNum].allTime;
|
||||
}
|
||||
|
||||
if (cpuCycleAll) {
|
||||
cpupRet = LOS_CPUP_PRECISION - (UINT32)((LOS_CPUP_PRECISION *
|
||||
g_cpup[g_idleTaskID].allTime) / cpuCycleAll);
|
||||
}
|
||||
|
||||
OsTskCycleStart();
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return cpupRet;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : LOS_HistorySysCpuUsage
|
||||
Description: get CPU usage history
|
||||
Input : mode: mode,0 = usage in 10s,1 = usage in last 1s, else = less than 1s
|
||||
Return : cpupRet:CPU usage history
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_HistorySysCpuUsage(UINT16 mode)
|
||||
{
|
||||
UINT64 cpuCycleAll = 0;
|
||||
UINT64 idleCycleAll = 0;
|
||||
UINT32 cpupRet = 0;
|
||||
UINT16 loopNum;
|
||||
UINT16 curPos;
|
||||
UINT16 prePos = 0;
|
||||
UINTPTR intSave;
|
||||
|
||||
if (g_cpupInitFlg == 0) {
|
||||
return LOS_ERRNO_CPUP_NO_INIT;
|
||||
}
|
||||
|
||||
// get end time of current task
|
||||
intSave = LOS_IntLock();
|
||||
OsTskCycleEnd();
|
||||
|
||||
OsGetPositions(mode, &curPos, &prePos);
|
||||
|
||||
for (loopNum = 0; loopNum < g_taskMaxNum; loopNum++) {
|
||||
if (mode == CPUP_IN_1S) {
|
||||
cpuCycleAll += g_cpup[loopNum].historyTime[curPos] - g_cpup[loopNum].historyTime[prePos];
|
||||
} else {
|
||||
cpuCycleAll += g_cpup[loopNum].allTime - g_cpup[loopNum].historyTime[curPos];
|
||||
}
|
||||
}
|
||||
|
||||
if (mode == CPUP_IN_1S) {
|
||||
idleCycleAll += g_cpup[g_idleTaskID].historyTime[curPos] -
|
||||
g_cpup[g_idleTaskID].historyTime[prePos];
|
||||
} else {
|
||||
idleCycleAll += g_cpup[g_idleTaskID].allTime - g_cpup[g_idleTaskID].historyTime[curPos];
|
||||
}
|
||||
|
||||
if (cpuCycleAll) {
|
||||
cpupRet = (LOS_CPUP_PRECISION - (UINT32)((LOS_CPUP_PRECISION * idleCycleAll) / cpuCycleAll));
|
||||
}
|
||||
|
||||
OsTskCycleStart();
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return cpupRet;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : LOS_TaskCpuUsage
|
||||
Description: get CPU usage of certain task
|
||||
Input : taskID : task ID
|
||||
Return : cpupRet:CPU usage of certain task
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskCpuUsage(UINT32 taskID)
|
||||
{
|
||||
UINT64 cpuCycleAll = 0;
|
||||
UINT16 loopNum;
|
||||
UINTPTR intSave;
|
||||
UINT32 cpupRet = 0;
|
||||
|
||||
if (g_cpupInitFlg == 0) {
|
||||
return LOS_ERRNO_CPUP_NO_INIT;
|
||||
}
|
||||
if (OS_TSK_GET_INDEX(taskID) >= g_taskMaxNum) {
|
||||
return LOS_ERRNO_CPUP_TSK_ID_INVALID;
|
||||
}
|
||||
if (g_cpup[taskID].cpupID != taskID) {
|
||||
return LOS_ERRNO_CPUP_THREAD_NO_CREATED;
|
||||
}
|
||||
if ((g_cpup[taskID].status & OS_TASK_STATUS_UNUSED) || (g_cpup[taskID].status == 0)) {
|
||||
return LOS_ERRNO_CPUP_THREAD_NO_CREATED;
|
||||
}
|
||||
intSave = LOS_IntLock();
|
||||
OsTskCycleEnd();
|
||||
|
||||
/* get total Cycle */
|
||||
for (loopNum = 0; loopNum < g_taskMaxNum; loopNum++) {
|
||||
if ((g_cpup[loopNum].status & OS_TASK_STATUS_UNUSED) || (g_cpup[loopNum].status == 0)) {
|
||||
continue;
|
||||
}
|
||||
cpuCycleAll += g_cpup[loopNum].allTime;
|
||||
}
|
||||
|
||||
if (cpuCycleAll) {
|
||||
cpupRet = (UINT32)((LOS_CPUP_PRECISION * g_cpup[taskID].allTime) / cpuCycleAll);
|
||||
}
|
||||
|
||||
OsTskCycleStart();
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return cpupRet;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : LOS_HistoryTaskCpuUsage
|
||||
Description: get CPU usage history of certain task
|
||||
Input : taskID : task ID
|
||||
: mode: mode,0 = usage in 10s,1 = usage in last 1s, else = less than 1s
|
||||
Return : cpupRet:CPU usage history of task
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_HistoryTaskCpuUsage(UINT32 taskID, UINT16 mode)
|
||||
{
|
||||
UINT64 cpuCycleAll = 0;
|
||||
UINT64 cpuCycleCurTsk = 0;
|
||||
UINT16 loopNum, curPos;
|
||||
UINT16 prePos = 0;
|
||||
UINTPTR intSave;
|
||||
UINT32 cpupRet = 0;
|
||||
|
||||
if (g_cpupInitFlg == 0) {
|
||||
return LOS_ERRNO_CPUP_NO_INIT;
|
||||
}
|
||||
if (OS_TSK_GET_INDEX(taskID) >= g_taskMaxNum) {
|
||||
return LOS_ERRNO_CPUP_TSK_ID_INVALID;
|
||||
}
|
||||
if (g_cpup[taskID].cpupID != taskID) {
|
||||
return LOS_ERRNO_CPUP_THREAD_NO_CREATED;
|
||||
}
|
||||
if ((g_cpup[taskID].status & OS_TASK_STATUS_UNUSED) || (g_cpup[taskID].status == 0)) {
|
||||
return LOS_ERRNO_CPUP_THREAD_NO_CREATED;
|
||||
}
|
||||
intSave = LOS_IntLock();
|
||||
OsTskCycleEnd();
|
||||
|
||||
OsGetPositions(mode, &curPos, &prePos);
|
||||
|
||||
/* get total Cycle in history */
|
||||
for (loopNum = 0; loopNum < g_taskMaxNum; loopNum++) {
|
||||
if ((g_cpup[loopNum].status & OS_TASK_STATUS_UNUSED) || (g_cpup[loopNum].status == 0)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (mode == CPUP_IN_1S) {
|
||||
cpuCycleAll += g_cpup[loopNum].historyTime[curPos] - g_cpup[loopNum].historyTime[prePos];
|
||||
} else {
|
||||
cpuCycleAll += g_cpup[loopNum].allTime - g_cpup[loopNum].historyTime[curPos];
|
||||
}
|
||||
}
|
||||
|
||||
if (mode == CPUP_IN_1S) {
|
||||
cpuCycleCurTsk += g_cpup[taskID].historyTime[curPos] - g_cpup[taskID].historyTime[prePos];
|
||||
} else {
|
||||
cpuCycleCurTsk += g_cpup[taskID].allTime - g_cpup[taskID].historyTime[curPos];
|
||||
}
|
||||
if (cpuCycleAll) {
|
||||
cpupRet = (UINT32)((LOS_CPUP_PRECISION * cpuCycleCurTsk) / cpuCycleAll);
|
||||
}
|
||||
|
||||
OsTskCycleStart();
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return cpupRet;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_AllTaskCpuUsage(CPUP_INFO_S *cpupInfo, UINT16 mode)
|
||||
{
|
||||
UINT16 loopNum;
|
||||
UINT16 curPos;
|
||||
UINT16 prePos = 0;
|
||||
UINTPTR intSave;
|
||||
UINT64 cpuCycleAll = 0;
|
||||
UINT64 cpuCycleCurTsk = 0;
|
||||
|
||||
if (g_cpupInitFlg == 0) {
|
||||
return LOS_ERRNO_CPUP_NO_INIT;
|
||||
}
|
||||
|
||||
if (cpupInfo == NULL) {
|
||||
return LOS_ERRNO_CPUP_TASK_PTR_NULL;
|
||||
}
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
OsTskCycleEnd();
|
||||
|
||||
OsGetPositions(mode, &curPos, &prePos);
|
||||
|
||||
for (loopNum = 0; loopNum < g_taskMaxNum; loopNum++) {
|
||||
if ((g_cpup[loopNum].status & OS_TASK_STATUS_UNUSED) ||
|
||||
(g_cpup[loopNum].status == 0)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (mode == CPUP_IN_1S) {
|
||||
cpuCycleAll += g_cpup[loopNum].historyTime[curPos] - g_cpup[loopNum].historyTime[prePos];
|
||||
} else {
|
||||
cpuCycleAll += g_cpup[loopNum].allTime - g_cpup[loopNum].historyTime[curPos];
|
||||
}
|
||||
}
|
||||
|
||||
for (loopNum = 0; loopNum < g_taskMaxNum; loopNum++) {
|
||||
if ((g_cpup[loopNum].status & OS_TASK_STATUS_UNUSED) ||
|
||||
(g_cpup[loopNum].status == 0)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (mode == CPUP_IN_1S) {
|
||||
cpuCycleCurTsk += g_cpup[loopNum].historyTime[curPos] - g_cpup[loopNum].historyTime[prePos];
|
||||
} else {
|
||||
cpuCycleCurTsk += g_cpup[loopNum].allTime - g_cpup[loopNum].historyTime[curPos];
|
||||
}
|
||||
cpupInfo[loopNum].usStatus = g_cpup[loopNum].status;
|
||||
if (cpuCycleAll) {
|
||||
cpupInfo[loopNum].uwUsage = (UINT32)((LOS_CPUP_PRECISION * cpuCycleCurTsk) / cpuCycleAll);
|
||||
}
|
||||
|
||||
cpuCycleCurTsk = 0;
|
||||
}
|
||||
|
||||
OsTskCycleStart();
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Function : LOS_CpupUsageMonitor
|
||||
Description: Get CPU usage history of certain task.
|
||||
Input : type: cpup type, SYS_CPU_USAGE and TASK_CPU_USAGE
|
||||
: taskID: task ID, Only in SYS_CPU_USAGE type, taskID is invalid
|
||||
: mode: mode, CPUP_IN_10S = usage in 10s, CPUP_IN_1S = usage in last 1s, CPUP_LESS_THAN_1S = less than 1s
|
||||
Return : LOS_OK on success, or OS_ERROR on failure
|
||||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_CpupUsageMonitor(CPUP_TYPE_E type, CPUP_MODE_E mode, UINT32 taskID)
|
||||
{
|
||||
UINT32 ret;
|
||||
LosTaskCB *taskCB = NULL;
|
||||
|
||||
switch (type) {
|
||||
case SYS_CPU_USAGE:
|
||||
if (mode == CPUP_IN_10S) {
|
||||
PRINTK("\nSysCpuUsage in 10s: ");
|
||||
} else if (mode == CPUP_IN_1S) {
|
||||
PRINTK("\nSysCpuUsage in 1s: ");
|
||||
} else {
|
||||
PRINTK("\nSysCpuUsage in <1s: ");
|
||||
}
|
||||
ret = LOS_HistorySysCpuUsage(mode);
|
||||
PRINTK("%d.%d", ret / LOS_CPUP_PRECISION_MULT, ret % LOS_CPUP_PRECISION_MULT);
|
||||
break;
|
||||
|
||||
case TASK_CPU_USAGE:
|
||||
if (taskID > LOSCFG_BASE_CORE_TSK_LIMIT) {
|
||||
PRINT_ERR("\nThe taskid is invalid.\n");
|
||||
return OS_ERROR;
|
||||
}
|
||||
taskCB = OS_TCB_FROM_TID(taskID);
|
||||
if ((taskCB->taskStatus & OS_TASK_STATUS_UNUSED)) {
|
||||
PRINT_ERR("\nThe taskid is invalid.\n");
|
||||
return OS_ERROR;
|
||||
}
|
||||
if (mode == CPUP_IN_10S) {
|
||||
PRINTK("\nCPUusage of taskID %d in 10s: ", taskID);
|
||||
} else if (mode == CPUP_IN_1S) {
|
||||
PRINTK("\nCPUusage of taskID %d in 1s: ", taskID);
|
||||
} else {
|
||||
PRINTK("\nCPUusage of taskID %d in <1s: ", taskID);
|
||||
}
|
||||
ret = LOS_HistoryTaskCpuUsage(taskID, mode);
|
||||
PRINTK("%u.%u", ret / LOS_CPUP_PRECISION_MULT, ret % LOS_CPUP_PRECISION_MULT);
|
||||
break;
|
||||
|
||||
default:
|
||||
PRINT_ERR("\nThe type is invalid.\n");
|
||||
return OS_ERROR;
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
#endif /* LOSCFG_BASE_CORE_CPUP */
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
|
@ -0,0 +1,111 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef _LOS_CPUP_PRI_H
|
||||
#define _LOS_CPUP_PRI_H
|
||||
|
||||
#include "los_cpup.h"
|
||||
#include "los_tick_pri.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
|
||||
/**
|
||||
* @ingroup los_cpup
|
||||
* Number of historical running time records
|
||||
*/
|
||||
#define OS_CPUP_HISTORY_RECORD_NUM 10
|
||||
|
||||
/**
|
||||
* @ingroup los_cpup
|
||||
* Count the CPU usage structures of a task.
|
||||
*/
|
||||
typedef struct {
|
||||
UINT32 cpupID; /**< Task ID */
|
||||
UINT16 status; /**< Task status */
|
||||
UINT64 allTime; /**< Total running time */
|
||||
UINT64 startTime; /**< Time before a task is invoked */
|
||||
UINT64 historyTime[OS_CPUP_HISTORY_RECORD_NUM]; /**< Historical running time */
|
||||
} OsCpupCB;
|
||||
|
||||
extern OsCpupCB *g_cpup;
|
||||
|
||||
/**
|
||||
* @ingroup los_cpup
|
||||
* @brief Initialization cpup.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to initialization cpup.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval UINT32 Initialization result.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_cpup.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern UINT32 OsCpupInit(VOID);
|
||||
|
||||
/**
|
||||
* @ingroup los_cpup
|
||||
* @brief Start task to get cycles count in current task ending.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to start task to get cycles count in current task ending.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_cpup.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern VOID OsTskCycleEndStart(VOID);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_CPUP_PRI_H */
|
|
@ -0,0 +1,262 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup kernel Kernel
|
||||
* @defgroup los_base Basic definitions
|
||||
* @ingroup kernel
|
||||
*/
|
||||
|
||||
#ifndef _LOS_BASE_H
|
||||
#define _LOS_BASE_H
|
||||
|
||||
#include "los_builddef.h"
|
||||
#include "los_typedef.h"
|
||||
#include "los_config.h"
|
||||
#include "los_printf.h"
|
||||
#include "los_list.h"
|
||||
#include "los_errno.h"
|
||||
#include "los_compiler.h"
|
||||
#include "los_hwi.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define SIZE(a) (a)
|
||||
|
||||
#define LOS_ASSERT_COND(expression)
|
||||
|
||||
/**
|
||||
* @ingroup los_base
|
||||
* Define the timeout interval as LOS_NO_WAIT.
|
||||
*/
|
||||
#define LOS_NO_WAIT 0
|
||||
|
||||
/**
|
||||
* @ingroup los_base
|
||||
* Define the timeout interval as LOS_WAIT_FOREVER.
|
||||
*/
|
||||
#define LOS_WAIT_FOREVER 0xFFFFFFFF
|
||||
|
||||
/**
|
||||
* @ingroup los_base
|
||||
* Align the beginning of the object with the base address addr,
|
||||
* with boundary bytes being the smallest unit of alignment.
|
||||
*/
|
||||
#ifndef ALIGN
|
||||
#define ALIGN(addr, boundary) LOS_Align(addr, boundary)
|
||||
#endif
|
||||
/**
|
||||
* @ingroup los_base
|
||||
* Align the tail of the object with the base address addr, with size bytes being the smallest unit of alignment.
|
||||
*/
|
||||
#define TRUNCATE(addr, size) ((addr) & ~((size)-1))
|
||||
|
||||
/**
|
||||
* @ingroup los_base
|
||||
* Read a UINT8 value from addr and stroed in value.
|
||||
*/
|
||||
#define READ_UINT8(value, addr) ((value) = *((volatile UINT8 *)(addr)))
|
||||
/**
|
||||
* @ingroup los_base
|
||||
* Read a UINT16 value from addr and stroed in addr.
|
||||
*/
|
||||
#define READ_UINT16(value, addr) ((value) = *((volatile UINT16 *)(addr)))
|
||||
/**
|
||||
* @ingroup los_base
|
||||
* Read a UINT32 value from addr and stroed in value.
|
||||
*/
|
||||
#define READ_UINT32(value, addr) ((value) = *((volatile UINT32 *)(addr)))
|
||||
/**
|
||||
* @ingroup los_base
|
||||
* Read a UINT64 value from addr and stroed in value.
|
||||
*/
|
||||
#define READ_UINT64(value, addr) ((value) = *((volatile UINT64 *)(addr)))
|
||||
|
||||
/**
|
||||
* @ingroup los_base
|
||||
* Get a UINT8 value from addr.
|
||||
*/
|
||||
#define GET_UINT8(addr) (*((volatile UINT8 *)(addr)))
|
||||
/**
|
||||
* @ingroup los_base
|
||||
* Get a UINT16 value from addr.
|
||||
*/
|
||||
#define GET_UINT16(addr) (*((volatile UINT16 *)(addr)))
|
||||
/**
|
||||
* @ingroup los_base
|
||||
* Get a UINT32 value from addr.
|
||||
*/
|
||||
#define GET_UINT32(addr) (*((volatile UINT32 *)(addr)))
|
||||
/**
|
||||
* @ingroup los_base
|
||||
* Get a UINT64 value from addr.
|
||||
*/
|
||||
#define GET_UINT64(addr) (*((volatile UINT64 *)(addr)))
|
||||
|
||||
/**
|
||||
* @ingroup los_base
|
||||
* Write a UINT8 value to addr.
|
||||
*/
|
||||
#define WRITE_UINT8(value, addr) (*((volatile UINT8 *)(addr)) = (value))
|
||||
/**
|
||||
* @ingroup los_base
|
||||
* Write a UINT16 value to addr.
|
||||
*/
|
||||
#define WRITE_UINT16(value, addr) (*((volatile UINT16 *)(addr)) = (value))
|
||||
/**
|
||||
* @ingroup los_base
|
||||
* Write a UINT32 value to addr.
|
||||
*/
|
||||
#define WRITE_UINT32(value, addr) (*((volatile UINT32 *)(addr)) = (value))
|
||||
/**
|
||||
* @ingroup los_base
|
||||
* Write a UINT64 addr to addr.
|
||||
*/
|
||||
#define WRITE_UINT64(value, addr) (*((volatile UINT64 *)(addr)) = (value))
|
||||
|
||||
#if PRINT_LEVEL < LOS_ERR_LEVEL
|
||||
#define LOS_ASSERT(judge)
|
||||
#else
|
||||
#define LOS_ASSERT(judge) \
|
||||
do { \
|
||||
if ((judge) == 0) { \
|
||||
(VOID)LOS_IntLock(); \
|
||||
PRINT_ERR("ASSERT ERROR! %s, %d, %s\n", __FILE__, __LINE__, __func__); \
|
||||
while (1) { } \
|
||||
} \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_base
|
||||
* @brief Align the value (addr) by some bytes (boundary) you specify.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to align the value (addr) by some bytes (boundary) you specify.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>the value of boundary usually is 4,8,16,32.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param addr [IN] The variable what you want to align.
|
||||
* @param boundary [IN] The align size what you want to align.
|
||||
*
|
||||
* @retval #UINT32 The variable what have been aligned.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_base.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
extern UINT32 LOS_Align(UINT32 addr, UINT32 boundary);
|
||||
|
||||
/**
|
||||
* @ingroup los_base
|
||||
* @brief Sleep the current task.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to delay the execution of the current task. The task is able to be scheduled
|
||||
* after it is delayed for a specified number of Ticks.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The task fails to be delayed if it is being delayed during interrupt processing or it is locked.</li>
|
||||
* <li>If 0 is passed in and the task scheduling is not locked,
|
||||
* execute the next task in the queue of tasks with the priority of the current task.
|
||||
* If no ready task with the priority of the current task is available,
|
||||
* the task scheduling will not occur, and the current task continues to be executed.</li>
|
||||
* <li>The parameter passed in can not be equal to LOS_WAIT_FOREVER(0xFFFFFFFF).
|
||||
* If that happens, the task will not sleep 0xFFFFFFFF milliseconds or sleep forever but sleep 0xFFFFFFFF Ticks.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param mSecs [IN] Type #UINT32 Number of MS for which the task is delayed.
|
||||
*
|
||||
* @retval None
|
||||
* @par Dependency:
|
||||
* <ul><li>los_base.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None
|
||||
*/
|
||||
extern VOID LOS_Msleep(UINT32 mSecs);
|
||||
|
||||
/**
|
||||
* @ingroup los_base
|
||||
* @brief System kernel initialization function.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to start liteOS .
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param: None.
|
||||
*
|
||||
* @retval #LOS_OK 0:LiteOS start success.
|
||||
*
|
||||
* @par Dependency:
|
||||
* <ul><li>los_config.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
extern UINT32 LOS_Start(VOID);
|
||||
|
||||
/**
|
||||
* @ingroup los_base
|
||||
* @brief System kernel initialization function.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to Initialize kernel ,configure all system modules.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param: None.
|
||||
*
|
||||
* @retval #LOS_OK 0:System kernel initialization success.
|
||||
*
|
||||
* @par Dependency:
|
||||
* <ul><li>los_config.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
extern UINT32 LOS_KernelInit(VOID);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_BASE_H */
|
|
@ -0,0 +1,139 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef _LOS_COMPILER_H
|
||||
#define _LOS_COMPILER_H
|
||||
|
||||
/* for IAR Compiler */
|
||||
#ifdef __ICCARM__
|
||||
#include"iccarm_builtin.h"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/* for IAR Compiler */
|
||||
#ifdef __ICCARM__
|
||||
|
||||
#ifndef ASM
|
||||
#define ASM __asm
|
||||
#endif
|
||||
|
||||
#ifndef INLINE
|
||||
#define INLINE inline
|
||||
#endif
|
||||
|
||||
#ifndef STATIC_INLINE
|
||||
#define STATIC_INLINE static inline
|
||||
#endif
|
||||
|
||||
#ifndef USED
|
||||
#define USED __root
|
||||
#endif
|
||||
|
||||
#ifndef WEAK
|
||||
#define WEAK __weak
|
||||
#endif
|
||||
|
||||
#ifndef CLZ
|
||||
#define CLZ __iar_builtin_CLZ
|
||||
#endif
|
||||
|
||||
/* for ARM Compiler */
|
||||
#elif defined(__CC_ARM)
|
||||
|
||||
#ifndef ASM
|
||||
#define ASM __asm
|
||||
#endif
|
||||
|
||||
#ifndef INLINE
|
||||
#define INLINE __inline
|
||||
#endif
|
||||
|
||||
#ifndef STATIC_INLINE
|
||||
#define STATIC_INLINE static __inline
|
||||
#endif
|
||||
|
||||
#ifndef USED
|
||||
#define USED __attribute__((used))
|
||||
#endif
|
||||
|
||||
#ifndef WEAK
|
||||
#define WEAK __attribute__((weak))
|
||||
#endif
|
||||
|
||||
#ifndef CLZ
|
||||
#define CLZ __clz
|
||||
#endif
|
||||
|
||||
#pragma anon_unions
|
||||
|
||||
/* for GNU Compiler */
|
||||
#elif defined(__GNUC__)
|
||||
|
||||
#ifndef ASM
|
||||
#define ASM __asm
|
||||
#endif
|
||||
|
||||
#ifndef INLINE
|
||||
#define INLINE inline
|
||||
#endif
|
||||
|
||||
#ifndef STATIC_INLINE
|
||||
#define STATIC_INLINE static inline
|
||||
#endif
|
||||
|
||||
#ifndef USED
|
||||
#define USED __attribute__((used))
|
||||
#endif
|
||||
|
||||
#ifndef WEAK
|
||||
#define WEAK __attribute__((weak))
|
||||
#endif
|
||||
|
||||
#ifndef CLZ
|
||||
#define CLZ __builtin_clz
|
||||
#endif
|
||||
|
||||
#else
|
||||
#error Unknown compiler.
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_COMPILER_H */
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup los_cppsupport c++
|
||||
* @ingroup kernel
|
||||
*/
|
||||
|
||||
#ifndef _LOS_CPPSUPPORT_H
|
||||
#define _LOS_CPPSUPPORT_H
|
||||
|
||||
#include "los_typedef.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @ingroup los_cppsupport
|
||||
* @brief System cppsupport initialization.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to initialize the cppsupport .
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>initArrayStart is the start address of .init_array section,
|
||||
* initArrayEnd is the end address of .init_array section.</li>
|
||||
* <li>initArrayStart must be smaller than initArrayEnd,
|
||||
* initArrayStart and initArrayEnd should be 4(32 bits platform) or 8(64 bits platform) bytes alignment.</li>
|
||||
* </ul>
|
||||
*
|
||||
*
|
||||
* @retval 0 always return 0.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_cppsupport.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern INT32 LOS_CppSystemInit(UINTPTR initArrayStart, UINTPTR initArrayEnd);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_CPPSUPPORT_H */
|
|
@ -0,0 +1,308 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup los_cpup CPU usage
|
||||
* @ingroup kernel
|
||||
*/
|
||||
|
||||
#ifndef _LOS_CPUP_H
|
||||
#define _LOS_CPUP_H
|
||||
|
||||
#include "los_hwi.h"
|
||||
#include "los_base.h"
|
||||
#include "los_sys.h"
|
||||
#include "los_task.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
|
||||
/**
|
||||
* @ingroup los_cpup
|
||||
* CPU usage error code: The request for memory fails.
|
||||
*
|
||||
* Value: 0x02001e00
|
||||
*
|
||||
* Solution: Decrease the maximum number of tasks.
|
||||
*/
|
||||
#define LOS_ERRNO_CPUP_NO_MEMORY LOS_ERRNO_OS_ERROR(LOS_MOD_CPUP, 0x00)
|
||||
|
||||
/**
|
||||
* @ingroup los_cpup
|
||||
* CPU usage error code: The pointer to an input parameter is NULL.
|
||||
*
|
||||
* Value: 0x02001e01
|
||||
*
|
||||
* Solution: Check whether the pointer to the input parameter is usable.
|
||||
*/
|
||||
#define LOS_ERRNO_CPUP_TASK_PTR_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_CPUP, 0x01)
|
||||
|
||||
/**
|
||||
* @ingroup los_cpup
|
||||
* CPU usage error code: The CPU usage is not initialized.
|
||||
*
|
||||
* Value: 0x02001e02
|
||||
*
|
||||
* Solution: Check whether the CPU usage is initialized.
|
||||
*/
|
||||
#define LOS_ERRNO_CPUP_NO_INIT LOS_ERRNO_OS_ERROR(LOS_MOD_CPUP, 0x02)
|
||||
|
||||
/**
|
||||
* @ingroup los_cpup
|
||||
* CPU usage error code: The number of threads is invalid.
|
||||
*
|
||||
* Value: 0x02001e03
|
||||
*
|
||||
* Solution: Check whether the number of threads is applicable for the current operation.
|
||||
*/
|
||||
#define LOS_ERRNO_CPUP_MAXNUM_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_CPUP, 0x03)
|
||||
|
||||
/**
|
||||
* @ingroup los_cpup
|
||||
* CPU usage error code: The target thread is not created.
|
||||
*
|
||||
* Value: 0x02001e04
|
||||
*
|
||||
* Solution: Check whether the target thread is created.
|
||||
*/
|
||||
#define LOS_ERRNO_CPUP_THREAD_NO_CREATED LOS_ERRNO_OS_ERROR(LOS_MOD_CPUP, 0x04)
|
||||
|
||||
/**
|
||||
* @ingroup los_cpup
|
||||
* CPU usage error code: The target task ID is invalid.
|
||||
*
|
||||
* Value: 0x02001e05
|
||||
*
|
||||
* Solution: Check whether the target task ID is applicable for the current operation.
|
||||
*/
|
||||
#define LOS_ERRNO_CPUP_TSK_ID_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_CPUP, 0x05)
|
||||
|
||||
/**
|
||||
* @ingroup los_cpup
|
||||
* Sum of cpup with all tasks. It means the value of cpup is a permillage.
|
||||
*/
|
||||
#define LOS_CPUP_PRECISION 1000
|
||||
|
||||
/**
|
||||
* @ingroup los_cpup
|
||||
* Multiple of current cpup precision change to percent.
|
||||
*/
|
||||
#define LOS_CPUP_PRECISION_MULT (LOS_CPUP_PRECISION / 100)
|
||||
|
||||
/**
|
||||
* @ingroup los_cpup
|
||||
* Count the CPU usage structures of all tasks.
|
||||
*/
|
||||
typedef struct tagCpupInfo {
|
||||
UINT16 usStatus; /**< save the cur task status */
|
||||
UINT32 uwUsage; /**< Usage. The value range is [0,1000]. */
|
||||
} CPUP_INFO_S;
|
||||
|
||||
/**
|
||||
* @ingroup los_monitor
|
||||
* Type of the CPU usage query.
|
||||
*/
|
||||
typedef enum {
|
||||
SYS_CPU_USAGE = 0, /* system cpu occupancy rate */
|
||||
TASK_CPU_USAGE, /* task cpu occupancy rate */
|
||||
} CPUP_TYPE_E;
|
||||
|
||||
/**
|
||||
* @ingroup los_monitor
|
||||
* Mode of the CPU usage query.
|
||||
*/
|
||||
typedef enum {
|
||||
CPUP_IN_10S = 0, /* cpu occupancy rate in 10s */
|
||||
CPUP_IN_1S, /* cpu occupancy rate in 1s */
|
||||
CPUP_LESS_THAN_1S, /* cpu occupancy rate less than 1s, if the input mode is none of them, it will be this. */
|
||||
} CPUP_MODE_E;
|
||||
|
||||
/**
|
||||
* @ingroup los_cpup
|
||||
* @brief Obtain the current CPU usage.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to obtain the current CPU usage.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>This API can be called only after the CPU usage is initialized. Otherwise, error codes will be returned.</li>
|
||||
* <li> The precision of the CPU usage can be adjusted by changing the value of the CPUP_PRECISION macro.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval #OS_ERRNO_CPUP_NO_INIT 0x02001e02: The CPU usage is not initialized.
|
||||
* @retval #cpup [0,100], current CPU usage, of which the precision is adjustable.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_cpup.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_SysCpuUsage
|
||||
*/
|
||||
extern UINT32 LOS_SysCpuUsage(VOID);
|
||||
|
||||
/**
|
||||
* @ingroup los_cpup
|
||||
* @brief Obtain the historical CPU usage.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to obtain the historical CPU usage.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>This API can be called only after the CPU usage is initialized. Otherwise, the CPU usage fails to be obtained.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param mode [IN] UINT16. Task mode. The parameter value 0 indicates that the CPU usage within 10s will be
|
||||
* obtained, and the parameter value 1 indicates that the CPU usage in the former 1s will be obtained. Other values
|
||||
* indicate that the CPU usage in the period that is less than 1s will be obtained.
|
||||
*
|
||||
* @retval #OS_ERRNO_CPUP_NO_INIT 0x02001e02: The CPU usage is not initialized.
|
||||
* @retval #cpup [0,100], historical CPU usage, of which the precision is adjustable.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_cpup.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_HistoryTaskCpuUsage
|
||||
*/
|
||||
extern UINT32 LOS_HistorySysCpuUsage(UINT16 mode);
|
||||
|
||||
/**
|
||||
* @ingroup los_cpup
|
||||
* @brief Obtain the CPU usage of a specified task.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to obtain the CPU usage of a task specified by a passed-in task ID.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>This API can be called only after the CPU usage is initialized. Otherwise, the CPU usage fails to be obtained.</li>
|
||||
* <li>The passed-in task ID must be valid and the task specified by the task ID must be created. Otherwise,
|
||||
* the CPU usage fails to be obtained.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param taskID [IN] UINT32. Task ID.
|
||||
*
|
||||
* @retval #OS_ERRNO_CPUP_NO_INIT 0x02001e02: The CPU usage is not initialized.
|
||||
* @retval #OS_ERRNO_CPUP_TSK_ID_INVALID 0x02001e05: The target task ID is invalid.
|
||||
* @retval #OS_ERRNO_CPUP_THREAD_NO_CREATED 0x02001e04: The target thread is not created.
|
||||
* @retval #cpup [0,100], CPU usage of the specified task.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_cpup.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_HistoryTaskCpuUsage
|
||||
*/
|
||||
extern UINT32 LOS_TaskCpuUsage(UINT32 taskID);
|
||||
|
||||
/**
|
||||
* @ingroup los_cpup
|
||||
* @brief Obtain the historical CPU usage of a specified task.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to obtain the historical CPU usage of a task specified by a passed-in task ID.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>This API can be called only after the CPU usage is initialized. Otherwise,
|
||||
* the CPU usage fails to be obtained.</li>
|
||||
* <li>The passed-in task ID must be valid and the task specified by the task ID must be created. Otherwise,
|
||||
* the CPU usage fails to be obtained.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param taskID [IN] UINT32. Task ID.
|
||||
* @param mode [IN] UINT16. Task mode. The parameter value 0 indicates that the CPU usage within 10s
|
||||
* will be obtained, and the parameter value 1 indicates that the CPU usage in the former 1s will be obtained.
|
||||
* Other values indicate that the CPU usage in the period that is less than 1s will be obtained.
|
||||
*
|
||||
* @retval #OS_ERRNO_CPUP_NO_INIT 0x02001e02: The CPU usage is not initialized.
|
||||
* @retval #OS_ERRNO_CPUP_TSK_ID_INVALID 0x02001e05: The target task ID is invalid.
|
||||
* @retval #OS_ERRNO_CPUP_THREAD_NO_CREATED 0x02001e04: The target thread is not created.
|
||||
* @retval #cpup [0,100], CPU usage of the specified task.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_cpup.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_HistorySysCpuUsage
|
||||
*/
|
||||
extern UINT32 LOS_HistoryTaskCpuUsage(UINT32 taskID, UINT16 mode);
|
||||
|
||||
/**
|
||||
* @ingroup los_cpup
|
||||
* @brief Obtain the CPU usage of all tasks.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to obtain the CPU usage of all tasks according to maximum number of threads.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>This API can be called only after the CPU usage is initialized. Otherwise, the CPU usage fails to be obtained.</li>
|
||||
* <li>The input parameter pointer must not be NULL, Otherwise, the CPU usage fails to be obtained.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param cpupInfo [OUT]Type. CPUP_INFO_S* Pointer to the task CPUP information structure to be obtained.
|
||||
* @param mode [IN] UINT16. Task mode. The parameter value 0 indicates that the CPU usage within 10s
|
||||
* will be obtained, and the parameter value 1 indicates that the CPU usage in the former 1s will be obtained.
|
||||
* Other values indicate that the CPU usage in the period that is less than 1s will be obtained.
|
||||
*
|
||||
* @retval #OS_ERRNO_CPUP_NO_INIT 0x02001e02: The CPU usage is not initialized.
|
||||
* @retval #OS_ERRNO_CPUP_TASK_PTR_NULL 0x02001e01: The input parameter pointer is NULL.
|
||||
* @retval #LOS_OK 0x00000000: The CPU usage of all tasks is successfully obtained.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_cpup.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_SysCpuUsage
|
||||
*/
|
||||
extern UINT32 LOS_AllTaskCpuUsage(CPUP_INFO_S *cpupInfo, UINT16 mode);
|
||||
|
||||
/**
|
||||
* @ingroup los_monitor
|
||||
* @brief Obtain CPU usage history of certain task.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to obtain CPU usage history of certain task.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>This API can be called only after the CPU usage is initialized. Otherwise, -1 will be returned.</li>
|
||||
* <li> Only in SYS_CPU_USAGE type, uwTaskID is invalid.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param type [IN] cpup type, SYS_CPU_USAGE and TASK_CPU_USAGE
|
||||
* @param mode [IN] mode,CPUP_IN_10S = usage in 10s,CPUP_IN_1S = usage in last 1s,
|
||||
* CPUP_LESS_THAN_1S = less than 1s, if the inpuit mode is none of them, it will be as CPUP_LESS_THAN_1S.
|
||||
* @param taskID [IN] task ID, Only in SYS_CPU_USAGE type, taskID is invalid
|
||||
*
|
||||
* @retval #OS_ERROR -1:CPU usage info obtain failed.
|
||||
* @retval #LOS_OK 0:CPU usage info is successfully obtained.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_monitor.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_CpupUsageMonitor
|
||||
*/
|
||||
extern UINT32 LOS_CpupUsageMonitor(CPUP_TYPE_E type, CPUP_MODE_E mode, UINT32 taskID);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_CPUP_H */
|
|
@ -0,0 +1,158 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup los_err Error handling
|
||||
* @ingroup kernel
|
||||
*/
|
||||
|
||||
#ifndef _LOS_ERR_H
|
||||
#define _LOS_ERR_H
|
||||
|
||||
#include "los_typedef.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
|
||||
/**
|
||||
* @ingroup los_err
|
||||
* @brief Define the pointer to the error handling function.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to define the pointer to the error handling function.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param fileName [IN] Log file that stores error information.
|
||||
* @param lineNo [IN] Line number of the erroneous line.
|
||||
* @param errorNo [IN] Error code.
|
||||
* @param paraLen [IN] Length of the input parameter pPara.
|
||||
* @param para [IN] User label of the error.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_err.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
typedef VOID (*LOS_ERRORHANDLE_FUNC)(CHAR *fileName,
|
||||
UINT32 lineNo, /**< Line number of the erroneous line. */
|
||||
UINT32 errorNo, /**< Error code. */
|
||||
UINT32 paraLen, /**< Length of the input parameter pPara. */
|
||||
VOID *para);
|
||||
|
||||
/**
|
||||
* @ingroup los_err
|
||||
* @brief Error handling function.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to perform different operations according to error types.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param fileName [IN] Log file that stores error information.
|
||||
* @param lineNo [IN] Line number of the erroneous line which should not be OS_ERR_MAGIC_WORD.
|
||||
* @param errorNo [IN] Error code.
|
||||
* @param paraLen [IN] Length of the input parameter pPara.
|
||||
* @param para [IN] User label of the error.
|
||||
*
|
||||
* @retval LOS_OK The error is successfully processed.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_err.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None
|
||||
*/
|
||||
extern UINT32 LOS_ErrHandle(CHAR *fileName, UINT32 lineNo,
|
||||
UINT32 errorNo, UINT32 paraLen,
|
||||
VOID *para);
|
||||
|
||||
/**
|
||||
* @ingroup los_err
|
||||
* Error handling function structure.
|
||||
*/
|
||||
typedef struct tagUserErrFunc {
|
||||
LOS_ERRORHANDLE_FUNC pfnHook; /**< Hook function for error handling. */
|
||||
} UserErrFunc;
|
||||
|
||||
|
||||
enum LOS_MOUDLE_ID {
|
||||
LOS_MOD_SYS = 0x0,
|
||||
LOS_MOD_MEM = 0x1,
|
||||
LOS_MOD_TSK = 0x2,
|
||||
LOS_MOD_SWTMR = 0x3,
|
||||
LOS_MOD_TICK = 0x4,
|
||||
LOS_MOD_MSG = 0x5,
|
||||
LOS_MOD_QUE = 0x6,
|
||||
LOS_MOD_SEM = 0x7,
|
||||
LOS_MOD_MBOX = 0x8,
|
||||
LOS_MOD_HWI = 0x9,
|
||||
LOS_MOD_HWWDG = 0xa,
|
||||
LOS_MOD_CACHE = 0xb,
|
||||
LOS_MOD_HWTMR = 0xc,
|
||||
LOS_MOD_MMU = 0xd,
|
||||
|
||||
LOS_MOD_LOG = 0xe,
|
||||
LOS_MOD_ERR = 0xf,
|
||||
|
||||
LOS_MOD_EXC = 0x10,
|
||||
LOS_MOD_CSTK = 0x11,
|
||||
|
||||
LOS_MOD_MPU = 0x12,
|
||||
LOS_MOD_NMHWI = 0x13,
|
||||
LOS_MOD_TRACE = 0x14,
|
||||
LOS_MOD_KNLSTAT = 0x15,
|
||||
LOS_MOD_EVTTIME = 0x16,
|
||||
LOS_MOD_THRDCPUP = 0x17,
|
||||
LOS_MOD_IPC = 0x18,
|
||||
LOS_MOD_STKMON = 0x19,
|
||||
LOS_MOD_TIMER = 0x1a,
|
||||
LOS_MOD_RESLEAKMON = 0x1b,
|
||||
LOS_MOD_EVENT = 0x1c,
|
||||
LOS_MOD_MUX = 0X1d,
|
||||
LOS_MOD_CPUP = 0x1e,
|
||||
LOS_MOD_SHELL = 0x31,
|
||||
LOS_MOD_BUTT
|
||||
};
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_ERR_H */
|
|
@ -0,0 +1,115 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup los_errno Error code
|
||||
* @ingroup kernel
|
||||
*/
|
||||
|
||||
#ifndef _LOS_ERRNO_H
|
||||
#define _LOS_ERRNO_H
|
||||
|
||||
#include "los_typedef.h"
|
||||
#include "los_err.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
|
||||
/**
|
||||
* @ingroup los_errno
|
||||
* OS error code flag.
|
||||
*/
|
||||
#define LOS_ERRNO_OS_ID ((UINT32)0x00 << 16)
|
||||
|
||||
/**
|
||||
* @ingroup los_errno
|
||||
* Define the error level as informative.
|
||||
*/
|
||||
#define LOS_ERRTYPE_NORMAL ((UINT32)0x00 << 24)
|
||||
|
||||
/**
|
||||
* @ingroup los_errno
|
||||
* Define the error level as warning.
|
||||
*/
|
||||
#define LOS_ERRTYPE_WARN ((UINT32)0x01 << 24)
|
||||
|
||||
/**
|
||||
* @ingroup los_errno
|
||||
* Define the error level as critical.
|
||||
*/
|
||||
#define LOS_ERRTYPE_ERROR ((UINT32)0x02 << 24)
|
||||
|
||||
/**
|
||||
* @ingroup los_errno
|
||||
* Define the error level as fatal.
|
||||
*/
|
||||
#define LOS_ERRTYPE_FATAL ((UINT32)0x03 << 24)
|
||||
|
||||
/**
|
||||
* @ingroup los_errno
|
||||
* Define fatal OS errors.
|
||||
*/
|
||||
#define LOS_ERRNO_OS_FATAL(moduleID, errno) \
|
||||
(LOS_ERRTYPE_FATAL | LOS_ERRNO_OS_ID | ((UINT32)(moduleID) << 8) | (errno))
|
||||
|
||||
/**
|
||||
* @ingroup los_errno
|
||||
* Define critical OS errors.
|
||||
*/
|
||||
#define LOS_ERRNO_OS_ERROR(moduleID, errno) \
|
||||
(LOS_ERRTYPE_ERROR | LOS_ERRNO_OS_ID | ((UINT32)(moduleID) << 8) | (errno))
|
||||
|
||||
/**
|
||||
* @ingroup los_errno
|
||||
* Define warning OS errors.
|
||||
*/
|
||||
#define LOS_ERRNO_OS_WARN(moduleID, errno) \
|
||||
(LOS_ERRTYPE_WARN | LOS_ERRNO_OS_ID | ((UINT32)(moduleID) << 8) | (errno))
|
||||
|
||||
/**
|
||||
* @ingroup los_errno
|
||||
* Define informative OS errors.
|
||||
*/
|
||||
#define LOS_ERRNO_OS_NORMAL(moduleID, errno) \
|
||||
(LOS_ERRTYPE_NORMAL | LOS_ERRNO_OS_ID | ((UINT32)(moduleID) << 8) | (errno))
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_ERRNO_H */
|
|
@ -0,0 +1,330 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup los_event Event
|
||||
* @ingroup kernel
|
||||
*/
|
||||
|
||||
#ifndef _LOS_EVENT_H
|
||||
#define _LOS_EVENT_H
|
||||
|
||||
#include "los_base.h"
|
||||
#include "los_list.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @ingroup los_event
|
||||
* Event reading mode: The task waits for all its expected events to occur.
|
||||
*/
|
||||
#define LOS_WAITMODE_AND (4) /* all bits must be set */
|
||||
|
||||
/**
|
||||
* @ingroup los_event
|
||||
* Event reading mode: The task waits for any of its expected events to occur.
|
||||
*/
|
||||
#define LOS_WAITMODE_OR (2) /* any bit must be set */
|
||||
|
||||
/**
|
||||
* @ingroup los_event
|
||||
* Event reading mode: The event flag is immediately cleared after the event is read.
|
||||
*/
|
||||
#define LOS_WAITMODE_CLR (1) /* clear when satisfied */
|
||||
|
||||
/**
|
||||
* @ingroup los_event
|
||||
* Bit 25 of the event mask cannot be set to an event because it is set to an error code.
|
||||
*
|
||||
* Value: 0x02001c00
|
||||
*
|
||||
* Solution: Set bits excluding bit 25 of the event mask to events.
|
||||
*/
|
||||
#define LOS_ERRNO_EVENT_SETBIT_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_EVENT, 0x00)
|
||||
/**
|
||||
* @ingroup los_event
|
||||
* Event reading error code: Event reading times out.
|
||||
*
|
||||
* Value: 0x02001c01
|
||||
*
|
||||
* Solution: Increase the waiting time for event reading, or make another task write a mask for the event.
|
||||
*/
|
||||
#define LOS_ERRNO_EVENT_READ_TIMEOUT LOS_ERRNO_OS_ERROR(LOS_MOD_EVENT, 0x01)
|
||||
|
||||
/**
|
||||
* @ingroup los_event
|
||||
* Event reading error code: The EVENTMASK input parameter value is valid. The input parameter value must not be 0.
|
||||
*
|
||||
* Value: 0x02001c02
|
||||
*
|
||||
* Solution: Pass in a valid EVENTMASK value.
|
||||
*/
|
||||
#define LOS_ERRNO_EVENT_EVENTMASK_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_EVENT, 0x02)
|
||||
|
||||
/**
|
||||
* @ingroup los_event
|
||||
* Event reading error code: The event is being read during an interrupt.
|
||||
*
|
||||
* Value: 0x02001c03
|
||||
*
|
||||
* Solution: Read the event in a task.
|
||||
*/
|
||||
#define LOS_ERRNO_EVENT_READ_IN_INTERRUPT LOS_ERRNO_OS_ERROR(LOS_MOD_EVENT, 0x03)
|
||||
|
||||
/**
|
||||
* @ingroup los_event
|
||||
* Event reading error code: The uwFlags input parameter value used in the event reading API is invalid.
|
||||
* This input parameter value is obtained by performing an OR operation on corresponding bits of either OS_EVENT_ANY or
|
||||
* OS_EVENT_ANY and corresponding bits of either OS_EVENT_WAIT or OS_EVENT_NOWAIT. The waiting time must be set to
|
||||
* a nonzero value when an event is read in the mode of OS_EVENT_WAIT.
|
||||
*
|
||||
* Value: 0x02001c04
|
||||
*
|
||||
* Solution: Pass in a valid uwFlags value.
|
||||
*/
|
||||
#define LOS_ERRNO_EVENT_FLAGS_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_EVENT, 0x04)
|
||||
|
||||
/**
|
||||
* @ingroup los_event
|
||||
* Event reading error code: The task is locked and is unable to read the event.
|
||||
*
|
||||
* Value: 0x02001c05
|
||||
*
|
||||
* Solution: Unlock the task and read the event.
|
||||
*/
|
||||
#define LOS_ERRNO_EVENT_READ_IN_LOCK LOS_ERRNO_OS_ERROR(LOS_MOD_EVENT, 0x05)
|
||||
|
||||
/**
|
||||
* @ingroup los_event
|
||||
* Event reading error code: Null pointer.
|
||||
*
|
||||
* Value: 0x02001c06
|
||||
*
|
||||
* Solution: Check whether the input parameter is null.
|
||||
*/
|
||||
#define LOS_ERRNO_EVENT_PTR_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_EVENT, 0x06)
|
||||
|
||||
/**
|
||||
* @ingroup los_event
|
||||
* Event reading error code: no initialized.
|
||||
*
|
||||
* Value: 0x02001c07
|
||||
*
|
||||
* Solution: Check whether the event is initialized.
|
||||
*/
|
||||
#define LOS_ERRNO_EVENT_NOT_INITIALIZED LOS_ERRNO_OS_ERROR(LOS_MOD_EVENT, 0x07)
|
||||
|
||||
/**
|
||||
* @ingroup los_event
|
||||
* Event reading error code: should not be distory.
|
||||
*
|
||||
* Value: 0x02001c08
|
||||
*
|
||||
* Solution: Check whether the event list is not empty.
|
||||
*/
|
||||
#define LOS_ERRNO_EVENT_SHOULD_NOT_DESTORY LOS_ERRNO_OS_ERROR(LOS_MOD_EVENT, 0x08)
|
||||
|
||||
/**
|
||||
* @ingroup los_event
|
||||
* Event control structure
|
||||
*/
|
||||
typedef struct tagEvent {
|
||||
UINT32 uwEventID; /**< Event mask in the event control block,
|
||||
indicating the event that has been logically processed. */
|
||||
LOS_DL_LIST stEventList; /**< Event control block linked list */
|
||||
} EVENT_CB_S, *PEVENT_CB_S;
|
||||
/**
|
||||
* @ingroup los_event
|
||||
* @brief Initialize an event control block.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to initialize the event control block pointed to by eventCB.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param eventCB [IN/OUT] Pointer to the event control block to be initialized.
|
||||
*
|
||||
* @retval #LOS_ERRNO_EVENT_PTR_NULL Null pointer.
|
||||
* @retval #LOS_OK The event control block is successfully initialized.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_event.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_EventClear
|
||||
*/
|
||||
extern UINT32 LOS_EventInit(PEVENT_CB_S eventCB);
|
||||
|
||||
/**
|
||||
* @ingroup los_event
|
||||
* @brief Obtain an event specified by the event ID.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to check whether an event expected by the user occurs according to the event ID, event mask,
|
||||
* and event reading mode, and process the event based on the event reading mode. The event ID must point to valid memory.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>When the mode is LOS_WAITMODE_CLR, the eventID is passed-out.</li>
|
||||
* <li>Otherwise the eventID is passed-in.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param eventID [IN/OUT] Pointer to the ID of the event to be checked.
|
||||
* @param eventMask [IN] Mask of the event expected to occur by the user, indicating the event obtained after
|
||||
* it is logically processed that matches the ID pointed to by mode.
|
||||
* @param mode [IN] Event reading mode. The modes include LOS_WAITMODE_AND, LOS_WAITMODE_OR, LOS_WAITMODE_CLR.
|
||||
*
|
||||
* @retval 0 The event expected by the user does not occur.
|
||||
* @retval #UINT32 The event expected by the user occurs.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_event.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_EventRead | LOS_EventWrite
|
||||
*/
|
||||
extern UINT32 LOS_EventPoll(UINT32 *eventID, UINT32 eventMask, UINT32 mode);
|
||||
|
||||
/**
|
||||
* @ingroup los_event
|
||||
* @brief Read an event.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to block or schedule a task that reads an event of which the event control block, event mask, reading mode,
|
||||
* and timeout information are specified.
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>An error code and an event return value can be same. To differentiate the error code and return value, bit 25 of
|
||||
* the event mask is forbidden to be used.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param eventCB [IN/OUT] Pointer to the event control block to be checked. This parameter must point to valid memory.
|
||||
* @param eventMask [IN] Mask of the event expected to occur by the user, indicating the event obtained after
|
||||
* it is logically processed that matches the ID pointed to by eventID.
|
||||
* @param mode [IN] Event reading mode.
|
||||
* @param timeOut [IN] Timeout interval of event reading (unit: Tick).
|
||||
*
|
||||
* @retval #LOS_ERRNO_EVENT_SETBIT_INVALID Bit 25 of the event mask cannot be set because it is set to an error number.
|
||||
* @retval #LOS_ERRNO_EVENT_EVENTMASK_INVALID The passed-in event reading mode is incorrect.
|
||||
* @retval #LOS_ERRNO_EVENT_READ_IN_INTERRUPT The event is being read during an interrupt.
|
||||
* @retval #LOS_ERRNO_EVENT_FLAGS_INVALID The event mode is invalid.
|
||||
* @retval #LOS_ERRNO_EVENT_READ_IN_LOCK The event reading task is locked.
|
||||
* @retval #LOS_ERRNO_EVENT_PTR_NULL The passed-in pointer is null.
|
||||
* @retval 0 The event expected by the user does not occur.
|
||||
* @retval #UINT32 The event expected by the user occurs.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_event.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_EventPoll | LOS_EventWrite
|
||||
*/
|
||||
extern UINT32 LOS_EventRead(PEVENT_CB_S eventCB, UINT32 eventMask, UINT32 mode, UINT32 timeOut);
|
||||
|
||||
/**
|
||||
* @ingroup los_event
|
||||
* @brief Write an event.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to write an event specified by the passed-in event mask into an event control block
|
||||
* pointed to by eventCB.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>To determine whether the LOS_EventRead API returns an event or an error code, bit 25 of the event mask
|
||||
* is forbidden to be used.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param eventCB [IN/OUT] Pointer to the event control block into which an event is to be written.
|
||||
* This parameter must point to valid memory.
|
||||
* @param events [IN] Event mask to be written.
|
||||
*
|
||||
* @retval #LOS_ERRNO_EVENT_SETBIT_INVALID Bit 25 of the event mask cannot be set to an event
|
||||
* because it is set to an error code.
|
||||
* @retval #LOS_ERRNO_EVENT_PTR_NULL Null pointer.
|
||||
* @retval #LOS_OK The event is successfully written.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_event.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_EventPoll | LOS_EventRead
|
||||
*/
|
||||
extern UINT32 LOS_EventWrite(PEVENT_CB_S eventCB, UINT32 events);
|
||||
|
||||
/**
|
||||
* @ingroup los_event
|
||||
* @brief Clear the event occurring in a specified task.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to set the ID of an event that has a specified mask and of which the information is stored in
|
||||
* an event control block pointed to by eventCB to 0. eventCB must point to valid memory.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The value of events needs to be reversed when it is passed-in.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param eventCB [IN/OUT] Pointer to the event control block to be cleared.
|
||||
* @param events [IN] Mask of the event to be cleared.
|
||||
*
|
||||
* @retval #LOS_ERRNO_EVENT_PTR_NULL Null pointer.
|
||||
* @retval #LOS_OK The event is successfully cleared.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_event.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_EventPoll | LOS_EventRead | LOS_EventWrite
|
||||
*/
|
||||
extern UINT32 LOS_EventClear(PEVENT_CB_S eventCB, UINT32 events);
|
||||
|
||||
/**
|
||||
* @ingroup los_event
|
||||
* @brief Destroy a event.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to Destroy a event.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The specific event should be a valid one.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param eventCB [IN/OUT] Pointer to the event control block to be Destroyed.
|
||||
*
|
||||
* @retval #LOS_ERRNO_EVENT_PTR_NULL Null pointer.
|
||||
* @retval #LOS_OK The event is successfully cleared.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_event.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_EventPoll | LOS_EventRead | LOS_EventWrite
|
||||
*/
|
||||
extern UINT32 LOS_EventDestroy(PEVENT_CB_S eventCB);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_EVENT_H */
|
|
@ -0,0 +1,232 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup los_heap Heap
|
||||
* @ingroup kernel
|
||||
*/
|
||||
|
||||
#ifndef _LOS_HEAP_H
|
||||
#define _LOS_HEAP_H
|
||||
|
||||
#include <los_typedef.h>
|
||||
#include "los_base.h"
|
||||
#if (LOSCFG_KERNEL_MEM_SLAB == YES)
|
||||
#include "los_slab.h"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define IS_ALIGNED(value) ((((UINT32)(value)) & ((UINT32)((value) - 1))) == 0)
|
||||
#define OS_MEM_ALIGN(value, align) (((UINT32)(UINTPTR)(value) + (UINT32)((align) - 1)) & \
|
||||
(~(UINT32)((align) - 1)))
|
||||
#define OS_MEM_ALIGN_FLAG 0x80000000
|
||||
#define OS_MEM_SET_ALIGN_FLAG(align) ((align) = ((align) | OS_MEM_ALIGN_FLAG))
|
||||
#define OS_MEM_GET_ALIGN_FLAG(align) ((align) & OS_MEM_ALIGN_FLAG)
|
||||
#define OS_MEM_GET_ALIGN_GAPSIZE(align) ((align) & (~OS_MEM_ALIGN_FLAG))
|
||||
|
||||
#define RAM_HEAP_SIZE ((OS_SYS_MEM_SIZE) & (~7))
|
||||
#define RAM_HEAP_START (OS_SYS_MEM_ADDR)
|
||||
|
||||
#ifdef CONFIG_DDR_HEAP
|
||||
#define DDR_HEAP_INIT() LOS_HeapInit((VOID *)DDR_HEAP_START, DDR_HEAP_SIZE)
|
||||
#define DDR_HEAP_ALLOC(sz) LOS_HeapAllocAlign((VOID *)DDR_HEAP_START, \
|
||||
OS_MEM_ALIGN(sz, DCACHE_LINE_SIZE), DCACHE_LINE_SIZE)
|
||||
#define DDR_HEAP_FREE(p) LOS_HeapFree((VOID *)DDR_HEAP_START, p)
|
||||
#endif
|
||||
|
||||
/* extra 2 blocks is for idle and extra temparary task */
|
||||
#define TASK_BLOCK_NUM (LOSCFG_BASE_CORE_TSK_LIMIT + 2)
|
||||
|
||||
#if (LOSCFG_KERNEL_MEM_STATISTICS == YES)
|
||||
#define TASKID_BITS 7
|
||||
/* 2 bits for used and align flag, 30 bits left */
|
||||
#define SIZE_BITS (30 - TASKID_BITS)
|
||||
#if (SIZE_BITS <= 0)
|
||||
#error task id bits too big!
|
||||
#endif
|
||||
#if (TASK_BLOCK_NUM > ((1 << TASKID_BITS) - 1))
|
||||
#error task id bits too small!
|
||||
#endif
|
||||
#endif
|
||||
|
||||
struct LOS_HEAP_NODE {
|
||||
struct LOS_HEAP_NODE* pstPrev;
|
||||
#if (LOSCFG_KERNEL_MEM_STATISTICS == YES)
|
||||
UINT32 uwSize : SIZE_BITS;
|
||||
UINT32 taskID : TASKID_BITS;
|
||||
#else
|
||||
UINT32 uwSize : 30;
|
||||
#endif
|
||||
UINT32 uwUsed : 1;
|
||||
UINT32 uwAlign : 1;
|
||||
UINT8 ucData[0]; /*lint !e43*/
|
||||
};
|
||||
|
||||
/**
|
||||
* @ingroup los_heap
|
||||
* @brief Initialization heap memory.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to initialization heap memory.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param pool [IN/OUT] A pointer pointed to the memory pool.
|
||||
* @param size [IN] Size of heap memory.
|
||||
*
|
||||
* @retval TRUE Initialization success.
|
||||
* @retval FALSE Initialization failed.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_heap.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern BOOL LOS_HeapInit(VOID *pool, UINT32 size);
|
||||
|
||||
/**
|
||||
* @ingroup los_heap
|
||||
* @brief Alloc memory block from heap memory.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to alloc memory block from heap memory.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param pool [IN/OUT] A pointer pointed to the memory pool.
|
||||
* @param size [IN] Size of heap memory.
|
||||
*
|
||||
* @retval VOID*
|
||||
* @par Dependency:
|
||||
* <ul><li>los_heap.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_HeapFree
|
||||
*/
|
||||
extern VOID* LOS_HeapAlloc(VOID *pool, UINT32 size);
|
||||
|
||||
/**
|
||||
* @ingroup los_heap
|
||||
* @brief Alloc aligned memory block from heap memory.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to alloc aligned memory block from heap memory.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param pool [IN/OUT] A pointer pointed to the memory pool.
|
||||
* @param size [IN] Size of heap memory.
|
||||
* @param boundary [IN] Boundary the heap needs align
|
||||
*
|
||||
* @retval VOID*
|
||||
* @par Dependency:
|
||||
* <ul><li>los_heap.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_HeapFree
|
||||
*/
|
||||
extern VOID* LOS_HeapAllocAlign(VOID *pool, UINT32 size, UINT32 boundary);
|
||||
|
||||
/**
|
||||
* @ingroup los_heap
|
||||
* @brief Free memory block from heap memory.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to free memory block from heap memory.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param pool [IN/OUT] A pointer pointed to the memory pool.
|
||||
* @param ptr [IN] Point to be freed.
|
||||
*
|
||||
* @retval BOOL TRUE free success FALSE free failed
|
||||
* @par Dependency:
|
||||
* <ul><li>los_heap.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_HeapAlloc
|
||||
*/
|
||||
extern BOOL LOS_HeapFree(VOID *pool, VOID* ptr);
|
||||
|
||||
/**
|
||||
* @ingroup los_memory
|
||||
* @brief Get the memory info from Heap.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to get the memory info from Heap.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
* @param None.
|
||||
*
|
||||
* @retval UINT32 Max size of heap memory being used.
|
||||
*
|
||||
* @par Dependency:
|
||||
* <ul><li>los_heap.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
#if (LOSCFG_HEAP_MEMORY_PEAK_STATISTICS == YES)
|
||||
extern UINT32 LOS_HeapGetHeapMemoryPeak(VOID);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_memory
|
||||
* @brief Get the memory statistics from Heap.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to get the memory statistics from Heap.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
* @param None.
|
||||
*
|
||||
* @retval None.
|
||||
*
|
||||
* @par Dependency:
|
||||
* <ul><li>los_heap.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
#if (LOSCFG_KERNEL_MEM_STATISTICS == YES)
|
||||
VOID LOS_HeapDumpMemoryStats(VOID *pool);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,428 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup los_list Doubly linked list
|
||||
* @ingroup kernel
|
||||
*/
|
||||
|
||||
#ifndef _LOS_LIST_H
|
||||
#define _LOS_LIST_H
|
||||
|
||||
#include "los_typedef.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @ingroup los_list
|
||||
* Structure of a node in a doubly linked list.
|
||||
*/
|
||||
typedef struct LOS_DL_LIST {
|
||||
struct LOS_DL_LIST *pstPrev; /**< Current node's pointer to the previous node */
|
||||
struct LOS_DL_LIST *pstNext; /**< Current node's pointer to the next node */
|
||||
} LOS_DL_LIST;
|
||||
|
||||
/**
|
||||
* @ingroup los_list
|
||||
* @brief Initialize a doubly linked list.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to initialize a doubly linked list.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The parameter passed in should be ensured to be a legal pointer.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param list [IN] Node in a doubly linked list.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
LITE_OS_SEC_ALW_INLINE STATIC_INLINE VOID LOS_ListInit(LOS_DL_LIST *list)
|
||||
{
|
||||
list->pstNext = list;
|
||||
list->pstPrev = list;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup los_list
|
||||
* @brief Point to the next node pointed to by the current node.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to point to the next node pointed to by the current node.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param object [IN] Node in the doubly linked list.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
#define LOS_DL_LIST_FIRST(object) ((object)->pstNext)
|
||||
|
||||
/**
|
||||
* @ingroup los_list
|
||||
* @brief Insert a new node to a doubly linked list.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to insert a new node to a doubly linked list.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The parameters passed in should be ensured to be legal pointers.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param list [IN] Doubly linked list where the new node is inserted.
|
||||
* @param node [IN] New node to be inserted.
|
||||
*
|
||||
* @retval None
|
||||
* @par Dependency:
|
||||
* <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_ListDelete
|
||||
*/
|
||||
LITE_OS_SEC_ALW_INLINE STATIC_INLINE VOID LOS_ListAdd(LOS_DL_LIST *list, LOS_DL_LIST *node)
|
||||
{
|
||||
node->pstNext = list->pstNext;
|
||||
node->pstPrev = list;
|
||||
list->pstNext->pstPrev = node;
|
||||
list->pstNext = node;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup los_list
|
||||
* @brief Insert a node to the tail of a doubly linked list.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to insert a new node to the tail of a doubly linked list.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The parameters passed in should be ensured to be legal pointers.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param list [IN] Doubly linked list where the new node is inserted.
|
||||
* @param node [IN] New node to be inserted.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_ListAdd | LOS_ListHeadInsert
|
||||
*/
|
||||
LITE_OS_SEC_ALW_INLINE STATIC_INLINE VOID LOS_ListTailInsert(LOS_DL_LIST *list, LOS_DL_LIST *node)
|
||||
{
|
||||
LOS_ListAdd(list->pstPrev, node);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup los_list
|
||||
* @brief Delete a specified node from a doubly linked list.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to delete a specified node from a doubly linked list.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The parameter passed in should be ensured to be a legal pointer.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param node [IN] Node to be deleted.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_ListAdd
|
||||
*/
|
||||
LITE_OS_SEC_ALW_INLINE STATIC_INLINE VOID LOS_ListDelete(LOS_DL_LIST *node)
|
||||
{
|
||||
node->pstNext->pstPrev = node->pstPrev;
|
||||
node->pstPrev->pstNext = node->pstNext;
|
||||
node->pstNext = (LOS_DL_LIST *)NULL;
|
||||
node->pstPrev = (LOS_DL_LIST *)NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup los_list
|
||||
* @brief Identify whether a specified doubly linked list is empty.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to return whether a doubly linked list is empty.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The parameter passed in should be ensured to be a legal pointer.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param list [IN] Doubly linked node.
|
||||
*
|
||||
* @retval TRUE The doubly linked list is empty.
|
||||
* @retval FALSE The doubly linked list is not empty.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
LITE_OS_SEC_ALW_INLINE STATIC_INLINE BOOL LOS_ListEmpty(LOS_DL_LIST *node)
|
||||
{
|
||||
return (BOOL)(node->pstNext == node);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup los_list
|
||||
* @brief Obtain the offset of a field to a structure address.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to obtain the offset of a field to a structure address.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param type [IN] Structure name.
|
||||
* @param field [IN] Name of the field of which the offset is to be measured.
|
||||
*
|
||||
* @retval Offset of the field to the structure address.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
#define OFFSET_OF_FIELD(type, field) ((UINT32)&(((type *)0)->field))
|
||||
|
||||
/**
|
||||
* @ingroup los_list
|
||||
* @brief Obtain the pointer to a doubly linked list in a structure.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to obtain the pointer to a doubly linked list in a structure.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param type [IN] Structure name.
|
||||
* @param member [IN] Member name of the doubly linked list in the structure.
|
||||
*
|
||||
* @retval Pointer to the doubly linked list in the structure.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
#define LOS_OFF_SET_OF(type, member) ((UINT32)&(((type *)0)->member)) /*lint -e(413) */
|
||||
|
||||
/**
|
||||
* @ingroup los_list
|
||||
* @brief Obtain the pointer to a structure that contains a doubly linked list.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to obtain the pointer to a structure that contains a doubly linked list.
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param item [IN] Current node's pointer to the next node.
|
||||
* @param type [IN] Structure name.
|
||||
* @param member [IN] Member name of the doubly linked list in the structure.
|
||||
*
|
||||
* @retval Pointer to the structure that contains the doubly linked list.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
#define LOS_DL_LIST_ENTRY(item, type, member) \
|
||||
((type *)(VOID *)((CHAR *)(item) - LOS_OFF_SET_OF(type, member))) \
|
||||
|
||||
/**
|
||||
* @ingroup los_list
|
||||
* @brief Iterate over a doubly linked list of given type.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to iterate over a doubly linked list of given type.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param item [IN] Pointer to the structure that contains the doubly linked list that is to be traversed.
|
||||
* @param list [IN] Pointer to the doubly linked list to be traversed.
|
||||
* @param type [IN] Structure name.
|
||||
* @param member [IN] Member name of the doubly linked list in the structure.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
#define LOS_DL_LIST_FOR_EACH_ENTRY(item, list, type, member) \
|
||||
for ((item) = LOS_DL_LIST_ENTRY((list)->pstNext, type, member); \
|
||||
&(item)->member != (list); \
|
||||
(item) = LOS_DL_LIST_ENTRY((item)->member.pstNext, type, member))
|
||||
|
||||
/**
|
||||
* @ingroup los_list
|
||||
* @brief iterate over a doubly linked list safe against removal of list entry.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to iterate over a doubly linked list safe against removal of list entry.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param item [IN] Pointer to the structure that contains the doubly linked list that is to be traversed.
|
||||
* @param next [IN] Save the next node.
|
||||
* @param list [IN] Pointer to the doubly linked list to be traversed.
|
||||
* @param type [IN] Structure name.
|
||||
* @param member [IN] Member name of the doubly linked list in the structure.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
#define LOS_DL_LIST_FOR_EACH_ENTRY_SAFE(item, next, list, type, member) \
|
||||
for ((item) = LOS_DL_LIST_ENTRY((list)->pstNext, type, member), \
|
||||
(next) = LOS_DL_LIST_ENTRY((item)->member.pstNext, type, member); \
|
||||
&((item)->member) != (list); \
|
||||
(item) = (next), (next) = LOS_DL_LIST_ENTRY((item)->member.pstNext, type, member))
|
||||
|
||||
/**
|
||||
* @ingroup los_list
|
||||
* @brief Delete initialize a doubly linked list.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to delete initialize a doubly linked list.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The parameter passed in should be ensured to be s legal pointer.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param list [IN] Doubly linked list.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
LITE_OS_SEC_ALW_INLINE STATIC_INLINE VOID LOS_ListDelInit(LOS_DL_LIST *list)
|
||||
{
|
||||
list->pstNext->pstPrev = list->pstPrev;
|
||||
list->pstPrev->pstNext = list->pstNext;
|
||||
LOS_ListInit(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup los_list
|
||||
* @brief iterate over a doubly linked list.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to iterate over a doubly linked list.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param item [IN] Pointer to the structure that contains the doubly linked list that is to be traversed.
|
||||
* @param list [IN] Pointer to the doubly linked list to be traversed.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
#define LOS_DL_LIST_FOR_EACH(item, list) \
|
||||
for ((item) = (list)->pstNext; (item) != (list); (item) = (item)->pstNext)
|
||||
|
||||
/**
|
||||
* @ingroup los_list
|
||||
* @brief Iterate over a doubly linked list safe against removal of list entry.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to iterate over a doubly linked list safe against removal of list entry.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param item [IN] Pointer to the structure that contains the doubly linked list that is to be traversed.
|
||||
* @param next [IN] Save the next node.
|
||||
* @param list [IN] Pointer to the doubly linked list to be traversed.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
#define LOS_DL_LIST_FOR_EACH_SAFE(item, next, list) \
|
||||
for ((item) = (list)->pstNext, (next) = (item)->pstNext; (item) != (list); \
|
||||
(item) = (next), (next) = (item)->pstNext)
|
||||
|
||||
/**
|
||||
* @ingroup los_list
|
||||
* @brief Initialize a double linked list.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to initialize a double linked list.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param list [IN] Pointer to the doubly linked list to be traversed.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
#define LOS_DL_LIST_HEAD(list) \
|
||||
LOS_DL_LIST list = { &(list), &(list) }
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_LIST_H */
|
|
@ -0,0 +1,201 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef _LOS_MEMBOX_H
|
||||
#define _LOS_MEMBOX_H
|
||||
|
||||
#include "los_config.h"
|
||||
#if (LOSCFG_PLATFORM_EXC == YES)
|
||||
#include "los_memcheck.h"
|
||||
#endif
|
||||
|
||||
#define BOX_ALIGN_8 0x80000000
|
||||
/* ----------------------------------------------------------------------------
|
||||
* Global Functions
|
||||
* --------------------------------------------------------------------------- */
|
||||
/**
|
||||
* @ingroup los_membox
|
||||
* Define whether to check the address validity
|
||||
*/
|
||||
#if (LOSCFG_PLATFORM_EXC == YES)
|
||||
#define LOS_MEMBOX_CHECK
|
||||
extern UINT8 g_memMang[];
|
||||
#endif
|
||||
|
||||
typedef struct tagMemBoxCB {
|
||||
UINT32 uwMaxBlk;
|
||||
UINT32 uwBlkCnt;
|
||||
UINT32 uwBlkSize; /* Memory block size */
|
||||
}OS_MEMBOX_S;
|
||||
|
||||
typedef OS_MEMBOX_S *OS_MEMBOX_S_P;
|
||||
|
||||
#ifdef LOS_MEMBOX_CHECK
|
||||
#define LOS_MEMBOX_MAGIC_SIZE 4
|
||||
#else
|
||||
#define LOS_MEMBOX_MAGIC_SIZE 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_membox
|
||||
* @brief Initialize a memory pool.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to initialize a memory pool.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The boxSize parameter value should match the following two conditions :</li>
|
||||
* <li>1) Be less than or equal to the Memory pool size; 2) Be greater than the size of LOS_MEMBOX_INFO.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param boxMem [IN] Memory pool address.
|
||||
* @param boxSize [IN] Memory pool size.
|
||||
* @param blkSize [IN] Memory block size.
|
||||
*
|
||||
* @retval #LOS_NOK The memory pool fails to be initialized.
|
||||
* @retval #LOS_OK The memory pool is successfully initialized.
|
||||
* @par Dependency:
|
||||
* <ul>
|
||||
* <li>los_membox.h: the header file that contains the API declaration.</li>
|
||||
* </ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern UINT32 LOS_MemboxInit(VOID *boxMem, UINT32 boxSize, UINT32 blkSize);
|
||||
|
||||
/**
|
||||
* @ingroup los_membox
|
||||
* @brief Request a memory block.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to request a memory block.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The input pool parameter must be initialized via func LOS_MemboxInit.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param boxMem [IN] Memory pool address.
|
||||
*
|
||||
* @retval #VOID* The request is accepted, and return a memory block address.
|
||||
* @retval #NULL The request fails.
|
||||
* @par Dependency:
|
||||
* <ul>
|
||||
* <li>los_membox.h: the header file that contains the API declaration.</li>
|
||||
* </ul>
|
||||
* @see LOS_MemboxFree
|
||||
*/
|
||||
extern VOID *LOS_MemboxAlloc(VOID *boxMem);
|
||||
|
||||
/**
|
||||
* @ingroup los_membox
|
||||
* @brief Free a memory block.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to free a memory block.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The input pool parameter must be initialized via func LOS_MemboxInit.</li>
|
||||
* <li>The input pBox parameter must be allocated by LOS_MemboxAlloc.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param boxMem [IN] Memory pool address.
|
||||
* @param box [IN] Memory block address.
|
||||
*
|
||||
* @retval #LOS_NOK This memory block fails to be freed.
|
||||
* @retval #LOS_OK This memory block is successfully freed.
|
||||
* @par Dependency:
|
||||
* <ul>
|
||||
* <li>los_membox.h: the header file that contains the API declaration.</li>
|
||||
* </ul>
|
||||
* @see LOS_MemboxAlloc
|
||||
*/
|
||||
extern UINT32 LOS_MemboxFree(const VOID *boxMem, VOID *box);
|
||||
|
||||
/**
|
||||
* @ingroup los_membox
|
||||
* @brief Clear a memory block.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to set the memory block value to be 0.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The input pool parameter must be initialized via func LOS_MemboxInit.</li>
|
||||
* <li>The input pBox parameter must be allocated by LOS_MemboxAlloc.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param boxMem [IN] Memory pool address.
|
||||
* @param box [IN] Memory block address.
|
||||
*
|
||||
* @retval VOID
|
||||
* @par Dependency:
|
||||
* <ul>
|
||||
* <li>los_membox.h: the header file that contains the API declaration.</li>
|
||||
* </ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern VOID LOS_MemboxClr(const VOID *boxMem, VOID *box);
|
||||
|
||||
|
||||
/**
|
||||
* @ingroup los_membox
|
||||
* @brief calculate membox information.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to calculate membox information.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>One parameter of this interface is a pointer, it should be a correct value, otherwise, the system may be
|
||||
* abnormal.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param boxMem [IN] Type #VOID* Pointer to the calculate membox.
|
||||
* @param maxBlk [OUT] Type #UINT32* Record membox max block.
|
||||
* @param blkCnt [OUT] Type #UINT32* Record membox block count alreay allocated.
|
||||
* @param blkSize [OUT] Type #UINT32* Record membox block size.
|
||||
*
|
||||
* @retval #LOS_OK The heap status calculate success.
|
||||
* @retval #LOS_NOK The membox status calculate with some error.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_memory.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_MemAlloc | LOS_MemRealloc | LOS_MemFree
|
||||
*/
|
||||
extern UINT32 LOS_MemboxStatisticsGet(const VOID *boxMem, UINT32 *maxBlk, UINT32 *blkCnt, UINT32 *blkSize);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,116 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef _LOS_MEMCHECK_H
|
||||
#define _LOS_MEMCHECK_H
|
||||
|
||||
#include "los_base.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
|
||||
#define MEM_INFO_SIZE ((sizeof(MEM_INFO) * OS_SYS_MEM_NUM) + 4)
|
||||
extern UINT8 g_memMang[];
|
||||
|
||||
enum _MEM_MANG_TYPE {
|
||||
MEM_MANG_MEMBOX,
|
||||
MEM_MANG_MEMORY,
|
||||
MEM_MANG_EMPTY,
|
||||
};
|
||||
|
||||
enum _MEM_MANG_SOUCE {
|
||||
MEM_MANG_UNUSED,
|
||||
MEM_MANG_INIT,
|
||||
MEM_MANG_INT,
|
||||
MEM_MANG_TASK,
|
||||
};
|
||||
|
||||
typedef struct _MEM_INFO {
|
||||
UINT32 uwType;
|
||||
UINT32 uwStartAddr;
|
||||
UINT32 uwSize;
|
||||
VOID * blkAddrArray;
|
||||
}MEM_INFO;
|
||||
|
||||
typedef struct _SLAB_INFO {
|
||||
UINT32 item_sz;
|
||||
UINT32 item_cnt;
|
||||
UINT32 cur_usage;
|
||||
}SLAB_INFO;
|
||||
|
||||
#define SLAB_CLASS_NUM (4U)
|
||||
typedef struct _MEM_INFO_S {
|
||||
UINT32 uwType;
|
||||
UINT32 uwStartAddr;
|
||||
UINT32 uwSize;
|
||||
UINT32 uwFree;
|
||||
UINT32 uwBlockSize;
|
||||
UINT32 uwErrorAddr;
|
||||
UINT32 uwErrorLen;
|
||||
UINT32 uwErrorOwner;
|
||||
SLAB_INFO stSlabInfo[SLAB_CLASS_NUM];
|
||||
}MEM_INFO_S;
|
||||
|
||||
/**
|
||||
* @ingroup los_memboxcheck
|
||||
* @brief Get the information of the exc memory.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to get the information of the exc memory.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param memNum [IN] Type #UINT32 Memory pool number.
|
||||
* @param memExcInfo [IN/OUT] Type #MEM_INFO_S * information of the exc memory.
|
||||
*
|
||||
* @retval UINT32 Get information result.
|
||||
* @par Dependency:
|
||||
* <ul>
|
||||
* <li>los_memboxcheck.h: the header file that contains the API declaration.</li>
|
||||
* </ul>
|
||||
* @see None.
|
||||
*/
|
||||
UINT32 LOS_MemExcInfoGet(UINT32 memNum, MEM_INFO_S *memExcInfo);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
|
||||
#endif /* _LOS_MEMCHECK_H */
|
|
@ -0,0 +1,610 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef _LOS_MEMORY_H
|
||||
#define _LOS_MEMORY_H
|
||||
#include "los_base.h"
|
||||
#if (LOSCFG_KERNEL_MEM_SLAB == YES)
|
||||
#include <los_slab.h>
|
||||
#endif
|
||||
#include <los_heap.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
typedef struct __s_LOS_MEM_STATUS {
|
||||
UINT32 totalSize;
|
||||
UINT32 usedSize;
|
||||
UINT32 freeSize;
|
||||
UINT32 allocCount;
|
||||
UINT32 freeCount;
|
||||
} LOS_MEM_STATUS;
|
||||
|
||||
#if (LOSCFG_MEMORY_BESTFIT == YES)
|
||||
|
||||
/**
|
||||
* @ingroup los_memory
|
||||
* Memory pool information structure
|
||||
*/
|
||||
typedef struct {
|
||||
VOID *pPoolAddr; /**< Starting address of a memory pool */
|
||||
UINT32 uwPoolSize; /**< Memory pool size */
|
||||
#if defined(OS_MEM_WATERLINE) && (OS_MEM_WATERLINE == YES)
|
||||
UINT32 uwPoolWaterLine; /**< Maximum usage size in a memory pool */
|
||||
UINT32 uwPoolCurUsedSize; /**< Current usage size in a memory pool */
|
||||
#endif
|
||||
#ifdef LOSCFG_MEM_MUL_POOL
|
||||
VOID *pNextPool;
|
||||
#endif
|
||||
} LOS_MEM_POOL_INFO;
|
||||
|
||||
#if (LOSCFG_BASE_MEM_NODE_INTEGRITY_CHECK == YES)
|
||||
extern UINT8 g_memMang[];
|
||||
#endif
|
||||
#if (LOSCFG_PLATFORM_EXC == YES)
|
||||
#define OS_MEM_ENABLE_ALLOC_CHECK
|
||||
#endif
|
||||
#if (LOSCFG_BASE_MEM_NODE_SIZE_CHECK == YES)
|
||||
#define OS_MEM_CHECK_DEBUG
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_MEM_MUL_POOL
|
||||
extern VOID *g_memPoolHead;
|
||||
#endif
|
||||
typedef VOID (*MALLOC_HOOK)(VOID);
|
||||
|
||||
extern MALLOC_HOOK g_mallocHook;
|
||||
|
||||
/**
|
||||
* @ingroup los_memory
|
||||
* @brief Get the size of memory totally used.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to get the size of memory totally used in memory pool.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The input pool parameter must be initialized via func LOS_MemInit.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param pool [IN] A pointer pointed to the memory pool.
|
||||
*
|
||||
* @retval #LOS_NOK The incoming parameter pool is NULL.
|
||||
* @retval #UINT32 The size of the memory pool used.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_memory.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern UINT32 LOS_MemTotalUsedGet(VOID *pool);
|
||||
|
||||
/**
|
||||
* @ingroup los_memory
|
||||
* @brief Get the number of free memory nodes.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to get the number of free memory nodes in memory pool.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The input pool parameter must be initialized via func LOS_MemInit.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param pool [IN] A pointer pointed to the memory pool.
|
||||
*
|
||||
* @retval #LOS_NOK The incoming parameter pool is NULL.
|
||||
* @retval #UINT32 The number of free memory nodes.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_memory.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern UINT32 LOS_MemFreeBlksGet(VOID *pool);
|
||||
|
||||
/**
|
||||
* @ingroup los_memory
|
||||
* @brief Get the number of used memory nodes.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to get the number of used memory nodes in memory pool.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The input pool parameter must be initialized via func LOS_MemInit.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param pool [IN] A pointer pointed to the memory pool.
|
||||
*
|
||||
* @retval #LOS_NOK The incoming parameter pool is NULL.
|
||||
* @retval #UINT32 The number of used memory nodes.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_memory.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern UINT32 LOS_MemUsedBlksGet(VOID *pool);
|
||||
|
||||
/**
|
||||
* @ingroup los_memory
|
||||
* @brief Get the task ID of a used memory node.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to get the task ID of a used memory node.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The input ptr parameter must be allocated by LOS_MemAlloc or LOS_MemAllocAlign.</li>
|
||||
* <li>This interface only support obtain the task ID of a used memory node which is allocated from
|
||||
* the system memory pool (OS_SYS_MEM_ADDR) at present.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param pool [IN] A used memory node.
|
||||
*
|
||||
* @retval #OS_INVALID The incoming parameter ptr is illegal.
|
||||
* @retval #UINT32 The task ID of used memory node ptr.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_memory.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern UINT32 LOS_MemTaskIdGet(const VOID *pool);
|
||||
|
||||
/**
|
||||
* @ingroup los_memory
|
||||
* @brief Get the address of last node.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to get the address of last node.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The input pool parameter must be initialized via func LOS_MemInit.</li>
|
||||
* <li>The last node of memory pool is not the end node.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param pool [IN] A pointer pointed to the memory pool.
|
||||
*
|
||||
* @retval #LOS_NOK The incoming parameter pool is NULL.
|
||||
* @retval #UINT32 The address of the last used node that casts to UINT32.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_memory.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern UINT32 LOS_MemLastUsedGet(VOID *pool);
|
||||
|
||||
/**
|
||||
* @ingroup los_memory
|
||||
* @brief Check the memory pool Integrity.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to check the memory pool Integrity.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The input pool parameter must be initialized via func LOS_MemInit.</li>
|
||||
* <li>LOS_MemIntegrityCheck will be called by malloc function when the macro of LOSCFG_BASE_MEM_NODE_INTEGRITY_CHECK
|
||||
* is defined in LiteOS.</li>
|
||||
* <li>LOS_MemIntegrityCheck function can be called by user anytime.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param pool [IN] A pointer pointed to the memory pool.
|
||||
*
|
||||
* @retval #LOS_NOK The memory pool (pool) is impaired.
|
||||
* @retval #LOS_OK The memory pool (pool) is integrated.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_memory.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern UINT32 LOS_MemIntegrityCheck(VOID *pool);
|
||||
|
||||
/**
|
||||
* @ingroup los_memory
|
||||
* Define a mem size check intensity
|
||||
*
|
||||
* Lowest mem check.
|
||||
*/
|
||||
#define LOS_MEM_CHECK_LEVEL_LOW 0
|
||||
|
||||
/**
|
||||
* @ingroup los_memory
|
||||
* Define a mem size check intensity
|
||||
*
|
||||
* Highest mem check.
|
||||
*/
|
||||
#define LOS_MEM_CHECK_LEVEL_HIGH 1
|
||||
|
||||
/**
|
||||
* @ingroup los_memory
|
||||
* Define a mem size check intensity
|
||||
*
|
||||
* disable mem check.
|
||||
*/
|
||||
#define LOS_MEM_CHECK_LEVEL_DISABLE 0xff
|
||||
|
||||
/**
|
||||
* @ingroup los_memory
|
||||
* Define a mem size check intensity
|
||||
*
|
||||
* default intensity set mem check.
|
||||
*/
|
||||
#define LOS_MEM_CHECK_LEVEL_DEFAULT LOS_MEM_CHECK_LEVEL_DISABLE
|
||||
|
||||
/**
|
||||
* @ingroup los_memory
|
||||
* @brief Check the size of memory node specified.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to check the size of memory node.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The input pool parameter must be initialized via func LOS_MemInit.</li>
|
||||
* <li>The input ptr parameter must be allocated by LOS_MemAlloc or LOS_MemAllocAlign.</li>
|
||||
* <li>The function will be called by function specified, such as memset or memcpy.</li>
|
||||
* <li>The feature can be enabled when you set the macro value of LOSCFG_BASE_MEM_NODE_SIZE_CHECK as YES.</li>
|
||||
* <li>You had better set memory check level as LOS_MEM_CHECK_LEVEL_DISABLE when copy bin file.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param pool [IN] A pointer pointed to the memory pool.
|
||||
* @param ptr [IN] A pointer pointed to the source node.
|
||||
* @param totalSize [OUT] A pointer to save total size, must point to valid memory.
|
||||
* @param availSize [OUT] A pointer to save available size, must point to valid memory.
|
||||
*
|
||||
* @retval #OS_ERRNO_MEMCHECK_DISABLED Memcheck function does not open.
|
||||
* @retval #OS_ERRNO_MEMCHECK_NOT_INIT Memcheck function does not init.
|
||||
* @retval #OS_ERRNO_MEMCHECK_PARA_NULL The pool or ptr is NULL.
|
||||
* @retval #OS_ERRNO_MEMCHECK_OUTSIDE The ptr address is not in the reasonable range.
|
||||
* @retval #OS_ERRNO_MEMCHECK_NO_HEAD Can't find the control head node from ptr.
|
||||
* @retval #OS_ERRNO_MEMCHECK_WRONG_LEVEL The memory check level is illegal.
|
||||
* @retval #LOS_OK Success to get total size and available
|
||||
* size of the memory node (ptr).
|
||||
* @par Dependency:
|
||||
* <ul><li>los_memory.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_MemCheckLevelSet | LOS_MemCheckLevelGet
|
||||
*/
|
||||
extern UINT32 LOS_MemNodeSizeCheck(VOID *pool, VOID *ptr, UINT32 *totalSize, UINT32 *availSize);
|
||||
|
||||
/**
|
||||
* @ingroup los_memory
|
||||
* @brief Set the memory check level.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to set the memory check level.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>There are three level you can set.</li>
|
||||
* <li>The legal level are LOS_MEM_CHECK_LEVEL_LOW, LOS_MEM_CHECK_LEVEL_HIGH, LOS_MEM_CHECK_LEVEL_DISABLE.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param level [IN] The level what you want to set.
|
||||
*
|
||||
* @retval #LOS_ERRNO_MEMCHECK_WRONG_LEVEL The memory check level what you want to set is illegal.
|
||||
* @retval #LOS_OK Success to set the memory check level.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_memory.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_MemNodeSizeCheck | LOS_MemCheckLevelGet
|
||||
*/
|
||||
extern UINT32 LOS_MemCheckLevelSet(UINT8 level);
|
||||
|
||||
/**
|
||||
* @ingroup los_memory
|
||||
* @brief Get the memory check level.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to get the current memory check level.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param None
|
||||
*
|
||||
* @retval #UINT8 The current memory check level.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_memory.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_MemNodeSizeCheck | LOS_MemCheckLevelSet
|
||||
*/
|
||||
extern UINT8 LOS_MemCheckLevelGet(VOID);
|
||||
/**
|
||||
* @ingroup los_memory
|
||||
* @brief Get the memory pool information.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to get the current memory pool used information.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param pool [IN] A pointer pointed to the memory pool.
|
||||
* @param status [IN] A pointer for storage the pool status.
|
||||
*
|
||||
* @retval #LOS_OK Success to get the memory pool information.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_memory.h: the header file that contains the API declaration.</li></ul>
|
||||
*/
|
||||
extern UINT32 LOS_MemInfoGet(VOID *pool, LOS_MEM_STATUS *status);
|
||||
#else
|
||||
|
||||
/**
|
||||
* @ingroup los_memory
|
||||
* @brief calculate heap information.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to calculate heap information.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>One parameter of this interface is a pointer, it should be a correct value, otherwise,
|
||||
* the system may be abnormal.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param pool [IN] Pointer to the memory pool that contains the memory block to be allocated.
|
||||
* @param status [OUT] Type #LOS_MEM_STATUS* Pointer to the heap status structure to be obtained.
|
||||
*
|
||||
* @retval #LOS_OK The heap status calculate success.
|
||||
* @retval #LOS_NOK The heap status calculate with some error.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_memory.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_MemAlloc | LOS_MemRealloc | LOS_MemFree
|
||||
*/
|
||||
extern UINT32 LOS_MemStatisticsGet(VOID *pool, LOS_MEM_STATUS *status);
|
||||
|
||||
/**
|
||||
* @ingroup los_memory
|
||||
* @brief calculate heap max free block size.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to calculate heap max free block size.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param pool [IN] Pointer to memory pool.
|
||||
*
|
||||
* @retval #UINT32 The max free block size.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_memory.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_MemAlloc | LOS_MemRealloc | LOS_MemFree
|
||||
*/
|
||||
extern UINT32 LOS_MemGetMaxFreeBlkSize(VOID *pool);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_memory
|
||||
* @brief Initialize dynamic memory.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to initialize the dynamic memory of a doubly linked list.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The size parameter value should match the following two conditions : 1) Be less than or equal to
|
||||
* the Memory pool size; 2) Be greater than the size of OS_MEM_MIN_POOL_SIZE.</li>
|
||||
* <li>Call this API when dynamic memory needs to be initialized during the startup of Huawei LiteOS.</li>
|
||||
* <li>The parameter input must be four byte-aligned.</li>
|
||||
* <li>The init area [pool, pool + size] should not conflict with other pools.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param pool [IN] Starting address of memory.
|
||||
* @param size [IN] Memory size.
|
||||
*
|
||||
* @retval #LOS_NOK The dynamic memory fails to be initialized.
|
||||
* @retval #LOS_OK The dynamic memory is successfully initialized.
|
||||
* @par Dependency:
|
||||
* <ul>
|
||||
* <li>los_memory.h: the header file that contains the API declaration.</li>
|
||||
* </ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern UINT32 LOS_MemInit(VOID *pool, UINT32 size);
|
||||
|
||||
/**
|
||||
* @ingroup los_memory
|
||||
* @brief Allocate dynamic memory.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to allocate a memory block of which the size is specified.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The input pool parameter must be initialized via func LOS_MemInit.</li>
|
||||
* <li>The size of the input parameter size can not be greater than the memory pool size
|
||||
* that specified at the second input parameter of LOS_MemInit.</li>
|
||||
* <li>The size of the input parameter size must be four byte-aligned.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param pool [IN] Pointer to the memory pool that contains the memory block to be allocated.
|
||||
* @param size [IN] Size of the memory block to be allocated (unit: byte).
|
||||
*
|
||||
* @retval #NULL The memory fails to be allocated.
|
||||
* @retval #VOID* The memory is successfully allocated with the starting address of
|
||||
* the allocated memory block returned.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_memory.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_MemRealloc | LOS_MemAllocAlign | LOS_MemFree
|
||||
*/
|
||||
extern VOID *LOS_MemAlloc(VOID *pool, UINT32 size);
|
||||
|
||||
/**
|
||||
* @ingroup los_memory
|
||||
* @brief Free dynamic memory.
|
||||
*
|
||||
* @par Description:
|
||||
* <li>This API is used to free specified dynamic memory that has been allocated.</li>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The input pool parameter must be initialized via func LOS_MemInit.</li>
|
||||
* <li>The input mem parameter must be allocated by LOS_MemAlloc or LOS_MemAllocAlign or LOS_MemRealloc.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param pool [IN] Pointer to the memory pool that contains the dynamic memory block to be freed.
|
||||
* @param mem [IN] Starting address of the memory block to be freed.
|
||||
*
|
||||
* @retval #LOS_NOK The memory block fails to be freed
|
||||
* @retval #LOS_OK The memory block is successfully freed.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_memory.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_MemAlloc | LOS_MemRealloc | LOS_MemAllocAlign
|
||||
*/
|
||||
extern UINT32 LOS_MemFree(VOID *pool, VOID *mem);
|
||||
|
||||
/**
|
||||
* @ingroup los_memory
|
||||
* @brief Re-allocate a memory block.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to allocate a new memory block of which the size is specified by size if the original
|
||||
* memory block size is insufficient. The new memory block will copy the data in the original memory block of
|
||||
* which the address is specified by ptr. The size of the new memory block determines the maximum size of data
|
||||
* to be copied. After the new memory block is created, the original one is freed.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The input pool parameter must be initialized via func LOS_MemInit.</li>
|
||||
* <li>The input ptr parameter must be allocated by LOS_MemAlloc.</li>
|
||||
* <li>The size of the input parameter size can not be greater than the memory pool size that specified at the
|
||||
* second input parameter of LOS_MemInit.</li>
|
||||
* <li>The size of the input parameter size must be aligned as follows: 1) if the ptr is allocated by LOS_MemAlloc,
|
||||
* it must be four byte-aligned; 2) if the ptr is allocated by LOS_MemAllocAlign, it must be aligned with the size
|
||||
* of the input parameter uwBoundary of LOS_MemAllocAlign.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param pool [IN] Pointer to the memory pool that contains the original and new memory blocks.
|
||||
* @param ptr [IN] Address of the original memory block.
|
||||
* @param size [IN] Size of the new memory block.
|
||||
*
|
||||
* @retval #NULL The memory fails to be re-allocated.
|
||||
* @retval #VOID* The memory is successfully re-allocated with the starting address of the new memory block
|
||||
* returned.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_memory.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_MemAlloc | LOS_MemAllocAlign | LOS_MemFree
|
||||
*/
|
||||
extern VOID *LOS_MemRealloc(VOID *pool, VOID *ptr, UINT32 size);
|
||||
|
||||
/**
|
||||
* @ingroup los_memory
|
||||
* @brief Allocate aligned memory.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to allocate memory blocks of specified size and of which the starting addresses are aligned
|
||||
* on a specified boundary.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The input pool parameter must be initialized via func LOS_MemInit.</li>
|
||||
* <li>The size of the input parameter size can not be greater than the memory pool size that specified at the second
|
||||
* input parameter of LOS_MemInit.</li>
|
||||
* <li>The alignment parameter value must be a power of 2 with the minimum value being 4.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param pool [IN] Pointer to the memory pool that contains the memory blocks to be allocated.
|
||||
* @param size [IN] Size of the memory to be allocated.
|
||||
* @param boundary [IN] Boundary on which the memory is aligned.
|
||||
*
|
||||
* @retval #NULL The memory fails to be allocated.
|
||||
* @retval #VOID* The memory is successfully allocated with the starting address of the allocated memory
|
||||
* returned.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_memory.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_MemAlloc | LOS_MemRealloc | LOS_MemFree
|
||||
*/
|
||||
extern VOID *LOS_MemAllocAlign(VOID *pool, UINT32 size, UINT32 boundary);
|
||||
|
||||
#if (LOSCFG_MEM_MUL_POOL == YES)
|
||||
/**
|
||||
* @ingroup los_memory
|
||||
* @brief Deinitialize dynamic memory.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to deinitialize the dynamic memory of a doubly linked list.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param pool [IN] Starting address of memory.
|
||||
*
|
||||
* @retval #LOS_NOK The dynamic memory fails to be deinitialized.
|
||||
* @retval #LOS_OK The dynamic memory is successfully deinitialized.
|
||||
* @par Dependency:
|
||||
* <ul>
|
||||
* <li>los_memory.h: the header file that contains the API declaration.</li>
|
||||
* </ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern UINT32 LOS_MemDeInit(const VOID *pool);
|
||||
|
||||
/**
|
||||
* @ingroup los_memory
|
||||
* @brief Print infomation about all pools.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to print infomation about all pools.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @retval #UINT32 The pool number.
|
||||
* @par Dependency:
|
||||
* <ul>
|
||||
* <li>los_memory.h: the header file that contains the API declaration.</li>
|
||||
* </ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern UINT32 LOS_MemPoolList(VOID);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_MEMORY_H */
|
|
@ -0,0 +1,293 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup los_mux Mutex
|
||||
* @ingroup kernel
|
||||
*/
|
||||
|
||||
#ifndef _LOS_MUX_H
|
||||
#define _LOS_MUX_H
|
||||
|
||||
#include "los_base.h"
|
||||
#include "los_sys.h"
|
||||
#include "los_list.h"
|
||||
#include "los_task.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @ingroup los_mux
|
||||
* Mutex error code: The memory request fails.
|
||||
*
|
||||
* Value: 0x02001d00
|
||||
*
|
||||
* Solution: Decrease the number of mutexes defined by LOSCFG_BASE_IPC_MUX_LIMIT.
|
||||
*/
|
||||
#define LOS_ERRNO_MUX_NO_MEMORY LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x00)
|
||||
|
||||
/**
|
||||
* @ingroup los_mux
|
||||
* Mutex error code: The mutex is not usable.
|
||||
*
|
||||
* Value: 0x02001d01
|
||||
*
|
||||
* Solution: Check whether the mutex ID and the mutex state are applicable for the current operation.
|
||||
*/
|
||||
#define LOS_ERRNO_MUX_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x01)
|
||||
|
||||
/**
|
||||
* @ingroup los_mux
|
||||
* Mutex error code: Null pointer.
|
||||
*
|
||||
* Value: 0x02001d02
|
||||
*
|
||||
* Solution: Check whether the input parameter is usable.
|
||||
*/
|
||||
#define LOS_ERRNO_MUX_PTR_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x02)
|
||||
|
||||
/**
|
||||
* @ingroup los_mux
|
||||
* Mutex error code: No mutex is available and the mutex request fails.
|
||||
*
|
||||
* Value: 0x02001d03
|
||||
*
|
||||
* Solution: Increase the number of mutexes defined by LOSCFG_BASE_IPC_MUX_LIMIT.
|
||||
*/
|
||||
#define LOS_ERRNO_MUX_ALL_BUSY LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x03)
|
||||
|
||||
/**
|
||||
* @ingroup los_mux
|
||||
* Mutex error code: The mutex fails to be locked in non-blocking mode because it is locked by another thread.
|
||||
*
|
||||
* Value: 0x02001d04
|
||||
*
|
||||
* Solution: Lock the mutex after it is unlocked by the thread that owns it, or set a waiting time.
|
||||
*/
|
||||
#define LOS_ERRNO_MUX_UNAVAILABLE LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x04)
|
||||
|
||||
/**
|
||||
* @ingroup los_mux
|
||||
* Mutex error code: The mutex is being locked during an interrupt.
|
||||
*
|
||||
* Value: 0x02001d05
|
||||
*
|
||||
* Solution: Check whether the mutex is being locked during an interrupt.
|
||||
*/
|
||||
#define LOS_ERRNO_MUX_PEND_INTERR LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x05)
|
||||
|
||||
/**
|
||||
* @ingroup los_mux
|
||||
* Mutex error code: A thread locks a mutex after waiting for the mutex to be unlocked by another thread
|
||||
* when the task scheduling is disabled.
|
||||
*
|
||||
* Value: 0x02001d06
|
||||
*
|
||||
* Solution: Check whether the task scheduling is disabled, or set uwtimeout to 0, which means that the
|
||||
* thread will not wait for the mutex to become available.
|
||||
*/
|
||||
#define LOS_ERRNO_MUX_PEND_IN_LOCK LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x06)
|
||||
|
||||
/**
|
||||
* @ingroup los_mux
|
||||
* Mutex error code: The mutex locking times out.
|
||||
*
|
||||
* Value: 0x02001d07
|
||||
*
|
||||
* Solution: Increase the waiting time or set the waiting time to LOS_WAIT_FOREVER (forever-blocking mode).
|
||||
*/
|
||||
#define LOS_ERRNO_MUX_TIMEOUT LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x07)
|
||||
|
||||
/**
|
||||
* @ingroup los_mux
|
||||
*
|
||||
* Value: 0x02001d08
|
||||
* Not in use temporarily.
|
||||
*/
|
||||
#define LOS_ERRNO_MUX_OVERFLOW LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x08)
|
||||
|
||||
/**
|
||||
* @ingroup los_mux
|
||||
* Mutex error code: The mutex to be deleted is being locked.
|
||||
*
|
||||
* Value: 0x02001d09
|
||||
*
|
||||
* Solution: Delete the mutex after it is unlocked.
|
||||
*/
|
||||
#define LOS_ERRNO_MUX_PENDED LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x09)
|
||||
|
||||
/**
|
||||
* @ingroup los_mux
|
||||
*
|
||||
* Value: 0x02001d0A
|
||||
* Not in use temporarily.
|
||||
*/
|
||||
#define LOS_ERRNO_MUX_GET_COUNT_ERR LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x0A)
|
||||
|
||||
/**
|
||||
* @ingroup los_mux
|
||||
*
|
||||
* Value: 0x02001d0B
|
||||
* Not in use temporarily.
|
||||
*/
|
||||
#define LOS_ERRNO_MUX_REG_ERROR LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x0B)
|
||||
|
||||
/**
|
||||
* @ingroup los_mux
|
||||
*
|
||||
* Mutex error code: LOS_ERRNO_MUX_MAXNUM_ZERO is zero.
|
||||
* Value: 0x02001d0C
|
||||
*
|
||||
* Solution: LOS_ERRNO_MUX_MAXNUM_ZERO should not be zero.
|
||||
*/
|
||||
#define LOS_ERRNO_MUX_MAXNUM_ZERO LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x0C)
|
||||
|
||||
/**
|
||||
* @ingroup los_mux
|
||||
* @brief Create a mutex.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to create a mutex. A mutex handle is assigned to muxHandle when the mutex is created successfully.
|
||||
* Return LOS_OK on creating successful, return specific error code otherwise.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The total number of mutexes is pre-configured. If there are no available mutexes, the mutex creation fails.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param muxHandle [OUT] Handle pointer of the successfully created mutex. The value of handle should be in
|
||||
* [0, LOSCFG_BASE_IPC_MUX_LIMIT - 1].
|
||||
*
|
||||
* @retval #LOS_ERRNO_MUX_PTR_NULL The muxHandle pointer is NULL.
|
||||
* @retval #LOS_ERRNO_MUX_ALL_BUSY No available mutex.
|
||||
* @retval #LOS_OK The mutex is successfully created.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_mux.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_MuxDelete
|
||||
*/
|
||||
extern UINT32 LOS_MuxCreate(UINT32 *muxHandle);
|
||||
|
||||
/**
|
||||
* @ingroup los_mux
|
||||
* @brief Delete a mutex.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to delete a specified mutex. Return LOS_OK on deleting successfully, return specific error code
|
||||
* otherwise.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The specific mutex should be created firstly.</li>
|
||||
* <li>The mutex can be deleted successfully only if no other tasks pend on it.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param muxHandle [IN] Handle of the mutex to be deleted. The value of handle should be in
|
||||
* [0, LOSCFG_BASE_IPC_MUX_LIMIT - 1].
|
||||
*
|
||||
* @retval #LOS_ERRNO_MUX_INVALID Invalid handle or mutex in use.
|
||||
* @retval #LOS_ERRNO_MUX_PENDED Tasks pended on this mutex.
|
||||
* @retval #LOS_OK The mutex is successfully deleted.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_mux.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_MuxCreate
|
||||
*/
|
||||
extern UINT32 LOS_MuxDelete(UINT32 muxHandle);
|
||||
|
||||
/**
|
||||
* @ingroup los_mux
|
||||
* @brief Wait to lock a mutex.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to wait for a specified period of time to lock a mutex.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The specific mutex should be created firstly.</li>
|
||||
* <li>The function fails if the mutex that is waited on is already locked by another thread when the task scheduling
|
||||
* is disabled.</li>
|
||||
* <li>Do not wait on a mutex during an interrupt.</li>
|
||||
* <li>The priority inheritance protocol is supported. If a higher-priority thread is waiting on a mutex, it changes
|
||||
* the priority of the thread that owns the mutex to avoid priority inversion.</li>
|
||||
* <li>A recursive mutex can be locked more than once by the same thread.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param muxHandle [IN] Handle of the mutex to be waited on. The value of handle should be
|
||||
* in [0, LOSCFG_BASE_IPC_MUX_LIMIT - 1].
|
||||
* @param timeout [IN] Waiting time. The value range is [0, LOS_WAIT_FOREVER](unit: Tick).
|
||||
*
|
||||
* @retval #LOS_ERRNO_MUX_INVALID The mutex state (for example, the mutex does not exist or is not in use)
|
||||
* is not applicable for the current operation.
|
||||
* @retval #LOS_ERRNO_MUX_UNAVAILABLE The mutex fails to be locked because it is locked by another thread and
|
||||
* a period of time is not set for waiting for the mutex to become available.
|
||||
* @retval #LOS_ERRNO_MUX_PEND_INTERR The mutex is being locked during an interrupt.
|
||||
* @retval #LOS_ERRNO_MUX_PEND_IN_LOCK The mutex is waited on when the task scheduling is disabled.
|
||||
* @retval #LOS_ERRNO_MUX_TIMEOUT The mutex waiting times out.
|
||||
* @retval #LOS_OK The mutex is successfully locked.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_mux.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_MuxCreate | LOS_MuxPost
|
||||
*/
|
||||
extern UINT32 LOS_MuxPend(UINT32 muxHandle, UINT32 timeout);
|
||||
|
||||
/**
|
||||
* @ingroup los_mux
|
||||
* @brief Release a mutex.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to release a specified mutex.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The specific mutex should be created firstly.</li>
|
||||
* <li>Do not release a mutex during an interrupt.</li>
|
||||
* <li>If a recursive mutex is locked for many times, it must be unlocked for the same times to be released.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param muxHandle [IN] Handle of the mutex to be released. The value of handle should be in
|
||||
* [0, LOSCFG_BASE_IPC_MUX_LIMIT - 1].
|
||||
*
|
||||
* @retval #LOS_ERRNO_MUX_INVALID The mutex state (for example, the mutex does not exist or is not in use
|
||||
* or owned by other thread) is not applicable for the current operation.
|
||||
* @retval #LOS_ERRNO_MUX_PEND_INTERR The mutex is being released during an interrupt.
|
||||
* @retval #LOS_OK The mutex is successfully released.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_mux.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_MuxCreate | LOS_MuxPend
|
||||
*/
|
||||
extern UINT32 LOS_MuxPost(UINT32 muxHandle);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_MUX_H */
|
|
@ -0,0 +1,728 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup los_queue Queue
|
||||
* @ingroup kernel
|
||||
*/
|
||||
|
||||
#ifndef _LOS_QUEUE_H
|
||||
#define _LOS_QUEUE_H
|
||||
|
||||
#include "los_base.h"
|
||||
#include "los_list.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue error code: The maximum number of queue resources is configured to 0.
|
||||
*
|
||||
* Value: 0x02000600
|
||||
*
|
||||
* Solution: Configure the maximum number of queue resources to be greater than 0. If queue modules are not used,
|
||||
* set the configuration item for the tailoring of the maximum number of queue resources to NO.
|
||||
*/
|
||||
#define LOS_ERRNO_QUEUE_MAXNUM_ZERO LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x00)
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue error code: The queue block memory fails to be initialized.
|
||||
*
|
||||
* Value: 0x02000601
|
||||
*
|
||||
* Solution: Allocate the queue block bigger memory partition, or decrease the maximum number of queue resources.
|
||||
*/
|
||||
#define LOS_ERRNO_QUEUE_NO_MEMORY LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x01)
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue error code: The memory for queue creation fails to be requested.
|
||||
*
|
||||
* Value: 0x02000602
|
||||
*
|
||||
* Solution: Allocate more memory for queue creation, or decrease the queue length and the number of nodes
|
||||
* in the queue to be created.
|
||||
*/
|
||||
#define LOS_ERRNO_QUEUE_CREATE_NO_MEMORY LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x02)
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue error code: The size of the biggest message in the created queue is too big.
|
||||
*
|
||||
* Value: 0x02000603
|
||||
*
|
||||
* Solution: Change the size of the biggest message in the created queue.
|
||||
*/
|
||||
#define LOS_ERRNO_QUEUE_SIZE_TOO_BIG LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x03)
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue error code: The upper limit of the number of created queues is exceeded.
|
||||
*
|
||||
* Value: 0x02000604
|
||||
*
|
||||
* Solution: Increase the configured number of resources for queues.
|
||||
*/
|
||||
#define LOS_ERRNO_QUEUE_CB_UNAVAILABLE LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x04)
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue error code: Invalid queue.
|
||||
*
|
||||
* Value: 0x02000605
|
||||
*
|
||||
* Solution: Ensure that the passed-in queue ID is valid.
|
||||
*/
|
||||
#define LOS_ERRNO_QUEUE_NOT_FOUND LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x05)
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue error code: The task is forbidden to be blocked on a queue when the task is locked.
|
||||
*
|
||||
* Value: 0x02000606
|
||||
*
|
||||
* Solution: Unlock the task before using a queue.
|
||||
*/
|
||||
#define LOS_ERRNO_QUEUE_PEND_IN_LOCK LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x06)
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue error code: The time set for waiting to processing the queue expires.
|
||||
*
|
||||
* Value: 0x02000607
|
||||
*
|
||||
* Solution: Check whether the expiry time setting is appropriate.
|
||||
*/
|
||||
#define LOS_ERRNO_QUEUE_TIMEOUT LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x07)
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue error code: The queue that blocks a task cannot be deleted.
|
||||
*
|
||||
* Value: 0x02000608
|
||||
*
|
||||
* Solution: Enable the task to obtain resources rather than be blocked on the queue.
|
||||
*/
|
||||
#define LOS_ERRNO_QUEUE_IN_TSKUSE LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x08)
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue error code: The queue cannot be written during an interrupt when the time for waiting to
|
||||
* processing the queue expires.
|
||||
*
|
||||
* Value: 0x02000609
|
||||
*
|
||||
* Solution: Set the expiry time to the never-waiting mode, or use asynchronous queues.
|
||||
*/
|
||||
#define LOS_ERRNO_QUEUE_WRITE_IN_INTERRUPT LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x09)
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue error code: The queue is not created.
|
||||
*
|
||||
* Value: 0x0200060a
|
||||
*
|
||||
* Solution: Check whether the passed-in queue handle value is valid.
|
||||
*/
|
||||
#define LOS_ERRNO_QUEUE_NOT_CREATE LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x0a)
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue error code: Queue reading and writing are not synchronous.
|
||||
*
|
||||
* Value: 0x0200060b
|
||||
*
|
||||
* Solution: Synchronize queue reading with queue writing.
|
||||
*/
|
||||
#define LOS_ERRNO_QUEUE_IN_TSKWRITE LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x0b)
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue error code: Parameters passed in during queue creation are null pointers.
|
||||
*
|
||||
* Value: 0x0200060c
|
||||
*
|
||||
* Solution: Ensure the passed-in parameters are not null pointers.
|
||||
*/
|
||||
#define LOS_ERRNO_QUEUE_CREAT_PTR_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x0c)
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue error code: The queue length or message node size passed in during queue creation is 0.
|
||||
*
|
||||
* Value: 0x0200060d
|
||||
*
|
||||
* Solution: Pass in correct queue length and message node size.
|
||||
*/
|
||||
#define LOS_ERRNO_QUEUE_PARA_ISZERO LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x0d)
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue error code: The handle of the queue is invalid.
|
||||
*
|
||||
* Value: 0x0200060e
|
||||
*
|
||||
* Solution: Check whether the passed-in queue handle value is valid.
|
||||
*/
|
||||
#define LOS_ERRNO_QUEUE_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x0e)
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue error code: The pointer passed in during queue reading is null.
|
||||
*
|
||||
* Value: 0x0200060f
|
||||
*
|
||||
* Solution: Check whether the passed-in pointer is null.
|
||||
*/
|
||||
#define LOS_ERRNO_QUEUE_READ_PTR_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x0f)
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue error code: The buffer size passed in during queue reading is 0.
|
||||
*
|
||||
* Value: 0x02000610
|
||||
*
|
||||
* Solution: Pass in a correct buffer size.
|
||||
*/
|
||||
#define LOS_ERRNO_QUEUE_READSIZE_ISZERO LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x10)
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue error code: The pointer passed in during queue writing is null.
|
||||
*
|
||||
* Value: 0x02000612
|
||||
*
|
||||
* Solution: Check whether the passed-in pointer is null.
|
||||
*/
|
||||
#define LOS_ERRNO_QUEUE_WRITE_PTR_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x12)
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue error code: The buffer size passed in during queue writing is 0.
|
||||
*
|
||||
* Value: 0x02000613
|
||||
*
|
||||
* Solution: Pass in a correct buffer size.
|
||||
*/
|
||||
#define LOS_ERRNO_QUEUE_WRITESIZE_ISZERO LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x13)
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue error code: The buffer size passed in during queue writing is bigger than the queue size.
|
||||
*
|
||||
* Value: 0x02000615
|
||||
*
|
||||
* Solution: Decrease the buffer size, or use a queue in which nodes are bigger.
|
||||
*/
|
||||
#define LOS_ERRNO_QUEUE_WRITE_SIZE_TOO_BIG LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x15)
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue error code: No free node is available during queue writing.
|
||||
*
|
||||
* Value: 0x02000616
|
||||
*
|
||||
* Solution: Ensure that free nodes are available before queue writing.
|
||||
*/
|
||||
#define LOS_ERRNO_QUEUE_ISFULL LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x16)
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue error code: The pointer passed in when the queue information is being obtained is null.
|
||||
*
|
||||
* Value: 0x02000617
|
||||
*
|
||||
* Solution: Check whether the passed-in pointer is null.
|
||||
*/
|
||||
#define LOS_ERRNO_QUEUE_PTR_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x17)
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue error code: The queue cannot be read during an interrupt
|
||||
* when the time for waiting to processing the queue expires.
|
||||
*
|
||||
* Value: 0x02000618
|
||||
*
|
||||
* Solution: Set the expiry time to the never-waiting mode, or use asynchronous queues.
|
||||
*/
|
||||
#define LOS_ERRNO_QUEUE_READ_IN_INTERRUPT LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x18)
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue error code: The handle of the queue passed-in when the memory for the queue is being freed is invalid.
|
||||
*
|
||||
* Value: 0x02000619
|
||||
*
|
||||
* Solution: Check whether the passed-in queue handle value is valid.
|
||||
*/
|
||||
#define LOS_ERRNO_QUEUE_MAIL_HANDLE_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x19)
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue error code: The pointer to the memory to be freed is null.
|
||||
*
|
||||
* Value: 0x0200061a
|
||||
*
|
||||
* Solution: Check whether the passed-in pointer is null.
|
||||
*/
|
||||
#define LOS_ERRNO_QUEUE_MAIL_PTR_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x1a)
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue error code: The memory for the queue fails to be freed.
|
||||
*
|
||||
* Value: 0x0200061b
|
||||
*
|
||||
* Solution: Pass in correct input parameters.
|
||||
*/
|
||||
#define LOS_ERRNO_QUEUE_MAIL_FREE_ERROR LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x1b)
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue error code: No resource is in the queue that is being read when the
|
||||
* time for waiting to processing the queue expires.
|
||||
*
|
||||
* Value: 0x0200061d
|
||||
*
|
||||
* Solution: Ensure that the queue contains messages when it is being read.
|
||||
*/
|
||||
#define LOS_ERRNO_QUEUE_ISEMPTY LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x1d)
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Queue error code: The buffer size passed in during queue readding is smaller than the queue size.
|
||||
*
|
||||
* Value: 0x0200061f
|
||||
*
|
||||
* Solution: Increase the buffer size, or use a queue in which nodes are smaller.
|
||||
*/
|
||||
#define LOS_ERRNO_QUEUE_READ_SIZE_TOO_SMALL LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x1f)
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* Structure of the block for queue information query
|
||||
*/
|
||||
typedef struct tagQueueInfo {
|
||||
UINT32 queueID; /**< Queue ID */
|
||||
UINT16 queueLen; /**< Queue length */
|
||||
UINT16 queueSize; /**< Node size */
|
||||
UINT16 queueHead; /**< Node head */
|
||||
UINT16 queueTail; /**< Node tail */
|
||||
UINT16 writableCnt; /**< Count of writable resources */
|
||||
UINT16 readableCnt; /**< Count of readable resources */
|
||||
UINT32 waitReadTask; /**< Resource reading task */
|
||||
UINT32 waitWriteTask; /**< Resource writing task */
|
||||
UINT32 waitMemTask; /**< Memory task */
|
||||
} QUEUE_INFO_S;
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* @brief Create a message queue.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to create a message queue.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>Threre are LOSCFG_BASE_IPC_QUEUE_LIMIT queues available, change it's value when necessory.</li>
|
||||
* </ul>
|
||||
* @param queueName [IN] Message queue name. Reserved parameter, not used for now.
|
||||
* @param len [IN] Queue length. The value range is [1,0xffff].
|
||||
* @param queueID [OUT] ID of the queue control structure that is successfully created.
|
||||
* @param flags [IN] Queue mode. Reserved parameter, not used for now.
|
||||
* @param maxMsgSize [IN] Node size. The value range is [1,0xffff-4].
|
||||
*
|
||||
* @retval #LOS_OK The message queue is successfully created.
|
||||
* @retval #LOS_ERRNO_QUEUE_CB_UNAVAILABLE The upper limit of the number of created queues is exceeded.
|
||||
* @retval #LOS_ERRNO_QUEUE_CREATE_NO_MEMORY Insufficient memory for queue creation.
|
||||
* @retval #LOS_ERRNO_QUEUE_CREAT_PTR_NULL Null pointer, queueID is NULL.
|
||||
* @retval #LOS_ERRNO_QUEUE_PARA_ISZERO The queue length or message node size passed in during queue
|
||||
* creation is 0.
|
||||
* @retval #LOS_ERRNO_QUEUE_SIZE_TOO_BIG The parameter maxMsgSize is larger than 0xffff - 4.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_queue.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_QueueDelete
|
||||
*/
|
||||
extern UINT32 LOS_QueueCreate(CHAR *queueName,
|
||||
UINT16 len,
|
||||
UINT32 *queueID,
|
||||
UINT32 flags,
|
||||
UINT16 maxMsgSize);
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* @brief Read a queue.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to read data in a specified queue, and store the obtained data to the address specified
|
||||
* by bufferAddr. The address and the size of the data to be read are defined by users.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The specific queue should be created firstly.</li>
|
||||
* <li>Queue reading adopts the fist in first out (FIFO) mode. The data that is first stored in the queue is read
|
||||
* first.</li>
|
||||
* <li>bufferAddr stores the obtained data.</li>
|
||||
* <li>Do not read or write a queue in unblocking modes such as an interrupt.</li>
|
||||
* <li>This API cannot be called before the Huawei LiteOS is initialized.</li>
|
||||
* <li>The argument timeOut is a relative time.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param queueID [IN] Queue ID created by LOS_QueueCreate. The value range is
|
||||
* [1,LOSCFG_BASE_IPC_QUEUE_LIMIT].
|
||||
* @param bufferAddr [OUT] Starting address that stores the obtained data. The starting address must not be
|
||||
* null.
|
||||
* @param bufferSize [IN/OUT] Where to maintain the buffer wantted-size before read, and the real-size after read.
|
||||
* @param timeOut [IN] Expiry time. The value range is [0,LOS_WAIT_FOREVER](unit: Tick).
|
||||
*
|
||||
* @retval #LOS_OK The queue is successfully read.
|
||||
* @retval #LOS_ERRNO_QUEUE_INVALID The handle of the queue that is being read is invalid.
|
||||
* @retval #LOS_ERRNO_QUEUE_READ_PTR_NULL The pointer passed in during queue reading is null.
|
||||
* @retval #LOS_ERRNO_QUEUE_READSIZE_ISZERO The buffer size passed in during queue reading is 0.
|
||||
* @retval #LOS_ERRNO_QUEUE_READ_IN_INTERRUPT The queue cannot be read during an interrupt when the time for
|
||||
* waiting to processing the queue expires.
|
||||
* @retval #LOS_ERRNO_QUEUE_NOT_CREATE The queue to be read is not created.
|
||||
* @retval #LOS_ERRNO_QUEUE_ISEMPTY No resource is in the queue that is being read when the time for
|
||||
* waiting to processing the queue expires.
|
||||
* @retval #LOS_ERRNO_QUEUE_PEND_IN_LOCK The task is forbidden to be blocked on a queue when the task is
|
||||
* locked.
|
||||
* @retval #LOS_ERRNO_QUEUE_TIMEOUT The time set for waiting to processing the queue expires.
|
||||
* @retval #LOS_ERRNO_QUEUE_READ_SIZE_TOO_SMALL The buffer size passed in during queue reading is less than
|
||||
* the queue size.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_queue.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_QueueWriteCopy | LOS_QueueCreate
|
||||
*/
|
||||
extern UINT32 LOS_QueueReadCopy(UINT32 queueID,
|
||||
VOID *bufferAddr,
|
||||
UINT32 *bufferSize,
|
||||
UINT32 timeOut);
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* @brief Write data into a queue.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to write the data of the size specified by bufferSize and stored at the address specified by
|
||||
* bufferAddr into a queue.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The specific queue should be created firstly.</li>
|
||||
* <li>Do not read or write a queue in unblocking modes such as interrupt.</li>
|
||||
* <li>This API cannot be called before the Huawei LiteOS is initialized.</li>
|
||||
* <li>The data to be written is of the size specified by bufferSize and is stored at the address specified by
|
||||
* BufferAddr.</li>
|
||||
* <li>The argument timeOut is a relative time.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param queueID [IN] Queue ID created by LOS_QueueCreate. The value range is
|
||||
* [1,LOSCFG_BASE_IPC_QUEUE_LIMIT].
|
||||
* @param bufferAddr [IN] Starting address that stores the data to be written.The starting address must
|
||||
* not be null.
|
||||
* @param bufferSize [IN] Passed-in buffer size. The value range is [1,USHRT_MAX - sizeof(UINT32)].
|
||||
* @param timeOut [IN] Expiry time. The value range is [0,LOS_WAIT_FOREVER](unit: Tick).
|
||||
*
|
||||
* @retval #LOS_OK The data is successfully written into the queue.
|
||||
* @retval #LOS_ERRNO_QUEUE_INVALID The queue handle passed in during queue writing is invalid.
|
||||
* @retval #LOS_ERRNO_QUEUE_WRITE_PTR_NULL The pointer passed in during queue writing is null.
|
||||
* @retval #LOS_ERRNO_QUEUE_WRITESIZE_ISZERO The buffer size passed in during queue writing is 0.
|
||||
* @retval #LOS_ERRNO_QUEUE_WRITE_IN_INTERRUPT The queue cannot be written during an interrupt when the time
|
||||
* for waiting to processing the queue expires.
|
||||
* @retval #LOS_ERRNO_QUEUE_NOT_CREATE The queue into which the data is written is not created.
|
||||
* @retval #LOS_ERRNO_QUEUE_WRITE_SIZE_TOO_BIG The buffer size passed in during queue writing is bigger than
|
||||
* the queue size.
|
||||
* @retval #LOS_ERRNO_QUEUE_ISFULL No free node is available during queue writing.
|
||||
* @retval #LOS_ERRNO_QUEUE_PEND_IN_LOCK The task is forbidden to be blocked on a queue when
|
||||
* the task is locked.
|
||||
* @retval #LOS_ERRNO_QUEUE_TIMEOUT The time set for waiting to processing the queue expires.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_queue.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_QueueReadCopy | LOS_QueueCreate
|
||||
*/
|
||||
extern UINT32 LOS_QueueWriteCopy(UINT32 queueID,
|
||||
VOID *bufferAddr,
|
||||
UINT32 bufferSize,
|
||||
UINT32 timeOut);
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* @brief Read a queue.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to read the address of data in a specified queue, and store it to the address specified by
|
||||
* bufferAddr.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The specific queue should be created firstly.</li>
|
||||
* <li>Queue reading adopts the fist in first out (FIFO) mode. The data that is first stored in the queue is
|
||||
* read first.</li>
|
||||
* <li>bufferAddr stores the obtained data address.</li>
|
||||
* <li>Do not read or write a queue in unblocking modes such as an interrupt.</li>
|
||||
* <li>This API cannot be called before the Huawei LiteOS is initialized.</li>
|
||||
* <li>The argument timeOut is a relative time.</li>
|
||||
* <li>The bufferSize is not really used in LOS_QueueRead, because the interface is only used to
|
||||
* obtain the address of data.</li>
|
||||
* <li>The buffer which the bufferAddr pointing to must be greater than or equal to 4 bytes.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param queueID [IN] Queue ID created by LOS_QueueCreate. The value range is
|
||||
* [1,LOSCFG_BASE_IPC_QUEUE_LIMIT].
|
||||
* @param bufferAddr [OUT] Starting address that stores the obtained data. The starting address must
|
||||
* not be null.
|
||||
* @param bufferSize [IN] Passed-in buffer size, which must not be 0. The value range is [1,0xffffffff].
|
||||
* @param timeOut [IN] Expiry time. The value range is [0,LOS_WAIT_FOREVER](unit: Tick).
|
||||
*
|
||||
* @retval #LOS_OK The queue is successfully read.
|
||||
* @retval #LOS_ERRNO_QUEUE_INVALID The handle of the queue that is being read is invalid.
|
||||
* @retval #LOS_ERRNO_QUEUE_READ_PTR_NULL The pointer passed in during queue reading is null.
|
||||
* @retval #LOS_ERRNO_QUEUE_READSIZE_ISZERO The buffer size passed in during queue reading is 0.
|
||||
* @retval #LOS_ERRNO_QUEUE_READ_IN_INTERRUPT The queue cannot be read during an interrupt when the time for
|
||||
* waiting to processing the queue expires.
|
||||
* @retval #LOS_ERRNO_QUEUE_NOT_CREATE The queue to be read is not created.
|
||||
* @retval #LOS_ERRNO_QUEUE_ISEMPTY No resource is in the queue that is being read when the time for
|
||||
* waiting to processing the queue expires.
|
||||
* @retval #LOS_ERRNO_QUEUE_PEND_IN_LOCK The task is forbidden to be blocked on a queue when the task is
|
||||
* locked.
|
||||
* @retval #LOS_ERRNO_QUEUE_TIMEOUT The time set for waiting to processing the queue expires.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_queue.h: The header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_QueueWrite | LOS_QueueCreate
|
||||
*/
|
||||
extern UINT32 LOS_QueueRead(UINT32 queueID,
|
||||
VOID *bufferAddr,
|
||||
UINT32 bufferSize,
|
||||
UINT32 timeOut);
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* @brief Write data into a queue.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to write the address of data specified by bufferAddr into a queue.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The specific queue should be created firstly.</li>
|
||||
* <li>Do not read or write a queue in unblocking modes such as an interrupt.</li>
|
||||
* <li>This API cannot be called before the Huawei LiteOS is initialized.</li>
|
||||
* <li>The address of the data of the size specified by bufferSize and stored at the address specified by
|
||||
* BufferAddr is to be written.</li>
|
||||
* <li>The argument timeOut is a relative time.</li>
|
||||
* <li>The bufferSize is not really used in LOS_QueueWrite, because the interface is only used to write the address
|
||||
* of data specified by bufferAddr into a queue.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param queueID [IN] Queue ID created by LOS_QueueCreate. The value range is
|
||||
* [1,LOSCFG_BASE_IPC_QUEUE_LIMIT].
|
||||
* @param bufferAddr [IN] Starting address that stores the data to be written. The starting address
|
||||
* must not be null.
|
||||
* @param bufferSize [IN] Passed-in buffer size, which must not be 0. The value range is [1,0xffffffff].
|
||||
* @param timeOut [IN] Expiry time. The value range is [0,LOS_WAIT_FOREVER](unit: Tick).
|
||||
*
|
||||
* @retval #LOS_OK The data is successfully written into the queue.
|
||||
* @retval #LOS_ERRNO_QUEUE_INVALID The queue handle passed in during queue writing is invalid.
|
||||
* @retval #LOS_ERRNO_QUEUE_WRITE_PTR_NULL The pointer passed in during queue writing is null.
|
||||
* @retval #LOS_ERRNO_QUEUE_WRITESIZE_ISZERO The buffer size passed in during queue writing is 0.
|
||||
* @retval #LOS_ERRNO_QUEUE_WRITE_IN_INTERRUPT The queue cannot be written during an interrupt when the time for
|
||||
* waiting to processing the queue expires.
|
||||
* @retval #LOS_ERRNO_QUEUE_NOT_CREATE The queue into which the data is written is not created.
|
||||
* @retval #LOS_ERRNO_QUEUE_WRITE_SIZE_TOO_BIG The buffer size passed in during queue writing is bigger than
|
||||
* the queue size.
|
||||
* @retval #LOS_ERRNO_QUEUE_ISFULL No free node is available during queue writing.
|
||||
* @retval #LOS_ERRNO_QUEUE_PEND_IN_LOCK The task is forbidden to be blocked on a queue when the task is
|
||||
* locked.
|
||||
* @retval #LOS_ERRNO_QUEUE_TIMEOUT The time set for waiting to processing the queue expires.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_queue.h: The header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_QueueRead | LOS_QueueCreate
|
||||
*/
|
||||
extern UINT32 LOS_QueueWrite(UINT32 queueID,
|
||||
VOID *bufferAddr,
|
||||
UINT32 bufferSize,
|
||||
UINT32 timeOut);
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* @brief Write data into a queue header.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to write the data of the size specified by bufferSize and stored at the address specified by
|
||||
* bufferAddr into a queue header.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>Do not read or write a queue in unblocking modes such as an interrupt.</li>
|
||||
* <li>This API cannot be called before the Huawei LiteOS is initialized.</li>
|
||||
* <li>The address of the data of the size specified by bufferSize and stored at the address specified by
|
||||
* BufferAddr is to be written.</li>
|
||||
* <li>The argument timeOut is a relative time.</li>
|
||||
* <li>LOS_QueueRead and LOS_QueueWriteHead are a set of interfaces, and the two groups of interfaces need to be used.
|
||||
* <li>
|
||||
* </ul>
|
||||
*
|
||||
* @param queueID [IN] Queue ID created by LOS_QueueCreate. The value range is
|
||||
* [1,LOSCFG_BASE_IPC_QUEUE_LIMIT].
|
||||
* @param bufferAddr [OUT] Starting address that stores the data to be written. The starting address
|
||||
* must not be null.
|
||||
* @param bufferSize [IN] Passed-in buffer size, which must not be 0. The value range is [1,0xffffffff].
|
||||
* @param timeOut [IN] Expiry time. The value range is [0,LOS_WAIT_FOREVER](unit: Tick).
|
||||
*
|
||||
* @retval #LOS_OK The data is successfully written into the queue.
|
||||
* @retval #LOS_ERRNO_QUEUE_INVALID The queue handle passed in during queue writing is invalid.
|
||||
* @retval #LOS_ERRNO_QUEUE_WRITE_PTR_NULL The pointer passed in during queue writing is null.
|
||||
* @retval #LOS_ERRNO_QUEUE_WRITESIZE_ISZERO The buffer size passed in during queue writing is 0.
|
||||
* @retval #LOS_ERRNO_QUEUE_WRITE_IN_INTERRUPT The queue cannot be written during an interrupt when the time for
|
||||
* waiting to processing the queue expires.
|
||||
* @retval #LOS_ERRNO_QUEUE_NOT_CREATE The queue into which the data is written is not created.
|
||||
* @retval #LOS_ERRNO_QUEUE_WRITE_SIZE_TOO_BIG The buffer size passed in during queue writing is bigger than
|
||||
* the queue size.
|
||||
* @retval #LOS_ERRNO_QUEUE_ISFULL No free node is available during queue writing.
|
||||
* @retval #LOS_ERRNO_QUEUE_PEND_IN_LOCK The task is forbidden to be blocked on a queue when the task is
|
||||
* locked.
|
||||
* @retval #LOS_ERRNO_QUEUE_TIMEOUT The time set for waiting to processing the queue expires.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_queue.h: The header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_QueueRead | LOS_QueueCreate
|
||||
*/
|
||||
extern UINT32 LOS_QueueWriteHead(UINT32 queueID,
|
||||
VOID *bufferAddr,
|
||||
UINT32 bufferSize,
|
||||
UINT32 timeOut);
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* @brief Write data into a queue header.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to write the data of the size specified by bufferSize and stored at the address specified by
|
||||
* bufferAddr into a queue header.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>Do not read or write a queue in unblocking modes such as an interrupt.</li>
|
||||
* <li>This API cannot be called before the Huawei LiteOS is initialized.</li>
|
||||
* <li>The address of the data of the size specified by bufferSize and stored at the address specified by
|
||||
* BufferAddr is to be written.</li>
|
||||
* <li>The argument timeOut is a relative time.</li>
|
||||
* <li>LOS_QueueRead and LOS_QueueWriteHead are a set of interfaces, and the two groups of interfaces need to be
|
||||
* used.<li>
|
||||
* </ul>
|
||||
*
|
||||
* @param queueID [IN] Queue ID created by LOS_QueueCreate. The value range is
|
||||
* [1,LOSCFG_BASE_IPC_QUEUE_LIMIT].
|
||||
* @param bufferAddr [OUT] Starting address that stores the data to be written.
|
||||
* The starting address must not be null.
|
||||
* @param bufferSize [IN] Passed-in buffer size, which must not be 0. The value range is [1,0xffffffff].
|
||||
* @param timeOut [IN] Expiry time. The value range is [0,LOS_WAIT_FOREVER](unit: Tick).
|
||||
*
|
||||
* @retval #LOS_OK The data is successfully written into the queue.
|
||||
* @retval #LOS_ERRNO_QUEUE_INVALID The queue handle passed in during queue writing is invalid.
|
||||
* @retval #LOS_ERRNO_QUEUE_WRITE_PTR_NULL The pointer passed in during queue writing is null.
|
||||
* @retval #LOS_ERRNO_QUEUE_WRITESIZE_ISZERO The buffer size passed in during queue writing is 0.
|
||||
* @retval #LOS_ERRNO_QUEUE_WRITE_IN_INTERRUPT The queue cannot be written during an interrupt when the time for
|
||||
* waiting to processing the queue expires.
|
||||
* @retval #LOS_ERRNO_QUEUE_NOT_CREATE The queue into which the data is written is not created.
|
||||
* @retval #LOS_ERRNO_QUEUE_WRITE_SIZE_TOO_BIG The buffer size passed in during queue writing is bigger than
|
||||
* the queue size.
|
||||
* @retval #LOS_ERRNO_QUEUE_ISFULL No free node is available during queue writing.
|
||||
* @retval #LOS_ERRNO_QUEUE_PEND_IN_LOCK The task is forbidden to be blocked on a queue when the task is
|
||||
* locked.
|
||||
* @retval #LOS_ERRNO_QUEUE_TIMEOUT The time set for waiting to processing the queue expires.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_queue.h: The header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_QueueWrite | LOS_QueueWriteHead
|
||||
*/
|
||||
extern UINT32 LOS_QueueWriteHeadCopy(UINT32 queueID,
|
||||
VOID *bufferAddr,
|
||||
UINT32 bufferSize,
|
||||
UINT32 timeOut);
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* @brief Delete a queue.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to delete a queue.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>This API cannot be used to delete a queue that is not created.</li>
|
||||
* <li>A synchronous queue fails to be deleted if any tasks are blocked on it, or some queues are being read or
|
||||
* written.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param queueID [IN] Queue ID created by LOS_QueueCreate. The value range is
|
||||
* [1,LOSCFG_BASE_IPC_QUEUE_LIMIT].
|
||||
*
|
||||
* @retval #LOS_OK The queue is successfully deleted.
|
||||
* @retval #LOS_ERRNO_QUEUE_NOT_FOUND The queue cannot be found.
|
||||
* @retval #LOS_ERRNO_QUEUE_NOT_CREATE The queue handle passed in when the queue is being deleted is
|
||||
* incorrect.
|
||||
* @retval #LOS_ERRNO_QUEUE_IN_TSKUSE The queue that blocks a task cannot be deleted.
|
||||
* @retval #LOS_ERRNO_QUEUE_IN_TSKWRITE Queue reading and writing are not synchronous.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_queue.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_QueueCreate | LOS_QueueCreate
|
||||
*/
|
||||
extern UINT32 LOS_QueueDelete(UINT32 queueID);
|
||||
|
||||
/**
|
||||
* @ingroup los_queue
|
||||
* @brief Obtain queue information.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to obtain queue information.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The specific queue should be created firstly.</li>
|
||||
* </ul>
|
||||
* @param queueID [IN] Queue ID created by LOS_QueueCreate. The value range is
|
||||
* [1,LOSCFG_BASE_IPC_QUEUE_LIMIT].
|
||||
* @param queueInfo [OUT] The queue information to be read must not be null.
|
||||
*
|
||||
* @retval #LOS_OK The queue information is successfully obtained.
|
||||
* @retval #LOS_ERRNO_QUEUE_PTR_NULL The pointer to the queue information to be obtained is null.
|
||||
* @retval #LOS_ERRNO_QUEUE_INVALID The handle of the queue that is being read is invalid.
|
||||
* @retval #LOS_ERRNO_QUEUE_NOT_CREATE The queue in which the information to be obtained is stored is
|
||||
* not created.
|
||||
*
|
||||
* @par Dependency:
|
||||
* <ul><li>los_queue.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_QueueCreate
|
||||
*/
|
||||
extern UINT32 LOS_QueueInfoGet(UINT32 queueID, QUEUE_INFO_S *queueInfo);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_QUEUE_H */
|
|
@ -0,0 +1,297 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup los_sem Semaphore
|
||||
* @ingroup kernel
|
||||
*/
|
||||
|
||||
#ifndef _LOS_SEM_H
|
||||
#define _LOS_SEM_H
|
||||
|
||||
#include "los_base.h"
|
||||
#include "los_err.h"
|
||||
#include "los_list.h"
|
||||
#include "los_task.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @ingroup los_sem
|
||||
* Semaphore error code: The memory is insufficient.
|
||||
*
|
||||
* Value: 0x02000700
|
||||
*
|
||||
* Solution: Allocate more memory.
|
||||
*/
|
||||
#define LOS_ERRNO_SEM_NO_MEMORY LOS_ERRNO_OS_ERROR(LOS_MOD_SEM, 0x00)
|
||||
|
||||
/**
|
||||
* @ingroup los_sem
|
||||
* Semaphore error code: Invalid parameter.
|
||||
*
|
||||
* Value: 0x02000701
|
||||
*
|
||||
* Solution: Change the passed-in invalid parameter value to a valid value.
|
||||
*/
|
||||
#define LOS_ERRNO_SEM_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_SEM, 0x01)
|
||||
|
||||
/**
|
||||
* @ingroup los_sem
|
||||
* Semaphore error code: Null pointer.
|
||||
*
|
||||
* Value: 0x02000702
|
||||
*
|
||||
* Solution: Change the passed-in null pointer to a valid non-null pointer.
|
||||
*/
|
||||
#define LOS_ERRNO_SEM_PTR_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_SEM, 0x02)
|
||||
|
||||
/**
|
||||
* @ingroup los_sem
|
||||
* Semaphore error code: No semaphore control structure is available.
|
||||
*
|
||||
* Value: 0x02000703
|
||||
*
|
||||
* Solution: Perform corresponding operations based on the requirements in the code context.
|
||||
*/
|
||||
#define LOS_ERRNO_SEM_ALL_BUSY LOS_ERRNO_OS_ERROR(LOS_MOD_SEM, 0x03)
|
||||
|
||||
/**
|
||||
* @ingroup los_sem
|
||||
* Semaphore error code: Invalid parameter that specifies the timeout interval.
|
||||
*
|
||||
* Value: 0x02000704
|
||||
*
|
||||
*
|
||||
* Solution: Change the passed-in parameter value to a valid nonzero value.
|
||||
*/
|
||||
#define LOS_ERRNO_SEM_UNAVAILABLE LOS_ERRNO_OS_ERROR(LOS_MOD_SEM, 0x04)
|
||||
|
||||
/**
|
||||
* @ingroup los_sem
|
||||
* Semaphore error code: The API is called during an interrupt, which is forbidden.
|
||||
*
|
||||
* Value: 0x02000705
|
||||
*
|
||||
* Solution: Do not call the API during an interrupt.
|
||||
*/
|
||||
#define LOS_ERRNO_SEM_PEND_INTERR LOS_ERRNO_OS_ERROR(LOS_MOD_SEM, 0x05)
|
||||
|
||||
/**
|
||||
* @ingroup los_sem
|
||||
* Semaphore error code: The task is unable to request a semaphore because task scheduling is locked.
|
||||
*
|
||||
* Value: 0x02000706
|
||||
*
|
||||
* Solution: Do not call LOS_SemPend when task scheduling is locked.
|
||||
*/
|
||||
#define LOS_ERRNO_SEM_PEND_IN_LOCK LOS_ERRNO_OS_ERROR(LOS_MOD_SEM, 0x06)
|
||||
|
||||
/**
|
||||
* @ingroup los_sem
|
||||
* Semaphore error code: The request for a semaphore times out.
|
||||
*
|
||||
* Value: 0x02000707
|
||||
*
|
||||
* Solution: Change the passed-in parameter value to the value within the valid range.
|
||||
*/
|
||||
#define LOS_ERRNO_SEM_TIMEOUT LOS_ERRNO_OS_ERROR(LOS_MOD_SEM, 0x07)
|
||||
|
||||
/**
|
||||
* @ingroup los_sem
|
||||
* Semaphore error code: The times of semaphore release exceed the maximum times permitted.
|
||||
*
|
||||
* Value: 0x02000708
|
||||
*
|
||||
* Solution: Perform corresponding operations based on the requirements in the code context.
|
||||
*/
|
||||
#define LOS_ERRNO_SEM_OVERFLOW LOS_ERRNO_OS_ERROR(LOS_MOD_SEM, 0x08)
|
||||
|
||||
/**
|
||||
* @ingroup los_sem
|
||||
* Semaphore error code: The queue of the tasks that are waiting on the semaphore control structure is not null.
|
||||
*
|
||||
* Value: 0x02000709
|
||||
*
|
||||
* Solution: Delete the semaphore after awaking all tasks that are waiting on the semaphore.
|
||||
*/
|
||||
#define LOS_ERRNO_SEM_PENDED LOS_ERRNO_OS_ERROR(LOS_MOD_SEM, 0x09)
|
||||
|
||||
/**
|
||||
* @ingroup los_sem
|
||||
* Semaphore error code: LOS_ERRNO_SEM_MAXNUM_ZERO is error.
|
||||
*
|
||||
* Value: 0x0200070A
|
||||
*
|
||||
* Solution: LOS_ERRNO_SEM_MAXNUM_ZERO should not be error.
|
||||
*/
|
||||
#define LOS_ERRNO_SEM_MAXNUM_ZERO LOS_ERRNO_OS_ERROR(LOS_MOD_SEM, 0x0A)
|
||||
|
||||
/**
|
||||
* @ingroup los_sem
|
||||
* @brief Create a Counting semaphore.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to create a semaphore control structure according to the initial number of available semaphores
|
||||
* specified by count and return the ID of this semaphore control structure.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param count [IN] Initial number of available semaphores. The value range is [0, OS_SEM_COUNTING_MAX_COUNT).
|
||||
* @param semHandle [OUT] ID of the semaphore control structure that is initialized.
|
||||
*
|
||||
* @retval #LOS_ERRNO_SEM_PTR_NULL The passed-in semHandle value is NULL.
|
||||
* @retval #LOS_ERRNO_SEM_OVERFLOW The passed-in count value is greater than the maximum number of available
|
||||
* semaphores.
|
||||
* @retval #LOS_ERRNO_SEM_ALL_BUSY No semaphore control structure is available.
|
||||
* @retval #LOS_OK The semaphore is successfully created.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_sem.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_SemDelete
|
||||
*/
|
||||
extern UINT32 LOS_SemCreate(UINT16 count, UINT32 *semHandle);
|
||||
|
||||
/**
|
||||
* @ingroup los_sem
|
||||
* @brief Create a binary semaphore.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to create a binary semaphore control structure according to the initial number of available
|
||||
* semaphores specified by count and return the ID of this semaphore control structure.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param count [IN] Initial number of available semaphores. The value range is [0, 1].
|
||||
* @param semHandle [OUT] ID of the semaphore control structure that is initialized.
|
||||
*
|
||||
* @retval #LOS_ERRNO_SEM_PTR_NULL The passed-in semHandle value is NULL.
|
||||
* @retval #LOS_ERRNO_SEM_OVERFLOW The passed-in count value is greater than the maximum number of available
|
||||
* semaphores.
|
||||
* @retval #LOS_ERRNO_SEM_ALL_BUSY No semaphore control structure is available.
|
||||
* @retval #LOS_OK The semaphore is successfully created.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_sem.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_SemDelete
|
||||
*/
|
||||
extern UINT32 LOS_BinarySemCreate(UINT16 count, UINT32 *semHandle);
|
||||
|
||||
/**
|
||||
* @ingroup los_sem
|
||||
* @brief Delete a semaphore.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to delete a semaphore control structure that has an ID specified by semHandle.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The specified sem id must be created first. </li>
|
||||
* </ul>
|
||||
*
|
||||
* @param semHandle [IN] ID of the semaphore control structure to be deleted. The ID of the semaphore
|
||||
* control structure is obtained from semaphore creation.
|
||||
*
|
||||
* @retval #LOS_ERRNO_SEM_INVALID The passed-in semHandle value is invalid.
|
||||
* @retval #LOS_ERRNO_SEM_PENDED The queue of the tasks that are waiting on the semaphore control structure is
|
||||
* not null.
|
||||
* @retval #LOS_OK The semaphore control structure is successfully deleted.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_sem.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_SemCreate
|
||||
*/
|
||||
extern UINT32 LOS_SemDelete(UINT32 semHandle);
|
||||
|
||||
/**
|
||||
* @ingroup los_sem
|
||||
* @brief Request a semaphore.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to request a semaphore based on the semaphore control structure ID specified by semHandle and the
|
||||
* parameter that specifies the timeout period.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The specified sem id must be created first. </li>
|
||||
* </ul>
|
||||
*
|
||||
* @param semHandle [IN] ID of the semaphore control structure to be requested. The ID of the semaphore control
|
||||
* structure is obtained from semaphore creation.
|
||||
* @param timeout [IN] Timeout interval for waiting on the semaphore. The value range is [0, 0xFFFFFFFF].
|
||||
* If the value is set to 0, the semaphore is not waited on. If the value is set to 0xFFFFFFFF,
|
||||
* the semaphore is waited on forever(unit: Tick).
|
||||
*
|
||||
* @retval #LOS_ERRNO_SEM_INVALID The passed-in semHandle value is invalid.
|
||||
* @retval #LOS_ERRNO_SEM_UNAVAILABLE There is no available semaphore resource.
|
||||
* @retval #LOS_ERRNO_SEM_PEND_INTERR The API is called during an interrupt, which is forbidden.
|
||||
* @retval #LOS_ERRNO_SEM_PEND_IN_LOCK The task is unable to request a semaphore because task scheduling is locked.
|
||||
* @retval #LOS_ERRNO_SEM_TIMEOUT The request for the semaphore times out.
|
||||
* @retval #LOS_OK The semaphore request succeeds.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_sem.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_SemPost | LOS_SemCreate
|
||||
*/
|
||||
extern UINT32 LOS_SemPend(UINT32 semHandle, UINT32 timeout);
|
||||
|
||||
/**
|
||||
* @ingroup los_sem
|
||||
* @brief Release a semaphore.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to release a semaphore that has a semaphore control structure ID specified by semHandle.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The specified sem id must be created first. </li>
|
||||
* </ul>
|
||||
*
|
||||
* @param semHandle [IN] ID of the semaphore control structure to be released.The ID of the semaphore control
|
||||
* structure is obtained from semaphore creation.
|
||||
*
|
||||
* @retval #LOS_ERRNO_SEM_INVALID The passed-in semHandle value is invalid.
|
||||
* @retval #LOS_ERRNO_SEM_OVERFLOW The times of semaphore release exceed the maximum times permitted.
|
||||
* @retval #LOS_OK The semaphore is successfully released.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_sem.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_SemPend | LOS_SemCreate
|
||||
*/
|
||||
extern UINT32 LOS_SemPost(UINT32 semHandle);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_SEM_H */
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup los_slab Slab
|
||||
* @ingroup kernel
|
||||
*/
|
||||
|
||||
#ifndef _LOS_SLAB_H
|
||||
#define _LOS_SLAB_H
|
||||
|
||||
#include <los_typedef.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
// number of slab class
|
||||
#define SLAB_MEM_COUNT 4
|
||||
|
||||
// step size of each class
|
||||
#define SLAB_MEM_CALSS_STEP_SIZE 0x10
|
||||
|
||||
// max size of each class
|
||||
#define SLAB_MEM_ALLOCATOR_SIZE 512
|
||||
|
||||
#define SLAB_BASIC_NEED_SIZE 0x1000
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,442 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup los_swtmr Software timer
|
||||
* @ingroup kernel
|
||||
*/
|
||||
|
||||
#ifndef _LOS_SWTMR_H
|
||||
#define _LOS_SWTMR_H
|
||||
|
||||
#include "los_base.h"
|
||||
#include "los_task.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* Software timer error code: The timeout handling function is NULL.
|
||||
*
|
||||
* Value: 0x02000300
|
||||
*
|
||||
* Solution: Define the timeout handling function.
|
||||
*/
|
||||
#define LOS_ERRNO_SWTMR_PTR_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x00)
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* Software timer error code: The expiration time is 0.
|
||||
*
|
||||
* Value: 0x02000301
|
||||
*
|
||||
* Solution: Re-define the expiration time.
|
||||
*/
|
||||
#define LOS_ERRNO_SWTMR_INTERVAL_NOT_SUITED LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x01)
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* Software timer error code: Invalid software timer mode.
|
||||
*
|
||||
* Value: 0x02000302
|
||||
*
|
||||
* Solution: Check the mode value. The value range is [0,3].
|
||||
*/
|
||||
#define LOS_ERRNO_SWTMR_MODE_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x02)
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* Software timer error code: The passed-in software timer ID is NULL.
|
||||
*
|
||||
* Value: 0x02000303
|
||||
*
|
||||
* Solution: Define the software timer ID before passing it in.
|
||||
*/
|
||||
#define LOS_ERRNO_SWTMR_RET_PTR_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x03)
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* Software timer error code: The number of software timers exceeds the configured permitted maximum number.
|
||||
*
|
||||
* Value: 0x02000304
|
||||
*
|
||||
* Solution: Re-configure the permitted maximum number of software timers, or wait for a software timer to become
|
||||
* available.
|
||||
*/
|
||||
#define LOS_ERRNO_SWTMR_MAXSIZE LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x04)
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* Software timer error code: Invalid software timer ID.
|
||||
*
|
||||
* Value: 0x02000305
|
||||
*
|
||||
* Solution: Pass in a valid software timer ID.
|
||||
*/
|
||||
#define LOS_ERRNO_SWTMR_ID_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x05)
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* Software timer error code: The software timer is not created.
|
||||
*
|
||||
* Value: 0x02000306
|
||||
*
|
||||
* Solution: Create a software timer.
|
||||
*/
|
||||
#define LOS_ERRNO_SWTMR_NOT_CREATED LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x06)
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* Software timer error code: Insufficient memory for software timer linked list creation.
|
||||
*
|
||||
* Value: 0x02000307
|
||||
*
|
||||
* Solution: Allocate bigger memory partition to software timer linked list creation.
|
||||
*/
|
||||
#define LOS_ERRNO_SWTMR_NO_MEMORY LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x07)
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* Software timer error code: Invalid configured number of software timers.
|
||||
*
|
||||
* Value: 0x02000308
|
||||
*
|
||||
* Solution: Re-configure the number of software timers.
|
||||
*/
|
||||
#define LOS_ERRNO_SWTMR_MAXSIZE_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x08)
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* Software timer error code: The software timer is being used during an interrupt.
|
||||
*
|
||||
* Value: 0x02000309
|
||||
*
|
||||
* Solution: Change the source code and do not use the software timer during an interrupt.
|
||||
*/
|
||||
#define LOS_ERRNO_SWTMR_HWI_ACTIVE LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x09)
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* Software timer error code: Insufficient memory allocated by membox.
|
||||
*
|
||||
* Value: 0x0200030a
|
||||
*
|
||||
* Solution: Expand the memory allocated by membox.
|
||||
*/
|
||||
#define LOS_ERRNO_SWTMR_HANDLER_POOL_NO_MEM LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x0a)
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* Software timer error code: The software timer queue fails to be created.
|
||||
*
|
||||
* Value: 0x0200030b
|
||||
*
|
||||
* Solution: Check whether more memory can be allocated to the queue to be created.
|
||||
*/
|
||||
#define LOS_ERRNO_SWTMR_QUEUE_CREATE_FAILED LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x0b)
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* Software timer error code: The software timer task fails to be created.
|
||||
*
|
||||
* Value: 0x0200030c
|
||||
*
|
||||
* Solution: Check whether the memory is sufficient and re-create the task.
|
||||
*/
|
||||
#define LOS_ERRNO_SWTMR_TASK_CREATE_FAILED LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x0c)
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* Software timer error code: The software timer is not started.
|
||||
*
|
||||
* Value: 0x0200030d
|
||||
*
|
||||
* Solution: Start the software timer.
|
||||
*/
|
||||
#define LOS_ERRNO_SWTMR_NOT_STARTED LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x0d)
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* Software timer error code: Invalid software timer state.
|
||||
*
|
||||
* Value: 0x0200030e
|
||||
*
|
||||
* Solution: Check the software timer state.
|
||||
*/
|
||||
#define LOS_ERRNO_SWTMR_STATUS_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x0e)
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* This error code is not in use temporarily.
|
||||
*/
|
||||
#define LOS_ERRNO_SWTMR_SORTLIST_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x0f)
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* Software timer error code: The passed-in number of remaining Ticks configured on the software timer is NULL.
|
||||
*
|
||||
* Value: 0x02000310
|
||||
*
|
||||
* Solution: Define a variable of the number of remaining Ticks before passing in the number of remaining Ticks.
|
||||
*/
|
||||
#define LOS_ERRNO_SWTMR_TICK_PTR_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x10)
|
||||
|
||||
#if (LOSCFG_BASE_CORE_SWTMR_ALIGN == YES)
|
||||
#define OS_ERRNO_SWTMR_ROUSES_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x11)
|
||||
#define OS_ERRNO_SWTMR_ALIGN_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x12)
|
||||
|
||||
enum enSwTmrRousesType {
|
||||
OS_SWTMR_ROUSES_IGNORE, /* timer don't need to wake up system */
|
||||
OS_SWTMR_ROUSES_ALLOW, /* timer can wake up system */
|
||||
};
|
||||
|
||||
enum enSwTmrAlignSensitive {
|
||||
OS_SWTMR_ALIGN_SENSITIVE, /* timer don't need to align */
|
||||
OS_SWTMR_ALIGN_INSENSITIVE, /* timer need to align */
|
||||
};
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* Software timer mode
|
||||
*/
|
||||
enum EnSwTmrType {
|
||||
LOS_SWTMR_MODE_ONCE, /* One-off software timer */
|
||||
LOS_SWTMR_MODE_PERIOD, /* Periodic software timer */
|
||||
LOS_SWTMR_MODE_NO_SELFDELETE, /* One-off software timer, but not self-delete */
|
||||
LOS_SWTMR_MODE_OPP, /* After the one-off timer finishes timing,
|
||||
the periodic software timer is enabled.
|
||||
This mode is not supported temporarily. */
|
||||
};
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* @brief Define the type of a callback function that handles software timer timeout.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to define the type of a callback function that handles software timer timeout, so that it can be
|
||||
* called when software timer timeout.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param para [IN] the parameter of the callback function that handles software timer timeout.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_swtmr.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
typedef VOID (*SWTMR_PROC_FUNC)(UINT32 para);
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* Software timer control structure
|
||||
*/
|
||||
typedef struct tagSwTmrCtrl {
|
||||
struct tagSwTmrCtrl *pstNext; /* Pointer to the next software timer */
|
||||
UINT8 ucState; /* Software timer state */
|
||||
UINT8 ucMode; /* Software timer mode */
|
||||
#if (LOSCFG_BASE_CORE_SWTMR_ALIGN == YES)
|
||||
UINT8 ucRouses; /* wake up enable */
|
||||
UINT8 ucSensitive; /* align enable */
|
||||
#endif
|
||||
UINT16 usTimerID; /* Software timer ID */
|
||||
UINT32 uwCount; /* Times that a software timer works */
|
||||
UINT32 uwInterval; /* Timeout interval of a periodic software timer */
|
||||
UINT32 uwArg; /* Parameter passed in when the callback function
|
||||
that handles software timer timeout is called */
|
||||
SWTMR_PROC_FUNC pfnHandler; /* Callback function that handles software timer timeout */
|
||||
} SWTMR_CTRL_S;
|
||||
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* @brief Start a software timer.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to start a software timer that has a specified ID.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The specific timer must be created first</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param swtmrID [IN] Software timer ID created by LOS_SwtmrCreate. The value of ID should be in
|
||||
* [0, LOSCFG_BASE_CORE_SWTMR_LIMIT - 1].
|
||||
*
|
||||
* @retval #LOS_ERRNO_SWTMR_ID_INVALID Invalid software timer ID.
|
||||
* @retval #LOS_ERRNO_SWTMR_NOT_CREATED The software timer is not created.
|
||||
* @retval #LOS_ERRNO_SWTMR_STATUS_INVALID Invalid software timer state.
|
||||
* @retval #LOS_OK The software timer is successfully started.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_swtmr.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_SwtmrStop | LOS_SwtmrCreate
|
||||
*/
|
||||
extern UINT32 LOS_SwtmrStart(UINT16 swtmrID);
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* @brief Stop a software timer.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to stop a software timer that has a specified ID.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The specific timer should be created and started firstly.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param swtmrID [IN] Software timer ID created by LOS_SwtmrCreate. The value of ID should be in
|
||||
* [0, LOSCFG_BASE_CORE_SWTMR_LIMIT - 1].
|
||||
*
|
||||
* @retval #LOS_ERRNO_SWTMR_ID_INVALID Invalid software timer ID.
|
||||
* @retval #LOS_ERRNO_SWTMR_NOT_CREATED The software timer is not created.
|
||||
* @retval #LOS_ERRNO_SWTMR_NOT_STARTED The software timer is not started.
|
||||
* @retval #LOS_ERRNO_SWTMR_STATUS_INVALID Invalid software timer state.
|
||||
* @retval #LOS_OK The software timer is successfully stopped.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_swtmr.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_SwtmrStart | LOS_SwtmrCreate
|
||||
*/
|
||||
extern UINT32 LOS_SwtmrStop(UINT16 swtmrID);
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* @brief Obtain the number of remaining Ticks configured on a software timer.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to obtain the number of remaining Ticks configured on the software timer of which the ID is
|
||||
* specified by usSwTmrID.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The specific timer should be created and started successfully, error happends otherwise.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param swtmrID [IN] Software timer ID created by LOS_SwtmrCreate. The value of ID should be in
|
||||
* [0, LOSCFG_BASE_CORE_SWTMR_LIMIT - 1].
|
||||
* @param tick [OUT] Number of remaining Ticks configured on the software timer.
|
||||
*
|
||||
* @retval #LOS_ERRNO_SWTMR_ID_INVALID Invalid software timer ID.
|
||||
* @retval #LOS_ERRNO_SWTMR_NOT_CREATED The software timer is not created.
|
||||
* @retval #LOS_ERRNO_SWTMR_NOT_STARTED The software timer is not started.
|
||||
* @retval #LOS_ERRNO_SWTMR_STATUS_INVALID Invalid software timer state.
|
||||
* @retval #LOS_OK The number of remaining Ticks is successfully obtained.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_swtmr.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_SwtmrCreate
|
||||
*/
|
||||
extern UINT32 LOS_SwtmrTimeGet(UINT16 swtmrID, UINT32 *tick);
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* @brief Create a software timer.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to create a software timer that has specified timing duration, timeout handling function,
|
||||
* and trigger mode, and to return a handle by which the software timer can be referenced.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>Do not use the delay interface in the callback function that handles software timer timeout.</li>
|
||||
* <li>Threre are LOSCFG_BASE_CORE_SWTMR_LIMIT timers available, change it's value when necessory.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param interval [IN] Timing duration of the software timer to be created (unit: ms).
|
||||
* @param mode [IN] Software timer mode. Pass in one of the modes specified by EnSwTmrType. There are three
|
||||
* types of modes, one-off, periodic, and continuously periodic after one-off, of which the third mode is not
|
||||
* supported temporarily.
|
||||
* @param handler [IN] Callback function that handles software timer timeout.
|
||||
* @param swtmrID [OUT] Software timer ID created by LOS_SwtmrCreate.
|
||||
* @param arg [IN] Parameter passed in when the callback function that handles software timer timeout is
|
||||
* called.
|
||||
*
|
||||
* @retval #LOS_ERRNO_SWTMR_INTERVAL_NOT_SUITED The software timer timeout interval is 0.
|
||||
* @retval #LOS_ERRNO_SWTMR_MODE_INVALID Invalid software timer mode.
|
||||
* @retval #LOS_ERRNO_SWTMR_PTR_NULL The callback function that handles software timer timeout is NULL.
|
||||
* @retval #LOS_ERRNO_SWTMR_RET_PTR_NULL The passed-in software timer ID is NULL.
|
||||
* @retval #LOS_ERRNO_SWTMR_MAXSIZE The number of software timers exceeds the configured permitted
|
||||
* maximum number.
|
||||
* @retval #LOS_OK The software timer is successfully created.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_swtmr.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_SwtmrDelete
|
||||
*/
|
||||
#if (LOSCFG_BASE_CORE_SWTMR_ALIGN == YES)
|
||||
extern UINT32 LOS_SwtmrCreate(UINT32 interval,
|
||||
UINT8 mode,
|
||||
SWTMR_PROC_FUNC handler,
|
||||
UINT16 *swtmrID,
|
||||
UINT32 arg,
|
||||
UINT8 rouses,
|
||||
UINT8 sensitive);
|
||||
#else
|
||||
extern UINT32 LOS_SwtmrCreate(UINT32 interval,
|
||||
UINT8 mode,
|
||||
SWTMR_PROC_FUNC handler,
|
||||
UINT16 *swtmrID,
|
||||
UINT32 arg);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_swtmr
|
||||
* @brief Delete a software timer.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to delete a software timer.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The specific timer should be created and then stopped firstly.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param swtmrID [IN] Software timer ID created by LOS_SwtmrCreate. The value of ID should be in
|
||||
* [0, LOSCFG_BASE_CORE_SWTMR_LIMIT - 1].
|
||||
*
|
||||
* @retval #LOS_ERRNO_SWTMR_ID_INVALID Invalid software timer ID.
|
||||
* @retval #LOS_ERRNO_SWTMR_NOT_CREATED The software timer is not created.
|
||||
* @retval #LOS_ERRNO_SWTMR_STATUS_INVALID Invalid software timer state.
|
||||
* @retval #LOS_OK The software timer is successfully deleted.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_swtmr.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_SwtmrCreate
|
||||
*/
|
||||
extern UINT32 LOS_SwtmrDelete(UINT16 swtmrID);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_SWTMR_H */
|
|
@ -0,0 +1,212 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup los_sys System time
|
||||
* @ingroup kernel
|
||||
*/
|
||||
|
||||
#ifndef _LOS_SYS_H
|
||||
#define _LOS_SYS_H
|
||||
|
||||
#include "los_hwi.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @ingroup los_sys
|
||||
* Number of milliseconds in one second.
|
||||
*/
|
||||
#define OS_SYS_MS_PER_SECOND 1000
|
||||
|
||||
/**
|
||||
* @ingroup los_sys
|
||||
* Number of microseconds in one second.
|
||||
*/
|
||||
#define OS_SYS_US_PER_SECOND 1000000
|
||||
|
||||
/**
|
||||
* @ingroup los_sys
|
||||
* System time basic function error code: Null pointer.
|
||||
*
|
||||
* Value: 0x02000010
|
||||
*
|
||||
* Solution: Check whether the input parameter is null.
|
||||
*/
|
||||
#define LOS_ERRNO_SYS_PTR_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_SYS, 0x10)
|
||||
|
||||
/**
|
||||
* @ingroup los_sys
|
||||
* System time basic function error code: Invalid system clock configuration.
|
||||
*
|
||||
* Value: 0x02000011
|
||||
*
|
||||
* Solution: Configure a valid system clock in los_config.h.
|
||||
*/
|
||||
#define LOS_ERRNO_SYS_CLOCK_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_SYS, 0x11)
|
||||
|
||||
/**
|
||||
* @ingroup los_sys
|
||||
* System time basic function error code: This error code is not in use temporarily.
|
||||
*
|
||||
* Value: 0x02000012
|
||||
*
|
||||
* Solution: None.
|
||||
*/
|
||||
#define LOS_ERRNO_SYS_MAXNUMOFCORES_IS_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_SYS, 0x12)
|
||||
|
||||
/**
|
||||
* @ingroup los_sys
|
||||
* System time error code: This error code is not in use temporarily.
|
||||
*
|
||||
* Value: 0x02000013
|
||||
*
|
||||
* Solution: None.
|
||||
*/
|
||||
#define LOS_ERRNO_SYS_PERIERRCOREID_IS_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_SYS, 0x13)
|
||||
|
||||
/**
|
||||
* @ingroup los_sys
|
||||
* System time error code: This error code is not in use temporarily.
|
||||
*
|
||||
* Value: 0x02000014
|
||||
*
|
||||
* Solution: None.
|
||||
*/
|
||||
#define LOS_ERRNO_SYS_HOOK_IS_FULL LOS_ERRNO_OS_ERROR(LOS_MOD_SYS, 0x14)
|
||||
|
||||
/**
|
||||
* @ingroup los_typedef
|
||||
* system time structure.
|
||||
*/
|
||||
typedef struct tagSysTime {
|
||||
UINT16 uwYear; /**< value 1970 ~ 2038 or 1970 ~ 2100 */
|
||||
UINT8 ucMonth; /**< value 1 - 12 */
|
||||
UINT8 ucDay; /**< value 1 - 31 */
|
||||
UINT8 ucHour; /**< value 0 - 23 */
|
||||
UINT8 ucMinute; /**< value 0 - 59 */
|
||||
UINT8 ucSecond; /**< value 0 - 59 */
|
||||
UINT8 ucWeek; /**< value 0 - 6 */
|
||||
} SYS_TIME_S;
|
||||
|
||||
/**
|
||||
* @ingroup los_sys
|
||||
* @brief Obtain the number of Ticks.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to obtain the number of Ticks.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param None
|
||||
*
|
||||
* @retval UINT64 The number of Ticks.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_sys.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None
|
||||
*/
|
||||
extern UINT64 LOS_TickCountGet(VOID);
|
||||
|
||||
/**
|
||||
* @ingroup los_sys
|
||||
* @brief Obtain the number of cycles in one second.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to obtain the number of cycles in one second.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param None
|
||||
*
|
||||
* @retval UINT32 Number of cycles obtained in one second.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_sys.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None
|
||||
*/
|
||||
extern UINT32 LOS_CyclePerTickGet(VOID);
|
||||
|
||||
/**
|
||||
* @ingroup los_sys
|
||||
* @brief Convert Ticks to milliseconds.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to convert Ticks to milliseconds.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The number of milliseconds obtained through the conversion is 32-bit.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param ticks [IN] Number of Ticks. The value range is (0,OS_SYS_CLOCK).
|
||||
*
|
||||
* @retval UINT32 Number of milliseconds obtained through the conversion. Ticks are successfully converted to
|
||||
* milliseconds.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_sys.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_MS2Tick
|
||||
*/
|
||||
extern UINT32 LOS_Tick2MS(UINT32 ticks);
|
||||
|
||||
/**
|
||||
* @ingroup los_sys
|
||||
* @brief Convert milliseconds to Ticks.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to convert milliseconds to Ticks.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>If the parameter passed in is equal to 0xFFFFFFFF, the retval is 0xFFFFFFFF. Pay attention to the value to be
|
||||
* converted because data possibly overflows.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param millisec [IN] Number of milliseconds.
|
||||
*
|
||||
* @retval UINT32 Number of Ticks obtained through the conversion.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_sys.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_Tick2MS
|
||||
*/
|
||||
extern UINT32 LOS_MS2Tick(UINT32 millisec);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_SYS_H */
|
|
@ -0,0 +1,128 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef _LOS_TABLES_H
|
||||
#define _LOS_TABLES_H
|
||||
|
||||
#include "los_typedef.h"
|
||||
|
||||
#define TO_STRING(x) #x
|
||||
#define X_TO_STRING(x) TO_STRING(x)
|
||||
|
||||
#ifndef LOS_HAL_TABLE_WOW_BEGIN
|
||||
#define LOS_HAL_TABLE_WOW_BEGIN(label, name) \
|
||||
__asm__(".section \".liteos.table." X_TO_STRING(name) ".wow.begin\",\"aw\"\n" \
|
||||
".globl " X_TO_STRING(LOS_LABEL_DEFN(label)) "\n" \
|
||||
".type " X_TO_STRING(LOS_LABEL_DEFN(label)) ",object\n" \
|
||||
".p2align " X_TO_STRING(LOSARC_P2ALIGNMENT) "\n" X_TO_STRING(LOS_LABEL_DEFN(label)) ":\n" \
|
||||
".previous\n")
|
||||
#endif
|
||||
|
||||
#ifndef LOS_HAL_TABLE_WOW_END
|
||||
#define LOS_HAL_TABLE_WOW_END(label, name) \
|
||||
__asm__(".section \".liteos.table." X_TO_STRING(name) ".wow.finish\",\"aw\"\n" \
|
||||
".globl " X_TO_STRING(LOS_LABEL_DEFN(label)) "\n" \
|
||||
".type " X_TO_STRING(LOS_LABEL_DEFN(label)) ",object\n" \
|
||||
".p2align " X_TO_STRING(LOSARC_P2ALIGNMENT) "\n" X_TO_STRING(LOS_LABEL_DEFN(label)) ":\n" \
|
||||
".previous\n")
|
||||
#endif
|
||||
|
||||
#ifndef LOS_HAL_TABLE_SCATTER_BEGIN
|
||||
#define LOS_HAL_TABLE_SCATTER_BEGIN(label, name) \
|
||||
__asm__(".section \".liteos.table." X_TO_STRING(name) ".scatter.begin\",\"aw\"\n" \
|
||||
".globl " X_TO_STRING(LOS_LABEL_DEFN(label)) "\n" \
|
||||
".type " X_TO_STRING(LOS_LABEL_DEFN(label)) ",object\n" \
|
||||
".p2align " X_TO_STRING(LOSARC_P2ALIGNMENT) "\n" X_TO_STRING(LOS_LABEL_DEFN(label)) ":\n" \
|
||||
".previous\n")
|
||||
#endif
|
||||
|
||||
#ifndef LOS_HAL_TABLE_SCATTER_END
|
||||
#define LOS_HAL_TABLE_SCATTER_END(label, name) \
|
||||
__asm__(".section \".liteos.table." X_TO_STRING(name) ".scatter.finish\",\"aw\"\n" \
|
||||
".globl " X_TO_STRING(LOS_LABEL_DEFN(label)) "\n" \
|
||||
".type " X_TO_STRING(LOS_LABEL_DEFN(label)) ",object\n" \
|
||||
".p2align " X_TO_STRING(LOSARC_P2ALIGNMENT) "\n" X_TO_STRING(LOS_LABEL_DEFN(label)) ":\n" \
|
||||
".previous\n")
|
||||
#endif
|
||||
|
||||
#ifndef LOS_HAL_TABLE_BEGIN
|
||||
#define LOS_HAL_TABLE_BEGIN(label, name) \
|
||||
__asm__(".section \".liteos.table." X_TO_STRING(name) ".begin\",\"aw\"\n" \
|
||||
".globl " X_TO_STRING(LOS_LABEL_DEFN(label)) "\n" \
|
||||
".type " X_TO_STRING(LOS_LABEL_DEFN(label)) ",object\n" \
|
||||
".p2align " X_TO_STRING(LOSARC_P2ALIGNMENT) "\n" X_TO_STRING(LOS_LABEL_DEFN(label)) ":\n" \
|
||||
".previous\n")
|
||||
#endif
|
||||
|
||||
#ifndef LOS_HAL_TABLE_END
|
||||
#define LOS_HAL_TABLE_END(label, name) \
|
||||
__asm__(".section \".liteos.table." X_TO_STRING(name) ".finish\",\"aw\"\n" \
|
||||
".globl " X_TO_STRING(LOS_LABEL_DEFN(label)) "\n" \
|
||||
".type " X_TO_STRING(LOS_LABEL_DEFN(label)) ",object\n" \
|
||||
".p2align " X_TO_STRING(LOSARC_P2ALIGNMENT) "\n" X_TO_STRING(LOS_LABEL_DEFN(label)) ":\n" \
|
||||
".previous\n")
|
||||
#endif
|
||||
|
||||
// This macro must be applied to any types whose objects are to be placed in tables
|
||||
#ifndef LOS_HAL_TABLE_TYPE
|
||||
#define LOS_HAL_TABLE_TYPE LOSBLD_ATTRIB_ALIGN(LOSARC_ALIGNMENT)
|
||||
#endif
|
||||
|
||||
#ifndef LOS_HAL_TABLE_EXTRA
|
||||
#define LOS_HAL_TABLE_EXTRA(name) \
|
||||
LOSBLD_ATTRIB_SECTION(".liteos.table." X_TO_STRING(name) ".extra")
|
||||
#endif
|
||||
|
||||
#ifndef LOS_HAL_TABLE_WOW_ENTRY
|
||||
#define LOS_HAL_TABLE_WOW_ENTRY(name) \
|
||||
LOSBLD_ATTRIB_SECTION(".liteos.table." X_TO_STRING(name) ".wow.data") \
|
||||
LOSBLD_ATTRIB_USED
|
||||
#endif
|
||||
|
||||
#ifndef LOS_HAL_TABLE_SCATTER_ENTRY
|
||||
#define LOS_HAL_TABLE_SCATTER_ENTRY(name) \
|
||||
LOSBLD_ATTRIB_SECTION(".liteos.table." X_TO_STRING(name) ".scatter.data") \
|
||||
LOSBLD_ATTRIB_USED
|
||||
#endif
|
||||
|
||||
#ifndef LOS_HAL_TABLE_ENTRY
|
||||
#define LOS_HAL_TABLE_ENTRY(name) \
|
||||
LOSBLD_ATTRIB_SECTION(".liteos.table." X_TO_STRING(name) ".data") \
|
||||
LOSBLD_ATTRIB_USED
|
||||
#endif
|
||||
|
||||
#ifndef LOS_HAL_TABLE_QUALIFIED_ENTRY
|
||||
#define LOS_HAL_TABLE_QUALIFIED_ENTRY(name, qual) \
|
||||
LOSBLD_ATTRIB_SECTION(".liteos.table." X_TO_STRING(name) ".data." X_TO_STRING(qual)) \
|
||||
LOSBLD_ATTRIB_USED
|
||||
#endif
|
||||
|
||||
#endif /* _LOS_TABLES_H */
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,107 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup los_tick Tick
|
||||
* @ingroup kernel
|
||||
*/
|
||||
|
||||
#ifndef _LOS_TICK_H
|
||||
#define _LOS_TICK_H
|
||||
|
||||
#include "los_errno.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @ingroup los_tick
|
||||
* Tick error code: The Tick configuration is incorrect.
|
||||
*
|
||||
* Value: 0x02000400
|
||||
*
|
||||
* Solution: Change values of the OS_SYS_CLOCK and LOSCFG_BASE_CORE_TICK_PER_SECOND
|
||||
* system time configuration modules in Los_config.h.
|
||||
*/
|
||||
#define LOS_ERRNO_TICK_CFG_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_TICK, 0x00)
|
||||
|
||||
/**
|
||||
* @ingroup los_tick
|
||||
* Tick error code: This error code is not in use temporarily.
|
||||
*
|
||||
* Value: 0x02000401
|
||||
*
|
||||
* Solution: None.
|
||||
*/
|
||||
#define LOS_ERRNO_TICK_NO_HWTIMER LOS_ERRNO_OS_ERROR(LOS_MOD_TICK, 0x01)
|
||||
|
||||
/**
|
||||
* @ingroup los_tick
|
||||
* Tick error code: The number of Ticks is too small.
|
||||
*
|
||||
* Value: 0x02000402
|
||||
*
|
||||
* Solution: Change values of the OS_SYS_CLOCK and LOSCFG_BASE_CORE_TICK_PER_SECOND
|
||||
* system time configuration modules according to the SysTick_Config function.
|
||||
*/
|
||||
#define LOS_ERRNO_TICK_PER_SEC_TOO_SMALL LOS_ERRNO_OS_ERROR(LOS_MOD_TICK, 0x02)
|
||||
|
||||
/**
|
||||
* @ingroup los_tick
|
||||
* @brief: System clock get function.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to get system clock.
|
||||
*
|
||||
* @attention:
|
||||
* <ul><li>None.</li></ul>
|
||||
*
|
||||
* @param: None.
|
||||
*
|
||||
* @retval: system clock.
|
||||
*
|
||||
* @par Dependency:
|
||||
* <ul><li>los_tick.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*
|
||||
* */
|
||||
extern UINT32 LOS_SysClockGet(VOID);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_TICK_H */
|
|
@ -0,0 +1,91 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup los_tickless Tickless
|
||||
* @ingroup kernel
|
||||
*/
|
||||
|
||||
#ifndef _LOS_TICKLESS_H
|
||||
#define _LOS_TICKLESS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @ingroup los_tickless
|
||||
* @brief enable the tickless mode.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to enable the tickless mode. System can change from periodic clock mode to dynamic clock mode.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* </ul>
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_tickless.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_TicklessDisable
|
||||
*/
|
||||
extern VOID LOS_TicklessEnable(VOID);
|
||||
/**
|
||||
* @ingroup los_tickless
|
||||
* @brief disable the tickless mode.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to diable the tickless mode. System will not change from periodic clock mode to dynamic clock mode.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* </ul>
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_tickless.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_TicklessEnable
|
||||
*/
|
||||
extern VOID LOS_TicklessDisable(VOID);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif
|
|
@ -0,0 +1,248 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup los_trace Trace
|
||||
* @ingroup kernel
|
||||
*/
|
||||
|
||||
#ifndef _LOS_TRACE_H
|
||||
#define _LOS_TRACE_H
|
||||
|
||||
#include "los_base.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @ingroup los_trace
|
||||
* Task error code: Insufficient memory for trace struct.
|
||||
*
|
||||
* Value: 0x02001400
|
||||
*
|
||||
* Solution: Decrease the maximum number of tasks.
|
||||
*/
|
||||
#define LOS_ERRNO_TRACE_NO_MEMORY LOS_ERRNO_OS_ERROR(LOS_MOD_TRACE, 0x00)
|
||||
|
||||
/**
|
||||
* @ingroup los_trace
|
||||
* Task error code: User type is invalid when register new trace.
|
||||
*
|
||||
* Value: 0x02001401
|
||||
*
|
||||
* Solution: Use valid type to regeister the new trace.
|
||||
*/
|
||||
#define LOS_ERRNO_TRACE_TYPE_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_TRACE, 0x01)
|
||||
|
||||
|
||||
/**
|
||||
* @ingroup los_trace
|
||||
* Task error code: The callback function is null when register new trace.
|
||||
*
|
||||
* Value: 0x02001402
|
||||
*
|
||||
* Solution: Use valid callback function to regeister the new trace.
|
||||
*/
|
||||
#define LOS_ERRNO_TRACE_FUNCTION_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_TRACE, 0x02)
|
||||
|
||||
/**
|
||||
* @ingroup los_trace
|
||||
* Task error code: The filled size is 0 when register new trace.
|
||||
*
|
||||
* Value: 0x02001403
|
||||
*
|
||||
* Solution: Use valid filled size to regeister the new trace.
|
||||
*/
|
||||
#define LOS_ERRNO_TRACE_MAX_SIZE_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_TRACE, 0x03)
|
||||
|
||||
/**
|
||||
* @ingroup los_trace
|
||||
* It's the total size of trace buffer. It's in the unit of char
|
||||
*/
|
||||
#define LOS_TRACE_BUFFER_SIZE 1024
|
||||
|
||||
/**
|
||||
* @ingroup los_trace
|
||||
* It's the legth of tag, filled by los_trace system
|
||||
*/
|
||||
#define LOS_TRACE_TAG_LENGTH sizeof(UINT32)
|
||||
|
||||
/**
|
||||
* @ingroup los_trace
|
||||
* Stands for the trace type can be registered.
|
||||
*/
|
||||
typedef enum enTraceType {
|
||||
LOS_TRACE_SWITCH = 0, /**< trace for task switch, 0 is reserved for taskswitch */
|
||||
LOS_TRACE_INTERRUPT = 1, /**< trace for Interrrupt, 1 is reserved for interrupt */
|
||||
LOS_TRACE_TYPE_NUM = 10, /**< num for the register type, user can use 2~ LOS_TRACE_TYPE_NUM-1 */
|
||||
} TRACE_TYPE_E;
|
||||
|
||||
|
||||
/**
|
||||
* @ingroup los_trace
|
||||
* struct to store the task switch infomation
|
||||
*/
|
||||
typedef struct tagTraceTaskSwitch {
|
||||
UINT8 ucSrcTaskId; /**< source taskid */
|
||||
UINT8 ucDestTaskId; /**< destination taskid */
|
||||
UINT32 uwSwitchTick; /**< Time at which the task switch happens */
|
||||
} TRACE_TASKSWITCH_S;
|
||||
|
||||
/**
|
||||
* @ingroup los_trace
|
||||
* struct to store the interrupt infomation
|
||||
*/
|
||||
typedef struct tagTraceInterrupt {
|
||||
UINT8 ucIRQEntryExit; /**< 1 stands for that the trace is happend before interrupt function */
|
||||
/**< 0 stands for that the trace is after before interrupt function */
|
||||
UINT16 usIRQNo; /**< IRQ number which trigger the interrupt */
|
||||
UINT32 uwTick; /**< Time at which the the trace is called */
|
||||
} TRACE_INTERRUPT_S;
|
||||
|
||||
/**
|
||||
* @ingroup los_trace
|
||||
* union struct to store the interrupt and task switch infomation
|
||||
*/
|
||||
typedef struct tagTrace {
|
||||
union {
|
||||
TRACE_TASKSWITCH_S stTraceTask; /**< It used for trace the task */
|
||||
TRACE_INTERRUPT_S stTraceInterrupt; /**< It used for trace the interrrupt */
|
||||
};
|
||||
} TRACE_S;
|
||||
|
||||
/**
|
||||
* @ingroup los_trace
|
||||
* Main struct to store the interrupt and task swithc infomation
|
||||
*/
|
||||
typedef struct tagTraceBuffer {
|
||||
UINT16 usTracePos;
|
||||
UINT16 usTraceWrapPos;
|
||||
UINT8 ucBuffer[LOS_TRACE_BUFFER_SIZE];
|
||||
} TRACE_BUFFER_S;
|
||||
|
||||
|
||||
/**
|
||||
* @ingroup los_trace
|
||||
* Struct to store the trace infomaion for each trace type
|
||||
*/
|
||||
typedef struct tagTraceInfo {
|
||||
TRACE_TYPE_E eType; /**< trace type, selected from TRACE_TYPE_E */
|
||||
UINT16 (*pfnHook)(UINT8 *outBuffer, VOID *pInfo); /**< callback function for the specific trace type.
|
||||
* This function is used to store the infomation
|
||||
* which want to be traced */
|
||||
} TRACE_INFO_S;
|
||||
|
||||
/**
|
||||
* @ingroup los_trace
|
||||
* @brief Intialize the trace when the system startup.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to intilize the trace for system level.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>This API can be called only after the memory is initialized. Otherwise, the CPU usage fails to be obtained.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval #LOS_ERRNO_TRACE_NO_MEMORY 0x02001400: The memory is not enough for initilize.
|
||||
* @retval #LOS_OK 0x00000000: The intialization is successful.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_trace.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_TraceInit
|
||||
*/
|
||||
extern UINT32 LOS_TraceInit(VOID);
|
||||
|
||||
|
||||
/**
|
||||
* @ingroup los_trace
|
||||
* @brief main trace function is called by user to logger the information.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to trace the infomation.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>This API can be called only after trace type is intialized. Otherwise, the trace will be failed.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param traceType [IN] TRACE_TYPE_E. Type of trace information.
|
||||
* @param traceInfo [IN] VOID*. It's a input buffer to store trace infomation
|
||||
*
|
||||
* @retval NONE.
|
||||
*
|
||||
* @par Dependency:
|
||||
* <ul><li>los_trace.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_Trace
|
||||
*/
|
||||
extern VOID LOS_Trace(TRACE_TYPE_E traceType, VOID *traceInfo);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @ingroup los_trace
|
||||
* @brief register the hook for specific trace type.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to register the hook for specific trace type.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>This API can be called only after trace type is called. therwise, the trace will be failed.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param traceType [IN] TRACE_TYPE_E. Type of trace information.
|
||||
* @param hook [IN] UINT16 (*)(UINT8*, VOID*). It's an callback function to store the useful trace
|
||||
* information
|
||||
* @param size [IN] UINT16. The maximum size the trace will use for the specific trace type.
|
||||
*
|
||||
* @retval #LOS_ERRNO_TRACE_NO_MEMORY 0x02001400: The memory is not enough for initilize.
|
||||
* @retval #LOS_ERRNO_TRACE_TYPE_INVALID 0x02001401: The trace type is invalid. Valid type is from
|
||||
* LOS_TRACE_TYPE_NUM-1
|
||||
* @retval #LOS_ERRNO_TRACE_FUNCTION_NULL 0x02001402: The input callback function is NULL
|
||||
* @retval #LOS_ERRNO_TRACE_MAX_SIZE_INVALID 0x02001403: The information maxmum size is 0 to store.
|
||||
* @retval #LOS_OK 0x00000000: The registeration is successful.
|
||||
*
|
||||
* @par Dependency:
|
||||
* <ul><li>los_trace.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_TraceUserReg
|
||||
*/
|
||||
extern UINT32 LOS_TraceUserReg(TRACE_TYPE_E traceType, UINT16 (*hook)(UINT8 *, VOID *), UINT16 size);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_TRACE_H */
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue