/**************************************************************************** * * Copy right: 2018 Copyrigths of EigenComm Ltd. * File name: bsp_custom.c * Description: * History: * ****************************************************************************/ #include #include #include "clock_ec616.h" #include "bsp_custom.h" #include "slpman_ec616.h" #include "plat_config.h" #include "debug_log.h" #include "os_exception.h" #if (WDT_FEATURE_ENABLE == 1) #include "wdt_ec616.h" #define WDT_TIMEOUT_VALUE (20) // in unit of second, shall be less than 256s #endif #include "AppSignal.h" #ifdef BL_FILE_LOG extern uint8_t lockoutState; #endif extern UINT8 Lockstatus; void GPR_SetUartClk(void) { GPR_ClockDisable(GPR_UART0FuncClk); GPR_ClockDisable(GPR_UART1FuncClk); GPR_ClockDisable(GPR_UART2FuncClk); GPR_SetClockSrc(GPR_UART0FuncClk, GPR_UART0ClkSel_26M); GPR_SetClockSrc(GPR_UART1FuncClk, GPR_UART1ClkSel_26M); GPR_SetClockSrc(GPR_UART2FuncClk, GPR_UART1ClkSel_26M); GPR_ClockEnable(GPR_UART0FuncClk); GPR_ClockEnable(GPR_UART1FuncClk); GPR_ClockEnable(GPR_UART2FuncClk); GPR_SWReset(GPR_ResetUART0Func); GPR_SWReset(GPR_ResetUART1Func); GPR_SWReset(GPR_ResetUART2Func); } extern ARM_DRIVER_USART Driver_USART0; extern ARM_DRIVER_USART Driver_USART1; /* * set printf uart port * Parameter: port: for printf */ static void SetPrintUart(usart_port_t port) { if (port == PORT_USART_0) { #if (RTE_UART0) UsartPrintHandle = &CREATE_SYMBOL(Driver_USART, 0); GPR_ClockDisable(GPR_UART0FuncClk); GPR_SetClockSrc(GPR_UART0FuncClk, GPR_UART0ClkSel_26M); GPR_ClockEnable(GPR_UART0FuncClk); GPR_SWReset(GPR_ResetUART0Func); #endif } else if (port == PORT_USART_1) { #if (RTE_UART1) UsartPrintHandle = &CREATE_SYMBOL(Driver_USART, 1); GPR_ClockDisable(GPR_UART1FuncClk); GPR_SetClockSrc(GPR_UART1FuncClk, GPR_UART1ClkSel_26M); GPR_ClockEnable(GPR_UART1FuncClk); GPR_SWReset(GPR_ResetUART1Func); #endif } if (UsartPrintHandle == NULL) return; UsartPrintHandle->Initialize(NULL); UsartPrintHandle->PowerControl(ARM_POWER_FULL); UsartPrintHandle->Control(ARM_USART_MODE_ASYNCHRONOUS | ARM_USART_DATA_BITS_8 | ARM_USART_PARITY_NONE | ARM_USART_STOP_BITS_1 | ARM_USART_FLOW_CONTROL_NONE, 115200ul); } #if LOW_POWER_AT_TEST slpManSlpState_t CheckUsrdefSlpStatus(void) { slpManSlpState_t status = SLP_HIB_STATE; if ((slpManGetWakeupPinValue() & (0x1 << 1)) == 0) // pad2 value is low status = SLP_IDLE_STATE; else status = SLP_HIB_STATE; return status; } #endif /** \fn void CheckLockOutState(void) \brief CheckLockOutState \param void */ void CheckLockOutState(void) { if ((slpManGetWakeupPinValue() & (0x1 << 2)) == 0) { #ifdef USING_PRINTF printf("LOCK_OUT DOWN\r\n"); #endif Lockstatus = true; #ifdef BL_FILE_LOG lockoutState = 1; #endif } else { Lockstatus = false; #ifdef USING_PRINTF printf("LOCK_OUT UP\r\n"); #endif #ifdef BL_FILE_LOG lockoutState = 0; #endif } } static void PMU_WakeupPadInit(void) { const padWakeupSettings_t cfg = { false, true, // group0 posedge, negedge true, true, // group1 posedge, negedge true, true, // group2 posedge, negedge }; slpManSetWakeupPad(cfg); } #if (WDT_FEATURE_ENABLE == 1) /* * WDT Initialize, wdt timeout value is 20s * Parameter: none */ void BSP_WdtInit(void) { // Config WDT clock, source from 32.768KHz and divide by WDT_TIMEOUT_VALUE GPR_SetClockSrc(GPR_WDGFuncClk, GPR_WDGClkSel_32K); GPR_SetClockDiv(GPR_WDGFuncClk, WDT_TIMEOUT_VALUE); wdt_config_t wdtConfig; wdtConfig.mode = WDT_InterruptResetMode; wdtConfig.timeoutValue = 32768U; WDT_Init(&wdtConfig); } void NMI_Handler() { ECOMM_TRACE(UNILOG_PLA_APP, enter_NMI_handler, P_ERROR, 0, "WDT timeout!!! Enter NMI Handler!!!"); // If we have been in exception handler excecution, we shall resume it. if (is_in_excep_handler()) { WDT_Stop(); } else { if (BSP_GetPlatConfigItemValue(PLAT_CONFIG_ITEM_FAULT_ACTION) == EXCEP_OPTION_SILENT_RESET) { ResetReasonWrite(RESET_REASON_WDT); EC_SystemReset(); while (1) ; } else { EC_ASSERT(0, 0, 0, 0); } } } #endif /* * custom board related init * Parameter: none * note: this function shall be called in OS task context for dependency of reading configure file * which is implemented based on file system */ void BSP_CustomInit(void) { extern void mpu_init(void); mpu_init(); GPR_SetUartClk(); relayConfigInit(); #if LOW_POWER_AT_TEST //slpManRegisterUsrSlpDepthCb(CheckUsrdefSlpStatus); //暂时屏蔽Rx拉低不允许睡眠的操作 #endif plat_config_raw_flash_t *rawFlashPlatConfig; BSP_LoadPlatConfigFromRawFlash(); rawFlashPlatConfig = BSP_GetRawFlashPlatConfig(); #if 1 #ifdef USING_PRINTF SetPrintUart(PORT_USART_0); #else if (rawFlashPlatConfig && (rawFlashPlatConfig->logControl != 0)) { SetUnilogUart(PORT_USART_0, rawFlashPlatConfig->uartBaudRate, true); uniLogInitStart(UART_0_FOR_UNILOG); ECOMM_STRING(UNILOG_PLA_STRING, build_info, P_SIG, "%s", getBuildInfo()); } #endif #endif #if (WDT_FEATURE_ENABLE == 1) if (BSP_GetPlatConfigItemValue(PLAT_CONFIG_ITEM_START_WDT)) { BSP_WdtInit(); WDT_Start(); } #endif slpManGetPMUSettings(); ResetReasonInit(); PMU_WakeupPadInit(); NVIC_EnableIRQ(PadWakeup0_IRQn); //can NVIC_DisableIRQ(PadWakeup1_IRQn); //rx NVIC_EnableIRQ(PadWakeup2_IRQn); //lock NVIC_DisableIRQ(PadWakeup3_IRQn); //gsensor NVIC_DisableIRQ(PadWakeup4_IRQn); //gsensor NVIC_EnableIRQ(PadWakeup5_IRQn); //wakeup2 CheckLockOutState(); slpManStartWaitATTimer(); CanSPIHandler(NULL, ARM_SPI_CPOL0_CPHA0, 8, 200000U); slpManAONIOPowerOn(); PowerPinConfig(AON_IO); PowerPinConfig(NORMAL_IO); posGGAReset(); GPSUsartHandler(9600); NetSocDisplay(LED_SOC_0, LED_TURN_ON); NetSocDisplay(LED_SOC_1, LED_TURN_ON); NetSocDisplay(LED_SOC_2, LED_TURN_ON); NetSocDisplay(LED_SOC_3, LED_TURN_ON); FaultDisplay(LED_TURN_ON); } /** \fn void NVIC_WakeupIntHandler(void) \brief NVIC wakeup interrupt handler \param void */ void Pad0_WakeupIntHandler(void) { if (slpManExtIntPreProcess(PadWakeup0_IRQn) == false) { return; } else { setbit(PadInterrupt, 0); } #ifdef USING_PRINTF1 printf("-[%d]-[%s]\n", __LINE__, __FUNCTION__); #endif } void Pad1_WakeupIntHandler(void) { if (slpManExtIntPreProcess(PadWakeup1_IRQn) == false) { return; } else { #ifdef USING_PRINTF printf("Pad1-[%d]\n", __LINE__); #endif setbit(PadInterrupt, 1); } } void Pad2_WakeupIntHandler(void) { CheckLockOutState(); if (slpManExtIntPreProcess(PadWakeup2_IRQn) == false) { return; } else { setbit(PadInterrupt, 2); } } void Pad3_WakeupIntHandler(void) { if (slpManExtIntPreProcess(PadWakeup3_IRQn) == false) { return; } else { setbit(PadInterrupt, 3); } } void Pad4_WakeupIntHandler(void) { if (slpManExtIntPreProcess(PadWakeup4_IRQn) == false) { return; } else { setbit(PadInterrupt, 4); } } void Pad5_WakeupIntHandler(void) { if (slpManExtIntPreProcess(PadWakeup5_IRQn) == false) { return; } else { setbit(PadInterrupt, 5); } }