]> rtime.felk.cvut.cz Git - arc.git/blobdiff - system/SchM/SchM.c
EcuM: Gpt and SchM Fixes.
[arc.git] / system / SchM / SchM.c
index 11046e3885b501c9bca02685d947b68ea7dd7134..a75e7f199e866b4943ea2c23a9db9f3811a581b8 100644 (file)
@@ -65,7 +65,7 @@
  *  Can     CanMainFunctionReadPerdiod             No      No\r
  *          CanMainFunctionWritePerdiod\r
  *          ..\r
- *  CanIf   Have mainf. but no period              No\r
+ *  CanIf   Have No mainf                          N/A\r
  *  CanNm   CanNmMainFunctionPeriod                Yes     Accessible in struct.. not as define\r
  *  CanSm   Have mainf. but no period              Yes*2   Nothing is generated\r
  *  CanTp   CanTpMainFunctionPeriod                Yes     CANTP_MAIN_FUNCTION_PERIOD_TIME_MS\r
  * * Support in specification is limited\r
  * * Support in studio is limited\r
  *\r
- *   It's probably best to write scheduling information directly in the SchM_<mod>.h files.\r
- *   Since the SchM_<mod>.h files is included in the implementation file, do runtime checks\r
+ *  Write scheduling information directly in the SchM_<mod>.h files.\r
+ *  OR\r
+ *  Write scheduling information in SchM_cfg.h....better (keeps information in one place)\r
  *\r
  *     #if defined(USE_SCHM)\r
  *     assert( SCHM_TIMER(x) == <period> )\r
  *     #endif\r
  *\r
+ *  It seems it's mandatory to include SchM_<mod>.h for each BSW module.\r
+ *  So,\r
+ *  - <mod>.c ALWAYS include SchM_<mod.h>\r
+ *  - SchM.c have condidional include on SchM_<mod>.h, e.g must define it's MainFunctions.\r
+ *\r
+ *\r
+ *\r
  */\r
 \r
 #include "SchM.h"\r
 #include "SchM_cfg.h"\r
+\r
+\r
+#if defined(USE_MCU)\r
+#include "Mcu.h"\r
+#endif\r
+#if defined(USE_GPT)\r
+#include "Gpt.h"\r
+#endif\r
+\r
+#if defined(USE_CAN)\r
+#include "Can.h"\r
+#include "SchM_Can.h"\r
+#else\r
+#define        SCHM_MAINFUNCTION_CAN_WRITE()\r
+#define        SCHM_MAINFUNCTION_CAN_READ()\r
+#define        SCHM_MAINFUNCTION_CAN_BUSOFF()\r
+#define        SCHM_MAINFUNCTION_CAN_ERROR()\r
+#define        SCHM_MAINFUNCTION_CAN_WAKEUP()\r
+#endif\r
+\r
+#if defined(USE_CANIF)\r
+#include "CanIf.h"\r
+#include "SchM_CanIf.h"\r
+#endif\r
+\r
+#if defined(USE_PDUR)\r
+#include "PduR.h"\r
+#include "SchM_PduR.h"\r
+#endif\r
+\r
+#if defined(USE_COM)\r
+#include "Com.h"\r
+#include "SchM_Com.h"\r
+#else\r
+#define SCHM_MAINFUNCTION_COMRX()\r
+#define SCHM_MAINFUNCTION_COMTX()\r
+#endif\r
+\r
+#if defined(USE_CANTP)\r
+#include "CanTp.h"\r
+#include "SchM_CanTp.h"\r
+#else\r
+#define SCHM_MAINFUNCTION_CANTP()\r
+#endif\r
+\r
+#if defined(USE_J1939TP)\r
+#include "J1939Tp.h"\r
+#include "SchM_J1939TP.h"\r
+#else\r
+#define SCHM_MAINFUNCTION_J1939TP()\r
+#endif\r
+\r
+\r
+#if defined(USE_DCM)\r
+#include "Dcm.h"\r
+#include "SchM_Dcm.h"\r
+#else\r
+#define SCHM_MAINFUNCTION_DCM()\r
+#endif\r
+\r
+#if defined(USE_DEM)\r
+#include "Dem.h"\r
+#include "SchM_Dem.h"\r
+#else\r
+#define SCHM_MAINFUNCTION_DEM()\r
+#endif\r
+\r
+#if defined(USE_PWM)\r
+#include "Pwm.h"\r
+#include "SchM_Pwm.h"\r
+#endif\r
+\r
+\r
+#if defined(USE_IOHWAB)\r
+#include "IoHwAb.h"\r
+#include "SchM_IoHwAb.h"\r
+#else\r
+#define SCHM_MAINFUNCTION_IOWHAB()\r
+#endif\r
+\r
+#if defined(USE_FLS)\r
+#include "Fls.h"\r
+#include "SchM_Fls.h"\r
+#else\r
+#define SCHM_MAINFUNCTION_FLS()\r
+#endif\r
+\r
 #if defined(USE_ECUM)\r
 #include "EcuM.h"\r
 #include "SchM_EcuM.h"\r
