add support for dm8000 rtc,
authorAndreas Monzner <andreas.monzner@multimedia-labs.de>
Tue, 26 Aug 2008 10:54:46 +0000 (10:54 +0000)
committerAndreas Monzner <andreas.monzner@multimedia-labs.de>
Tue, 26 Aug 2008 10:54:46 +0000 (10:54 +0000)
add support for dm8000 deepstandby wakeup,
go back to deepstandby after deepstandby timer wakeup even when not
explicitely selected (this needs new drivers and / or new atmel firmware)
add some sanity checks to dont break anything even with old drivers/atmel
firmware

Navigation.py
RecordTimer.py
lib/dvb/dvbtime.cpp
lib/python/Screens/Standby.py
lib/python/Tools/DreamboxHardware.py
main/enigma.cpp
mytest.py

index eb1a2b14585c3e7ca09deb40c89758c6c248c99e..f46b92d44fac0784ed55ae1ea2ebced32a05a29c 100644 (file)
@@ -1,9 +1,11 @@
 from enigma import eServiceCenter, eServiceReference, pNavigation, getBestPlayableServiceReference, iPlayableService
 from Components.ParentalControl import parentalControl
 from Tools.BoundFunction import boundFunction
+from Tools.DreamboxHardware import setFPWakeuptime, getFPWakeuptime, getFPWasTimerWakeup, clearFPWasTimerWakeup
+from time import time
 import RecordTimer
 import SleepTimer
-
+import Screens.Standby
 import NavigationInstance
 import ServiceReference
 
@@ -27,6 +29,19 @@ class Navigation:
                self.currentlyPlayingServiceReference = None
                self.currentlyPlayingService = None
                self.RecordTimer = RecordTimer.RecordTimer()
+               if getFPWasTimerWakeup():
+                       clearFPWasTimerWakeup()
+                       if getFPWasTimerWakeup(): # sanity check to detect if the FP driver is working correct!
+                               print "buggy fp driver detected!!! please update drivers.... ignore timer wakeup!"
+                               setFPWakeuptime(0)
+                       elif len(self.getRecordings()) or abs(self.RecordTimer.getNextRecordingTime() - time()) <= 360:
+                               setFPWakeuptime(0x89ABCDEF)
+                               if getFPWakeuptime() != 0x89ABCDEF: # sanity check to detect if the FP Atmel Firmware is working correct!
+                                       print "buggy atmel firmware detected!! atmel update needed... ignore fp timer wakeup!"
+                                       setFPWakeuptime(0)
+                               elif not Screens.Standby.inTryQuitMainloop: # not a shutdown messagebox is open
+                                       RecordTimer.RecordTimerEntry.TryQuitMainloop(0) # start shutdown handling
+               setFPWakeuptime(1)
                self.SleepTimer = SleepTimer.SleepTimer()
 
        def dispatchEvent(self, i):
index 147a38fc6510660b340719e9d5fa2c74d6a6d407..f93872cd69c19c9e02bdad2ae3d3830c02d00097 100644 (file)
@@ -79,7 +79,7 @@ class RecordTimerEntry(timer.TimerEntry, object):
                RecordTimerEntry.receiveRecordEvents = False
 
        @staticmethod
-       def TryQuitMainloop():
+       def TryQuitMainloop(default_yes = True):
                if not RecordTimerEntry.receiveRecordEvents:
                        print "RecordTimer.TryQuitMainloop"
                        NavigationInstance.instance.record_event.append(RecordTimerEntry.staticGotRecordEvent)
@@ -88,7 +88,7 @@ class RecordTimerEntry(timer.TimerEntry, object):
                        # other timers start in a few seconds
                        RecordTimerEntry.staticGotRecordEvent(None, iRecordableService.evEnd)
                        # send normal notification for the case the user leave the standby now..
