-
Notifications
You must be signed in to change notification settings - Fork 40
/
Adc_Internal.c
323 lines (289 loc) · 9.8 KB
/
Adc_Internal.c
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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
/* -------------------------------- Arctic Core ------------------------------
* Arctic Core - the open source AUTOSAR platform http://arccore.com
*
* Copyright (C) 2009 ArcCore AB <[email protected]>
*
* This source code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published by the
* Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
* -------------------------------- Arctic Core ------------------------------*/
#include "Modules.h"
#include "Adc.h"
#if defined(USE_DET)
#include "Det.h"
#endif
#include "Os.h"
#include "arc.h"
#include "Adc_Internal.h"
#ifndef CFG_MPC560X
#define ADC_NOF_GROUP_PER_CONTROLLER 100
#endif
/* Validate functions used for development error check */
#if ( ADC_DEV_ERROR_DETECT == STD_ON )
Std_ReturnType ValidateInit(Adc_StateType adcState, Adc_APIServiceIDType api)
{
Std_ReturnType res = E_OK;
if(!(ADC_INIT == adcState)) {
Det_ReportError(MODULE_ID_ADC,0,api,ADC_E_UNINIT );
res = E_NOT_OK;
}
return res;
}
Std_ReturnType ValidateGroup(const Adc_ConfigType *ConfigPtr, Adc_GroupType group,Adc_APIServiceIDType api)
{
Std_ReturnType res = E_OK;
if(!(((group % ADC_NOF_GROUP_PER_CONTROLLER) >= 0) && ((group % ADC_NOF_GROUP_PER_CONTROLLER) < ConfigPtr->nbrOfGroups))
|| ConfigPtr == 0) {
Det_ReportError(MODULE_ID_ADC,0,api,ADC_E_PARAM_GROUP );
res = E_NOT_OK;
}
return res;
}
#endif
Adc_StatusType Adc_InternalGetGroupStatus (Adc_StateType adcState, const Adc_ConfigType *ConfigPtr, Adc_GroupType group)
{
Adc_StatusType returnValue;
#if ( ADC_DEV_ERROR_DETECT == STD_ON )
if( (ValidateInit(adcState, ADC_GETGROUPSTATUS_ID) == E_NOT_OK) ||
(ValidateGroup(ConfigPtr, group, ADC_GETGROUPSTATUS_ID) == E_NOT_OK))
{
returnValue = ADC_IDLE;
}
else
{
returnValue = ConfigPtr->groupConfigPtr[group%ADC_NOF_GROUP_PER_CONTROLLER].status->groupStatus;
}
#else
returnValue = ConfigPtr->groupConfigPtr[group%ADC_NOF_GROUP_PER_CONTROLLER].status->groupStatus;
#endif
return (returnValue);
}
#if (ADC_GRP_NOTIF_CAPABILITY == STD_ON)
void Adc_EnableInternalGroupNotification (Adc_StateType adcState, const Adc_ConfigType *ConfigPtr, Adc_GroupType group)
{
Std_ReturnType res;
#if ( ADC_DEV_ERROR_DETECT == STD_ON )
if( (ValidateInit(adcState, ADC_ENABLEGROUPNOTIFICATION_ID) == E_NOT_OK) ||
(ValidateGroup(ConfigPtr, group, ADC_ENABLEGROUPNOTIFICATION_ID) == E_NOT_OK))
{
res = E_NOT_OK;
}
else if (ConfigPtr->groupConfigPtr[group%ADC_NOF_GROUP_PER_CONTROLLER].groupCallback == NULL)
{
res = E_NOT_OK;
Det_ReportError(MODULE_ID_ADC,0,ADC_ENABLEGROUPNOTIFICATION_ID ,ADC_E_NOTIF_CAPABILITY );
}
else
{
/* Nothing strange. Go on... */
res = E_OK;
}
#else
res = E_OK;
#endif
if (E_OK == res){
ConfigPtr->groupConfigPtr[group%ADC_NOF_GROUP_PER_CONTROLLER].status->notifictionEnable = 1;
}
}
void Adc_InternalDisableGroupNotification (Adc_StateType adcState, const Adc_ConfigType *ConfigPtr, Adc_GroupType group)
{
Std_ReturnType res;
#if ( ADC_DEV_ERROR_DETECT == STD_ON )
if( (ValidateInit(adcState, ADC_DISABLEGROUPNOTIFICATION_ID) == E_NOT_OK) ||
(ValidateGroup(ConfigPtr, group, ADC_DISABLEGROUPNOTIFICATION_ID) == E_NOT_OK))
{
res = E_NOT_OK;
}
else if (ConfigPtr->groupConfigPtr[group%ADC_NOF_GROUP_PER_CONTROLLER].groupCallback == NULL)
{
res = E_NOT_OK;
Det_ReportError(MODULE_ID_ADC,0,ADC_DISABLEGROUPNOTIFICATION_ID ,ADC_E_NOTIF_CAPABILITY );
}
else
{
/* Nothing strange. Go on... */
res = E_OK;
}
#else
res = E_OK;
#endif
if (E_OK == res){
ConfigPtr->groupConfigPtr[group%ADC_NOF_GROUP_PER_CONTROLLER].status->notifictionEnable = 0;
}
}
#endif
/* Development error checking functions. */
#if (ADC_READ_GROUP_API == STD_ON)
Std_ReturnType Adc_CheckReadGroup (Adc_StateType adcState, const Adc_ConfigType *ConfigPtr, Adc_GroupType group)
{
Std_ReturnType returnValue = E_OK;
#if ( ADC_DEV_ERROR_DETECT == STD_ON )
if( (ValidateInit(adcState, ADC_READGROUP_ID) == E_NOT_OK) ||
(ValidateGroup(ConfigPtr, group, ADC_READGROUP_ID) == E_NOT_OK))
{
returnValue = E_NOT_OK;
}
else if (ADC_IDLE == ConfigPtr->groupConfigPtr[group%ADC_NOF_GROUP_PER_CONTROLLER].status->groupStatus)
{
/* ADC388. */
returnValue = E_NOT_OK;
Det_ReportError(MODULE_ID_ADC,0,ADC_READGROUP_ID ,ADC_E_IDLE );
}
else
{
/* Nothing strange. Go on... */
returnValue = E_OK;
}
#endif
return (returnValue);
}
#endif
#if (ADC_ENABLE_START_STOP_GROUP_API == STD_ON)
Std_ReturnType Adc_CheckStartGroupConversion (Adc_StateType adcState, const Adc_ConfigType *ConfigPtr, Adc_GroupType group)
{
Std_ReturnType returnValue = E_OK;
#if ( ADC_DEV_ERROR_DETECT == STD_ON )
if( (ValidateInit(adcState, ADC_STARTGROUPCONVERSION_ID) == E_NOT_OK) ||
(ValidateGroup(ConfigPtr, group, ADC_STARTGROUPCONVERSION_ID) == E_NOT_OK))
{
returnValue = E_NOT_OK;
}
else if ( NULL == ConfigPtr->groupConfigPtr[group%ADC_NOF_GROUP_PER_CONTROLLER].status->resultBufferPtr )
{
/* ResultBuffer not set, ADC424 */
Det_ReportError(MODULE_ID_ADC,0,ADC_STARTGROUPCONVERSION_ID, ADC_E_BUFFER_UNINIT );
returnValue = E_NOT_OK;
}
else if (!(ADC_TRIGG_SRC_SW == ConfigPtr->groupConfigPtr[group%ADC_NOF_GROUP_PER_CONTROLLER].triggerSrc))
{
/* Wrong trig source, ADC133. */
Det_ReportError(MODULE_ID_ADC,0,ADC_STARTGROUPCONVERSION_ID, ADC_E_WRONG_TRIGG_SRC);
returnValue = E_NOT_OK;
}
else if (!((ADC_IDLE == ConfigPtr->groupConfigPtr[group%ADC_NOF_GROUP_PER_CONTROLLER].status->groupStatus) ||
(ADC_STREAM_COMPLETED == ConfigPtr->groupConfigPtr[group%ADC_NOF_GROUP_PER_CONTROLLER].status->groupStatus)))
{
/* Group status not OK, ADC351, ADC428 */
Det_ReportError(MODULE_ID_ADC,0,ADC_STARTGROUPCONVERSION_ID, ADC_E_BUSY );
//returnValue = E_NOT_OK;
returnValue = E_OK;
}
else
{
returnValue = E_OK;
}
#endif
return (returnValue);
}
Std_ReturnType Adc_CheckStopGroupConversion (Adc_StateType adcState, const Adc_ConfigType *ConfigPtr, Adc_GroupType group)
{
Std_ReturnType returnValue = E_OK;
#if ( ADC_DEV_ERROR_DETECT == STD_ON )
if( (ValidateInit(adcState, ADC_STOPGROUPCONVERSION_ID) == E_NOT_OK) ||
(ValidateGroup(ConfigPtr, group, ADC_STOPGROUPCONVERSION_ID) == E_NOT_OK))
{
returnValue = E_NOT_OK;
}
else if (!(ADC_TRIGG_SRC_SW == ConfigPtr->groupConfigPtr[group%ADC_NOF_GROUP_PER_CONTROLLER].triggerSrc))
{
/* Wrong trig source, ADC164. */
Det_ReportError(MODULE_ID_ADC,0,ADC_STOPGROUPCONVERSION_ID, ADC_E_WRONG_TRIGG_SRC);
returnValue = E_NOT_OK;
}
else if (ADC_IDLE == ConfigPtr->groupConfigPtr[group%ADC_NOF_GROUP_PER_CONTROLLER].status->groupStatus)
{
/* Group status not OK, ADC241 */
Det_ReportError(MODULE_ID_ADC,0,ADC_STOPGROUPCONVERSION_ID, ADC_E_IDLE );
returnValue = E_NOT_OK;
}
else
{
returnValue = E_OK;
}
#endif
return (returnValue);
}
#endif
Std_ReturnType Adc_CheckInit (Adc_StateType adcState, const Adc_ConfigType *ConfigPtr)
{
Std_ReturnType returnValue = E_OK;
#if ( ADC_DEV_ERROR_DETECT == STD_ON )
if (!(ADC_UNINIT == adcState))
{
/* Oops, already initialised. */
Det_ReportError(MODULE_ID_ADC,0,ADC_INIT_ID, ADC_E_ALREADY_INITIALIZED );
returnValue = E_NOT_OK;
}
else if (ConfigPtr == NULL)
{
/* Wrong config! */
Det_ReportError(MODULE_ID_ADC,0,ADC_INIT_ID, ADC_E_PARAM_CONFIG );
returnValue = E_NOT_OK;
}
else
{
/* Looks good!! */
returnValue = E_OK;
}
#endif
return (returnValue);
}
#if (ADC_DEINIT_API == STD_ON)
Std_ReturnType Adc_CheckDeInit (Adc_StateType adcState, const Adc_ConfigType *ConfigPtr)
{
Std_ReturnType returnValue = E_OK;
#if ( ADC_DEV_ERROR_DETECT == STD_ON )
if(ValidateInit(adcState, ADC_DEINIT_ID) == E_OK)
{
for (Adc_GroupType group = (Adc_GroupType)0; group < ConfigPtr->nbrOfGroups; group++)
{
/* Check ADC is IDLE or COMPLETE*/
if((ConfigPtr->groupConfigPtr[group%ADC_NOF_GROUP_PER_CONTROLLER].status->groupStatus != ADC_IDLE) && (ConfigPtr->groupConfigPtr[group%ADC_NOF_GROUP_PER_CONTROLLER].status->groupStatus != ADC_STREAM_COMPLETED))
{
Det_ReportError(MODULE_ID_ADC,0,ADC_DEINIT_ID, ADC_E_BUSY );
returnValue = E_NOT_OK;
}
}
}
else
{
returnValue = E_NOT_OK;
}
#endif
return (returnValue);
}
#endif
Std_ReturnType Adc_CheckSetupResultBuffer (Adc_StateType adcState, const Adc_ConfigType *ConfigPtr, Adc_GroupType group)
{
Std_ReturnType returnValue = E_OK;
#if ( ADC_DEV_ERROR_DETECT == STD_ON )
if( (ValidateInit(adcState, ADC_SETUPRESULTBUFFER_ID) == E_NOT_OK) ||
(ValidateGroup(ConfigPtr, group, ADC_SETUPRESULTBUFFER_ID) == E_NOT_OK))
{
returnValue = E_NOT_OK;
}
#endif
return (returnValue);
}
Std_ReturnType Adc_CheckGetStreamLastPointer (Adc_StateType adcState, const Adc_ConfigType *ConfigPtr, Adc_GroupType group)
{
Std_ReturnType returnValue = E_OK;
#if ( ADC_DEV_ERROR_DETECT == STD_ON )
if( (ValidateInit(adcState, ADC_GETSTREAMLASTPOINTER_ID) == E_NOT_OK) ||
(ValidateGroup(ConfigPtr, group, ADC_GETSTREAMLASTPOINTER_ID) == E_NOT_OK))
{
returnValue = E_NOT_OK;
}
else if(ConfigPtr->groupConfigPtr[group%ADC_NOF_GROUP_PER_CONTROLLER].status->groupStatus == ADC_IDLE)
{ /** @req ADC215 Check ADC is not in IDLE */
Det_ReportError(MODULE_ID_ADC,0,ADC_GETSTREAMLASTPOINTER_ID, ADC_E_IDLE );
returnValue = E_NOT_OK;
}
#endif
return (returnValue);
}