123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259 |
- /****************************************************************************
- *
- * Copy right: 2018 Copyrigths of EigenComm Ltd.
- * File name: bsp_custom.c
- * Description:
- * History:
- *
- ****************************************************************************/
- #include <stdio.h>
- #include <stdarg.h>
- #include "clock_ec616.h"
- #include "bsp_custom.h"
- #include "slpman_ec616.h"
- #include "plat_config.h"
- #include "debug_log.h"
- #ifdef BL_FILE_LOG
- extern uint8_t lockoutState;
- #endif
- 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) // pad1 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
- #ifdef BL_FILE_LOG
- lockoutState=1;
- #endif
- }else{
- #ifdef USING_PRINTF
- printf("LOCK_OUT UP\r\n",__LINE__);
- #endif
- #ifdef BL_FILE_LOG
- lockoutState=0;
- #endif
- }
- }
- static void PMU_WakeupPadInit(void)
- {
- const padWakeupSettings_t cfg =
- {
- true, false, // group0 posedge, negedge
- true, true, // group1 posedge, negedge
- true, true, // 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();
- relayConfigInit();
- #if LOW_POWER_AT_TEST
- slpManRegisterUsrSlpDepthCb(CheckUsrdefSlpStatus);
- #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
- slpManGetPMUSettings();
- PMU_WakeupPadInit();
- NVIC_DisableIRQ(PadWakeup0_IRQn);//can
- NVIC_EnableIRQ(PadWakeup1_IRQn);//rx
- NVIC_EnableIRQ(PadWakeup2_IRQn);//lock
- NVIC_EnableIRQ(PadWakeup3_IRQn);//gsensor
- NVIC_EnableIRQ(PadWakeup4_IRQn);//gsensor
- NVIC_DisableIRQ(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;
- #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)
- {
- CheckLockOutState();
- 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;
- }
|