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 /** @reqSettings DEFAULT_SPECIFICATION_REVISION=3.1.5 */
\r
19 /* ----------------------------[information]----------------------------------*/
\r
27 * Implements the Can Driver module
\r
30 * General Have Support
\r
31 * -------------------------------------------
\r
32 * ECUM_TTII_ENABLED N
\r
33 * ECUM_DEV_ERROR_DETECT Y
\r
34 * ECUM_VERSION_INFO_API Y
\r
35 * ECUM_INCLUDE_DEM N (controlled by USE_x macro's instead)
\r
36 * ECUM_INCLUDE_NVRAM_MGR N (controlled by USE_x macro's instead)
\r
37 * ECUM_INLCUDE_DET N (controlled by USE_x macro's instead)
\r
38 * ECUM_MAIN_FUNCTION_PERDIOD Y
\r
39 * ECUM_TTII_WKSOURCE N
\r
41 * Configuration Have Support
\r
42 * -------------------------------------------
\r
43 * ECUM_SLEEP_ACTIVITY_PERIOD ?
\r
44 * ECUM_CONFIGCONSISTENCY_HASH N
\r
45 * ECUM_RUN_SELF_REQUEST_PERIOD ?
\r
46 * ECUM_NVRAM_WRITEALL_TIMEOUT Y
\r
47 * ECUM_DEFAULT_APP_MODE ?
\r
50 * DefaultShutdownTarget
\r
51 * -------------------------------------------
\r
52 * ECUM_DEFAULT_SHUTDOWN_TARGET N
\r
55 * Things to start with:
\r
57 * - EcuM2861 , Watchdog
\r
58 * - ComM_EcuM_RunModeIndication() not called, See Figure 8 (Seems that the ComM does not do much either)
\r
64 //lint -emacro(904,VALIDATE,VALIDATE_RV,VALIDATE_NO_RV) //904 PC-Lint exception to MISRA 14.7 (validate macros).
\r
67 /* ----------------------------[includes]------------------------------------*/
\r
69 #include "Std_Types.h"
\r
71 #include "Modules.h"
\r
74 #include "EcuM_Generated_Types.h"
\r
75 #include "EcuM_Internals.h"
\r
76 #include "EcuM_Cbk.h"
\r
77 #include "SchM_EcuM.h"
\r
80 #include "ComStack_Types.h"
\r
81 #if defined(USE_DET)
\r
85 #if defined(USE_NVM)
\r
88 #if defined(USE_RTE)
\r
89 #include "Rte_Main.h"
\r
91 #if defined(USE_SCHM)
\r
96 /* ----------------------------[private define]------------------------------*/
\r
97 /* ----------------------------[private macro]-------------------------------*/
\r
98 /* ----------------------------[private typedef]-----------------------------*/
\r
99 /* ----------------------------[private function prototypes]-----------------*/
\r
100 /* ----------------------------[private variables]---------------------------*/
\r
102 EcuM_GlobalType internal_data;
\r
104 /* ----------------------------[private functions]---------------------------*/
\r
107 /* ----------------------------[public functions]----------------------------*/
\r
109 #if !defined(USE_DET) && defined(ECUM_DEV_ERROR_DETECT)
\r
110 #error EcuM configuration error. DET is not enabled when ECUM_DEV_ERROR_DETECT is set
\r
113 void EcuM_Init( void )
\r
115 Std_ReturnType status;
\r
116 set_current_state(ECUM_STATE_STARTUP_ONE);
\r
118 // Initialize drivers that are needed to determine PostBuild configuration
\r
119 EcuM_AL_DriverInitZero();
\r
121 // Initialize the OS
\r
124 // Setup interrupts
\r
127 // Determine PostBuild configuration
\r
128 internal_data.config = EcuM_DeterminePbConfiguration();
\r
131 // TODO: Check consistency of PB configuration
\r
133 // Initialize drivers needed before the OS-starts
\r
134 EcuM_AL_DriverInitOne(internal_data.config);
\r
136 // Determine the reset/wakeup reason
\r
137 // TODO Mcu_ResetType type = Mcu_GetResetReason();
\r
139 // Moved this here because EcuM_SelectShutdownTarget needs us to be initilized.
\r
140 internal_data.initiated = TRUE;
\r
142 // Set default shutdown target
\r
143 status = EcuM_SelectShutdownTarget(internal_data.config->EcuMDefaultShutdownTarget,internal_data.config->EcuMDefaultSleepMode);/** @req EcuM2181 */
\r
145 //TODO: Report error.
\r
149 // Set default application mode
\r
150 status = EcuM_SelectApplicationMode(internal_data.config->EcuMDefaultAppMode);
\r
152 //TODO: Report error.
\r
155 #if defined(USE_COMM) || defined(USE_ECUM_COMM)
\r
156 internal_data.run_comm_requests = 0;
\r
158 internal_data.run_requests = 0;
\r
159 internal_data.postrun_requests = 0;
\r
161 // Start this baby up
\r
162 AppModeType appMode;
\r
163 status = EcuM_GetApplicationMode(&appMode);
\r
165 //TODO: Report error.
\r
167 StartOS(appMode); /** @req EcuM2141 */
\r
171 * The order defined here is found in 3.1.5/EcuM2411
\r
173 void EcuM_StartupTwo(void)
\r
175 //TODO: Validate that we are in state STARTUP_ONE.
\r
176 #if defined(USE_NVM)
\r
177 extern CounterType Os_Arc_OsTickCounter;
\r
178 TickType tickTimerStart, tickTimerElapsed;
\r
179 static NvM_RequestResultType readAllResult;
\r
180 TickType tickTimer;
\r
181 StatusType tickTimerStatus;
\r
184 // Initialize the BSW scheduler
\r
185 #if defined(USE_SCHM)
\r
189 #if defined(USE_WDGM)
\r
190 WdgM_SetMode(internal_data.config->EcuMWdgMConfig->EcuMWdgMStartupMode);
\r
193 // Initialize drivers that don't need NVRAM data
\r
194 EcuM_AL_DriverInitTwo(internal_data.config);
\r
196 #if defined(USE_NVM)
\r
197 // Start timer to wait for NVM job to complete
\r
198 tickTimerStart = GetOsTick();
\r
201 // Prepare the system to startup RTE
\r
202 // TODO EcuM_OnRTEStartup();
\r
203 #if defined(USE_RTE)
\r
207 set_current_state(ECUM_STATE_STARTUP_TWO);
\r
209 #if defined(USE_NVM)
\r
212 /* Wait for the NVM job (NvmReadAll) to terminate. This assumes that:
\r
213 * - A task runs the memory MainFunctions, e.g. Ea_MainFunction(), Eep_MainFunction()
\r
215 * - A task runs the service functions for EcuM, Nvm.
\r
218 * Prio: LOW (So that the service functions for the other may run)
\r
221 /* Read the multiblock status */
\r
222 NvM_GetErrorStatus(0, &readAllResult);
\r
223 tickTimerElapsed = OS_TICKS2MS_OsTick(GetOsTick() - tickTimerStart);
\r
224 /* The timeout EcuMNvramReadAllTimeout is in ms */
\r
225 } while( (readAllResult == NVM_REQ_PENDING) && (tickTimerElapsed < internal_data.config->EcuMNvramReadAllTimeout) );
\r
227 // Wait for the NVM job (NvmReadAll) to terminate
\r
229 NvM_GetErrorStatus(0, &readAllResult); // Read the multiblock status
\r
230 tickTimer = tickTimerStart; // Save this because the GetElapsedCounterValue() will destroy it.
\r
231 tickTimerStatus = GetElapsedCounterValue(Os_Arc_OsTickCounter, &tickTimer, &tickTimerElapsed);
\r
232 if (tickTimerStatus != E_OK) {
\r
233 DET_REPORTERROR(MODULE_ID_ECUM, 0, ECUM_ARC_STARTUPTWO_ID, ECUM_E_ARC_TIMERERROR);
\r
235 } while( (readAllResult == NVM_REQ_PENDING) && (tickTimerElapsed < internal_data.config->EcuMNvramReadAllTimeout) );
\r
239 // Initialize drivers that need NVRAM data
\r
240 EcuM_AL_DriverInitThree(internal_data.config);
\r
242 // TODO: Indicate mode change to RTE
\r
244 // If coming from startup sequence, enter Run mode
\r
245 // if (internal_data.current_state == ECUM_STATE_STARTUP_TWO)
\r
246 EcuM_enter_run_mode();
\r
250 // Typically called from OS shutdown hook
\r
251 void EcuM_Shutdown(void)
\r
253 set_current_state(ECUM_STATE_GO_OFF_TWO);
\r
255 // Let the last drivers do a nice shutdown
\r
258 if (internal_data.shutdown_target == ECUM_STATE_OFF)
\r
260 EcuM_AL_SwitchOff();
\r
264 #if (MCU_PERFORM_RESET_API == STD_ON)
\r
265 Mcu_PerformReset();
\r
275 Std_ReturnType EcuM_GetState(EcuM_StateType* state)
\r
277 VALIDATE_RV(internal_data.initiated, ECUM_GETSTATE_ID, ECUM_E_NOT_INITIATED, E_NOT_OK);
\r
278 VALIDATE_RV(state != NULL, ECUM_GETSTATE_ID, ECUM_E_NULL_POINTER, E_NOT_OK);
\r
280 *state = internal_data.current_state;
\r
285 Std_ReturnType EcuM_SelectApplicationMode(AppModeType appMode)
\r
287 VALIDATE_RV(internal_data.initiated, ECUM_SELECTAPPMODE_ID, ECUM_E_NOT_INITIATED, E_NOT_OK);
\r
289 internal_data.app_mode = appMode;
\r
294 Std_ReturnType EcuM_GetApplicationMode(AppModeType* appMode)
\r
296 VALIDATE_RV(internal_data.initiated, ECUM_GETAPPMODE_ID, ECUM_E_NOT_INITIATED, E_NOT_OK);
\r
297 VALIDATE_RV(appMode != NULL, ECUM_GETAPPMODE_ID, ECUM_E_NULL_POINTER, E_NOT_OK);
\r
299 *appMode = internal_data.app_mode;
\r
304 Std_ReturnType EcuM_SelectBootTarget(EcuM_BootTargetType target)
\r
306 VALIDATE_RV(internal_data.initiated, ECUM_SELECT_BOOTARGET_ID, ECUM_E_NOT_INITIATED, E_NOT_OK);
\r
308 // TODO Do something great here
\r
314 Std_ReturnType EcuM_GetBootTarget(EcuM_BootTargetType* target)
\r
316 VALIDATE_RV(internal_data.initiated, ECUM_GET_BOOTARGET_ID, ECUM_E_NOT_INITIATED, E_NOT_OK);
\r
317 VALIDATE_RV(target != NULL, ECUM_GET_BOOTARGET_ID, ECUM_E_NULL_POINTER, E_NOT_OK);
\r
319 // TODO Return selected boot target here
\r
326 Std_ReturnType EcuM_SelectShutdownTarget(EcuM_StateType shutdownTarget, uint8 sleepMode)
\r
328 VALIDATE_RV(internal_data.initiated, ECUM_SELECTSHUTDOWNTARGET_ID, ECUM_E_NOT_INITIATED, E_NOT_OK);
\r
329 VALIDATE_RV((shutdownTarget == ECUM_STATE_OFF) || (shutdownTarget == ECUM_STATE_RESET) || (shutdownTarget == ECUM_STATE_SLEEP), ECUM_SELECTSHUTDOWNTARGET_ID, ECUM_E_INVALID_PAR, E_NOT_OK);
\r
331 internal_data.shutdown_target = shutdownTarget;
\r
332 internal_data.sleep_mode = sleepMode;
\r
338 Std_ReturnType EcuM_GetShutdownTarget(EcuM_StateType* shutdownTarget, uint8* sleepMode) /** @req EcuM2824 */
\r
340 VALIDATE_RV(internal_data.initiated, ECUM_GETSHUTDOWNTARGET_ID, ECUM_E_NOT_INITIATED, E_NOT_OK);
\r
341 VALIDATE_RV(shutdownTarget != NULL, ECUM_GETSHUTDOWNTARGET_ID, ECUM_E_NULL_POINTER, E_NOT_OK);
\r
342 VALIDATE_RV(sleepMode != NULL, ECUM_GETSHUTDOWNTARGET_ID, ECUM_E_NULL_POINTER, E_NOT_OK);
\r
344 *shutdownTarget = internal_data.shutdown_target;
\r
345 *sleepMode = internal_data.sleep_mode;
\r
351 Std_ReturnType EcuM_RequestRUN(EcuM_UserType user)
\r
353 VALIDATE_RV(internal_data.initiated, ECUM_REQUESTRUN_ID, ECUM_E_NOT_INITIATED, E_NOT_OK);
\r
354 VALIDATE_RV(user < ECUM_USER_ENDMARK, ECUM_REQUESTRUN_ID, ECUM_E_INVALID_PAR, E_NOT_OK);
\r
356 internal_data.run_requests |= (uint32)1 << user;
\r
361 Std_ReturnType EcuM_ReleaseRUN(EcuM_UserType user)
\r
363 VALIDATE_RV(internal_data.initiated, ECUM_RELEASERUN_ID, ECUM_E_NOT_INITIATED, E_NOT_OK);
\r
364 VALIDATE_RV(user < ECUM_USER_ENDMARK, ECUM_RELEASERUN_ID, ECUM_E_INVALID_PAR, E_NOT_OK);
\r
366 internal_data.run_requests &= ~((uint32)1 << user);
\r
374 void EcuM_KillAllRUNRequests( void ) {
\r
375 /* NOT IMPLEMENTED */
\r
383 void EcuM_SetWakeupEvent(EcuM_WakeupSourceType sources) {
\r
384 /* @req 3.1.5/EcuM2826 The function exists */
\r
385 /* @req 3.1.5/EcuM2171 */
\r
387 /* @req 3.1.5/EcuM2867 */
\r
388 #if ( ECUM_DEV_ERROR_DETECT == STD_ON )
\r
390 EcuM_WakeupSourceType wkSource;
\r
391 const EcuM_SleepModeType *sleepModePtr;
\r
393 sleepModePtr = &internal_data.config->EcuMSleepModeConfig[internal_data.sleep_mode];
\r
394 wkSource = sleepModePtr->EcuMWakeupSourceMask;
\r
396 if( !((sources | wkSource) == wkSource)) {
\r
397 Det_ReportError(MODULE_ID_ECUM, 0, ECUM_VALIDATE_WAKEUP_EVENT_ID, ECUM_E_UNKNOWN_WAKEUP_SOURCE );
\r
404 /* @req 3.1.5/EcuM1117 */
\r
405 internal_data.wakeupEvents |= sources;
\r
407 /* @req 3.1.5/EcuM2707 @req 3.1.5/EcuM2709*/
\r
408 // internal_data.wakeupTimer = ECUM_VALIDATION_TIMEOUT;
\r
412 #if defined(USE_COMM) || defined(USE_ECUM_COMM)
\r
413 Std_ReturnType EcuM_ComM_RequestRUN(NetworkHandleType channel)
\r
415 VALIDATE_RV(internal_data.initiated, ECUM_COMM_REQUESTRUN_ID, ECUM_E_NOT_INITIATED, E_NOT_OK);
\r
416 VALIDATE_RV(channel < 32, ECUM_COMM_REQUESTRUN_ID, ECUM_E_INVALID_PAR, E_NOT_OK);
\r
418 internal_data.run_comm_requests |= (uint32)1 << channel;
\r
423 Std_ReturnType EcuM_ComM_ReleaseRUN(NetworkHandleType channel)
\r
425 VALIDATE_RV(internal_data.initiated, ECUM_COMM_RELEASERUN_ID, ECUM_E_NOT_INITIATED, E_NOT_OK);
\r
426 VALIDATE_RV(channel < 32, ECUM_COMM_RELEASERUN_ID, ECUM_E_INVALID_PAR, E_NOT_OK);
\r
428 internal_data.run_comm_requests &= ~((uint32)1 << channel);
\r
433 boolean EcuM_ComM_HasRequestedRUN(NetworkHandleType channel)
\r
435 VALIDATE_RV(internal_data.initiated, ECUM_COMM_HASREQUESTEDRUN_ID, ECUM_E_NOT_INITIATED, FALSE);
\r
436 VALIDATE_RV(channel < 32, ECUM_COMM_HASREQUESTEDRUN_ID, ECUM_E_INVALID_PAR, FALSE);
\r
438 return (internal_data.run_comm_requests &((uint32)1 << channel)) != 0;
\r
442 Std_ReturnType EcuM_RequestPOST_RUN(EcuM_UserType user)
\r
444 VALIDATE_RV(internal_data.initiated, ECUM_REQUESTPOSTRUN_ID, ECUM_E_NOT_INITIATED, E_NOT_OK);
\r
445 VALIDATE_RV(user < ECUM_USER_ENDMARK, ECUM_REQUESTPOSTRUN_ID, ECUM_E_INVALID_PAR, E_NOT_OK);
\r
447 internal_data.postrun_requests |= (uint32)1 << user;
\r
452 Std_ReturnType EcuM_ReleasePOST_RUN(EcuM_UserType user)
\r
454 VALIDATE_RV(internal_data.initiated, ECUM_RELEASEPOSTRUN_ID, ECUM_E_NOT_INITIATED, E_NOT_OK);
\r
455 VALIDATE_RV(user < ECUM_USER_ENDMARK, ECUM_RELEASEPOSTRUN_ID, ECUM_E_INVALID_PAR, E_NOT_OK);
\r
457 internal_data.postrun_requests &= ~((uint32)1 << user);
\r
463 * TODO: Don't yet understand the use
\r
465 void EcuM_ClearWakeupEvent( EcuM_WakeupSourceType source )
\r
468 case ECUM_WKSTATUS_NONE:
\r
469 /* Seems quite pointless */
\r
471 case ECUM_WKSTATUS_PENDING:
\r
473 case ECUM_WKSTATUS_VALIDATED:
\r
475 case ECUM_WKSTATUS_EXPIRED:
\r
483 * Get the pending wakeup events.
\r
487 EcuM_WakeupSourceType EcuM_GetPendingWakeupEvents( void ) {
\r
488 /* @req 3.1.5/EcuM2827 API
\r
489 * @req 3.1.5/EcuM2172 Callable from interrupt context
\r
492 /* @req 3.1.5/EcuM1156 */
\r
493 return internal_data.wakeupEvents;
\r
498 void EcuM_CheckValidation(EcuM_WakeupSourceType wakeupSource) {
\r
499 /* Used only if CanIf is used ? CanIf_Checkvalidation(wakeupSource) */
\r
500 (void)wakeupSource;
\r
504 EcuM_WakeupSourceType EcuM_GetValidatedWakeupEvents( void ) {
\r
509 EcuM_WakeupStatusType EcuM_GetStatusOfWakeupSource( EcuM_WakeupSourceType sources ) {
\r