|
1 /* |
|
2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * naviengine_assp\naviengine.cpp |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 #include <naviengine_priv.h> |
|
22 #include "watchdog.h" |
|
23 |
|
24 const TInt KWatchdogTimeoutSecs = 5; // the period, in seconds, that the watchdog timer will expire |
|
25 |
|
26 // |
|
27 // Pat the watchdog to prevent the board from resetting |
|
28 // |
|
29 void TNaviEngineWatchdog::WatchdogTimer(TAny* aPtr) |
|
30 { |
|
31 __KTRACE_OPT(KHARDWARE, Kern::Printf("watchdogTimer expired")); |
|
32 //Kern::Printf("watchdogTimer expired"); |
|
33 |
|
34 TNaviEngineWatchdog *pDog = (TNaviEngineWatchdog *) aPtr; |
|
35 |
|
36 // Pat the Dog now to give us the full period to respond with the timer |
|
37 AsspRegister::Write32(KHwWatchdog_WDTINT, 1); |
|
38 |
|
39 // Now queue the timer again so that we can pat it next time around |
|
40 pDog->iWatchdogTimer.Again(NKern::TimerTicks(pDog->iWatchdogTimerPeriodMs)); |
|
41 } |
|
42 |
|
43 |
|
44 |
|
45 // |
|
46 // Constructor |
|
47 // |
|
48 // We only really need the constructor to create the timer instance. |
|
49 // |
|
50 TNaviEngineWatchdog::TNaviEngineWatchdog() : |
|
51 iWatchdogTimer(WatchdogTimer,this) |
|
52 { |
|
53 } |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 // Destructor should never be called |
|
59 TNaviEngineWatchdog::~TNaviEngineWatchdog() |
|
60 { |
|
61 __crash(); |
|
62 } |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 /** |
|
68 Perform hardware-dependent initialisation |
|
69 |
|
70 Called by platform independent layer |
|
71 */ |
|
72 TInt TNaviEngineWatchdog::Create() |
|
73 { |
|
74 __KTRACE_OPT(KEXTENSION,Kern::Printf("TNaviEngineWatchdog::Create")); |
|
75 //Kern::Printf("TNaviEngineWatchdog::Create"); |
|
76 SetTimer(KWatchdogTimeoutSecs); |
|
77 return KErrNone; |
|
78 } |
|
79 |
|
80 |
|
81 // |
|
82 // Enable/disable the external watchdog timer (eWDT). |
|
83 // |
|
84 void TNaviEngineWatchdog::SetTimer(TUint aTimeoutInSeconds) |
|
85 { |
|
86 __KTRACE_OPT(KHARDWARE, Kern::Printf(">TNaviEngine::SetWatchdogTimer timeout=%d seconds", aTimeoutInSeconds)); |
|
87 //Kern::Printf(">TNaviEngine::SetWatchdogTimer timeout=%d seconds", aTimeoutInSeconds); |
|
88 |
|
89 // Disable eWDT |
|
90 AsspRegister::Write32(KHwWatchdog_WDTCNT, 0); |
|
91 |
|
92 // If only disabling then we're done |
|
93 if (aTimeoutInSeconds > 0) |
|
94 { |
|
95 // Set the WTD period to something very near the required number |
|
96 // of seconds (this assumes a 66.666MHz clock) |
|
97 AsspRegister::Write32(KHwWatchdog_WDTSET, (aTimeoutInSeconds*63)<<20); |
|
98 AsspRegister::Write32(KHwWatchdog_WDTTIM, 0); |
|
99 |
|
100 // Enable eWDT - start counting |
|
101 AsspRegister::Write32(KHwWatchdog_WDTCNT, 1); |
|
102 |
|
103 // Pat the Dog now to give us the full period to respond with the timer |
|
104 AsspRegister::Write32(KHwWatchdog_WDTINT, 1); |
|
105 |
|
106 // We have to decide how often to pat the dog, in seconds. |
|
107 // The board will flag a warning after aTimeoutInSeconds, and reset after a further aTimeoutInSeconds. |
|
108 // So we have to fire the watchdog at least every aTimeoutInSeconds to prevent the warning |
|
109 // I've decided that we'll fire 500ms before the alarm to be sure we've patted the dog in time |
|
110 __KTRACE_OPT(KHARDWARE, Kern::Printf("TNaviEngine::SetWatchdogTimer kicking off a timer...")); |
|
111 //Kern::Printf("TNaviEngine::SetWatchdogTimer kicking off a timer..."); |
|
112 |
|
113 iWatchdogTimerPeriodMs = ((aTimeoutInSeconds * 1000) - 500); |
|
114 iWatchdogTimer.OneShot(NKern::TimerTicks(iWatchdogTimerPeriodMs)); |
|
115 } |
|
116 } |
|
117 |
|
118 |
|
119 DECLARE_STANDARD_EXTENSION() |
|
120 { |
|
121 __KTRACE_OPT(KEXTENSION,Kern::Printf("Watchdog: Starting timer service")); |
|
122 //Kern::Printf("Watchdog: Starting timer service"); |
|
123 |
|
124 // create the watchdog handler |
|
125 TInt r=KErrNoMemory; |
|
126 TNaviEngineWatchdog* pH=new TNaviEngineWatchdog; |
|
127 if (pH) |
|
128 { |
|
129 r=pH->Create(); |
|
130 } |
|
131 |
|
132 __KTRACE_OPT(KEXTENSION,Kern::Printf("Watchdog: Returns %d",r)); |
|
133 //Kern::Printf("Watchdog: Returns %d",r); |
|
134 return r; |
|
135 } |
|
136 |