bsptemplate/asspandvariant/template_assp/gpio.cpp
changeset 90 947f0dc9f7a8
parent 0 a41df078684a
child 257 3e88ff8f41d5
--- a/bsptemplate/asspandvariant/template_assp/gpio.cpp	Tue Feb 02 01:24:03 2010 +0200
+++ b/bsptemplate/asspandvariant/template_assp/gpio.cpp	Fri Apr 16 16:24:37 2010 +0300
@@ -39,6 +39,87 @@
 
 static TInt32	GpioInterruptId; // place to store interrupt handle returned from Interrupt::Bind()
 
+
+/**
+Calculate 16-bit device pin Id from 32-bit pin Id. Use DeviceId() to 
+get device Id.
+@param   aId         32-bit pin Id
+@return  16-bit device specific pin Id
+ */
+static inline TUint16 DevicePinId(TInt aId)
+    {return static_cast<TUint16>(aId & 0x0000FFFF);}
+
+
+//Commented out to satisfy compiler(as method is not used in the code) but can  
+//be usefull later
+/**
+Calculate and return GPIO device Id(either SOC or one of the extenders)
+defined in TGpioBaseId from the 32-bit pin Id
+@param   aId         32-bit pin Id
+@return
+   - EInternalId              SOC GPIO 
+   - EExtender0-15            GPIO extenders from 0-15
+
+static inline GPIO::TGpioBaseId ExtenderId(TInt aId)
+    {return static_cast<GPIO::TGpioBaseId>((aId & 0xFFFF0000));}
+*/
+
+//Commented out to satisfy compiler(as method is not used in the code) but can  
+//be usefull later
+/**
+Generate 32-bit pin Id from the device Id and device specific 16-bit 
+pin Id.
+@param   aExtenderId     Device Id is defined in TGpioBaseId
+@param   aPinId          16-bit device pin Id
+return   32-bit pin Id  
+
+static inline TInt Id(GPIO::TGpioBaseId aExtenderId, TUint16 aPinId)
+    {return static_cast<TInt>(aExtenderId |aPinId);}
+*/
+
+//Commented out to satisfy compiler(as method is not used in the code) but can  
+//be usefull later
+/**
+Find index in extender GPIO device table.
+@param   aExtenderId     Extender Id is defined in TGpioBaseId
+@return  singned 32-bit integer index device, possible value 
+        from 0 to 15
+ 
+static TInt DeviceIndex(GPIO::TGpioBaseId aExtenderId)
+    {
+    TUint16 val = (TUint16)((aExtenderId & 0xFFFF0000) >> 16);
+    if(val == 0) return GPIO::EInternalId;
+
+    //The algorithm steps througth the value until first non-zero bit is
+    //found.
+    //
+    TInt index = 0;
+    if(val & 0xFF00) {index  = 8; val = val >> 8;} // 2 x 8-bits
+    if(val & 0x00F0) {index += 4; val = val >> 4;} // 2 x 4-bits
+    if(val & 0x000C) {index += 2; val = val >> 2;} // 2 x 2 bits
+    if(val & 0x0002) {index += 1; val = val >> 1;} // 2 x 1 bits
+
+    return index;
+    }
+*/
+
+
+//Commented out to satisfy compiler(as method is not used in the code) but can  
+//be usefull later
+/**
+Find index in extender GPIO device table.
+@param   aId    32-bit GPIO pin Id
+@return  singned 32-bit integer index device, possible value 
+         from 0 to 15
+
+static TInt DeviceIndex(TInt aId){return DeviceIndex(ExtenderId(aId));}
+*/
+
+
+
+
+
+
 /**
 GPIO interrupt handler
 generic argument (TAny*) is a pointer to the GpioPins array
@@ -72,7 +153,8 @@
    	TGpioMode aMode
 	)
 	{
-	if (aId < 0 || aId > KHwGpioPinMax)
+    TUint16 pinId = DevicePinId(aId);
+	if (pinId > KHwGpioPinMax)
 		{
 		return KErrArgument;
 		}
@@ -86,7 +168,8 @@
    	TGpioMode & aMode
 	)
 	{
-	if (aId < 0 || aId > KHwGpioPinMax)
+    TUint16 pinId = DevicePinId(aId);
+	if (pinId > KHwGpioPinMax)
 		{
 		return KErrArgument;
 		}
@@ -100,7 +183,8 @@
    	TGpioDirection aDirection
 	)
 	{
-	if (aId < 0 || aId > KHwGpioPinMax || aDirection == ETriStated)
+    TUint16 pinId = DevicePinId(aId);
+	if (pinId > KHwGpioPinMax || aDirection == ETriStated)
 		{
 		return KErrArgument;
 		}
@@ -114,7 +198,8 @@
    	TGpioDirection & aDirection
 	)
 	{
-	if (aId < 0 || aId > KHwGpioPinMax)
+    TUint16 pinId = DevicePinId(aId);
+	if (pinId > KHwGpioPinMax)
 		{
 		return KErrArgument;
 		}
@@ -128,7 +213,8 @@
    	TGpioBias aBias
 	)
 	{
-	if (aId < 0 || aId > KHwGpioPinMax)
+    TUint16 pinId = DevicePinId(aId);
+	if (pinId > KHwGpioPinMax)
 		{
 		return KErrArgument;
 		}
@@ -142,7 +228,8 @@
    	TGpioBias & aBias
 	)
 	{
-	if (aId < 0 || aId > KHwGpioPinMax)
+    TUint16 pinId = DevicePinId(aId);
+	if (pinId > KHwGpioPinMax)
 		{
 		return KErrArgument;
 		}
@@ -156,7 +243,8 @@
    	TInt		/*aConf*/
 	)
 	{
-	if (aId < 0 || aId > KHwGpioPinMax)
+    TUint16 pinId = DevicePinId(aId);
+	if (pinId > KHwGpioPinMax)
 		{
 		return KErrArgument;
 		}
@@ -170,7 +258,8 @@
    	TInt	  & aBias
 	)
 	{
-	if (aId < 0 || aId > KHwGpioPinMax)
+    TUint16 pinId = DevicePinId(aId);
+	if (pinId > KHwGpioPinMax)
 		{
 		return KErrArgument;
 		}
@@ -185,18 +274,19 @@
    	TAny *   aPtr
 	)
 	{
-	if (aId < 0 || aId > KHwGpioPinMax || aIsr == NULL)
+    TUint16 pinId = DevicePinId(aId);
+	if (pinId > KHwGpioPinMax || aIsr == NULL)
 		{
 		return KErrArgument;
 		}
-	if (GpioPins[aId].iIsr != NULL)
+	if (GpioPins[pinId].iIsr != NULL)
 		{
 		// already bound
 		return KErrInUse;
 		}
 	// record isr and arg bound to this pin
-	GpioPins[aId].iIsr = aIsr;
-	GpioPins[aId].iPtr = aPtr;
+	GpioPins[pinId].iIsr = aIsr;
+	GpioPins[pinId].iPtr = aPtr;
 	return KErrNone;
 	}
 
