1 /******************************************************************************
2 ###############################################################################
3 # Copyright (c) [2017-2020] [ICT/CAS] #
4 # Licensed under the ORAN Software License v1.0 (License) #
5 ###############################################################################
6 ******************************************************************************/
9 #ifndef __BITS_PACK_H__
10 #define __BITS_PACK_H__
12 #include "vos_types.h"
14 /* Dependencies ------------------------------------------------------------- */
16 /* Constants ---------------------------------------------------------------- */
19 * The Bits operation type.
21 typedef enum bitOptType
23 BIT_PACKED, /* Packed bits. */
24 BIT_UNPACKED /* Unpacked bits. */
27 /* Types -------------------------------------------------------------------- */
30 * Type of Bits for pack message operation.
34 UINT8 *pMsg; /* Point to the message whitch packed or unpacked */
35 UINT32 bitOffset; /* The bit offset from the start of msg_p. */
36 UINT32 msgLen; /* The total length of the message. */
40 /* Globals ------------------------------------------------------------------ */
42 extern INT32 unpackBitsWithdebug(BitOpt_t *pBit, UINT32 n,unsigned char *fun, unsigned long line);
43 extern INT32 packBitsWithdebug(BitOpt_t *pBit, UINT32 n, UINT32 value,unsigned char *fun, unsigned long line);
44 /* Functions ---------------------------------------------------------------- */
45 /*******************************************************************************
46 * Convert length of bits to length of bytes.
48 * Input: bitLen : The lenght of bits.
50 * Output: return the length of bytes.
51 ******************************************************************************/
52 extern UINT32 convertBitlen2Bytelen(UINT32 bitLen);
54 /*******************************************************************************
55 * Get the length of message.
57 * Input: pBit : The pointer to struct bit operation.
59 * Output: return the length of message, or -1 when filed.
60 ******************************************************************************/
61 extern INT32 getBitsMsgLen(BitOpt_t *pBit, UINT32 optType);
64 /*******************************************************************************
65 * Show every bits of memory.
67 * Input: pMsg: The start pointer of memory.
68 * msgLen: The length of memory.
69 * lable: The lable of the memory.
72 ******************************************************************************/
73 extern void showBits(UINT8 *pMsg, UINT32 msgLen, INT8 *name);
75 /*******************************************************************************
76 * Initial the struct of BitOpt.
78 * Input: pBit : The pointer to struct bit operation.
79 * pMsg : Point to the message, that will be packed or unpacked.
80 * msgLen : The length of message.
81 * bitOffset : The bit offset from the start of msg_p;
83 * Output: return 0, or -1 when filed.
84 ******************************************************************************/
85 extern INT32 initBits(BitOpt_t *pBit, UINT8 *pMsg, UINT32 msgLen, UINT8 bitOffset);
87 /*******************************************************************************
88 * Skip n bits in packed or unpacked operation. Pack operation, not insure the
89 * validity of the bits that ware sikped.
91 * Input: pBit : The pointer to struct bit operation.
92 * n : The number of bits will be skiped.
94 * Output: return 0, or -1 when filed.
95 ******************************************************************************/
96 extern INT32 skipBits(BitOpt_t *pBit, UINT32 n, UINT8 optType);
98 /*******************************************************************************
99 * Unpack n bits from message, not support 32 bits or more.
101 * Input: pBit : The pointer to struct bit operation.
102 * n : The number of bits will be unpacked.
103 * msgLen : The length of message.
105 * Output: return the unpacked value, or -1 when error occur.
106 ******************************************************************************/
107 #define unpackBits(pBit,n) unpackBitsWithdebug(pBit, n,(UCHAR *)__func__,__LINE__)
109 /*******************************************************************************
110 * Pack the value into message with n bits, not support more than 32 bits.
112 * Input: pBit : The pointer to struct bit operation.
113 * n : The number of bits will be packed.
114 * value : The value need pacded into message.
116 * Output: return the length of message after packed, or -1 when filed.
117 ******************************************************************************/
118 #define packBits(pBit,n,value) packBitsWithdebug(pBit, n, value,(UCHAR *)__func__,__LINE__)