Skip to content

Commit

Permalink
Fix #504: AVR 32-bit shifts need casts on left operand
Browse files Browse the repository at this point in the history
  • Loading branch information
terrillmoore committed Dec 28, 2019
1 parent a4044c0 commit 4a267e5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
28 changes: 14 additions & 14 deletions src/lmic/lmic.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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) ) {
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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)));
Expand Down Expand Up @@ -1255,27 +1255,27 @@ 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 ) {
EV(specCond, INFO, (e_.reason = EV::specCond_t::DNSEQNO_OBSOLETE,
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 ) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/lmic/lmic.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/lmic/lmic_us_like.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/lmic/radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4a267e5

Please sign in to comment.