1 /******************************************************************************
3 * Copyright (c) 2020 ICT/CAS.
5 * Licensed under the O-RAN Software License, Version 1.0 (the "Software License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * https://www.o-ran.org/software
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 *******************************************************************************/
21 #ifndef __BITS_PACK_H__
22 #define __BITS_PACK_H__
24 #include "vos_types.h"
26 /* Dependencies ------------------------------------------------------------- */
28 /* Constants ---------------------------------------------------------------- */
31 * The Bits operation type.
33 typedef enum bitOptType
35 BIT_PACKED, /* Packed bits. */
36 BIT_UNPACKED /* Unpacked bits. */
39 /* Types -------------------------------------------------------------------- */
42 * Type of Bits for pack message operation.
46 UINT8 *pMsg; /* Point to the message whitch packed or unpacked */
47 UINT32 bitOffset; /* The bit offset from the start of msg_p. */
48 UINT32 msgLen; /* The total length of the message. */
52 /* Globals ------------------------------------------------------------------ */
54 extern INT32 unpackBitsWithdebug(BitOpt_t *pBit, UINT32 n,unsigned char *fun, unsigned long line);
55 extern INT32 packBitsWithdebug(BitOpt_t *pBit, UINT32 n, UINT32 value,unsigned char *fun, unsigned long line);
56 /* Functions ---------------------------------------------------------------- */
57 /*******************************************************************************
58 * Convert length of bits to length of bytes.
60 * Input: bitLen : The lenght of bits.
62 * Output: return the length of bytes.
63 ******************************************************************************/
64 extern UINT32 convertBitlen2Bytelen(UINT32 bitLen);
66 /*******************************************************************************
67 * Get the length of message.
69 * Input: pBit : The pointer to struct bit operation.
71 * Output: return the length of message, or -1 when filed.
72 ******************************************************************************/
73 extern INT32 getBitsMsgLen(BitOpt_t *pBit, UINT32 optType);
76 /*******************************************************************************
77 * Show every bits of memory.
79 * Input: pMsg: The start pointer of memory.
80 * msgLen: The length of memory.
81 * lable: The lable of the memory.
84 ******************************************************************************/
85 extern void showBits(UINT8 *pMsg, UINT32 msgLen, INT8 *name);
87 /*******************************************************************************
88 * Initial the struct of BitOpt.
90 * Input: pBit : The pointer to struct bit operation.
91 * pMsg : Point to the message, that will be packed or unpacked.
92 * msgLen : The length of message.
93 * bitOffset : The bit offset from the start of msg_p;
95 * Output: return 0, or -1 when filed.
96 ******************************************************************************/
97 extern INT32 initBits(BitOpt_t *pBit, UINT8 *pMsg, UINT32 msgLen, UINT8 bitOffset);
99 /*******************************************************************************
100 * Skip n bits in packed or unpacked operation. Pack operation, not insure the
101 * validity of the bits that ware sikped.
103 * Input: pBit : The pointer to struct bit operation.
104 * n : The number of bits will be skiped.
106 * Output: return 0, or -1 when filed.
107 ******************************************************************************/
108 extern INT32 skipBits(BitOpt_t *pBit, UINT32 n, UINT8 optType);
110 /*******************************************************************************
111 * Unpack n bits from message, not support 32 bits or more.
113 * Input: pBit : The pointer to struct bit operation.
114 * n : The number of bits will be unpacked.
115 * msgLen : The length of message.
117 * Output: return the unpacked value, or -1 when error occur.
118 ******************************************************************************/
119 #define unpackBits(pBit,n) unpackBitsWithdebug(pBit, n,(UCHAR *)__func__,__LINE__)
121 /*******************************************************************************
122 * Pack the value into message with n bits, not support more than 32 bits.
124 * Input: pBit : The pointer to struct bit operation.
125 * n : The number of bits will be packed.
126 * value : The value need pacded into message.
128 * Output: return the length of message after packed, or -1 when filed.
129 ******************************************************************************/
130 #define packBits(pBit,n,value) packBitsWithdebug(pBit, n, value,(UCHAR *)__func__,__LINE__)