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 |
// omap3530/beaglboard/src/variant.cpp
|
|
15 |
//
|
|
16 |
|
|
17 |
#include <kernel.h>
|
|
18 |
#include <beagle/variant.h>
|
|
19 |
#include <beagle/mconf.h>
|
|
20 |
#include <beagle/beagle_gpio.h>
|
|
21 |
#include <assp/omap3530_assp/omap3530_uart.h>
|
|
22 |
#include <assp/omap3530_assp/omap3530_gpio.h>
|
|
23 |
#include <assp/omap3530_shared/tps65950.h>
|
|
24 |
|
|
25 |
#define ENABLE_WFI
|
|
26 |
#define IDLE_TICK_SUPPRESSION
|
|
27 |
|
|
28 |
|
|
29 |
#ifdef IDLE_TICK_SUPPRESSION
|
|
30 |
#include <assp/omap3530_shared/omap3_mstick.h>
|
|
31 |
#endif
|
|
32 |
|
|
33 |
|
|
34 |
GLREF_C void ArmWaitForInterrupt();
|
|
35 |
|
|
36 |
|
|
37 |
//These constants define Custom Restart Reasons in SuperPage::iHwStartupReason
|
|
38 |
const TUint KHtCustomRestartMax = 0xff;
|
|
39 |
const TUint KHtCustomRestartShift = 8;
|
|
40 |
const TUint KHtCustomRestartMask = KHtCustomRestartMax << KHtCustomRestartShift;
|
|
41 |
|
|
42 |
//TODO: unncomment when referenced
|
|
43 |
const TUint KHtRestartStartupModesMax = 0xf; // Variable, platform dependant
|
|
44 |
//const TUint KHtRestartStartupModesShift = 16; // Variable, platform dependant
|
|
45 |
//const TUint KHtRestartStartupModesMask = KHtRestartStartupModesMax << KHtRestartStartupModesShift;
|
|
46 |
|
|
47 |
void BeagleVariantFault(TInt aLine)
|
|
48 |
{
|
|
49 |
Kern::Fault("BeagleVariant",aLine);
|
|
50 |
}
|
|
51 |
|
|
52 |
#define V_FAULT() BeagleVariantFault(__LINE__)
|
|
53 |
|
|
54 |
// Debug output
|
|
55 |
#define XON 17
|
|
56 |
#define XOFF 19
|
|
57 |
#define DEBUG_XON_XOFF 0 // Non-zero if we want XON-XOFF handshaking
|
|
58 |
|
|
59 |
GLDEF_D Beagle TheVariant;
|
|
60 |
TUint32 Variant::iBaseAddress=0;
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
66 |
EXPORT_C Asic* VariantInitialise()
|
|
67 |
{
|
|
68 |
return &TheVariant;
|
|
69 |
}
|
|
70 |
|
|
71 |
Beagle::Beagle()
|
|
72 |
{
|
|
73 |
iDebugInitialised=EFalse;
|
|
74 |
}
|
|
75 |
|
|
76 |
//
|
|
77 |
// TO DO: (optional)
|
|
78 |
//
|
|
79 |
// Specify the RAM zone configuration.
|
|
80 |
//
|
|
81 |
// The lowest addressed zone must have the highest preference as the bootstrap
|
|
82 |
// will always allocate from the lowest address up. Once the kernel has initialised
|
|
83 |
// then the zone preferences will decide from which RAM zone memory is allocated.
|
|
84 |
//
|
|
85 |
// const TUint KVariantRamZoneCount = ?;
|
|
86 |
// static const SRamZone KRamZoneConfig[KVariantRamZoneCount+1] =
|
|
87 |
// iBase iSize iID iPref iFlags
|
|
88 |
// {
|
|
89 |
// __SRAM_ZONE(0x????????, 0x???????, ?, ?, ?),
|
|
90 |
// ...
|
|
91 |
// __SRAM_ZONE(0x????????, 0x???????, ?, ?, ?),
|
|
92 |
// __SRAM_ZONE_END, // end of zone list
|
|
93 |
// };
|
|
94 |
//
|
|
95 |
|
|
96 |
TInt Beagle::RamZoneCallback(TRamZoneOp aOp, TAny* aId, const TAny* aMasks)
|
|
97 |
{
|
|
98 |
//
|
|
99 |
// TO DO: (optional)
|
|
100 |
//
|
|
101 |
// Handle RAM zone operations requested by the kernel.
|
|
102 |
//
|
|
103 |
return TheVariant.DoRamZoneCallback(aOp, (TUint)aId, (const TUint*)aMasks);
|
|
104 |
}
|
|
105 |
|
|
106 |
|
|
107 |
TInt Beagle::DoRamZoneCallback(TRamZoneOp aOp, TUint aId, const TUint* aMasks)
|
|
108 |
{
|
|
109 |
//
|
|
110 |
// TO DO: (optional)
|
|
111 |
//
|
|
112 |
// Handle RAM zone operations requested by the kernel.
|
|
113 |
//
|
|
114 |
// Three types of operation need to be supported:
|
|
115 |
// ERamZoneOp_Init: Update power state of the RAM zones after the
|
|
116 |
// kernel has initialised.
|
|
117 |
// ERamZoneOp_PowerUp: A RAM zone changing from used to empty.
|
|
118 |
// ERamZoneOp_PowerDown: A RAM zone changing from empty to used.
|
|
119 |
//
|
|
120 |
|
|
121 |
switch (aOp)
|
|
122 |
{
|
|
123 |
case ERamZoneOp_Init:
|
|
124 |
break;
|
|
125 |
case ERamZoneOp_PowerUp:
|
|
126 |
break;
|
|
127 |
case ERamZoneOp_PowerDown:
|
|
128 |
break;
|
|
129 |
default:
|
|
130 |
return KErrNotSupported;
|
|
131 |
}
|
|
132 |
return KErrNone;
|
|
133 |
}
|
|
134 |
|
|
135 |
TUint Beagle::SysClkFrequency() const
|
|
136 |
{
|
|
137 |
return 26000000;
|
|
138 |
}
|
|
139 |
|
|
140 |
TUint Beagle::SysClk32kFrequency() const
|
|
141 |
{
|
|
142 |
return 32768;
|
|
143 |
}
|
|
144 |
|
|
145 |
TUint Beagle::AltClkFrequency() const
|
|
146 |
{
|
|
147 |
// Doesn't appear to be connected on Beagle
|
|
148 |
return 0;
|
|
149 |
}
|
|
150 |
|
|
151 |
void Beagle::Init1()
|
|
152 |
{
|
|
153 |
__KTRACE_OPT(KBOOT,Kern::Printf("Beagle::Init1()"));
|
|
154 |
Omap3530Assp::Init1();
|
|
155 |
}
|
|
156 |
|
|
157 |
|
|
158 |
EXPORT_C TInt Variant::GetMsTickPeriod()
|
|
159 |
{
|
|
160 |
return TheVariant.MsTickPeriod();
|
|
161 |
|
|
162 |
}
|
|
163 |
|
|
164 |
void Beagle::Init3()
|
|
165 |
{
|
|
166 |
__KTRACE_OPT(KBOOT,Kern::Printf("Beagle::Init3()"));
|
|
167 |
|
|
168 |
Omap3530Assp::Init3();
|
|
169 |
|
|
170 |
Variant::Init3();
|
|
171 |
}
|
|
172 |
|
|
173 |
void Variant::Init3()
|
|
174 |
//
|
|
175 |
// Phase 3 initialisation
|
|
176 |
//
|
|
177 |
{
|
|
178 |
__KTRACE_OPT(KHARDWARE, Kern::Printf(">Variant::Init3"));
|
|
179 |
}
|
|
180 |
|
|
181 |
EXPORT_C TUint Variant::BaseLinAddress()
|
|
182 |
{
|
|
183 |
return((TUint)iBaseAddress);
|
|
184 |
}
|
|
185 |
|
|
186 |
EXPORT_C void Variant::MarkDebugPortOff()
|
|
187 |
{
|
|
188 |
TheVariant.iDebugInitialised=EFalse;
|
|
189 |
}
|
|
190 |
|
|
191 |
EXPORT_C void Variant::UartInit()
|
|
192 |
{
|
|
193 |
if (!TheVariant.iDebugInitialised)
|
|
194 |
{
|
|
195 |
const Omap3530Uart::TUartNumber portNumber( Omap3530Assp::DebugPortNumber() );
|
|
196 |
|
|
197 |
if( portNumber >= 0 )
|
|
198 |
{
|
|
199 |
Omap3530Uart::TUart uart( portNumber );
|
|
200 |
|
|
201 |
uart.Init();
|
|
202 |
uart.DefineMode( Omap3530Uart::TUart::EUart );
|
|
203 |
uart.SetBaud( Omap3530Uart::TUart::E115200 );
|
|
204 |
uart.SetDataFormat( Omap3530Uart::TUart::E8Data, Omap3530Uart::TUart::E1Stop, Omap3530Uart::TUart::ENone );
|
|
205 |
uart.Enable();
|
|
206 |
|
|
207 |
TheVariant.iDebugInitialised=ETrue;
|
|
208 |
}
|
|
209 |
}
|
|
210 |
}
|
|
211 |
|
|
212 |
void Beagle::DebugInit()
|
|
213 |
{
|
|
214 |
Variant::UartInit();
|
|
215 |
}
|
|
216 |
|
|
217 |
void Beagle::DebugOutput(TUint aLetter)
|
|
218 |
//
|
|
219 |
// Output a character to the debug port
|
|
220 |
//
|
|
221 |
{
|
|
222 |
const Omap3530Uart::TUartNumber portNumber( Omap3530Assp::DebugPortNumber() );
|
|
223 |
|
|
224 |
if( portNumber >= 0 )
|
|
225 |
{
|
|
226 |
if (!iDebugInitialised)
|
|
227 |
{
|
|
228 |
DebugInit();
|
|
229 |
}
|
|
230 |
Omap3530Uart::TUart uart( portNumber );
|
|
231 |
// If the FIFO is full we need to wait..
|
|
232 |
while( uart.TxFifoFull() );
|
|
233 |
uart.Write( aLetter );
|
|
234 |
}
|
|
235 |
}
|
|
236 |
|
|
237 |
void Beagle::Idle()
|
|
238 |
//
|
|
239 |
// The NULL thread idle loop
|
|
240 |
//
|
|
241 |
{
|
|
242 |
// Idle the CPU, suppressing the system tick if possible
|
|
243 |
|
|
244 |
//
|
|
245 |
// TO DO: (optional)
|
|
246 |
//
|
|
247 |
// Idle Tick supression:
|
|
248 |
// 1- obtain the number of idle Ticks before the next NTimer expiration (NTimerQ::IdleTime())
|
|
249 |
// 2- if the number of Ticks is large enough (criteria to be defined) reset the Hardware Timer
|
|
250 |
// to only interrupt again when the corresponding time has expired.
|
|
251 |
// 2.1- the calculation of the new value to program the Hardware Timer with should take in
|
|
252 |
// consideration the rounding value (NTimerQ::iRounding)
|
|
253 |
// 3- call the low level Sleep function (e'g. Bootstrap: address in iIdleFunction)
|
|
254 |
// 4- on coming back from Idle need to read the Hardware Timer and determine if woken up due to
|
|
255 |
// timer expiration (system time for new match<=current system time<system time for new match-tick period)
|
|
256 |
// or some other Interrupt.
|
|
257 |
// 4.1- if timer expiration, adjust System Time by adding the number of Ticks suppressed to NTimerQ::iMsCount
|
|
258 |
// 4.2- if other interrupt, calculate the number of Ticks skipped until woken up and adjust the System Time as
|
|
259 |
// above
|
|
260 |
//
|
|
261 |
// Support for different Sleep Modes:
|
|
262 |
// Often the Sleep mode a platform can go to depends on how many resources such as clocks/voltages can be
|
|
263 |
// turned Off or lowered to a suitable level. If different Sleep modes are supported this code may need
|
|
264 |
// to be able to find out what power resources are On or Off or used to what level. This could be achieved by
|
|
265 |
// enquiring the Resource Manager (see \beagle_variant\inc\beagle_power.h).
|
|
266 |
// Then a decision could be made to what Sleep level we go to.
|
|
267 |
//
|
|
268 |
// Example calls:
|
|
269 |
// Obtain the number of Idle Ticks before the next NTimer expiration
|
|
270 |
// TInt aTicksLeft = NTimerQ::IdleTime();
|
|
271 |
// ...
|
|
272 |
// Find out the deepest Sleep mode available for current resource usage and sleeping time
|
|
273 |
// TemplateResourceManager* aManager = TTemplatePowerController::ResourceManager();
|
|
274 |
// TemplateResourceManager::TSleepModes aMode = aManager -> MapSleepMode(aTicksLeft*MsTickPeriod());
|
|
275 |
// ...
|
|
276 |
// Find out the state of some particular resources
|
|
277 |
// TBool aResourceState = aManager -> GetResourceState(TemplateResourceManager::AsynchBinResourceUsedByZOnly);
|
|
278 |
// TUint aResourceLevel = aManager -> GetResourceLevel(TemplateResourceManager::SynchMlResourceUsedByXOnly);
|
|
279 |
// ...
|
|
280 |
|
|
281 |
#ifdef ENABLE_WFI
|
|
282 |
TInt irq = NKern::DisableAllInterrupts();
|
|
283 |
|
|
284 |
# ifdef IDLE_TICK_SUPPRESSION
|
|
285 |
TInt maxSleepTicks = NTimerQ::IdleTime();
|
|
286 |
TInt suppressedTicks = Omap3::MsTick::SuppressIdleTicks( maxSleepTicks );
|
|
287 |
# endif
|
|
288 |
|
|
289 |
ArmWaitForInterrupt();
|
|
290 |
|
|
291 |
|
|
292 |
# ifdef IDLE_TICK_SUPPRESSION
|
|
293 |
if( suppressedTicks > 0 )
|
|
294 |
{
|
|
295 |
suppressedTicks = Omap3::MsTick::EndIdleTickSuppression( suppressedTicks );
|
|
296 |
if( suppressedTicks > 0 )
|
|
297 |
{
|
|
298 |
NTimerQ::Advance( suppressedTicks );
|
|
299 |
}
|
|
300 |
}
|
|
301 |
# endif
|
|
302 |
|
|
303 |
NKern::RestoreInterrupts( irq );
|
|
304 |
#endif // ifdef ENABLE_WFI
|
|
305 |
}
|
|
306 |
|
|
307 |
TInt Beagle::VariantHal(TInt aFunction, TAny* a1, TAny* a2)
|
|
308 |
{
|
|
309 |
TInt r=KErrNone;
|
|
310 |
switch(aFunction)
|
|
311 |
{
|
|
312 |
case EVariantHalVariantInfo:
|
|
313 |
{
|
|
314 |
TVariantInfoV01Buf infoBuf;
|
|
315 |
TVariantInfoV01& info=infoBuf();
|
|
316 |
info.iRomVersion=Epoc::RomHeader().iVersion;
|
|
317 |
|
|
318 |
//
|
|
319 |
// TO DO: (mandatory)
|
|
320 |
//
|
|
321 |
// Fill in the TVariantInfoV01 info structure
|
|
322 |
// info.iMachineUniqueId=;
|
|
323 |
// info.iLedCapabilities=;
|
|
324 |
// info.iProcessorClockInKHz=;
|
|
325 |
// info.iSpeedFactor=;
|
|
326 |
//
|
|
327 |
Kern::InfoCopy(*(TDes8*)a1,infoBuf);
|
|
328 |
break;
|
|
329 |
}
|
|
330 |
case EVariantHalDebugPortSet:
|
|
331 |
{
|
|
332 |
//
|
|
333 |
// TO DO: (mandatory)
|
|
334 |
//
|
|
335 |
// Write the iDebugPort field of the SuperPage, as in the following EXAMPLE ONLY:
|
|
336 |
//
|
|
337 |
TUint32 thePort = (TUint32)a1;
|
|
338 |
switch(thePort)
|
|
339 |
{
|
|
340 |
case 1:
|
|
341 |
case 2:
|
|
342 |
case 3:
|
|
343 |
TheVariant.iDebugInitialised=EFalse;
|
|
344 |
case (TUint32)KNullDebugPort:
|
|
345 |
Kern::SuperPage().iDebugPort = thePort;
|
|
346 |
break;
|
|
347 |
default:
|
|
348 |
r=KErrNotSupported;
|
|
349 |
}
|
|
350 |
break;
|
|
351 |
}
|
|
352 |
case EVariantHalDebugPortGet:
|
|
353 |
{
|
|
354 |
kumemput32(a1, &Kern::SuperPage().iDebugPort, sizeof(TUint32));
|
|
355 |
break;
|
|
356 |
}
|
|
357 |
case EVariantHalSwitches:
|
|
358 |
{
|
|
359 |
//
|
|
360 |
// TO DO: (optional)
|
|
361 |
//
|
|
362 |
// Read the state of any switches, as in the following EXAMPLE ONLY:
|
|
363 |
//
|
|
364 |
TUint32 x = Variant::Switches();
|
|
365 |
kumemput32(a1, &x, sizeof(x));
|
|
366 |
break;
|
|
367 |
}
|
|
368 |
case EVariantHalLedMaskSet:
|
|
369 |
{
|
|
370 |
//
|
|
371 |
// TO DO: (optional)
|
|
372 |
//
|
|
373 |
// Set the state of any on-board LEDs, e.g:
|
|
374 |
// TUint32 aLedMask=(TUint32)a1;
|
|
375 |
// Variant::ModifyLedState(~aLedMask,aLedMask);
|
|
376 |
//
|
|
377 |
break;
|
|
378 |
}
|
|
379 |
case EVariantHalLedMaskGet:
|
|
380 |
{
|
|
381 |
//
|
|
382 |
// TO DO: (optional)
|
|
383 |
//
|
|
384 |
// Read the state of any on-board LEDs, e.g:
|
|
385 |
// TUint32 x = Variant::LedState();
|
|
386 |
// kumemput32(a1, &x, sizeof(x));
|
|
387 |
//
|
|
388 |
break;
|
|
389 |
}
|
|
390 |
|
|
391 |
case EVariantHalCustomRestartReason:
|
|
392 |
{
|
|
393 |
//Restart reason is stored in super page
|
|
394 |
TInt x = (Kern::SuperPage().iHwStartupReason & KHtCustomRestartMask) >> KHtCustomRestartShift ;
|
|
395 |
kumemput32(a1, &x, sizeof(TInt));
|
|
396 |
break;
|
|
397 |
}
|
|
398 |
|
|
399 |
case EVariantHalCustomRestart:
|
|
400 |
{
|
|
401 |
if(!Kern::CurrentThreadHasCapability(ECapabilityPowerMgmt,__PLATSEC_DIAGNOSTIC_STRING("Checked by Hal function EVariantHalCustomRestart")))
|
|
402 |
return KErrPermissionDenied;
|
|
403 |
if ((TUint)a1 > KHtCustomRestartMax)
|
|
404 |
return KErrArgument;
|
|
405 |
Kern::Restart((TInt)a1 << KHtCustomRestartShift);
|
|
406 |
}
|
|
407 |
break;
|
|
408 |
|
|
409 |
case EVariantHalCaseState:
|
|
410 |
{
|
|
411 |
//
|
|
412 |
// TO DO: (optional)
|
|
413 |
//
|
|
414 |
// Read the state of the case, e.g:
|
|
415 |
// TUint32 x = Variant::CaseState();
|
|
416 |
// kumemput32(a1, &x, sizeof(x));
|
|
417 |
//
|
|
418 |
break;
|
|
419 |
}
|
|
420 |
|
|
421 |
case EVariantHalPersistStartupMode:
|
|
422 |
{
|
|
423 |
if (!Kern::CurrentThreadHasCapability(ECapabilityWriteDeviceData,__PLATSEC_DIAGNOSTIC_STRING("Checked by Hal function EDisplayHalSetBacklightOn")))
|
|
424 |
return KErrPermissionDenied;
|
|
425 |
|
|
426 |
if ((TUint)a1 > KHtRestartStartupModesMax ) // Restart startup mode max value
|
|
427 |
return KErrArgument;
|
|
428 |
//
|
|
429 |
// TO DO: (optional)
|
|
430 |
//
|
|
431 |
// Store the restart reason locally,
|
|
432 |
// which will eventually be picked up by
|
|
433 |
// the power controller, e.g:
|
|
434 |
// iCustomRestartReason = (TUint)a1;
|
|
435 |
break;
|
|
436 |
}
|
|
437 |
|
|
438 |
|
|
439 |
case EVariantHalGetPersistedStartupMode:
|
|
440 |
{
|
|
441 |
//
|
|
442 |
// TO DO: (optional)
|
|
443 |
//
|
|
444 |
// Read the restart startup mode, e.g:
|
|
445 |
// TInt startup = (Kern::SuperPage().iHwStartupReason & KHtRestartStartupModesMask) >> KHtRestartStartupModesShift;
|
|
446 |
// kumemput32(a1, &startup, sizeof(TInt));
|
|
447 |
break;
|
|
448 |
}
|
|
449 |
|
|
450 |
case EVariantHalGetMaximumCustomRestartReasons:
|
|
451 |
{
|
|
452 |
//
|
|
453 |
// TO DO: (optional)
|
|
454 |
//
|
|
455 |
// Read the maximum custom restart reason, e.g:
|
|
456 |
// kumemput32(a1, &KHtCustomRestartMax, sizeof(TUint));
|
|
457 |
break;
|
|
458 |
}
|
|
459 |
|
|
460 |
|
|
461 |
case EVariantHalGetMaximumRestartStartupModes:
|
|
462 |
{
|
|
463 |
//
|
|
464 |
// TO DO: (optional)
|
|
465 |
//
|
|
466 |
// Read the maximum restart startup mode, e.g:
|
|
467 |
// kumemput32(a1, &KHtRestartStartupModesMax, sizeof(TUint));
|
|
468 |
break;
|
|
469 |
}
|
|
470 |
|
|
471 |
|
|
472 |
default:
|
|
473 |
r=KErrNotSupported;
|
|
474 |
break;
|
|
475 |
}
|
|
476 |
return r;
|
|
477 |
}
|
|
478 |
|
|
479 |
TPtr8 Beagle::MachineConfiguration()
|
|
480 |
{
|
|
481 |
return TPtr8((TUint8*)&Kern::MachineConfig(),sizeof(TActualMachineConfig),sizeof(TActualMachineConfig));
|
|
482 |
}
|
|
483 |
|
|
484 |
|
|
485 |
EXPORT_C void Variant::PowerReset()
|
|
486 |
{
|
|
487 |
//
|
|
488 |
// TO DO: (optional)
|
|
489 |
//
|
|
490 |
// Reset all power supplies
|
|
491 |
//
|
|
492 |
}
|
|
493 |
|
|
494 |
EXPORT_C TUint Variant::Switches()
|
|
495 |
{
|
|
496 |
//
|
|
497 |
// TO DO: (optional)
|
|
498 |
//
|
|
499 |
// Read the state of on-board switches
|
|
500 |
//
|
|
501 |
return 0; // EXAMPLE ONLY
|
|
502 |
}
|
|
503 |
|
|
504 |
// USB Client controller
|
|
505 |
|
|
506 |
TBool Beagle::UsbClientConnectorDetectable()
|
|
507 |
{
|
|
508 |
__KTRACE_OPT(KHARDWARE, Kern::Printf("Beagle::UsbClientConnectorDetectable"));
|
|
509 |
|
|
510 |
// TO DO: The return value should reflect the actual situation.
|
|
511 |
return ETrue;
|
|
512 |
}
|
|
513 |
|
|
514 |
|
|
515 |
TBool Beagle::UsbClientConnectorInserted()
|
|
516 |
{
|
|
517 |
__KTRACE_OPT(KHARDWARE, Kern::Printf("Beagle::UsbClientConnectorInserted"));
|
|
518 |
|
|
519 |
// TO DO: Query cable status here. The return value should reflect the actual current state.
|
|
520 |
return ETrue;
|
|
521 |
}
|
|
522 |
|
|
523 |
|
|
524 |
TInt Beagle::RegisterUsbClientConnectorCallback(TInt (*aCallback)(TAny*), TAny* aPtr)
|
|
525 |
{
|
|
526 |
__KTRACE_OPT(KHARDWARE, Kern::Printf("Beagle::RegisterUsbClientConnectorCallback"));
|
|
527 |
|
|
528 |
iUsbClientConnectorCallback = aCallback;
|
|
529 |
iUsbClientConnectorCallbackArg = aPtr;
|
|
530 |
|
|
531 |
// TO DO: Register and enable the interrupt(s) for detecting USB cable insertion/removal here.
|
|
532 |
// (Register UsbClientConnectorIsr.)
|
|
533 |
|
|
534 |
// TO DO: The return value should reflect the actual situation.
|
|
535 |
return KErrNone;
|
|
536 |
}
|
|
537 |
|
|
538 |
|
|
539 |
void Beagle::UnregisterUsbClientConnectorCallback()
|
|
540 |
{
|
|
541 |
__KTRACE_OPT(KHARDWARE, Kern::Printf("Beagle::UnregisterUsbClientConnectorCallback"));
|
|
542 |
|
|
543 |
// TO DO: Disable and unbind the interrupt(s) for detecting USB cable insertion/removal here.
|
|
544 |
|
|
545 |
iUsbClientConnectorCallback = NULL;
|
|
546 |
iUsbClientConnectorCallbackArg = NULL;
|
|
547 |
}
|
|
548 |
|
|
549 |
|
|
550 |
TBool Beagle::UsbSoftwareConnectable()
|
|
551 |
{
|
|
552 |
__KTRACE_OPT(KHARDWARE, Kern::Printf("Beagle::UsbSoftwareConnectable"));
|
|
553 |
|
|
554 |
// TO DO: The return value should reflect the actual situation.
|
|
555 |
return ETrue;
|
|
556 |
}
|
|
557 |
|
|
558 |
|
|
559 |
TInt Beagle::UsbConnect()
|
|
560 |
{
|
|
561 |
__KTRACE_OPT(KHARDWARE, Kern::Printf("Beagle::UsbConnect"));
|
|
562 |
|
|
563 |
// TO DO: Do here whatever is necessary for the UDC to appear on the bus (and thus to the host).
|
|
564 |
|
|
565 |
return KErrNone;
|
|
566 |
}
|
|
567 |
|
|
568 |
|
|
569 |
TInt Beagle::UsbDisconnect()
|
|
570 |
{
|
|
571 |
__KTRACE_OPT(KHARDWARE, Kern::Printf("Beagle::UsbDisconnect"));
|
|
572 |
|
|
573 |
// TO DO: Do here whatever is necessary for the UDC to appear disconnected from the bus (and thus from the
|
|
574 |
// host).
|
|
575 |
|
|
576 |
return KErrNone;
|
|
577 |
}
|
|
578 |
|
|
579 |
|
|
580 |
void Beagle::UsbClientConnectorIsr(TAny *aPtr)
|
|
581 |
//
|
|
582 |
// Services the USB cable interrupt.
|
|
583 |
//
|
|
584 |
{
|
|
585 |
__KTRACE_OPT(KHARDWARE, Kern::Printf("Beagle::UsbClientConnectorIsr()"));
|
|
586 |
|
|
587 |
Beagle* tm = static_cast<Beagle*>(aPtr);
|
|
588 |
|
|
589 |
// TO DO: Service interrupt here: determmine cause, clear condition flag (if applicable), etc.
|
|
590 |
|
|
591 |
if (tm->UsbClientConnectorInserted())
|
|
592 |
{
|
|
593 |
__KTRACE_OPT(KHARDWARE, Kern::Printf(" > USB cable now inserted."));
|
|
594 |
}
|
|
595 |
else
|
|
596 |
{
|
|
597 |
__KTRACE_OPT(KHARDWARE, Kern::Printf(" > USB cable now removed."));
|
|
598 |
}
|
|
599 |
|
|
600 |
// Important: Inform the USB stack.
|
|
601 |
if (tm->iUsbClientConnectorCallback)
|
|
602 |
{
|
|
603 |
(*tm->iUsbClientConnectorCallback)(tm->iUsbClientConnectorCallbackArg);
|
|
604 |
}
|
|
605 |
}
|
|
606 |
|
|
607 |
// Used to convert time to BCD and vice-versa
|
|
608 |
const TInt KSecsPerMin = 60;
|
|
609 |
const TInt KSecsPerHour = 60*KSecsPerMin;
|
|
610 |
const TInt KSecsPerDay = 24*KSecsPerHour;
|
|
611 |
//const TInt KSecsPerLeapYr = 366*KSecsPerDay;
|
|
612 |
const TInt KSecsPerYr = 365*KSecsPerDay;
|
|
613 |
const TInt KSecsDaysPer4Years = (3*KSecsPerYr)+ 366*KSecsPerDay;
|
|
614 |
|
|
615 |
//#define BCDTONUM0_3_4_7(a) ((a&0xf)+(((a)>>4)*10))
|
|
616 |
#define BCDTONUM0_3_4_6(a) ((a&0xf)+((((a)>>4)&7)*10))
|
|
617 |
|
|
618 |
// Days in each month
|
|
619 |
LOCAL_D const TInt8 mTab[2][12]=
|
|
620 |
{
|
|
621 |
{31,28,31,30,31,30,31,31,30,31,30,31}, // 28 days in Feb
|
|
622 |
{31,29,31,30,31,30,31,31,30,31,30,31} // 29 days in Feb
|
|
623 |
};
|
|
624 |
|
|
625 |
void GetMonthData(TInt aDayInYear, TBool aLeap, TUint8& aMonth, TUint8& aDay )
|
|
626 |
/**
|
|
627 |
Work out day of the month and month
|
|
628 |
@param aDayInYear Day of the year
|
|
629 |
@param aLeap True if it is a leap year
|
|
630 |
@param aMonth Return month (range 01-12)
|
|
631 |
@param aDay Return day of the month (range 01-31)
|
|
632 |
*/
|
|
633 |
{
|
|
634 |
TInt i;
|
|
635 |
TInt runtot=0;
|
|
636 |
for (i=0; i<12; i++)
|
|
637 |
{
|
|
638 |
if ((aDayInYear>=runtot) && (aDayInYear < mTab[aLeap][i]+runtot))
|
|
639 |
{
|
|
640 |
// Month and day of the month both start from 1, rather than
|
|
641 |
// zero (hence the +1)
|
|
642 |
aMonth=i+1;
|
|
643 |
aDay=aDayInYear-runtot+1;
|
|
644 |
break;
|
|
645 |
}
|
|
646 |
runtot+=mTab[aLeap][i];
|
|
647 |
}
|
|
648 |
}
|
|
649 |
|
|
650 |
LOCAL_C void SecondsToYMD( const TInt aTime, TUint8& aYear, TUint8& aMonth, TUint8& aDay )
|
|
651 |
/**
|
|
652 |
Work out year, day of the month and month
|
|
653 |
@param aTime Time in secs from year 2000
|
|
654 |
@param aYear Return year number
|
|
655 |
@param aMonth Return month (range 01-12)
|
|
656 |
@param aDay Return day of the month (range 01-31)
|
|
657 |
*/
|
|
658 |
{
|
|
659 |
// Work out year within 4 years first
|
|
660 |
aYear = (aTime / KSecsDaysPer4Years)*4;
|
|
661 |
aDay=0;
|
|
662 |
aMonth=0;
|
|
663 |
TInt adjyear = aTime % KSecsDaysPer4Years;
|
|
664 |
|
|
665 |
|
|
666 |
if (adjyear<KSecsPerYr + KSecsPerDay)
|
|
667 |
{
|
|
668 |
GetMonthData(adjyear/KSecsPerDay, ETrue, aMonth, aDay);
|
|
669 |
}
|
|
670 |
else
|
|
671 |
{
|
|
672 |
adjyear-=(KSecsPerYr + KSecsPerDay);
|
|
673 |
aYear+=(adjyear/KSecsPerYr)+1;
|
|
674 |
GetMonthData((adjyear%KSecsPerYr)/KSecsPerDay, EFalse, aMonth, aDay);
|
|
675 |
}
|
|
676 |
}
|
|
677 |
|
|
678 |
|
|
679 |
EXPORT_C TInt Beagle::SystemTimeInSecondsFrom2000(TInt& aTime)
|
|
680 |
{
|
|
681 |
|
|
682 |
if(!TPS65950::Initialized())
|
|
683 |
{
|
|
684 |
return KErrNotSupported;
|
|
685 |
}
|
|
686 |
|
|
687 |
TPS65950::TRtcTime time;
|
|
688 |
TPS65950::GetRtcData( time );
|
|
689 |
|
|
690 |
aTime = time.iSecond;
|
|
691 |
aTime += time.iMinute * KSecsPerMin;
|
|
692 |
aTime += time.iHour * KSecsPerHour;
|
|
693 |
|
|
694 |
// Careful - day starts from 1
|
|
695 |
aTime += (time.iDay-1) * KSecsPerDay;
|
|
696 |
|
|
697 |
// Determine whether it is a leap year, for the purpose of this chip
|
|
698 |
// years run from 2000 onwards and the driver won't care beyond
|
|
699 |
// yr2000 + 0x7fffffff(secs) (60 odd years). In brief, we can just divide
|
|
700 |
// by 4 and ignore the problem of years divisible by 100
|
|
701 |
TInt yrs= time.iYear;
|
|
702 |
TUint yrsMod4 = yrs%4;
|
|
703 |
TBool isLeap = (yrsMod4) ? EFalse : ETrue;
|
|
704 |
|
|
705 |
// Careful - month starts from 1
|
|
706 |
for (TInt i=0; i < time.iMonth-1; i++)
|
|
707 |
{
|
|
708 |
aTime += mTab[isLeap][i] * KSecsPerDay;
|
|
709 |
}
|
|
710 |
|
|
711 |
aTime += (yrs/4) * KSecsDaysPer4Years;
|
|
712 |
|
|
713 |
if ( isLeap )
|
|
714 |
{
|
|
715 |
// Add KSecsPerDay, because first year is always a leap year
|
|
716 |
aTime+=(KSecsPerYr*(yrsMod4))+KSecsPerDay;
|
|
717 |
}
|
|
718 |
return KErrNone;
|
|
719 |
}
|
|
720 |
|
|
721 |
EXPORT_C TInt Beagle::SetSystemTimeInSecondsFrom2000(TInt aTime)
|
|
722 |
{
|
|
723 |
if(!TPS65950::Initialized())
|
|
724 |
{
|
|
725 |
return KErrNotSupported;
|
|
726 |
}
|
|
727 |
|
|
728 |
TPS65950::TRtcTime rtc;
|
|
729 |
TInt secs = aTime % KSecsPerMin;
|
|
730 |
TInt mins_insecs = (aTime % KSecsPerHour) - secs;
|
|
731 |
TInt hours_insecs = (aTime % KSecsPerDay) - mins_insecs - secs;
|
|
732 |
|
|
733 |
rtc.iSecond = secs;
|
|
734 |
rtc.iMinute = mins_insecs/KSecsPerMin;
|
|
735 |
rtc.iHour = hours_insecs/KSecsPerHour;
|
|
736 |
|
|
737 |
SecondsToYMD( aTime, rtc.iYear, rtc.iMonth, rtc.iDay);
|
|
738 |
|
|
739 |
TPS65950::SetRtcData( rtc );
|
|
740 |
|
|
741 |
return KErrNone;
|
|
742 |
}
|
|
743 |
|
|
744 |
|
|
745 |
TInt Beagle::IsExternalInterrupt(TInt /*anId*/)
|
|
746 |
{
|
|
747 |
return EFalse;
|
|
748 |
}
|
|
749 |
|
|
750 |
TInt Beagle::InterruptBind(TInt /*anId*/, TIsr /*anIsr*/, TAny* /*aPtr*/)
|
|
751 |
{
|
|
752 |
return KErrNotSupported;
|
|
753 |
}
|
|
754 |
|
|
755 |
TInt Beagle::InterruptUnbind(TInt /*anId*/)
|
|
756 |
{
|
|
757 |
return KErrNotSupported;
|
|
758 |
}
|
|
759 |
|
|
760 |
TInt Beagle::InterruptEnable(TInt /*anId*/)
|
|
761 |
{
|
|
762 |
return KErrNotSupported;
|
|
763 |
}
|
|
764 |
|
|
765 |
TInt Beagle::InterruptDisable(TInt /*anId*/)
|
|
766 |
{
|
|
767 |
return KErrNotSupported;
|
|
768 |
}
|
|
769 |
|
|
770 |
TInt Beagle::InterruptClear(TInt /*anId*/)
|
|
771 |
{
|
|
772 |
return KErrNotSupported;
|
|
773 |
}
|
|
774 |
|
|
775 |
|
|
776 |
|
|
777 |
|
|
778 |
|
|
779 |
|
|
780 |
//---eof
|