-                       Notifications.AddNotification(Screens.Standby.TryQuitMainloop, 1, onSessionOpenCallback=RecordTimerEntry.stopTryQuitMainloop)
+                       Notifications.AddNotification(Screens.Standby.TryQuitMainloop, 1, onSessionOpenCallback=RecordTimerEntry.stopTryQuitMainloop, default_yes = default_yes)
 #################################################################
 
        def __init__(self, serviceref, begin, end, name, description, eit, disabled = False, justplay = False, afterEvent = AFTEREVENT.NONE, checkOldTimers = False, dirname = None):
@@ -271,9 +271,9 @@ class RecordTimerEntry(timer.TimerEntry, object):
                        if self.afterEvent == AFTEREVENT.STANDBY:
                                if not Screens.Standby.inStandby: # not already in standby
                                        Notifications.AddNotificationWithCallback(self.sendStandbyNotification, MessageBox, _("A finished record timer wants to set your\nDreambox to standby. Do that now?"), timeout = 20)
-                       if self.afterEvent == AFTEREVENT.DEEPSTANDBY:
+                       elif self.afterEvent == AFTEREVENT.DEEPSTANDBY:
                                if not Screens.Standby.inTryQuitMainloop: # not a shutdown messagebox is open
-                                       if Screens.Standby.inStandby: # not in standby
+                                       if Screens.Standby.inStandby: # in standby
                                                RecordTimerEntry.TryQuitMainloop() # start shutdown handling without screen
                                        else:
                                                Notifications.AddNotificationWithCallback(self.sendTryQuitMainloopNotification, MessageBox, _("A finished record timer wants to shut down\nyour Dreambox. Shutdown now?"), timeout = 20)
index 616363f9107af2400d1da8e6e93ec04adf6a1dcc..6cfaccc89f06d213638157d2a3d13a2043a7b384 100644 (file)
@@ -15,26 +15,61 @@ static time_t prev_time;
 
 void setRTC(time_t time)
 {
-       int fd = open("/dev/dbox/fp0", O_RDWR);
-       if ( fd >= 0 )
+       FILE *f = fopen("/proc/stb/fp/rtc", "w");
+       if (f)
        {
-               if ( ::ioctl(fd, FP_IOCTL_SET_RTC, (void*)&time ) < 0 )
-                       eDebug("FP_IOCTL_SET_RTC failed(%m)");
+               time_t wakeup=0;
+               FILE *f2 = fopen("/proc/stb/fp/wakeup_time", "r");
+               if (f2)
+               {
+                       fscanf(f2, "%u", &wakeup);
+                       fclose(f2);
+               }
+               if (wakeup) // atmel firmware okay?
+               {
+                       if (fprintf(f, "%u", time))
+                               prev_time = time;
+                       else
+                               eDebug("write /proc/stb/fp/rtc failed (%m)");
+                       fclose(f);
+               }
                else
-                       prev_time = time;
-               close(fd);
+                       eDebug("dont set rtc because of buggy atmel firmware!");
+       }
+       else
+       {
+               int fd = open("/dev/dbox/fp0", O_RDWR);
+               if ( fd >= 0 )
+               {
+                       if ( ::ioctl(fd, FP_IOCTL_SET_RTC, (void*)&time ) < 0 )
+                               eDebug("FP_IOCTL_SET_RTC failed(%m)");
+                       else
+                               prev_time = time;
+                       close(fd);
+               }
        }
 }
 
 time_t getRTC()
 {
        time_t rtc_time=0;
-       int fd = open("/dev/dbox/fp0", O_RDWR);
-       if ( fd >= 0 )
+       FILE *f = fopen("/proc/stb/fp/rtc", "r");
+       if (f)
+       {
+               // sanity check to detect corrupt atmel firmware
+               if (fscanf(f, "%u", &rtc_time) != 1)
+                       eDebug("read /proc/stb/fp/rtc failed (%m)");
+               fclose(f);
+       }
+       else
        {
-               if ( ::ioctl(fd, FP_IOCTL_GET_RTC, (void*)&rtc_time ) < 0 )
-                       eDebug("FP_IOCTL_GET_RTC failed(%m)");
-               close(fd);
+               int fd = open("/dev/dbox/fp0", O_RDWR);
+               if ( fd >= 0 )
+               {
+                       if ( ::ioctl(fd, FP_IOCTL_GET_RTC, (void*)&rtc_time ) < 0 )
+                               eDebug("FP_IOCTL_GET_RTC failed(%m)");
+                       close(fd);
+               }
        }
        return rtc_time != prev_time ? rtc_time : 0;
 }
