]> rtime.felk.cvut.cz Git - arc.git/blob - diagnostic/Det/Det.c
Initial commit.
[arc.git] / diagnostic / Det / Det.c
1 /* -------------------------------- Arctic Core ------------------------------
2  * Arctic Core - the open source AUTOSAR platform http://arccore.com
3  *
4  * Copyright (C) 2009  ArcCore AB <contact@arccore.com>
5  *
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>.
9  *
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
13  * for more details.
14  * -------------------------------- Arctic Core ------------------------------*/
15
16
17
18
19
20
21
22
23 /*\r
24  * Development Error Tracer driver\r
25  *\r
26  * Specification: Autosar v2.0.1, Final\r
27  *\r
28  */\r
29 \r
30 #include "Std_Types.h"\r
31 #include "Det.h"\r
32 #include "Cpu.h"\r
33 #include "stdio.h"\r
34 \r
35 #define DEBUG_LVL 1\r
36 #include "Trace.h"\r
37 \r
38 typedef enum\r
39 {\r
40   DET_UNINITIALIZED = 0,\r
41   DET_INITIALIZED,\r
42   DET_STARTED\r
43 } Det_StateType;\r
44 \r
45 static Det_StateType _detState = DET_UNINITIALIZED;\r
46 \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
51 #endif\r
52 \r
53 #if ( DET_ENABLE_CALLBACKS == STD_ON )\r
54 detCbk_t detCbk_List[DET_NUMBER_OF_CALLBACKS];\r
55 \r
56 uint8 Det_AddCbk(detCbk_t detCbk)\r
57 {\r
58   if (_detState != DET_UNINITIALIZED)\r
59   {\r
60     for (uint32 i=0; i<DET_NUMBER_OF_CALLBACKS; i++)\r
61     {\r
62       if (NULL==detCbk_List[i])\r
63       {\r
64         detCbk_List[i]=detCbk;\r
65         return i;\r
66       }\r
67     }\r
68   }\r
69 \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
72 }\r
73 \r
74 void Det_RemoveCbk(uint8 detCbkIndex)\r
75 {\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
79 \r
80   detCbk_List[detCbkIndex]=NULL;\r
81 }\r
82 #endif\r
83 \r
84 \r
85 void Det_Init(void)\r
86 {\r
87 #if ( DET_ENABLE_CALLBACKS == STD_ON )\r
88   for (uint32 i=0; i<DET_NUMBER_OF_CALLBACKS; i++)\r
89   {\r
90     detCbk_List[i]=NULL;\r
91   }\r
92 #endif\r
93 \r
94 #if ( DET_USE_RAMLOG == STD_ON )\r
95   for(uint32 i=0; i < DET_RAMLOG_SIZE; i++)\r
96   {\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
101   }\r
102   Det_RamlogIndex = 0;\r
103 #endif\r
104 \r
105   _detState = DET_INITIALIZED;\r
106 }\r
107 \r
108 #if DET_DEINIT_API == STD_ON\r
109 void Det_DeInit( void )\r
110 {\r
111   _detState = DET_UNINITIALIZED;\r
112 }\r
113 #endif\r
114 \r
115 void Det_ReportError(uint16 ModuleId, uint8 InstanceId, uint8 ApiId, uint8 ErrorId)\r
116 {\r
117   if (_detState == DET_STARTED) // No action is taken if the module is not started\r
118   {\r
119 #if ( DET_ENABLE_CALLBACKS == STD_ON )
120   long old1;\r
121   Irq_Save(old1);\r
122   for (uint32 i=0; i<DET_NUMBER_OF_CALLBACKS; i++)\r
123   {\r
124     if (NULL!=detCbk_List[i])\r
125     {\r
126       (*detCbk_List[i])(ModuleId, InstanceId, ApiId, ErrorId);\r
127     }\r
128   }\r
129   Irq_Restore(old1);\r
130 #endif\r
131 \r
132 #if ( DET_USE_RAMLOG == STD_ON )
133   long old2;\r
134   Irq_Save(old2);\r
135   if (Det_RamlogIndex < DET_RAMLOG_SIZE)\r
136   {\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
141     Det_RamlogIndex++;\r
142 #if ( DET_WRAP_RAMLOG == STD_ON )\r
143     if (Det_RamlogIndex == DET_RAMLOG_SIZE)\r
144       Det_RamlogIndex = 0;\r
145 #endif\r
146   }\r
147   Irq_Restore(old2);\r
148 #endif\r
149 \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
153 #endif\r
154   }\r
155 }\r
156 \r
157 void Det_Start(void)\r
158 {\r
159   _detState = DET_STARTED;\r
160 }\r