@@ -205,18 +295,19 @@
 	TInt aId
 	)
 	{
-	if (aId < 0 || aId > KHwGpioPinMax)
+    TUint16 pinId = DevicePinId(aId);
+	if (pinId > KHwGpioPinMax)
 		{
 		return KErrArgument;
 		}
-	if (GpioPins[aId].iIsr == NULL)
+	if (GpioPins[pinId].iIsr == NULL)
 		{
 		// nothing bound
 		return KErrGeneral;
 		}
 	// NULL isr bound to this pin
-	GpioPins[aId].iIsr = NULL;
-	GpioPins[aId].iPtr = NULL;
+	GpioPins[pinId].iIsr = NULL;
+	GpioPins[pinId].iPtr = NULL;
 	return KErrNone;
 	}
 
@@ -225,11 +316,12 @@
 	TInt aId
 	)
 	{
-	if (aId < 0 || aId > KHwGpioPinMax)
+    TUint16 pinId = DevicePinId(aId);
+	if (pinId > KHwGpioPinMax)
 		{
 		return KErrArgument;
 		}
-	if (GpioPins[aId].iIsr == NULL)
+	if (GpioPins[pinId].iIsr == NULL)
 		{
 		// nothing bound
 		return KErrGeneral;
@@ -243,11 +335,12 @@
 	TInt aId
 	)
 	{
-	if (aId < 0 || aId > KHwGpioPinMax)
+    TUint16 pinId = DevicePinId(aId);
+	if (pinId > KHwGpioPinMax)
 		{
 		return KErrArgument;
 		}
-	if (GpioPins[aId].iIsr == NULL)
+	if (GpioPins[pinId].iIsr == NULL)
 		{
 		// nothing bound
 		return KErrGeneral;
@@ -262,11 +355,12 @@
    	TBool & aEnable
 	)
 	{
-	if (aId < 0 || aId > KHwGpioPinMax)
+    TUint16 pinId = DevicePinId(aId);
+	if (pinId > KHwGpioPinMax)
 		{
 		return KErrArgument;
 		}
-	if (GpioPins[aId].iIsr == NULL)
+	if (GpioPins[pinId].iIsr == NULL)
 		{
 		// nothing bound
 		return KErrGeneral;
@@ -280,11 +374,12 @@
 	TInt aId
 	)
 	{
-	if (aId < 0 || aId > KHwGpioPinMax)
+    TUint16 pinId = DevicePinId(aId);
+	if (pinId > KHwGpioPinMax)
 		{
 		return KErrArgument;
 		}
-	if (GpioPins[aId].iIsr == NULL)
+	if (GpioPins[pinId].iIsr == NULL)
 		{
 		// nothing bound
 		return KErrGeneral;
@@ -299,7 +394,8 @@
    	TBool & aActive
 	)
 	{
-	if (aId < 0 || aId > KHwGpioPinMax)
+    TUint16 pinId = DevicePinId(aId);
+	if (pinId > KHwGpioPinMax)
 		{
 		return KErrArgument;
 		}
@@ -313,7 +409,8 @@
    	TBool & aActive
 	)
 	{
-	if (aId < 0 || aId > KHwGpioPinMax)
+    TUint16 pinId = DevicePinId(aId);
+	if (pinId > KHwGpioPinMax)
 		{
 		return KErrArgument;
 		}
@@ -327,7 +424,8 @@
    	TGpioDetectionTrigger aTrigger
 	)
 	{
-	if (aId < 0 || aId > KHwGpioPinMax)
+    TUint16 pinId = DevicePinId(aId);
+	if (pinId > KHwGpioPinMax)
 		{
 		return KErrArgument;
 		}
@@ -340,7 +438,8 @@
 	TInt aId
 	)
 	{
-	if (aId < 0 || aId > KHwGpioPinMax)
+    TUint16 pinId = DevicePinId(aId);
+	if (pinId > KHwGpioPinMax)
 		{
 		return KErrArgument;
 		}
@@ -353,7 +452,8 @@
 	TInt aId
 	)
 	{
-	if (aId < 0 || aId > KHwGpioPinMax)
+    TUint16 pinId = DevicePinId(aId);
+	if (pinId > KHwGpioPinMax)
 		{
 		return KErrArgument;
 		}
@@ -367,7 +467,8 @@
    	TBool & aEnable
 	)
 	{
-	if (aId < 0 || aId > KHwGpioPinMax)
+    TUint16 pinId = DevicePinId(aId);
+	if (pinId > KHwGpioPinMax)
 		{
 		return KErrArgument;
 		}
@@ -381,7 +482,8 @@
    	TGpioDetectionTrigger aTrigger
 	)
 	{
-	if (aId < 0 || aId > KHwGpioPinMax)
+    TUint16 pinId = DevicePinId(aId);
+	if (pinId > KHwGpioPinMax)
 		{
 		return KErrArgument;
 		}
@@ -395,7 +497,8 @@
    	TInt aTime
 	)
 	{
-	if (aId < 0 || aId > KHwGpioPinMax)
+    TUint16 pinId = DevicePinId(aId);
+	if (pinId > KHwGpioPinMax)
 		{
 		return KErrArgument;
 		}
@@ -410,7 +513,8 @@
    	TInt & aTime
 	)
 	{
-	if (aId < 0 || aId > KHwGpioPinMax)
+    TUint16 pinId = DevicePinId(aId);
+	if (pinId > KHwGpioPinMax)
 		{
 		return KErrArgument;
 		}
@@ -424,7 +528,8 @@
    	TGpioState & aState
 	)
 	{
-	if (aId < 0 || aId > KHwGpioPinMax)
+    TUint16 pinId = DevicePinId(aId);
+	if (pinId > KHwGpioPinMax)
 		{
 		return KErrArgument;
 		}
@@ -442,7 +547,8 @@
    	TGpioState aState
 	)
 	{
-	if (aId < 0 || aId > KHwGpioPinMax)
+    TUint16 pinId = DevicePinId(aId);
+	if (pinId > KHwGpioPinMax)
 		{
 		return KErrArgument;
 		}
@@ -456,7 +562,8 @@
    	TGpioState & aState
 	)
 	{
-	if (aId < 0 || aId > KHwGpioPinMax)
+    TUint16 pinId = DevicePinId(aId);
+	if (pinId > KHwGpioPinMax)
 		{
 		return KErrArgument;
 		}
@@ -470,7 +577,8 @@
    	TGpioCallback		* aCb
 	)
 	{
-	if (aId < 0 || aId > KHwGpioPinMax)
+    TUint16 pinId = DevicePinId(aId);
+	if (pinId > KHwGpioPinMax)
 		{
 		return KErrArgument;
 		}
@@ -485,7 +593,8 @@
    	TGpioCallback		* aCb
 	)
 	{
-	if (aId < 0 || aId > KHwGpioPinMax)
+    TUint16 pinId = DevicePinId(aId);
+	if (pinId > KHwGpioPinMax)
 		{
 		return KErrArgument;
 		}
@@ -501,7 +610,8 @@
 	TAny	* aArg2
 	)
 	{
-	if (aId < 0 || aId > KHwGpioPinMax)
+    TUint16 pinId = DevicePinId(aId);
+	if (pinId > KHwGpioPinMax)
 		{
 		return KErrArgument;
 		}