Bug 3620 - Update for LED driver generic_fixes_and_updates
authorLukasz Forynski <lukasz.forynski@gmail.com>
Wed, 25 Aug 2010 02:53:30 +0100
branchgeneric_fixes_and_updates
changeset 54 4dfcb6499328
parent 53 1a6d5cf981cd
child 55 fa7dcb51ca22
Bug 3620 - Update for LED driver
omap3530/beagle_drivers/led/led.cpp
omap3530/beagle_drivers/led/led.mmp
omap3530/beagleboard/inc/beagle_gpio.h
omap3530/beagleboard/rom/base_beagle.iby
omap3530/beagleboard/rom/kernel.iby
--- a/omap3530/beagle_drivers/led/led.cpp	Wed Aug 25 01:56:36 2010 +0100
+++ b/omap3530/beagle_drivers/led/led.cpp	Wed Aug 25 02:53:30 2010 +0100
@@ -13,82 +13,106 @@
 // Description:
 // omap3530/beagle_drivers/led/led.cpp
 //
+#include <beagle/beagle_gpio.h>
 
-#include <kern_priv.h>
-#include <beagle/beagle_gpio.h>
-#include <assp/omap3530_assp/omap3530_gpio.h>
-#include <beagle/variant.h>
-#include <assp/omap3530_assp/omap3530_assp_priv.h>
-#include <assp/omap3530_assp/omap3530_irqmap.h> // GPIO interrupts
-
-#include <assp.h> // Required for definition of TIsr
+const TInt KBeatTimeInSeconds = 4;
 
-static NTimer * heartBeatTimer;
-
-
+class LedHeartBeat
+	{
+public:
+	inline LedHeartBeat();
+	/*inline ~LedHeartBeat() { iTimer.Cancel(); }*/ // will it ever be destroyed?
+	TInt DoCreate();
+	static void Beat(TAny *aPtr);
+private:
+	NTimer iTimer;
+	TBool iIsLedOn;
+	};
 
