92 lines
2.4 KiB
C
Executable File
92 lines
2.4 KiB
C
Executable File
/***************************************************************************//**
|
|
* \file main_cm0plus.c
|
|
*
|
|
* CYT4BFBCJE rev_d CM0+ entry point for the four-motor seat movement ECU.
|
|
*******************************************************************************/
|
|
|
|
#include "cy_project.h"
|
|
#include "cy_device_headers.h"
|
|
#include "motor_control.h"
|
|
#include "safety_manager.h"
|
|
#include "seat_move_application.h"
|
|
#include "seat_move_config.h"
|
|
#include "bsp_seat_backrest_heater.h"
|
|
#include "bsp_seat_fan.h"
|
|
#include "seat_controller_thermal.h"
|
|
#include "seat_feature_profile.h"
|
|
|
|
volatile uint32_t g_seatMoveResetReason = 0u;
|
|
volatile uint32_t g_seatMoveInitResult = MOTOR_API_FAILURE;
|
|
|
|
static void SeatMove_HoldSafeOff(void)
|
|
{
|
|
for(;;)
|
|
{
|
|
Motor_ForceSafeOff();
|
|
SeatControllerThermal_ForceSafeOff();
|
|
SafetyManager_KickWatchdog();
|
|
Cy_SysTick_DelayInUs(SEAT_MOVE_TASK_PERIOD_US);
|
|
}
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
(void)BspSeatBackrestHeater_ForceOff();
|
|
(void)BspSeatFan_ForceOff();
|
|
SystemInit();
|
|
|
|
/* DRVOFF is asserted and IN1..IN4 are GPIO-low before any motor clock,
|
|
* SPI transaction or CAN command can enable a bridge. */
|
|
Motor_ForceSafeOff();
|
|
if(!BspSeatBackrestHeater_ForceOff() || !BspSeatFan_ForceOff())
|
|
{
|
|
SeatMove_HoldSafeOff();
|
|
}
|
|
g_seatMoveResetReason = Cy_SysReset_GetResetReason();
|
|
Cy_SysReset_ClearAllResetReasons();
|
|
|
|
SafetyManager_Init(g_seatMoveResetReason);
|
|
if(SafetyManager_IsInhibited())
|
|
{
|
|
SeatMove_HoldSafeOff();
|
|
}
|
|
|
|
__enable_irq();
|
|
g_seatMoveInitResult = Motor_Init();
|
|
if(g_seatMoveInitResult != MOTOR_API_SUCCESS)
|
|
{
|
|
SafetyManager_LatchFault(SAFETY_FAULT_DRIVER);
|
|
SeatMove_HoldSafeOff();
|
|
}
|
|
|
|
Motor_SetWatchdogServiceEnabled(true);
|
|
#if SEAT_FEATURE_THERMAL
|
|
if(!SeatControllerThermal_Init())
|
|
{
|
|
SafetyManager_LatchFault(SAFETY_FAULT_DRIVER);
|
|
SeatMove_HoldSafeOff();
|
|
}
|
|
#endif
|
|
if(!SeatMoveApplication_Init())
|
|
{
|
|
SeatMove_HoldSafeOff();
|
|
}
|
|
|
|
for(;;)
|
|
{
|
|
SeatMoveApplication_Service();
|
|
#if SEAT_FEATURE_THERMAL
|
|
SeatControllerThermal_Service1ms();
|
|
#endif
|
|
if(SafetyManager_IsInhibited())
|
|
{
|
|
Motor_ForceSafeOff();
|
|
SeatControllerThermal_ForceSafeOff();
|
|
}
|
|
SafetyManager_KickWatchdog();
|
|
Cy_SysTick_DelayInUs(SEAT_MOVE_TASK_PERIOD_US);
|
|
}
|
|
}
|
|
|
|
/* [] END OF FILE */
|