bsp_custom.c 6.5 KB

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