]> rtime.felk.cvut.cz Git - arc.git/blob - system/SchM/SchM.c
a75e7f199e866b4943ea2c23a9db9f3811a581b8
[arc.git] / system / SchM / SchM.c
1 /* -------------------------------- Arctic Core ------------------------------\r
2  * Arctic Core - the open source AUTOSAR platform http://arccore.com\r
3  *\r
4  * Copyright (C) 2009  ArcCore AB <contact@arccore.com>\r
5  *\r
6  * This source code is free software; you can redistribute it and/or modify it\r
7  * under the terms of the GNU General Public License version 2 as published by the\r
8  * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.\r
9  *\r
10  * This program is distributed in the hope that it will be useful, but\r
11  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
12  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License\r
13  * for more details.\r
14  * -------------------------------- Arctic Core ------------------------------*/\r
15 \r
16 \r
17 /* ----------------------------[information]----------------------------------*/\r
18 /*\r
19  * Author: mahi\r
20  *\r
21  * Part of Release:\r
22  *   3.1.5\r
23  *\r
24  * Description:\r
25  *   Implements the SchM module\r
26  *\r
27  * Support:\r
28  *   General                              Have Support\r
29  *   -------------------------------------------\r
30  *   SCHM_DEV_ERROR_DETECT              N\r
31  *   SCHM_VERSION_INFO_API              N\r
32  *\r
33  *   General                              Have Support\r
34  *   -------------------------------------------\r
35  *   SCHM_POSITION_IN_TASK              N\r
36  *   SCHM_MAINFUNCTION_REF              N\r
37  *   SCHM_MAPPED_TO_TASK                N\r
38  *   .....\r
39  *\r
40  * Implementation Notes:\r
41  *   There are a lot of examples in SchM about scheduling and it\r
42  *   all seems very complicated. What is boils down to is that\r
43  *   the BSW MainFunctions have different requirements. Most modules\r
44  *   have only periodic needs for timeouts and other things. But there\r
45  *   are also module that needs extra iterations at certain points in time, to\r
46  *   be really efficient.\r
47  *\r
48  *\r
49  *   BSW Module Code:\r
50  *    SchM_Enter_NvM(EXCLUSIVE_AREA_0);\r
51  *    ..Do stuff...\r
52  *    SchM_Enter_NvM(EXCLUSIVE_AREA_0);\r
53  *\r
54  *   but today we have Irq_Save(state), Irq_Restore(state).\r
55  *   ArcCore Irq_Save/Irq_Restore is almost the same as SuspendAllInterrupts/ResumeAllInterrupts,\r
56  *   since they can both be nested and saves state. But the OSEK (Susp../Resume..) can't do it locally, it\r
57  *   assumes some kind of local FIFO, that is bad.\r
58  *\r
59  *\r
60  * BSW Modules with generated mainfunction period times. Checked Only 3.1.5\r
61  *\r
62  *          Specification                        Studio   Core=Generator\r
63  *  --------------------------------------------------------------------------------------\r
64  *  Adc     N/A *1\r
65  *  Can     CanMainFunctionReadPerdiod             No      No\r
66  *          CanMainFunctionWritePerdiod\r
67  *          ..\r
68  *  CanIf   Have No mainf                          N/A\r
69  *  CanNm   CanNmMainFunctionPeriod                Yes     Accessible in struct.. not as define\r
70  *  CanSm   Have mainf. but no period              Yes*2   Nothing is generated\r
71  *  CanTp   CanTpMainFunctionPeriod                Yes     CANTP_MAIN_FUNCTION_PERIOD_TIME_MS\r
72  *  CanTrcv Have mainf. but no period              N/A\r
73  *  Com     Have mainf. but no period              No*3\r
74  *  ComM    ComMMainFunctionPeriod                 Yes     Accessible in struct.. not as define\r
75  *  Dcm     Have MainF. DcmTaskTime                Yes     DCM_MAIN_FUNCTION_PERIOD_TIME_MS\r
76  *  Dem     Have MainF. DemTaskTime                                 No\r
77  *  EcuM    Have MainF.EcuMMainFunctionPeriod      Yes     ECUM_MAIN_FUNCTION_PERIOD\r
78  *  Ea      Have MainF. ON_PRE_CONDITION (ie not cyclic)\r
79  *  Eep     Have MainF. VARIABLE_CYCLIC\r
80  *  Fee     Have MainF. ON_PRE_CONDITION\r
81  *  Fls     Have MainF. FIXED_CYCLIC\r
82  *  IoHwAb  Have no mainfunction\r
83  *  ..\r
84  *  Nm      Have MainF. FIXED_CYCLIC ,            No\r
85  *          NmCycletimeMainFunction\r
86  *  NvM     Have MainF. VARIABLE_CYCLIC                   No\r
87  *  PduR    Have no MainF.\r
88  *  Spi     Have MainF. FIXED_CYCLIC, no period\r
89  *  WdgM    Have MainF. WdgMTriggerCycle           *4\r
90  *\r
91  * *1 No MainFunction\r
92  * *2 What is it used for?\r
93  * *3 Com have lots of timing... it's related to what? (reads timer?)\r
94  * *4 Probably not.\r
95  *\r
96  * ----->>>>\r
97  *\r
98  * Conclusion:\r
99  * * Support in generator is extremely limited.\r
100  * * Support in specification is limited\r
101  * * Support in studio is limited\r
102  *\r
103  *  Write scheduling information directly in the SchM_<mod>.h files.\r
104  *  OR\r
105  *  Write scheduling information in SchM_cfg.h....better (keeps information in one place)\r
106  *\r
107  *     #if defined(USE_SCHM)\r
108  *     assert( SCHM_TIMER(x) == <period> )\r
109  *     #endif\r
110  *\r
111  *  It seems it's mandatory to include SchM_<mod>.h for each BSW module.\r
112  *  So,\r
113  *  - <mod>.c ALWAYS include SchM_<mod.h>\r
114  *  - SchM.c have condidional include on SchM_<mod>.h, e.g must define it's MainFunctions.\r
115  *\r
116  *\r
117  *\r
118  */\r
119 \r
120 #include "SchM.h"\r
121 #include "SchM_cfg.h"\r
122 \r
123 \r
124 #if defined(USE_MCU)\r
125 #include "Mcu.h"\r
126 #endif\r
127 #if defined(USE_GPT)\r
128 #include "Gpt.h"\r
129 #endif\r
130 \r
131 #if defined(USE_CAN)\r
132 #include "Can.h"\r
133 #include "SchM_Can.h"\r
134 #else\r
135 #define SCHM_MAINFUNCTION_CAN_WRITE()\r
136 #define SCHM_MAINFUNCTION_CAN_READ()\r
137 #define SCHM_MAINFUNCTION_CAN_BUSOFF()\r
138 #define SCHM_MAINFUNCTION_CAN_ERROR()\r
139 #define SCHM_MAINFUNCTION_CAN_WAKEUP()\r
140 #endif\r
141 \r
142 #if defined(USE_CANIF)\r
143 #include "CanIf.h"\r
144 #include "SchM_CanIf.h"\r
145 #endif\r
146 \r
147 #if defined(USE_PDUR)\r
148 #include "PduR.h"\r
149 #include "SchM_PduR.h"\r
150 #endif\r
151 \r
152 #if defined(USE_COM)\r
153 #include "Com.h"\r
154 #include "SchM_Com.h"\r
155 #else\r
156 #define SCHM_MAINFUNCTION_COMRX()\r
157 #define SCHM_MAINFUNCTION_COMTX()\r
158 #endif\r
159 \r
160 #if defined(USE_CANTP)\r
161 #include "CanTp.h"\r
162 #include "SchM_CanTp.h"\r
163 #else\r
164 #define SCHM_MAINFUNCTION_CANTP()\r
165 #endif\r
166 \r
167 #if defined(USE_J1939TP)\r
168 #include "J1939Tp.h"\r
169 #include "SchM_J1939TP.h"\r
170 #else\r
171 #define SCHM_MAINFUNCTION_J1939TP()\r
172 #endif\r
173 \r
174 \r
175 #if defined(USE_DCM)\r
176 #include "Dcm.h"\r
177 #include "SchM_Dcm.h"\r
178 #else\r
179 #define SCHM_MAINFUNCTION_DCM()\r
180 #endif\r
181 \r
182 #if defined(USE_DEM)\r
183 #include "Dem.h"\r
184 #include "SchM_Dem.h"\r
185 #else\r
186 #define SCHM_MAINFUNCTION_DEM()\r
187 #endif\r
188 \r
189 #if defined(USE_PWM)\r
190 #include "Pwm.h"\r
191 #include "SchM_Pwm.h"\r
192 #endif\r
193 \r
194 \r
195 #if defined(USE_IOHWAB)\r
196 #include "IoHwAb.h"\r
197 #include "SchM_IoHwAb.h"\r
198 #else\r
199 #define SCHM_MAINFUNCTION_IOWHAB()\r
200 #endif\r
201 \r
202 #if defined(USE_FLS)\r
203 #include "Fls.h"\r
204 #include "SchM_Fls.h"\r
205 #else\r
206 #define SCHM_MAINFUNCTION_FLS()\r
207 #endif\r
208 \r
209 #if defined(USE_ECUM)\r
210 #include "EcuM.h"\r
211 #include "SchM_EcuM.h"\r
212 #else\r
213 #define SCHM_MAINFUNCTION_ECUM()\r
214 #endif\r
215 \r
216 #if defined(USE_EEP)\r
217 #include "Eep.h"\r
218 #include "SchM_Fls.h"\r
219 #else\r
220 #define SCHM_MAINFUNCTION_EEP()\r
221 #endif\r
222 \r
223 #if defined(USE_FEE)\r
224 #include "Fee.h"\r
225 #include "SchM_Fee.h"\r
226 #else\r
227 #define SCHM_MAINFUNCTION_FEE()\r
228 #endif\r
229 \r
230 #if defined(USE_EA)\r
231 #include "Ea.h"\r
232 #include "SchM_Ea.h"\r
233 #else\r
234 #define SCHM_MAINFUNCTION_EA()\r
235 #endif\r
236 \r
237 #if defined(USE_NVM)\r
238 #include "NvM.h"\r
239 #include "SchM_NvM.h"\r
240 #else\r
241 #define SCHM_MAINFUNCTION_NVM()\r
242 #endif\r
243 \r
244 #if defined(USE_COMM)\r
245 #include "ComM.h"\r
246 #include "SchM_ComM.h"\r
247 #else\r
248 #define SCHM_MAINFUNCTION_COMM()\r
249 #endif\r
250 \r
251 #if defined(USE_NM)\r
252 #include "Nm.h"\r
253 #include "SchM_Nm.h"\r
254 #else\r
255 #define SCHM_MAINFUNCTION_NM()\r
256 #endif\r
257 \r
258 #if defined(USE_CANNM)\r
259 #include "CanNm.h"\r
260 #include "SchM_CanNm.h"\r
261 #else\r
262 #define SCHM_MAINFUNCTION_CANNM()\r
263 #endif\r
264 \r
265 #if defined(USE_CANSM)\r
266 #include "CanSM.h"\r
267 #include "SchM_CanSM.h"\r
268 #else\r
269 #define SCHM_MAINFUNCTION_CANSM()\r
270 #endif\r
271 \r
272 #if defined(USE_UDPNM)\r
273 #include "UdpNm.h"\r
274 #endif\r
275 \r
276 #if defined(USE_LINSM)\r
277 #include "LinSM.h"\r
278 #endif\r
279 \r
280 #if defined(USE_SPI)\r
281 #include "Spi.h"\r
282 #include "SchM_Spi.h"\r
283 #else\r
284 #define SCHM_MAINFUNCTION_SPI()\r
285 #endif\r
286 \r
287 #if defined(USE_WDG)\r
288 #include "Wdg.h"\r
289 #endif\r
290 \r
291 #if defined(USE_WDGM)\r
292 #include "WdgM.h"\r
293 #include "SchM_WdgM.h"\r
294 #else\r
295 #define SCHM_MAINFUNCTION_WDMG()\r
296 #endif\r
297 \r
298 SCHM_DECLARE(CAN_WRITE);\r
299 SCHM_DECLARE(CAN_READ);\r
300 SCHM_DECLARE(CAN_BUSOFF);\r
301 SCHM_DECLARE(CAN_WAKEUP);\r
302 SCHM_DECLARE(CAN_ERROR);\r
303 SCHM_DECLARE(COMRX);\r
304 SCHM_DECLARE(COMTX);\r
305 SCHM_DECLARE(CANTP);\r
306 SCHM_DECLARE(CANNM);\r
307 SCHM_DECLARE(DCM);\r
308 SCHM_DECLARE(DEM);\r
309 SCHM_DECLARE(COMM);\r
310 SCHM_DECLARE(NM);\r
311 SCHM_DECLARE(CANSM);\r
312 SCHM_DECLARE(ECUM);\r
313 SCHM_DECLARE(NVM);\r
314 SCHM_DECLARE(FEE);\r
315 SCHM_DECLARE(EA);\r
316 SCHM_DECLARE(FLS);\r
317 SCHM_DECLARE(WDGM_TRIGGER);\r
318 SCHM_DECLARE(WDGM_ALIVESUPERVISION);\r
319 \r
320 \r
321 \r
322 void SchM_Init( void ) {\r
323 \r
324 }\r
325 \r
326 void SchM_Deinit( void ) {\r
327 \r
328 }\r
329 \r
330 void SchM_GetVersionInfo( Std_VersionInfoType *versionInfo ) {\r
331 \r
332 }\r
333 \r
334 \r
335 static void runMemory( void ) {\r
336         SCHM_MAINFUNCTION_NVM();\r
337         SCHM_MAINFUNCTION_EA();\r
338         SCHM_MAINFUNCTION_FEE();\r
339         SCHM_MAINFUNCTION_EEP();\r
340         SCHM_MAINFUNCTION_FLS();\r
341         SCHM_MAINFUNCTION_SPI();\r
342 }\r
343 \r
344 /**\r
345  * Startup task.\r
346  */\r
347 TASK(SchM_Startup){\r
348 \r
349         /* At this point EcuM ==  ECUM_STATE_STARTUP_ONE */\r
350 \r
351         /* Schedule memory task more often that usaul so that EcuM_StartupTwo() may return quicker */\r
352         ActivateTask(TASK_ID_SchM_BswService);\r
353         /* Set events on TASK_ID_BswService_Mem */\r
354         SetRelAlarm(ALARM_ID_Alarm_BswService, 10, 2);\r
355 \r
356         /*\r
357          * Call EcuM_StartupTwo that do:\r
358          * - Startup RTE,\r
359          * - Wait for Nvm to complete\r
360          * - Call EcuM_AL_DriverInitThree() to initiate Nvm dependent modules.\r
361          */\r
362         EcuM_StartupTwo();\r
363 \r
364         /* Start to schedule BSW parts */\r
365         SetRelAlarm(ALARM_ID_Alarm_BswService, 10, 5);\r
366 \r
367         EcuM_RequestRUN(ECUM_USER_User_1);\r
368 \r
369         ActivateTask(TASK_ID_Application);\r
370 \r
371         TerminateTask();\r
372 \r
373 }\r
374 \r
375 \r
376 TASK(SchM_BswService) {\r
377         EcuM_StateType  state;\r
378 \r
379         EcuM_GetState(&state);\r
380 \r
381         switch( state ) {\r
382         case ECUM_STATE_STARTUP_ONE:\r
383                 /* Nothing to schedule */\r
384                 break;\r
385         case ECUM_STATE_STARTUP_TWO:\r
386                 runMemory();\r
387                 break;\r
388         default:\r
389                 runMemory();\r
390 \r
391                 SCHM_MAINFUNCTION_ECUM();\r
392 \r
393                 SCHM_MAINFUNCTION_CAN_WRITE();\r
394                 SCHM_MAINFUNCTION_CAN_READ();\r
395                 SCHM_MAINFUNCTION_CAN_BUSOFF();\r
396                 SCHM_MAINFUNCTION_CAN_ERROR();\r
397                 SCHM_MAINFUNCTION_CAN_WAKEUP();\r
398 \r
399 \r
400                 SCHM_MAINFUNCTION_COMRX();\r
401                 SCHM_MAINFUNCTION_COMTX();\r
402 \r
403                 SCHM_MAINFUNCTION_CANTP();\r
404                 SCHM_MAINFUNCTION_J1939TP();\r
405                 SCHM_MAINFUNCTION_DCM();\r
406                 SCHM_MAINFUNCTION_DEM();\r
407 \r
408                 SCHM_MAINFUNCTION_IOWHAB();\r
409                 SCHM_MAINFUNCTION_COMM();\r
410                 SCHM_MAINFUNCTION_NM();\r
411                 SCHM_MAINFUNCTION_CANNM();\r
412                 SCHM_MAINFUNCTION_CANSM();\r
413                 SCHM_MAINFUNCTION_WDGM_TRIGGER();\r
414                 SCHM_MAINFUNCTION_WDGM_ALIVESUPERVISION();\r
415                 break;\r
416         }\r
417 \r
418         TerminateTask();\r
419 }\r
420 \r
421 void SchM_MainFunction( void ) {\r
422 \r
423 }\r
424 \r
425 \r
426 \r