Skip to content

Commit

Permalink
Workaround for compiler bug
Browse files Browse the repository at this point in the history
  • Loading branch information
olicooper committed Oct 19, 2021
1 parent caceeb4 commit 8e834e7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/Arduino_LoRaWAN.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ class Arduino_LoRaWAN
;
}

static bool setFrequencyRaw(uint8_t *pFreq, unsigned iCh, uint32_t frequency);

/*
|| provisioning things:
*/
Expand Down Expand Up @@ -358,16 +360,12 @@ class Arduino_LoRaWAN
///
bool setFrequency(uint8_t (&freq)[nCh * 3], unsigned iCh, uint32_t frequency)
{
// check the template parameter while it's in scope.
if (iCh > nCh)
return false;
const uint32_t reducedFreq = frequency / 100;
if (reducedFreq > 0xFFFFFFu)
return false;

auto const chPtr = freq + iCh * 3;
chPtr[0] = uint8_t(reducedFreq >> 16);
chPtr[1] = uint8_t(reducedFreq >> 8);
chPtr[2] = uint8_t(reducedFreq);
// call an external function to make it harder for optimizer to do the wrong thing (for test)
return Arduino_LoRaWAN::setFrequencyRaw(freq, iCh, frequency);
}

/// \brief clear all entries in the channel table.
Expand Down
15 changes: 15 additions & 0 deletions src/lib/arduino_lorawan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,18 @@ Revision history:
Arduino_LoRaWAN::Arduino_LoRaWAN()
{
}

// this is the former body of setFrequency(), with &freq changed to pFreq
/* static */
bool Arduino_LoRaWAN::setFrequencyRaw(uint8_t *pFreq, unsigned iCh, uint32_t frequency)
{
const uint32_t reducedFreq = frequency / 100;
if (reducedFreq > 0xFFFFFFu)
return false;

auto const chPtr = pFreq + iCh * 3;
chPtr[0] = uint8_t(reducedFreq >> 16);
chPtr[1] = uint8_t(reducedFreq >> 8);
chPtr[2] = uint8_t(reducedFreq);
}

0 comments on commit 8e834e7

Please sign in to comment.