};\r
#endif\r
\r
-void Port_Init(const Port_ConfigType *configType) {\r
- VALIDATE_PARAM_CONFIG(configType, PORT_INIT_ID);\r
+void Port_RefreshPin(uint16 pinNumber) {\r
+ uint8 port = GET_PIN_PORT(_configPtr->pins[pinNumber].pin);\r
+ uint32 mask = GET_PIN_MASK(_configPtr->pins[pinNumber].pin);\r
+ uint16 conf = _configPtr->pins[pinNumber].conf;\r
+\r
+ if (conf & PORT_FUNC) {\r
+ // Don't do anything, let each driver configure???\r
+ return;\r
+ }\r
\r
- // Bring GIO register out of reset.\r
- gioREG->GCR0 = 1;\r
+ // Set pin direction\r
+ if (conf & PORT_PIN_IN) {\r
+ Port_Base[port]->DIR &= ~mask;\r
\r
- for (uint16 i = 0; i < PORT_NUMBER_OF_PINS; i++) {\r
- uint8 port = GET_PIN_PORT(configType->pins[i].pin);\r
- uint32 mask = GET_PIN_MASK(configType->pins[i].pin);\r
- uint16 conf = configType->pins[i].conf;\r
+ } else {\r
+ Port_Base[port]->DIR |= mask;\r
\r
- if (conf & PORT_FUNC) {\r
- // Don't do anything, let each driver configure???\r
- continue;\r
+ // Set open drain\r
+ if (conf & PORT_ODE_ENABLE) {\r
+ Port_Base[port]->PDR |= mask;\r
+ } else {\r
+ Port_Base[port]->PDR &= ~mask;\r
}\r
+ }\r
+\r
+ // Set pull up or down or nothing.\r
+ if (conf & PORT_PULL_NONE) {\r
+ Port_Base[port]->PULDIS |= mask;\r
\r
- // Set pin direction\r
- if (conf & PORT_PIN_IN) {\r
- Port_Base[port]->DIR &= ~mask;\r
+ } else {\r
+ Port_Base[port]->PULDIS &= ~mask;\r
+ if (conf & PORT_PULL_UP) {\r
+ Port_Base[port]->PSL |= mask;\r
\r
} else {\r
- Port_Base[port]->DIR |= mask;\r
-\r
- // Set open drain\r
- if (conf & PORT_ODE_ENABLE) {\r
- Port_Base[port]->PDR |= mask;\r
- } else {\r
- Port_Base[port]->PDR &= ~mask;\r
- }\r
+ Port_Base[port]->PSL &= ~mask;\r
}\r
+ }\r
+}\r
\r
- // Set pull up or down or nothing.\r
- if (conf & PORT_PULL_NONE) {\r
- Port_Base[port]->PULDIS |= mask;\r
\r
- } else {\r
- Port_Base[port]->PULDIS &= ~mask;\r
- if (conf & PORT_PULL_UP) {\r
- Port_Base[port]->PSL |= mask;\r
\r
- } else {\r
- Port_Base[port]->PSL &= ~mask;\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
+ gioREG->GCR0 = 1;\r
+\r
+ for (uint16 i = 0; i < PORT_NUMBER_OF_PINS; i++) {\r
+ Port_RefreshPin(i);\r
}\r
+\r
+ _portState = PORT_INITIALIZED;\r
+\r
cleanup:return;\r
}\r
\r
#if ( PORT_SET_PIN_DIRECTION_API == STD_ON )\r
void Port_SetPinDirection( Port_PinType pin, Port_PinDirectionType direction )\r
{\r
- VALIDATE_STATE_INIT(PORT_SET_PIN_DIRECTION_ID);\r
- VALIDATE_PARAM_PIN(pin, PORT_SET_PIN_DIRECTION_ID);\r
- // TODO IMPLEMENT!\r
+ 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
+\r
+ if (direction & PORT_PIN_IN) {\r
+ Port_Base[port]->DIR &= ~mask;\r
+\r
+ } else {\r
+ Port_Base[port]->DIR |= mask;\r
+\r
+ }\r
\r
cleanup:return;\r
}\r
\r
void Port_RefreshPortDirection( void )\r
{\r
- // TODO IMPLEMENT!\r
+ for (uint16 i = 0; i < PORT_NUMBER_OF_PINS; i++) {\r
+ if (!(_configPtr->pins[i].conf & PORT_DIRECTION_CHANGEABLE)) {\r
+ Port_RefreshPin(i);\r
+ }\r
+ }\r
}\r
\r
+\r
#if PORT_VERSION_INFO_API == STD_ON\r
void Port_GetVersionInfo(Std_VersionInfoType* versionInfo)\r
{\r
uint8 port = GET_PIN_PORT(Pin);\r
uint8 pin = GET_PIN_PIN(Pin);\r
uint32 mask = GET_PIN_MASK(Pin);\r
-/*\r
- Port_PinType pin = Pin & 0x1F;\r
- Port_PinType port = Pin >> 8;\r
- Port_PinType mask = 1 << pin;\r
-*/\r
+\r
Port_Base[port]->FUN &= ~mask;\r
Port_Base[port]->FUN |= ((Mode & 1) << pin);\r
}\r