Share Pastebin
Guest
Public paste!

sweetlilmre

By: a guest | Aug 23rd, 2010 | Syntax: None | Size: 1.70 KB | Hits: 169 | Expires: Never
Copy text to clipboard
  1. /*
  2.  * This macro tests the CPU reset state and takes appropriate actions as follows:
  3.  *
  4.  *   Watchdog Reset: (Reset from linux)
  5.  *      Continue to Normal boot
  6.  *   Sleep-Exit Reset (Sleep, or Deep-Sleep from linux poweroff() / other boot):
  7.  *      Check for non-zero in Scratch register, if so resume from Scratch register
  8.  *      If not issue WatchDog reset
  9.  *   All other reset types:
  10.  *      Enter Deep-Sleep mode
  11.  * Clobbered regs: r4, r5
  12.  */
  13.  
  14. .macro  z2_wakeup
  15.         ldr             r4,             =RCSR
  16.         ldr             r5,             [r4]
  17.         and             r5,             r5,             #(RCSR_GPR | RCSR_SMR | RCSR_WDR | RCSR_HWR)
  18.         str             r5,             [r4]
  19.  
  20. // check for Watchdog Reset
  21.         teq             r5,             #RCSR_WDR
  22.         beq             z2_wakeup_exit
  23.  
  24. // check for Sleep-Exit Reset
  25.         teq             r5,             #RCSR_SMR
  26.         beq             z2_wakeup_sleep_exit
  27.  
  28. // Nope something else woke us up
  29. // zero the scratch register
  30.         ldr             r4,             =PSPR
  31.         mov             r5,             #0
  32.         str             r5,             [r4]
  33. // enter deep sleep
  34.         mov             r4,             #7
  35.         mcr             p14,    0, r4, c7, c0, 0
  36.  
  37. z2_wakeup_sleep_loop:
  38.         b                       z2_wakeup_sleep_loop
  39.  
  40. z2_wakeup_sleep_exit:
  41.         ldr             r4,             =PSSR
  42.         mov             r5,             #PSSR_PH
  43.         str             r5,             [r4]
  44.  
  45.         ldr             r4,             =PSPR
  46.         ldr             r5,             [r4]
  47.         cmp             r5,             #0x0
  48.         beq             z2_wakeup_watchdog_reset
  49. // continue wakeup
  50.         ldr             pc,             [r4]
  51.  
  52. // scratch == 0 (exit from deep sleep) so perform a clean watchdog reset ( when control returns, initiate a boot )
  53. z2_wakeup_watchdog_reset:
  54.  
  55. // enable Watchdog match to generate reset
  56.         ldr             r4,             =OWER
  57.         mov             r5,             #OWER_WME
  58.         str             r5,             [r4]
  59.        
  60. // Clear the Match Status for Watchdog: M3
  61.  
  62.         ldr             r4,             =OSSR
  63.         mov             r5,             #OSSR_M3
  64.         str             r5,             [r4]
  65.  
  66. // reset when OSMR3 and OSCR match ~ 100 ms
  67.         ldr             r4,             =OSCR
  68.         ldr             r5,             [r4]
  69.         add             r5,             r5,             #0x50000
  70.         ldr             r4,             =OSMR3
  71.         str             r5,             [r4]
  72.  
  73.         b                       z2_wakeup_sleep_loop
  74.  
  75. z2_wakeup_exit:
  76. .endm