-
Notifications
You must be signed in to change notification settings - Fork 0
/
Port.h
275 lines (228 loc) · 10.6 KB
/
Port.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
/******************************************************************************
*
* Module: Port
*
* File Name: Port.h
*
* Description: Header file for TM4C123GH6PM Microcontroller - Port Driver
*
* Author: Ahmed Badra
******************************************************************************/
#ifndef PORT_H
#define PORT_H
/* Id for the company in the AUTOSAR
* for example Ahmed Badra's ID = 1000 :) */
#define PORT_VENDOR_ID (1000U)
/* port Module Id */
#define PORT_MODULE_ID (124U)
/* port Instance Id */
#define PORT_INSTANCE_ID (0U)
/*
* Module Version 1.0.0
*/
#define PORT_SW_MAJOR_VERSION (1U)
#define PORT_SW_MINOR_VERSION (0U)
#define PORT_SW_PATCH_VERSION (0U)
/*
* AUTOSAR Version 4.0.3
*/
#define PORT_AR_RELEASE_MAJOR_VERSION (4U)
#define PORT_AR_RELEASE_MINOR_VERSION (0U)
#define PORT_AR_RELEASE_PATCH_VERSION (3U)
/*
* Macros for Port Status
*/
#define PORT_INITIALIZED (1U)
#define PORT_NOT_INITIALIZED (0U)
/* Number of Pins in the Single Port (MCU Specific) */
#define NUM_OF_PORT_SINGLE_PORT (8U)
/*
* macros for pin different Modes,
* assigned to mode of type Port_PinModeType
*/
#define PORT_DIO_MODE (0U)
#define PORT_ALTERNATE_FUNCTION_01_MODE (1U)
#define PORT_ALTERNATE_FUNCTION_02_MODE (2U)
#define PORT_ALTERNATE_FUNCTION_03_MODE (3U)
#define PORT_ALTERNATE_FUNCTION_04_MODE (4U)
#define PORT_ALTERNATE_FUNCTION_05_MODE (5U)
#define PORT_ALTERNATE_FUNCTION_06_MODE (6U)
#define PORT_ALTERNATE_FUNCTION_07_MODE (7U)
#define PORT_ALTERNATE_FUNCTION_08_MODE (8U)
#define PORT_ALTERNATE_FUNCTION_09_MODE (9U)
#define PORT_ALTERNATE_FUNCTION_10_MODE (10U)
#define PORT_ALTERNATE_FUNCTION_11_MODE (11U)
#define PORT_ALTERNATE_FUNCTION_12_MODE (12U)
#define PORT_ALTERNATE_FUNCTION_13_MODE (13U)
#define PORT_ALTERNATE_FUNCTION_14_MODE (14U)
#define PORT_ANALOG_MODE (15U)
/*
* symbolic names of each Port-Pin in the Microcontroller (MCU SPECIFIC)
* , must be as symbolic names provided by the configuration tool,
* this Project doesn't have a configuration tool so it's up to you
*/
#define PORT_PA0 (0U)
#define PORT_PA1 (1U)
#define PORT_PA2 (2U)
#define PORT_PA3 (3U)
#define PORT_PA4 (4U)
#define PORT_PA5 (5U)
#define PORT_PA6 (6U)
#define PORT_PA7 (7U)
#define PORT_PB0 (8U)
#define PORT_PB1 (9U)
#define PORT_PB2 (10U)
#define PORT_PB3 (11U)
#define PORT_PB4 (12U)
#define PORT_PB5 (13U)
#define PORT_PB6 (14U)
#define PORT_PB7 (15U)
#define PORT_PC0 (16U)
#define PORT_PC1 (17U)
#define PORT_PC2 (18U)
#define PORT_PC3 (19U)
#define PORT_PC4 (20U)
#define PORT_PC5 (21U)
#define PORT_PC6 (22U)
#define PORT_PC7 (23U)
#define PORT_PD0 (24U)
#define PORT_PD1 (25U)
#define PORT_PD2 (26U)
#define PORT_PD3 (27U)
#define PORT_PD4 (28U)
#define PORT_PD5 (29U)
#define PORT_PD6 (30U)
#define PORT_PD7 (31U)
#define PORT_PE0 (32U)
#define PORT_PE1 (33U)
#define PORT_PE2 (34U)
#define PORT_PE3 (35U)
#define PORT_PE4 (36U)
#define PORT_PE5 (37U)
#define PORT_PE6 (38U)
#define PORT_PE7 (39U)
#define PORT_PF0 (40U)
#define PORT_PF1 (41U)
#define PORT_PF2 (42U)
#define PORT_PF3 (43U)
#define PORT_PF4 (44U)
#define PORT_PF5 (45U)
#define PORT_PF6 (46U)
#define PORT_PF7 (47U)
/* Standard AUTOSAR types */
#include "Std_Types.h"
/* AUTOSAR checking between Std Types and Port Modules */
#if ((STD_TYPES_AR_RELEASE_MAJOR_VERSION != PORT_AR_RELEASE_MAJOR_VERSION)\
|| (STD_TYPES_AR_RELEASE_MINOR_VERSION != PORT_AR_RELEASE_MINOR_VERSION)\
|| (STD_TYPES_AR_RELEASE_PATCH_VERSION != PORT_AR_RELEASE_PATCH_VERSION))
#error "The AR version of Std_Types.h does not match the expected version"
#endif
/* Port Pre-Compile Configuration Header file */
#include "Port_Cfg.h"
/* AUTOSAR Version checking between Port_Cfg.h and Port.h files */
#if ((PORT_CFG_AR_RELEASE_MAJOR_VERSION != PORT_AR_RELEASE_MAJOR_VERSION)\
|| (PORT_CFG_AR_RELEASE_MINOR_VERSION != PORT_AR_RELEASE_MINOR_VERSION)\
|| (PORT_CFG_AR_RELEASE_PATCH_VERSION != PORT_AR_RELEASE_PATCH_VERSION))
#error "The AR version of Port_Cfg.h does not match the expected version"
#endif
/* Software Version checking between Port_Cfg.h and Port.h files */
#if ((PORT_CFG_SW_MAJOR_VERSION != PORT_SW_MAJOR_VERSION)\
|| (PORT_CFG_SW_MINOR_VERSION != PORT_SW_MINOR_VERSION)\
|| (PORT_CFG_SW_PATCH_VERSION != PORT_SW_PATCH_VERSION))
#error "The SW version of Port_Cfg.h does not match the expected version"
#endif
/* Non AUTOSAR files */
#include "Common_Macros.h"
/******************************************************************************
* API Service Id Macros *
******************************************************************************/
/* service ID for PORT init */
#define PORT_INIT_SID (uint8)0x00
/* service ID for PORT set pin direction */
#define PORT_SET_PIN_DIRECTION_SID (uint8)0x01
/* service ID for PORT refresh pin direction */
#define PORT_REFRESH_PORT_DIRECTION_SID (uint8)0x02
/* service ID for PORT get version info */
#define PORT_GET_VERSION_INFO_SID (uint8)0x03
/* service ID for PORT set pin mode */
#define PORT_SET_PIN_MODE_SID (uint8)0x04
/*******************************************************************************
* DET Error Codes *
*******************************************************************************/
/* DET Code for Invalid Port Pin ID requested */
#define PORT_E_PARAM_PIN (uint8)0x0A
/* DET Code for Port Pin not configured as changeable */
#define PORT_E_DIRECTION_UNCHANGEABLE (uint8)0x0B
/* DET Code for API Port_Init service called with wrong parameter */
#define PORT_E_PARAM_CONFIG (uint8)0x0C
/* DET Code for API Port_SetPinMode service called with wrong parameter Mode */
#define PORT_E_PARAM_INVALID_MODE (uint8)0x0D
/* DET Code for API Port_SetPinMode service called when mode is unchangeable */
#define PORT_E_MODE_UNCHANGEABLE (uint8)0x0E
/* DET Code for API service called without module initialization */
#define PORT_E_UNINIT (uint8)0x0F
/* DET Code for APIs called with a Null Pointer */
#define PORT_E_PARAM_POINTER (uint8)0x10
/*******************************************************************************
* Module Data Types *
*******************************************************************************/
/* Data type for the symbolic name of a port pin */
typedef uint8 Port_PinType;
/* Possible directions of a port pin */
typedef enum{
PORT_PIN_IN, /* Sets port pin as input */
PORT_PIN_OUT, /* Sets port pin as output */
}Port_PinDirectionType;
/* Different port pin modes */
typedef uint8 Port_PinModeType;
/* Description: Enum to hold internal resistor type for PIN */
typedef enum
{
OFF,PULL_UP,PULL_DOWN
}Port_InternalResistor;
/* Description: Structure to configure each individual PIN:
* 1. the direction of pin --> INPUT or OUTPUT
* 2. the internal resistor --> Disable, Pull up or Pull down
* 3. the initial value in output case -> high or low
* 4. pin's Mode -> DIO, Aletrnate Function 01, .... ,Analog
* 5. pin direction changeability -> ON or OFF
* 6. pin mode changeability -> ON or OFF
*/
typedef struct
{
Port_PinDirectionType direction; /* PORT_PIN_IN, PORT_PIN_OUT */
Port_InternalResistor resistor; /* OFF,PULL_UP,PULL_DOWN */
uint8 initial_value; /* STD_HIGH, STD_LOW */
Port_PinModeType mode; /* PORT_DIO_MODE...PORT_ANALOG_MODE */
uint8 direction_change; /* STD_ON, STD_OFF */
uint8 mode_change; /* STD_ON, STD_OFF */
}Port_ConfigPin;
/* structure that is required for initialization API */
typedef struct
{
/* array of pointers to config struct to optimize memory storage */
const Port_ConfigPin* Pins[PORT_ALL_PINS_NUMBER];
}Port_ConfigType;
/*******************************************************************************
* Function Prototypes *
*******************************************************************************/
/* function for PORT initialization API */
void Port_Init( const Port_ConfigType* ConfigPtr );
#if (PORT_SET_PIN_DIRECTION_API == STD_ON)
/* function for setting direction API */
void Port_SetPinDirection( Port_PinType Pin, Port_PinDirectionType Direction );
#endif
/* function for refreshing port direction API */
void Port_RefreshPortDirection( void );
/* function for setting pin mode API */
void Port_SetPinMode( Port_PinType Pin, Port_PinModeType Mode );
/* function for getting version info API */
#if (PORT_VERSION_INFO_API == STD_ON)
void Port_GetVersionInfo( Std_VersionInfoType* versioninfo );
#endif
/*******************************************************************************
* External Variables *
*******************************************************************************/
/* Extern PB structures to be used by Port and other modules */
extern const Port_ConfigType Port_pinConfigurationSet;
#endif /* PORT_H */