-static void ledIsr(TAny* aPtr)
-	{									
-	//make sure the led is always in the sma estate when we crash
-	
-	GPIO::SetOutputState(KGPIO_LED1, GPIO::ELow);
-	Kern::Fault("User invoked crash via keypad",KErrDied);
+LedHeartBeat::LedHeartBeat() :
+	iTimer(Beat, this)
+	{
 	}
 
-static void beatLedHeartBeat(TAny * ptr)
+TInt LedHeartBeat::DoCreate()
 	{
-	GPIO::TGpioState ledState;
-	GPIO::GetOutputState(KGPIO_LED1, ledState);
-		
-	if(GPIO::EHigh == ledState)
+	TInt r = GPIO::SetPinDirection(KGPIO_LED0, GPIO::EOutput);
+	if (r != KErrNone)
 		{
-		GPIO::SetOutputState(KGPIO_LED1, GPIO::ELow);
+		Kern::Printf("LedHeartBeat: SetPinDirection for LED failed, r %d", r);
+		}
+	GPIO::SetPinMode(KGPIO_LED0, GPIO::EEnabled);
+	GPIO::SetOutputState(KGPIO_LED0, GPIO::ELow);
+	iTimer.OneShot(NKern::TimerTicks(KBeatTimeInSeconds * 1000));
+	return r;
+	}
+
+void LedHeartBeat::Beat(TAny * aPtr)
+	{
+	LedHeartBeat* b = (LedHeartBeat*)aPtr;
+	if(b->iIsLedOn)
+		{
+		GPIO::SetOutputState(KGPIO_LED0, GPIO::ELow);
+		b->iIsLedOn = EFalse;
 		}
 	else
 		{
-		GPIO::SetOutputState(KGPIO_LED1, GPIO::EHigh);
+		GPIO::SetOutputState(KGPIO_LED0, GPIO::EHigh);
+		b->iIsLedOn = ETrue;
 		}
-	
-	heartBeatTimer->Again(Variant::GetMsTickPeriod());
+	b->iTimer.Again(NKern::TimerTicks(KBeatTimeInSeconds * 1000));
+	}
+
+// the following macro is defined in led.mmp file..
+#ifdef USER_BUTTON_ENTERS_CRASH_DEBUGGER
+static void UserButtonIsr(TAny* aPtr)
+	{
+	//make sure the heartbeat led is OFF when we crash
+	GPIO::SetOutputState(KGPIO_LED0, GPIO::ELow);
+	Kern::Printf("User button pressed, entering crash debugger..\n");
+	Kern::Fault("led.cpp", __LINE__);
 	}
 
+TInt SetupUserButton()
+	{
+	TInt r = GPIO::BindInterrupt(KGPIO_UserButton, UserButtonIsr, NULL);
+	if(r != KErrNone)
+		{
+		Kern::Printf("GPIO::BindInterrupt() failed for button %d, r=%d, (is in use?)",
+		             KGPIO_UserButton, r);
+		return r;
+		}
+
+	r = GPIO::SetInterruptTrigger(KGPIO_UserButton, GPIO::EEdgeRising);
+	if(r == KErrNone)
+		{
+		r = GPIO::SetPinDirection(KGPIO_UserButton, GPIO::EInput);
+		if(r == KErrNone)
+			{
+			GPIO::SetDebounceTime(KGPIO_UserButton, 500);
+			GPIO::SetPinMode(KGPIO_UserButton, GPIO::EEnabled);
+			r = GPIO::EnableInterrupt(KGPIO_UserButton);
+			}
+		}
+	return r;
+	}
+#endif
 
 DECLARE_STANDARD_EXTENSION()
 	{
-		
-	//Set up the button to proivde a panic button invoking Fault()
-	if(KErrNone != GPIO::SetPinDirection(KGPIO_UserButton, GPIO::EInput))
-		return KErrArgument;
-		
-	GPIO::SetPinMode(KGPIO_UserButton, GPIO::EEnabled);
-	GPIO::SetDebounceTime(KGPIO_UserButton, 500);
-	
-	if(KErrNone !=GPIO::BindInterrupt(KGPIO_UserButton, ledIsr,NULL))
-		return KErrArgument;
-		
-	if(KErrNone !=GPIO::SetInterruptTrigger(KGPIO_UserButton, GPIO::EEdgeRising))
-		return KErrArgument;
-		
-	if(KErrNone !=GPIO::EnableInterrupt(KGPIO_UserButton))
+	TInt r = KErrNoMemory;
+	LedHeartBeat* beat = new LedHeartBeat;
+	if(beat)
 		{
-		GPIO::UnbindInterrupt(KGPIO_UserButton);
-		return KErrInUse;
-		}		
+		r = beat->DoCreate();
+		}
 
-	//setup the Led to flash at the system tick rate ( heartbeat) 
-	heartBeatTimer = new NTimer(beatLedHeartBeat,NULL);
-	
-	if(KErrNone != GPIO::SetPinDirection(KGPIO_LED1, GPIO::EOutput))
-			return KErrArgument;
-	
-	if(KErrNone != GPIO::SetPinDirection(KGPIO_LED0, GPIO::EOutput))
-				return KErrArgument;
-
-	GPIO::SetPinMode(KGPIO_LED0, GPIO::EEnabled);
-	GPIO::SetPinMode(KGPIO_LED1, GPIO::EEnabled);
-	GPIO::SetOutputState(KGPIO_LED0, GPIO::ELow);	
-	
-	heartBeatTimer->OneShot(Variant::GetMsTickPeriod(),ETrue);
-	return KErrNone;	
+#ifdef USER_BUTTON_ENTERS_CRASH_DEBUGGER
+	if(r == KErrNone)
+		{
+		r = SetupUserButton();
+		}
+#endif
+	return r;
 	}
 
--- a/omap3530/beagle_drivers/led/led.mmp	Wed Aug 25 01:56:36 2010 +0100
+++ b/omap3530/beagle_drivers/led/led.mmp	Wed Aug 25 02:53:30 2010 +0100
@@ -30,6 +30,11 @@
 targettype			kext
 romtarget			led.dll
 
+
+// comment the following macro out - if you don't wan to..
+// ..use USER button to enter the crash debugger
+macro USER_BUTTON_ENTERS_CRASH_DEBUGGER
+
 sourcepath			.
 source				led.cpp
 
--- a/omap3530/beagleboard/inc/beagle_gpio.h	Wed Aug 25 01:56:36 2010 +0100
+++ b/omap3530/beagleboard/inc/beagle_gpio.h	Wed Aug 25 02:53:30 2010 +0100
@@ -20,13 +20,13 @@
 #include <assp/omap3530_assp/omap3530_gpio.h>
 
 const TUint KGPIOINT_UserButton = EGPIOIRQ_PIN_7;
-const TUint KGPIOINT_LED0 = EGPIOIRQ_PIN_149;
-const TUint KGPIOINT_LED1 = EGPIOIRQ_PIN_150;
+const TUint KGPIOINT_LED0 = EGPIOIRQ_PIN_150;
+const TUint KGPIOINT_LED1 = EGPIOIRQ_PIN_149;
 const TUint KGPIOINT_TFP410_POWERDOWN = EGPIOIRQ_PIN_170;//DVI_PUP Controls the DVI-D interface. A Hi = DVI-D enabled.
-const TUint KGPIOINT_MMC1_WP = EGPIOIRQ_PIN_29; // I MMC1_WP SD/MMC card slot Write protect 
+const TUint KGPIOINT_MMC1_WP = EGPIOIRQ_PIN_29; // I MMC1_WP SD/MMC card slot Write protect
 
 const TUint KGPIO_UserButton = 7;