+#else\r
+#define SCHM_MAINFUNCTION_ECUM()\r
 #endif\r
 \r
+#if defined(USE_EEP)\r
+#include "Eep.h"\r
+#include "SchM_Fls.h"\r
+#else\r
+#define SCHM_MAINFUNCTION_EEP()\r
+#endif\r
 \r
+#if defined(USE_FEE)\r
+#include "Fee.h"\r
+#include "SchM_Fee.h"\r
+#else\r
+#define SCHM_MAINFUNCTION_FEE()\r
+#endif\r
 \r
-typedef struct  {\r
-       uint32 timer;\r
-} SchM_InfoType;\r
+#if defined(USE_EA)\r
+#include "Ea.h"\r
+#include "SchM_Ea.h"\r
+#else\r
+#define SCHM_MAINFUNCTION_EA()\r
+#endif\r
 \r
-#define SCHM_INFO(_mod)        \\r
-               SchM_InfoType SchM_Info_ ## _mod\r
+#if defined(USE_NVM)\r
+#include "NvM.h"\r
+#include "SchM_NvM.h"\r
+#else\r
+#define SCHM_MAINFUNCTION_NVM()\r
+#endif\r
 \r
-#define SCHM_MAINFUNCTION(_mod,_func) \\r
-               if( SchM_Info_ ## _mod.timer++ > SCHM_TIMER_WRAP_ ## _mod ) { \\r
-                       _func; \\r
-                       SchM_Info_ ## _mod.timer = 0; \\r
-               }\r
+#if defined(USE_COMM)\r
+#include "ComM.h"\r
+#include "SchM_ComM.h"\r
+#else\r
+#define SCHM_MAINFUNCTION_COMM()\r
+#endif\r
 \r
-SCHM_INFO(EcuM);\r
-SCHM_INFO(NvM);\r
-SCHM_INFO(Fee);\r
-SCHM_INFO(Fee);\r
+#if defined(USE_NM)\r
+#include "Nm.h"\r
+#include "SchM_Nm.h"\r
+#else\r
+#define SCHM_MAINFUNCTION_NM()\r
+#endif\r
+\r
+#if defined(USE_CANNM)\r
+#include "CanNm.h"\r
+#include "SchM_CanNm.h"\r
+#else\r
+#define SCHM_MAINFUNCTION_CANNM()\r
+#endif\r
+\r
+#if defined(USE_CANSM)\r
+#include "CanSM.h"\r
+#include "SchM_CanSM.h"\r
+#else\r
+#define SCHM_MAINFUNCTION_CANSM()\r
+#endif\r
+\r
+#if defined(USE_UDPNM)\r
+#include "UdpNm.h"\r
+#endif\r
+\r
+#if defined(USE_LINSM)\r
+#include "LinSM.h"\r
+#endif\r
+\r
+#if defined(USE_SPI)\r
+#include "Spi.h"\r
+#include "SchM_Spi.h"\r
+#else\r
+#define SCHM_MAINFUNCTION_SPI()\r
+#endif\r
+\r
+#if defined(USE_WDG)\r
+#include "Wdg.h"\r
+#endif\r
+\r
+#if defined(USE_WDGM)\r
+#include "WdgM.h"\r
+#include "SchM_WdgM.h"\r
+#else\r
+#define SCHM_MAINFUNCTION_WDMG()\r
+#endif\r
+\r
+SCHM_DECLARE(CAN_WRITE);\r
+SCHM_DECLARE(CAN_READ);\r
+SCHM_DECLARE(CAN_BUSOFF);\r
+SCHM_DECLARE(CAN_WAKEUP);\r
+SCHM_DECLARE(CAN_ERROR);\r
+SCHM_DECLARE(COMRX);\r
+SCHM_DECLARE(COMTX);\r
+SCHM_DECLARE(CANTP);\r
+SCHM_DECLARE(CANNM);\r
+SCHM_DECLARE(DCM);\r
+SCHM_DECLARE(DEM);\r
+SCHM_DECLARE(COMM);\r
+SCHM_DECLARE(NM);\r
+SCHM_DECLARE(CANSM);\r
+SCHM_DECLARE(ECUM);\r
+SCHM_DECLARE(NVM);\r
+SCHM_DECLARE(FEE);\r
+SCHM_DECLARE(EA);\r
+SCHM_DECLARE(FLS);\r
+SCHM_DECLARE(WDGM_TRIGGER);\r
+SCHM_DECLARE(WDGM_ALIVESUPERVISION);\r
 \r
 \r
 \r
@@ -150,31 +331,96 @@ void SchM_GetVersionInfo( Std_VersionInfoType *versionInfo ) {
 \r
 }\r
 \r
