/* --------------------------------------------------------------------------- * Copyright (c) Huawei Technologies Co., Ltd. 2013-2019. All rights reserved. * Description: Software Timer Manager HeadFile * Author: Huawei LiteOS Team * Create: 2013-01-01 * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * 1. Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, this list * of conditions and the following disclaimer in the documentation and/or other materials * provided with the distribution. * 3. Neither the name of the copyright holder nor the names of its contributors may be used * to endorse or promote products derived from this software without specific prior written * permission. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * --------------------------------------------------------------------------- */ /*这段代码是关于软件定时器的管理接口,主要包括软件定时器的创建、启动、停止、删除等操作。这段代码提供了一套完整的软件定时器管理接口,方便开发人员在嵌入式系统中实现基于时间的任务调度和处理。*/ /** * @defgroup los_swtmr Software timer * @ingroup kernel */ #ifndef _LOS_SWTMR_H #define _LOS_SWTMR_H #include "los_base.h" #include "los_task.h" #ifdef __cplusplus #if __cplusplus extern "C" { #endif /* __cplusplus */ #endif /* __cplusplus */ /** * @ingroup los_swtmr * Software timer error code: The timeout handling function is NULL. * * Value: 0x02000300. * * Solution: Define the timeout handling function. */ #define LOS_ERRNO_SWTMR_PTR_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x00)/**/ /*错误代码LOS_ERRNO_SWTMR_PTR_NULL表示软件定时器的超时处理函数为空。这意味着当定时器到期时,没有要执行的函数*/ /** * @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]./*要解决此错误,您需要重新定义定时器的到期时间。确保到期时间大于0,并且与您的需求相符。 */ #define LOS_ERRNO_SWTMR_MODE_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x02) /*错误代码LOS_ERRNO_SWTMR_INTERVAL_NOT_SUITED表示定时器的到期时间为0。这意味着定时器的到期时间设置不合适*/ /** * @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.要解决此错误,您需要在传入函数之前定义软件定时器ID。确保为软件定时器分配一个有效的ID,并在使用该ID时进行传入。 */ #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)/ /*错误代码LOS_ERRNO_SWTMR_MAXSIZE表示软件定时器的数量超过了配置的允许最大数量。*/ /** * @ingroup los_swtmr * Software timer error code: Invalid software timer ID. * * Value: 0x02000305. * * Solution: Pass in a valid software timer ID.解决方案:传入有效的软件计时器ID */ #define LOS_ERRNO_SWTMR_ID_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x05) /*错误代码LOS_ERRNO_SWTMR_ID_INVALID表示软件计时器ID无效。*/ /** * @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) /*错误代码LOS_ERRNO_SWTMR_NOT_CREATED表示软件计时器未创建*/ /** * @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) /*错误代码LOS_ERRNO_SWTMR_NO_MEMORY内存不足,无法创建软件计时器链表*/ /** * @ingroup los_swtmr * Software timer error code: Invalid configured number of software timers. * * Value: 0x02000308. * * Solution: Re-configure the number of software timers.解决方案:重新配置软件计时器的数量。 * @deprecated This error code is obsolete since LiteOS 5.0.0. */ #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.解决方案:扩展membox分配的内存 * @deprecated This error code is obsolete since LiteOS 5.0.0. */ #define LOS_ERRNO_SWTMR_HANDLER_POOL_NO_MEM LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x0a) /*软件计时器错误代码:membox分配的内存不足*/ /** * @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 * Software timer error code: This error code is not in use temporarily. * * Value: 0x0200030f * @deprecated This error code is obsolete since LiteOS 5.0.0. */ #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) /*软件计时器错误代码:软件计时器上配置的传入的剩余Tick数为NULL*/ /** * @ingroup los_swtmr * Software timer error code: The software sortlink fails to be created. * * Value: 0x02000311. * * Solution: Check whether the memory is sufficient and re-create the sortlink. */ #define LOS_ERRNO_SWTMR_SORTLINK_CREATE_FAILED LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x11) /*软件计时器错误代码:无法创建软件排序链接。*/ /** * @ingroup los_swtmr * Software timer mode */ enum enSwTmrType { LOS_SWTMR_MODE_ONCE, /**< One-off software timer, the value is 0. */ LOS_SWTMR_MODE_PERIOD, /**< Periodic software timer, the value is 1. */ LOS_SWTMR_MODE_NO_SELFDELETE, /**< One-off software timer, but not self-delete, the value is 2. */ LOS_SWTMR_MODE_OPP /**< After the one-off timer finishes timing, the periodic software timer is enabled. The value is 3. This mode is not supported temporarily. */ }; /*这段代码定义了软件定时器的模式,使用了一个枚举类型enSwTmrType来表示。其中包含以下几种模式: LOS_SWTMR_MODE_ONCE:一次性软件定时器,值为0。 LOS_SWTMR_MODE_PERIOD:周期性软件定时器,值为1。 LOS_SWTMR_MODE_NO_SELFDELETE:一次性软件定时器,但不会自我删除,值为2。 LOS_SWTMR_MODE_OPP:在一次性定时器完成定时后,启用周期性软件定时器。该模式的值为3。目前暂不支持该模式*/ /** * @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 * None. * * @param arg [IN] the parameter of the callback function that handles software timer timeout. * * @retval None. * @par Dependency: *