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
23 #include "Std_Types.h"
\r
25 #include "mpc55xx.h"
\r
27 #if defined(USE_DEM)
\r
33 * Have a bunch of ports:
\r
34 * - PAxx, input only port
\r
35 * - PBxx to PKxx, i/o ports
\r
36 * where xx is 0 to 15
\r
38 * PCRx( Pad Config Register ) - register function(in, out, pull up/down, etc )
\r
40 * 16 - 43 : Port B to J
\r
42 * GPD0( Pin Data Output Registers ) -
\r
48 PORT_UNINITIALIZED = 0, PORT_INITIALIZED,
\r
51 static Port_StateType _portState = PORT_UNINITIALIZED;
\r
52 static const Port_ConfigType * _configPtr = &PortConfigData;
\r
54 #if (PORT_DEV_ERROR_DETECT)
\r
55 #define VALIDATE_PARAM_CONFIG(_ptr,_api) \
\r
56 if( (_ptr)==((void *)0) ) { \
\r
57 Det_ReportError(MODULE_ID_PORT, 0, _api, PORT_E_PARAM_CONFIG ); \
\r
61 #define VALIDATE_STATE_INIT(_api)\
\r
62 if(PORT_INITIALIZED!=_portState){\
\r
63 Det_ReportError(MODULE_ID_PORT, 0, _api, PORT_E_UNINIT ); \
\r
67 #define VALIDATE_PARAM_PIN(_pin, _api)\
\r
68 if(_pin>sizeof(SIU.PCR)){\
\r
69 Det_ReportError(MODULE_ID_PORT, 0, _api, PORT_E_PARAM_PIN ); \
\r
73 #define VALIDATE_PARAM_CONFIG(_ptr,_api)
\r
74 #define VALIDATE_STATE_INIT(_api)
\r
75 #define VALIDATE_PARAM_PIN(_pin, _api)
\r
78 #if PORT_VERSION_INFO_API == STD_ON
\r
79 static Std_VersionInfoType _Port_VersionInfo =
\r
81 .vendorID = (uint16)1,
\r
82 .moduleID = (uint16) MODULE_ID_PORT,
\r
83 .instanceID = (uint8)1,
\r
84 .sw_major_version = (uint8)PORT_SW_MAJOR_VERSION,
\r
85 .sw_minor_version = (uint8)PORT_SW_MINOR_VERSION,
\r
86 .sw_patch_version = (uint8)PORT_SW_PATCH_VERSION,
\r
87 .ar_major_version = (uint8)PORT_AR_MAJOR_VERSION,
\r
88 .ar_minor_version = (uint8)PORT_AR_MINOR_VERSION,
\r
89 .ar_patch_version = (uint8)PORT_AR_PATCH_VERSION,
\r
93 void Port_Init(const Port_ConfigType *configType)
\r
95 VALIDATE_PARAM_CONFIG(configType, PORT_INIT_ID);
\r
97 #if defined(CFG_MPC560X)
\r
101 while(i < (configType->padCnt/sizeof(uint16_t)))
\r
103 SIU.PCR[i].R = configType->padConfig[i];
\r
106 #if defined(CFG_MPC560XB)
\r
107 if(32 == i || 33 == i) i=34;
\r
108 if(121 == i || 122 == i) i=123;
\r
109 #elif defined(CFG_MPC5606S)
\r
110 // Out of reset pins PH[0:3](PCR99~PCR102) are available as JTAG pins(TCK,TDI,TDO and TMS respectively)
\r
111 if(99 == i || 100 == i || 101 == i || 102 == i) i=103;
\r
115 while(j < configType->outCnt)
\r
117 SIU.GPDO[j].B.PDO = configType->outConfig[j];
\r
122 // Pointers to the register memory areas
\r
123 vuint16_t * padConfig = &(SIU.PCR[0].R);
\r
124 vuint8_t * outConfig = &(SIU.GPDO[0].R);
\r
126 // vuint8_t * inConfig = &(SIU.GPDI[0].R); // Read only
\r
127 // Copy config to register areas
\r
128 memcpy((void *)outConfig, configType->outConfig, configType->outCnt);
\r
129 memcpy((void *)padConfig, configType->padConfig, configType->padCnt);
\r
130 //memcpy((void *)inConfig, configType->inConfig, configType->inCnt);
\r
133 _portState = PORT_INITIALIZED;
\r
134 _configPtr = configType;
\r
139 #if ( PORT_SET_PIN_DIRECTION_API == STD_ON )
\r
140 void Port_SetPinDirection( Port_PinType pin, Port_PinDirectionType direction )
\r
142 VALIDATE_STATE_INIT(PORT_SET_PIN_DIRECTION_ID);
\r
143 VALIDATE_PARAM_PIN(pin, PORT_SET_PIN_DIRECTION_ID);
\r
144 unsigned long state;
\r
146 Irq_Save(state); // Lock interrupts
\r
147 if (direction==PORT_PIN_IN)
\r
149 SIU.PCR[pin].B.IBE = 1;
\r
150 SIU.PCR[pin].B.OBE = 0;
\r
154 SIU.PCR[pin].B.IBE = 0;
\r
155 SIU.PCR[pin].B.OBE = 1;
\r
157 Irq_Restore(state); // Restore interrupts
\r
162 void Port_RefreshPortDirection( void )
\r
164 VALIDATE_STATE_INIT(PORT_REFRESH_PORT_DIRECTION_ID);
\r
165 vuint16_t * pcrPtr = &(SIU.PCR[0].R);
\r
166 const uint16_t * padCfgPtr = _configPtr->padConfig;
\r
167 uint16_t bitMask = PORT_IBE_ENABLE|PORT_OBE_ENABLE;
\r
169 unsigned long state;
\r
170 for (i=0; i < sizeof(SIU.PCR)/sizeof(SIU.PCR[0]); i++)
\r
172 Irq_Save(state); // Lock interrupts
\r
173 *pcrPtr = (*pcrPtr & ~bitMask) | (*padCfgPtr & bitMask);
\r
174 Irq_Restore(state); // Restore interrupts
\r
177 #if defined(CFG_MPC560XB)
\r
182 padCfgPtr = padCfgPtr+2;
\r
188 padCfgPtr = padCfgPtr+2;
\r
190 #elif defined(CFG_MPC5606S)
\r
195 padCfgPtr = padCfgPtr+5;
\r
205 #if PORT_VERSION_INFO_API == STD_ON
\r
206 void Port_GetVersionInfo(Std_VersionInfoType* versionInfo)
\r
208 VALIDATE_STATE_INIT(PORT_GET_VERSION_INFO_ID);
\r
209 memcpy(versionInfo, &_Port_VersionInfo, sizeof(Std_VersionInfoType));
\r
214 #if (PORT_SET_PIN_MODE_API == STD_ON)
\r
215 void Port_SetPinMode(Port_PinType Pin, Port_PinModeType Mode)
\r
217 VALIDATE_STATE_INIT(PORT_SET_PIN_MODE_ID);
\r
218 VALIDATE_PARAM_PIN(Pin, PORT_SET_PIN_MODE_ID);
\r
219 //The pad configuration registers (SIU_PCR) in the SIU allow software control of the static electrical
\r
220 //characteristics of external pins. The PCRs can select the multiplexed function of a pin, selection of pullup
\r
221 //or pulldown devices, the slew rate of I/O signals, open drain mode for output pins, and hysteresis.
\r
222 SIU.PCR[Pin].R = Mode; // Put the selected mode to the PCR register
\r