Bit I/O


Data Structures

struct  bit_buffer_tag

Defines

#define BIT_BUFFER_OK   0
#define BIT_BUFFER_OVERFLOW   1
#define BIT_BUFFER_UNDERFLOW   2
#define write_0(_bb)   write_bits(_bb, 0UL, 1)
#define write_1(_bb)   write_bits(_bb, 1UL, 1)
#define read_bit(_bb, _bit)   read_bits(_bb, _bit, 1)

Typedefs

typedef struct bit_buffer_tag bit_buffer

Functions

void init_bits (bit_buffer *bb, unsigned char *buf, int size)
int write_bits (bit_buffer *bb, int value, int size)
int read_bits (bit_buffer *bb, int *value, int size)
int flush_bits (bit_buffer *bb)

Detailed Description


Define Documentation

#define BIT_BUFFER_OK   0

#define BIT_BUFFER_OVERFLOW   1

Cannot write bits, output buffer is full

Referenced by speck_encode_I(), and write_bits().

#define BIT_BUFFER_UNDERFLOW   2

Cannot read bits, input buffer is empty

Referenced by read_bits(), and speck_decode_I().

#define write_0 ( _bb   )     write_bits(_bb, 0UL, 1)

#define write_1 ( _bb   )     write_bits(_bb, 1UL, 1)

#define read_bit ( _bb,
_bit   )     read_bits(_bb, _bit, 1)


Typedef Documentation

typedef struct bit_buffer_tag bit_buffer

Bit-buffer structure

This structure represents bit-buffer.


Function Documentation

void init_bits ( bit_buffer bb,
unsigned char *  buf,
int  size 
)

Initialize bit-buffer for reading or writting

This function initializes bit-buffer bb for reading or writting bits.

Parameters:
bb Bit-buffer to initialize
buf Actual input/output buffer
size Actual buffer size
Returns:
VOID

References bit_buffer_tag::bits, bit_buffer_tag::end, bit_buffer_tag::next, bit_buffer_tag::pending, and bit_buffer_tag::start.

Referenced by speck_decode(), and speck_encode().

int write_bits ( bit_buffer bb,
int  value,
int  size 
)

Write bits

This function writes size least significant bits of the value to the bit-buffer bb.

Note:
The function expects that size <= 24.
Parameters:
bb Bit-buffer
value Bits to write
size Number of bits to write
Returns:
Either BIT_BUFFER_OK or BIT_BUFFER_OVERFLOW

References BIT_BUFFER_OK, BIT_BUFFER_OVERFLOW, bit_buffer_tag::bits, bit_buffer_tag::end, bit_buffer_tag::next, and bit_buffer_tag::pending.

Referenced by flush_bits(), and speck_encode().

int read_bits ( bit_buffer bb,
int *  value,
int  size 
)

Read bits

This function reads size least significant bits from the bit-buffer bb into the value argument.

Note:
Function expects that size <= 24.
Parameters:
bb Bit-buffer
value Location to store the bits
size Number of bits to read
Returns:
Either BIT_BUFFER_OK or BIT_BUFFER_UNDERFLOW

References BIT_BUFFER_OK, BIT_BUFFER_UNDERFLOW, bit_buffer_tag::bits, bit_buffer_tag::end, bit_buffer_tag::next, and bit_buffer_tag::pending.

Referenced by speck_decode().

int flush_bits ( bit_buffer bb  ) 

Flush bits

This function flushes all pending bits if there are any.

Parameters:
bb Bit-buffer
Returns:
Either BIT_BUFFER_OK or BIT_BUFFER_OVERFLOW

References BIT_BUFFER_OK, bit_buffer_tag::pending, and write_bits().

Referenced by speck_encode().


Generated on Fri May 27 14:50:00 2011 for EPSILON by  doxygen 1.5.6