author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 31 Aug 2010 16:34:26 +0300 | |
branch | RCL_3 |
changeset 43 | c1f20ce4abcf |
parent 0 | a41df078684a |
child 44 | 3e88ff8f41d5 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 1994-2009 Nokia Corporation and/or its subsidiary(-ies). |
2 |
// All rights reserved. |
|
3 |
// This component and the accompanying materials are made available |
|
4 |
// under the terms of the License "Eclipse Public License v1.0" |
|
5 |
// which accompanies this distribution, and is available |
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 |
// |
|
8 |
// Initial Contributors: |
|
9 |
// Nokia Corporation - initial contribution. |
|
10 |
// |
|
11 |
// Contributors: |
|
12 |
// |
|
13 |
// Description: |
|
14 |
// template\template_variant\specific\variant.cpp |
|
15 |
// |
|
16 |
// |
|
17 |
||
18 |
#include "variant.h" |
|
19 |
#include "mconf.h" |
|
20 |
#include <videodriver.h> |
|
21 |
#include <drivers/xyin.h> |
|
22 |
#include "template_power.h" |
|
23 |
||
24 |
//These constants define Custom Restart Reasons in SuperPage::iHwStartupReason |
|
25 |
const TUint KHtCustomRestartMax = 0xff; |
|
26 |
const TUint KHtCustomRestartShift = 8; |
|
27 |
const TUint KHtCustomRestartMask = KHtCustomRestartMax << KHtCustomRestartShift; |
|
28 |
||
29 |
const TUint KHtRestartStartupModesMax = 0xf; // Variable, platform dependant |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
30 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
31 |
#undef USE_MODE_SHIFT_MASK |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
32 |
#ifdef USE_MODE_SHIFT_MASK |
0 | 33 |
const TUint KHtRestartStartupModesShift = 16; // Variable, platform dependant |
34 |
const TUint KHtRestartStartupModesMask = KHtRestartStartupModesMax << KHtRestartStartupModesShift; |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
35 |
#endif |
0 | 36 |
|
37 |
void TemplateVariantFault(TInt aLine) |
|
38 |
{ |
|
39 |
Kern::Fault("TemplateVariant",aLine); |
|
40 |
} |
|
41 |
||
42 |
#define V_FAULT() TemplateVariantFault(__LINE__) |
|
43 |
||
44 |
// Debug output |
|
45 |
#define XON 17 |
|
46 |
#define XOFF 19 |
|
47 |
#define DEBUG_XON_XOFF 0 // Non-zero if we want XON-XOFF handshaking |
|
48 |
||
49 |
GLDEF_D Template TheVariant; |
|
50 |
TUint32 Variant::iBaseAddress=0; |
|
51 |
||
52 |
TUint32 Template::HandlerData[3]; |
|
53 |
SInterruptHandler Template::Handlers[ENumXInts]; |
|
54 |
||
55 |
extern void XIntDispatch(TAny*); |
|
56 |
||
57 |
EXPORT_C Asic* VariantInitialise() |
|
58 |
{ |
|
59 |
return &TheVariant; |
|
60 |
} |
|
61 |
||
62 |
Template::Template() |
|
63 |
{ |
|
64 |
iDebugInitialised=EFalse; |
|
65 |
} |
|
66 |
||
67 |
// |
|
68 |
// TO DO: (optional) |
|
69 |
// |
|
70 |
// Specify the RAM zone configuration. |
|
71 |
// |
|
72 |
// The lowest addressed zone must have the highest preference as the bootstrap |
|
73 |
// will always allocate from the lowest address up. Once the kernel has initialised |
|
74 |
// then the zone preferences will decide from which RAM zone memory is allocated. |
|
75 |
// |
|
76 |
// const TUint KVariantRamZoneCount = ?; |
|
77 |
// static const SRamZone KRamZoneConfig[KVariantRamZoneCount+1] = |
|
78 |
// iBase iSize iID iPref iFlags |
|
79 |
// { |
|
80 |
// __SRAM_ZONE(0x????????, 0x???????, ?, ?, ?), |
|
81 |
// ... |
|
82 |
// __SRAM_ZONE(0x????????, 0x???????, ?, ?, ?), |
|
83 |
// __SRAM_ZONE_END, // end of zone list |
|
84 |
// }; |
|
85 |
// |
|
86 |
||
87 |
TInt Template::RamZoneCallback(TRamZoneOp aOp, TAny* aId, const TAny* aMasks) |
|
88 |
{ |
|
89 |
// |
|
90 |
// TO DO: (optional) |
|
91 |
// |
|
92 |
// Handle RAM zone operations requested by the kernel. |
|
93 |
// |
|
94 |
return TheVariant.DoRamZoneCallback(aOp, (TUint)aId, (const TUint*)aMasks); |
|
95 |
} |
|
96 |
||
97 |
||
98 |
TInt Template::DoRamZoneCallback(TRamZoneOp aOp, TUint aId, const TUint* aMasks) |
|
99 |
{ |
|
100 |
// |
|
101 |
// TO DO: (optional) |
|
102 |
// |
|
103 |
// Handle RAM zone operations requested by the kernel. |
|
104 |
// |
|
105 |
// Three types of operation need to be supported: |
|
106 |
// ERamZoneOp_Init: Update power state of the RAM zones after the |
|
107 |
// kernel has initialised. |
|
108 |
// ERamZoneOp_PowerUp: A RAM zone changing from used to empty. |
|
109 |
// ERamZoneOp_PowerDown: A RAM zone changing from empty to used. |
|
110 |
// |
|
111 |
||
112 |
switch (aOp) |
|
113 |
{ |
|
114 |
case ERamZoneOp_Init: |
|
115 |
break; |
|
116 |
case ERamZoneOp_PowerUp: |
|
117 |
break; |
|
118 |
case ERamZoneOp_PowerDown: |
|
119 |
break; |
|
120 |
default: |
|
121 |
return KErrNotSupported; |
|
122 |
} |
|
123 |
return KErrNone; |
|
124 |
} |
|
125 |
||
126 |
||
127 |
void Template::Init1() |
|
128 |
{ |
|
129 |
__KTRACE_OPT(KBOOT,Kern::Printf("Template::Init1()")); |
|
130 |
||
131 |
// |
|
132 |
// TO DO: (mandatory) |
|
133 |
// |
|
134 |
// Configure Memory controller and Memrory Bus parameters (in addition to what was done in the Bootstrap) |
|
135 |
// |
|
136 |
__KTRACE_OPT(KBOOT,Kern::Printf("Memory Configuration done")); |
|
137 |
||
138 |
// |
|
139 |
// TO DO: (optional) |
|
140 |
// |
|
141 |
// Inform the kernel of the RAM zone configuration via Epoc::SetRamZoneConfig(). |
|
142 |
// For devices that wish to reduce power consumption of the RAM IC(s) the callback functions |
|
143 |
// RamZoneCallback() and DoRamZoneCallback() will need to be implemented and passed |
|
144 |
// to Epoc::SetRamZoneConfig() as the parameter aCallback. |
|
145 |
// The kernel will assume that all RAM ICs are fully intialised and ready for use from boot. |
|
146 |
// |
|
147 |
||
148 |
// |
|
149 |
// TO DO: (optional) |
|
150 |
// |
|
151 |
// Initialise other critical hardware functions such as I/O interfaces, etc, not done by Bootstrap |
|
152 |
// |
|
153 |
// if CPU is Sleep-capable, and requires some preparation to be put in that state (code provided in Bootstrap), |
|
154 |
// the address of the idle code is writen at this location by the Bootstrap |
|
155 |
// e.g. |
|
156 |
// iIdleFunction=*(TLinAddr*)((TUint8*)&Kern::SuperPage()+0x1000); |
|
157 |
// |
|
158 |
TemplateAssp::Init1(); |
|
159 |
} |
|
160 |
||
161 |
void Template::Init3() |
|
162 |
{ |
|
163 |
__KTRACE_OPT(KBOOT,Kern::Printf("Template::Init3()")); |
|
164 |
||
165 |
TemplateAssp::Init3(); |
|
166 |
||
167 |
Variant::Init3(); |
|
168 |
// |
|
169 |
// TO DO: (optional) |
|
170 |
// |
|
171 |
// Initialise other accessor classes, if required |
|
172 |
// |
|
173 |
||
174 |
InitInterrupts(); |
|
175 |
} |
|
176 |
||
177 |
void Variant::Init3() |
|
178 |
// |
|
179 |
// Phase 3 initialisation |
|
180 |
// |
|
181 |
{ |
|
182 |
__KTRACE_OPT(KHARDWARE, Kern::Printf(">Variant::Init3")); |
|
183 |
||
184 |
// |
|
185 |
// TO DO: (optional) |
|
186 |
// |
|
187 |
// Initialise any Variant class data members here, map in Variant and external hardware addresses |
|
188 |
// |
|
189 |
DPlatChunkHw* pC=NULL; |
|
190 |
TInt r=DPlatChunkHw::New(pC,KHwVariantPhysBase,0x2000,EMapAttrSupRw|EMapAttrFullyBlocking); |
|
191 |
__ASSERT_ALWAYS(r==KErrNone,V_FAULT()); |
|
192 |
iBaseAddress=pC->LinearAddress(); |
|
193 |
} |
|
194 |
||
195 |
EXPORT_C TUint Variant::BaseLinAddress() |
|
196 |
{ |
|
197 |
return((TUint)iBaseAddress); |
|
198 |
} |
|
199 |
||
200 |
EXPORT_C void Variant::MarkDebugPortOff() |
|
201 |
{ |
|
202 |
TheVariant.iDebugInitialised=EFalse; |
|
203 |
} |
|
204 |
||
205 |
EXPORT_C void Variant::UartInit() |
|
206 |
{ |
|
207 |
NKern::Lock(); |
|
208 |
if (!TheVariant.iDebugInitialised) |
|
209 |
{ |
|
210 |
// |
|
211 |
// TO DO: (mandatory) |
|
212 |
// |
|
213 |
// Reset and initialise the UART used to output debug strings |
|
214 |
// |
|
215 |
TheVariant.iDebugInitialised=ETrue; |
|
216 |
} |
|
217 |
NKern::Unlock(); |
|
218 |
} |
|
219 |
||
220 |
void Template::DebugInit() |
|
221 |
{ |
|
222 |
// |
|
223 |
// TO DO: (mandatory) |
|
224 |
// |
|
225 |
// Initialise the UART used for outputting Debug Strings (no Interrupts), as in the following EXAMPLE ONLY: |
|
226 |
// |
|
227 |
Variant::UartInit(); |
|
228 |
TTemplate::BootWaitMilliSeconds(10); // wait loop to ensure that the port is fully initialised and output buffer empty |
|
229 |
} |
|
230 |
||
231 |
void Template::DebugOutput(TUint aLetter) |
|
232 |
// |
|
233 |
// Output a character to the debug port |
|
234 |
// |
|
235 |
{ |
|
236 |
if (!iDebugInitialised) |
|
237 |
{ |
|
238 |
DebugInit(); |
|
239 |
} |
|
240 |
// |
|
241 |
// TO DO: (mandatory) |
|
242 |
// |
|
243 |
// Write the character aLetter to the UART output register and wait until sent (do NOT use interrupts!) |
|
244 |
// |
|
245 |
} |
|
246 |
||
247 |
void Template::Idle() |
|
248 |
// |
|
249 |
// The NULL thread idle loop |
|
250 |
// |
|
251 |
{ |
|
252 |
// Idle the CPU, suppressing the system tick if possible |
|
253 |
||
254 |
// |
|
255 |
// TO DO: (optional) |
|
256 |
// |
|
257 |
// Idle Tick supression: |
|
258 |
// 1- obtain the number of idle Ticks before the next NTimer expiration (NTimerQ::IdleTime()) |
|
259 |
// 2- if the number of Ticks is large enough (criteria to be defined) reset the Hardware Timer |
|
260 |
// to only interrupt again when the corresponding time has expired. |
|
261 |
// 2.1- the calculation of the new value to program the Hardware Timer with should take in |
|
262 |
// consideration the rounding value (NTimerQ::iRounding) |
|
263 |
// 3- call the low level Sleep function (e'g. Bootstrap: address in iIdleFunction) |
|
264 |
// 4- on coming back from Idle need to read the Hardware Timer and determine if woken up due to |
|
265 |
// timer expiration (system time for new match<=current system time<system time for new match-tick period) |
|
266 |
// or some other Interrupt. |
|
267 |
// 4.1- if timer expiration, adjust System Time by adding the number of Ticks suppressed to NTimerQ::iMsCount |
|
268 |
// 4.2- if other interrupt, calculate the number of Ticks skipped until woken up and adjust the System Time as |
|
269 |
// above |
|
270 |
// |
|
271 |
// Support for different Sleep Modes: |
|
272 |
// Often the Sleep mode a platform can go to depends on how many resources such as clocks/voltages can be |
|
273 |
// turned Off or lowered to a suitable level. If different Sleep modes are supported this code may need |
|
274 |
// to be able to find out what power resources are On or Off or used to what level. This could be achieved by |
|
275 |
// enquiring the Resource Manager (see \template_variant\inc\template_power.h). |
|
276 |
// Then a decision could be made to what Sleep level we go to. |
|
277 |
// |
|
278 |
// Example calls: |
|
279 |
// Obtain the number of Idle Ticks before the next NTimer expiration |
|
280 |
// TInt aTicksLeft = NTimerQ::IdleTime(); |
|
281 |
// ... |
|
282 |
// Find out the deepest Sleep mode available for current resource usage and sleeping time |
|
283 |
// TemplateResourceManager* aManager = TTemplatePowerController::ResourceManager(); |
|
284 |
// TemplateResourceManager::TSleepModes aMode = aManager -> MapSleepMode(aTicksLeft*MsTickPeriod()); |
|
285 |
// ... |
|
286 |
// Find out the state of some particular resources |
|
287 |
// TBool aResourceState = aManager -> GetResourceState(TemplateResourceManager::AsynchBinResourceUsedByZOnly); |
|
288 |
// TUint aResourceLevel = aManager -> GetResourceLevel(TemplateResourceManager::SynchMlResourceUsedByXOnly); |
|
289 |
// ... |
|
290 |
} |
|
291 |
||
292 |
TInt Template::VariantHal(TInt aFunction, TAny* a1, TAny* a2) |
|
293 |
{ |
|
294 |
TInt r=KErrNone; |
|
295 |
switch(aFunction) |
|
296 |
{ |
|
297 |
case EVariantHalVariantInfo: |
|
298 |
{ |
|
299 |
TVariantInfoV01Buf infoBuf; |
|
300 |
TVariantInfoV01& info=infoBuf(); |
|
301 |
info.iRomVersion=Epoc::RomHeader().iVersion; |
|
302 |
||
303 |
// |
|
304 |
// TO DO: (mandatory) |
|
305 |
// |
|
306 |
// Fill in the TVariantInfoV01 info structure |
|
307 |
// info.iMachineUniqueId=; |
|
308 |
// info.iLedCapabilities=; |
|
309 |
// info.iProcessorClockInKHz=; |
|
310 |
// info.iSpeedFactor=; |
|
311 |
// |
|
312 |
Kern::InfoCopy(*(TDes8*)a1,infoBuf); |
|
313 |
break; |
|
314 |
} |
|
315 |
case EVariantHalDebugPortSet: |
|
316 |
{ |
|
317 |
// |
|
318 |
// TO DO: (mandatory) |
|
319 |
// |
|
320 |
// Write the iDebugPort field of the SuperPage, as in the following EXAMPLE ONLY: |
|
321 |
// |
|
322 |
TUint32 thePort = (TUint32)a1; |
|
323 |
switch(thePort) |
|
324 |
{ |
|
325 |
case 1: |
|
326 |
case 2: |
|
327 |
case 3: |
|
328 |
TheVariant.iDebugInitialised=EFalse; |
|
329 |
case (TUint32)KNullDebugPort: |
|
330 |
Kern::SuperPage().iDebugPort = thePort; |
|
331 |
break; |
|
332 |
default: |
|
333 |
r=KErrNotSupported; |
|
334 |
} |
|
335 |
break; |
|
336 |
} |
|
337 |
case EVariantHalDebugPortGet: |
|
338 |
{ |
|
339 |
// |
|
340 |
// TO DO: (mandatory) |
|
341 |
// |
|
342 |
// Obtain the Linear address of the Uart used for outputting Debug strings as in the following EXAMPLE ONLY: |
|
343 |
// |
|
344 |
||
345 |
TUint32 thePort = TTemplate::DebugPortAddr(); |
|
346 |
kumemput32(a1, &thePort, sizeof(TUint32)); |
|
347 |
break; |
|
348 |
} |
|
349 |
case EVariantHalSwitches: |
|
350 |
{ |
|
351 |
// |
|
352 |
// TO DO: (optional) |
|
353 |
// |
|
354 |
// Read the state of any switches, as in the following EXAMPLE ONLY: |
|
355 |
// |
|
356 |
TUint32 x = Variant::Switches(); |
|
357 |
kumemput32(a1, &x, sizeof(x)); |
|
358 |
break; |
|
359 |
} |
|
360 |
case EVariantHalLedMaskSet: |
|
361 |
{ |
|
362 |
// |
|
363 |
// TO DO: (optional) |
|
364 |
// |
|
365 |
// Set the state of any on-board LEDs, e.g: |
|
366 |
// TUint32 aLedMask=(TUint32)a1; |
|
367 |
// Variant::ModifyLedState(~aLedMask,aLedMask); |
|
368 |
// |
|
369 |
break; |
|
370 |
} |
|
371 |
case EVariantHalLedMaskGet: |
|
372 |
{ |
|
373 |
// |
|
374 |
// TO DO: (optional) |
|
375 |
// |
|
376 |
// Read the state of any on-board LEDs, e.g: |
|
377 |
// TUint32 x = Variant::LedState(); |
|
378 |
// kumemput32(a1, &x, sizeof(x)); |
|
379 |
// |
|
380 |
break; |
|
381 |
} |
|
382 |
||
383 |
case EVariantHalCustomRestartReason: |
|
384 |
{ |
|
385 |
//Restart reason is stored in super page |
|
386 |
TInt x = (Kern::SuperPage().iHwStartupReason & KHtCustomRestartMask) >> KHtCustomRestartShift ; |
|
387 |
kumemput32(a1, &x, sizeof(TInt)); |
|
388 |
break; |
|
389 |
} |
|
390 |
||
391 |
case EVariantHalCustomRestart: |
|
392 |
{ |
|
393 |
if(!Kern::CurrentThreadHasCapability(ECapabilityPowerMgmt,__PLATSEC_DIAGNOSTIC_STRING("Checked by Hal function EVariantHalCustomRestart"))) |
|
394 |
return KErrPermissionDenied; |
|
395 |
if ((TUint)a1 > KHtCustomRestartMax) |
|
396 |
return KErrArgument; |
|
397 |
Kern::Restart((TInt)a1 << KHtCustomRestartShift); |
|
398 |
} |
|
399 |
break; |
|
400 |
||
401 |
case EVariantHalCaseState: |
|
402 |
{ |
|
403 |
// |
|
404 |
// TO DO: (optional) |
|
405 |
// |
|
406 |
// Read the state of the case, e.g: |
|
407 |
// TUint32 x = Variant::CaseState(); |
|
408 |
// kumemput32(a1, &x, sizeof(x)); |
|
409 |
// |
|
410 |
break; |
|
411 |
} |
|
412 |
||
413 |
case EVariantHalPersistStartupMode: |
|
414 |
{ |
|
415 |
if (!Kern::CurrentThreadHasCapability(ECapabilityWriteDeviceData,__PLATSEC_DIAGNOSTIC_STRING("Checked by Hal function EDisplayHalSetBacklightOn"))) |
|
416 |
return KErrPermissionDenied; |
|
417 |
||
418 |
if ((TUint)a1 > KHtRestartStartupModesMax ) // Restart startup mode max value |
|
419 |
return KErrArgument; |
|
420 |
// |
|
421 |
// TO DO: (optional) |
|
422 |
// |
|
423 |
// Store the restart reason locally, |
|
424 |
// which will eventually be picked up by |
|
425 |
// the power controller, e.g: |
|
426 |
// iCustomRestartReason = (TUint)a1; |
|
427 |
break; |
|
428 |
} |
|
429 |
||
430 |
||
431 |
case EVariantHalGetPersistedStartupMode: |
|
432 |
{ |
|
433 |
// |
|
434 |
// TO DO: (optional) |
|
435 |
// |
|
436 |
// Read the restart startup mode, e.g: |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
437 |
#undef USE_MODE_SHIFT_MASK |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
438 |
#ifdef USE_MODE_SHIFT_MASK |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
439 |
TInt startup = (Kern::SuperPage().iHwStartupReason & KHtRestartStartupModesMask) >> KHtRestartStartupModesShift; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
440 |
kumemput32(a1, &startup, sizeof(TInt)); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
441 |
#endif |
0 | 442 |
break; |
443 |
} |
|
444 |
||
445 |
case EVariantHalGetMaximumCustomRestartReasons: |
|
446 |
{ |
|
447 |
// |
|
448 |
// TO DO: (optional) |
|
449 |
// |
|
450 |
// Read the maximum custom restart reason, e.g: |
|
451 |
// kumemput32(a1, &KHtCustomRestartMax, sizeof(TUint)); |
|
452 |
break; |
|
453 |
} |
|
454 |
||
455 |
||
456 |
case EVariantHalGetMaximumRestartStartupModes: |
|
457 |
{ |
|
458 |
// |
|
459 |
// TO DO: (optional) |
|
460 |
// |
|
461 |
// Read the maximum restart startup mode, e.g: |
|
462 |
// kumemput32(a1, &KHtRestartStartupModesMax, sizeof(TUint)); |
|
463 |
break; |
|
464 |
} |
|
465 |
||
466 |
case EVariantHalProfilingDefaultInterruptBase: |
|
467 |
{ |
|
468 |
// |
|
469 |
// TO DO: (optional) |
|
470 |
// |
|
471 |
//Set the default interrupt number for the sampling profiler. |
|
472 |
//TInt interruptNumber = KIntCpuProfilingDefaultInterruptBase; |
|
473 |
//kumemput(a1,&interruptNumber,sizeof(interruptNumber)); |
|
474 |
break; |
|
475 |
} |
|
476 |
||
477 |
default: |
|
478 |
r=KErrNotSupported; |
|
479 |
break; |
|
480 |
} |
|
481 |
return r; |
|
482 |
} |
|
483 |
||
484 |
TPtr8 Template::MachineConfiguration() |
|
485 |
{ |
|
486 |
return TPtr8((TUint8*)&Kern::MachineConfig(),sizeof(TActualMachineConfig),sizeof(TActualMachineConfig)); |
|
487 |
} |
|
488 |
||
489 |
TInt Template::VideoRamSize() |
|
490 |
{ |
|
491 |
// |
|
492 |
// TO DO: (mandatory) |
|
493 |
// |
|
494 |
// Return the size of the area of RAM used to store the Video Buffer, as in the following EXAMPLE ONLY: |
|
495 |
// |
|
496 |
return 0x28000; |
|
497 |
} |
|
498 |
||
499 |
EXPORT_C void Variant::PowerReset() |
|
500 |
{ |
|
501 |
// |
|
502 |
// TO DO: (optional) |
|
503 |
// |
|
504 |
// Reset all power supplies |
|
505 |
// |
|
506 |
} |
|
507 |
||
508 |
EXPORT_C TUint Variant::Switches() |
|
509 |
{ |
|
510 |
// |
|
511 |
// TO DO: (optional) |
|
512 |
// |
|
513 |
// Read the state of on-board switches |
|
514 |
// |
|
515 |
return 0; // EXAMPLE ONLY |
|
516 |
} |
|
517 |
||
518 |
/****************************************************************************** |
|
519 |
* Interrupt handling/dispatch |
|
520 |
******************************************************************************/ |
|
521 |
TInt Template::InterruptBind(TInt anId, TIsr anIsr, TAny* aPtr) |
|
522 |
{ |
|
523 |
TUint id=anId&0x7fffffff; // mask off second-level interrupt mask |
|
524 |
if (id>=ENumXInts) |
|
525 |
return KErrArgument; |
|
526 |
TInt r=KErrNone; |
|
527 |
SInterruptHandler& h=Handlers[id]; |
|
528 |
TInt irq=NKern::DisableAllInterrupts(); |
|
529 |
if (h.iIsr!=Spurious) |
|
530 |
r=KErrInUse; |
|
531 |
else |
|
532 |
{ |
|
533 |
h.iIsr=anIsr; |
|
534 |
h.iPtr=aPtr; |
|
535 |
} |
|
536 |
NKern::RestoreInterrupts(irq); |
|
537 |
return r; |
|
538 |
} |
|
539 |
||
540 |
TInt Template::InterruptUnbind(TInt anId) |
|
541 |
{ |
|
542 |
TUint id=anId&0x7fffffff; // mask off second-level interrupt mask |
|
543 |
if (id>=ENumXInts) |
|
544 |
return KErrArgument; |
|
545 |
InterruptDisable(anId); |
|
546 |
InterruptClear(anId); |
|
547 |
TInt r=KErrNone; |
|
548 |
SInterruptHandler& h=Handlers[id]; |
|
549 |
TInt irq=NKern::DisableAllInterrupts(); |
|
550 |
if (h.iIsr!=Spurious) |
|
551 |
{ |
|
552 |
h.iIsr=Spurious; |
|
553 |
h.iPtr=(TAny*)id; |
|
554 |
} |
|
555 |
NKern::RestoreInterrupts(irq); |
|
556 |
return r; |
|
557 |
} |
|
558 |
||
559 |
TInt Template::InterruptEnable(TInt anId) |
|
560 |
{ |
|
561 |
TUint id=anId&0x7fffffff; // mask off second-level interrupt mask |
|
562 |
if (id>=ENumXInts) |
|
563 |
return KErrArgument; |
|
564 |
TInt r=KErrNone; |
|
565 |
SInterruptHandler& h=Handlers[id]; |
|
566 |
TInt irq=NKern::DisableAllInterrupts(); |
|
567 |
if (h.iIsr==Spurious) |
|
568 |
r=KErrNotReady; |
|
569 |
else |
|
570 |
{ |
|
571 |
// |
|
572 |
// TO DO: (mandatory) |
|
573 |
// |
|
574 |
// Enable the hardware interrupt in the source, e.g. |
|
575 |
// Variant::EnableInt(anId); |
|
576 |
// |
|
577 |
} |
|
578 |
NKern::RestoreInterrupts(irq); |
|
579 |
return r; |
|
580 |
} |
|
581 |
||
582 |
TInt Template::InterruptDisable(TInt anId) |
|
583 |
{ |
|
584 |
TUint id=anId&0x7fffffff; // mask off second-level interrupt mask |
|
585 |
if (id>=ENumXInts) |
|
586 |
return KErrArgument; |
|
587 |
// |
|
588 |
// TO DO: (mandatory) |
|
589 |
// |
|
590 |
// Disable the hardware interrupt in the source, e.g. |
|
591 |
// Variant::DisableInt(anId); |
|
592 |
// |
|
593 |
return KErrNone; |
|
594 |
} |
|
595 |
||
596 |
TInt Template::InterruptClear(TInt anId) |
|
597 |
{ |
|
598 |
TUint id=anId&0x7fffffff; |
|
599 |
if (id>=ENumXInts) |
|
600 |
return KErrArgument; |
|
601 |
// |
|
602 |
// TO DO: (mandatory) |
|
603 |
// |
|
604 |
// Clear the hardware interrupt in the source, e.g. |
|
605 |
// Variant::ClearInt(anId); |
|
606 |
// |
|
607 |
return KErrNone; |
|
608 |
} |
|
609 |
||
610 |
void Template::InitInterrupts() |
|
611 |
{ |
|
612 |
// Set up the variant interrupt dispatcher |
|
613 |
||
614 |
// all interrupts initially unbound |
|
615 |
TInt i; |
|
616 |
for (i=0; i<(TInt)ENumXInts; i++) |
|
617 |
{ |
|
618 |
Handlers[i].iPtr=(TAny*)i; |
|
619 |
Handlers[i].iIsr=Spurious; |
|
620 |
} |
|
621 |
||
622 |
// Set up data for 2nd level interrupt dispatcher |
|
623 |
HandlerData[0]=Variant::BaseLinAddress(); // Linear Base address of 2nd level Int Controller |
|
624 |
HandlerData[1]=(TUint32)&Handlers[0]; // Pointer to handler array |
|
625 |
HandlerData[2]=0; // |
|
626 |
||
627 |
// |
|
628 |
// TO DO: (mandatory) |
|
629 |
// |
|
630 |
// set up ASSP expansion interrupt to generate interrupts whenever a 2nd level interrupt occurrs |
|
631 |
// |
|
632 |
||
633 |
// bind Template ASSP expansion interrupt input to our interrupt dispatcher |
|
634 |
TInt r=Interrupt::Bind(KIntIdExpansion, XIntDispatch, HandlerData); |
|
635 |
__ASSERT_ALWAYS(r==KErrNone,V_FAULT()); |
|
636 |
Interrupt::Enable(KIntIdExpansion); // enable expansion interrupt |
|
637 |
} |
|
638 |
||
639 |
void Template::Spurious(TAny* aId) |
|
640 |
{ |
|
641 |
TUint32 id=((TUint32)aId)|0x80000000u; |
|
642 |
Kern::Fault("SpuriousInt",id); |
|
643 |
} |
|
644 |
||
645 |
||
646 |
// USB Client controller |
|
647 |
||
648 |
TBool Template::UsbClientConnectorDetectable() |
|
649 |
{ |
|
650 |
__KTRACE_OPT(KHARDWARE, Kern::Printf("Template::UsbClientConnectorDetectable")); |
|
651 |
||
652 |
// TO DO: The return value should reflect the actual situation. |
|
653 |
return ETrue; |
|
654 |
} |
|
655 |
||
656 |
||
657 |
TBool Template::UsbClientConnectorInserted() |
|
658 |
{ |
|
659 |
__KTRACE_OPT(KHARDWARE, Kern::Printf("Template::UsbClientConnectorInserted")); |
|
660 |
||
661 |
// TO DO: Query cable status here. The return value should reflect the actual current state. |
|
662 |
return ETrue; |
|
663 |
} |
|
664 |
||
665 |
||
666 |
TInt Template::RegisterUsbClientConnectorCallback(TInt (*aCallback)(TAny*), TAny* aPtr) |
|
667 |
{ |
|
668 |
__KTRACE_OPT(KHARDWARE, Kern::Printf("Template::RegisterUsbClientConnectorCallback")); |
|
669 |
||
670 |
iUsbClientConnectorCallback = aCallback; |
|
671 |
iUsbClientConnectorCallbackArg = aPtr; |
|
672 |
||
673 |
// TO DO: Register and enable the interrupt(s) for detecting USB cable insertion/removal here. |
|
674 |
// (Register UsbClientConnectorIsr.) |
|
675 |
||
676 |
// TO DO: The return value should reflect the actual situation. |
|
677 |
return KErrNone; |
|
678 |
} |
|
679 |
||
680 |
||
681 |
void Template::UnregisterUsbClientConnectorCallback() |
|
682 |
{ |
|
683 |
__KTRACE_OPT(KHARDWARE, Kern::Printf("Template::UnregisterUsbClientConnectorCallback")); |
|
684 |
||
685 |
// TO DO: Disable and unbind the interrupt(s) for detecting USB cable insertion/removal here. |
|
686 |
||
687 |
iUsbClientConnectorCallback = NULL; |
|
688 |
iUsbClientConnectorCallbackArg = NULL; |
|
689 |
} |
|
690 |
||
691 |
||
692 |
TBool Template::UsbSoftwareConnectable() |
|
693 |
{ |
|
694 |
__KTRACE_OPT(KHARDWARE, Kern::Printf("Template::UsbSoftwareConnectable")); |
|
695 |
||
696 |
// TO DO: The return value should reflect the actual situation. |
|
697 |
return ETrue; |
|
698 |
} |
|
699 |
||
700 |
||
701 |
TInt Template::UsbConnect() |
|
702 |
{ |
|
703 |
__KTRACE_OPT(KHARDWARE, Kern::Printf("Template::UsbConnect")); |
|
704 |
||
705 |
// TO DO: Do here whatever is necessary for the UDC to appear on the bus (and thus to the host). |
|
706 |
||
707 |
return KErrNone; |
|
708 |
} |
|
709 |
||
710 |
||
711 |
TInt Template::UsbDisconnect() |
|
712 |
{ |
|
713 |
__KTRACE_OPT(KHARDWARE, Kern::Printf("Template::UsbDisconnect")); |
|
714 |
||
715 |
// TO DO: Do here whatever is necessary for the UDC to appear disconnected from the bus (and thus from the |
|
716 |
// host). |
|
717 |
||
718 |
return KErrNone; |
|
719 |
} |
|
720 |
||
721 |
||
722 |
void Template::UsbClientConnectorIsr(TAny *aPtr) |
|
723 |
// |
|
724 |
// Services the USB cable interrupt. |
|
725 |
// |
|
726 |
{ |
|
727 |
__KTRACE_OPT(KHARDWARE, Kern::Printf("Template::UsbClientConnectorIsr()")); |
|
728 |
||
729 |
Template* tm = static_cast<Template*>(aPtr); |
|
730 |
||
731 |
// TO DO: Service interrupt here: determmine cause, clear condition flag (if applicable), etc. |
|
732 |
||
733 |
if (tm->UsbClientConnectorInserted()) |
|
734 |
{ |
|
735 |
__KTRACE_OPT(KHARDWARE, Kern::Printf(" > USB cable now inserted.")); |
|
736 |
} |
|
737 |
else |
|
738 |
{ |
|
739 |
__KTRACE_OPT(KHARDWARE, Kern::Printf(" > USB cable now removed.")); |
|
740 |
} |
|
741 |
||
742 |
// Important: Inform the USB stack. |
|
743 |
if (tm->iUsbClientConnectorCallback) |
|
744 |
{ |
|
745 |
(*tm->iUsbClientConnectorCallback)(tm->iUsbClientConnectorCallbackArg); |
|
746 |
} |
|
747 |
} |
|
748 |
||
749 |
||
750 |
//---eof |