; generated by Component: ARM Compiler 5.05 update 2 (build 169) Tool: ArmCC [4d0f38]
; commandline ArmCC [--c99 --list --split_sections --debug -c --asm --interleave -o..\..\..\..\build\demo\mico-fire_f429\obj_rvmdk\platform_mcu_powersave.o --asm_dir=..\..\..\..\Build\demo\MICO-Fire_F429\list_RVMDK\ --list_dir=..\..\..\..\Build\demo\MICO-Fire_F429\list_RVMDK\ --depend=..\..\..\..\build\demo\mico-fire_f429\obj_rvmdk\platform_mcu_powersave.d --cpu=Cortex-M4.fp --apcs=interwork -O0 --diag_suppress=9931,1,1293 -I..\..\..\..\Board\fire_F429 -I..\..\..\..\Demos\fire\ov2640 -I..\..\..\..\include -I..\..\..\..\libraries\utilities -I..\..\..\..\libraries\utilities\json_c -I..\..\..\..\MICO\core -I..\..\..\..\MICO\security -I..\..\..\..\MICO\system -I..\..\..\..\MICO\system\command_console -I..\..\..\..\Platform\include -I..\..\..\..\Platform\Cortex-M4 -I..\..\..\..\Platform\Cortex-M4\CMSIS -I..\..\..\..\Platform\MCU\STM32F4xx\peripherals -I..\..\..\..\Platform\MCU\STM32F4xx\peripherals\Libraries\STM32F4xx_StdPeriph_Driver\inc -I..\..\..\..\Platform\MCU\STM32F4xx\peripherals\Libraries -I..\..\..\..\Platform\MCU\STM32F4xx\wlan_bus_driver -I..\..\..\..\Platform\Drivers\spi_flash -I..\..\..\..\Platform\Drivers -I..\..\..\..\libraries\daemons\homekit_server -I..\..\..\..\libraries\daemons\http_server -I..\..\..\..\Platform\Drivers\malloc -I..\..\..\..\Platform\Drivers\SDRAM -I..\..\..\..\Platform\Drivers\ov5640 -IG:\GIT_OSC\STM32_develop\F429-V2\develop\6-WIFI\STM32-WiFi\3.wifi_ov5640\Projects\STM32F429\demo\RVMDK\RTE -IC:\Keil_v5\ARM\PACK\Keil\STM32F4xx_DFP\2.5.0\Drivers\CMSIS\Device\ST\STM32F4xx\Include -IC:\Keil_v5\ARM\CMSIS\Include -IC:\Keil_v5\ARM\PACK\Keil\STM32F4xx_DFP\2.5.0 -D__UVISION_VERSION=515 -DSTM32F429xx -DUSE_STDPERIPH_DRIVER -DDEBUG -DHSE_VALUE=25000000 -DOV5640 --omf_browse=..\..\..\..\build\demo\mico-fire_f429\obj_rvmdk\platform_mcu_powersave.crf ..\..\..\..\Platform\MCU\STM32F4xx\peripherals\platform_mcu_powersave.c]
                          THUMB

                          AREA ||i.RTC_WKUP_irq||, CODE, READONLY, ALIGN=1

                  RTC_WKUP_irq PROC
                  ||__tagsym$$used||
;;;466    //#ifndef MICO_DISABLE_MCU_POWERSAVE
;;;467    MICO_RTOS_DEFINE_ISR( RTC_WKUP_irq )
000000  b510              PUSH     {r4,lr}
;;;468    {
;;;469        EXTI_ClearITPendingBit( RTC_INTERRUPT_EXTI_LINE );
000002  f44f0080          MOV      r0,#0x400000
000006  f7fffffe          BL       EXTI_ClearITPendingBit
;;;470    }
00000a  bd10              POP      {r4,pc}
;;;471    //#endif
                          ENDP


                          AREA ||i.platform_idle_hook||, CODE, READONLY, ALIGN=1

                  platform_idle_hook PROC
;;;307    
;;;308    void platform_idle_hook( void )
000000  bf30              WFI      
;;;309    {
;;;310        __asm("wfi");
;;;311    }
000002  4770              BX       lr
;;;312    
                          ENDP


                          AREA ||i.platform_mcu_enter_standby||, CODE, READONLY, ALIGN=2

                          REQUIRE _printf_pre_padding
                          REQUIRE _printf_percent
                          REQUIRE _printf_widthprec
                          REQUIRE _printf_d
                          REQUIRE _printf_s
                          REQUIRE _printf_int_dec
                          REQUIRE _printf_str
                  platform_mcu_enter_standby PROC