index f7c819de8da932ff501b050995e3e8dc8328e182..fd7ca8efdca072e04cd7168f89aa6a6643b629fd 100644 (file)
@@ -93,7 +93,7 @@ from time import time
 inTryQuitMainloop = False
 
 class TryQuitMainloop(MessageBox):
-       def __init__(self, session, retvalue=1, timeout=-1):
+       def __init__(self, session, retvalue=1, timeout=-1, default_yes = True):
                self.retval=retvalue
                recordings = len(session.nav.getRecordings())
                self.connected = False
@@ -102,13 +102,13 @@ class TryQuitMainloop(MessageBox):
                        next_rec_time = session.nav.RecordTimer.getNextRecordingTime()
                if recordings or (next_rec_time > 0 and (next_rec_time - time()) < 360):
                        if retvalue == 1:
-                               MessageBox.__init__(self, session, _("Recording(s) are in progress or coming up in few seconds... really shutdown now?"), type = MessageBox.TYPE_YESNO, timeout = timeout)
+                               MessageBox.__init__(self, session, _("Recording(s) are in progress or coming up in few seconds... really shutdown now?"), type = MessageBox.TYPE_YESNO, timeout = timeout, default = default_yes)
                        elif retvalue == 2:
-                               MessageBox.__init__(self, session, _("Recording(s) are in progress or coming up in few seconds... really reboot now?"), type = MessageBox.TYPE_YESNO, timeout = timeout)
+                               MessageBox.__init__(self, session, _("Recording(s) are in progress or coming up in few seconds... really reboot now?"), type = MessageBox.TYPE_YESNO, timeout = timeout, default = default_yes)
                        elif retvalue == 4:
                                pass
                        else:
-                               MessageBox.__init__(self, session, _("Recording(s) are in progress or coming up in few seconds... really restart now?"), type = MessageBox.TYPE_YESNO, timeout = timeout)
+                               MessageBox.__init__(self, session, _("Recording(s) are in progress or coming up in few seconds... really restart now?"), type = MessageBox.TYPE_YESNO, timeout = timeout, default = default_yes)
                        self.skinName = "MessageBox"
                        session.nav.record_event.append(self.getRecordEvent)
                        self.connected = True
index 5eaaeecaba7fbd8eef7cc0d0b95e4e2de206e970..2a0ddeeec76d6e2913a282acd1b5c29d7dab770e 100644 (file)
@@ -1,17 +1,54 @@
+from fcntl import ioctl
+from struct import pack, unpack
+
 def getFPVersion():
-       from fcntl import ioctl
        try:
                fp = open("/dev/dbox/fp0")
                return ioctl(fp.fileno(),0)
        except IOError:
+               print "getFPVersion failed!"
                return None
 
 def setFPWakeuptime(wutime):
-       from fcntl import ioctl
-       from struct import pack
+       try:
+               open("/proc/stb/fp/wakeup_time", "w").write(str(wutime))
+       except IOError:
+               try:
+                       fp = open("/dev/dbox/fp0")
+                       ioctl(fp.fileno(), 6, pack('L', wutime)) # set wake up
+               except IOError:
+                       print "setFPWakeupTime failed!"
 
+def getFPWakeuptime():
+       ret = 0
        try:
-               fp = open("/dev/dbox/fp0")
-               ioctl(fp.fileno(), 6, pack('L', wutime)) # set wake up
+               ret = long(open("/proc/stb/fp/wakeup_time", "r").read())
        except IOError:
