omap3530/shared/monitor/monitor.cpp
author Lukasz Forynski <lukasz.forynski@gmail.com>
Tue, 07 Sep 2010 08:40:04 +0100
changeset 63 8cf16be5c3dd
parent 0 6663340f3fc9
child 69 39ed99121282
permissions -rwxr-xr-x
Bug 3674 fix

// Copyright (c) 1994-2009 Nokia Corporation and/or its subsidiary(-ies).
// All rights reserved.
// This component and the accompanying materials are made available
// under the terms of the License "Eclipse Public License v1.0"
// which accompanies this distribution, and is available
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
//
// Initial Contributors:
// Nokia Corporation - initial contribution.
//
// Contributors:
//
// Description:
// omap3530/shared/monitor/monitor.cpp
// 
//

#include <monitor.h>
#include <assp/omap3530_assp/omap3530_assp_priv.h>
#include <assp/omap3530_assp/omap3530_uart.h>
#include <assp/omap3530_assp/omap3530_prcm.h>

void CrashDebugger::InitUart()
	{
	const Omap3530Uart::TUartNumber portNumber( Omap3530Assp::DebugPortNumber() );

	if( portNumber >= 0 )
		{
		Omap3530Uart::TUart uart( portNumber );

		// wait for uart to fihish any transmission that could be started (i.e. crash info)
		while(!uart.TxFifoEmpty());

		// Ensure UART clocks are running
		Prcm::SetClockState( uart.PrcmInterfaceClk(),Prcm::EClkOn );
		Prcm::SetClockState( uart.PrcmFunctionClk(), Prcm::EClkOn );
	
		// We don't know what state the UART is in, so reinitialize it
		uart.Init();
		uart.DefineMode( Omap3530Uart::TUart::EUart );
		uart.SetBaud( Omap3530Uart::TUart::E115200 );
		uart.SetDataFormat( Omap3530Uart::TUart::E8Data, Omap3530Uart::TUart::E1Stop, Omap3530Uart::TUart::ENone );
		uart.Enable();
		}
	}

void CrashDebugger::UartOut(TUint aChar)
	{
	const Omap3530Uart::TUartNumber portNumber( Omap3530Assp::DebugPortNumber() );

	if( portNumber >= 0 )
		{
		Omap3530Uart::TUart uart( portNumber );

		TUint c=0;
			
		while ( !uart.RxFifoEmpty() )
			{ 
			if ( CheckPower() )
				{
				return;
				}

			c = uart.Read();
			
			if ( c == 19 )            // XOFF
				{
				FOREVER
					{
					while( uart.RxFifoEmpty() )
						{
						if ( CheckPower() )
							{
							return;
							}
						}

					c = uart.Read();
					
					if ( c == 17 )    // XON
						{
						break;
						}
					else if ( c == 3 )		// Ctrl C
						{
						Leave(KErrCancel);
						}
					}
				}
			else if ( c == 3 )		// Ctrl C
				{
				Leave(KErrCancel);
				}
			}

		while ( uart.TxFifoFull() )
			{
			CheckPower();
			}

		uart.Write( aChar );
		}
	}

TUint8 CrashDebugger::UartIn()
	{
	const Omap3530Uart::TUartNumber portNumber( Omap3530Assp::DebugPortNumber() );

	if( portNumber >= 0 )
		{
		Omap3530Uart::TUart uart( portNumber );

		while ( uart.RxFifoEmpty() )
			{
			if ( CheckPower() )
				{
				return 0x0d;
				}
			}
		return uart.Read();
		}
	
	return 0;
	}

TBool CrashDebugger::CheckPower()
	{
	//
	// Check if power supply is stable and return ETrue if not
	//
	return EFalse;	// EXAMPLE ONLY
	}