]> rtime.felk.cvut.cz Git - arc.git/commitdiff
Added pin multiplexing for the LED Blinker example
authorLeos Mikulka <mikulleo@fel.cvut.cz>
Tue, 19 Feb 2013 10:47:15 +0000 (11:47 +0100)
committerLeos Mikulka <mikulleo@fel.cvut.cz>
Tue, 19 Feb 2013 10:47:15 +0000 (11:47 +0100)
arch/arm/arm_cr4/drivers/Port.c
include/Port.h

index fb764f08186c81bcc556c576f17a122a3a78daf4..67446fbeac69a6a4a79b7409128a6c624fcc34f4 100644 (file)
@@ -46,9 +46,9 @@ typedef volatile struct
 \r
 #define PORT_NOT_CONFIGURED 0x00000000\r
 \r
-#define PORT_0_BASE ((Port_RegisterType *)0xFFF7BC30)                  // GIO Emulation B register\r
-#define PORT_1_BASE ((Port_RegisterType *)0xFFF7BC50)                  // GIO Pull Select Register A ??\r
-#define PORT_2_BASE ((Port_RegisterType *)0xFFF7B848)                  // N2HET1\r
+#define PORT_0_BASE ((Port_RegisterType *)0xFFF7BC30)\r
+#define PORT_1_BASE ((Port_RegisterType *)0xFFF7BC50)\r
+#define PORT_2_BASE ((Port_RegisterType *)0xFFF7B848)                  // N2HET1 Base\r
 #define PORT_3_BASE ((Port_RegisterType *)PORT_NOT_CONFIGURED)\r
 #define PORT_4_BASE ((Port_RegisterType *)PORT_NOT_CONFIGURED)\r
 #define PORT_5_BASE ((Port_RegisterType *)PORT_NOT_CONFIGURED)\r
@@ -74,7 +74,74 @@ static Port_RegisterType * const Port_Base[] =
     PORT_10_BASE,\r
 };\r
 \r
-\r
+typedef volatile uint32 PinMuxBase;\r
+\r
+#define PINMUX0  ((PinMuxBase *)0xFFFFEB10)\r
+#define PINMUX1  ((PinMuxBase *)0xFFFFEB14)\r
+#define PINMUX2  ((PinMuxBase *)0xFFFFEB18)\r
+#define PINMUX3  ((PinMuxBase *)0xFFFFEB1C)\r
+#define PINMUX4  ((PinMuxBase *)0xFFFFEB20)\r
+#define PINMUX5  ((PinMuxBase *)0xFFFFEB24)\r
+#define PINMUX6  ((PinMuxBase *)0xFFFFEB28)\r
+#define PINMUX7  ((PinMuxBase *)0xFFFFEB2C)\r
+#define PINMUX8  ((PinMuxBase *)0xFFFFEB30)\r
+#define PINMUX9  ((PinMuxBase *)0xFFFFEB34)\r
+#define PINMUX10 ((PinMuxBase *)0xFFFFEB38)\r
+#define PINMUX11 ((PinMuxBase *)0xFFFFEB3C)\r
+#define PINMUX12 ((PinMuxBase *)0xFFFFEB40)\r
+#define PINMUX13 ((PinMuxBase *)0xFFFFEB44)\r
+#define PINMUX14 ((PinMuxBase *)0xFFFFEB48)\r
+#define PINMUX15 ((PinMuxBase *)0xFFFFEB4C)\r
+#define PINMUX16 ((PinMuxBase *)0xFFFFEB50)\r
+#define PINMUX17 ((PinMuxBase *)0xFFFFEB54)\r
+#define PINMUX18 ((PinMuxBase *)0xFFFFEB58)\r
+#define PINMUX19 ((PinMuxBase *)0xFFFFEB5C)\r
+#define PINMUX20 ((PinMuxBase *)0xFFFFEB60)\r
+#define PINMUX21 ((PinMuxBase *)0xFFFFEB64)\r
+#define PINMUX22 ((PinMuxBase *)0xFFFFEB68)\r
+#define PINMUX23 ((PinMuxBase *)0xFFFFEB6C)\r
+#define PINMUX24 ((PinMuxBase *)0xFFFFEB70)\r
+#define PINMUX25 ((PinMuxBase *)0xFFFFEB74)\r
+#define PINMUX26 ((PinMuxBase *)0xFFFFEB78)\r
+#define PINMUX27 ((PinMuxBase *)0xFFFFEB7C)\r
+#define PINMUX28 ((PinMuxBase *)0xFFFFEB80)\r
+#define PINMUX29 ((PinMuxBase *)0xFFFFEB84)\r
+#define PINMUX30 ((PinMuxBase *)0xFFFFEB88)\r
+\r
+static PinMuxBase * PinMux_Base[] =\r
+{\r
+       PINMUX0,\r
+       PINMUX1,\r
+       PINMUX2,\r
+       PINMUX3,\r
+       PINMUX4,\r
+       PINMUX5,\r
+       PINMUX6,\r
+       PINMUX7,\r
+       PINMUX8,\r
+       PINMUX9,\r
+       PINMUX10,\r
+       PINMUX11,\r
+       PINMUX12,\r
+       PINMUX13,\r
+       PINMUX14,\r
+       PINMUX15,\r
+       PINMUX16,\r
+       PINMUX17,\r
+       PINMUX18,\r
+       PINMUX19,\r
+       PINMUX20,\r
+       PINMUX21,\r
+       PINMUX22,\r
+       PINMUX23,\r
+       PINMUX24,\r
+       PINMUX25,\r
+       PINMUX26,\r
+       PINMUX27,\r
+       PINMUX28,\r
+       PINMUX29,\r
+       PINMUX30\r
+};\r
 \r
 static Port_StateType _portState = PORT_UNINITIALIZED;\r
 static const Port_ConfigType * _configPtr = &PortConfigData;\r
