navienginebsp/ne1_tb/ethernet/shared_ethernet.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 * ne1_tb\ethernet\shared_ethernet.cpp
       
    16 * Ethernet driver implementation.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 
       
    22 /**
       
    23  @addtogroup 
       
    24  @ingroup 
       
    25 */
       
    26 
       
    27 #include "shared_ethernet.h"
       
    28 
       
    29 
       
    30 /********************************************************************/
       
    31 /*  Class DEthernetPowerHandler implementation                      */
       
    32 /********************************************************************/
       
    33 
       
    34 /*
       
    35  * Device power down modes
       
    36  */
       
    37 enum TPowerDownMode
       
    38 	{
       
    39 	ENormalPowerDown,
       
    40 	EEmergencyPowerDown
       
    41 	};
       
    42 
       
    43 _LIT(KLitEthernet,"Ethernet");
       
    44 
       
    45 DEthernetPowerHandler::DEthernetPowerHandler()
       
    46 :DPowerHandler(KLitEthernet),
       
    47 iCurPoweredUp(EFalse),
       
    48 iCurPowerState(EPwActive)
       
    49 	{
       
    50 	}
       
    51 
       
    52 void DEthernetPowerHandler::RequestPower()
       
    53 	{
       
    54 	#if defined(INSTR) && defined(KTRACE_SYNCH)
       
    55 	KPROFILE_PRINT("DEthernetPowerHandler::RequestPower()");
       
    56 	#endif
       
    57 
       
    58     // Do power up the Ethernet if not already powered up.
       
    59     if(!iCurPoweredUp)
       
    60 		{
       
    61 	    iCurPoweredUp = ETrue;
       
    62 		}
       
    63 	}
       
    64 
       
    65 TInt DEthernetPowerHandler::SetEthernetPdd(DEthernetPdd* aEthernetPdd)
       
    66 	{
       
    67    #if defined(INSTR) && defined(KTRACE_SYNCH)
       
    68     KPROFILE_PRINT("DEthernetPowerHandler::SetEthernetPdd()");
       
    69    #endif
       
    70 
       
    71 	 iEthernetPdd = aEthernetPdd;
       
    72 	 return KErrNone;
       
    73 	}
       
    74 
       
    75 void DEthernetPowerHandler::PowerUp()
       
    76 	{
       
    77 	#if defined(INSTR) && defined(KTRACE_SYNCH)
       
    78     KPROFILE_PRINT("DEthernetPowerHandler::PowerUp()");	
       
    79     #endif
       
    80     iCurPowerState = EPwActive;
       
    81 	iEthernetPdd->Wakeup();
       
    82     PowerUpDone();
       
    83 	}
       
    84 
       
    85 void DEthernetPowerHandler::PowerDown(TPowerState aState)
       
    86 	{
       
    87 	#if defined(INSTR) && defined(KTRACE_SYNCH)
       
    88     KPROFILE_PRINT("DEthernetPowerHandler::PowerDown()");	
       
    89     #endif
       
    90 	iCurPowerState = aState;
       
    91 	// Stop recieving more frames.
       
    92 	iEthernetPdd->Stop(EStopNormal);
       
    93 
       
    94     // Do power down on Ethernet
       
    95 	RelinquishPower();
       
    96     PowerDownDone();
       
    97 	}
       
    98 
       
    99 void DEthernetPowerHandler::RelinquishPower()
       
   100 	{
       
   101 	#if defined(INSTR) && defined(KTRACE_SYNCH)
       
   102     KPROFILE_PRINT("DEthernetPowerHandler::RelinquishPower()");	
       
   103     #endif
       
   104 
       
   105     // Do power standby on Ethernet if it is powered up.
       
   106     if(iCurPoweredUp)
       
   107 		{
       
   108  	    iCurPoweredUp = EFalse;
       
   109 		}
       
   110 	iEthernetPdd->Sleep();
       
   111 	}
       
   112  
       
   113 DEthernetPdd::DEthernetPdd()
       
   114 //Constructor
       
   115 	{
       
   116 	}
       
   117 
       
   118 DEthernetPdd::~DEthernetPdd()
       
   119 //Destructor
       
   120 	{
       
   121 	}
       
   122 
       
   123 TInt DEthernetPdd::Start()
       
   124 /**
       
   125  * Start receiving frames
       
   126  * @return KErrNone if driver started
       
   127  */
       
   128 	{
       
   129 	#if defined(INSTR) && defined(KTRACE_SYNCH)
       
   130     KPROFILE_PRINT("DEthernetPdd::Start()");
       
   131     #endif
       
   132 
       
   133 	if(iReady)
       
   134 		{
       
   135 		return KErrNone;
       
   136 		}
       
   137 	iReady = ETrue;
       
   138 	TInt r = Configure(iDefaultConfig);
       
   139 	return r;
       
   140 	}
       
   141 
       
   142 TInt DEthernetPdd::ValidateConfig(const TEthernetConfigV01& aConfig) const
       
   143 /**
       
   144  * Validate a new config
       
   145  * Validates a new configuration should be called before Configure
       
   146  * @param aConfig is the configuration to be validated
       
   147  * @return ETrue or EFalse if the Configuration is allowed
       
   148  * @see Configure()
       
   149  */
       
   150 	{
       
   151 	#if defined(INSTR) && defined(KTRACE_SYNCH)
       
   152     KPROFILE_PRINT("DEthernetPdd::ValidateConfig()");
       
   153     #endif
       
   154 	switch(aConfig.iEthSpeed)
       
   155 		{
       
   156 	case KEthSpeedAuto:
       
   157 	case KEthSpeed10BaseT:
       
   158 	case KEthSpeed100BaseTX:
       
   159 		break;
       
   160 	case KEthSpeedUnknown:
       
   161 	default:
       
   162 		return KErrNotSupported;
       
   163 		}
       
   164 
       
   165 	switch(aConfig.iEthDuplex)
       
   166 		{
       
   167 	case KEthDuplexAuto:
       
   168 	case KEthDuplexFull:
       
   169 	case KEthDuplexHalf:
       
   170 		break;
       
   171 	default:
       
   172 	case KEthDuplexUnknown:
       
   173 		return KErrNotSupported;
       
   174 		}
       
   175 
       
   176 	return KErrNone;
       
   177 	}
       
   178 
       
   179 
       
   180 
       
   181 void DEthernetPdd::GetConfig(TEthernetConfigV01& aConfig) const
       
   182 /**
       
   183  * Get the current config from the chip
       
   184  * This returns the current configuration of the chip with the folling fields
       
   185  * The Transmit Speed
       
   186  * The Duplex Setting
       
   187  * The MAC address
       
   188  * @param aConfig is a TEthernetConfigV01 reference that will be filled in
       
   189  */
       
   190 	{
       
   191 	#if defined(INSTR) && defined(KTRACE_SYNCH)
       
   192     KPROFILE_PRINT("DEthernetPdd::GetConfig()");
       
   193     #endif
       
   194 	aConfig = iDefaultConfig;
       
   195 	return;
       
   196 	}
       
   197 
       
   198 
       
   199 void DEthernetPdd::CheckConfig(TEthernetConfigV01& /*aConfig*/)
       
   200 /**
       
   201  * Check a configuration
       
   202  * @param aConfig	a reference to the structure TEthernetConfigV01 with configuration to check
       
   203  */
       
   204 	{
       
   205 	#if defined(INSTR) && defined(KTRACE_SYNCH)
       
   206     KPROFILE_PRINT("DEthernetPdd::CheckConfig()");
       
   207     #endif
       
   208 	return;
       
   209 	}
       
   210 
       
   211 
       
   212 void DEthernetPdd::Caps(TDes8& /*aCaps*/) const
       
   213 /**
       
   214  * Query the device's capabilities
       
   215  * @param aCaps To be filled in with the capabilites
       
   216  */
       
   217 	{	
       
   218 	#if defined(INSTR) && defined(KTRACE_SYNCH)
       
   219     KPROFILE_PRINT("DEthernetPdd::Caps()");
       
   220     #endif
       
   221 	return;
       
   222 	}
       
   223 
       
   224 TInt DEthernetPdd::DisableIrqs()
       
   225 /**
       
   226  * Disables all IRQ's
       
   227  * @return The IRQ level before it was changed
       
   228  * @see RestoreIrqs()
       
   229  */
       
   230 	{
       
   231 	return KErrNotSupported;
       
   232 	}
       
   233 
       
   234 void DEthernetPdd::RestoreIrqs(TInt /*aIrq*/)
       
   235 /**
       
   236  * Restore the IRQ's to the supplied level
       
   237  * @param aIrq The level to set the irqs to.
       
   238  * @see DisableIrqs()
       
   239  */
       
   240 	{
       
   241 	}
       
   242 
       
   243 TDfcQue* DEthernetPdd::DfcQ(TInt /*aUnit*/)
       
   244 /**
       
   245  * Return the DFC Queue that this device should use
       
   246  * @param aUnit The Channel number
       
   247  * @return Then DFC Queue to use
       
   248  */
       
   249 	{
       
   250 	#if defined(INSTR) && defined(KTRACE_SYNCH)
       
   251 	KPROFILE_PRINT("DEthernetPdd::DfcQ()");
       
   252 	#endif
       
   253 
       
   254 	return iDfcQ;
       
   255 	}