los_swtmr.h

浏览该文件的文档。
00001 /*----------------------------------------------------------------------------
00002  * Copyright (c) <2013-2015>, <Huawei Technologies Co., Ltd>
00003  * All rights reserved.
00004  * Redistribution and use in source and binary forms, with or without modification,
00005  * are permitted provided that the following conditions are met:
00006  * 1. Redistributions of source code must retain the above copyright notice, this list of
00007  * conditions and the following disclaimer.
00008  * 2. Redistributions in binary form must reproduce the above copyright notice, this list
00009  * of conditions and the following disclaimer in the documentation and/or other materials
00010  * provided with the distribution.
00011  * 3. Neither the name of the copyright holder nor the names of its contributors may be used
00012  * to endorse or promote products derived from this software without specific prior written
00013  * permission.
00014  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00015  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
00016  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00017  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
00018  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00019  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00020  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
00021  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
00022  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
00023  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00024  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00025  *---------------------------------------------------------------------------*/
00026 /*----------------------------------------------------------------------------
00027  * Notice of Export Control Law
00028  * ===============================================
00029  * Huawei LiteOS may be subject to applicable export control laws and regulations, which might
00030  * include those applicable to Huawei LiteOS of U.S. and the country in which you are located.
00031  * Import, export and usage of Huawei LiteOS in any manner by you shall be in compliance with such
00032  * applicable export control laws and regulations.
00033  *---------------------------------------------------------------------------*/
00034 
00035 /** @defgroup los_swtmr Software timer
00036  * @ingroup kernel
00037  */
00038 
00039 #ifndef _LOS_SWTMR_H
00040 #define _LOS_SWTMR_H
00041 
00042 #include "los_base.h"
00043 #include "los_task.h"
00044 
00045 #ifdef __cplusplus
00046 #if __cplusplus
00047 extern "C" {
00048 #endif /* __cplusplus */
00049 #endif /* __cplusplus */
00050 
00051 
00052 /**
00053  * @ingroup los_swtmr
00054  * Software timer error code: The timeout handling function is NULL.
00055  *
00056  * Value: 0x02000300
00057  *
00058  * Solution: Define the timeout handling function.
00059  */
00060 #define LOS_ERRNO_SWTMR_PTR_NULL                     LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x00)
00061 
00062 /**
00063  * @ingroup los_swtmr
00064  * Software timer error code: The expiration time is 0.
00065  *
00066  * Value: 0x02000301
00067  *
00068  * Solution: Re-define the expiration time.
00069  */
00070 #define LOS_ERRNO_SWTMR_INTERVAL_NOT_SUITED          LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x01)
00071 
00072 /**
00073  * @ingroup los_swtmr
00074  * Software timer error code: Invalid software timer mode.
00075  *
00076  * Value: 0x02000302
00077  *
00078  * Solution: Check the mode value. The value range is [0,3].
00079  */
00080 #define LOS_ERRNO_SWTMR_MODE_INVALID                 LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x02)
00081 
00082 /**
00083  * @ingroup los_swtmr
00084  * Software timer error code: The passed-in software timer ID is NULL.
00085  *
00086  * Value: 0x02000303
00087  *
00088  * Solution: Define the software timer ID before passing it in.
00089  */
00090 #define LOS_ERRNO_SWTMR_RET_PTR_NULL                 LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x03)
00091 
00092 /**
00093  * @ingroup los_swtmr
00094  * Software timer error code: The number of software timers exceeds the configured permitted maximum number.
00095  *
00096  * Value: 0x02000304
00097  *
00098  * Solution: Re-configure the permitted maximum number of software timers, or wait for a software timer to become available.
00099  */
00100 #define LOS_ERRNO_SWTMR_MAXSIZE                      LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x04)
00101 
00102 /**
00103  * @ingroup los_swtmr
00104  * Software timer error code: Invalid software timer ID.
00105  *
00106  * Value: 0x02000305
00107  *
00108  * Solution: Pass in a valid software timer ID.
00109  */
00110 #define LOS_ERRNO_SWTMR_ID_INVALID                   LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x05)
00111 
00112 /**
00113  * @ingroup los_swtmr
00114  * Software timer error code: The software timer is not created.
00115  *
00116  * Value: 0x02000306
00117  *
00118  * Solution: Create a software timer.
00119  */
00120 #define LOS_ERRNO_SWTMR_NOT_CREATED                  LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x06)
00121 
00122 /**
00123  * @ingroup los_swtmr
00124  * Software timer error code: Insufficient memory for software timer linked list creation.
00125  *
00126  * Value: 0x02000307
00127  *
00128  * Solution: Allocate bigger memory partition to software timer linked list creation.
00129  */
00130 #define LOS_ERRNO_SWTMR_NO_MEMORY                    LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x07)
00131 
00132 /**
00133  * @ingroup los_swtmr
00134  * Software timer error code: Invalid configured number of software timers.
00135  *
00136  * Value: 0x02000308
00137  *
00138  * Solution: Re-configure the number of software timers.
00139  */
00140 #define LOS_ERRNO_SWTMR_MAXSIZE_INVALID              LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x08)
00141 
00142 /**
00143  * @ingroup los_swtmr
00144  * Software timer error code: The software timer is being used during an interrupt.
00145  *
00146  * Value: 0x02000309
00147  *
00148  * Solution: Change the source code and do not use the software timer during an interrupt.
00149  */
00150 #define LOS_ERRNO_SWTMR_HWI_ACTIVE                   LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x09)
00151 
00152 /**
00153  * @ingroup los_swtmr
00154  * Software timer error code: Insufficient memory allocated by membox.
00155  *
00156  * Value: 0x0200030a
00157  *
00158  * Solution: Expand the memory allocated by membox.
00159  */
00160 #define LOS_ERRNO_SWTMR_HANDLER_POOL_NO_MEM          LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x0a)
00161 
00162 /**
00163  * @ingroup los_swtmr
00164  * Software timer error code: The software timer queue fails to be created.
00165  *
00166  * Value: 0x0200030b
00167  *
00168  * Solution: Check whether more memory can be allocated to the queue to be created.
00169  */
00170 #define LOS_ERRNO_SWTMR_QUEUE_CREATE_FAILED          LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x0b)
00171 
00172 /**
00173  * @ingroup los_swtmr
00174  * Software timer error code: The software timer task fails to be created.
00175  *
00176  * Value: 0x0200030c
00177  *
00178  * Solution: Check whether the memory is sufficient and re-create the task.
00179  */
00180 #define LOS_ERRNO_SWTMR_TASK_CREATE_FAILED           LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x0c)
00181 
00182 /**
00183  * @ingroup los_swtmr
00184  * Software timer error code: The software timer is not started.
00185  *
00186  * Value: 0x0200030d
00187  *
00188  * Solution: Start the software timer.
00189  */
00190 #define LOS_ERRNO_SWTMR_NOT_STARTED                  LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x0d)
00191 
00192 /**
00193  * @ingroup los_swtmr
00194  * Software timer error code: Invalid software timer state.
00195  *
00196  * Value: 0x0200030e
00197  *
00198  * Solution: Check the software timer state.
00199  */
00200 #define LOS_ERRNO_SWTMR_STATUS_INVALID               LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x0e)
00201 
00202 /**
00203  * @ingroup los_swtmr
00204  * This error code is not in use temporarily.
00205  */
00206 #define LOS_ERRNO_SWTMR_SORTLIST_NULL                LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x0f)
00207 
00208 /**
00209  * @ingroup los_swtmr
00210  * Software timer error code: The passed-in number of remaining Ticks configured on the software timer is NULL.
00211  *
00212  * Value: 0x02000310
00213  *
00214  * Solution: Define a variable of the number of remaining Ticks before passing in the number of remaining Ticks.
00215  */
00216 #define LOS_ERRNO_SWTMR_TICK_PTR_NULL                LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x10)
00217 
00218 #if (LOSCFG_BASE_CORE_SWTMR_ALIGN == YES)
00219 #define OS_ERRNO_SWTMR_ROUSES_INVALID               LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x11)
00220 #define OS_ERRNO_SWTMR_ALIGN_INVALID                LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x12)
00221 
00222 #define OS_SWTMR_BIT_ALREADY_ALIGNED                (1 << 31)
00223 #define OS_SWTMR_BIT_CAN_ALIGNED                    (1 << 30)
00224 #define OS_SWTMR_BIT_MULTIPLE                       (1 << 29)
00225 
00226 #define SET_ALIGN_SWTMR_ALREADY_ALIGNED(num)                ((num) = 0x80000000 | ((num) & 0x7FFFFFFF))
00227 #define SET_ALIGN_SWTMR_ALREADY_NOT_ALIGNED(num)            ((num) = ((num) & 0x7FFFFFFF))
00228 #define SET_ALIGN_SWTMR_CAN_ALIGNED(num)                    ((num) = 0x40000000| (num & 0xBFFFFFFF))
00229 #define SET_ALIGN_SWTMR_CAN_NOT_ALIGNED(num)                ((num) = (num & 0xBFFFFFFF))
00230 #define SET_ALIGN_SWTMR_CAN_MULTIPLE(num)                   ((num)= 0x20000000|(num & 0xDFFFFFFF) )
00231 #define SET_ALIGN_SWTMR_CAN_NOT_MULTIPLE(num)               ((num)= (num & 0xDFFFFFFF) )
00232 #define SET_ALIGN_SWTMR_DIVISOR_TIMERS(num, value)          (num = (value & 0x00FFFFFF) | (num & 0xFF000000))//bit23:0
00233 #define GET_ALIGN_SWTMR_DIVISOR_TIMERS(num)                 (num & 0x00FFFFFF)
00234 
00235 #define CHECK_ALIGN_SWTMR_CAN_MULTI_ALIGN(num)              ((num & 0xE0000000) == 0x60000000)
00236 #define CHECK_ALIGN_SWTMR_CAN_PERIODIC_ALIGN(num)           ((num & 0xE0000000) == 0x40000000)
00237 #define CHECK_ALIGN_SWTMR_ALREADY_ALIGN(num)                ((num & 0xC0000000) == 0xC0000000)
00238 
00239 enum enSwTmrRousesType
00240 {
00241     OS_SWTMR_ROUSES_IGNORE,    /* timer don't need to wake up system */
00242     OS_SWTMR_ROUSES_ALLOW,     /* timer can wake up system */
00243 };
00244 
00245 enum enSwTmrAlignSensitive
00246 {
00247     OS_SWTMR_ALIGN_SENSITIVE,         /* timer don't need to align  */
00248     OS_SWTMR_ALIGN_INSENSITIVE,     /* timer need to align */
00249 };
00250 #endif
00251 
00252 /**
00253  * @ingroup los_swtmr
00254  * Software timer mode
00255  */
00256 enum enSwTmrType
00257 {
00258     LOS_SWTMR_MODE_ONCE,                 /**< One-off software timer */
00259     LOS_SWTMR_MODE_PERIOD,               /**< Periodic software timer */
00260     LOS_SWTMR_MODE_NO_SELFDELETE,        /**< One-off software timer, but not self-delete */
00261     LOS_SWTMR_MODE_OPP,                  /**< After the one-off timer finishes timing, the periodic software timer is enabled. This mode is not supported temporarily.*/
00262 };
00263 
00264 /**
00265 * @ingroup  los_swtmr
00266 * @brief Define the type of a callback function that handles software timer timeout.
00267 *
00268 * @par Description:
00269 * 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.
00270 *
00271 * @attention
00272 * <ul>
00273 * <li>None.</li>
00274 * </ul>
00275 *
00276 * @param  uwPar     [IN] the parameter of the callback function that handles software timer timeout.
00277 *
00278 * @retval None.
00279 * @par Dependency:
00280 * <ul><li>los_swtmr.h: the header file that contains the API declaration.</li></ul>
00281 * @see None.
00282 * @since Huawei LiteOS V100R001C00
00283 */
00284 typedef VOID (*SWTMR_PROC_FUNC)(UINT32 uwPar);
00285 
00286 /**
00287  * @ingroup los_swtmr
00288  * Software timer control structure
00289  */
00290 typedef struct tagSwTmrCtrl
00291 {
00292     struct tagSwTmrCtrl *pstNext;       /**< Pointer to the next software timer                      */
00293     UINT8               ucState;        /**< Software timer state                                    */
00294     UINT8               ucMode;         /**< Software timer mode                                     */
00295 #if (LOSCFG_BASE_CORE_SWTMR_ALIGN == YES)
00296     UINT8               ucRouses;       /*wake up enable                                             */
00297     UINT8               ucSensitive;    /*align enable                                               */
00298 #endif
00299     UINT16              usTimerID;      /**< Software timer ID                                       */
00300     UINT32              uwCount;        /**< Times that a software timer works                       */
00301     UINT32              uwInterval;     /**< Timeout interval of a periodic software timer           */
00302     UINT32              uwArg;          /**< Parameter passed in when the callback function that handles software timer timeout is called */
00303     SWTMR_PROC_FUNC     pfnHandler;     /**< Callback function that handles software timer timeout   */
00304 } SWTMR_CTRL_S;
00305 
00306 
00307 /**
00308  *@ingroup los_swtmr
00309  *@brief Start a software timer.
00310  *
00311  *@par Description:
00312  *This API is used to start a software timer that has a specified ID.
00313  *@attention
00314  *<ul>
00315  *<li>The specific timer must be created first</li>
00316  *</ul>
00317  *
00318  *@param  usSwTmrID  [IN] Software timer ID created by LOS_SwtmrCreate. The value of ID should be in [0, LOSCFG_BASE_CORE_SWTMR_LIMIT - 1].
00319  *
00320  *@retval #LOS_ERRNO_SWTMR_ID_INVALID       Invalid software timer ID.
00321  *@retval #LOS_ERRNO_SWTMR_NOT_CREATED      The software timer is not created.
00322  *@retval #LOS_ERRNO_SWTMR_STATUS_INVALID   Invalid software timer state.
00323  *@retval #LOS_OK                           The software timer is successfully started.
00324  *@par Dependency:
00325  *<ul><li>los_swtmr.h: the header file that contains the API declaration.</li></ul>
00326  *@see LOS_SwtmrStop | LOS_SwtmrCreate
00327  *@since Huawei LiteOS V100R001C00
00328  */
00329 extern UINT32 LOS_SwtmrStart(UINT16 usSwTmrID);
00330 
00331 /**
00332  *@ingroup los_swtmr
00333  *@brief Stop a software timer.
00334  *
00335  *@par Description:
00336  *This API is used to stop a software timer that has a specified ID.
00337  *@attention
00338  *<ul>
00339  *<li>The specific timer should be created and started firstly.</li>
00340  *</ul>
00341  *
00342  *@param  usSwTmrID  [IN] Software timer ID created by LOS_SwtmrCreate. The value of ID should be in [0, LOSCFG_BASE_CORE_SWTMR_LIMIT - 1].
00343  *
00344  *@retval #LOS_ERRNO_SWTMR_ID_INVALID       Invalid software timer ID.
00345  *@retval #LOS_ERRNO_SWTMR_NOT_CREATED      The software timer is not created.
00346  *@retval #LOS_ERRNO_SWTMR_NOT_STARTED      The software timer is not started.
00347  *@retval #LOS_ERRNO_SWTMR_STATUS_INVALID   Invalid software timer state.
00348  *@retval #LOS_OK                           The software timer is successfully stopped.
00349  *@par Dependency:
00350  *<ul><li>los_swtmr.h: the header file that contains the API declaration.</li></ul>
00351  *@see LOS_SwtmrStart | LOS_SwtmrCreate
00352  *@since Huawei LiteOS V100R001C00
00353  */
00354 extern UINT32 LOS_SwtmrStop(UINT16 usSwTmrID);
00355 
00356 /**
00357  *@ingroup los_swtmr
00358  *@brief Obtain the number of remaining Ticks configured on a software timer.
00359  *
00360  *@par Description:
00361  *This API is used to obtain the number of remaining Ticks configured on the software timer of which the ID is specified by usSwTmrID.
00362  *@attention
00363  *<ul>
00364  *<li>The specific timer should be created and started successfully, error happends otherwise.</li>
00365  *</ul>
00366  *
00367  *@param  usSwTmrID  [IN]  Software timer ID created by LOS_SwtmrCreate. The value of ID should be in [0, LOSCFG_BASE_CORE_SWTMR_LIMIT - 1].
00368  *@param  uwTick     [OUT] Number of remaining Ticks configured on the software timer.
00369  *
00370  *@retval #LOS_ERRNO_SWTMR_ID_INVALID      Invalid software timer ID.
00371  *@retval #LOS_ERRNO_SWTMR_NOT_CREATED     The software timer is not created.
00372  *@retval #LOS_ERRNO_SWTMR_NOT_STARTED     The software timer is not started.
00373  *@retval #LOS_ERRNO_SWTMR_STATUS_INVALID  Invalid software timer state.
00374  *@retval #LOS_OK                          The number of remaining Ticks is successfully obtained.
00375  *@par Dependency:
00376  *<ul><li>los_swtmr.h: the header file that contains the API declaration.</li></ul>
00377  *@see LOS_SwtmrCreate
00378  *@since Huawei LiteOS V100R001C00
00379  */
00380 extern UINT32 LOS_SwtmrTimeGet(UINT16 usSwTmrID, UINT32 *uwTick);
00381 
00382 /**
00383  *@ingroup los_swtmr
00384  *@brief Create a software timer.
00385  *
00386  *@par Description:
00387  *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.
00388  *@attention
00389  *<ul>
00390  *<li>Do not use the delay interface in the callback function that handles software timer timeout.</li>
00391  *<li>Threre are LOSCFG_BASE_CORE_SWTMR_LIMIT timers available, change it's value when necessory.</li>
00392  *</ul>
00393  *
00394  *@param  uwInterval     [IN] Timing duration of the software timer to be created (unit: ms).
00395  *@param  ucMode         [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.
00396  *@param  pfnHandler     [IN] Callback function that handles software timer timeout.
00397  *@param  pusSwTmrID     [OUT] Software timer ID created by LOS_SwtmrCreate.
00398  *@param  uwArg          [IN] Parameter passed in when the callback function that handles software timer timeout is called.
00399  *
00400  *@retval #LOS_ERRNO_SWTMR_INTERVAL_NOT_SUITED   The software timer timeout interval is 0.
00401  *@retval #LOS_ERRNO_SWTMR_MODE_INVALID          Invalid software timer mode.
00402  *@retval #LOS_ERRNO_SWTMR_PTR_NULL              The callback function that handles software timer timeout is NULL.
00403  *@retval #LOS_ERRNO_SWTMR_RET_PTR_NULL          The passed-in software timer ID is NULL.
00404  *@retval #LOS_ERRNO_SWTMR_MAXSIZE               The number of software timers exceeds the configured permitted maximum number.
00405  *@retval #LOS_OK                                The software timer is successfully created.
00406  *@par Dependency:
00407  *<ul><li>los_swtmr.h: the header file that contains the API declaration.</li></ul>
00408  *@see LOS_SwtmrDelete
00409  *@since Huawei LiteOS V100R001C00
00410  */
00411  extern UINT32 LOS_SwtmrCreate(UINT32 uwInterval, UINT8 ucMode, SWTMR_PROC_FUNC pfnHandler, UINT16 *pusSwTmrID, UINT32 uwArg
00412                                           #if (LOSCFG_BASE_CORE_SWTMR_ALIGN == YES)
00413                                           , UINT8 ucRouses, UINT8 ucSensitive
00414                                           #endif
00415                                           );
00416 
00417 /**
00418  *@ingroup los_swtmr
00419  *@brief Delete a software timer.
00420  *
00421  *@par Description:
00422  *This API is used to delete a software timer.
00423  *@attention
00424  *<ul>
00425  *<li>The specific timer should be created and then stopped firstly.</li>
00426  *</ul>
00427  *
00428  *@param  usSwTmrID     [IN] Software timer ID created by LOS_SwtmrCreate. The value of ID should be in [0, LOSCFG_BASE_CORE_SWTMR_LIMIT - 1].
00429  *
00430  *@retval #LOS_ERRNO_SWTMR_ID_INVALID        Invalid software timer ID.
00431  *@retval #LOS_ERRNO_SWTMR_NOT_CREATED       The software timer is not created.
00432  *@retval #LOS_ERRNO_SWTMR_STATUS_INVALID    Invalid software timer state.
00433  *@retval #LOS_OK                            The software timer is successfully deleted.
00434  *@par Dependency:
00435  *<ul><li>los_swtmr.h: the header file that contains the API declaration.</li></ul>
00436  *@see LOS_SwtmrCreate
00437  *@since Huawei LiteOS V100R001C00
00438  */
00439 extern UINT32 LOS_SwtmrDelete(UINT16 usSwTmrID);
00440 
00441 
00442 #ifdef __cplusplus
00443 #if __cplusplus
00444 }
00445 #endif /* __cplusplus */
00446 #endif /* __cplusplus */
00447 
00448 #endif /* _LOS_SWTMR_H */