gfornax / LowPowerCANode

A simple, low power CAN node for use in cars. Uses Arduino, MCP2515 and TJA1051
GNU General Public License v3.0
2 stars 0 forks source link

minor issue: redundant sei() and cli() calls #1

Open gregsell opened 5 months ago

gregsell commented 5 months ago

Hi, nice project, thanks for sharing! I believe the cli() and sei() calls are not necessary, as they are implemented in the LowPower library by rocketscream. Not really a problem, I was just a bit confused and wanted to mention it for future reference.

  do{
    cli();
    if(digitalRead(CAN0_INT)) // last check for messages before going to sleep
      LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
    sei();
    analogRead(BAT_AIN); // dummy readout after powering ADC
  } while (analogRead(BAT_AIN) <= LOWVOLT_THRESH || digitalRead(CAN0_INT));

Refer to the following code from LowPower.cpp, which gets indirectly executed if LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF) is called:

#define lowPowerBodOff(mode)
do {                        
      set_sleep_mode(mode); 
      cli();                
      sleep_enable();       
      sleep_bod_disable(); 
      sei();                
      sleep_cpu();          
      sleep_disable();      
      sei();                
} while (0);
#endif
gfornax commented 5 months ago

You're right, thanks. Fixed.