1 /* -------------------------------- Arctic Core ------------------------------
\r
2 * Arctic Core - the open source AUTOSAR platform http://arccore.com
\r
4 * Copyright (C) 2009 ArcCore AB <contact@arccore.com>
\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
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
14 * -------------------------------- Arctic Core ------------------------------*/
\r
17 /* ----------------------------[information]----------------------------------*/
\r
25 * Implements the SchM module
\r
28 * General Have Support
\r
29 * -------------------------------------------
\r
30 * SCHM_DEV_ERROR_DETECT N
\r
31 * SCHM_VERSION_INFO_API N
\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
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
50 * SchM_Enter_NvM(EXCLUSIVE_AREA_0);
\r
52 * SchM_Enter_NvM(EXCLUSIVE_AREA_0);
\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
60 * BSW Modules with generated mainfunction period times. Checked Only 3.1.5
\r
62 * Specification Studio Core=Generator
\r
63 * --------------------------------------------------------------------------------------
\r
65 * Can CanMainFunctionReadPerdiod No No
\r
66 * CanMainFunctionWritePerdiod
\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
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
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
99 * * Support in generator is extremely limited.
\r
100 * * Support in specification is limited
\r
101 * * Support in studio is limited
\r
103 * Write scheduling information directly in the SchM_<mod>.h files.
\r
105 * Write scheduling information in SchM_cfg.h....better (keeps information in one place)
\r
107 * #if defined(USE_SCHM)
\r
108 * assert( SCHM_TIMER(x) == <period> )
\r
111 * It seems it's mandatory to include SchM_<mod>.h for each BSW module.
\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
121 #include "SchM_cfg.h"
\r
124 #if defined(USE_MCU)
\r
127 #if defined(USE_GPT)
\r
131 #if defined(USE_CAN)
\r
133 #include "SchM_Can.h"
\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
142 #if defined(USE_CANIF)
\r
144 #include "SchM_CanIf.h"
\r
147 #if defined(USE_PDUR)
\r
149 #include "SchM_PduR.h"
\r
152 #if defined(USE_COM)
\r
154 #include "SchM_Com.h"
\r
156 #define SCHM_MAINFUNCTION_COMRX()
\r
157 #define SCHM_MAINFUNCTION_COMTX()
\r
160 #if defined(USE_CANTP)
\r
162 #include "SchM_CanTp.h"
\r
164 #define SCHM_MAINFUNCTION_CANTP()
\r
167 #if defined(USE_J1939TP)
\r
168 #include "J1939Tp.h"
\r
169 #include "SchM_J1939TP.h"
\r
171 #define SCHM_MAINFUNCTION_J1939TP()
\r
175 #if defined(USE_DCM)
\r
177 #include "SchM_Dcm.h"
\r
179 #define SCHM_MAINFUNCTION_DCM()
\r
182 #if defined(USE_DEM)
\r
184 #include "SchM_Dem.h"
\r
186 #define SCHM_MAINFUNCTION_DEM()
\r
189 #if defined(USE_PWM)
\r
191 #include "SchM_Pwm.h"
\r
195 #if defined(USE_IOHWAB)
\r
196 #include "IoHwAb.h"
\r
197 #include "SchM_IoHwAb.h"
\r
199 #define SCHM_MAINFUNCTION_IOWHAB()
\r
202 #if defined(USE_FLS)
\r
204 #include "SchM_Fls.h"
\r
206 #define SCHM_MAINFUNCTION_FLS()
\r
209 #if defined(USE_ECUM)
\r
211 #include "SchM_EcuM.h"
\r
213 #define SCHM_MAINFUNCTION_ECUM()
\r
216 #if defined(USE_EEP)
\r
218 #include "SchM_Fls.h"
\r
220 #define SCHM_MAINFUNCTION_EEP()
\r
223 #if defined(USE_FEE)
\r
225 #include "SchM_Fee.h"
\r
227 #define SCHM_MAINFUNCTION_FEE()
\r
230 #if defined(USE_EA)
\r
232 #include "SchM_Ea.h"
\r
234 #define SCHM_MAINFUNCTION_EA()
\r
237 #if defined(USE_NVM)
\r
239 #include "SchM_NvM.h"
\r
241 #define SCHM_MAINFUNCTION_NVM()
\r
244 #if defined(USE_COMM)
\r
246 #include "SchM_ComM.h"
\r
248 #define SCHM_MAINFUNCTION_COMM()
\r
251 #if defined(USE_NM)
\r
253 #include "SchM_Nm.h"
\r
255 #define SCHM_MAINFUNCTION_NM()
\r
258 #if defined(USE_CANNM)
\r
260 #include "SchM_CanNm.h"
\r
262 #define SCHM_MAINFUNCTION_CANNM()
\r
265 #if defined(USE_CANSM)
\r
267 #include "SchM_CanSM.h"
\r
269 #define SCHM_MAINFUNCTION_CANSM()
\r
272 #if defined(USE_UDPNM)
\r
276 #if defined(USE_LINSM)
\r
280 #if defined(USE_SPI)
\r
282 #include "SchM_Spi.h"
\r
284 #define SCHM_MAINFUNCTION_SPI()
\r
287 #if defined(USE_WDG)
\r
291 #if defined(USE_WDGM)
\r
293 #include "SchM_WdgM.h"
\r
295 #define SCHM_MAINFUNCTION_WDMG()
\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
309 SCHM_DECLARE(COMM);
\r
311 SCHM_DECLARE(CANSM);
\r
312 SCHM_DECLARE(ECUM);
\r
320 void SchM_Init( void ) {
\r
324 void SchM_Deinit( void ) {
\r
328 void SchM_GetVersionInfo( Std_VersionInfoType *versionInfo ) {
\r
333 static void runMemory( void ) {
\r
334 SCHM_MAINFUNCTION_NVM();
\r
335 SCHM_MAINFUNCTION_EA();
\r
336 SCHM_MAINFUNCTION_FEE();
\r
337 SCHM_MAINFUNCTION_EEP();
\r
338 SCHM_MAINFUNCTION_FLS();
\r
339 SCHM_MAINFUNCTION_SPI();
\r
345 TASK(SchM_Startup){
\r
347 /* At this point EcuM == ECUM_STATE_STARTUP_ONE */
\r
349 /* Schedule memory task more often that usaul so that EcuM_StartupTwo() may return quicker */
\r
350 ActivateTask(TASK_ID_SchM_BswService);
\r
351 /* Set events on TASK_ID_BswService_Mem */
\r
352 SetRelAlarm(ALARM_ID_Alarm_BswService, 10, 2);
\r
355 * Call EcuM_StartupTwo that do:
\r
357 * - Wait for Nvm to complete
\r
358 * - Call EcuM_AL_DriverInitThree() to initiate Nvm dependent modules.
\r
362 /* Start to schedule BSW parts */
\r
363 SetRelAlarm(ALARM_ID_Alarm_BswService, 10, 5);
\r
365 EcuM_RequestRUN(ECUM_USER_User_1);
\r
367 ActivateTask(TASK_ID_Application);
\r
374 TASK(SchM_BswService) {
\r
375 EcuM_StateType state;
\r
377 EcuM_GetState(&state);
\r
380 case ECUM_STATE_STARTUP_ONE:
\r
381 /* Nothing to schedule */
\r
383 case ECUM_STATE_STARTUP_TWO:
\r
389 SCHM_MAINFUNCTION_ECUM();
\r
391 SCHM_MAINFUNCTION_CAN_WRITE();
\r
392 SCHM_MAINFUNCTION_CAN_READ();
\r
393 SCHM_MAINFUNCTION_CAN_BUSOFF();
\r
394 SCHM_MAINFUNCTION_CAN_ERROR();
\r
395 SCHM_MAINFUNCTION_CAN_WAKEUP();
\r
398 SCHM_MAINFUNCTION_COMRX();
\r
399 SCHM_MAINFUNCTION_COMTX();
\r
401 SCHM_MAINFUNCTION_CANTP();
\r
402 SCHM_MAINFUNCTION_J1939TP();
\r
403 SCHM_MAINFUNCTION_DCM();
\r
404 SCHM_MAINFUNCTION_DEM();
\r
406 SCHM_MAINFUNCTION_IOWHAB();
\r
407 SCHM_MAINFUNCTION_COMM();
\r
408 SCHM_MAINFUNCTION_NM();
\r
409 SCHM_MAINFUNCTION_CANNM();
\r
410 SCHM_MAINFUNCTION_CANSM();
\r
411 SCHM_MAINFUNCTION_WDMG();
\r
418 void SchM_MainFunction( void ) {
\r