There are three ways to sleep the system in wince:
1. Select suspend from the Start Menu.
2. You can press the power button to request the system to enter sleep mode (for example, if you want to press and shut down for a long time or press sleep for a short time)
3. the user has not been operating for a long time. The system status is changed from power_state_on to power_state_useridle and power_state_idle. Then, the user enters the power_state_suspend state, that is, sleep state.
Before sleep, the system calls the xxx_powerdown interface of this driver to shut down the power of the driver that supports power management. Then the system calls the oempoweroff interface to sleep.
Oempoweroff is located at smdk2440a/src/common/power/off. in file C, do not be confused by its name. It is not only responsible for sleep, but is also implemented internally after being awakened. Its execution process is as follows:
1. Call bsppoweroff to disable unnecessary device power during sleep, such as USB
2. Save information such as the current gpio and LCD controller in the memory
3. Set gpio to low power consumption and disable LCD and other devices.
4. Call oalcpupoweroff. The SDRAM enters the auto-Refresh mode, closes the CPU, and waits for the interruption to wake up.
5. Restore information such as gpio and LCD controller stored in memory
6. Call bsppoweron to power on the relevant device, and then return
In this process, the most vulnerable part is the oalcpupoweroff part, which starts from the 2440 sleep mode.
2440 two independent power supplies are required. One power supply is used to power the CPU and its internal logic, and the other power supply is used to separately power the wake-up logic. When 2440 enters sleep, the power supply of the CPU and its internal logic will stop, and only the power supply of the wake-up logic will be retained. The wake-up logic supports EINT0-15 and RTC interruptions. If these interruptions occur during sleep, the system will recover power to the CPU and wake up the CPU.
Since the CPU loses power during sleep, after it is awakened, it will start to execute commands from address 0x00000000. That is to say, at this time, the CPU is out of the wince execution space and runs bootloader!
After the bootloader is executed, perform necessary initialization tasks, such as setting the system clock, and then check the gstatus2 [1] bits. If it is set to 1, it indicates that the system is restored from sleep. bootloader will skip the normal startup process, recover power supply to the SDRAM, and then recover the data stored before sleep from the SDRAM, including the wake-up address, then go to the wake-up address for execution and return the execution space of wince.
The following code details the process (smdk2440a/src/oal/oallib/startup. s ):
; Oalcpupoweroff call entry <br/> leaf_entry oalcpupoweroff </P> <p>; 1. Push SVC state onto our stack <br/> analytic dB SP !, {R4-r12} <br/> analytic dB SP !, {LR} </P> <p>; 2. save MMU & CPU register to ram <br/>; Note: sleepdata_base_virtual uses a virtual address, the mapped physical address must be consistent with that set in bootloader <br/> LDR R3, = sleepdata_base_virtual; base of sleep mode storage </P> <p> LDR R2, = awake_address; store virtual return address <br/> STR R2, [R3], #4 </P> <p> MRC P15, 0, R2, C1, C0, 0; load R2 with MMU Control <br/> LDR r0, = mmu_ctl_mask; mask off the undefined bits <br/> Bic r2, R2, R0 <br/> STR R2, [R3], #4; store MMU control data </P> <p> MRC P15, 0, R2, C2, C0, 0; load R2 with TTB address. <br/> LDR r0, = mmu_ttb_mask; mask off the undefined bits <br/> Bic R2, R2, R0 <br/> STR R2, [R3], #4; store TTB address </P> <p> MRC P15, 0, R2, C3, C0, 0; load R2 with domain access control. <br/> STR R2, [R3], #4; store domain access control </P> <p> STR sp, [R3], #4; store SVC Stack pointer </P> <p> Mrs R2, spsr <br/> STR R2, [R3], #4; store SVC status register </P> <p> mov R1, # mode_fiq: Or: I _bit: Or: f_bit; enter FIQ mode, no interrupts <br/> MSR CPSR, r1 <br/> Mrs R2, spsr <br/> stmia R3 !, {R2, r8-r12, SP, LR}; store the FIQ mode registers </P> <p> mov R1, # mode_abt: Or: I _bit: Or: f_bit; enter abt mode, no interrupts <br/> msr cpsr, R1 <br/> Mrs r0, spsr <br/> stmia R3 !, {R0, SP, LR}; store the Abt mode registers </P> <p> mov R1, # mode_irq: Or: I _bit: Or: f_bit; enter IRQ mode, no interrupts <br/> msr cpsr, R1 <br/> Mrs r0, spsr <br/> stmia R3 !, {R0, SP, LR}; store the IRQ mode registers </P> <p> mov R1, # mode_und: Or: I _bit: Or: f_bit; enter und mode, no interrupts <br/> msr cpsr, R1 <br/> Mrs r0, spsr <br/> stmia R3 !, {R0, SP, LR}; store the und mode registers </P> <p> mov R1, # mode_sys: Or: I _bit: Or: f_bit; enter sys mode, no interrupts <br/> msr cpsr, R1 <br/> stmia R3 !, {Sp, LR}; store the Sys mode registers </P> <p> mov R1, # mode_svc: Or: I _bit: Or: f_bit; Back to SVC mode, no interrupts <br/> msr cpsr, R1 </P> <p>; 3. do checksum on the sleepdata <br/> LDR R3, = sleepdata_base_virtual; get pointer to sleepdata <br/> LDR R2, = 0x0 <br/> LDR r0, = (SLEEPDATA_SIZE-1); get size of Data Structure (in words) <br/> 30 <br/> LDR R1, [R3], #4 <br/> and R1, r1, #0x1 <br/> mov r1, R1, Ror #31 <br/> Add R2, R2, R1 <br/> subs r0, R0, #1 <br/> BNE % B30 </P> <p>; Save the data checksum in gstatus3. Check is required in bootloader. wince is returned only when the verification is correct, otherwise, follow the Cold Start Process <br/> LDR r0, = vgpiobase <br/> STR R2, [r0, # ogstatus3]; store in Power Manager scratch pad register </P> <p>; 4. interrupt disable <br/> LDR r0, = vintbase <br/> MVN R2, #0 <br/> STR R2, [r0, # ointmsk] <br/> STR R2, [r0, # osrcpnd] <br/> STR R2, [r0, # oint PND] </P> <p>; 5. cache flush <br/> BL oalclearutlb <br/> BL oalflushicache <br/> LDR r0, = (dcache_lines_per_set-1) <br/> LDR R1, = (dcache_num_sets-1) <br/> LDR R2, = dcache_set_index_bit <br/> LDR R3, = dcache_line_size <br/> BL oalflushdcache </P> <p>; 6. setting wakeup External Interrupt (eint0, 1) mode <br/> LDR r0, = vgpiobase </P> <p> LDR R1, = 0x550a <br/> STR R1, [r0, # ogpfcon] </P> <p>; 7. go To power-off mode <br/> LDR r0, = vmiscr; hit the TLB <br/> LDR r0, [R0] <br/> LDR r0, = vclkcon <br/> LDR r0, [R0] </P> <p>; the memory enters the auto-Refresh mode, and the content is kept after the CPU power is down <br/> LDR r0, = vrefresh <br/> LDR R1, [R0]; R1 = rrefresh <br/> Orr R1, R1, #(1 <22) </P> <p> LDR R2, = vmiscr <br/> LDR R3, [R2] <br/> Orr R3, R3, #(7 <17 ); make sure that sclk0: sclk-> 0, sclk1: sclk-> 0, scke = L during boot-up <br/> Bic R3, R3, #(7 <20) <br /> Orr R3, R3, #(6 <20) </P> <p> LDR R4, = vclkcon <br/> LDR R5, = 0x1ffff8; power off mode </P> <p> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;; <br/>; sometimes it is not working in cache mode. so I modify to jump to Rom area. <br/>; LDR R6, = 0x92000000; make address to 0x9200 0020 <br/>; add R6, R6, #0x20; <br/>; MoV PC, R6; jump to power off Code in ROM <br/> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;; </P> <p> B selfrefreshandpoweroff </P> <p> align 32; for I-Cache line (32 byte, 8 word) </P> <p> ;; disable CPU <br/> selfreshandpoweroff; run with instruction cache's Code <br/> STR R1, [R0]; Enable SDRAM self-Refresh <br/> STR R3, [R2]; miscr setting <br/> STR R5, [R4]; power off !! <Br/> B. </P> <p>
The following code wakes up part of the Bootloader:
; Check if the boot is caused by the wake-up from sleep mode. <br/> LDR R1, = gstatus2 <br/> LDR r0, [R1] <br/> TST r0, #0x2 </P> <p>; in case of the wake-up from sleep mode, go to sleep_wakeup handler. <br/> BNE wakeup_sleep </P> <p> wakeup_sleep <br/>; release sclkn after wake-up from the sleep mode. <br/> LDR R1, = miscr <br/> LDR r0, [R1] <br/> Bic r0, R0, #(7 <17); sclk0: 0-> sclk, sclk1: 0-> sclk, scke: 0-> = scke. <br/> STR r0, [R1] </P> <p>; Set memory control registers <br/> LDR r0, = smrdata <br/> LDR R1, = bwscon; bwscon address <br/> Add R2, R0, #52; end address of smrdata <br/> 0 <br/> LDR R3, [R0], #4 <br/> STR R3, [R1], #4 <br/> CMP R2, R0 <br/> BNE % B0 </P> <p> mov R1, #256 <br/> 0 subs R1, R1, #1; 1) wait until the selfrefresh is released. <br/> BNE % B0 </P> <p>; Recovery <br/>; recover process: starting point <br/>; 1. checksum calculation saved data <br/>; sleepdata_base_physical here. The preceding virtual address sleepdata_base_virtual must be mapped to the same physical memory <br/> LDR R5, = sleepdata_base_physical; pointer to physical address of reserved sleep mode INFO Data Structure <br/> mov R3, R5; pointer for checksum calculation <br/> LDR R2, = 0x0 <br/> LDR r0, = (SLEEPDATA_SIZE-1); get size of Data Structure to do checksum on <br/> 50 <br/> LDR R1, [R3], #4; pointer to sleepdata <br/> and R1, R1, #0x1 <br/> mov R1, R1, ror #31 <br/> Add R2, R2, R1 <br/> subs r0, R0, #1; Dec the count <br/> BNE % B50; loop till done </P> <p>; check the checksum. If the checksum does not match, it indicates that the data stored in the memory is faulty. Run it by cold start. <br/> LDR r0, = gstatus3 <br/> LDR R3, [R0]; get the sleep data checksum from the Power Manager scratch pad register <br/> CMP R2, R3; compare to what we saved before going to sleep <br/> BNE bringupwince; bad news-Do a cold boot </P> <p>; 2. MMU enable <br/> LDR R10, [R5, # sleepstate_mmudomain]; load the MMU domain access info <br/> LDR R9, [R5, # sleepstate_mmuttb]; load the mmu ttb info <br/> LDR R8, [R5, # sleepstate_mmuctl]; load the MMU control info <br/> LDR R7, [R5, # sleepstate_wakeaddr]; load the LR address <br/> NOP </P> <p>; if software reset <br/> mov R1, #0 <br/> TEQ R1, r7 <br/> BNE % f60 <br/> B bringupwince </P> <p>; wakeup routine <br/> 60 MCR P15, 0, R10, C3, C0, 0; Setup access to domain 0 <br/> MCR P15, 0, R9, C2, C0, 0; Pt address <br/> MCR P15, 0, R0, C8, c7, 0; flush I + D tlbs <br/> MCR P15, 0, R8, C1, C0, 0; restore MMU Control </P> <p>; 3. jump to kernel image's FW. S (awake_address) <br/> mov PC, R7; jump to new VA (back up power management stack) <br/> NOP </P> <p> bringupwince <br/>; bad news, data lose, bring up wince again <br/> mov r0, #2 <br/> LDR R1, = gstatus2 <br/> STR r0, [R1] <br/>