first submission

This commit is contained in:
qiyongshuang
2023-02-01 14:19:13 +08:00
parent d534aad004
commit b79c6ac80d
3711 changed files with 745432 additions and 2 deletions
@@ -0,0 +1,698 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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_config System configuration items
* @ingroup kernel
*/
#ifndef _LOS_CONFIG_H
#define _LOS_CONFIG_H
#include "target_config.h"
#include "los_compiler.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
/* =============================================================================
System clock module configuration
============================================================================= */
/**
* @ingroup los_config
* System clock (unit: HZ)
*/
#ifndef OS_SYS_CLOCK
#error "OS_SYS_CLOCK is system clock rate which should be defined in target_config.h"
#endif
/**
* @ingroup los_config
* Number of Ticks in one second
*/
#ifndef LOSCFG_BASE_CORE_TICK_PER_SECOND
#define LOSCFG_BASE_CORE_TICK_PER_SECOND (100UL)
#endif
#if defined(LOSCFG_BASE_CORE_TICK_PER_SECOND) && \
((LOSCFG_BASE_CORE_TICK_PER_SECOND < 1UL) || (LOSCFG_BASE_CORE_TICK_PER_SECOND > 1000000000UL))
#error "LOSCFG_BASE_CORE_TICK_PER_SECOND SHOULD big than 0, and less than 1000000000UL"
#endif
#if (LOSCFG_BASE_CORE_TICK_PER_SECOND <= 1000UL)
/**
* @ingroup los_config
* How much time one tick spent (unit:ms)
*/
#ifndef LOSCFG_BASE_CORE_TICK_PERIOD_MS
#define LOSCFG_BASE_CORE_TICK_PERIOD_MS (1000UL / LOSCFG_BASE_CORE_TICK_PER_SECOND)
#endif
#elif (LOSCFG_BASE_CORE_TICK_PER_SECOND <= 1000000UL)
/**
* @ingroup los_config
* How much time one tick spent (unit:us)
*/
#ifndef LOSCFG_BASE_CORE_TICK_PERIOD_US
#define LOSCFG_BASE_CORE_TICK_PERIOD_US (1000000UL / LOSCFG_BASE_CORE_TICK_PER_SECOND)
#endif
#else
/**
* @ingroup los_config
* How much time one tick spent (unit:ns)
*/
#ifndef LOSCFG_BASE_CORE_TICK_PERIOD_NS
#define LOSCFG_BASE_CORE_TICK_PERIOD_NS (1000000000UL / LOSCFG_BASE_CORE_TICK_PER_SECOND)
#endif
#endif
#ifndef LOSCFG_BASE_CORE_TICK_HW_TIME
#define LOSCFG_BASE_CORE_TICK_HW_TIME 0
#endif
/**
* @ingroup los_config
* System timer is a 64/128 bit timer
*/
#ifndef LOSCFG_BASE_CORE_TICK_WTIMER
#define LOSCFG_BASE_CORE_TICK_WTIMER 0
#endif
/**
* @ingroup los_config
* System timer count maximum
*/
#ifndef LOSCFG_BASE_CORE_TICK_RESPONSE_MAX
#define LOSCFG_BASE_CORE_TICK_RESPONSE_MAX 0
#endif
/* =============================================================================
Hardware interrupt module configuration
============================================================================= */
/**
* @ingroup los_config
* Configuration item for hardware interrupt tailoring
*/
#ifndef LOSCFG_PLATFORM_HWI
#define LOSCFG_PLATFORM_HWI 1
#endif
/**
* @ingroup los_config
* Configuration item for using system defined vector base address and interrupt handlers.
* If LOSCFG_USE_SYSTEM_DEFINED_INTERRUPT is set to 0, vector base address will not be
* modified by system. In arm, it should be noted that PendSV_Handler and SysTick_Handler should
* be redefined to HalPendSV and OsTickHandler respectly in this case, because system depends on
* these interrupt handlers to run normally. What's more, LOS_HwiCreate will not register handler.
*/
#ifndef LOSCFG_USE_SYSTEM_DEFINED_INTERRUPT
#define LOSCFG_USE_SYSTEM_DEFINED_INTERRUPT 0
#endif
#if (LOSCFG_USE_SYSTEM_DEFINED_INTERRUPT == 1)
#if (LOSCFG_PLATFORM_HWI == 0)
#error "if LOSCFG_USE_SYSTEM_DEFINED_INTERRUPT is set to 1, then LOSCFG_PLATFORM_HWI must also be set to 1"
#endif
#endif
/**
* @ingroup los_config
* Maximum number of used hardware interrupts, including Tick timer interrupts.
*/
#ifndef LOSCFG_PLATFORM_HWI_LIMIT
#define LOSCFG_PLATFORM_HWI_LIMIT 32
#endif
/* =============================================================================
Task module configuration
============================================================================= */
/**
* @ingroup los_config
* Minimum stack size.
*
* 0x80 bytes, aligned on a boundary of 8.
*/
#ifndef LOSCFG_BASE_CORE_TSK_MIN_STACK_SIZE
#define LOSCFG_BASE_CORE_TSK_MIN_STACK_SIZE (ALIGN(0x80, 4))
#endif
/**
* @ingroup los_config
* Default task priority
*/
#ifndef LOSCFG_BASE_CORE_TSK_DEFAULT_PRIO
#define LOSCFG_BASE_CORE_TSK_DEFAULT_PRIO 10
#endif
/**
* @ingroup los_config
* Maximum supported number of tasks except the idle task rather than the number of usable tasks
*/
#ifndef LOSCFG_BASE_CORE_TSK_LIMIT
#define LOSCFG_BASE_CORE_TSK_LIMIT 5
#endif
/**
* @ingroup los_config
* Size of the idle task stack
*/
#ifndef LOSCFG_BASE_CORE_TSK_IDLE_STACK_SIZE
#define LOSCFG_BASE_CORE_TSK_IDLE_STACK_SIZE 0x180UL
#endif
/**
* @ingroup los_config
* Default task stack size
*/
#ifndef LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE
#define LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE 0x400UL
#endif
/**
* @ingroup los_config
* Configuration item for task Robin tailoring
*/
#ifndef LOSCFG_BASE_CORE_TIMESLICE
#define LOSCFG_BASE_CORE_TIMESLICE 1
#endif
/**
* @ingroup los_config
* Longest execution time of tasks with the same priorities
*/
#ifndef LOSCFG_BASE_CORE_TIMESLICE_TIMEOUT
#define LOSCFG_BASE_CORE_TIMESLICE_TIMEOUT 20000 /* 20ms */
#endif
/**
* @ingroup los_config
* Configuration item for task (stack) monitoring module tailoring
*/
#ifndef LOSCFG_BASE_CORE_TSK_MONITOR
#define LOSCFG_BASE_CORE_TSK_MONITOR 0
#endif
/**
* @ingroup los_config
* Configuration item for task perf task filter hook
*/
#ifndef LOSCFG_BASE_CORE_EXC_TSK_SWITCH
#define LOSCFG_BASE_CORE_EXC_TSK_SWITCH 0
#endif
/**
* @ingroup los_config
* Define a usable task priority.Highest task priority.
*/
#ifndef LOS_TASK_PRIORITY_HIGHEST
#define LOS_TASK_PRIORITY_HIGHEST 0
#endif
/**
* @ingroup los_config
* Define a usable task priority.Lowest task priority.
*/
#ifndef LOS_TASK_PRIORITY_LOWEST
#define LOS_TASK_PRIORITY_LOWEST 31
#endif
/**
* @ingroup los_config
* Configuration item for task stack independent
*/
#ifndef LOSCFG_BASE_CORE_TASKSTACK_INDEPENDENT
#define LOSCFG_BASE_CORE_TASKSTACK_INDEPENDENT 0
#endif
/**
* @ingroup los_config
* SP align size
*/
#ifndef LOSCFG_STACK_POINT_ALIGN_SIZE
#define LOSCFG_STACK_POINT_ALIGN_SIZE 8
#endif
/* =============================================================================
Semaphore module configuration
============================================================================= */
/**
* @ingroup los_config
* Configuration item for semaphore module tailoring
*/
#ifndef LOSCFG_BASE_IPC_SEM
#define LOSCFG_BASE_IPC_SEM 1
#endif
/**
* @ingroup los_config
* Maximum supported number of semaphores
*/
#ifndef LOSCFG_BASE_IPC_SEM_LIMIT
#define LOSCFG_BASE_IPC_SEM_LIMIT 6
#endif
/**
* @ingroup los_config
* Maximum number of semaphores.
*/
#ifndef OS_SEM_COUNTING_MAX_COUNT
#define OS_SEM_COUNTING_MAX_COUNT 0xFFFF
#endif
/* =============================================================================
Mutex module configuration
============================================================================= */
/**
* @ingroup los_config
* Configuration item for mutex module tailoring
*/
#ifndef LOSCFG_BASE_IPC_MUX
#define LOSCFG_BASE_IPC_MUX 1
#endif
/**
* @ingroup los_config
* Maximum supported number of mutexes
*/
#ifndef LOSCFG_BASE_IPC_MUX_LIMIT
#define LOSCFG_BASE_IPC_MUX_LIMIT 6
#endif
/* =============================================================================
Queue module configuration
============================================================================= */
/**
* @ingroup los_config
* Configuration item for queue module tailoring
*/
#ifndef LOSCFG_BASE_IPC_QUEUE
#define LOSCFG_BASE_IPC_QUEUE 1
#endif
/**
* @ingroup los_config
* Maximum supported number of queues rather than the number of usable queues
*/
#ifndef LOSCFG_BASE_IPC_QUEUE_LIMIT
#define LOSCFG_BASE_IPC_QUEUE_LIMIT 6
#endif
/* =============================================================================
Software timer module configuration
============================================================================= */
/**
* @ingroup los_config
* Configuration item for software timer module tailoring
*/
#ifndef LOSCFG_BASE_CORE_SWTMR
#define LOSCFG_BASE_CORE_SWTMR 1
#endif
/**
* @ingroup los_config
* Maximum supported number of software timers rather than the number of usable software timers
*/
#ifndef LOSCFG_BASE_CORE_SWTMR_LIMIT
#define LOSCFG_BASE_CORE_SWTMR_LIMIT 5
#endif
/**
* @ingroup los_config
* Software timer task stack size
*/
#ifndef LOSCFG_BASE_CORE_TSK_SWTMR_STACK_SIZE
#define LOSCFG_BASE_CORE_TSK_SWTMR_STACK_SIZE LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE
#endif
/**
* @ingroup los_config
* Configurate item for software timer align tailoring
*/
#ifndef LOSCFG_BASE_CORE_SWTMR_ALIGN
#define LOSCFG_BASE_CORE_SWTMR_ALIGN 0
#endif
#if (LOSCFG_BASE_CORE_SWTMR_ALIGN == 1)
#if (LOSCFG_BASE_CORE_SWTMR == 0)
#error "if LOSCFG_BASE_CORE_SWTMR_ALIGN is set to 1, then LOSCFG_BASE_CORE_SWTMR must also be set to 1"
#endif
#endif
/**
* @ingroup los_config
* Maximum size of a software timer queue
*/
#ifndef OS_SWTMR_HANDLE_QUEUE_SIZE
#define OS_SWTMR_HANDLE_QUEUE_SIZE (LOSCFG_BASE_CORE_SWTMR_LIMIT + 0)
#endif
/**
* @ingroup los_config
* Minimum divisor of software timer multiple alignment
*/
#ifndef LOS_COMMON_DIVISOR
#define LOS_COMMON_DIVISOR 10
#endif
#if (LOSCFG_BASE_CORE_SWTMR == 1)
#if (LOSCFG_BASE_IPC_QUEUE == 0)
#error "if LOSCFG_BASE_CORE_SWTMR is set to 1, then LOSCFG_BASE_IPC_QUEUE must also be set to 1"
#endif
#endif
/* =============================================================================
Memory module configuration ---- to be refactored
============================================================================= */
extern UINT8 *m_aucSysMem0;
/**
* @ingroup los_config
* Configure whether the kernel uses external heap memory
*/
#ifndef LOSCFG_SYS_EXTERNAL_HEAP
#define LOSCFG_SYS_EXTERNAL_HEAP 0
#endif
/**
* @ingroup los_config
* Starting address of the memory
*/
#ifndef LOSCFG_SYS_HEAP_ADDR
#define LOSCFG_SYS_HEAP_ADDR (&m_aucSysMem0[0])
#endif
/**
* @ingroup los_config
* Starting address of the task stack
*/
#ifndef OS_TASK_STACK_ADDR
#define OS_TASK_STACK_ADDR LOSCFG_SYS_HEAP_ADDR
#endif
/**
* @ingroup los_config
* Memory size
*/
#ifndef LOSCFG_SYS_HEAP_SIZE
#define LOSCFG_SYS_HEAP_SIZE 0x00013000
#endif
/**
* @ingroup los_config
* Configuration module tailoring of more mempry pool checking
*/
#ifndef LOSCFG_MEM_MUL_POOL
#define LOSCFG_MEM_MUL_POOL 1
#endif
/**
* @ingroup los_config
* Configuration module tailoring of memory released by task id
*/
#ifndef LOSCFG_MEM_FREE_BY_TASKID
#define LOSCFG_MEM_FREE_BY_TASKID 0
#endif
/**
* @ingroup los_config
* Configuration module tailoring of mem node integrity checking
*/
#ifndef LOSCFG_BASE_MEM_NODE_INTEGRITY_CHECK
#define LOSCFG_BASE_MEM_NODE_INTEGRITY_CHECK 0
#endif
/**
* @ingroup los_config
* Configuration memory leak detection
* @attention
* Need to enable backtrace module synchronously by configuration LOSCFG_BACKTRACE_TYPE,
* and call OSBackTraceInit to complete initialization before the memory pool is initialized.
*/
#ifndef LOSCFG_MEM_LEAKCHECK
#define LOSCFG_MEM_LEAKCHECK 0
#endif
#if (LOSCFG_MEM_LEAKCHECK == 1) && (LOSCFG_BACKTRACE_TYPE == 0)
#error "if LOSCFG_MEM_LEAKCHECK is set to 1, then LOSCFG_BACKTRACE_TYPE must be set to 1, 2 or 3."
#endif
/**
* @ingroup los_config
* The default is 4, which means that the function call stack is recorded from the kernel interface,
* such as LOS_MemAlloc/LOS_MemAllocAlign/LOS_MemRealloc/LOS_MemFree. If you want to further ignore
* the number of function call layers, you can increase this value appropriately.
* @attention
* The default is in the IAR tool. Under different compilation environments, this value needs to be adjusted.
*/
#ifndef LOSCFG_MEM_OMIT_LR_CNT
#define LOSCFG_MEM_OMIT_LR_CNT 4
#endif
/**
* @ingroup los_config
* The record number of layers of the function call relationship starting from the number of
* ignored layers(LOSCFG_MEM_OMIT_LR_CNT).
*/
#ifndef LOSCFG_MEM_RECORD_LR_CNT
#define LOSCFG_MEM_RECORD_LR_CNT 3
#endif
/**
* @ingroup los_config
* Configuration memory leak recorded num
*/
#ifndef LOSCFG_MEM_LEAKCHECK_RECORD_MAX_NUM
#define LOSCFG_MEM_LEAKCHECK_RECORD_MAX_NUM 1024
#endif
/**
* @ingroup los_config
* Configuration of memory pool record memory consumption waterline
*/
#ifndef LOSCFG_MEM_WATERLINE
#define LOSCFG_MEM_WATERLINE 1
#endif
/**
* @ingroup los_config
* Number of memory checking blocks
*/
#ifndef OS_SYS_MEM_NUM
#define OS_SYS_MEM_NUM 20
#endif
/**
* @ingroup los_config
* Size of unaligned memory
*/
#ifndef OS_SYS_NOCACHEMEM_SIZE
#define OS_SYS_NOCACHEMEM_SIZE 0x0UL
#endif
/**
* @ingroup los_config
* Starting address of the unaligned memory
*/
#if (OS_SYS_NOCACHEMEM_SIZE > 0)
#define OS_SYS_NOCACHEMEM_ADDR (&g_sysNoCacheMem0[0])
#endif
/* =============================================================================
Exception module configuration
============================================================================= */
/**
* @ingroup los_config
* Configuration item for exception tailoring
*/
#ifndef LOSCFG_PLATFORM_EXC
#define LOSCFG_PLATFORM_EXC 0
#endif
/**
* @ingroup los_config
* Configuration of hardware stack protection
*/
#ifndef LOSCFG_EXC_HARDWARE_STACK_PROTECTION
#define LOSCFG_EXC_HARDWARE_STACK_PROTECTION 0
#endif
/* =============================================================================
CPUP configuration
============================================================================= */
/**
* @ingroup los_config
* Configuration item for CPU usage tailoring
*/
#ifndef LOSCFG_BASE_CORE_CPUP
#define LOSCFG_BASE_CORE_CPUP 0
#endif
/* =============================================================================
Test module configuration
============================================================================= */
/**
* @ingroup los_config
* Configuration test case to open
*/
/**
* @ingroup los_config
* Configuration CMSIS_OS_VER
*/
#ifndef CMSIS_OS_VER
#define CMSIS_OS_VER 2
#endif
/* =============================================================================
trace configuration
============================================================================= */
/**
* @ingroup los_config
* Configuration liteos trace
*/
#ifndef LOSCFG_KERNEL_TRACE
#define LOSCFG_KERNEL_TRACE 0
#endif
#ifndef LOSCFG_SUPPORT_LITTLEFS
#define LOSCFG_SUPPORT_LITTLEFS 1
#endif
#ifndef LOSCFG_LFS_MAX_MOUNT_SIZE
#define LOSCFG_LFS_MAX_MOUNT_SIZE 3
#endif
/**
* @ingroup los_config
* Configuration trace tool
*/
#ifndef LOSCFG_DEBUG_HOOK
#define LOSCFG_DEBUG_HOOK 0
#endif
/* =============================================================================
printf configuration
============================================================================= */
/**
* @ingroup los_config
* Configuration liteos printf
*/
#ifndef LOSCFG_KERNEL_PRINTF
#define LOSCFG_KERNEL_PRINTF 1
#endif
/* =============================================================================
backtrace configuration
============================================================================= */
/**
* @ingroup los_config
* Configuration backtrace type
* 0: Close stack analysis module.
* 1: Call stack analysis for cortex-m series by scanning the stack.
* 2: Call stack analysis for risc-v by using frame pointer.
* 3: Call stack analysis for risc-v by scanning the stack.
* others: Not currently supported.
*/
#ifndef LOSCFG_BACKTRACE_TYPE
#define LOSCFG_BACKTRACE_TYPE 0
#endif
/**
* @ingroup los_config
* Configuration backtrace depth.
*/
#ifndef LOSCFG_BACKTRACE_DEPTH
#define LOSCFG_BACKTRACE_DEPTH 15
#endif
/**
* @ingroup los_config
* Configuration item for low power frame tailoring
*/
#ifndef LOSCFG_KERNEL_PM
#define LOSCFG_KERNEL_PM 1
#endif
/**
* @ingroup los_config
* Configuration item for priority of low-power task.
*/
#ifndef LOSCFG_KERNEL_PM_TASK_PTIORITY
#define LOSCFG_KERNEL_PM_TASK_PTIORITY 1
#endif
/**
* @ingroup los_config
* Configuration item for stack size of low-power task.
*/
#ifndef LOSCFG_KERNEL_PM_TASK_STACKSIZE
#define LOSCFG_KERNEL_PM_TASK_STACKSIZE 0x800
#endif
/**
* @ingroup los_config
* Configuration item for low power frame debug tailoring
*/
#ifndef LOSCFG_KERNEL_PM_DEBUG
#define LOSCFG_KERNEL_PM_DEBUG 0
#endif
/**
* @ingroup los_config
* Configuration trustzone secure heap size.
*/
#ifndef LOSCFG_SECURE_HEAP_SIZE
#define LOSCFG_SECURE_HEAP_SIZE 2048
#endif
/**
* @ingroup los_config
* Configuration trustzone secure stack default size.
* The secure stack must be allocated before the task calls non-secure callble functions.
*/
#ifndef LOSCFG_SECURE_STACK_DEFAULT_SIZE
#define LOSCFG_SECURE_STACK_DEFAULT_SIZE 512
#endif
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_CONFIG_H */
@@ -0,0 +1,332 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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_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 destroyed.
*
* Value: 0x02001c08
*
* Solution: Check whether the event list is not empty.
*/
#define LOS_ERRNO_EVENT_SHOULD_NOT_DESTROYED 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 of the eventCB by a specified eventMask.
*
* @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 eventMask [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 eventMask);
/**
* @ingroup los_event
* @brief Destroy an event.
*
* @par Description:
* <ul>
* <li>This API is used to Destroy an 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);
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_H */
@@ -0,0 +1,258 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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_membox Static memory
* @ingroup kernel
*/
#ifndef _LOS_MEMBOX_H
#define _LOS_MEMBOX_H
#include "los_config.h"
#include "los_debug.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#define OS_MEMBOX_NEXT(addr, blkSize) (LOS_MEMBOX_NODE *)(VOID *)((UINT8 *)(addr) + (blkSize))
#define OS_MEMBOX_NODE_HEAD_SIZE sizeof(LOS_MEMBOX_NODE)
/**
* @ingroup los_membox
* Structure of a free node in a memory pool
*/
typedef struct tagMEMBOX_NODE {
struct tagMEMBOX_NODE *pstNext; /**< Free node's pointer to the next node in a memory pool */
} LOS_MEMBOX_NODE;
/**
* @ingroup los_membox
* Memory pool information structure
*/
typedef struct LOS_MEMBOX_INFO {
UINT32 uwBlkSize; /**< Block size */
UINT32 uwBlkNum; /**< Block number */
UINT32 uwBlkCnt; /**< The number of allocated blocks */
#if (LOSCFG_PLATFORM_EXC == 1)
struct LOS_MEMBOX_INFO *nextMemBox; /**< Point to the next membox */
#endif
LOS_MEMBOX_NODE stFreeList; /**< Free list */
} LOS_MEMBOX_INFO;
typedef LOS_MEMBOX_INFO OS_MEMBOX_S;
#if (LOSCFG_PLATFORM_EXC == 1)
UINT32 OsMemboxExcInfoGet(UINT32 memNumMax, MemInfoCB *memExcInfo);
#endif
/**
* @ingroup los_membox
* Memory pool alignment
*/
#define LOS_MEMBOX_ALIGNED(memAddr) (((UINTPTR)(memAddr) + sizeof(UINTPTR) - 1) & (~(sizeof(UINTPTR) - 1)))
/**
* @ingroup los_membox
* Memory pool size
*/
#define LOS_MEMBOX_SIZE(blkSize, blkNum) \
(sizeof(LOS_MEMBOX_INFO) + (LOS_MEMBOX_ALIGNED((blkSize) + OS_MEMBOX_NODE_HEAD_SIZE) * (blkNum)))
/**
* @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 poolSize 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 LOS_MEMBOX_INFO.</li>
* </ul>
*
* @param pool [IN] Memory pool address.
* @param poolSize [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 *pool, UINT32 poolSize, 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 pool [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 *pool);
/**
* @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 box parameter must be allocated by LOS_MemboxAlloc.</li>
* </ul>
*
* @param pool [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(VOID *pool, 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 box parameter must be allocated by LOS_MemboxAlloc.</li>
* </ul>
*
* @param pool [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(VOID *pool, VOID *box);
/**
* @ingroup los_membox
* @brief show membox info.
*
* @par Description:
* <ul>
* <li>This API is used to show the memory pool info.</li>
* </ul>
* @attention
* <ul>
* <li>The input pool parameter must be initialized via func LOS_MemboxInit.</li>
* </ul>
*
* @param pool [IN] Memory pool 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_ShowBox(VOID *pool);
/**
* @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);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_MEMBOX_H */
@@ -0,0 +1,438 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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_memory Dynamic memory
* @ingroup kernel
*/
#ifndef _LOS_MEMORY_H
#define _LOS_MEMORY_H
#include "los_config.h"
#include "los_list.h"
#include "los_debug.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#if (LOSCFG_PLATFORM_EXC == 1)
UINT32 OsMemExcInfoGet(UINT32 memNumMax, MemInfoCB *memExcInfo);
#endif
/**
* @ingroup los_memory
* Starting address of the memory.
*/
#define OS_SYS_MEM_ADDR LOSCFG_SYS_HEAP_ADDR
#if (LOSCFG_MEM_LEAKCHECK == 1)
/**
* @ingroup los_memory
* @brief Print function call stack information of all used nodes.
*
* @par Description:
* <ul>
* <li>This API is used to print function call stack information of all used nodes.</li>
* </ul>
*
* @param pool [IN] Starting address of memory.
*
* @retval none.
* @par Dependency:
* <ul>
* <li>los_memory.h: the header file that contains the API declaration.</li>
* </ul>
* @see None.
*/
extern VOID LOS_MemUsedNodeShow(VOID *pool);
#endif
#if (LOSCFG_MEM_MUL_POOL == 1)
/**
* @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 #OS_ERROR 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(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
/**
* @ingroup los_memory
* Memory pool extern information structure
*/
typedef struct {
UINT32 totalUsedSize;
UINT32 totalFreeSize;
UINT32 maxFreeNodeSize;
UINT32 usedNodeNum;
UINT32 freeNodeNum;
#if (LOSCFG_MEM_WATERLINE == 1)
UINT32 usageWaterLine;
#endif
} LOS_MEM_POOL_STATUS;
/**
* @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 #OS_ERROR 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 ptr 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 ptr [IN] Starting address of the memory block to be freed.
*
* @retval #LOS_NOK The memory block fails to be freed because the starting address of the memory block is
* invalid, or the memory overwriting occurs.
* @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 *ptr);
/**
* @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 or LOS_MemAllocAlign.</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 boundary 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);
/**
* @ingroup los_memory
* @brief Get the size of memory pool's size.
*
* @par Description:
* <ul>
* <li>This API is used to get the size of memory pool' total size.</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.
* @par Dependency:
* <ul><li>los_memory.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
extern UINT32 LOS_MemPoolSizeGet(const VOID *pool);
/**
* @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 infomation of memory pool.
*
* @par Description:
* <ul>
* <li>This API is used to get the infomation of 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.
* @param poolStatus [IN] A pointer for storage the pool status
*
* @retval #LOS_NOK The incoming parameter pool is NULL or invalid.
* @retval #LOS_OK Success to get memory infomation.
* @par Dependency:
* <ul><li>los_memory.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
extern UINT32 LOS_MemInfoGet(VOID *pool, LOS_MEM_POOL_STATUS *poolStatus);
/**
* @ingroup los_memory
* @brief Get the number of free node in every size.
*
* @par Description:
* <ul>
* <li>This API is used to get the number of free node in every size.</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 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_MemFreeNodeShow(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(const VOID *pool);
/**
* @ingroup los_memory
* @brief Enable memory pool to support no internal lock during using interfaces.
*
* @par Description:
* <ul>
* <li>This API is used to enable memory pool to support no internal lock during using interfaces,</li>
* <li>such as LOS_MemAlloc/LOS_MemAllocAlign/LOS_MemRealloc/LOS_MemFree and so on.
* </ul>
* @attention
* <ul>
* <li>The memory pool does not support multi-threaded concurrent application scenarios.
* <li>If you want to use this function, you need to call this interface before the memory
* pool is used, it cannot be called during the trial period.</li>
* </ul>
*
* @param pool [IN] Starting address of memory.
*
* @retval node.
* @par Dependency:
* <ul>
* <li>los_memory.h: the header file that contains the API declaration.</li>
* </ul>
* @see None.
*/
extern VOID LOS_MemUnlockEnable(VOID *pool);
extern UINT32 OsMemSystemInit(VOID);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_MEMORY_H */
@@ -0,0 +1,350 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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_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);
/**
* @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.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
#endif /* __cplusplus */
#endif /* _LOS_MUX_H */
@@ -0,0 +1,912 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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_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>There are LOSCFG_BASE_IPC_QUEUE_LIMIT queues available, change it's value when necessary.</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 expected-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);
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.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.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.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.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_H */
@@ -0,0 +1,150 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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_SCHED_H
#define _LOS_SCHED_H
#include "los_task.h"
#include "los_interrupt.h"
#include "los_timer.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#define OS_SCHED_MAX_RESPONSE_TIME (UINT64)(((UINT64)-1) - 1U)
extern UINT32 g_taskScheduled;
typedef BOOL (*SchedScan)(VOID);
VOID OsSchedUpdateSchedTimeBase(VOID);
UINT64 OsGetCurrSchedTimeCycle(VOID);
VOID OsSchedSetIdleTaskSchedParam(LosTaskCB *idleTask);
UINT32 OsSchedSwtmrScanRegister(SchedScan func);
VOID OsSchedUpdateExpireTime(UINT64 startTime, BOOL timeUpdate);
VOID OsSchedTaskDeQueue(LosTaskCB *taskCB);
VOID OsSchedTaskEnQueue(LosTaskCB *taskCB);
VOID OsSchedTaskWait(LOS_DL_LIST *list, UINT32 timeout);
VOID OsSchedTaskWake(LosTaskCB *resumedTask);
BOOL OsSchedModifyTaskSchedParam(LosTaskCB *taskCB, UINT16 priority);
VOID OsSchedDelay(LosTaskCB *runTask, UINT32 tick);
VOID OsSchedYield(VOID);
VOID OsSchedTaskExit(LosTaskCB *taskCB);
VOID OsSchedTick(VOID);
UINT32 OsSchedInit(VOID);
VOID OsSchedStart(VOID);
BOOL OsSchedTaskSwitch(VOID);
LosTaskCB *OsGetTopTask(VOID);
UINT32 OsSchedRealSleepTimeSet(VOID (*func)(UINT64));
VOID OsSchedTimerBaseReset(UINT64 currTime);
/**
* @ingroup los_sched
* @brief Get the time, in nanoseconds, remaining before the next tick interrupt response.
*
* @par Description:
* This API is used to get the time, in nanoseconds, remaining before the next tick interrupt response.
*
* @attention None.
*
* @param None.
*
* @retval #time, in nanoseconds.
* @par Dependency:
* <ul><li>los_sched.h: the header file that contains the API declaration.</li></ul>
* @see
*/
extern UINT64 LOS_SchedTickTimeoutNsGet(VOID);
/**
* @ingroup los_sched
* @brief The system-provided tick interrupt handler.
*
* @par Description:
* This API is used to wake up a task that is blocked by time.
*
* @attention None.
*
* @param None.
*
* @retval None.
* @par Dependency:
* <ul><li>los_sched.h: the header file that contains the API declaration.</li></ul>
* @see
*/
extern VOID LOS_SchedTickHandler(VOID);
/**
* @ingroup los_sched
* @brief Trigger a system dispatch.
*
* @par Description:
* This API is used to trigger a system dispatch.
*
* @attention None.
*
* @param None.
*
* @retval None.
* @par Dependency:
* <ul><li>los_sched.h: the header file that contains the API declaration.</li></ul>
* @see
*/
extern VOID LOS_Schedule(VOID);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_SCHED_H */
@@ -0,0 +1,382 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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_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);
extern UINT32 LOS_SemGetValue(UINT32 semHandle, INT32 *currVal);
/**
* @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_config
* Max count of binary semaphores.
*/
#define OS_SEM_BINARY_MAX_COUNT 1
/**
* @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.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.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_H */
@@ -0,0 +1,76 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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_SORTLINK_H
#define _LOS_SORTLINK_H
#include "los_compiler.h"
#include "los_list.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
typedef enum {
OS_SORT_LINK_TASK = 1,
OS_SORT_LINK_SWTMR = 2,
} SortLinkType;
typedef struct {
LOS_DL_LIST sortLinkNode;
UINT64 responseTime;
} SortLinkList;
typedef struct {
LOS_DL_LIST sortLink;
} SortLinkAttribute;
#define OS_SORT_LINK_INVALID_TIME ((UINT64)-1)
#define SET_SORTLIST_VALUE(sortList, value) (((SortLinkList *)(sortList))->responseTime = (value))
SortLinkAttribute *OsGetSortLinkAttribute(SortLinkType type);
UINT64 OsGetNextExpireTime(UINT64 startTime);
UINT32 OsSortLinkInit(SortLinkAttribute *sortLinkHeader);
VOID OsDeleteNodeSortLink(SortLinkAttribute *sortLinkHeader, SortLinkList *sortList);
VOID OsAdd2SortLink(SortLinkList *node, UINT64 startTime, UINT32 waitTicks, SortLinkType type);
VOID OsDeleteSortLink(SortLinkList *node, SortLinkType type);
UINT32 OsSortLinkGetTargetExpireTime(UINT64 currTime, const SortLinkList *targetSortList);
UINT32 OsSortLinkGetNextExpireTime(const SortLinkAttribute *sortLinkHeader);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_SORTLINK_H */
@@ -0,0 +1,528 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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_sortlink.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 == 1)
#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 == 1)
UINT8 ucRouses; /* wake up enable */
UINT8 ucSensitive; /* align enable */
#endif
UINT32 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 */
SortLinkList stSortList;
} 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.
*
* @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(UINT32 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.
*
* @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(UINT32 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.
* @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(UINT32 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>There are LOSCFG_BASE_CORE_SWTMR_LIMIT timers available, change it's value when necessary.</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 == 1)
extern UINT32 LOS_SwtmrCreate(UINT32 interval,
UINT8 mode,
SWTMR_PROC_FUNC handler,
UINT32 *swtmrID,
UINT32 arg,
UINT8 rouses,
UINT8 sensitive);
#else
extern UINT32 LOS_SwtmrCreate(UINT32 interval,
UINT8 mode,
SWTMR_PROC_FUNC handler,
UINT32 *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.
*
* @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(UINT32 swtmrID);
/**
* @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 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.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.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.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_H */
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,472 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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
* @ingroup kernel
*/
#ifndef _LOS_TICK_H
#define _LOS_TICK_H
#include "los_error.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 timer cycles get function.
*
* @par Description:
* This API is used to get system timer cycles.
*
* @attention:
* <ul><li>None.</li></ul>
*
* @param: None.
*
* @retval: current system cycles.
*
* @par Dependency:
* <ul><li>los_tick.h: the header file that contains the API declaration.</li></ul>
* @see None.
*
* */
extern UINT64 LOS_SysCycleGet(VOID);
/**
* @ingroup los_tick
* Number of milliseconds in one second.
*/
#define OS_SYS_MS_PER_SECOND 1000
/**
* @ingroup los_tick
* Number of microseconds in one second.
*/
#define OS_SYS_US_PER_SECOND 1000000
#define OS_SYS_NS_PER_SECOND 1000000000
#define OS_SYS_NS_PER_US 1000
#define OS_CYCLE_PER_TICK (OS_SYS_CLOCK / LOSCFG_BASE_CORE_TICK_PER_SECOND)
#define OS_NS_PER_CYCLE (OS_SYS_NS_PER_SECOND / OS_SYS_CLOCK)
#define OS_MS_PER_TICK (OS_SYS_MS_PER_SECOND / LOSCFG_BASE_CORE_TICK_PER_SECOND)
#define OS_US_PER_TICK (OS_SYS_US_PER_SECOND / LOSCFG_BASE_CORE_TICK_PER_SECOND)
#define OS_NS_PER_TICK (OS_SYS_NS_PER_SECOND / LOSCFG_BASE_CORE_TICK_PER_SECOND)
#define OS_SYS_CYCLE_TO_NS(cycle, freq) (((cycle) / (freq)) * OS_SYS_NS_PER_SECOND + \
((cycle) % OS_SYS_CLOCK) * OS_SYS_NS_PER_SECOND / (freq))
#define OS_SYS_NS_TO_CYCLE(time, freq) (((time) / OS_SYS_NS_PER_SECOND) * (freq) + \
(time % OS_SYS_NS_PER_SECOND) * (freq) / OS_SYS_NS_PER_SECOND)
/**
* @ingroup los_tick
* 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_tick
* 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_tick
* 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_tick
* 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_tick
* 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_tick
* 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_tick
* @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_tick.h: the header file that contains the API declaration.</li></ul>
* @see None
*/
extern UINT64 LOS_TickCountGet(VOID);
/**
* @ingroup los_tick
* @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_tick.h: the header file that contains the API declaration.</li></ul>
* @see None
*/
extern UINT32 LOS_CyclePerTickGet(VOID);
/**
* @ingroup los_tick
* @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_tick.h: the header file that contains the API declaration.</li></ul>
* @see LOS_MS2Tick
*/
extern UINT32 LOS_Tick2MS(UINT32 ticks);
/**
* @ingroup los_tick
* @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_tick.h: the header file that contains the API declaration.</li></ul>
* @see LOS_Tick2MS
*/
extern UINT32 LOS_MS2Tick(UINT32 millisec);
/**
* @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.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
extern VOID OsTickHandler(VOID);
/**
* @ingroup los_tick
* 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;
/**
* @ingroup los_tick
* Number of operable bits of a 32-bit operand
*/
#define OS_SYS_MV_32_BIT 32
/**
* @ingroup los_tick
* Number of milliseconds in one second.
*/
#define OS_SYS_MS_PER_SECOND 1000
/**
* @ingroup los_tick
* Number of microseconds in one second.
*/
#define OS_SYS_US_PER_SECOND 1000000
/**
* @ingroup los_tick
* The maximum length of name.
*/
#define OS_SYS_APPVER_NAME_MAX 64
/**
* @ingroup los_tick
* The magic word.
*/
#define OS_SYS_MAGIC_WORD 0xAAAAAAAA
/**
* @ingroup los_tick
* The initialization value of stack space.
*/
#define OS_SYS_EMPTY_STACK 0xCACACACA
/**
* @ingroup los_tick
* @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_tick.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
extern UINT32 OsCpuTick2MS(CpuTick *cpuTick, UINT32 *msHi, UINT32 *msLo);
/**
* @ingroup los_tick
* @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_tick.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
extern UINT32 OsCpuTick2US(CpuTick *cpuTick, UINT32 *usHi, UINT32 *usLo);
/**
* @ingroup los_tick
* @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_tick.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_tick
* @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_tick.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_TICK_H */