BlueSync - BLE Time Sync for Zephyr
High-precision time synchronization for BLE Mesh networks
Loading...
Searching...
No Matches
bluesync_bitfields.c File Reference
#include <zephyr/kernel.h>
#include "stdio.h"
#include "bluesync_bitfields.h"
Include dependency graph for bluesync_bitfields.c:

Go to the source code of this file.

Functions

void print_bitfield_as_binary (uint8_t *bitfield, size_t size)
 
void set_bit (uint8_t *bitfield, size_t bit_index)
 Set a specific bit in the bitfield.
 
bool is_bit_set (uint8_t *bitfield, size_t bit_index)
 Check if a specific bit is set in the bitfield.
 
void bitwise_and_bitfields (uint8_t *result, const bluesync_timestamps_t *rcv, const bluesync_timestamps_t *local, size_t num_bytes)
 Perform a bitwise AND between two bitfields and store the result.
 
static uint8_t count_bits_in_byte (uint8_t byte)
 
size_t count_set_bits (uint8_t *bitfield, size_t num_bytes)
 Count the number of bits set to 1 in a bitfield.
 

Function Documentation

◆ bitwise_and_bitfields()

void bitwise_and_bitfields ( uint8_t *  result,
const bluesync_timestamps_t rcv,
const bluesync_timestamps_t local,
size_t  num_bytes 
)

Perform a bitwise AND between two bitfields and store the result.

This is typically used to find common timestamps (slots) between received and local sets.

Parameters
resultOutput buffer where the result will be stored.
rcvPointer to the bitfield from received timestamps.
localPointer to the bitfield from local timestamps.
num_bytesNumber of bytes in each bitfield.

Definition at line 45 of file bluesync_bitfields.c.

◆ count_bits_in_byte()

static uint8_t count_bits_in_byte ( uint8_t  byte)
inlinestatic

Definition at line 52 of file bluesync_bitfields.c.

◆ count_set_bits()

size_t count_set_bits ( uint8_t *  bitfield,
size_t  num_bytes 
)

Count the number of bits set to 1 in a bitfield.

Useful for determining how many timeslots have been received.

Parameters
bitfieldPointer to the bitfield array.
num_bytesNumber of bytes in the bitfield.
Returns
Number of bits set to 1.

Definition at line 68 of file bluesync_bitfields.c.

◆ is_bit_set()

bool is_bit_set ( uint8_t *  bitfield,
size_t  bit_index 
)

Check if a specific bit is set in the bitfield.

Parameters
bitfieldPointer to the bitfield array.
bit_indexIndex of the bit to check.
Returns
true if the bit is set, false otherwise.

Definition at line 41 of file bluesync_bitfields.c.

◆ print_bitfield_as_binary()

void print_bitfield_as_binary ( uint8_t *  bitfield,
size_t  size 
)

Definition at line 29 of file bluesync_bitfields.c.

◆ set_bit()

void set_bit ( uint8_t *  bitfield,
size_t  bit_index 
)

Set a specific bit in the bitfield.

Parameters
bitfieldPointer to the bitfield array.
bit_indexIndex of the bit to set.

Definition at line 37 of file bluesync_bitfields.c.