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
151 #define SCHM_MAINFUNCTION_PDUR()
\r
154 #if defined(USE_COM)
\r
156 #include "SchM_Com.h"
\r
158 #define SCHM_MAINFUNCTION_COMRX()
\r
159 #define SCHM_MAINFUNCTION_COMTX()
\r
162 #if defined(USE_CANTP)
\r
164 #include "SchM_CanTp.h"
\r
166 #define SCHM_MAINFUNCTION_CANTP()
\r
169 #if defined(USE_J1939TP)
\r
170 #include "J1939Tp.h"
\r
171 #include "SchM_J1939TP.h"
\r
173 #define SCHM_MAINFUNCTION_J1939TP()
\r
177 #if defined(USE_DCM)
\r
179 #include "SchM_Dcm.h"
\r
181 #define SCHM_MAINFUNCTION_DCM()
\r
184 #if defined(USE_DEM)
\r
186 #include "SchM_Dem.h"
\r
188 #define SCHM_MAINFUNCTION_DEM()
\r
191 #if defined(USE_PWM)
\r
193 #include "SchM_Pwm.h"
\r
195 #define SCHM_MAINFUNCTION_PWM()
\r
199 #if defined(USE_IOHWAB)
\r
200 #include "IoHwAb.h"
\r
201 #include "SchM_IoHwAb.h"
\r
203 #define SCHM_MAINFUNCTION_IOWHAB()
\r
206 #if defined(USE_FLS)
\r
208 #include "SchM_Fls.h"
\r
210 #define SCHM_MAINFUNCTION_FLS()
\r
213 #if defined(USE_ECUM)
\r
215 #include "SchM_EcuM.h"
\r
217 #define SCHM_MAINFUNCTION_ECUM()
\r
220 #if defined(USE_EEP)
\r
222 #include "SchM_Fls.h"
\r
224 #define SCHM_MAINFUNCTION_EEP()
\r
227 #if defined(USE_FEE)
\r
229 #include "SchM_Fee.h"
\r
231 #define SCHM_MAINFUNCTION_FEE()
\r
234 #if defined(USE_EA)
\r
236 #include "SchM_Ea.h"
\r
238 #define SCHM_MAINFUNCTION_EA()
\r
241 #if defined(USE_NVM)
\r
243 #include "SchM_NvM.h"
\r
245 #define SCHM_MAINFUNCTION_NVM()
\r
248 #if defined(USE_COMM)
\r
250 #include "SchM_ComM.h"
\r
252 #define SCHM_MAINFUNCTION_COMM()
\r
255 #if defined(USE_NM)
\r
257 #include "SchM_Nm.h"
\r
259 #define SCHM_MAINFUNCTION_NM()
\r
262 #if defined(USE_CANNM)
\r
264 #include "SchM_CanNm.h"
\r
266 #define SCHM_MAINFUNCTION_CANNM()
\r
269 #if defined(USE_CANSM)
\r
271 #include "SchM_CanSM.h"
\r
273 #define SCHM_MAINFUNCTION_CANSM()
\r
276 #if defined(USE_UDPNM)
\r
280 #if defined(USE_LINSM)
\r
284 #if defined(USE_SPI)
\r
286 #include "SchM_Spi.h"
\r
288 #define SCHM_MAINFUNCTION_SPI()
\r
291 #if defined(USE_WDG)
\r
295 #if defined(USE_WDGM)
\r
297 #include "SchM_WdgM.h"
\r
299 #define SCHM_MAINFUNCTION_WDMG()
\r
302 SCHM_DECLARE(ECUM);
\r
310 void SchM_Init( void ) {
\r
314 void SchM_Deinit( void ) {
\r
318 void SchM_GetVersionInfo( Std_VersionInfoType *versionInfo ) {
\r
323 static void runMemory( void ) {
\r
324 SCHM_MAINFUNCTION_NVM();
\r
325 SCHM_MAINFUNCTION_EA();
\r
326 SCHM_MAINFUNCTION_FEE();
\r
327 SCHM_MAINFUNCTION_EEP();
\r
328 SCHM_MAINFUNCTION_FLS();
\r
329 SCHM_MAINFUNCTION_SPI();
\r
335 TASK(SchM_Startup){
\r
337 /* At this point EcuM == ECUM_STATE_STARTUP_ONE */
\r
339 /* Schedule memory task more often that usaul so that EcuM_StartupTwo() may return quicker */
\r
340 ActivateTask(TASK_ID_SchM_BswService);
\r
341 /* Set events on TASK_ID_BswService_Mem */
\r
342 SetRelAlarm(ALARM_ID_Alarm_BswService, 10, 2);
\r
345 * Call EcuM_StartupTwo that do:
\r
347 * - Wait for Nvm to complete
\r
348 * - Call EcuM_AL_DriverInitThree() to initiate Nvm dependent modules.
\r
352 /* Start to schedule BSW parts */
\r
353 SetRelAlarm(ALARM_ID_Alarm_BswService, 10, 5);
\r
355 EcuM_RequestRUN(ECUM_USER_User_1);
\r
357 ActivateTask(TASK_ID_Application);
\r
364 TASK(SchM_BswService) {
\r
365 EcuM_StateType state;
\r
367 EcuM_GetState(&state);
\r
370 case ECUM_STATE_STARTUP_ONE:
\r
371 /* Nothing to schedule */
\r
373 case ECUM_STATE_STARTUP_TWO:
\r
379 SCHM_MAINFUNCTION_ECUM();
\r
381 SCHM_MAINFUNCTION_CAN_WRITE();
\r
382 SCHM_MAINFUNCTION_CAN_READ();
\r
383 SCHM_MAINFUNCTION_CAN_BUSOFF();
\r
384 SCHM_MAINFUNCTION_CAN_ERROR();
\r
385 SCHM_MAINFUNCTION_CAN_WAKEUP();
\r
387 SCHM_MAINFUNCTION_PDUR();
\r
389 SCHM_MAINFUNCTION_COMRX();
\r
390 SCHM_MAINFUNCTION_COMTX();
\r
392 SCHM_MAINFUNCTION_CANTP();
\r
393 SCHM_MAINFUNCTION_J1939TP();
\r
394 SCHM_MAINFUNCTION_DCM();
\r
395 SCHM_MAINFUNCTION_DEM();
\r
396 SCHM_MAINFUNCTION_PWM();
\r
397 SCHM_MAINFUNCTION_IOWHAB();
\r
398 SCHM_MAINFUNCTION_COMM();
\r
399 SCHM_MAINFUNCTION_NM();
\r
400 SCHM_MAINFUNCTION_CANNM();
\r
401 SCHM_MAINFUNCTION_CANSM();
\r
402 SCHM_MAINFUNCTION_WDMG();
\r
409 void SchM_MainFunction( void ) {
\r