-
Notifications
You must be signed in to change notification settings - Fork 3
/
Dio.h
212 lines (163 loc) · 7.07 KB
/
Dio.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
/******************************************************************************
*
* Module: Dio
*
* File Name: Dio.h
*
* Description: Header file for Dio Module.
*
* Author: Abdelrahman Bakr
******************************************************************************/
#ifndef DIO_H
#define DIO_H
/* Id for the company in the AUTOSAR
* for example my company`s ID = 1000 :) */
#define DIO_VENDOR_ID (1000U)
/* Dio Module Id */
#define DIO_MODULE_ID (120U)
/* Dio Instance Id */
#define DIO_INSTANCE_ID (0U)
/*
* Module Version 1.0.0
*/
#define DIO_SW_MAJOR_VERSION (1U)
#define DIO_SW_MINOR_VERSION (0U)
#define DIO_SW_PATCH_VERSION (0U)
/*
* AUTOSAR Version 4.0.3
*/
#define DIO_AR_RELEASE_MAJOR_VERSION (4U)
#define DIO_AR_RELEASE_MINOR_VERSION (0U)
#define DIO_AR_RELEASE_PATCH_VERSION (3U)
/*
* Macros for Dio Status
*/
#define DIO_INITIALIZED (1U)
#define DIO_NOT_INITIALIZED (0U)
/* Standard AUTOSAR types */
#include "Std_Types.h"
/* AUTOSAR checking between Std Types and Dio Modules */
#if ((STD_TYPES_AR_RELEASE_MAJOR_VERSION != DIO_AR_RELEASE_MAJOR_VERSION)\
|| (STD_TYPES_AR_RELEASE_MINOR_VERSION != DIO_AR_RELEASE_MINOR_VERSION)\
|| (STD_TYPES_AR_RELEASE_PATCH_VERSION != DIO_AR_RELEASE_PATCH_VERSION))
#error "The AR version of Std_Types.h does not match the expected version"
#endif
/* Dio Pre-Compile Configuration Header file */
#include "Dio_Cfg.h"
/* AUTOSAR Version checking between Dio_Cfg.h and Dio.h files */
#if ((DIO_CFG_AR_RELEASE_MAJOR_VERSION != DIO_AR_RELEASE_MAJOR_VERSION)\
|| (DIO_CFG_AR_RELEASE_MINOR_VERSION != DIO_AR_RELEASE_MINOR_VERSION)\
|| (DIO_CFG_AR_RELEASE_PATCH_VERSION != DIO_AR_RELEASE_PATCH_VERSION))
#error "The AR version of Dio_Cfg.h does not match the expected version"
#endif
/* Software Version checking between Dio_Cfg.h and Dio.h files */
#if ((DIO_CFG_SW_MAJOR_VERSION != DIO_SW_MAJOR_VERSION)\
|| (DIO_CFG_SW_MINOR_VERSION != DIO_SW_MINOR_VERSION)\
|| (DIO_CFG_SW_PATCH_VERSION != DIO_SW_PATCH_VERSION))
#error "The SW version of Dio_Cfg.h does not match the expected version"
#endif
/* Non AUTOSAR files */
#include "Common_Macros.h"
#include "stm32f446xx.h" // include device registers
/******************************************************************************
* API Service Id Macros *
******************************************************************************/
/* Service ID for DIO read Channel */
#define DIO_READ_CHANNEL_SID (uint8)0x00
/* Service ID for DIO write Channel */
#define DIO_WRITE_CHANNEL_SID (uint8)0x01
/* Service ID for DIO read Port */
#define DIO_READ_PORT_SID (uint8)0x02
/* Service ID for DIO write Port */
#define DIO_WRITE_PORT_SID (uint8)0x03
/* Service ID for DIO read Channel Group */
#define DIO_READ_CHANNEL_GROUP_SID (uint8)0x04
/* Service ID for DIO write Channel Group */
#define DIO_WRITE_CHANNEL_GROUP_SID (uint8)0x05
/* Service ID for DIO GetVersionInfo */
#define DIO_GET_VERSION_INFO_SID (uint8)0x12
/* Service ID for DIO Init Channel */
#define DIO_INIT_SID (uint8)0x10
/* Service ID for DIO flip Channel */
#define DIO_FLIP_CHANNEL_SID (uint8)0x11
/*******************************************************************************
* DET Error Codes *
*******************************************************************************/
/* DET code to report Invalid Channel */
#define DIO_E_PARAM_INVALID_CHANNEL_ID (uint8)0x0A
/* Dio_Init API service called with NULL pointer parameter */
#define DIO_E_PARAM_CONFIG (uint8)0x10
/* DET code to report Invalid Port */
#define DIO_E_PARAM_INVALID_PORT_ID (uint8)0x14
/* DET code to report Invalid Channel Group */
#define DIO_E_PARAM_INVALID_GROUP (uint8)0x1F
/*
* The API service shall return immediately without any further action,
* beside reporting this development error.
*/
#define DIO_E_PARAM_POINTER (uint8)0x20
/*
* API service used without module initialization is reported using following
* error code (Not exist in AUTOSAR 4.0.3 DIO SWS Document.
*/
#define DIO_E_UNINIT (uint8)0xF0
/*******************************************************************************
* Module Data Types *
*******************************************************************************/
/* Type definition for Dio_ChannelType used by the DIO APIs */
typedef uint8 Dio_ChannelType;
/* Type definition for Dio_PortType used by the DIO APIs */
typedef uint8 Dio_PortType;
/* Type definition for Dio_LevelType used by the DIO APIs */
typedef uint8 Dio_LevelType;
/* Type definition for Dio_PortLevelType used by the DIO APIs */
typedef uint32 Dio_PortLevelType;
/* Structure for Dio_ChannelGroup */
typedef struct
{
/* Mask which defines the positions of the channel group */
uint8 mask;
/* Position of the group from LSB */
uint8 offset;
/* This shall be the port ID which the Channel group is defined. */
Dio_PortType PortIndex;
} Dio_ChannelGroupType;
typedef struct
{
/* Member contains the ID of the Port that this channel belongs to */
Dio_PortType Port_Num;
/* Member contains the ID of the Channel*/
Dio_ChannelType Ch_Num;
}Dio_ConfigChannel;
/* Data Structure required for initializing the Dio Driver */
typedef struct
{
Dio_ConfigChannel Channels[DIO_CONFIGURED_CHANNLES];
} Dio_ConfigType;
/*******************************************************************************
* Function Prototypes *
*******************************************************************************/
/* Function for DIO read Channel API */
Dio_PortLevelType Dio_ReadPort(Dio_PortType PortId);
/* Function for DIO write Channel API */
void Dio_WritePort(Dio_PortType PortId, Dio_PortLevelType Level);
/* Function for DIO read Port API */
Dio_LevelType Dio_ReadChannel(Dio_ChannelType ChannelId);
/* Function for DIO write Port API */
void Dio_WriteChannel(Dio_ChannelType ChannelId, Dio_LevelType Level);
/* Function for DIO Initialization API */
void Dio_Init(const Dio_ConfigType * ConfigPtr);
#if (DIO_FLIP_CHANNEL_API == STD_ON)
/* Function for DIO flip channel API */
Dio_LevelType Dio_FlipChannel(Dio_ChannelType ChannelId);
#endif
/* Function for DIO Get Version Info API */
#if (DIO_VERSION_INFO_API == STD_ON)
void Dio_GetVersionInfo(Std_VersionInfoType *versioninfo);
#endif
/*******************************************************************************
* External Variables *
*******************************************************************************/
/* Extern PB structures to be used by Dio and other modules */
extern const Dio_ConfigType Dio_Configuration;
#endif