/**************************************************************************** * * 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" void GPR_SetUartClk(void) { #if 0 GPR_ClockDisable(GPR_UART0FuncClk); GPR_SetClockSrc(GPR_UART0FuncClk, GPR_UART0ClkSel_26M); GPR_ClockEnable(GPR_UART0FuncClk); GPR_SWReset(GPR_ResetUART0Func); #else GPR_ClockDisable(GPR_UART1FuncClk); GPR_SetClockSrc(GPR_UART1FuncClk, GPR_UART1ClkSel_26M); GPR_ClockEnable(GPR_UART1FuncClk); GPR_SWReset(GPR_ResetUART1Func); #endif } 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) // pad1 value is low status = SLP_IDLE_STATE; else status = SLP_HIB_STATE; return status; } #endif static void PMU_WakeupPadInit(void) { const padWakeupSettings_t cfg = { false, true, // group0 posedge, negedge false, false, // group1 posedge, negedge false, false, // group2 posedge, negedge }; slpManSetWakeupPad(cfg); } /* * 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(); #if LOW_POWER_AT_TEST slpManRegisterUsrSlpDepthCb(CheckUsrdefSlpStatus); #endif plat_config_raw_flash_t* rawFlashPlatConfig; BSP_LoadPlatConfigFromRawFlash(); rawFlashPlatConfig = BSP_GetRawFlashPlatConfig(); #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 slpManGetPMUSettings(); PMU_WakeupPadInit(); NVIC_DisableIRQ(PadWakeup0_IRQn); slpManStartWaitATTimer(); CanSPIHandler(NULL,ARM_SPI_CPOL0_CPHA0,8,200000U); slpManAONIOPowerOn(); PowerPinConfig(AON_IO); PowerPinConfig(NORMAL_IO); posGGAReset(); 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; #ifdef USING_PRINTF printf("[%d]PadWakeup0_IRQn\r\n",__LINE__); #else ECOMM_TRACE(UNILOG_PLA_APP, pad0_Wk, P_SIG, 0, "PadWakeup0_IRQn"); #endif //CanTiggerEvt(1); } void Pad1_WakeupIntHandler(void) { if(slpManExtIntPreProcess(PadWakeup1_IRQn)==false) return; } void Pad2_WakeupIntHandler(void) { if(slpManExtIntPreProcess(PadWakeup2_IRQn)==false) return; } void Pad3_WakeupIntHandler(void) { if(slpManExtIntPreProcess(PadWakeup3_IRQn)==false) return; // add custom code below // #ifdef USING_PRINTF printf("[%d]PadWakeup3_IRQn\r\n",__LINE__); #else ECOMM_TRACE(UNILOG_PLA_APP, pad3_Wk, P_SIG, 0, "PadWakeup3_IRQn"); #endif } void Pad4_WakeupIntHandler(void) { if(slpManExtIntPreProcess(PadWakeup4_IRQn)==false) return; // add custom code below // #ifdef USING_PRINTF printf("[%d]PadWakeup3_IRQn\r\n",__LINE__); #else ECOMM_TRACE(UNILOG_PLA_APP, pad4_Wk, P_SIG, 0, "PadWakeup4_IRQn"); #endif } void Pad5_WakeupIntHandler(void) { if(slpManExtIntPreProcess(PadWakeup5_IRQn)==false) return; }