From a1f700efc1a39d4ee7df4297909a8d0567a87857 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Sun, 19 Mar 2023 13:26:03 +0100 Subject: [PATCH] avr: add an initial wait time before starting the node. This allows for desyncing of nodes to reduce COM collisions. --- avr/main.asm | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/avr/main.asm b/avr/main.asm index aa254cc..b9e6a96 100644 --- a/avr/main.asm +++ b/avr/main.asm @@ -13,6 +13,10 @@ main: out SPL, r16 ; init LSB stack pointer rcall initModules + + rcall Utils_SetupUid + + rcall initialWait sei ; Enable interrupts rcall onSystemStart @@ -271,6 +275,41 @@ sendValueMsg_done: ret + +; --------------------------------------------------------------------------- +; initialWait +; +; Initial wait to desync nodes. +; +; This routine waits for between 10 to 2560 milliseconds (derived from UID) +; +; IN: +; - nothing +; OUT: +; - nothing +; USED: r16, r17, r18, r19, r20, r21, r22, X + +initialWait: + ; setup initial wait loop + rcall Utils_ReadUid ; (R16, X) + clr r16 + eor r16, r18 + eor r16, r19 + eor r16, r20 + eor r16, r21 + +initialWait_l1: ; wait R16 x 10 milliseconds + ldi r17, 200 +initialWait_l2: ; wait for 10ms + Utils_WaitNanoSecs 50000, 0, r22 ; wait for 50 microseconds + dec r17 + brne initialWait_l2 + dec r16 + brne initialWait_l1 + ret + + + textStatsPacketsIn: .db "In : ", 0 textStatsPacketsRecvErr: .db "RecvErr: ", 0 textStatsPacketsOut: .db "Out : ", 0