1 /* -------------------------------- Arctic Core ------------------------------
\r
2 * Arctic Core - the open source AUTOSAR platform http://arccore.com
\r
4 * Copyright (C) 2009 ArcCore AB <contact@arccore.com>
\r
6 * This source code is free software; you can redistribute it and/or modify it
\r
7 * under the terms of the GNU General Public License version 2 as published by the
\r
8 * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.
\r
10 * This program is distributed in the hope that it will be useful, but
\r
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
\r
14 * -------------------------------- Arctic Core ------------------------------*/
\r
17 #include "Std_Types.h"
\r
23 #define GET_PIN_PORT(_pin) (_pin >> 8)
\r
24 #define GET_PIN_PIN(_pin) (_pin & 0x1F)
\r
25 #define GET_PIN_MASK(_pin) (1 << (_pin & 0x1F))
\r
29 PORT_UNINITIALIZED = 0, PORT_INITIALIZED,
\r
33 typedef volatile struct
\r
44 } Port_RegisterType;
\r
47 #define PORT_NOT_CONFIGURED 0x00000000
\r
49 #define PORT_0_BASE ((Port_RegisterType *)0xFFF7BC30)
\r
50 #define PORT_1_BASE ((Port_RegisterType *)0xFFF7BC50)
\r
51 #define PORT_2_BASE ((Port_RegisterType *)PORT_NOT_CONFIGURED)
\r
52 #define PORT_3_BASE ((Port_RegisterType *)PORT_NOT_CONFIGURED)
\r
53 #define PORT_4_BASE ((Port_RegisterType *)PORT_NOT_CONFIGURED)
\r
54 #define PORT_5_BASE ((Port_RegisterType *)PORT_NOT_CONFIGURED)
\r
55 #define PORT_6_BASE ((Port_RegisterType *)PORT_NOT_CONFIGURED)
\r
56 #define PORT_7_BASE ((Port_RegisterType *)PORT_NOT_CONFIGURED)
\r
57 #define PORT_8_BASE ((Port_RegisterType *)0xFFF7DDE0)
\r
58 #define PORT_9_BASE ((Port_RegisterType *)0xFFF7DFE0)
\r
59 #define PORT_10_BASE ((Port_RegisterType *)0xFFF7E1E0)
\r
60 #define PORT_NUMBER_OF_PORTS 11
\r
62 static Port_RegisterType * const Port_Base[] =
\r
79 static Port_StateType _portState = PORT_UNINITIALIZED;
\r
80 static const Port_ConfigType * _configPtr = &PortConfigData;
\r
82 #if (PORT_DEV_ERROR_DETECT)
\r
83 #define VALIDATE_PARAM_CONFIG(_ptr,_api) \
\r
84 if( (_ptr)==((void *)0) ) { \
\r
85 Det_ReportError(MODULE_ID_PORT, 0, _api, PORT_E_PARAM_CONFIG ); \
\r
89 #define VALIDATE_STATE_INIT(_api)\
\r
90 if(PORT_INITIALIZED!=_portState){\
\r
91 Det_ReportError(MODULE_ID_PORT, 0, _api, PORT_E_UNINIT ); \
\r
95 #define VALIDATE_PARAM_PIN(_pin, _api)\
\r
96 if(GET_PIN_PORT(_pin) >= PORT_NUMBER_OF_PORTS || Port_Base[GET_PIN_PORT(_pin)] == PORT_NOT_CONFIGURED || GET_PIN_PIN(_pin) > 7 ){\
\r
97 Det_ReportError(MODULE_ID_PORT, 0, _api, PORT_E_PARAM_PIN ); \
\r
102 #define VALIDATE_PARAM_CONFIG(_ptr,_api)
\r
103 #define VALIDATE_STATE_INIT(_api)
\r
104 #define VALIDATE_PARAM_PIN(_pin, _api)
\r
107 #if PORT_VERSION_INFO_API == STD_ON
\r
108 static Std_VersionInfoType _Port_VersionInfo =
\r
110 .vendorID = (uint16)1,
\r
111 .moduleID = (uint16) MODULE_ID_PORT,
\r
112 .instanceID = (uint8)1,
\r
113 .sw_major_version = (uint8)PORT_SW_MAJOR_VERSION,
\r
114 .sw_minor_version = (uint8)PORT_SW_MINOR_VERSION,
\r
115 .sw_patch_version = (uint8)PORT_SW_PATCH_VERSION,
\r
116 .ar_major_version = (uint8)PORT_AR_MAJOR_VERSION,
\r
117 .ar_minor_version = (uint8)PORT_AR_MINOR_VERSION,
\r
118 .ar_patch_version = (uint8)PORT_AR_PATCH_VERSION,
\r
122 void Port_Init(const Port_ConfigType *configType) {
\r
123 VALIDATE_PARAM_CONFIG(configType, PORT_INIT_ID);
\r
125 // Bring GIO register out of reset.
\r
128 for (uint16 i = 0; i < PORT_NUMBER_OF_PINS; i++) {
\r
129 uint8 port = GET_PIN_PORT(configType->pins[i].pin);
\r
130 uint32 mask = GET_PIN_MASK(configType->pins[i].pin);
\r
131 uint16 conf = configType->pins[i].conf;
\r
133 if (conf & PORT_FUNC) {
\r
134 // Don't do anything, let each driver configure???
\r
138 // Set pin direction
\r
139 if (conf & PORT_PIN_IN) {
\r
140 Port_Base[port]->DIR &= ~mask;
\r
143 Port_Base[port]->DIR |= mask;
\r
146 if (conf & PORT_ODE_ENABLE) {
\r
147 Port_Base[port]->PDR |= mask;
\r
149 Port_Base[port]->PDR &= ~mask;
\r
153 // Set pull up or down or nothing.
\r
154 if (conf & PORT_PULL_NONE) {
\r
155 Port_Base[port]->PULDIS |= mask;
\r
158 Port_Base[port]->PULDIS &= ~mask;
\r
159 if (conf & PORT_PULL_UP) {
\r
160 Port_Base[port]->PSL |= mask;
\r
163 Port_Base[port]->PSL &= ~mask;
\r
170 #if ( PORT_SET_PIN_DIRECTION_API == STD_ON )
\r
171 void Port_SetPinDirection( Port_PinType pin, Port_PinDirectionType direction )
\r
173 VALIDATE_STATE_INIT(PORT_SET_PIN_DIRECTION_ID);
\r
174 VALIDATE_PARAM_PIN(pin, PORT_SET_PIN_DIRECTION_ID);
\r
181 void Port_RefreshPortDirection( void )
\r
186 #if PORT_VERSION_INFO_API == STD_ON
\r
187 void Port_GetVersionInfo(Std_VersionInfoType* versionInfo)
\r
189 VALIDATE_STATE_INIT(PORT_GET_VERSION_INFO_ID);
\r
190 memcpy(versionInfo, &_Port_VersionInfo, sizeof(Std_VersionInfoType));
\r
195 #if (PORT_SET_PIN_MODE_API == STD_ON)
\r
196 void Port_SetPinMode(Port_PinType Pin, Port_PinModeType Mode) {
\r
197 uint8 port = GET_PIN_PORT(Pin);
\r
198 uint8 pin = GET_PIN_PIN(Pin);
\r
199 uint32 mask = GET_PIN_MASK(Pin);
\r
201 Port_PinType pin = Pin & 0x1F;
\r
202 Port_PinType port = Pin >> 8;
\r
203 Port_PinType mask = 1 << pin;
\r
205 Port_Base[port]->FUN &= ~mask;
\r
206 Port_Base[port]->FUN |= ((Mode & 1) << pin);
\r