-const TUint KGPIO_LED0 = 149;
-const TUint KGPIO_LED1 = 150;
+const TUint KGPIO_LED0 = 150;
+const TUint KGPIO_LED1 = 149;
 
 #endif //__BEAGLE_GPIO_H__
--- a/omap3530/beagleboard/rom/base_beagle.iby	Wed Aug 25 01:56:36 2010 +0100
+++ b/omap3530/beagleboard/rom/base_beagle.iby	Wed Aug 25 02:53:30 2010 +0100
@@ -108,12 +108,15 @@
 extension[VARID]=	KERNEL_DIR\DEBUG_DIR\_PLATFORM_NAME_medstaticrd.pdd		\sys\bin\medstaticrd.pdd
 
 extension[VARID]=\epoc32\release\ARMV5\BUILD_DIR\_omap3530_i2c.dll			\sys\bin\i2c.dll
+
+#include <rom/omap3530/spi.iby>
 #include <../omapshared/tps65950.iby>
 
 #ifdef SYMBIAN_BASE_USE_GCE
 	// Use the new GCE compliant display driver  
 	extension[VARID]=\epoc32\release\ARMV5\BUILD_DIR\_beagle_lcd_gce.dll	\sys\bin\lcd.dll
 	device[VARID]=KERNEL_DIR\DEBUG_DIR\display.ldd			\sys\bin\display0.ldd
+	#file=ABI_DIR\DEBUG_DIR\_beagle_ekdata.dll				\sys\bin\ekdata.dll
 	extension[VARID]=\epoc32\release\ARMV5\BUILD_DIR\_omap3530_serialkeyboard_uisoftkeys.dll	\sys\bin\ekeyb.dll
 #else
 	#ifdef TSHELL_SERIAL
@@ -136,7 +139,7 @@
 //device[VARID]	=KERNEL_DIR\BUILD_DIR\pipelib.ldd							\sys\bin\pipelib.ldd // Removed for clash in 3.0.0
 //device[VARID]	=KERNEL_DIR\BUILD_DIR\minkda.ldd							\sys\bin\minkda.ldd
 extension[VARID]=KERNEL_DIR\BUILD_DIR\exstart.dll							\sys\bin\exstart.dll
-//extension[VARID]=\epoc32\release\ARMV5\BUILD_DIR\_beagle_led.dll						\sys\bin\led.dll
+extension[VARID]=\epoc32\release\ARMV5\BUILD_DIR\_beagle_led.dll						\sys\bin\led.dll
 #ifdef INCLUDE_USB
 extension[VARID]=\epoc32\release\ARMV5\BUILD_DIR\_omap3530_usbcc.dll					\sys\bin\usbcc.dll
 device[VARID]=	KERNEL_DIR\BUILD_DIR\usbc.ldd							\sys\bin\eusbc.ldd
--- a/omap3530/beagleboard/rom/kernel.iby	Wed Aug 25 01:56:36 2010 +0100
+++ b/omap3530/beagleboard/rom/kernel.iby	Wed Aug 25 02:53:30 2010 +0100
@@ -35,7 +35,7 @@
 
 extension[VARID]=	\Epoc32\Release\ARMV5\##BUILD##\_omap3530_GPIO.DLL            	\sys\bin\gpio.dll
 
-//extension[VARID]=	\epoc32\release\ARMV5\##BUILD##\_##VARIANT##_LED.DLL		\sys\bin\led.dll
+extension[VARID]=	\epoc32\release\ARMV5\##BUILD##\_##VARIANT##_LED.DLL		\sys\bin\led.dll
 // Uncommnet to include West Bridge Astoria Symbian Storage driver 
 //extension[VARID]=	\epoc32\release\ARMV5\##BUILD##\_##VARIANT##_WB.DLL		\sys\bin\wb.dll
 //extension[VARID]=	\epoc32\release\ARMV5\##BUILD##\wb.dll		\sys\bin\wb.dll
@@ -45,10 +45,9 @@
 
 extension[VARID]=	\Epoc32\Release\ARMV5\##BUILD##\_omap3530_I2C.DLL                \sys\bin\I2C.DLL
 
+#include <rom/omap3530/spi.iby>
 #include <rom/omapshared/tps65950.iby>
 
-device[VARID]=\Epoc32\Release\ARMV5\##BUILD##\_omap3530_EUART.PDD				\sys\bin\euart.pdd
-device[VARID]=\Epoc32\Release\ARMV5\##BUILD##\ECOMM.LDD						\sys\bin\ecomm.ldd
 #ifdef TSHELL_SERIAL
 	//Use VT100 Over Serial
 #	define EDISP_DRV	\EDISP_VT100.DLL