From f9b7416df0dd0465d1ddcdeb5e148486e32f4563 Mon Sep 17 00:00:00 2001 From: Robert Fisk Date: Sun, 8 May 2016 22:37:54 +1200 Subject: [PATCH] Sleep instead of busy-wait, approx 50% power reduction! --- Downstream/Src/main.c | 11 +++++++++++ Upstream/Src/main.c | 3 ++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Downstream/Src/main.c b/Downstream/Src/main.c index f64aa9a..a13a160 100644 --- a/Downstream/Src/main.c +++ b/Downstream/Src/main.c @@ -52,6 +52,8 @@ void CheckFirmwareMatchesHardware(void); int main(void) { + uint32_t iterationCount = 0; + //First things first! DisableFlashWrites(); CheckFirmwareMatchesHardware(); @@ -74,6 +76,15 @@ int main(void) USB_Host_Process(); Downstream_SPIProcess(); Downstream_PacketProcessor_CheckNotifyDisconnectReply(); + + //Some USB host state transitions take 3 iterations to fully apply. + //We'll be generous and give it 5 before sleeping. + iterationCount++; + if (iterationCount > 4) + { + iterationCount = 0; + __WFI(); //sleep time! + } } } diff --git a/Upstream/Src/main.c b/Upstream/Src/main.c index d6886c2..b640d54 100755 --- a/Upstream/Src/main.c +++ b/Upstream/Src/main.c @@ -78,11 +78,12 @@ int main(void) while (1) { - + __WFI(); //sleep time! } } + void DisableFlashWrites(void) { //Disable flash writes until the next reset