1 /* -------------------------------- Arctic Core ------------------------------
2 * Arctic Core - the open source AUTOSAR platform http://arccore.com
4 * Copyright (C) 2009 ArcCore AB <contact@arccore.com>
6 * This source code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published by the
8 * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * -------------------------------- Arctic Core ------------------------------*/
24 * Development Error Tracer driver
\r
26 * Specification: Autosar v2.0.1, Final
\r
30 #include "Std_Types.h"
\r
40 DET_UNINITIALIZED = 0,
\r
45 static Det_StateType _detState = DET_UNINITIALIZED;
\r
47 #if ( DET_USE_RAMLOG == STD_ON )
\r
48 // TODO Put this in a section that is not initialised after a reset
\r
49 uint32 Det_RamlogIndex = 0;
\r
50 Det_EntryType Det_RamLog[DET_RAMLOG_SIZE];
\r
53 #if ( DET_ENABLE_CALLBACKS == STD_ON )
\r
54 detCbk_t detCbk_List[DET_NUMBER_OF_CALLBACKS];
\r
56 uint8 Det_AddCbk(detCbk_t detCbk)
\r
58 if (_detState != DET_UNINITIALIZED)
\r
60 for (uint32 i=0; i<DET_NUMBER_OF_CALLBACKS; i++)
\r
62 if (NULL==detCbk_List[i])
\r
64 detCbk_List[i]=detCbk;
\r
70 Det_ReportError(DET_MODULE_ID, 0, DET_CALLBACK_API, DET_E_CBK_REGISTRATION_FAILED);
\r
71 return (0xFF); // Return 0xff to indicate that the registration failed
\r
74 void Det_RemoveCbk(uint8 detCbkIndex)
\r
76 // Validate the index
\r
77 if (detCbkIndex >= DET_NUMBER_OF_CALLBACKS)
\r
78 Det_ReportError(DET_MODULE_ID, 0, DET_CALLBACK_API, DET_E_INDEX_OUT_OF_RANGE);
\r
80 detCbk_List[detCbkIndex]=NULL;
\r
87 #if ( DET_ENABLE_CALLBACKS == STD_ON )
\r
88 for (uint32 i=0; i<DET_NUMBER_OF_CALLBACKS; i++)
\r
90 detCbk_List[i]=NULL;
\r
94 #if ( DET_USE_RAMLOG == STD_ON )
\r
95 for(uint32 i=0; i < DET_RAMLOG_SIZE; i++)
\r
97 Det_RamLog[i].moduleId = 0;
\r
98 Det_RamLog[i].instanceId = 0;
\r
99 Det_RamLog[i].apiId = 0;
\r
100 Det_RamLog[i].errorId = 0;
\r
102 Det_RamlogIndex = 0;
\r
105 _detState = DET_INITIALIZED;
\r
108 #if DET_DEINIT_API == STD_ON
\r
109 void Det_DeInit( void )
\r
111 _detState = DET_UNINITIALIZED;
\r
115 void Det_ReportError(uint16 ModuleId, uint8 InstanceId, uint8 ApiId, uint8 ErrorId)
\r
117 if (_detState == DET_STARTED) // No action is taken if the module is not started
\r
119 #if ( DET_ENABLE_CALLBACKS == STD_ON )
122 for (uint32 i=0; i<DET_NUMBER_OF_CALLBACKS; i++)
\r
124 if (NULL!=detCbk_List[i])
\r
126 (*detCbk_List[i])(ModuleId, InstanceId, ApiId, ErrorId);
\r
132 #if ( DET_USE_RAMLOG == STD_ON )
135 if (Det_RamlogIndex < DET_RAMLOG_SIZE)
\r
137 Det_RamLog[Det_RamlogIndex].moduleId = ModuleId;
\r
138 Det_RamLog[Det_RamlogIndex].instanceId = InstanceId;
\r
139 Det_RamLog[Det_RamlogIndex].apiId = ApiId;
\r
140 Det_RamLog[Det_RamlogIndex].errorId = ErrorId;
\r
142 #if ( DET_WRAP_RAMLOG == STD_ON )
\r
143 if (Det_RamlogIndex == DET_RAMLOG_SIZE)
\r
144 Det_RamlogIndex = 0;
\r
150 #if ( DET_USE_STDERR == STD_ON )
\r
151 simple_printf("Det Error: ModuleId=%d, InstanceId=%d, ApiId=%d, ErrorId=%d\n", ModuleId, InstanceId, ApiId, ErrorId);
\r
152 //fprintf(stderr, "Det Error: ModuleId=%d, InstanceId=%d, ApiId=%d, ErrorId=%d\n", ModuleId, InstanceId, ApiId, ErrorId);
\r
157 void Det_Start(void)
\r
159 _detState = DET_STARTED;
\r