|
BlueSync - BLE Time Sync for Zephyr
High-precision time synchronization for BLE Mesh networks
|
#include <zephyr/kernel.h>#include <zephyr/bluetooth/bluetooth.h>#include <zephyr/bluetooth/hci.h>#include <zephyr/bluetooth/mesh.h>#include <zephyr/sys/byteorder.h>#include <zephyr/sys/util.h>#include <math.h>#include <bluesync/bluesync.h>#include "bluesync.h"#include "bs_state_machine.h"#include "bluesync_bitfields.h"#include "local_time.h"#include <zephyr/logging/log.h>
Go to the source code of this file.
Macros | |
| #define | BT_UNIT_MS_TO_TICKS(_ms) ((_ms) * 8 / 5) |
| #define | BLUESYNC_BT_MIN_ADV_INT BT_UNIT_MS_TO_TICKS(30) |
| #define | BLUESYNC_BT_MAX_ADV_INT BT_UNIT_MS_TO_TICKS(60) |
| #define | BLUESYNC_BT_SCAN_INT BT_UNIT_MS_TO_TICKS(60) |
| #define | BLUESYNC_BT_SCAN_WIND_SIZE BT_UNIT_MS_TO_TICKS(60) |
Functions | |
| LOG_MODULE_REGISTER (bluesync, CONFIG_BLUESYNC_LOG_LEVEL) | |
| K_THREAD_STACK_DEFINE (bluesync_thread_stack, CONFIG_BLUESYNC_THREAD_STACK_SIZE) | |
| K_MSGQ_DEFINE (bluesync_rx_msgq, sizeof(struct bluesync_msg_client), 17, 1) | |
| K_SEM_DEFINE (bluesync_end_sync_sem, 0, 1) | |
| K_SEM_DEFINE (bluesync_start_new_sync_sem, 0, 1) | |
| K_SEM_DEFINE (bluesync_role_assign_sem, 0, 1) | |
| static void | reset_bluesync_timestamps (bluesync_timestamps_t *elem) |
| static void | add_bluesync_timestamps (bluesync_timestamps_t *elem, uint8_t pos, int64_t ticks) |
| static void | bluesync_reset_param () |
| static bluesync_status_t | calculate_lr_from_history (double *slope, double *offset, size_t min_nb_timestamp) |
| static void | bluesync_decode_msg (struct bluesync_msg_client *msg, struct net_buf_simple *buf) |
| static void | bluesync_store_current_burst () |
| static bluesync_status_t | end_sync_timeslot_process () |
| void | drift_estimation_handler (struct k_timer *timer_id) |
| static void | bluesync_scan_packet_process () |
| static bluesync_status_t | bluesync_encode_msg (struct bt_data *bt_pkt, uint8_t current_round_id, uint8_t current_timeslot_idx, int64_t time_ticks) |
| static void | bluesync_send_adv () |
| void | scan_cb (const bt_addr_le_t *addr, int8_t rssi, struct net_buf_simple *buf) |
| static void | bt_scan_cb (const bt_addr_le_t *addr, int8_t rssi, uint8_t adv_type, struct net_buf_simple *buf) |
| static void | bluesync_scan_start () |
| static void | bluesync_scan_stop () |
| static void | bluesync_adv_process () |
| void | adv_sent_cb (struct bt_le_ext_adv *adv, struct bt_le_ext_adv_sent_info *info) |
| static void | bluesync_init_adv () |
| void | bs_scan_wait_for_sync_handler (void) |
| void | bs_sync_handler () |
| void | bs_update_handler (void) |
| void | bs_adv_handler (void) |
| void | bs_stop_handler (void) |
| void | bluesync_thread_fnt (void *arg1, void *arg2, void *arg3) |
| void | bluesync_init () |
| Initializes the BlueSync time synchronization module. | |
| void | bluesync_set_role (bluesync_role_t role) |
| Sets the operational role of the BlueSync node. | |
| void | bluesync_start_net_sync () |
| Starts a BlueSync synchronization round as the time authority. | |
| void | bluesync_start_net_sync_with_unix_epoch_us (uint64_t unix_epoch_us) |
| Starts a synchronization round using a known UNIX epoch time. | |
Variables | |
| static struct bluesync_param | param |
| static uint8_t | bt_packet_buf [sizeof(uint16_t)+sizeof(struct bluesync_msg)] = {0} |
| static struct bt_le_ext_adv_cb | bt_callbacks |
| struct bs_sm_handlers | handlers |
| #define BLUESYNC_BT_MAX_ADV_INT BT_UNIT_MS_TO_TICKS(60) |
Definition at line 54 of file bluesync.c.
| #define BLUESYNC_BT_MIN_ADV_INT BT_UNIT_MS_TO_TICKS(30) |
Definition at line 53 of file bluesync.c.
| #define BLUESYNC_BT_SCAN_INT BT_UNIT_MS_TO_TICKS(60) |
Definition at line 55 of file bluesync.c.
| #define BLUESYNC_BT_SCAN_WIND_SIZE BT_UNIT_MS_TO_TICKS(60) |
Definition at line 56 of file bluesync.c.
| #define BT_UNIT_MS_TO_TICKS | ( | _ms | ) | ((_ms) * 8 / 5) |
Definition at line 52 of file bluesync.c.
|
static |
Definition at line 124 of file bluesync.c.
| void adv_sent_cb | ( | struct bt_le_ext_adv * | adv, |
| struct bt_le_ext_adv_sent_info * | info | ||
| ) |
Definition at line 518 of file bluesync.c.
|
static |
Definition at line 511 of file bluesync.c.
|
static |
Definition at line 223 of file bluesync.c.
|
static |
Definition at line 362 of file bluesync.c.
|
static |
Definition at line 540 of file bluesync.c.
|
static |
Definition at line 139 of file bluesync.c.
|
static |
Definition at line 293 of file bluesync.c.
|
static |
Definition at line 481 of file bluesync.c.
|
static |
Definition at line 494 of file bluesync.c.
|
static |
Definition at line 394 of file bluesync.c.
|
static |
Definition at line 233 of file bluesync.c.
| void bluesync_thread_fnt | ( | void * | arg1, |
| void * | arg2, | ||
| void * | arg3 | ||
| ) |
Definition at line 597 of file bluesync.c.
| void bs_adv_handler | ( | void | ) |
Definition at line 574 of file bluesync.c.
| void bs_scan_wait_for_sync_handler | ( | void | ) |
Definition at line 550 of file bluesync.c.
| void bs_stop_handler | ( | void | ) |
Definition at line 582 of file bluesync.c.
| void bs_sync_handler | ( | ) |
Definition at line 557 of file bluesync.c.
| void bs_update_handler | ( | void | ) |
Definition at line 561 of file bluesync.c.
|
static |
Definition at line 473 of file bluesync.c.
|
static |
Definition at line 154 of file bluesync.c.
| void drift_estimation_handler | ( | struct k_timer * | timer_id | ) |
Definition at line 289 of file bluesync.c.
|
static |
Definition at line 259 of file bluesync.c.
| K_MSGQ_DEFINE | ( | bluesync_rx_msgq | , |
| sizeof(struct bluesync_msg_client) | , | ||
| 17 | , | ||
| 1 | |||
| ) |
| K_SEM_DEFINE | ( | bluesync_end_sync_sem | , |
| 0 | , | ||
| 1 | |||
| ) |
| K_SEM_DEFINE | ( | bluesync_role_assign_sem | , |
| 0 | , | ||
| 1 | |||
| ) |
| K_SEM_DEFINE | ( | bluesync_start_new_sync_sem | , |
| 0 | , | ||
| 1 | |||
| ) |
| K_THREAD_STACK_DEFINE | ( | bluesync_thread_stack | , |
| CONFIG_BLUESYNC_THREAD_STACK_SIZE | |||
| ) |
| LOG_MODULE_REGISTER | ( | bluesync | , |
| CONFIG_BLUESYNC_LOG_LEVEL | |||
| ) |
|
static |
Definition at line 119 of file bluesync.c.
| void scan_cb | ( | const bt_addr_le_t * | addr, |
| int8_t | rssi, | ||
| struct net_buf_simple * | buf | ||
| ) |
Definition at line 428 of file bluesync.c.
|
static |
Definition at line 536 of file bluesync.c.
|
static |
Definition at line 360 of file bluesync.c.
| struct bs_sm_handlers handlers |
Definition at line 586 of file bluesync.c.
|
static |
Definition at line 60 of file bluesync.c.