@@ -124,6 +191,22 @@ void Port_RefreshPin(uint16 pinNumber) {
        uint32 mask = GET_PIN_MASK(_configPtr->pins[pinNumber].pin);\r
        uint16 conf = _configPtr->pins[pinNumber].conf;\r
 \r
+       uint32 pinmux = _configPtr->pins[pinNumber].pinmux;\r
+       uint8 pinmuxFunctionNum = _configPtr->pins[pinNumber].pinmuxFunctionNum;\r
+       uint8 pinmuxBaseNum = _configPtr->pins[pinNumber].pinmuxBaseNum;\r
+\r
+       /* Enable Pin Muxing */\r
+               kickerReg->KICKER0 = 0x83E70B13;\r
+               kickerReg->KICKER1 = 0x95A4F1E0;\r
+\r
+       /* ex.: Hack to connect N2HET1[27] (function 2) to pin A9 */\r
+       *PinMux_Base[pinmuxBaseNum] &= (~(0xFF << pinmux));//\r
+       *PinMux_Base[pinmuxBaseNum] |= (~(pinmuxFunctionNum << pinmux));\r
+\r
+       /* Disable Pin Muxing */\r
+               kickerReg->KICKER0 = 0x00000000;\r
+               kickerReg->KICKER1 = 0x00000000;\r
+\r
        if (conf & PORT_FUNC) {\r
                // Don't do anything, let each driver configure???\r
                return;\r
@@ -160,18 +243,15 @@ void Port_RefreshPin(uint16 pinNumber) {
 }\r
 \r
 \r
-\r
 void Port_Init(const Port_ConfigType *configType) {\r
        VALIDATE_PARAM_CONFIG(configType, PORT_INIT_ID);\r
 \r
        _configPtr = (Port_ConfigType *)configType;\r
 \r
-       // Bring GIO register out of reset.\r
+       /* Bring GIO register out of reset. */\r
        gioREG->GCR0 = 1;\r
-\r
-       /* Hack to connect N2HET1[27] (function 2) to pin A9 */\r
-       *(volatile uint32*)0xFFFFEB10 &= ~0xFF000000;\r
-       *(volatile uint32*)0xFFFFEB10 |= ~0x04000000;\r
+    gioREG->INTENACLR = 0xFF;  // Interrupt Enable Clear Register\r
+    gioREG->LVLCLR    = 0xFF;  // Interrupt Priority Clear Register\r
 \r
        for (uint16 i = 0; i < PORT_NUMBER_OF_PINS; i++) {\r
                Port_RefreshPin(i);\r
@@ -188,8 +268,8 @@ void Port_SetPinDirection( Port_PinType pin, Port_PinDirectionType direction )
        VALIDATE_STATE_INIT(PORT_SET_PIN_DIRECTION_ID);\r
        VALIDATE_PARAM_PIN(pin, PORT_SET_PIN_DIRECTION_ID);\r
 \r
-       uint8 port = GET_PIN_PORT(pin);\r
-       uint32 mask = GET_PIN_MASK(pin);\r
+       uint8 port = GET_PIN_PORT(pin);         // ex.: LED1 - 0x021b >> 8 = 2 (uint8)\r
+       uint32 mask = GET_PIN_MASK(pin);        // ex.: LED1 - 1 << (0x1b) = 0x08000000 (uint32)\r
 \r
        if (direction & PORT_PIN_IN) {\r
                Port_Base[port]->DIR |= mask;\r
@@ -229,6 +309,10 @@ void Port_SetPinMode(Port_PinType Pin, Port_PinModeType Mode) {
        VALIDATE_STATE_INIT(PORT_SET_PIN_MODE_ID);\r
        VALIDATE_PARAM_PIN(Pin, PORT_SET_PIN_MODE_ID);\r
 \r
+       #if (PORT_DEV_ERROR_DETECT == STD_ON)\r
+               Det_ReportError(MODULE_ID_PORT, 0, PORT_SET_PIN_MODE_ID, PORT_E_MODE_UNCHANGEABLE );\r
+       #endif\r
+\r
        uint8 port = GET_PIN_PORT(Pin);\r
        uint8 pin = GET_PIN_PIN(Pin);\r
        uint32 mask = GET_PIN_MASK(Pin);\r
index dc8af9ba9e72e9b54e3d8a1d6a335fe64c8c56a6..a5fa82d9f8a5e63bdb2d82ea99816ffc678066df 100644 (file)
@@ -27,6 +27,7 @@
 #define PORT_SW_MINOR_VERSION 0
 #define PORT_SW_PATCH_VERSION 0
 
+/** @req PORT114 */
 #define PORT_AR_MAJOR_VERSION 3
 #define PORT_AR_MINOR_VERSION 1
 #define PORT_AR_PATCH_VERSION 0
@@ -47,6 +48,7 @@ void Port_GetVersionInfo(Std_VersionInfoType *versionInfo);
 #define PORT_E_PARAM_INVALID_MODE     0x0d
 #define PORT_E_MODE_UNCHANGEABLE      0x0e
 #define PORT_E_UNINIT                 0x0f
+#define PORT_E_PARAM_POINTER             0x10
 //@}
 
 /** @name Service id's */
@@ -87,5 +89,17 @@ void Port_RefreshPortDirection(void);
 void Port_SetPinMode(Port_PinType Pin, Port_PinModeType Mode);
 #endif
 
+typedef volatile struct pinMuxKicker
+{
+    uint32 KICKER0;       /* kicker 0 register */
+    uint32 KICKER1;       /* kicker 1 register */
+} pinMuxKICKER;
+
+/** @def kickerReg
+*   @brief Pin Muxing Kicker Register Frame Pointer
+*      - used to enable and disable muxing across the device.
+*/
+#define kickerReg ((pinMuxKICKER *) 0xFFFFEA38)
+
 #endif /*PORT_H_*/
 /** @} */