omap3530/omap3530_drivers/spi/omap3530_spi.inl
branchBeagle_BSP_dev
changeset 82 65b40f262685
parent 77 e5fd00cbb70a
child 84 09e266454dcf
equal deleted inserted replaced
77:e5fd00cbb70a 82:65b40f262685
    16 // the driver!
    16 // the driver!
    17 //
    17 //
    18 
    18 
    19 
    19 
    20 // This sets the CS line to inactive mode (Specify aActiveMode as appropriate for configuration)
    20 // This sets the CS line to inactive mode (Specify aActiveMode as appropriate for configuration)
    21 // The CS pin will be put back to the opposite mode - using GPIO..
    21 // The CS pin will be put back to the opposite mode - using GPIO.. THis is in order to always keep
       
    22 // the CS line in an 'inactive' state (de-asserted) when the SPI is disabled.
    22 inline void SetCsInactive(TInt aModule, TInt aChannel, TSpiSsPinMode aActiveMode)
    23 inline void SetCsInactive(TInt aModule, TInt aChannel, TSpiSsPinMode aActiveMode)
    23 	{
    24 	{
    24 	//__ASSERT_DEBUG(aModule < KMaxSpiChannelsPerModule, Kern::Fault("omap3530_spi.inl, line: ", __LINE__)); // aChannel > module channels
    25 	//__ASSERT_DEBUG(aModule < KMaxSpiChannelsPerModule, Kern::Fault("omap3530_spi.inl, line: ", __LINE__)); // aChannel > module channels
    25 	// set the pin to the opposite to the currently active CS mode..
    26 	// set the pin to the opposite to the currently active CS mode..
    26 	TUint16 csPinOptions = aActiveMode == ESpiCSPinActiveLow ? KCsPinModeUp : KCsPinModeDown;
       
    27 	const TPinConfig& csConf = ModulePinConfig[aModule].iCs[aChannel];
    27 	const TPinConfig& csConf = ModulePinConfig[aModule].iCs[aChannel];
    28 	__ASSERT_DEBUG(csConf.iAddress, Kern::Fault("omap3530_spi.inl, line: ", __LINE__)); // aChannel > module channels
    28 	__ASSERT_DEBUG(csConf.iAddress, Kern::Fault("omap3530_spi.inl, line: ", __LINE__)); // aChannel > module channels
    29 
    29 
    30 	// now switch the pin mode..
    30 	// now switch the pin mode..(making sure it is at the proper level before that)
    31 	SCM::SetPadConfig(csConf.iAddress, csConf.iMswLsw, SCM::EMode4 | csPinOptions); // always go to mode 4 (gpio)
    31 	GPIO::SetOutputState(csConf.iPinNumber, aActiveMode == ESpiCSPinActiveLow ? GPIO::EHigh : GPIO::ELow);
       
    32 	SCM::SetPadConfig(csConf.iAddress, csConf.iMswLsw, SCM::EMode4); // always go to mode 4 (gpio)
    32 	}
    33 	}
    33 
    34 
    34 void SetCsActive(TInt aModule, TInt aChannel, TSpiSsPinMode aActiveMode)
    35 void SetCsActive(TInt aModule, TInt aChannel)
    35 	{
    36 	{
    36 	//__ASSERT_DEBUG(aModule < KMaxSpiChannelsPerModule, Kern::Fault("omap3530_spi.inl, line: ", __LINE__)); // aChannel > module channels
    37 	//__ASSERT_DEBUG(aModule < KMaxSpiChannelsPerModule, Kern::Fault("omap3530_spi.inl, line: ", __LINE__)); // aChannel > module channels
    37 	TUint16 csPinOptions = aActiveMode == ESpiCSPinActiveLow ? KCsPinModeUp : KCsPinModeDown;
       
    38 	const TPinConfig &csConf = ModulePinConfig[aModule].iCs[aChannel];
    38 	const TPinConfig &csConf = ModulePinConfig[aModule].iCs[aChannel];
    39 	__ASSERT_DEBUG(csConf.iAddress, Kern::Fault("omap3530_spi.inl, line: ", __LINE__)); // aChannel > module channels
    39 	__ASSERT_DEBUG(csConf.iAddress, Kern::Fault("omap3530_spi.inl, line: ", __LINE__)); // aChannel > module channels
    40 
    40 
    41 	// now switch the pin mode back to the SPI
    41 	// now switch the pin mode back to the SPI
    42 	SCM::SetPadConfig(csConf.iAddress, csConf.iMswLsw, csConf.iFlags | csPinOptions); // revert to intended mode
    42 	SCM::SetPadConfig(csConf.iAddress, csConf.iMswLsw, csConf.iFlags | SCM::EInputEnable); // revert to intended mode
    43 	}
    43 	}
    44 
    44 
    45 
    45 
    46 // Setup pad function for SPI pins..
    46 // Setup pad function for SPI pins..
    47 void SetupSpiPins(TUint aSpiModule)
    47 void SetupSpiPins(TUint aSpiModule)
    49 	//__ASSERT_DEBUG(aModule < KMaxSpiChannelsPerModule, Kern::Fault("omap3530_spi.inl, line: ", __LINE__)); // aChannel > module channels
    49 	//__ASSERT_DEBUG(aModule < KMaxSpiChannelsPerModule, Kern::Fault("omap3530_spi.inl, line: ", __LINE__)); // aChannel > module channels
    50 	const TSpiPinConfig& pinCnf = ModulePinConfig[aSpiModule];
    50 	const TSpiPinConfig& pinCnf = ModulePinConfig[aSpiModule];
    51 	SCM::SetPadConfig(pinCnf.iClk.iAddress, pinCnf.iClk.iMswLsw, pinCnf.iClk.iFlags);
    51 	SCM::SetPadConfig(pinCnf.iClk.iAddress, pinCnf.iClk.iMswLsw, pinCnf.iClk.iFlags);
    52 	SCM::SetPadConfig(pinCnf.iSimo.iAddress, pinCnf.iSimo.iMswLsw, pinCnf.iSimo.iFlags);
    52 	SCM::SetPadConfig(pinCnf.iSimo.iAddress, pinCnf.iSimo.iMswLsw, pinCnf.iSimo.iFlags);
    53 	SCM::SetPadConfig(pinCnf.iSomi.iAddress, pinCnf.iSomi.iMswLsw, pinCnf.iSomi.iFlags);
    53 	SCM::SetPadConfig(pinCnf.iSomi.iAddress, pinCnf.iSomi.iMswLsw, pinCnf.iSomi.iFlags);
    54 	// Cs pins are set dynamically during operations.
    54 
       
    55 	// Setup GPIO mode/direction for all CS pins only once - here.
       
    56 	for(TInt i = 0; i < KMaxSpiChannelsPerModule; i++)
       
    57 		{
       
    58 		if(pinCnf.iCs[i].iPinNumber)
       
    59 			{
       
    60 			GPIO::SetPinDirection(pinCnf.iCs[i].iPinNumber, GPIO::EOutput);
       
    61 			GPIO::SetPinMode(pinCnf.iCs[i].iPinNumber, GPIO::EEnabled);
       
    62 			}
       
    63 		else
       
    64 			{
       
    65 			break;
       
    66 			}
       
    67 		}
    55 	}
    68 	}
    56 
    69 
    57 // helper function - returns appropriate value for the register for a given mode
    70 // helper function - returns appropriate value for the register for a given mode
    58 inline TUint32 SpiClkMode(TSpiClkMode aClkMode)
    71 inline TUint32 SpiClkMode(TSpiClkMode aClkMode)
    59 	{
    72 	{