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
16 #include "Std_Types.h"
\r
17 #include "Port.h" /** @req PORT131 */
\r
19 #if defined(USE_DET)
\r
25 * Have a bunch of ports:
\r
26 * - PA, PB, PE, PK is CPU registers (used as address bus if external RAM is used)
\r
27 * - PH, PJ, PM, PP, PS, PT is peripheral registers
\r
32 PORT_UNINITIALIZED = 0, PORT_INITIALIZED,
\r
35 static Port_StateType _portState = PORT_UNINITIALIZED;
\r
36 static const Port_ConfigType * _configPtr = NULL;
\r
39 #if (PORT_DEV_ERROR_DETECT == STD_ON)
\r
40 #define VALIDATE_PARAM_CONFIG(_ptr,_api) \
\r
41 if( (_ptr)==((void *)0) ) { \
\r
42 Det_ReportError(MODULE_ID_PORT, 0, _api, PORT_E_PARAM_CONFIG ); \
\r
46 #define VALIDATE_STATE_INIT(_api)\
\r
47 if(PORT_INITIALIZED!=_portState){\
\r
48 Det_ReportError(MODULE_ID_PORT, 0, _api, PORT_E_UNINIT ); \
\r
53 #define VALIDATE_PARAM_CONFIG(_ptr,_api)
\r
54 #define VALIDATE_STATE_INIT(_api)
\r
55 #define VALIDATE_PARAM_PIN(_api)
\r
58 #if PORT_VERSION_INFO_API == STD_ON
\r
59 static Std_VersionInfoType _Port_VersionInfo =
\r
61 .vendorID = (uint16)1,
\r
62 .moduleID = (uint16) MODULE_ID_PORT,
\r
63 .instanceID = (uint8)1,
\r
64 .sw_major_version = (uint8)PORT_SW_MAJOR_VERSION,
\r
65 .sw_minor_version = (uint8)PORT_SW_MINOR_VERSION,
\r
66 .sw_patch_version = (uint8)PORT_SW_PATCH_VERSION,
\r
67 .ar_major_version = (uint8)PORT_AR_MAJOR_VERSION,
\r
68 .ar_minor_version = (uint8)PORT_AR_MINOR_VERSION,
\r
69 .ar_patch_version = (uint8)PORT_AR_PATCH_VERSION, };
\r
73 /** @req PORT041 Comment: To reduce flash usage the configuration tool can disable configuration of some ports */
\r
74 /** @req PORT078 See environment i.e Ecu State Manager */
\r
76 /** @req PORT113 Number 2 in list is applicable for all pins. */
\r
77 /** @req PORT043 Comment: Output value is set before direction */
\r
78 /** @req PORT071 See environment i.e Ecu State Manager */
\r
79 /** @req PORT002 The _portState varialble is initialised. */
\r
80 /** @req PORT003 See environment i.e Ecu State Manager */
\r
81 /** @req PORT055 Comment: Output value is set before direction */
\r
83 void Port_Init(const Port_ConfigType *configType)
\r
85 VALIDATE_PARAM_CONFIG(configType, PORT_INIT_ID); /** @req PORT105 */
\r
87 // Setup pin drives and pullups
\r
88 RDRIV = configType->coreReducedDriveRegister;
\r
89 PUCR = configType->corePullUpRegister;
\r
91 // CAN and SPI routing of pins
\r
92 MODDR = configType->modeRoutingRegister;
\r
95 #if ( PORTA_CONFIGURABLE == STD_ON )
\r
96 PORTA = configType->portAOutValue;
\r
97 DDRA = configType->portADirection;
\r
100 #if ( PORTB_CONFIGURABLE == STD_ON )
\r
101 PORTB = configType->portBOutValue;
\r
102 DDRB = configType->portBDirection;
\r
105 #if ( PORTE_CONFIGURABLE == STD_ON )
\r
106 PORTE = configType->portEOutValue;
\r
107 DDRE = configType->portEDirection;
\r
110 #if ( PORTK_CONFIGURABLE == STD_ON )
\r
111 PORTK = configType->portKOutValue;
\r
112 DDRK = configType->portKDirection;
\r
115 #if ( PORTH_CONFIGURABLE == STD_ON )
\r
116 RDRH = configType->portHReducedDriveRegister;
\r
117 PERH = configType->portHPullEnableRegister;
\r
118 PPSH = configType->portHPullPolarityRegsiter;
\r
119 PTH = configType->portHOutValue;
\r
120 DDRH = configType->portHDirection;
\r
123 #if ( PORTJ_CONFIGURABLE == STD_ON )
\r
124 RDRJ = configType->portJReducedDriveRegister;
\r
125 PERJ = configType->portJPullEnableRegister;
\r
126 PPSJ = configType->portJPullPolarityRegsiter;
\r
127 PTJ = configType->portJOutValue;
\r
128 DDRJ = configType->portJDirection;
\r
131 #if ( PORTM_CONFIGURABLE == STD_ON )
\r
132 RDRM = configType->portMReducedDriveRegister;
\r
133 PERM = configType->portMPullEnableRegister;
\r
134 PPSM = configType->portMPullPolarityRegsiter;
\r
135 WOMM = configType->portMWiredModeRegsiter;
\r
136 PTM = configType->portMOutValue;
\r
137 DDRM = configType->portMDirection;
\r
140 #if ( PORTP_CONFIGURABLE == STD_ON )
\r
141 RDRP = configType->portPReducedDriveRegister;
\r
142 PERP = configType->portPPullEnableRegister;
\r
143 PPSP = configType->portPPullPolarityRegsiter;
\r
144 PTP = configType->portPOutValue;
\r
145 DDRP = configType->portPDirection;
\r
148 #if ( PORTS_CONFIGURABLE == STD_ON )
\r
149 RDRS = configType->portSReducedDriveRegister;
\r
150 PERS = configType->portSPullEnableRegister;
\r
151 PPSS = configType->portSPullPolarityRegsiter;
\r
152 WOMS = configType->portSWiredModeRegsiter;
\r
153 PTS = configType->portSOutValue;
\r
154 DDRS = configType->portSDirection;
\r
157 #if ( PORTT_CONFIGURABLE == STD_ON )
\r
158 RDRT = configType->portTReducedDriveRegister;
\r
159 PERT = configType->portTPullEnableRegister;
\r
160 PPST = configType->portTPullPolarityRegsiter;
\r
161 PTT = configType->portTOutValue;
\r
162 DDRT = configType->portTDirection;
\r
165 _portState = PORT_INITIALIZED;
\r
166 _configPtr = configType;
\r
171 /** @req PORT141 */
\r
172 /** @req PORT063 */
\r
173 /** @req PORT054 */
\r
174 /** @req PORT086 */
\r
175 #if ( PORT_SET_PIN_DIRECTION_API == STD_ON )
\r
176 void Port_SetPinDirection( Port_PinType pin, Port_PinDirectionType direction )
\r
178 VALIDATE_STATE_INIT(PORT_SET_PIN_DIRECTION_ID);
\r
183 base = pin & PORT_BASEMASK;
\r
184 bitmask = 1 << (pin & PORT_BITMASK);
\r
185 if (base == PORT_A_BASE)
\r
187 curValue = DDRA & ~(bitmask);
\r
188 if (direction == PORT_PIN_OUT)
\r
189 curValue = curValue | bitmask;
\r
192 else if (base == PORT_B_BASE)
\r
194 curValue = DDRB & ~(bitmask);
\r
195 if (direction == PORT_PIN_OUT)
\r
196 curValue = curValue | bitmask;
\r
199 else if (base == PORT_E_BASE)
\r
201 curValue = DDRE & ~(bitmask);
\r
202 if (direction == PORT_PIN_OUT)
\r
203 curValue = curValue | bitmask;
\r
206 else if (base == PORT_K_BASE)
\r
208 curValue = DDRK & ~(bitmask);
\r
209 if (direction == PORT_PIN_OUT)
\r
210 curValue = curValue | bitmask;
\r
213 else if (base == PORT_H_BASE)
\r
215 curValue = DDRH & ~(bitmask);
\r
216 if (direction == PORT_PIN_OUT)
\r
217 curValue = curValue | bitmask;
\r
220 else if (base == PORT_J_BASE)
\r
222 curValue = DDRJ & ~(bitmask);
\r
223 if (direction == PORT_PIN_OUT)
\r
224 curValue = curValue | bitmask;
\r
227 else if (base == PORT_M_BASE)
\r
229 curValue = DDRM & ~(bitmask);
\r
230 if (direction == PORT_PIN_OUT)
\r
231 curValue = curValue | bitmask;
\r
234 else if (base == PORT_P_BASE)
\r
236 curValue = DDRP & ~(bitmask);
\r
237 if (direction == PORT_PIN_OUT)
\r
238 curValue = curValue | bitmask;
\r
241 else if (base == PORT_S_BASE)
\r
243 curValue = DDRS & ~(bitmask);
\r
244 if (direction == PORT_PIN_OUT)
\r
245 curValue = curValue | bitmask;
\r
248 else if (base == PORT_T_BASE)
\r
250 curValue = DDRT & ~(bitmask);
\r
251 if (direction == PORT_PIN_OUT)
\r
252 curValue = curValue | bitmask;
\r
257 Det_ReportError(MODULE_ID_PORT, 0, PORT_SET_PIN_DIRECTION_ID, PORT_E_PARAM_PIN );
\r
264 /** @req PORT066 */
\r
265 /** @req PORT142 */
\r
266 /** @req PORT060 */
\r
267 /** @req PORT061 */
\r
268 void Port_RefreshPortDirection(void)
\r
271 VALIDATE_STATE_INIT(PORT_REFRESH_PORT_DIRECTION_ID);
\r
273 #if ( PORTA_CONFIGURABLE == STD_ON )
\r
274 curValue = DDRA & ~(_configPtr->portAMask);
\r
275 curValue |= (_configPtr->portADirection & _configPtr->portAMask);
\r
279 #if ( PORTB_CONFIGURABLE == STD_ON )
\r
280 curValue = DDRB & ~(_configPtr->portBMask);
\r
281 curValue |= (_configPtr->portBDirection & _configPtr->portBMask);
\r
285 #if ( PORTE_CONFIGURABLE == STD_ON )
\r
286 curValue = DDRE & ~(_configPtr->portEMask);
\r
287 curValue |= (_configPtr->portEDirection & _configPtr->portEMask);
\r
291 #if ( PORTK_CONFIGURABLE == STD_ON )
\r
292 curValue = DDRK & ~(_configPtr->portKMask);
\r
293 curValue |= (_configPtr->portKDirection & _configPtr->portKMask);
\r
297 #if ( PORTH_CONFIGURABLE == STD_ON )
\r
298 curValue = DDRH & ~(_configPtr->portHMask);
\r
299 curValue |= (_configPtr->portHDirection & _configPtr->portHMask);
\r
303 #if ( PORTJ_CONFIGURABLE == STD_ON )
\r
304 curValue = DDRJ & ~(_configPtr->portJMask);
\r
305 curValue |= (_configPtr->portJDirection & _configPtr->portJMask);
\r
309 #if ( PORTM_CONFIGURABLE == STD_ON )
\r
310 curValue = DDRM & ~(_configPtr->portMMask);
\r
311 curValue |= (_configPtr->portMDirection & _configPtr->portMMask);
\r
315 #if ( PORTP_CONFIGURABLE == STD_ON )
\r
316 curValue = DDRP & ~(_configPtr->portPMask);
\r
317 curValue |= (_configPtr->portPDirection & _configPtr->portPMask);
\r
321 #if ( PORTS_CONFIGURABLE == STD_ON )
\r
322 curValue = DDRS & ~(_configPtr->portSMask);
\r
323 curValue |= (_configPtr->portSDirection & _configPtr->portSMask);
\r
327 #if ( PORTT_CONFIGURABLE == STD_ON )
\r
328 curValue = DDRT & ~(_configPtr->portTMask);
\r
329 curValue |= (_configPtr->portTDirection & _configPtr->portTMask);
\r
339 #if (PORT_VERSION_INFO_API == STD_ON)
\r
340 void Port_GetVersionInfo(Std_VersionInfoType* versionInfo)
\r
342 VALIDATE_STATE_INIT(PORT_GET_VERSION_INFO_ID);
\r
343 memcpy(versionInfo, &_Port_VersionInfo, sizeof(Std_VersionInfoType));
\r
351 #if (PORT_SET_PIN_MODE_API == STD_ON)
\r
352 void Port_SetPinMode(Port_PinType Pin, Port_PinModeType Mode)
\r
354 VALIDATE_STATE_INIT(PORT_SET_PIN_MODE_ID);
\r
356 // Mode of pins not changeable on this CPU
\r
357 #if (PORT_DEV_ERROR_DETECT == STD_ON)
\r
358 Det_ReportError(MODULE_ID_PORT, 0, PORT_SET_PIN_MODE_ID, PORT_E_MODE_UNCHANGEABLE );
\r