Skip to content

Commit

Permalink
Use tickless idle to save power.
Browse files Browse the repository at this point in the history
  • Loading branch information
AriZuu committed Apr 22, 2016
1 parent 0ed76a4 commit ab97fef
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 6 deletions.
1 change: 1 addition & 0 deletions config/lwipopts.h
Expand Up @@ -90,6 +90,7 @@ int sys_random(void);
#define WDCFG_FIRMWARE "43362A2.bin"
#define WDCFG_FIRMWARE_PATH "/firmware", "/flash"

//#define TIMERS_DEBUG LWIP_DBG_ON
//#define TCPIP_DEBUG LWIP_DBG_ON
//#define NETIF_DEBUG LWIP_DBG_ON
//#define SOCKETS_DEBUG LWIP_DBG_OFF
Expand Down
1 change: 1 addition & 0 deletions config/pos_cmsis.h
Expand Up @@ -33,6 +33,7 @@
void USART2_IRQHandler(void);
void SDIO_irq(void);
void DMA2_Stream3_irq(void);
void RTC_WKUP_IRQHandler(void);

/*
* These are interrupt handlers inside Wiced usart code.
Expand Down
7 changes: 6 additions & 1 deletion config/poscfg.h
Expand Up @@ -536,13 +536,18 @@

#define PORTCFG_IRQ_STACK_SIZE 2048
#define PORTCFG_VECTORS 1
#define PORTCFG_TICK_SYSTICK 1
#define PORTCFG_CONOUT_ITM 0
#define PORTCFG_API_MAX_PRI 2 // same as used by Wiced
/*
* WIfiMCU has console at usart 2.
*/
#define PORTCFG_CON_USART 2

#define PORTCFG_TICK_SYSTICK 0
#define PORTCFG_TICK_RTC 1
#define PORTCFG_POWER_TICKLESS_MIN MS(20)
#define POSCFG_FEATURE_POWER 1
#define POSCFG_FEATURE_POWER_WAKEUP 1
#define POSCFG_FEATURE_TICKLESS 1

#endif /* _POSCFG_H */
2 changes: 2 additions & 0 deletions config/stm32f4xx_conf.h
Expand Up @@ -42,6 +42,8 @@
#include "stm32f4xx_spi.h"
#include "stm32f4xx_wwdg.h"
#include "stm32f4xx_rtc.h"
#include "stm32f4xx_exti.h"
#include "stm32f4xx_pwr.h"
#include "stm32f4xx_flash.h"
#include "misc.h"

Expand Down
21 changes: 21 additions & 0 deletions main.c
Expand Up @@ -40,6 +40,7 @@
#include "lwip/mem.h"
#include "lwip/memp.h"
#include "lwip/sys.h"
#include "lwip/netifapi.h"

#include "lwip/stats.h"
#include "lwip/inet.h"
Expand Down Expand Up @@ -154,7 +155,16 @@ static void mainTask(void* arg)

eshStartTelnetd();
guiStart();

/*
* Enable sleep. It is initially enabled in pico]OS, but Wiced
* disables it during initialization.
*/
posPowerEnableSleep();

#if NOSCFG_FEATURE_CONIN
eshConsole();
#endif
}


Expand Down Expand Up @@ -185,6 +195,17 @@ int main(int argc, char **argv)

#endif

#if !NOSCFG_FEATURE_CONIN

/*
* STM32 cannot sleep deep if USART input is needed (because it needs clock).
*/
PWR->CR |= PWR_CR_LPDS;
PWR->CR &= (unsigned long) ( ~( PWR_CR_PDDS ) );

SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
#endif

nosInit(mainTask, NULL, 1, 5000, 512);
return 0;
}
3 changes: 0 additions & 3 deletions sta.c
Expand Up @@ -109,11 +109,8 @@ void ifStatusCallback(struct netif *netif)
/*
* Powersave experiments. Without these, about 73 mA is used.
* With wifi powersave, 15-20 mA is used.
* Platform powersave cannot be used (yet), as it will stop
* systick.
*/
//wwd_wifi_enable_powersave();
//platform_mcu_powersave_enable();

potatoStart();
}
Expand Down
5 changes: 3 additions & 2 deletions startup.c
Expand Up @@ -47,10 +47,11 @@ void Default_Handler()

extern unsigned int __stack[];

PORT_WEAK_HANDLER(SysTick_Handler);
PORT_WEAK_HANDLER(WWDG_irq);
PORT_WEAK_HANDLER(PVD_irq);
PORT_WEAK_HANDLER(TAMP_STAMP_irq);
PORT_WEAK_HANDLER(RTC_WKUP_irq);
PORT_WEAK_HANDLER(RTC_WKUP_IRQHandler);
PORT_WEAK_HANDLER(FLASH_irq);
PORT_WEAK_HANDLER(RCC_irq);
PORT_WEAK_HANDLER(EXTI0_irq);
Expand Down Expand Up @@ -151,7 +152,7 @@ PortExcHandlerFunc vectorTable[] __attribute__ ((section(".vectors"))) =
WWDG_irq, // Window WatchDog
PVD_irq, // PVD through EXTI Line detection
TAMP_STAMP_irq, // Tamper and TimeStamps through the EXTI line
RTC_WKUP_irq, // RTC Wakeup through the EXTI line
RTC_WKUP_IRQHandler, // RTC Wakeup through the EXTI line
FLASH_irq, // FLASH
RCC_irq, // RCC
EXTI0_irq, // EXTI Line0
Expand Down

0 comments on commit ab97fef

Please sign in to comment.