Commit 0be02e69 authored by Reto Da Forno's avatar Reto Da Forno
Browse files

LWB: use node ID instead of DPP_DEVICE_ID_SINK when assigning slots to the host node

parent 262ab08e
......@@ -502,7 +502,7 @@ static void lwb_receive_packet(lwb_time_t slot_start, uint32_t slot_length, uint
#if LWB_USE_TX_DELAY
if (schedule.has_delay_mask) {
uint8_t* delay_mask = (uint8_t*)&schedule.slot[schedule.n_slots]; /* delay mask starts after the last slot in the schedule */
uint16_t id_ofs = (NODE_ID - LWB_MIN_NODE_ID);
uint16_t id_ofs = (LWB_NODE_ID - LWB_MIN_NODE_ID);
if (delay_mask[id_ofs / 8] & (1 << (id_ofs & 0x7))) {
gloria_set_tx_delay(1);
}
......@@ -562,7 +562,7 @@ static void lwb_contention(lwb_time_t slot_start)
if (!is_host &&
ipi_changed &&
rand_backoff == 0) {
packet.cont.node_id = NODE_ID;
packet.cont.node_id = LWB_NODE_ID;
packet.cont.ipi = ipi;
LWB_SET_PKT_HEADER(&packet);
LOG_INFO("transmitting node ID");
......@@ -583,7 +583,7 @@ static void lwb_contention(lwb_time_t slot_start)
rand_backoff = (rand() % LWB_RAND_BACKOFF);
if (slot_cb) {
slot_cb(NODE_ID, LWB_PHASE_CONT, &packet);
slot_cb(LWB_NODE_ID, LWB_PHASE_CONT, &packet);
}
} else {
......@@ -652,7 +652,7 @@ static void lwb_send_rcv_sched2(lwb_time_t slot_start)
LWB_IS_PKT_HEADER_VALID(&packet) &&
(gloria_get_payload_len() == packet_len)) { /* packet received? */
schedule.period = packet.sched2.period; /* extract updated period */
if (packet.sched2.cont_winner == NODE_ID) {
if (packet.sched2.cont_winner == LWB_NODE_ID) {
ipi_changed = false;
LOG_VERBOSE("IPI change confirmed");
}
......@@ -814,7 +814,7 @@ static void lwb_run(void)
uint32_t slot_idx;
for (slot_idx = 0; slot_idx < schedule.n_slots; slot_idx++) {
/* note: slots with node ID 0 belong to the host */
bool is_initiator = (schedule.slot[slot_idx] == NODE_ID) || (is_host && schedule.slot[slot_idx] == DPP_DEVICE_ID_SINK);
bool is_initiator = (schedule.slot[slot_idx] == LWB_NODE_ID) || (is_host && schedule.slot[slot_idx] == DPP_DEVICE_ID_SINK);
if (is_initiator) {
lwb_send_packet(slot_ofs, t_data, slot_idx); /* initiator -> send packet */
} else {
......
......@@ -48,6 +48,10 @@
#define LWB_NETWORK_ID 0x2222 /* custom 15-bit network ID */
#endif /* LWB_NETWORK_ID */
#ifndef LWB_NODE_ID
#define LWB_NODE_ID NODE_ID
#endif /* LWB_NODE_ID */
/* the smallest node ID in the network (the host will ignore requests from nodes with smaller IDs) */
#ifndef LWB_MIN_NODE_ID
#define LWB_MIN_NODE_ID 1
......
......@@ -84,7 +84,7 @@ bool lwb_sched_add_node(uint16_t node_id, uint16_t ipi)
}
if (node_id == DPP_DEVICE_ID_SINK ||
node_id == DPP_DEVICE_ID_BROADCAST ||
node_id == NODE_ID ||
node_id == LWB_NODE_ID ||
node_id < LWB_MIN_NODE_ID ||
node_id > LWB_MAX_NODE_ID) {
LOG_WARNING("invalid node ID %u", node_id);
......@@ -211,7 +211,7 @@ uint32_t lwb_sched_compute(lwb_schedule_t* const sched,
/* assign slots to the host */
while (reserve_slots_host && sched->n_slots < LWB_MAX_SLOTS_HOST) {
sched->slot[sched->n_slots++] = DPP_DEVICE_ID_SINK; /* use ID 0 for the HOST */
sched->slot[sched->n_slots++] = LWB_NODE_ID;
reserve_slots_host--;
}
......@@ -232,7 +232,7 @@ uint32_t lwb_sched_compute(lwb_schedule_t* const sched,
/* complete the schedule */
sched->period = curr_period;
sched->time = lwb_time + lwb_time_ofs;
sched->host_id = NODE_ID;
sched->host_id = LWB_NODE_ID;
sched->header.net_id = LWB_NETWORK_ID; /* set the network ID */
sched->header.type = 1; /* packet type 'schedule' */
......@@ -349,14 +349,14 @@ void lwb_sched_set_time_offset(uint32_t ofs)
void lwb_sched_set_delay_nodes(const uint16_t* delay_node_list, uint8_t num_nodes)
{
/* clear delay node mask */
memset(delay_mask, 0, LSR_TX_DELAY_MASK_SIZE);
memset(delay_mask, 0, LWB_TX_DELAY_MASK_SIZE);
delay_mask_set = false;
if (delay_node_list && num_nodes) {
uint32_t i;
for (i = 0; i < num_nodes; i++) {
if (delay_node_list[i] >= LSR_MIN_NODE_ID && delay_node_list[i] <= LSR_MAX_NODE_ID) {
uint16_t ofs = delay_node_list[i] - LSR_MIN_NODE_ID;
if (delay_node_list[i] >= LWB_MIN_NODE_ID && delay_node_list[i] <= LWB_MAX_NODE_ID) {
uint16_t ofs = delay_node_list[i] - LWB_MIN_NODE_ID;
delay_mask[ofs / 8] |= 1 << (ofs & 0x7);
delay_mask_set = true;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment