source: svn/newcon3bcm2_21bu/BSEAV/lib/utils/biobits.h @ 46

Last change on this file since 46 was 46, checked in by megakiss, 11 years ago

459Mhz로 OTC 주파수 변경

  • Property svn:executable set to *
File size: 3.0 KB
Line 
1/***************************************************************************
2 *     Copyright (c) 2006-2007, Broadcom Corporation
3 *     All Rights Reserved
4 *     Confidential Property of Broadcom Corporation
5 *
6 *  THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE
7 *  AGREEMENT  BETWEEN THE USER AND BROADCOM.  YOU HAVE NO RIGHT TO USE OR
8 *  EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT.
9 *
10 * $brcm_Workfile: biobits.h $
11 * $brcm_Revision: 3 $
12 * $brcm_Date: 7/9/07 3:53p $
13 *
14 * Module Description:
15 *
16 * Bit stream utility
17 *
18 * Revision History:
19 *
20 * $brcm_Log: /BSEAV/lib/utils/biobits.h $
21 *
22 * 3   7/9/07 3:53p vsilyaev
23 * PR 32846: Improved documentation
24 *
25 * 2   10/10/06 12:16p vsilyaev
26 * PR 24844: Added bit extraction routines
27 *
28 * 1   7/28/06 4:09p vsilyaev
29 * PR 22578: Bitstream utility
30 *
31 *
32 *******************************************************************************/
33#ifndef _BIOBITS_H__
34#define _BIOBITS_H__
35
36#include "biovec.h"
37
38#ifdef __cplusplus
39extern "C"
40{
41#endif
42
43/* low level bit manipulation */
44/*
45Summary:
46Returns bit 'b' from word 'w',
47
48Example:
49        B_GET_BIT(0xDE,1)==0
50        B_GET_BIT(0xDE,7)!=0
51*/
52#define B_GET_BIT(w,b)  ((w)&(1<<(b)))
53
54/*
55Summary:
56Returns bits 'e'..'b' from word 'w',
57
58Example:
59        B_GET_BITS(0xDE,7,4)==0x0D
60        B_GET_BITS(0xDE,3,0)=0x0E
61*/
62#define B_GET_BITS(w,e,b)  (((w)>>(b))&(((unsigned)(-1))>>((sizeof(unsigned))*8-(e+1-b))))
63
64/*
65Summary:
66Sets bit 'b 'to value of 'v', 'name' is ignored (used as inline comment).
67'v' is converted to bool (0/1) before setting bit, e.g. v with values of 1 or 1000 would generate the same result
68
69Example:
70        B_SET_BIT("example 1",1,0)==1
71        B_SET_BIT("example 2",1,2)==4
72        B_SET_BIT("example 3",100,2)==4
73*/
74
75#define B_SET_BIT(name,v,b)  (((unsigned)((v)!=0)<<(b)))
76
77/*
78Summary:
79Sets bits 'e'..'b 'to value of 'v', 'name' is ignored (used as inline comment).
80'v' is not truncated to 'e'-'b', e.g. if v has more than 'e'-'b'+1 bits result is undefined
81
82*/
83#define B_SET_BITS(name,v,e,b)  (((unsigned)(v))<<(b))
84
85/*
86Summary:
87Sets bit 'b'...'e' to value of 'v', name is ignored (used as inline comment).
88'v' is not truncated, e.g. it's the user responsibilty that it would feet into the given number of bits
89
90Example:
91        B_SET_BITS("example 1",1,0,0)==1
92        B_SET_BITS("example 2",1,1,0)==1
93        B_SET_BITS("example 3",0x55,7,1)==0xAA
94*/
95
96#define B_SET_BITS(name,v,e,b)  (((unsigned)(v))<<(b))
97
98/* this type is used to define bitstrem */
99typedef struct bio_bitstream {
100        bio_cursor *cursor;
101        uint32_t cache;
102        int cache_pos;
103} bio_bitstream;
104
105void bio_bitstream_init(bio_bitstream *bs, bio_cursor *cursor);
106void bio_bitstream_dump(bio_bitstream *bs);
107bool bio_bitstream_eof(bio_bitstream *bs);
108int bio_bitstream_show(bio_bitstream *bs);
109int bio_bitstream_bit(bio_bitstream *bs);
110int bio_bitstream_drop(bio_bitstream *bs);
111unsigned bio_bitstream_bits(bio_bitstream *bs, unsigned nbits);
112void bio_bitstream_drop_bits(bio_bitstream *bs, unsigned nbits);
113
114#ifdef __cplusplus
115}
116#endif
117
118#endif /* _BIOBITS_H__ */
119
Note: See TracBrowser for help on using the repository browser.