bsp_custom.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /****************************************************************************
  2. *
  3. * Copy right: 2018 Copyrigths of EigenComm Ltd.
  4. * File name: bsp_custom.c
  5. * Description:
  6. * History:
  7. *
  8. ****************************************************************************/
  9. #include <stdio.h>
  10. #include <stdarg.h>
  11. #include "clock_ec616.h"
  12. #include "bsp_custom.h"
  13. #include "slpman_ec616.h"
  14. #include "plat_config.h"
  15. #include "debug_log.h"
  16. void GPR_SetUartClk(void)
  17. {
  18. #if 0
  19. GPR_ClockDisable(GPR_UART0FuncClk);
  20. GPR_SetClockSrc(GPR_UART0FuncClk, GPR_UART0ClkSel_26M);
  21. GPR_ClockEnable(GPR_UART0FuncClk);
  22. GPR_SWReset(GPR_ResetUART0Func);
  23. #else
  24. GPR_ClockDisable(GPR_UART1FuncClk);
  25. GPR_SetClockSrc(GPR_UART1FuncClk, GPR_UART1ClkSel_26M);
  26. GPR_ClockEnable(GPR_UART1FuncClk);
  27. GPR_SWReset(GPR_ResetUART1Func);
  28. #endif
  29. }
  30. extern ARM_DRIVER_USART Driver_USART0;
  31. extern ARM_DRIVER_USART Driver_USART1;
  32. /*
  33. * set printf uart port
  34. * Parameter: port: for printf
  35. */
  36. static void SetPrintUart(usart_port_t port)
  37. {
  38. if(port == PORT_USART_0)
  39. {
  40. #if (RTE_UART0)
  41. UsartPrintHandle = &CREATE_SYMBOL(Driver_USART, 0);
  42. GPR_ClockDisable(GPR_UART0FuncClk);
  43. GPR_SetClockSrc(GPR_UART0FuncClk, GPR_UART0ClkSel_26M);
  44. GPR_ClockEnable(GPR_UART0FuncClk);
  45. GPR_SWReset(GPR_ResetUART0Func);
  46. #endif
  47. }
  48. else if(port == PORT_USART_1)
  49. {
  50. #if (RTE_UART1)
  51. UsartPrintHandle = &CREATE_SYMBOL(Driver_USART, 1);
  52. GPR_ClockDisable(GPR_UART1FuncClk);
  53. GPR_SetClockSrc(GPR_UART1FuncClk, GPR_UART1ClkSel_26M);
  54. GPR_ClockEnable(GPR_UART1FuncClk);
  55. GPR_SWReset(GPR_ResetUART1Func);
  56. #endif
  57. }
  58. if(UsartPrintHandle == NULL)
  59. return;
  60. UsartPrintHandle->Initialize(NULL);
  61. UsartPrintHandle->PowerControl(ARM_POWER_FULL);
  62. UsartPrintHandle->Control(ARM_USART_MODE_ASYNCHRONOUS | ARM_USART_DATA_BITS_8 |
  63. ARM_USART_PARITY_NONE | ARM_USART_STOP_BITS_1 |
  64. ARM_USART_FLOW_CONTROL_NONE, 115200ul);
  65. }
  66. #if LOW_POWER_AT_TEST
  67. slpManSlpState_t CheckUsrdefSlpStatus(void)
  68. {
  69. slpManSlpState_t status = SLP_HIB_STATE;
  70. if((slpManGetWakeupPinValue() & (0x1<<1)) == 0) // pad1 value is low
  71. status = SLP_IDLE_STATE;
  72. else
  73. status = SLP_HIB_STATE;
  74. return status;
  75. }
  76. #endif
  77. static void PMU_WakeupPadInit(void)
  78. {
  79. const padWakeupSettings_t cfg =
  80. {
  81. false, true, // group0 posedge, negedge
  82. false, false, // group1 posedge, negedge
  83. false, false, // group2 posedge, negedge
  84. };
  85. slpManSetWakeupPad(cfg);
  86. }
  87. /*
  88. * custom board related init
  89. * Parameter: none
  90. * note: this function shall be called in OS task context for dependency of reading configure file
  91. * which is implemented based on file system
  92. */
  93. void BSP_CustomInit(void)
  94. {
  95. extern void mpu_init(void);
  96. mpu_init();
  97. GPR_SetUartClk();
  98. #if LOW_POWER_AT_TEST
  99. slpManRegisterUsrSlpDepthCb(CheckUsrdefSlpStatus);
  100. #endif
  101. plat_config_raw_flash_t* rawFlashPlatConfig;
  102. BSP_LoadPlatConfigFromRawFlash();
  103. rawFlashPlatConfig = BSP_GetRawFlashPlatConfig();
  104. #ifdef USING_PRINTF
  105. SetPrintUart(PORT_USART_0);
  106. #else
  107. if(rawFlashPlatConfig && (rawFlashPlatConfig->logControl != 0 ))
  108. {
  109. SetUnilogUart(PORT_USART_0, rawFlashPlatConfig->uartBaudRate, true);
  110. uniLogInitStart(UART_0_FOR_UNILOG);
  111. ECOMM_STRING(UNILOG_PLA_STRING, build_info, P_SIG, "%s", getBuildInfo());
  112. }
  113. #endif
  114. slpManGetPMUSettings();
  115. PMU_WakeupPadInit();
  116. NVIC_DisableIRQ(PadWakeup0_IRQn);
  117. slpManStartWaitATTimer();
  118. CanSPIHandler(NULL,ARM_SPI_CPOL0_CPHA0,8,200000U);
  119. slpManAONIOPowerOn();
  120. PowerPinConfig(AON_IO);
  121. PowerPinConfig(NORMAL_IO);
  122. posGGAReset();
  123. NetSocDisplay(LED_SOC_0,LED_TURN_ON);
  124. NetSocDisplay(LED_SOC_1,LED_TURN_ON);
  125. NetSocDisplay(LED_SOC_2,LED_TURN_ON);
  126. NetSocDisplay(LED_SOC_3,LED_TURN_ON);
  127. FaultDisplay(LED_TURN_ON);
  128. }
  129. /**
  130. \fn void NVIC_WakeupIntHandler(void)
  131. \brief NVIC wakeup interrupt handler
  132. \param void
  133. */
  134. void Pad0_WakeupIntHandler(void)
  135. {
  136. if(slpManExtIntPreProcess(PadWakeup0_IRQn)==false)
  137. return;
  138. #ifdef USING_PRINTF
  139. printf("[%d]PadWakeup0_IRQn\r\n",__LINE__);
  140. #else
  141. ECOMM_TRACE(UNILOG_PLA_APP, pad0_Wk, P_SIG, 0, "PadWakeup0_IRQn");
  142. #endif
  143. //CanTiggerEvt(1);
  144. }
  145. void Pad1_WakeupIntHandler(void)
  146. {
  147. if(slpManExtIntPreProcess(PadWakeup1_IRQn)==false)
  148. return;
  149. }
  150. void Pad2_WakeupIntHandler(void)
  151. {
  152. if(slpManExtIntPreProcess(PadWakeup2_IRQn)==false)
  153. return;
  154. }
  155. void Pad3_WakeupIntHandler(void)
  156. {
  157. if(slpManExtIntPreProcess(PadWakeup3_IRQn)==false)
  158. return;
  159. // add custom code below //
  160. #ifdef USING_PRINTF
  161. printf("[%d]PadWakeup3_IRQn\r\n",__LINE__);
  162. #else
  163. ECOMM_TRACE(UNILOG_PLA_APP, pad3_Wk, P_SIG, 0, "PadWakeup3_IRQn");
  164. #endif
  165. }
  166. void Pad4_WakeupIntHandler(void)
  167. {
  168. if(slpManExtIntPreProcess(PadWakeup4_IRQn)==false)
  169. return;
  170. // add custom code below //
  171. #ifdef USING_PRINTF
  172. printf("[%d]PadWakeup3_IRQn\r\n",__LINE__);
  173. #else
  174. ECOMM_TRACE(UNILOG_PLA_APP, pad4_Wk, P_SIG, 0, "PadWakeup4_IRQn");
  175. #endif
  176. }
  177. void Pad5_WakeupIntHandler(void)
  178. {
  179. if(slpManExtIntPreProcess(PadWakeup5_IRQn)==false)
  180. return;
  181. }