BeRTOS
Defines | Functions
bitarray.h File Reference

Bitarray module. More...

#include <cfg/compiler.h>
#include <cfg/macros.h>
#include <cfg/debug.h>
#include <cpu/types.h>

Go to the source code of this file.

Defines

#define BITARRAY_ALLOC(name, size)   uint8_t name[DIV_ROUNDUP((size), 8)]
 Convenience macro to create a memory area for the BitArray.

Functions

void bitarray_set (BitArray *bitx, int idx)
 Set one bit into the bit array.
void bitarray_clear (BitArray *bitx, int idx)
 Clear one bit in the bit array.
void bitarray_setRange (BitArray *bitx, int idx, int offset)
 Set a range of bits.
void bitarray_clearRange (BitArray *bitx, int idx, int offset)
 Clear a range of bits.
bool bitarray_test (BitArray *bitx, int idx)
 Test a bit.
bool bitarray_isFull (BitArray *bitx)
 Check if the bitarray is full.
bool bitarray_isRangeFull (BitArray *bitx, int idx, int offset)
 Test if a range of bit is full.
bool bitarray_isRangeEmpty (BitArray *bitx, int idx, int offset)
 Test if a range of bit is empty.
void bitarray_dump (BitArray *bitx)
 Print on debug serial a BitArray.
void bitarray_init (BitArray *bitx, size_t bitarray_len, uint8_t *array, size_t size)
 Init a BitArray.

Detailed Description

Bitarray module.

Author:
Daniele Basile <asterix@develer.com>

Definition in file bitarray.h.


Define Documentation

#define BITARRAY_ALLOC (   name,
  size 
)    uint8_t name[DIV_ROUNDUP((size), 8)]

Convenience macro to create a memory area for the BitArray.

Parameters:
nameName of the variable.
sizeNumber of bits requested. It will be rounded to the nearest byte

Definition at line 61 of file bitarray.h.


Function Documentation

void bitarray_clear ( BitArray *  bitx,
int  idx 
) [inline]

Clear one bit in the bit array.

Parameters:
bitxBitArray context
idxThe bit to clear

Definition at line 83 of file bitarray.h.

void bitarray_clearRange ( BitArray *  bitx,
int  idx,
int  offset 
) [inline]

Clear a range of bits.

The range starts from idx (inclusive) and spans offset bits.

Parameters:
bitxBitArray context
idxStarting bit
offsetNumber of bits to clear

Definition at line 119 of file bitarray.h.

void bitarray_dump ( BitArray *  bitx) [inline]

Print on debug serial a BitArray.

Note:
This module does not use the logging module, so you can't decide the logging level.
Parameters:
bitxBitArray to be printed.

Definition at line 217 of file bitarray.h.

void bitarray_init ( BitArray *  bitx,
size_t  bitarray_len,
uint8_t *  array,
size_t  size 
) [inline]

Init a BitArray.

The BitArray uses an external array for storage. You can use the macro BITARRAY_ALLOC to declare an appropriate memory size. Example usage:

 BITARRAY_ALLOC(bits_mem, 17);
 BitArray bits;
 bitarray_init(&bits, 17, bits_mem, sizeof(bits_mem))
Parameters:
bitxBitArray context
bitarray_lenNumber of bits in the BitArray
arrayMemory area for the BitArray
sizeSize (in bytes) of the memory area array

Definition at line 257 of file bitarray.h.

bool bitarray_isFull ( BitArray *  bitx) [inline]

Check if the bitarray is full.

Only bitarray_len bits are tested.

Parameters:
bitxBitArray to test
Returns:
True if bitx is full, false otherwise

Definition at line 151 of file bitarray.h.

bool bitarray_isRangeEmpty ( BitArray *  bitx,
int  idx,
int  offset 
) [inline]

Test if a range of bit is empty.

Parameters:
bitxBitArray context
idxStarting bit
offsetNumber of bits to test
Returns:
True if range is empty, false otherwise

Definition at line 200 of file bitarray.h.

bool bitarray_isRangeFull ( BitArray *  bitx,
int  idx,
int  offset 
) [inline]

Test if a range of bit is full.

Parameters:
bitxBitArray context
idxStarting bit
offsetNumber of bits to test
Returns:
True if range is full, false otherwise

Definition at line 178 of file bitarray.h.

void bitarray_set ( BitArray *  bitx,
int  idx 
) [inline]

Set one bit into the bit array.

Parameters:
bitxBitArray context
idxThe bit to set

Definition at line 68 of file bitarray.h.

void bitarray_setRange ( BitArray *  bitx,
int  idx,
int  offset 
) [inline]

Set a range of bits.

The range starts from idx (inclusive) and spans offset bits.

Parameters:
bitxBitArray context
idxStarting bit
offsetNumber of bit to set

Definition at line 102 of file bitarray.h.

bool bitarray_test ( BitArray *  bitx,
int  idx 
) [inline]

Test a bit.

Parameters:
bitxBitArray context
idxBit to test
Returns:
True if bit is set, false otherwise.

Definition at line 134 of file bitarray.h.