From 4a267e598409ed31a947503f1ec8b3f55c90f31c Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Sat, 28 Dec 2019 17:49:25 -0500 Subject: [PATCH] Fix #504: AVR 32-bit shifts need casts on left operand --- src/lmic/lmic.c | 28 ++++++++++++++-------------- src/lmic/lmic.h | 8 ++++---- src/lmic/lmic_us_like.c | 2 +- src/lmic/radio.c | 2 +- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/lmic/lmic.c b/src/lmic/lmic.c index 78e8397b..3fcb4e84 100644 --- a/src/lmic/lmic.c +++ b/src/lmic/lmic.c @@ -757,7 +757,7 @@ applyAdrRequests( u1_t chpage = p4 & MCMD_LinkADRReq_Redundancy_ChMaskCntl_MASK; // channel page map_ok = LMICbandplan_mapChannels(chpage, chmap); - LMICOS_logEventUint32("applyAdrRequests: mapChannels", (chpage << 16)|(chmap << 0)); + LMICOS_logEventUint32("applyAdrRequests: mapChannels", ((u4_t)chpage << 16)|(chmap << 0)); } } @@ -799,7 +799,7 @@ applyAdrRequests( changes = 1; } - LMICOS_logEventUint32("applyAdrRequests: setDrTxPow", (adrAns << 16)|(dr << 8)|(p1 << 0)); + LMICOS_logEventUint32("applyAdrRequests: setDrTxPow", ((u4_t)adrAns << 16)|(dr << 8)|(p1 << 0)); // handle power changes here, too. changes |= setDrTxpow(DRCHG_NWKCMD, dr, pow2dBm(p1)); @@ -846,7 +846,7 @@ scan_mac_cmds_link_adr( if( !LMICbandplan_canMapChannels(chpage, chmap) ) { adrAns &= ~MCMD_LinkADRAns_ChannelACK; - LMICOS_logEventUint32("scan_mac_cmds_link_adr: failed canMapChannels", (chpage << UINT32_C(16))|(chmap << UINT32_C(0))); + LMICOS_logEventUint32("scan_mac_cmds_link_adr: failed canMapChannels", ((u4_t)chpage << 16)|((u4_t)chmap << 0)); } if( !validDR(dr) ) { @@ -1003,7 +1003,7 @@ scan_mac_cmds( if( ans == (MCMD_NewChannelAns_DataRateACK|MCMD_NewChannelAns_ChannelACK)) { if ( ! LMIC_setupChannel(chidx, freq, DR_RANGE_MAP(MinDR, MaxDR), -1) ) { - LMICOS_logEventUint32("NewChannelReq: setupChannel failed", (MaxDR << 24u) | (MinDR << 16u) | (raw_f_not_zero << 8) | (chidx << 0)); + LMICOS_logEventUint32("NewChannelReq: setupChannel failed", ((u4_t)MaxDR << 24u) | ((u4_t)MinDR << 16u) | (raw_f_not_zero << 8) | (chidx << 0)); ans &= ~MCMD_NewChannelAns_ChannelACK; } } @@ -1214,7 +1214,7 @@ static bit_t decodeFrame (void) { goto norx; } if( poff > pend ) { - LMICOS_logEventUint32("decodeFrame: corrupted frame", (dlen << 16) | (fct << 8) | (poff - pend)); + LMICOS_logEventUint32("decodeFrame: corrupted frame", ((u4_t)dlen << 16) | (fct << 8) | (poff - pend)); EV(specCond, ERR, (e_.reason = EV::specCond_t::CORRUPTED_FRAME, e_.eui = MAIN::CDEV->getEui(), e_.info = 0x1000000 + (poff-pend) + (fct<<8) + (dlen<<16))); @@ -1255,7 +1255,7 @@ static bit_t decodeFrame (void) { e_.eui = MAIN::CDEV->getEui(), e_.info = LMIC.seqnoDn, e_.info2 = seqno)); - LMICOS_logEventUint32("decodeFrame: rollover discarded", (seqno << 16) | (LMIC.lastDnConf << 8) | (ftype << 0)); + LMICOS_logEventUint32("decodeFrame: rollover discarded", ((u4_t)seqno << 16) | (LMIC.lastDnConf << 8) | (ftype << 0)); goto norx; } if( seqno != LMIC.seqnoDn-1 || !LMIC.lastDnConf || ftype != HDR_FTYPE_DCDN ) { @@ -1263,19 +1263,19 @@ static bit_t decodeFrame (void) { e_.eui = MAIN::CDEV->getEui(), e_.info = LMIC.seqnoDn, e_.info2 = seqno)); - LMICOS_logEventUint32("decodeFrame: Retransmit confimed discarded", (seqno << 16) | (LMIC.lastDnConf << 8) | (ftype << 0)); + LMICOS_logEventUint32("decodeFrame: Retransmit confimed discarded", ((u4_t)seqno << 16) | (LMIC.lastDnConf << 8) | (ftype << 0)); goto norx; } // Replay of previous sequence number allowed only if // previous frame and repeated both requested confirmation // but set a flag, so we don't actually process the message. - LMICOS_logEventUint32("decodeFrame: Retransmit confimed accepted", (seqno << 16) | (LMIC.lastDnConf << 8) | (ftype << 0)); + LMICOS_logEventUint32("decodeFrame: Retransmit confimed accepted", ((u4_t)seqno << 16) | (LMIC.lastDnConf << 8) | (ftype << 0)); replayConf = 1; LMIC.dnConf = FCT_ACK; } else { if( seqnoDiff > LMICbandplan_MAX_FCNT_GAP) { - LMICOS_logEventUint32("decodeFrame: gap too big", (seqnoDiff << 16) | (seqno & 0xFFFFu)); + LMICOS_logEventUint32("decodeFrame: gap too big", ((u4_t)seqnoDiff << 16) | (seqno & 0xFFFFu)); goto norx; } if( seqno > LMIC.seqnoDn ) { @@ -1289,7 +1289,7 @@ static bit_t decodeFrame (void) { // DN frame requested confirmation - provide ACK once with next UP frame LMIC.dnConf = LMIC.lastDnConf = (ftype == HDR_FTYPE_DCDN ? FCT_ACK : 0); if (LMIC.dnConf) - LMICOS_logEventUint32("decodeFrame: Confirmed downlink", (seqno << 16) | (LMIC.lastDnConf << 8) | (ftype << 0)); + LMICOS_logEventUint32("decodeFrame: Confirmed downlink", ((u4_t)seqno << 16) | (LMIC.lastDnConf << 8) | (ftype << 0)); } if (port == 0 && olen != 0 && pend > poff) { @@ -1374,7 +1374,7 @@ static bit_t decodeFrame (void) { e_.info = Base::lsbf4(&d[pend]), e_.info2 = seqno)); // discard the data - LMICOS_logEventUint32("decodeFrame: discarding replay", (seqno << 16) | (LMIC.lastDnConf << 8) | (ftype << 0)); + LMICOS_logEventUint32("decodeFrame: discarding replay", ((u4_t)seqno << 16) | (LMIC.lastDnConf << 8) | (ftype << 0)); goto norx; } @@ -1911,7 +1911,7 @@ static bit_t buildDataFrame (void) { u1_t maxFlen = LMICbandplan_maxFrameLen(LMIC.datarate); if (flen > maxFlen) { - LMICOS_logEventUint32("frame too long for this bandplan", (dlen << 16) | (flen << 8) | maxFlen); + LMICOS_logEventUint32("frame too long for this bandplan", ((u4_t)dlen << 16) | (flen << 8) | maxFlen); return 0; } @@ -1925,7 +1925,7 @@ static bit_t buildDataFrame (void) { LMIC.seqnoUp += 1; DO_DEVDB(LMIC.seqnoUp,seqnoUp); } else { - LMICOS_logEventUint32("retransmit", (LMIC.frame[OFF_DAT_FCT] << 24u) | (LMIC.txCnt << 16u) | (LMIC.upRepeatCount << 8u) | (LMIC.upRepeat<<0u)); + LMICOS_logEventUint32("retransmit", ((u4_t)LMIC.frame[OFF_DAT_FCT] << 24u) | ((u4_t)LMIC.txCnt << 16u) | (LMIC.upRepeatCount << 8u) | (LMIC.upRepeat<<0u)); EV(devCond, INFO, (e_.reason = EV::devCond_t::RE_TX, e_.eui = MAIN::CDEV->getEui(), e_.info = LMIC.seqnoUp-1, @@ -2848,7 +2848,7 @@ void LMIC_setTxData (void) { } void LMIC_setTxData_strict (void) { - LMICOS_logEventUint32(__func__, (LMIC.pendTxPort << 24u) | (LMIC.pendTxConf << 16u) | (LMIC.pendTxLen << 0u)); + LMICOS_logEventUint32(__func__, ((u4_t)LMIC.pendTxPort << 24u) | ((u4_t)LMIC.pendTxConf << 16u) | (LMIC.pendTxLen << 0u)); LMIC.opmode |= OP_TXDATA; if( (LMIC.opmode & OP_JOINING) == 0 ) { LMIC.txCnt = 0; // reset the confirmed uplink FSM diff --git a/src/lmic/lmic.h b/src/lmic/lmic.h index aaa493e8..29b56751 100644 --- a/src/lmic/lmic.h +++ b/src/lmic/lmic.h @@ -103,18 +103,18 @@ extern "C"{ // Arduino LMIC version #define ARDUINO_LMIC_VERSION_CALC(major, minor, patch, local) \ - (((major) << 24ul) | ((minor) << 16ul) | ((patch) << 8ul) | ((local) << 0ul)) + ((((major)*UINT32_C(1)) << 24) | (((minor)*UINT32_C(1)) << 16) | (((patch)*UINT32_C(1)) << 8) | (((local)*UINT32_C(1)) << 0)) #define ARDUINO_LMIC_VERSION ARDUINO_LMIC_VERSION_CALC(3, 0, 99, 9) /* v3.0.99.9 */ #define ARDUINO_LMIC_VERSION_GET_MAJOR(v) \ - (((v) >> 24u) & 0xFFu) + ((((v)*UINT32_C(1)) >> 24u) & 0xFFu) #define ARDUINO_LMIC_VERSION_GET_MINOR(v) \ - (((v) >> 16u) & 0xFFu) + ((((v)*UINT32_C(1)) >> 16u) & 0xFFu) #define ARDUINO_LMIC_VERSION_GET_PATCH(v) \ - (((v) >> 8u) & 0xFFu) + ((((v)*UINT32_C(1)) >> 8u) & 0xFFu) #define ARDUINO_LMIC_VERSION_GET_LOCAL(v) \ ((v) & 0xFFu) diff --git a/src/lmic/lmic_us_like.c b/src/lmic/lmic_us_like.c index c6b075fe..d1383bdc 100644 --- a/src/lmic/lmic_us_like.c +++ b/src/lmic/lmic_us_like.c @@ -186,7 +186,7 @@ bit_t LMICuslike_mapChannels(u1_t chpage, u2_t chmap) { } } - LMICOS_logEventUint32("LMICuslike_mapChannels", (LMIC.activeChannels125khz << 16u)|(LMIC.activeChannels500khz << 0u)); + LMICOS_logEventUint32("LMICuslike_mapChannels", ((u4_t)LMIC.activeChannels125khz << 16u)|(LMIC.activeChannels500khz << 0u)); return (LMIC.activeChannels125khz > 0) || (LMIC.activeChannels500khz > 0); } diff --git a/src/lmic/radio.c b/src/lmic/radio.c index dbfc81f9..59cbc6a0 100644 --- a/src/lmic/radio.c +++ b/src/lmic/radio.c @@ -1329,7 +1329,7 @@ void radio_irq_handler_v2 (u1_t dio, ostime_t now) { u1_t flags1 = readReg(FSKRegIrqFlags1); u1_t flags2 = readReg(FSKRegIrqFlags2); - LMICOS_logEventUint32("*radio_irq_handler_v2: FSK", (flags2 << UINT32_C(8)) | flags1); + LMICOS_logEventUint32("*radio_irq_handler_v2: FSK", ((u2_t)flags2 << 8) | flags1); if( flags2 & IRQ_FSK2_PACKETSENT_MASK ) { // save exact tx time