-               pass    
+               try:
+                       fp = open("/dev/dbox/fp0")
+                       ret = unpack('L', ioctl(fp.fileno(), 5, '    '))[0] # get wakeuptime
+               except IOError:
+                       print "getFPWakeupTime failed!"
+       return ret
+
+def getFPWasTimerWakeup():
+       was_wakeup = False
+       try:
+               was_wakeup = int(open("/proc/stb/fp/was_timer_wakeup", "r").read()) and True or False
+       except:
+               try:
+                       fp = open("/dev/dbox/fp0")
+                       was_wakeup = unpack('B', ioctl(fp.fileno(), 9, ' '))[0] and True or False
+               except IOError:
+                       print "wasTimerWakeup failed!"
+       return was_wakeup
+
+def clearFPWasTimerWakeup():
+       try:
+               open("/proc/stb/fp/was_timer_wakeup", "w").write('0')
+       except:
+               try:
+                       fp = open("/dev/dbox/fp0")
+                       ioctl(fp.fileno(), 10)
+               except IOError:
+                       print "clearFPWasTimerWakeup failed!"
index 307edd5a9fd35fb9f0fbe322b7574a1582e2c4ed..0893b035f74cb4cbf814f8ccfbb1f95579022ba9 100644 (file)
@@ -1,5 +1,8 @@
-#include <stdio.h>
 #include <unistd.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/ioctl.h>
 #include <libsig_comp.h>
 
 #include <lib/actions/action.h>
@@ -277,6 +280,24 @@ void runMainloop()
 
 void quitMainloop(int exitCode)
 {
+       FILE *f = fopen("/proc/stb/fp/was_timer_wakeup", "w");
+       if (f)
+       {
+               fprintf(f, "%d", 0);
+               fclose(f);
+       }
+       else
+       {
+               int fd = open("/dev/dbox/fp0", O_WRONLY);
+               if (fd >= 0)
+               {
+                       if (ioctl(fd, 10 /*FP_CLEAR_WAKEUP_TIMER*/) < 0)
+                               eDebug("FP_CLEAR_WAKEUP_TIMER failed (%m)");
+                       close(fd);
+               }
+               else
+                       eDebug("open /dev/dbox/fp0 for wakeup timer clear failed!(%m)");
+       }
        exit_code = exitCode;
        eApp->quit(0);
 }
index 0c448d702a774dba1d6ac2a09f9285c82c34ae64..2dcd0d3317c5c3d7abd83361b090156e0c0fcda3 100644 (file)
--- a/mytest.py
+++ b/mytest.py
@@ -467,7 +467,7 @@ def runScreenTest():
 
        profile("wakeup")
        from time import time
-       from Tools.DreamboxHardware import setFPWakeuptime
+       from Tools.DreamboxHardware import setFPWakeuptime, getFPWakeuptime
        #get currentTime
        nowTime = time()
        wakeupList = [
@@ -478,12 +478,16 @@ def runScreenTest():
                if x != -1
        ]
        wakeupList.sort()
-       if len(wakeupList):
+       if len(wakeupList) and getFPWakeuptime(): # getFPWakeuptime returns 1 when the sanity check in Navigation.py was okay..
                startTime = wakeupList.pop(0)
-               if (startTime - nowTime < 330): # no time to switch box back on
-                       setFPWakeuptime(nowTime + 30) # so switch back on in 30 seconds
+               if (startTime - nowTime) < 330: # no time to switch box back on
+                       wptime = nowTime + 30  # so switch back on in 30 seconds
                else:
-                       setFPWakeuptime(startTime - 300)
+                       wptime = startTime - 300
+               setFPWakeuptime(wptime)
+       else:
+               print "buggy atmel firmware detected... dont set a wakeup time!"
+               setFPWakeuptime(0)
        profile("stopService")
        session.nav.stopService()
        profile("nav shutdown")