-void SchM_MainFunction( void ) {\r
 \r
-#define EXCLUSIVE_AREA_0       0\r
-       SchM_Enter_EcuM(EXCLUSIVE_AREA_0);\r
-       SchM_Exit_EcuM(EXCLUSIVE_AREA_0);\r
-\r
-       SCHM_MAINFUNCTION(EcuM,EcuM_MainFunction);\r
+static void runMemory( void ) {\r
+       SCHM_MAINFUNCTION_NVM();\r
+       SCHM_MAINFUNCTION_EA();\r
+       SCHM_MAINFUNCTION_FEE();\r
+       SCHM_MAINFUNCTION_EEP();\r
+       SCHM_MAINFUNCTION_FLS();\r
+       SCHM_MAINFUNCTION_SPI();\r
 }\r
 \r
-/*\r
- * Implement\r
+/**\r
+ * Startup task.\r
  */\r
-// Critical sections\r
-// void SchM_Enter_<ModulePrefix>( uint8 instance, uint8 exclusiveArea )\r
-// void SchM_Exit_<ModulePrefix>( uint8 instance, uint8 exclusiveArea )\r
+TASK(SchM_Startup){\r
 \r
-// Triggers\r
-// SchM_ReturnType SchM_ActMainFunction_<ModulePrefix>( uint8 instance, uint8 activationPoint );\r
-// SchM_ReturnType SchM_CancelMainFunction_<ModulePrefix>( uint8 instance, uint8 activationPoint );\r
+       /* At this point EcuM ==  ECUM_STATE_STARTUP_ONE */\r
 \r
-/*\r
- * Callable functions in the <ModulePrefix>\r
- */\r
-// <ModulePrefix>_MainFunction_<name>()\r
-// <ModulePrefix>_MainFunction_<name>()\r
+       /* Schedule memory task more often that usaul so that EcuM_StartupTwo() may return quicker */\r
+       ActivateTask(TASK_ID_SchM_BswService);\r
+       /* Set events on TASK_ID_BswService_Mem */\r
+       SetRelAlarm(ALARM_ID_Alarm_BswService, 10, 2);\r
+\r
+       /*\r
+        * Call EcuM_StartupTwo that do:\r
+        * - Startup RTE,\r
+        * - Wait for Nvm to complete\r
+        * - Call EcuM_AL_DriverInitThree() to initiate Nvm dependent modules.\r
+        */\r
+       EcuM_StartupTwo();\r
+\r
+       /* Start to schedule BSW parts */\r
+       SetRelAlarm(ALARM_ID_Alarm_BswService, 10, 5);\r
+\r
+       EcuM_RequestRUN(ECUM_USER_User_1);\r
+\r
+       ActivateTask(TASK_ID_Application);\r
+\r
+       TerminateTask();\r
+\r
+}\r
+\r
+\r
+TASK(SchM_BswService) {\r
+       EcuM_StateType  state;\r
+\r
+       EcuM_GetState(&state);\r
+\r
+       switch( state ) {\r
+       case ECUM_STATE_STARTUP_ONE:\r
+               /* Nothing to schedule */\r
+               break;\r
+       case ECUM_STATE_STARTUP_TWO:\r
+               runMemory();\r
+               break;\r
+       default:\r
+               runMemory();\r
+\r
+               SCHM_MAINFUNCTION_ECUM();\r
+\r
+               SCHM_MAINFUNCTION_CAN_WRITE();\r
+               SCHM_MAINFUNCTION_CAN_READ();\r
+               SCHM_MAINFUNCTION_CAN_BUSOFF();\r
+               SCHM_MAINFUNCTION_CAN_ERROR();\r
+               SCHM_MAINFUNCTION_CAN_WAKEUP();\r
+\r
+\r
+               SCHM_MAINFUNCTION_COMRX();\r
+               SCHM_MAINFUNCTION_COMTX();\r
+\r
+               SCHM_MAINFUNCTION_CANTP();\r
+               SCHM_MAINFUNCTION_J1939TP();\r
+               SCHM_MAINFUNCTION_DCM();\r
+               SCHM_MAINFUNCTION_DEM();\r
+\r
+               SCHM_MAINFUNCTION_IOWHAB();\r
+               SCHM_MAINFUNCTION_COMM();\r
+               SCHM_MAINFUNCTION_NM();\r
+               SCHM_MAINFUNCTION_CANNM();\r
+               SCHM_MAINFUNCTION_CANSM();\r
+               SCHM_MAINFUNCTION_WDGM_TRIGGER();\r
+               SCHM_MAINFUNCTION_WDGM_ALIVESUPERVISION();\r
+               break;\r
+       }\r
+\r
+       TerminateTask();\r
+}\r
+\r
+void SchM_MainFunction( void ) {\r
+\r
+}\r
 \r
 \r
 \r