;;;417    
;;;418    void platform_mcu_enter_standby(uint32_t secondsToWakeup)
000000  b5f0              PUSH     {r4-r7,lr}
;;;419    { 
000002  b089              SUB      sp,sp,#0x24
000004  4604              MOV      r4,r0
;;;420      platform_rtc_time_t time;
;;;421      uint32_t currentSecond;
;;;422      RTC_AlarmTypeDef  RTC_AlarmStructure;
;;;423    
;;;424      PWR_WakeUpPinCmd(ENABLE);
000006  2001              MOVS     r0,#1
000008  f7fffffe          BL       PWR_WakeUpPinCmd
;;;425    
;;;426      if(secondsToWakeup == MICO_WAIT_FOREVER)
00000c  1c60              ADDS     r0,r4,#1
00000e  b908              CBNZ     r0,|L3.20|
;;;427        PWR_EnterSTANDBYMode();
000010  f7fffffe          BL       PWR_EnterSTANDBYMode
                  |L3.20|
;;;428    
;;;429      platform_log("Wake up in %d seconds", secondsToWakeup);
000014  bf00              NOP      
000016  483f              LDR      r0,|L3.276|
000018  6800              LDR      r0,[r0,#0]  ; mico_debug_enabled
00001a  b900              CBNZ     r0,|L3.30|
00001c  e020              B        |L3.96|
                  |L3.30|
00001e  483e              LDR      r0,|L3.280|
000020  f7fffffe          BL       mico_rtos_lock_mutex
000024  215c              MOVS     r1,#0x5c
000026  483d              LDR      r0,|L3.284|
000028  f7fffffe          BL       strrchr
00002c  b128              CBZ      r0,|L3.58|
00002e  215c              MOVS     r1,#0x5c
000030  483a              LDR      r0,|L3.284|
000032  f7fffffe          BL       strrchr
000036  1c40              ADDS     r0,r0,#1
000038  e000              B        |L3.60|
                  |L3.58|
00003a  4838              LDR      r0,|L3.284|
                  |L3.60|
00003c  4606              MOV      r6,r0
00003e  f7fffffe          BL       mico_get_time
000042  4607              MOV      r7,r0
000044  f24010ad          MOV      r0,#0x1ad
000048  4633              MOV      r3,r6
00004a  a235              ADR      r2,|L3.288|
00004c  4639              MOV      r1,r7
00004e  e9cd0400          STRD     r0,r4,[sp,#0]
000052  a036              ADR      r0,|L3.300|
000054  f7fffffe          BL       __2printf
000058  482f              LDR      r0,|L3.280|
00005a  f7fffffe          BL       mico_rtos_unlock_mutex
00005e  bf00              NOP      
                  |L3.96|
000060  bf00              NOP      
;;;430     
;;;431      platform_rtc_get_time(&time);
000062  a807              ADD      r0,sp,#0x1c
000064  f7fffffe          BL       platform_rtc_get_time
;;;432      currentSecond = time.hr*3600 + time.min*60 + time.sec;
000068  f89d001e          LDRB     r0,[sp,#0x1e]
00006c  f44f6161          MOV      r1,#0xe10
000070  fb10f001          SMULBB   r0,r0,r1
000074  f89d101d          LDRB     r1,[sp,#0x1d]
000078  ebc11101          RSB      r1,r1,r1,LSL #4
00007c  eb000081          ADD      r0,r0,r1,LSL #2
000080  f89d101c          LDRB     r1,[sp,#0x1c]
000084  1845              ADDS     r5,r0,r1
;;;433      currentSecond += secondsToWakeup;
000086  4425              ADD      r5,r5,r4
;;;434      RTC_AlarmStructure.RTC_AlarmTime.RTC_H12     = RTC_HourFormat_24;
000088  2000              MOVS     r0,#0
00008a  f88d000f          STRB     r0,[sp,#0xf]
;;;435      RTC_AlarmStructure.RTC_AlarmTime.RTC_Hours   = currentSecond/3600%24;
00008e  f44f6061          MOV      r0,#0xe10
000092  fbb5f0f0          UDIV     r0,r5,r0
000096  2118              MOVS     r1,#0x18
000098  fbb0f2f1          UDIV     r2,r0,r1
00009c  fb010012          MLS      r0,r1,r2,r0
0000a0  f88d000c          STRB     r0,[sp,#0xc]
;;;436      RTC_AlarmStructure.RTC_AlarmTime.RTC_Minutes = currentSecond/60%60;
0000a4  203c              MOVS     r0,#0x3c
0000a6  fbb5f0f0          UDIV     r0,r5,r0
0000aa  213c              MOVS     r1,#0x3c
0000ac  fbb0f2f1          UDIV     r2,r0,r1
0000b0  fb010012          MLS      r0,r1,r2,r0
0000b4  f88d000d          STRB     r0,[sp,#0xd]
;;;437      RTC_AlarmStructure.RTC_AlarmTime.RTC_Seconds = currentSecond%60;
0000b8  203c              MOVS     r0,#0x3c
0000ba  fbb5f1f0          UDIV     r1,r5,r0
0000be  fb005011          MLS      r0,r0,r1,r5
0000c2  f88d000e          STRB     r0,[sp,#0xe]
;;;438      RTC_AlarmStructure.RTC_AlarmDateWeekDay = 0x31;
0000c6  2031              MOVS     r0,#0x31
0000c8  f88d0018          STRB     r0,[sp,#0x18]
;;;439      RTC_AlarmStructure.RTC_AlarmDateWeekDaySel = RTC_AlarmDateWeekDaySel_Date;
0000cc  2000              MOVS     r0,#0
0000ce  9005              STR      r0,[sp,#0x14]
;;;440      RTC_AlarmStructure.RTC_AlarmMask = RTC_AlarmMask_DateWeekDay ;
0000d0  f04f4000          MOV      r0,#0x80000000
0000d4  9004              STR      r0,[sp,#0x10]
;;;441    
;;;442      RTC_AlarmCmd(RTC_Alarm_A, DISABLE);
0000d6  2100              MOVS     r1,#0
0000d8  0dc0              LSRS     r0,r0,#23
0000da  f7fffffe          BL       RTC_AlarmCmd
;;;443      /* Disable the Alarm A */
;;;444      RTC_ITConfig(RTC_IT_ALRA, DISABLE);
0000de  2100              MOVS     r1,#0
0000e0  f44f5080          MOV      r0,#0x1000
0000e4  f7fffffe          BL       RTC_ITConfig
;;;445    
;;;446      /* Clear RTC Alarm Flag */ 
;;;447      RTC_ClearFlag(RTC_FLAG_ALRAF);
0000e8  f44f7080          MOV      r0,#0x100
0000ec  f7fffffe          BL       RTC_ClearFlag
;;;448    
;;;449      RTC_SetAlarm(RTC_Format_BIN, RTC_Alarm_A, &RTC_AlarmStructure);
0000f0  aa03              ADD      r2,sp,#0xc
0000f2  f44f7180          MOV      r1,#0x100
0000f6  2000              MOVS     r0,#0
0000f8  f7fffffe          BL       RTC_SetAlarm
;;;450    
;;;451      /* Enable RTC Alarm A Interrupt: this Interrupt will wake-up the system from
;;;452         STANDBY mode (RTC Alarm IT not enabled in NVIC) */
;;;453      RTC_ITConfig(RTC_IT_ALRA, ENABLE);
0000fc  2101              MOVS     r1,#1
0000fe  0308              LSLS     r0,r1,#12
000100  f7fffffe          BL       RTC_ITConfig
;;;454    
;;;455      /* Enable the Alarm A */
;;;456      RTC_AlarmCmd(RTC_Alarm_A, ENABLE);
000104  2101              MOVS     r1,#1
000106  0208              LSLS     r0,r1,#8
000108  f7fffffe          BL       RTC_AlarmCmd
;;;457    
;;;458      PWR_EnterSTANDBYMode();
00010c  f7fffffe          BL       PWR_EnterSTANDBYMode
;;;459    }
000110  b009              ADD      sp,sp,#0x24
000112  bdf0              POP      {r4-r7,pc}
;;;460    
                          ENDP

                  |L3.276|
                          DCD      mico_debug_enabled
                  |L3.280|
                          DCD      stdio_tx_mutex
                  |L3.284|
                          DCD      ||.conststring||
                  |L3.288|
000120  506c6174          DCB      "Platform",0
000124  666f726d
000128  00      
000129  00                DCB      0
00012a  00                DCB      0
00012b  00                DCB      0
                  |L3.300|
00012c  5b25645d          DCB      "[%d][%s: %s:%4d] Wake up in %d seconds\r\n",0
000130  5b25733a
000134  2025733a
000138  2534645d
00013c  2057616b
000140  65207570
000144  20696e20
000148  25642073
00014c  65636f6e
000150  64730d0a
000154  00      
000155  00                DCB      0
000156  00                DCB      0
000157  00                DCB      0

                          AREA ||i.platform_mcu_powersave_disable||, CODE, READONLY, ALIGN=2

                  platform_mcu_powersave_disable PROC
;;;197    
;;;198    OSStatus platform_mcu_powersave_disable( void )
000000  b672              CPSID    i
;;;199    {
;;;200    #ifndef MICO_DISABLE_MCU_POWERSAVE
;;;201        DISABLE_INTERRUPTS;
;;;202        if ( stm32f2_clock_needed_counter <= 0 )
000002  480a              LDR      r0,|L4.44|
000004  6800              LDR      r0,[r0,#0]  ; stm32f2_clock_needed_counter
000006  2800              CMP      r0,#0
000008  dc08              BGT      |L4.28|
;;;203        {
;;;204            SCB->SCR &= (~((unsigned long)SCB_SCR_SLEEPDEEP_Msk));
00000a  4809              LDR      r0,|L4.48|
00000c  6800              LDR      r0,[r0,#0]
00000e  f0200004          BIC      r0,r0,#4
000012  4907              LDR      r1,|L4.48|
000014  6008              STR      r0,[r1,#0]
;;;205            stm32f2_clock_needed_counter = 0;
000016  2000              MOVS     r0,#0
000018  4904              LDR      r1,|L4.44|
00001a  6008              STR      r0,[r1,#0]  ; stm32f2_clock_needed_counter
                  |L4.28|
;;;206        }
;;;207        stm32f2_clock_needed_counter++;
00001c  4803              LDR      r0,|L4.44|
00001e  6800              LDR      r0,[r0,#0]  ; stm32f2_clock_needed_counter
000020  1c40              ADDS     r0,r0,#1
000022  4902              LDR      r1,|L4.44|
000024  6008              STR      r0,[r1,#0]  ; stm32f2_clock_needed_counter
;;;208        ENABLE_INTERRUPTS;
000026  b662              CPSIE    i
;;;209    
;;;210        return kNoErr;
000028  2000              MOVS     r0,#0
;;;211    #else
;;;212        return kUnsupportedErr;
;;;213    #endif
;;;214    }
00002a  4770              BX       lr
;;;215    
                          ENDP

                  |L4.44|
                          DCD      stm32f2_clock_needed_counter
                  |L4.48|
                          DCD      0xe000ed10

                          AREA ||i.platform_mcu_powersave_enable||, CODE, READONLY, ALIGN=2

                  platform_mcu_powersave_enable PROC
;;;215    
;;;216    OSStatus platform_mcu_powersave_enable( void )
000000  b672              CPSID    i
;;;217    {
;;;218    #ifndef MICO_DISABLE_MCU_POWERSAVE
;;;219        DISABLE_INTERRUPTS;
;;;220        stm32f2_clock_needed_counter--;
000002  480a              LDR      r0,|L5.44|
000004  6800              LDR      r0,[r0,#0]  ; stm32f2_clock_needed_counter
000006  1e40              SUBS     r0,r0,#1
000008  4908              LDR      r1,|L5.44|
00000a  6008              STR      r0,[r1,#0]  ; stm32f2_clock_needed_counter
;;;221        if ( stm32f2_clock_needed_counter <= 0 )
00000c  4608              MOV      r0,r1
00000e  6800              LDR      r0,[r0,#0]  ; stm32f2_clock_needed_counter
000010  2800              CMP      r0,#0
000012  dc08              BGT      |L5.38|
;;;222        {
;;;223            SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
000014  4806              LDR      r0,|L5.48|
000016  6800              LDR      r0,[r0,#0]
000018  f0400004          ORR      r0,r0,#4
00001c  4904              LDR      r1,|L5.48|
00001e  6008              STR      r0,[r1,#0]
;;;224            stm32f2_clock_needed_counter = 0;
000020  2000              MOVS     r0,#0
000022  4902              LDR      r1,|L5.44|
000024  6008              STR      r0,[r1,#0]  ; stm32f2_clock_needed_counter
                  |L5.38|
;;;225        }
;;;226        ENABLE_INTERRUPTS;
000026  b662              CPSIE    i
;;;227    
;;;228        return kNoErr;
000028  2000              MOVS     r0,#0
;;;229    #else
;;;230        return kUnsupportedErr;
;;;231    #endif
;;;232    }
00002a  4770              BX       lr
;;;233    
                          ENDP

                  |L5.44|
                          DCD      stm32f2_clock_needed_counter
                  |L5.48|
                          DCD      0xe000ed10

                          AREA ||i.platform_mcu_powersave_exit_notify||, CODE, READONLY, ALIGN=2

                  platform_mcu_powersave_exit_notify PROC
;;;233    
;;;234    void platform_mcu_powersave_exit_notify( void )
000000  2001              MOVS     r0,#1
;;;235    {
;;;236    #ifndef MICO_DISABLE_MCU_POWERSAVE
;;;237      UNUSED_PARAMETER( wake_up_interrupt_triggered );
;;;238      wake_up_interrupt_triggered = true;
000002  4901              LDR      r1,|L6.8|
000004  7008              STRB     r0,[r1,#0]
;;;239    #endif
;;;240    }
000006  4770              BX       lr
;;;241    
                          ENDP

                  |L6.8|
                          DCD      wake_up_interrupt_triggered

                          AREA ||i.platform_mcu_powersave_init||, CODE, READONLY, ALIGN=2

                  platform_mcu_powersave_init PROC
;;;112    
;;;113    OSStatus platform_mcu_powersave_init(void)
000000  b500              PUSH     {lr}
;;;114    {
000002  b085              SUB      sp,sp,#0x14
;;;115    #ifndef MICO_DISABLE_MCU_POWERSAVE
;;;116      EXTI_InitTypeDef EXTI_InitStructure;
;;;117      RTC_InitTypeDef RTC_InitStruct;
;;;118      
;;;119      //RTC_DeInit( );
;;;120    
;;;121      RTC_InitStruct.RTC_HourFormat = RTC_HourFormat_24;
000004  2000              MOVS     r0,#0
000006  9000              STR      r0,[sp,#0]
;;;122      
;;;123      /* RTC ticks every second */
;;;124      RTC_InitStruct.RTC_AsynchPrediv = 0x7F;
000008  207f              MOVS     r0,#0x7f
00000a  9001              STR      r0,[sp,#4]
;;;125      RTC_InitStruct.RTC_SynchPrediv = 0xFF;
00000c  20ff              MOVS     r0,#0xff
00000e  9002              STR      r0,[sp,#8]
;;;126      
;;;127      RTC_Init( &RTC_InitStruct );
000010  4668              MOV      r0,sp
000012  f7fffffe          BL       RTC_Init
;;;128      
;;;129      /* Enable the PWR clock */
;;;130      RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
000016  2101              MOVS     r1,#1
000018  0708              LSLS     r0,r1,#28
00001a  f7fffffe          BL       RCC_APB1PeriphClockCmd
;;;131      
;;;132      /* RTC clock source configuration ------------------------------------------*/
;;;133      /* Allow access to BKP Domain */
;;;134      PWR_BackupAccessCmd(ENABLE);
00001e  2001              MOVS     r0,#1
000020  f7fffffe          BL       PWR_BackupAccessCmd
;;;135      PWR_BackupRegulatorCmd(ENABLE);
000024  2001              MOVS     r0,#1
000026  f7fffffe          BL       PWR_BackupRegulatorCmd
;;;136      
;;;137      /* Enable the LSE OSC */
;;;138      RCC_LSEConfig(RCC_LSE_ON);
00002a  2001              MOVS     r0,#1
00002c  f7fffffe          BL       RCC_LSEConfig
;;;139      /* Wait till LSE is ready */
;;;140      while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
000030  bf00              NOP      
                  |L7.50|
000032  2041              MOVS     r0,#0x41
000034  f7fffffe          BL       RCC_GetFlagStatus
000038  2800              CMP      r0,#0
00003a  d0fa              BEQ      |L7.50|
;;;141      {
;;;142      }
;;;143      
;;;144      /* Select the RTC Clock Source */
;;;145      RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
00003c  f44f7080          MOV      r0,#0x100
000040  f7fffffe          BL       RCC_RTCCLKConfig
;;;146      
;;;147      /* Enable the RTC Clock */
;;;148      RCC_RTCCLKCmd(ENABLE);
000044  2001              MOVS     r0,#1
000046  f7fffffe          BL       RCC_RTCCLKCmd
;;;149      
;;;150      
;;;151      /* RTC configuration -------------------------------------------------------*/
;;;152      /* Wait for RTC APB registers synchronisation */
;;;153      RTC_WaitForSynchro();
00004a  f7fffffe          BL       RTC_WaitForSynchro
;;;154      
;;;155      RTC_WakeUpCmd( DISABLE );
00004e  2000              MOVS     r0,#0
000050  f7fffffe          BL       RTC_WakeUpCmd
;;;156      EXTI_ClearITPendingBit( RTC_INTERRUPT_EXTI_LINE );
000054  f44f0080          MOV      r0,#0x400000
000058  f7fffffe          BL       EXTI_ClearITPendingBit
;;;157      PWR_ClearFlag(PWR_FLAG_WU);
00005c  2001              MOVS     r0,#1
00005e  f7fffffe          BL       PWR_ClearFlag
;;;158      RTC_ClearFlag(RTC_FLAG_WUTF);
000062  f44f6080          MOV      r0,#0x400
000066  f7fffffe          BL       RTC_ClearFlag
;;;159      
;;;160      RTC_WakeUpClockConfig(RTC_WakeUpClock_RTCCLK_Div2);
00006a  2003              MOVS     r0,#3
00006c  f7fffffe          BL       RTC_WakeUpClockConfig
;;;161      
;;;162      EXTI_ClearITPendingBit( RTC_INTERRUPT_EXTI_LINE );
000070  f44f0080          MOV      r0,#0x400000
000074  f7fffffe          BL       EXTI_ClearITPendingBit
;;;163      EXTI_InitStructure.EXTI_Line = RTC_INTERRUPT_EXTI_LINE;
000078  f44f0080          MOV      r0,#0x400000
00007c  9003              STR      r0,[sp,#0xc]
;;;164      EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
00007e  2000              MOVS     r0,#0
000080  f88d0010          STRB     r0,[sp,#0x10]
;;;165      EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
000084  2008              MOVS     r0,#8
000086  f88d0011          STRB     r0,[sp,#0x11]
;;;166      EXTI_InitStructure.EXTI_LineCmd = ENABLE;
00008a  2001              MOVS     r0,#1
00008c  f88d0012          STRB     r0,[sp,#0x12]
;;;167      EXTI_Init(&EXTI_InitStructure);
000090  a803              ADD      r0,sp,#0xc
000092  f7fffffe          BL       EXTI_Init
;;;168      
;;;169      NVIC_EnableIRQ( RTC_WKUP_IRQn );
000096  2003              MOVS     r0,#3
000098  2101              MOVS     r1,#1
00009a  4081              LSLS     r1,r1,r0
00009c  0942              LSRS     r2,r0,#5
00009e  0092              LSLS     r2,r2,#2
0000a0  f10222e0          ADD      r2,r2,#0xe000e000
0000a4  f8c21100          STR      r1,[r2,#0x100]
0000a8  bf00              NOP      
;;;170    
;;;171      RTC_ITConfig(RTC_IT_WUT, DISABLE);
0000aa  2100              MOVS     r1,#0
0000ac  f44f4080          MOV      r0,#0x4000
0000b0  f7fffffe          BL       RTC_ITConfig
;;;172      
;;;173      /* Prepare Stop-Mode but leave disabled */
;;;174      //PWR_ClearFlag(PWR_FLAG_WU);
;;;175      PWR->CR  |= PWR_CR_LPDS;
0000b4  4810              LDR      r0,|L7.248|
0000b6  6800              LDR      r0,[r0,#0]
0000b8  f0400001          ORR      r0,r0,#1
0000bc  490e              LDR      r1,|L7.248|
0000be  6008              STR      r0,[r1,#0]
;;;176      PWR->CR  &= (unsigned long)(~(PWR_CR_PDDS));
0000c0  4608              MOV      r0,r1
0000c2  6800              LDR      r0,[r0,#0]
0000c4  f0200002          BIC      r0,r0,#2
0000c8  6008              STR      r0,[r1,#0]
;;;177      SCB->SCR |= ((unsigned long)SCB_SCR_SLEEPDEEP_Msk);
0000ca  480c              LDR      r0,|L7.252|
0000cc  6800              LDR      r0,[r0,#0]
0000ce  f0400004          ORR      r0,r0,#4
0000d2  490a              LDR      r1,|L7.252|
0000d4  6008              STR      r0,[r1,#0]
;;;178      
;;;179    #ifdef USE_RTC_BKP
;;;180      if (RTC_ReadBackupRegister(RTC_BKP_DR0) != USE_RTC_BKP) {
0000d6  2000              MOVS     r0,#0
0000d8  f7fffffe          BL       RTC_ReadBackupRegister
0000dc  4908              LDR      r1,|L7.256|
0000de  4288              CMP      r0,r1
0000e0  d006              BEQ      |L7.240|
;;;181        /* set it to 12:20:30 08/04/2013 monday */
;;;182        platform_rtc_set_time(&default_rtc_time);
0000e2  4808              LDR      r0,|L7.260|
0000e4  f7fffffe          BL       platform_rtc_set_time
;;;183        RTC_WriteBackupRegister(RTC_BKP_DR0, USE_RTC_BKP);
0000e8  4905              LDR      r1,|L7.256|
0000ea  2000              MOVS     r0,#0
0000ec  f7fffffe          BL       RTC_WriteBackupRegister
                  |L7.240|
;;;184      }
;;;185    #else
;;;186      //#ifdef RTC_ENABLED
;;;187      /* application must have mico_application_default_time structure declared somewhere, otherwise it wont compile */
;;;188      /* write default application time inside rtc */
;;;189      platform_rtc_set_time( &default_rtc_time );
;;;190      //#endif /* RTC_ENABLED */
;;;191    #endif
;;;192      return kNoErr;
0000f0  2000              MOVS     r0,#0
;;;193    #else
;;;194      return kUnsupportedErr;
;;;195    #endif
;;;196    }
0000f2  b005              ADD      sp,sp,#0x14
0000f4  bd00              POP      {pc}
;;;197    
                          ENDP

0000f6  0000              DCW      0x0000
                  |L7.248|
                          DCD      0x40007000
                  |L7.252|
                          DCD      0xe000ed10
                  |L7.256|
                          DCD      0x00bb32f2
                  |L7.260|
                          DCD      default_rtc_time

                          AREA ||i.platform_power_down_hook||, CODE, READONLY, ALIGN=1

                  platform_power_down_hook PROC
;;;312    
;;;313    uint32_t platform_power_down_hook( uint32_t sleep_ms )
000000  b510              PUSH     {r4,lr}
;;;314    {
000002  4604              MOV      r4,r0
;;;315    #ifdef MICO_DISABLE_MCU_POWERSAVE
;;;316        /* If MCU powersave feature is disabled, enter idle mode when powerdown hook is called by the RTOS */
;;;317        return idle_power_down_hook( sleep_ms );
;;;318    
;;;319    #else
;;;320        /* If MCU powersave feature is enabled, enter STOP mode when powerdown hook is called by the RTOS */
;;;321        return stop_mode_power_down_hook( sleep_ms );
000004  4620              MOV      r0,r4
000006  f7fffffe          BL       stop_mode_power_down_hook
;;;322    
;;;323    #endif
;;;324    }
00000a  bd10              POP      {r4,pc}
;;;325    
                          ENDP


                          AREA ||i.select_wut_prescaler_calculate_wakeup_time||, CODE, READONLY, ALIGN=2

                  select_wut_prescaler_calculate_wakeup_time PROC
;;;243    #ifndef MICO_DISABLE_MCU_POWERSAVE
;;;244    static OSStatus select_wut_prescaler_calculate_wakeup_time( unsigned long* wakeup_time, unsigned long sleep_ms, unsigned long* scale_factor )
000000  e92d47f0          PUSH     {r4-r10,lr}
;;;245    {
000004  4605              MOV      r5,r0
000006  460e              MOV      r6,r1
000008  4617              MOV      r7,r2
;;;246      unsigned long temp;
;;;247      bool scale_factor_is_found = false;
00000a  f04f0900          MOV      r9,#0
;;;248      int i                              = 0;
00000e  2400              MOVS     r4,#0
;;;249      
;;;250      static unsigned long int available_wut_prescalers[] =
;;;251      {
;;;252        RTC_WakeUpClock_RTCCLK_Div2,
;;;253        RTC_WakeUpClock_RTCCLK_Div4,
;;;254        RTC_WakeUpClock_RTCCLK_Div8,
;;;255        RTC_WakeUpClock_RTCCLK_Div16
;;;256      };
;;;257      static unsigned long scale_factor_values[] = { 2, 4, 8, 16 };
;;;258      
;;;259      if ( sleep_ms == 0xFFFFFFFF )
000010  1c70              ADDS     r0,r6,#1
000012  b968              CBNZ     r0,|L9.48|
;;;260      {
;;;261        /* wake up in a 100ms, since currently there may be no tasks to run, but after a few milliseconds */
;;;262        /* some of them can get unblocked( for example a task is blocked on mutex with unspecified ) */
;;;263        *scale_factor = 2;
000014  2002              MOVS     r0,#2
000016  6038              STR      r0,[r7,#0]
;;;264        RTC_WakeUpClockConfig( RTC_WakeUpClock_RTCCLK_Div2 );
000018  2003              MOVS     r0,#3
00001a  f7fffffe          BL       RTC_WakeUpClockConfig
;;;265        *wakeup_time = NUMBER_OF_LSE_TICKS_PER_MILLISECOND( scale_factor_values[0] ) * 100;
00001e  481f              LDR      r0,|L9.156|
000020  6800              LDR      r0,[r0,#0]  ; scale_factor_values
000022  2120              MOVS     r1,#0x20
000024  fbb1f0f0          UDIV     r0,r1,r0
000028  2164              MOVS     r1,#0x64
00002a  4348              MULS     r0,r1,r0
00002c  6028              STR      r0,[r5,#0]
00002e  e033              B        |L9.152|
                  |L9.48|
;;;266      }
;;;267      else
;;;268      {
;;;269        for ( i = 0; i < 4; i++ )
000030  2400              MOVS     r4,#0
000032  e015              B        |L9.96|
                  |L9.52|
;;;270        {
;;;271          temp = NUMBER_OF_LSE_TICKS_PER_MILLISECOND( scale_factor_values[i] ) * sleep_ms;
000034  4819              LDR      r0,|L9.156|
000036  f8500024          LDR      r0,[r0,r4,LSL #2]
00003a  2120              MOVS     r1,#0x20
00003c  fbb1f0f0          UDIV     r0,r1,r0
000040  fb00f806          MUL      r8,r0,r6
;;;272          if ( temp < WUT_COUNTER_MAX )
000044  f64f70ff          MOV      r0,#0xffff
000048  4580              CMP      r8,r0
00004a  d208              BCS      |L9.94|
;;;273          {
;;;274            scale_factor_is_found = true;
00004c  f04f0901          MOV      r9,#1
;;;275            *wakeup_time = temp;
000050  f8c58000          STR      r8,[r5,#0]
;;;276            *scale_factor = scale_factor_values[i];
000054  4811              LDR      r0,|L9.156|
000056  f8500024          LDR      r0,[r0,r4,LSL #2]
00005a  6038              STR      r0,[r7,#0]
;;;277            break;
00005c  e002              B        |L9.100|
                  |L9.94|
00005e  1c64              ADDS     r4,r4,#1              ;269
                  |L9.96|
000060  2c04              CMP      r4,#4                 ;269
000062  dbe7              BLT      |L9.52|
                  |L9.100|
000064  bf00              NOP      
;;;278          }
;;;279        }
;;;280        if ( scale_factor_is_found )
000066  f1b90f00          CMP      r9,#0
00006a  d005              BEQ      |L9.120|
;;;281        {
;;;282          /* set new prescaler for wakeup timer */
;;;283          RTC_WakeUpClockConfig( available_wut_prescalers[i] );
00006c  490c              LDR      r1,|L9.160|
00006e  f8510024          LDR      r0,[r1,r4,LSL #2]
000072  f7fffffe          BL       RTC_WakeUpClockConfig
000076  e00f              B        |L9.152|
                  |L9.120|
;;;284        }
;;;285        else
;;;286        {
;;;287          /* scale factor can not be picked up for delays more that 32 seconds when RTCLK is selected as a clock source for the wakeup timer
;;;288          * for delays more than 32 seconds change from RTCCLK to 1Hz ck_spre clock source( used to update calendar registers ) */
;;;289          RTC_WakeUpClockConfig( RTC_WakeUpClock_CK_SPRE_16bits );
000078  2004              MOVS     r0,#4
00007a  f7fffffe          BL       RTC_WakeUpClockConfig
;;;290          
;;;291          /* with 1Hz ck_spre clock source the resolution changes to seconds  */
;;;292          *wakeup_time = ( sleep_ms / 1000 ) + 1;
00007e  f44f707a          MOV      r0,#0x3e8
000082  fbb6f0f0          UDIV     r0,r6,r0
000086  1c40              ADDS     r0,r0,#1
000088  6028              STR      r0,[r5,#0]
;;;293          *scale_factor = CK_SPRE_CLOCK_SOURCE_SELECTED;
00008a  f64f70ff          MOV      r0,#0xffff
00008e  6038              STR      r0,[r7,#0]
;;;294          
;;;295          return kGeneralErr;
000090  f04f30ff          MOV      r0,#0xffffffff
                  |L9.148|
;;;296        }
;;;297      }
;;;298      
;;;299      return kNoErr;
;;;300    }
000094  e8bd87f0          POP      {r4-r10,pc}
                  |L9.152|
000098  2000              MOVS     r0,#0                 ;299
00009a  e7fb              B        |L9.148|
;;;301    #endif
                          ENDP

                  |L9.156|
                          DCD      scale_factor_values
                  |L9.160|
                          DCD      available_wut_prescalers

                          AREA ||i.stop_mode_power_down_hook||, CODE, READONLY, ALIGN=2

                  stop_mode_power_down_hook PROC
;;;335    #else
;;;336    static unsigned long stop_mode_power_down_hook( unsigned long sleep_ms )
000000  b57c              PUSH     {r2-r6,lr}
;;;337    {
000002  4604              MOV      r4,r0
;;;338      unsigned long retval;
;;;339      unsigned long wut_ticks_passed;
;;;340      unsigned long scale_factor = 0;
000004  2000              MOVS     r0,#0
000006  9000              STR      r0,[sp,#0]
;;;341      UNUSED_PARAMETER(sleep_ms);
;;;342      UNUSED_PARAMETER(rtc_timeout_start_time);
;;;343      UNUSED_PARAMETER(scale_factor);
;;;344      
;;;345      if ( ( ( SCB->SCR & (unsigned long)SCB_SCR_SLEEPDEEP_Msk) != 0) && sleep_ms < 5 ){
000008  4837              LDR      r0,|L10.232|
00000a  6800              LDR      r0,[r0,#0]
00000c  f0000004          AND      r0,r0,#4
000010  b188              CBZ      r0,|L10.54|
000012  2c05              CMP      r4,#5
000014  d20f              BCS      |L10.54|
;;;346        SCB->SCR &= (~((unsigned long)SCB_SCR_SLEEPDEEP_Msk));
000016  4834              LDR      r0,|L10.232|
000018  6800              LDR      r0,[r0,#0]
00001a  f0200004          BIC      r0,r0,#4
00001e  4932              LDR      r1,|L10.232|
000020  6008              STR      r0,[r1,#0]
;;;347        __asm("wfi");
000022  bf30              WFI      
;;;348        SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
000024  4830              LDR      r0,|L10.232|
000026  6800              LDR      r0,[r0,#0]
000028  f0400004          ORR      r0,r0,#4
00002c  492e              LDR      r1,|L10.232|
00002e  6008              STR      r0,[r1,#0]
;;;349        /* Note: We return 0 ticks passed because system tick is still going when wfi instruction gets executed */
;;;350        ENABLE_INTERRUPTS;
000030  b662              CPSIE    i
;;;351        return 0;
000032  2000              MOVS     r0,#0
                  |L10.52|
;;;352      }
;;;353      
;;;354      if ( ( ( SCB->SCR & (unsigned long)SCB_SCR_SLEEPDEEP_Msk) ) != 0 )
;;;355      {
;;;356        /* pick up the appropriate prescaler for a requested delay */
;;;357        select_wut_prescaler_calculate_wakeup_time(&rtc_timeout_start_time, sleep_ms, &scale_factor );
;;;358    
;;;359        DISABLE_INTERRUPTS;
;;;360        
;;;361        SysTick->CTRL &= (~(SysTick_CTRL_TICKINT_Msk|SysTick_CTRL_ENABLE_Msk)); /* systick IRQ off */
;;;362        RTC_ITConfig(RTC_IT_WUT, ENABLE);
;;;363        
;;;364        EXTI_ClearITPendingBit( RTC_INTERRUPT_EXTI_LINE );
;;;365        PWR_ClearFlag(PWR_FLAG_WU);
;;;366        RTC_ClearFlag(RTC_FLAG_WUTF);
;;;367        
;;;368        RTC_SetWakeUpCounter( rtc_timeout_start_time );
;;;369        RTC_WakeUpCmd( ENABLE );
;;;370        platform_rtc_enter_powersave();
;;;371        
;;;372        DBGMCU->CR |= 0x03; /* Enable debug in stop mode */
;;;373        
;;;374        /* This code will be running with BASEPRI register value set to 0, the main intention behind that is that */
;;;375        /* all interrupts must be allowed to wake the CPU from the power-down mode */
;;;376        /* the PRIMASK is set to 1( see DISABLE_INTERRUPTS), thus we disable all interrupts before entering the power-down mode */
;;;377        /* This may sound contradictory, however according to the ARM CM3 documentation power-management unit */
;;;378        /* takes into account only the contents of the BASEPRI register and it is an external from the CPU core unit */
;;;379        /* PRIMASK register value doesn't affect its operation. */
;;;380        /* So, if the interrupt has been triggered just before the wfi instruction */
;;;381        /* it remains pending and wfi instruction will be treated as a nop  */
;;;382        __asm("wfi");
;;;383        
;;;384        /* After CPU exits powerdown mode, the processer will not execute the interrupt handler(PRIMASK is set to 1) */
;;;385        /* Disable rtc for now */
;;;386        RTC_WakeUpCmd( DISABLE );
;;;387        RTC_ITConfig(RTC_IT_WUT, DISABLE);
;;;388        
;;;389        /* Initialise the clocks again */
;;;390        init_clocks( );
;;;391        
;;;392        /* Enable CPU ticks */
;;;393        SysTick->CTRL |= (SysTick_CTRL_TICKINT_Msk|SysTick_CTRL_ENABLE_Msk);
;;;394        
;;;395        /* Get the time of how long the sleep lasted */
;;;396        wut_ticks_passed = rtc_timeout_start_time - RTC_GetWakeUpCounter();
;;;397        UNUSED_VARIABLE(wut_ticks_passed);
;;;398        platform_rtc_exit_powersave( sleep_ms, (uint32_t *)&retval );
;;;399        /* as soon as interrupts are enabled, we will go and execute the interrupt handler */
;;;400        /* which triggered a wake up event */
;;;401        ENABLE_INTERRUPTS;
;;;402        wake_up_interrupt_triggered = false;
;;;403        return retval;
;;;404      }
;;;405      else
;;;406      {
;;;407        UNUSED_PARAMETER(wut_ticks_passed);
;;;408        ENABLE_INTERRUPTS;
;;;409        __asm("wfi");
;;;410        
;;;411        /* Note: We return 0 ticks passed because system tick is still going when wfi instruction gets executed */
;;;412        return 0;
;;;413      }
;;;414    }
000034  bd7c              POP      {r2-r6,pc}
                  |L10.54|
000036  482c              LDR      r0,|L10.232|
000038  6800              LDR      r0,[r0,#0]            ;354
00003a  f0000004          AND      r0,r0,#4              ;354
00003e  2800              CMP      r0,#0                 ;354
000040  d04d              BEQ      |L10.222|
000042  466a              MOV      r2,sp                 ;357
000044  4621              MOV      r1,r4                 ;357
000046  4829              LDR      r0,|L10.236|
000048  f7fffffe          BL       select_wut_prescaler_calculate_wakeup_time
00004c  b672              CPSID    i                     ;359
00004e  f04f20e0          MOV      r0,#0xe000e000        ;361
000052  6900              LDR      r0,[r0,#0x10]         ;361
000054  f0200003          BIC      r0,r0,#3              ;361
000058  f04f21e0          MOV      r1,#0xe000e000        ;361
00005c  6108              STR      r0,[r1,#0x10]         ;361
00005e  2101              MOVS     r1,#1                 ;362
000060  0388              LSLS     r0,r1,#14             ;362
000062  f7fffffe          BL       RTC_ITConfig
000066  f44f0080          MOV      r0,#0x400000          ;364
00006a  f7fffffe          BL       EXTI_ClearITPendingBit
00006e  2001              MOVS     r0,#1                 ;365
000070  f7fffffe          BL       PWR_ClearFlag
000074  f44f6080          MOV      r0,#0x400             ;366
000078  f7fffffe          BL       RTC_ClearFlag
00007c  481b              LDR      r0,|L10.236|
00007e  6800              LDR      r0,[r0,#0]            ;368  ; rtc_timeout_start_time
000080  f7fffffe          BL       RTC_SetWakeUpCounter
000084  2001              MOVS     r0,#1                 ;369
000086  f7fffffe          BL       RTC_WakeUpCmd
00008a  f7fffffe          BL       platform_rtc_enter_powersave
00008e  4818              LDR      r0,|L10.240|
000090  6840              LDR      r0,[r0,#4]            ;372
000092  f0400003          ORR      r0,r0,#3              ;372
000096  4916              LDR      r1,|L10.240|
000098  6048              STR      r0,[r1,#4]            ;372
00009a  bf30              WFI                            ;382
00009c  2000              MOVS     r0,#0                 ;386
00009e  f7fffffe          BL       RTC_WakeUpCmd
0000a2  2100              MOVS     r1,#0                 ;387
0000a4  f44f4080          MOV      r0,#0x4000            ;387
0000a8  f7fffffe          BL       RTC_ITConfig
0000ac  f7fffffe          BL       init_clocks
0000b0  f04f20e0          MOV      r0,#0xe000e000        ;393
0000b4  6900              LDR      r0,[r0,#0x10]         ;393
0000b6  f0400003          ORR      r0,r0,#3              ;393
0000ba  f04f21e0          MOV      r1,#0xe000e000        ;393
0000be  6108              STR      r0,[r1,#0x10]         ;393
0000c0  f7fffffe          BL       RTC_GetWakeUpCounter
0000c4  4909              LDR      r1,|L10.236|
0000c6  6809              LDR      r1,[r1,#0]            ;396  ; rtc_timeout_start_time
0000c8  1a0d              SUBS     r5,r1,r0              ;396
0000ca  a901              ADD      r1,sp,#4              ;398
0000cc  4620              MOV      r0,r4                 ;398
0000ce  f7fffffe          BL       platform_rtc_exit_powersave
0000d2  b662              CPSIE    i                     ;401
0000d4  2000              MOVS     r0,#0                 ;402
0000d6  4907              LDR      r1,|L10.244|
0000d8  7008              STRB     r0,[r1,#0]            ;402
0000da  9801              LDR      r0,[sp,#4]            ;403
0000dc  e7aa              B        |L10.52|
                  |L10.222|
0000de  b662              CPSIE    i                     ;408
0000e0  bf30              WFI                            ;409
0000e2  2000              MOVS     r0,#0                 ;412
0000e4  e7a6              B        |L10.52|
;;;415    #endif /* MICO_DISABLE_MCU_POWERSAVE */
                          ENDP

0000e6  0000              DCW      0x0000
                  |L10.232|
                          DCD      0xe000ed10
                  |L10.236|
                          DCD      rtc_timeout_start_time
                  |L10.240|
                          DCD      0xe0042000
                  |L10.244|
                          DCD      wake_up_interrupt_triggered

                          AREA ||.constdata||, DATA, READONLY, ALIGN=0

                  default_rtc_time
000000  1e140c01          DCB      0x1e,0x14,0x0c,0x01
000004  08040d            DCB      0x08,0x04,0x0d

                          AREA ||.conststring||, DATA, READONLY, MERGE=1, STRINGS, ALIGN=2

000000  2e2e5c2e          DCB      "..\\..\\..\\..\\Platform\\MCU\\STM32F4xx\\peripherals\\"
000004  2e5c2e2e
000008  5c2e2e5c
00000c  506c6174
000010  666f726d
000014  5c4d4355
000018  5c53544d
00001c  33324634
000020  78785c70
000024  65726970
000028  68657261
00002c  6c735c  
00002f  706c6174          DCB      "platform_mcu_powersave.c",0
000033  666f726d
000037  5f6d6375
00003b  5f706f77
00003f  65727361
000043  76652e63
000047  00      

                          AREA ||.data||, DATA, ALIGN=2

                  wake_up_interrupt_triggered
000000  00000000          DCB      0x00,0x00,0x00,0x00
                  rtc_timeout_start_time
                          DCD      0x00000000
                  stm32f2_clock_needed_counter
                          DCD      0x00000000
                  available_wut_prescalers
                          DCD      0x00000003
                          DCD      0x00000002
                          DCD      0x00000001
                          DCD      0x00000000
                  scale_factor_values
                          DCD      0x00000002
                          DCD      0x00000004
                          DCD      0x00000008
                          DCD      0x00000010

;*** Start embedded assembler ***

#line 1 "..\\..\\..\\..\\Platform\\MCU\\STM32F4xx\\peripherals\\platform_mcu_powersave.c"
	AREA ||.rev16_text||, CODE
	THUMB
	EXPORT |__asm___24_platform_mcu_powersave_c_669374f9____REV16|
#line 114 "..\\..\\..\\..\\Platform\\Cortex-M4\\CMSIS\\core_cmInstr.h"
|__asm___24_platform_mcu_powersave_c_669374f9____REV16| PROC
#line 115

 rev16 r0, r0
 bx lr
	ENDP
	AREA ||.revsh_text||, CODE
	THUMB
	EXPORT |__asm___24_platform_mcu_powersave_c_669374f9____REVSH|
#line 128
|__asm___24_platform_mcu_powersave_c_669374f9____REVSH| PROC
#line 129

 revsh r0, r0
 bx lr
	ENDP

;*** End   embedded assembler ***
