bsp_custom.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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. #ifdef BL_FILE_LOG
  17. extern uint8_t lockoutState;
  18. #endif
  19. void GPR_SetUartClk(void)
  20. {
  21. GPR_ClockDisable(GPR_UART0FuncClk);
  22. GPR_ClockDisable(GPR_UART1FuncClk);
  23. GPR_ClockDisable(GPR_UART2FuncClk);
  24. GPR_SetClockSrc(GPR_UART0FuncClk, GPR_UART0ClkSel_26M);
  25. GPR_SetClockSrc(GPR_UART1FuncClk, GPR_UART1ClkSel_26M);
  26. GPR_SetClockSrc(GPR_UART2FuncClk, GPR_UART1ClkSel_26M);
  27. GPR_ClockEnable(GPR_UART0FuncClk);
  28. GPR_ClockEnable(GPR_UART1FuncClk);
  29. GPR_ClockEnable(GPR_UART2FuncClk);
  30. GPR_SWReset(GPR_ResetUART0Func);
  31. GPR_SWReset(GPR_ResetUART1Func);
  32. GPR_SWReset(GPR_ResetUART2Func);
  33. }
  34. extern ARM_DRIVER_USART Driver_USART0;
  35. extern ARM_DRIVER_USART Driver_USART1;
  36. /*
  37. * set printf uart port
  38. * Parameter: port: for printf
  39. */
  40. static void SetPrintUart(usart_port_t port)
  41. {
  42. if(port == PORT_USART_0)
  43. {
  44. #if (RTE_UART0)
  45. UsartPrintHandle = &CREATE_SYMBOL(Driver_USART, 0);
  46. GPR_ClockDisable(GPR_UART0FuncClk);
  47. GPR_SetClockSrc(GPR_UART0FuncClk, GPR_UART0ClkSel_26M);
  48. GPR_ClockEnable(GPR_UART0FuncClk);
  49. GPR_SWReset(GPR_ResetUART0Func);
  50. #endif
  51. }
  52. else if(port == PORT_USART_1)
  53. {
  54. #if (RTE_UART1)
  55. UsartPrintHandle = &CREATE_SYMBOL(Driver_USART, 1);
  56. GPR_ClockDisable(GPR_UART1FuncClk);
  57. GPR_SetClockSrc(GPR_UART1FuncClk, GPR_UART1ClkSel_26M);
  58. GPR_ClockEnable(GPR_UART1FuncClk);
  59. GPR_SWReset(GPR_ResetUART1Func);
  60. #endif
  61. }
  62. if(UsartPrintHandle == NULL)
  63. return;
  64. UsartPrintHandle->Initialize(NULL);
  65. UsartPrintHandle->PowerControl(ARM_POWER_FULL);
  66. UsartPrintHandle->Control(ARM_USART_MODE_ASYNCHRONOUS | ARM_USART_DATA_BITS_8 |
  67. ARM_USART_PARITY_NONE | ARM_USART_STOP_BITS_1 |
  68. ARM_USART_FLOW_CONTROL_NONE, 115200ul);
  69. }
  70. #if LOW_POWER_AT_TEST
  71. slpManSlpState_t CheckUsrdefSlpStatus(void)
  72. {
  73. slpManSlpState_t status = SLP_HIB_STATE;
  74. if((slpManGetWakeupPinValue() & (0x1<<1)) == 0) // pad1 value is low
  75. status = SLP_IDLE_STATE;
  76. else
  77. status = SLP_HIB_STATE;
  78. return status;
  79. }
  80. #endif
  81. /**
  82. \fn void CheckLockOutState(void)
  83. \brief CheckLockOutState
  84. \param void
  85. */
  86. void CheckLockOutState(void){
  87. if((slpManGetWakeupPinValue() & (0x1<<2)) == 0){
  88. #ifdef USING_PRINTF
  89. printf("LOCK_OUT DOWN\r\n");
  90. #endif
  91. #ifdef BL_FILE_LOG
  92. lockoutState=1;
  93. #endif
  94. }else{
  95. #ifdef USING_PRINTF
  96. printf("LOCK_OUT UP\r\n",__LINE__);
  97. #endif
  98. #ifdef BL_FILE_LOG
  99. lockoutState=0;
  100. #endif
  101. }
  102. }
  103. static void PMU_WakeupPadInit(void)
  104. {
  105. const padWakeupSettings_t cfg =
  106. {
  107. true, false, // group0 posedge, negedge
  108. true, true, // group1 posedge, negedge
  109. true, true, // group2 posedge, negedge
  110. };
  111. slpManSetWakeupPad(cfg);
  112. }
  113. /*
  114. * custom board related init
  115. * Parameter: none
  116. * note: this function shall be called in OS task context for dependency of reading configure file
  117. * which is implemented based on file system
  118. */
  119. void BSP_CustomInit(void)
  120. {
  121. extern void mpu_init(void);
  122. mpu_init();
  123. GPR_SetUartClk();
  124. relayConfigInit();
  125. #if LOW_POWER_AT_TEST
  126. slpManRegisterUsrSlpDepthCb(CheckUsrdefSlpStatus);
  127. #endif
  128. plat_config_raw_flash_t* rawFlashPlatConfig;
  129. BSP_LoadPlatConfigFromRawFlash();
  130. rawFlashPlatConfig = BSP_GetRawFlashPlatConfig();
  131. #if 1
  132. #ifdef USING_PRINTF
  133. SetPrintUart(PORT_USART_0);
  134. #else
  135. if(rawFlashPlatConfig && (rawFlashPlatConfig->logControl != 0 ))
  136. {
  137. SetUnilogUart(PORT_USART_0, rawFlashPlatConfig->uartBaudRate, true);
  138. uniLogInitStart(UART_0_FOR_UNILOG);
  139. ECOMM_STRING(UNILOG_PLA_STRING, build_info, P_SIG, "%s", getBuildInfo());
  140. }
  141. #endif
  142. #endif
  143. slpManGetPMUSettings();
  144. PMU_WakeupPadInit();
  145. NVIC_DisableIRQ(PadWakeup0_IRQn);//can
  146. NVIC_EnableIRQ(PadWakeup1_IRQn);//rx
  147. NVIC_EnableIRQ(PadWakeup2_IRQn);//lock
  148. NVIC_EnableIRQ(PadWakeup3_IRQn);//gsensor
  149. NVIC_EnableIRQ(PadWakeup4_IRQn);//gsensor
  150. NVIC_DisableIRQ(PadWakeup5_IRQn);//wakeup2
  151. CheckLockOutState();
  152. slpManStartWaitATTimer();
  153. CanSPIHandler(NULL,ARM_SPI_CPOL0_CPHA0,8,200000U);
  154. slpManAONIOPowerOn();
  155. PowerPinConfig(AON_IO);
  156. PowerPinConfig(NORMAL_IO);
  157. posGGAReset();
  158. GPSUsartHandler(9600);
  159. NetSocDisplay(LED_SOC_0,LED_TURN_ON);
  160. NetSocDisplay(LED_SOC_1,LED_TURN_ON);
  161. NetSocDisplay(LED_SOC_2,LED_TURN_ON);
  162. NetSocDisplay(LED_SOC_3,LED_TURN_ON);
  163. FaultDisplay(LED_TURN_ON);
  164. }
  165. /**
  166. \fn void NVIC_WakeupIntHandler(void)
  167. \brief NVIC wakeup interrupt handler
  168. \param void
  169. */
  170. void Pad0_WakeupIntHandler(void)
  171. {
  172. if(slpManExtIntPreProcess(PadWakeup0_IRQn)==false)
  173. return;
  174. #ifdef USING_PRINTF
  175. printf("[%d]PadWakeup0_IRQn\r\n",__LINE__);
  176. #else
  177. ECOMM_TRACE(UNILOG_PLA_APP, pad0_Wk, P_SIG, 0, "PadWakeup0_IRQn");
  178. #endif
  179. //CanTiggerEvt(1);
  180. }
  181. void Pad1_WakeupIntHandler(void)
  182. {
  183. if(slpManExtIntPreProcess(PadWakeup1_IRQn)==false)
  184. return;
  185. }
  186. void Pad2_WakeupIntHandler(void)
  187. {
  188. CheckLockOutState();
  189. if(slpManExtIntPreProcess(PadWakeup2_IRQn)==false)
  190. return;
  191. }
  192. void Pad3_WakeupIntHandler(void)
  193. {
  194. if(slpManExtIntPreProcess(PadWakeup3_IRQn)==false)
  195. return;
  196. // add custom code below //
  197. #ifdef USING_PRINTF
  198. printf("[%d]PadWakeup3_IRQn\r\n",__LINE__);
  199. #else
  200. ECOMM_TRACE(UNILOG_PLA_APP, pad3_Wk, P_SIG, 0, "PadWakeup3_IRQn");
  201. #endif
  202. }
  203. void Pad4_WakeupIntHandler(void)
  204. {
  205. if(slpManExtIntPreProcess(PadWakeup4_IRQn)==false)
  206. return;
  207. // add custom code below //
  208. #ifdef USING_PRINTF
  209. printf("[%d]PadWakeup3_IRQn\r\n",__LINE__);
  210. #else
  211. ECOMM_TRACE(UNILOG_PLA_APP, pad4_Wk, P_SIG, 0, "PadWakeup4_IRQn");
  212. #endif
  213. }
  214. void Pad5_WakeupIntHandler(void)
  215. {
  216. if(slpManExtIntPreProcess(PadWakeup5_IRQn)==false)
  217. return;
  218. }