typedef struct readBitsContext { const muchar_t *buff; muint32_t bitpos; muint32_t nb; } readBitsContext_t; static muint32_t readBits(readBitsContext_t *ctx, muint32_t nbits) { const muchar_t *p = ctx->buff + ctx->bitpos/8; muint32_t pos = ctx->bitpos % 8; mint32_t bits2go = nbits; muint64_t res = 0; const muchar_t mask[8] = {0xff, 0x7f, 0x3f, 0x1f, 0x0f, 0x07, 0x03, 0x01}; if(pos + nbits > ctx->nb * 8) { ctx->bitpos = ctx->nb*8; ELOG(log_domain,"Trying to read past end of buffer, ignoring"); goto done; } while (bits2go > 0) { res = (res << 8) | (*p++ & mask[pos]); bits2go -= (8 - pos); pos = 0; } bits2go = -bits2go; res >>= bits2go; ctx->bitpos += nbits; done: return (muint32_t) res; }
2012/06/05
Read bits from stream
Subscribe to:
Post Comments (Atom)
Post Code on Blogger
Simplest way to post code to blogger for me: <pre style="background: #f0f0f0; border: 1px dashed #CCCCCC; color: black;overflow-x:...
-
Explain There is not interrupt PIN for PCIe interrupt. When device wants to raise an interrupt, an interrupt message is sent to host via ...
-
Configure Space Addressing One of the major improvements the PCI Local Bus had over other I/O architectures was its configuration mechanism...
-
What is LMA and VMA Every loadable or allocatable output section has two addresses. The first is the VMA, or virtual memory address. This ...
No comments:
Post a Comment