#!/bin/bash
#
# Shell script to put CPU into sleep mode
#

# Flush the file system
/bin/sync

# Set PWER
# This sets the bits for what can wake us out of sleep
# The current bits set are:
# 0x80000000 = SA1100 RTC (/root/suspend needs this)
# 0x8 and 0x4 = Exar UARTs (/dev/ttySX{0-15})
# 0x1        = MSP430
# See the Sidearm4 documentation on the the assignment
# of GPIO bits.  Set additional bits as necessary.
/root/setPWER 80000001

#Suspend a minimum of 6 seconds (3 to wait for flush, 3 for suspend)
if [ $1 -gt 6 ]
then
# Do a sleep (busy-wait) for 3 seconds to allow CFM to flush
    sleep 3

# Now put the CPU into sleep
# Uncomment the ifdown/iup lines if you want ethernet after sleep
# But note that ifup can take many seconds.
#   ifdown eth0
    let sleepTime=$1-3
    /root/suspend -v $sleepTime
    /root/ricohRTC -s
#   ifup eth0
fi
