navienginebsp/naviengine_assp/assp.cpp
changeset 0 5de814552237
equal deleted inserted replaced
-1:000000000000 0:5de814552237
       
     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\assp.cpp
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 #include <naviengine_priv.h>
       
    22 #include <upd35001_timer.h>
       
    23 
       
    24 NaviEngineAssp* NaviEngineAssp::Variant=NULL;
       
    25 TPhysAddr NaviEngineAssp::VideoRamPhys;
       
    26 
       
    27 
       
    28 DECLARE_STANDARD_ASSP()
       
    29 
       
    30 EXPORT_C NaviEngineAssp::NaviEngineAssp()
       
    31 	{
       
    32 	NaviEngineAssp::Variant=this;
       
    33 	iDebugInitialised = EFalse;
       
    34 
       
    35 	/* Initialize timers 1 and 2 to generate the system timestamp counter */
       
    36 	NETimer& T1 = NETimer::Timer(1);
       
    37 	NETimer& T2 = NETimer::Timer(2);
       
    38 
       
    39 	T1.iTimerCtrl = 0;						// stop and reset timer 1
       
    40 	T1.iGTICtrl = 0;						// disable timer 1 capture modes
       
    41 	T2.iTimerCtrl = 0;						// stop and reset timer 2
       
    42 	T2.iGTICtrl = 0;						// disable timer 2 capture modes
       
    43 	__e32_io_completion_barrier();
       
    44 #ifdef __SMP__
       
    45 	T1.iPrescaler = KNETimerPrescaleBy1;	// Timer 1 prescaled by 1 (=66.667MHz)
       
    46 	T2.iPrescaler = KNETimerPrescaleBy1;	// Timer 2 prescaled by 1 (=66.667MHz)
       
    47 #else
       
    48 	T1.iPrescaler = KNETimerPrescaleBy32;	// Timer 1 prescaled by 32 (=2.0833MHz)
       
    49 	T2.iPrescaler = KNETimerPrescaleBy32;	// Timer 2 prescaled by 32 (=2.0833MHz)
       
    50 #endif
       
    51 	__e32_io_completion_barrier();
       
    52 	T1.iGTInterruptEnable = 0;
       
    53 	T2.iGTInterruptEnable = 0;
       
    54 	__e32_io_completion_barrier();
       
    55 	T1.iGTInterrupt = KNETimerGTIInt_All;
       
    56 	T2.iGTInterrupt = KNETimerGTIInt_All;
       
    57 	__e32_io_completion_barrier();
       
    58 	T1.iTimerCtrl = KNETimerCtrl_CE;		// deassert reset for timer 1, count still stopped
       
    59 	T2.iTimerCtrl = KNETimerCtrl_CE;		// deassert reset for timer 2, count still stopped
       
    60 	__e32_io_completion_barrier();
       
    61 	T1.iTimerReset = 0xfffffeffu;			// timer 1 wraps after 2^32-256 counts
       
    62 	T2.iTimerReset = 0xffffffffu;			// timer 2 wraps after 2^32 counts
       
    63 	__e32_io_completion_barrier();
       
    64 	T1.iTimerCtrl = KNETimerCtrl_CE | KNETimerCtrl_CAE;	// start timer 1
       
    65 	__e32_io_completion_barrier();			// make sure timer 1 started before timer 2
       
    66 	T2.iTimerCtrl = KNETimerCtrl_CE | KNETimerCtrl_CAE;	// start timer 2
       
    67 	__e32_io_completion_barrier();
       
    68 
       
    69 	// Each time T1 wraps, (T1-T2) increases by 256 after starting at 0
       
    70 	// t1=T1; t2=T2; n=(t1-t2)>>8; time = t1 + n * (2^32-256)
       
    71 
       
    72 	}
       
    73 
       
    74 extern void MsTimerTick(TAny* aPtr);
       
    75 
       
    76 
       
    77 EXPORT_C TMachineStartupType NaviEngineAssp::StartupReason()
       
    78 	{
       
    79 	__KTRACE_OPT(KBOOT,Kern::Printf("NaviEngineAssp::StartupReason"));
       
    80 #ifdef _DEBUG															// REMOVE THIS
       
    81 	TUint s = Kern::SuperPage().iHwStartupReason;
       
    82 	__KTRACE_OPT(KBOOT,Kern::Printf("CPU page value %08x", s));
       
    83 #endif																	// REMOVE THIS
       
    84 	//
       
    85 	// TO DO: (mandatory)
       
    86 	//
       
    87 	// Map the startup reason read from the Super Page to one of TMachineStartupType enumerated values
       
    88 	// and return this
       
    89 	//
       
    90 	return EStartupCold;   // EXAMPLE ONLY
       
    91 	}
       
    92 
       
    93 EXPORT_C void NaviEngineAssp::Init1()
       
    94 	{
       
    95 	__KTRACE_OPT(KBOOT,Kern::Printf("NaviEngineAssp::Init1()"));
       
    96 	//
       
    97 	// TO DO: (optional)
       
    98 	//
       
    99 	NaviEngineInterrupt::Init1();			// initialise the ASSP interrupt controller
       
   100 
       
   101 	//
       
   102 	// TO DO: (optional)
       
   103 	//
       
   104 	// Initialises any hardware blocks which require early initialisation, e.g. enable and power the LCD, set up
       
   105 	// RTC clocks, disable DMA controllers. etc.
       
   106 	//
       
   107 	TNaviEngine::Init1();
       
   108 	}
       
   109 
       
   110 
       
   111 EXPORT_C void NaviEngineAssp::Init3()
       
   112 	{
       
   113 	__KTRACE_OPT(KBOOT,Kern::Printf("NaviEngineAssp::Init3()"));
       
   114 
       
   115 	TNaviEngine::Init3();
       
   116 
       
   117 #ifdef TOGLE_UART_DTR_LINE
       
   118      AsspRegister::Write32(KHwRwGpio_Port_Control_Enable, 1<<9);   
       
   119 #endif
       
   120 
       
   121 
       
   122 	NTimerQ& m=*(NTimerQ*)NTimerQ::TimerAddress();
       
   123 	iTimerQ=&m;
       
   124 
       
   125 	// Initialize timer 0 to generate the 1ms periodic system tick
       
   126 	NETimer& NET = NETimer::Timer(0);
       
   127 	NET.iTimerCtrl = 0;						// reset counter
       
   128 	NET.iGTICtrl = 0;						// disable input capture
       
   129 	__e32_io_completion_barrier();
       
   130 	NET.iPrescaler = KNETimerPrescaleBy1;	// prescaler divides by 1
       
   131 	__e32_io_completion_barrier();
       
   132 	NET.iTimerCtrl = KNETimerCtrl_CE;		// take timer out of reset
       
   133 	__e32_io_completion_barrier();
       
   134 	NET.iTimerReset = 66666;				// clocks before timer reset (66.666MHz clock frequency)
       
   135 	__e32_io_completion_barrier();
       
   136 	NET.iGTInterrupt = KNETimerGTIInt_All;	// clear any pending interrupts
       
   137 	__e32_io_completion_barrier();
       
   138 	NET.iGTInterruptEnable = KNETimerGTIIntE_TCE;	// enable counter reset interrupt
       
   139 	__e32_io_completion_barrier();
       
   140 	NET.iTimerCtrl = KNETimerCtrl_CE | KNETimerCtrl_CAE;	// start counter
       
   141 	__e32_io_completion_barrier();
       
   142     
       
   143 	//
       
   144 	// TO DO: (mandatory)
       
   145 	//
       
   146 	// If Hardware Timer used for System Ticks cannot give exactly the period required store the initial rounding value
       
   147 	// here which is updated every time a match occurrs. Note this leads to "wobbly" timers whose exact period change
       
   148 	// but averages exactly the required value
       
   149 	// e.g.
       
   150 	// m.iRounding=-5;
       
   151 	//
       
   152 	
       
   153 	TInt r=Interrupt::Bind(KIntIdOstMatchMsTimer,MsTimerTick,&m);	// bind the System Tick interrupt
       
   154 	if (r<0)
       
   155 		Kern::Fault("BindMsTick",r);
       
   156 
       
   157 	// 
       
   158 	// TO DO: (mandatory)
       
   159 	//
       
   160 	// Clear any pending OST interrupts and enable any OST match registers.
       
   161 	// If possible may reset the OST here (to start counting from a full period). Set the harwdare to produce an 
       
   162 	// interrupt on full count
       
   163 	//
       
   164 
       
   165 	r=Interrupt::Enable(r);	// enable the System Tick interrupt
       
   166 	if (r!=KErrNone)
       
   167 		Kern::Fault("EnbMsTick",r);
       
   168 
       
   169 	// Allocate physical RAM for video buffer.
       
   170 	TInt vSize=VideoRamSize();
       
   171 	r=Epoc::AllocPhysicalRam(2*vSize,NaviEngineAssp::VideoRamPhys); //Alloc memory for both secure and non-secure display.
       
   172 	if (r!=KErrNone)
       
   173 		Kern::Fault("AllocVRam",r);
       
   174 	}
       
   175 
       
   176 EXPORT_C TInt NaviEngineAssp::MsTickPeriod()
       
   177 	{
       
   178 	// Return the OST tick period (System Tick)
       
   179 	return 1000;
       
   180 	}
       
   181 
       
   182 EXPORT_C TInt NaviEngineAssp::SystemTimeInSecondsFrom2000(TInt& aTime)
       
   183 	{
       
   184 	aTime=(TInt)TNaviEngine::RtcData();
       
   185 	__KTRACE_OPT(KHARDWARE,Kern::Printf("RTC READ: %d",aTime));
       
   186 	return KErrNone;
       
   187 	}
       
   188 
       
   189 EXPORT_C TInt NaviEngineAssp::SetSystemTimeInSecondsFrom2000(TInt aTime)
       
   190 	{
       
   191 	//
       
   192 	// TO DO: (optional)
       
   193 	//
       
   194 	// Check if the RTC is running and is stable
       
   195 	//
       
   196 	__KTRACE_OPT(KHARDWARE,Kern::Printf("Set RTC: %d",aTime));
       
   197 	TNaviEngine::SetRtcData(aTime);
       
   198 	__KTRACE_OPT(KHARDWARE,Kern::Printf("RTC: %d",TNaviEngine::RtcData()));
       
   199 	return KErrNone;
       
   200 	}
       
   201 
       
   202 EXPORT_C TUint32 NaviEngineAssp::NanoWaitCalibration()
       
   203 	{
       
   204 	// 
       
   205 	// TO DO: (mandatory)
       
   206 	//
       
   207 	// Return the minimum time in nano-seconds that it takes to execute the following code:
       
   208 	//	 nanowait_loop:
       
   209 	//	 		  subs r0, r0, r1
       
   210 	//	 		  bhi nanowait_loop
       
   211 	//
       
   212 	// If accurate timings are required by the Base Port, then it should provide it's own implementation 
       
   213 	// of NanoWait which uses a hardware counter. (See Kern::SetNanoWaitHandler)
       
   214 	//
       
   215 	
       
   216 	return 0;   // EXAMPLE ONLY
       
   217 	}
       
   218 
       
   219 EXPORT_C void NaviEngineAssp::DebugOutput(TUint aLetter)
       
   220 //
       
   221 // Output a character to the debug port
       
   222 //
       
   223     {
       
   224 	if (!iDebugInitialised)
       
   225 		{
       
   226 		TNaviEngine::InitDebugOutput();
       
   227 		iDebugInitialised = ETrue;
       
   228 		}
       
   229 	TNaviEngine::DoDebugOutput(aLetter);
       
   230     }
       
   231