formus14 / narcoleptic

Automatically exported from code.google.com/p/narcoleptic
1 stars 0 forks source link

change implementation of delay() #5

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Some processors do not have WTDO_4S and WDTO_8S implemented. See wdt.h

To support these devices the implementation of delay() should include some 
conditional code. Proposal:

void NarcolepticClass::delay(uint32_t milliseconds) 
{
#if defined WDP3
  while (milliseconds >= 8000) { sleep(WDTO_8S); milliseconds -= 8000; }
  if (milliseconds >= 4000)    { sleep(WDTO_4S); milliseconds -= 4000; }
  if (milliseconds >= 2000)    { sleep(WDTO_2S); milliseconds -= 2000; }
#else
  while (milliseconds >= 2000) { sleep(WDTO_2S); milliseconds -= 2000; }
#endif
  if (milliseconds >= 1000)    { sleep(WDTO_1S); milliseconds -= 1000; }
  if (milliseconds >= 500)     { sleep(WDTO_500MS); milliseconds -= 500; }
  if (milliseconds >= 250)     { sleep(WDTO_250MS); milliseconds -= 250; }
  if (milliseconds >= 125)     { sleep(WDTO_120MS); milliseconds -= 120; }
  if (milliseconds >= 64)      { sleep(WDTO_60MS); milliseconds -= 60; }
  if (milliseconds >= 32)      { sleep(WDTO_30MS); milliseconds -= 30; }
  if (milliseconds >= 16)      { sleep(WDTO_15MS); milliseconds -= 15; }
}

Original issue reported on code.google.com by rob.till...@gmail.com on 16 Sep 2013 at 11:28