Ejemplo n.º 1
0
/* @req EcuM4046 */
Std_ReturnType EcuM_GoDown(uint16 caller) {
    VALIDATE_RV(EcuM_World.initiated, ECUM_GODOWN_ID, ECUM_E_UNINIT, E_NOT_OK);

    EcuM_WakeupSourceType wakeupEvents;
    Std_ReturnType rv = E_OK;
    /* !req EcuM4047 */
#if ECUM_DEFENSIVE_BEHAVIOR == STD_ON
    if (!isCallerAllowed(caller)) {
#if defined(USE_DEM)
        //TODO: Report ECUM_E_IMPROPER_CALLER to DEM when we have the 4.1 config
#endif
        return E_NOT_OK;
    }
#endif

#if defined(USE_BSWM)
    BswM_Deinit();
#endif

#if defined(USE_SCHM)
    SchM_Deinit();
#endif

    wakeupEvents = EcuM_GetPendingWakeupEvents();

    if (wakeupEvents != 0) {
        rv = EcuM_SelectShutdownTarget(ECUM_STATE_RESET, 0);
    }

    /* @req EcuM2952 */
    ShutdownOS(E_OK);

    return rv;
}
Ejemplo n.º 2
0
/**
 * Initialize EcuM.
 */
void EcuM_Init(void) {
	Std_ReturnType status;
	set_current_state(ECUM_STATE_STARTUP_ONE);

	// Initialize drivers that are needed to determine PostBuild configuration
	EcuM_AL_DriverInitZero();

	// Initialize the OS
	InitOS();

	// Setup interrupts
	Os_IsrInit();

	// Determine PostBuild configuration
	EcuM_World.config = EcuM_DeterminePbConfiguration();

	// TODO: Check consistency of PB configuration

	// Initialize drivers needed before the OS-starts
	EcuM_AL_DriverInitOne(EcuM_World.config);

	// Determine the reset/wakeup reason
	switch (Mcu_GetResetReason()) {
	case MCU_POWER_ON_RESET:
		EcuM_SetWakeupEvent(ECUM_WKSOURCE_POWER);
		break;
	case MCU_SW_RESET:
		EcuM_SetWakeupEvent(ECUM_WKSOURCE_RESET);
		break;
	case MCU_RESET_UNDEFINED:
		break;
	case MCU_WATCHDOG_RESET:
		EcuM_SetWakeupEvent(ECUM_WKSOURCE_INTERNAL_WDG);
		break;
	default:
		assert(0);
		break;
	}

	// Moved this here because EcuM_SelectShutdownTarget needs us to be initilized.
	EcuM_World.initiated = TRUE;

	// Set default shutdown target

	status = EcuM_SelectShutdownTarget(
					EcuM_World.config->EcuMDefaultShutdownTarget,
					EcuM_World.config->EcuMDefaultSleepMode);/** @req EcuM2181 */
	if (status != E_OK) {
		//TODO: Report error.
	}

	// Set default application mode
	status = EcuM_SelectApplicationMode(
					EcuM_World.config->EcuMDefaultAppMode);
	if (status != E_OK) {
		//TODO: Report error.
	}

#if defined(USE_COMM)
	EcuM_World.run_comm_requests = 0;
#endif
	EcuM_World.run_requests = 0;
	EcuM_World.postrun_requests = 0;

	// Start this baby up
	AppModeType appMode;
	status = EcuM_GetApplicationMode(&appMode);
	if (status != E_OK) {
		//TODO: Report error.
	}

	StartOS(appMode); /** @req EcuM2141 */
}