1 /* ---------------------------------------------------------------------------- 2 * Copyright (c) Huawei Technologies Co., Ltd. 2013-2019. All rights reserved. 3 * Description: Sortlink Private HeadFile 4 * Author: Huawei LiteOS Team 5 * Create: 2013-01-01 6 * Redistribution and use in source and binary forms, with or without modification, 7 * are permitted provided that the following conditions are met: 8 * 1. Redistributions of source code must retain the above copyright notice, this list of 9 * conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 * of conditions and the following disclaimer in the documentation and/or other materials 12 * provided with the distribution. 13 * 3. Neither the name of the copyright holder nor the names of its contributors may be used 14 * to endorse or promote products derived from this software without specific prior written 15 * permission. 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 18 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 20 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 23 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 25 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * --------------------------------------------------------------------------- */ 28 29 #ifndef _LOS_SORTLINK_PRI_H 30 #define _LOS_SORTLINK_PRI_H 31 32 #include "los_typedef.h" 33 #include "los_list.h" 34 #include "los_config.h" 35 36 #ifdef __cplusplus 37 extern "C" { 38 #endif /* __cplusplus */ 39 40 /* 41 * Sortlink Rollnum Structure: 42 * ------------------------------------------ 43 * | 31 | 30 | 29 |.......| 4 | 3 | 2 | 1 | 0 | 44 * ------------------------------------------ 45 * |<-High Bits->|<---------Low Bits--------->| 46 * 47 * Low Bits : circles 48 * High Bits : sortlink index 49 */ 50 #ifndef LOSCFG_BASE_CORE_USE_SINGLE_LIST 51 #ifndef LOSCFG_BASE_CORE_USE_MULTI_LIST 52 #error "NO SORTLIST TYPE SELECTED" 53 #endif 54 #endif 55 56 #ifdef LOSCFG_BASE_CORE_USE_SINGLE_LIST 57 58 #define OS_TSK_SORTLINK_LOGLEN 0U 59 #define OS_TSK_SORTLINK_LEN 1U 60 #define OS_TSK_MAX_ROLLNUM 0xFFFFFFFEU 61 #define OS_TSK_LOW_BITS_MASK 0xFFFFFFFFU 62 63 #define SORTLINK_CURSOR_UPDATE(CURSOR) 64 #define SORTLINK_LISTOBJ_GET(LISTOBJ, SORTLINK) (LISTOBJ = SORTLINK->sortLink) 65 66 #define ROLLNUM_SUB(NUM1, NUM2) ((NUM1) = (ROLLNUM(NUM1) - ROLLNUM(NUM2))) 67 #define ROLLNUM_ADD(NUM1, NUM2) ((NUM1) = (ROLLNUM(NUM1) + ROLLNUM(NUM2))) 68 #define ROLLNUM_DEC(NUM) ((NUM) = ((NUM) - 1)) 69 #define ROLLNUM(NUM) (NUM) 70 71 #define SET_SORTLIST_VALUE(sortList, value) (((SortLinkList *)(sortList))->idxRollNum = (value)) 72 73 #else 74 75 #define OS_TSK_HIGH_BITS 3U 76 #define OS_TSK_LOW_BITS (32U - OS_TSK_HIGH_BITS) 77 #define OS_TSK_SORTLINK_LOGLEN OS_TSK_HIGH_BITS 78 #define OS_TSK_SORTLINK_LEN (1U << OS_TSK_SORTLINK_LOGLEN) 79 #define OS_TSK_SORTLINK_MASK (OS_TSK_SORTLINK_LEN - 1U) 80 #define OS_TSK_MAX_ROLLNUM (0xFFFFFFFFU - OS_TSK_SORTLINK_LEN) 81 #define OS_TSK_HIGH_BITS_MASK (OS_TSK_SORTLINK_MASK << OS_TSK_LOW_BITS) 82 #define OS_TSK_LOW_BITS_MASK (~OS_TSK_HIGH_BITS_MASK) 83 84 #define SORTLINK_CURSOR_UPDATE(CURSOR) ((CURSOR) = ((CURSOR) + 1) & OS_TSK_SORTLINK_MASK) 85 #define SORTLINK_LISTOBJ_GET(LISTOBJ, SORTLINK) ((LISTOBJ) = (SORTLINK)->sortLink + (SORTLINK)->cursor) 86 87 #define EVALUATE_L(NUM, VALUE) ((NUM) = (((NUM) & OS_TSK_HIGH_BITS_MASK) | (VALUE))) 88 89 #define EVALUATE_H(NUM, VALUE) ((NUM) = (((NUM) & OS_TSK_LOW_BITS_MASK) | ((VALUE) << OS_TSK_LOW_BITS))) 90 91 #define ROLLNUM_SUB(NUM1, NUM2) ((NUM1) = (((NUM1) & OS_TSK_HIGH_BITS_MASK) | \ 92 (ROLLNUM(NUM1) - ROLLNUM(NUM2)))) 93 94 #define ROLLNUM_ADD(NUM1, NUM2) ((NUM1) = (((NUM1) & OS_TSK_HIGH_BITS_MASK) | \ 95 (ROLLNUM(NUM1) + ROLLNUM(NUM2)))) 96 97 #define ROLLNUM_DEC(NUM) ((NUM) = ((NUM) - 1)) 98 99 #define ROLLNUM(NUM) ((NUM) & OS_TSK_LOW_BITS_MASK) 100 101 #define SORT_INDEX(NUM) ((NUM) >> OS_TSK_LOW_BITS) 102 103 #define SET_SORTLIST_VALUE(sortList, value) (((SortLinkList *)(sortList))->idxRollNum = (value)) 104 105 #endif 106 107 typedef struct { 108 LOS_DL_LIST sortLinkNode; 109 UINT32 idxRollNum; 110 } SortLinkList; 111 112 typedef struct { 113 LOS_DL_LIST *sortLink; 114 UINT16 cursor; 115 UINT16 reserved; 116 } SortLinkAttribute; 117 118 extern VOID OsSortLinkInit(SortLinkAttribute *sortLinkHeader, LOS_DL_LIST *list); 119 extern VOID OsAdd2SortLink(const SortLinkAttribute *sortLinkHeader, SortLinkList *sortList); 120 extern VOID OsDeleteSortLink(const SortLinkAttribute *sortLinkHeader, SortLinkList *sortList); 121 extern UINT32 OsSortLinkGetNextExpireTime(const SortLinkAttribute *sortLinkHeader); 122 extern UINT32 OsSortLinkGetTargetExpireTime(const SortLinkAttribute *sortLinkHeader, 123 const SortLinkList *targetSortList); 124 extern VOID OsSortLinkUpdateExpireTime(UINT32 sleepTicks, SortLinkAttribute *sortLinkHeader); 125 extern UINT32 OsSortLinkGetNextTaskExpireTime(UINT32 *taskId, UINTPTR *handler); 126 extern UINT32 OsSortLinkGetNextSwtmrExpireTime(UINT32 *swtmrId, UINTPTR *handler); 127 #ifdef __cplusplus 128 } 129 #endif /* __cplusplus */ 130 131 #endif /* _LOS_SORTLINK_PRI_H */ 132