3c90d6dd60c5e4588d3bca6fd490f9c2ed25f453
[scp/ocu/5gnr.git] / Include / bitsPack.h
1 /******************************************************************************
2 ###############################################################################
3 #   Copyright (c) [2017-2020] [ICT/CAS]                                        #
4 #   Licensed under the ORAN Software License v1.0 (License)             #
5 ###############################################################################
6 ******************************************************************************/
7
8
9 #ifndef __BITS_PACK_H__
10 #define __BITS_PACK_H__
11
12 #include "vos_types.h"
13
14 /* Dependencies ------------------------------------------------------------- */
15
16 /* Constants ---------------------------------------------------------------- */
17
18 /*
19  * The Bits operation type.
20  */
21 typedef enum bitOptType
22 {
23     BIT_PACKED,     /* Packed bits. */
24     BIT_UNPACKED    /* Unpacked bits. */
25 } BitOptType_t;
26
27 /* Types -------------------------------------------------------------------- */
28
29 /*
30  * Type of Bits for pack message operation.
31  */
32 typedef struct bitOpt
33 {
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. */
37 } BitOpt_t;
38
39
40 /* Globals ------------------------------------------------------------------ */
41
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.
47  *
48  * Input: bitLen : The lenght of bits.
49  *
50  * Output: return the length of bytes.
51  ******************************************************************************/
52 extern UINT32 convertBitlen2Bytelen(UINT32 bitLen);
53
54 /*******************************************************************************
55  * Get the length of message.
56  *
57  * Input: pBit : The pointer to struct bit operation.
58  *
59  * Output: return the length of message, or -1 when filed.
60  ******************************************************************************/
61 extern INT32 getBitsMsgLen(BitOpt_t *pBit, UINT32 optType);
62
63
64 /*******************************************************************************
65  * Show every bits of memory.
66  *
67  * Input: pMsg: The start pointer of memory.
68  *        msgLen: The length of memory.
69  *        lable: The lable of the memory.
70  *
71  * Output: None.
72  ******************************************************************************/
73 extern void showBits(UINT8 *pMsg, UINT32 msgLen, INT8 *name);
74
75 /*******************************************************************************
76  * Initial the struct of BitOpt.
77  *
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;
82  *
83  * Output: return 0, or -1 when filed.
84  ******************************************************************************/
85 extern INT32 initBits(BitOpt_t *pBit, UINT8 *pMsg, UINT32 msgLen, UINT8 bitOffset);
86
87 /*******************************************************************************
88  * Skip n bits in packed or unpacked operation. Pack operation, not insure the
89  * validity of the bits that ware sikped.
90  *
91  * Input: pBit : The pointer to struct bit operation.
92  *        n : The number of bits will be skiped.
93  *
94  * Output: return 0, or -1 when filed.
95  ******************************************************************************/
96 extern INT32 skipBits(BitOpt_t *pBit, UINT32 n, UINT8 optType);
97
98 /*******************************************************************************
99  * Unpack n bits from message, not support 32 bits or more.
100  *
101  * Input: pBit : The pointer to struct bit operation.
102  *        n : The number of bits will be unpacked.
103  *        msgLen : The length of message.
104  *
105  * Output: return the unpacked value, or -1 when error occur.
106  ******************************************************************************/
107 #define unpackBits(pBit,n)  unpackBitsWithdebug(pBit,  n,(UCHAR *)__func__,__LINE__)
108
109 /*******************************************************************************
110  * Pack the value into message with n bits, not support more than 32 bits.
111  *
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.
115  *
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__)
119
120 #endif
121
122
123
124