main.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. /*==================================================================================================
  2. * Project : RTD AUTOSAR 4.4
  3. * Platform : CORTEXM
  4. * Peripheral : S32K3XX
  5. * Dependencies : none
  6. *
  7. * Autosar Version : 4.4.0
  8. * Autosar Revision : ASR_REL_4_4_REV_0000
  9. * Autosar Conf.Variant :
  10. * SW Version : 1.0.0
  11. * Build Version : S32K3_RTD_1_0_0_D2110_ASR_REL_4_4_REV_0000_20211007
  12. *
  13. * (c) Copyright 2020 - 2021 NXP Semiconductors
  14. * All Rights Reserved.
  15. *
  16. * NXP Confidential. This software is owned or controlled by NXP and may only be
  17. * used strictly in accordance with the applicable license terms. By expressly
  18. * accepting such terms or by downloading, installing, activating and/or otherwise
  19. * using the software, you are agreeing that you have read, and that you agree to
  20. * comply with and are bound by, such license terms. If you do not agree to be
  21. * bound by the applicable license terms, then you may not retain, install,
  22. * activate or otherwise use the software.
  23. ==================================================================================================*/
  24. /**
  25. * @file main.c
  26. * 主函数入口
  27. * @addtogroup main_module main module documentation
  28. * @{
  29. */
  30. /* Including necessary configuration files. */
  31. #include "Mcal.h"
  32. #include "CAN.h"
  33. #include "SchM_Can.h"
  34. #include "Mcu.h"
  35. #include "Mcl.h"
  36. #include "Port.h"
  37. #include "Dio.h"
  38. #include "Uart.h"
  39. #include "Eep.h"
  40. #include "Fls.h"
  41. #include "SchM_Fls.h"
  42. #include "Platform.h"
  43. #include "Lpuart_Uart_Ip_Irq.h"
  44. #include "Flexio_Uart_Ip_Irq.h"
  45. #include "Dma_Ip.h"
  46. #include "Dma_Ip_Irq.h"
  47. #include "Lpuart_Uart_Ip.h"
  48. #include "Gpt.h"
  49. #include "Wdg_43_Instance0.h"
  50. #include "Icu.h"
  51. /* User includes */
  52. #include <string.h>
  53. #include "hal_adapter.h"
  54. #include "Lpuart_Uart_Ip.h"
  55. #include "AppTaskMain.h"
  56. #include "AppTaskUart0.h"
  57. #include "AppTaskUart1.h"
  58. #include "AppTaskCan.h"
  59. #include "AppTaskGps.h"
  60. #include "Hal_Fls.h"
  61. #include "SEGGER_SYSVIEW.h"
  62. #include "cm_backtrace.h"
  63. #define APPNAME "S32K146_4G"
  64. #define HARDWARE_VERSION "V1.0.0"
  65. #define SOFTWARE_VERSION "V0.0.1"
  66. int main(void)
  67. {
  68. volatile int exit_code = 0;
  69. coreInit();
  70. /* Initialize all pins*/
  71. #if (PORT_PRECOMPILE_SUPPORT == STD_ON)
  72. Port_Init(NULL_PTR);
  73. #elif (PORT_PRECOMPILE_SUPPORT == STD_OFF)
  74. Port_Init(&Port_Config_VS_0);
  75. #endif
  76. SystemModulesInit();
  77. //4G module power on
  78. Dio_WriteChannel(DioConf_DioChannel_PTA6_GPIO_OUT_MCU_4G_POW_EN, STD_ON);
  79. Dio_WriteChannel(DioConf_DioChannel_PTA7_GPIO_OUT_MCU_4G_PWRKEY, STD_ON);
  80. //GPS module power on
  81. Dio_WriteChannel(DioConf_DioChannel_PTD1_GPIO_OUT_MCU_GPS_POW_EN, STD_ON);
  82. // // this function should be called in ADC Task at once
  83. // Adc_CalibrationStatusType CalibStatus;
  84. // Adc_Calibrate(AdcHwUnit_0, &CalibStatus);
  85. // if (CalibStatus.Adc_UnitSelfTestStatus == E_NOT_OK)
  86. // {
  87. // // if so, the adc is failed to Calibrate;
  88. // }
  89. // ADC_ReadValue();
  90. // Boot_CheckDownlaodAPPStatus();
  91. // Dio_WriteChannel(DioConf_DioChannel_PTE0_GPIO_OUT_MCU_LED1, STD_OFF);
  92. // Dio_WriteChannel(DioConf_DioChannel_PTE1_GPIO_OUT_MCU_LED2, STD_OFF);
  93. // Dio_WriteChannel(DioConf_DioChannel_PTE7_GPIO_OUT_MCU_LED3, STD_OFF);
  94. // Dio_WriteChannel(DioConf_DioChannel_PTE8_GPIO_OUT_MCU_LED4, STD_OFF);
  95. // Dio_WriteChannel(DioConf_DioChannel_PTE9_GPIO_OUT_MCU_LED5, STD_OFF);
  96. Mcu_ResetType bootreason;
  97. bootreason = Mcu_GetResetReason();
  98. if(bootreason == MCU_STOP_ACKNOWLEDGE_ERROR_RESET)
  99. Dio_WriteChannel(DioConf_DioChannel_PTE0_GPIO_OUT_MCU_LED1, STD_OFF);
  100. else if(bootreason == MCU_MDM_AP_SYSTEM_RESET)
  101. Dio_WriteChannel(DioConf_DioChannel_PTE1_GPIO_OUT_MCU_LED2, STD_OFF);
  102. else if(bootreason == MCU_SW_RESET)
  103. {
  104. Dio_WriteChannel(DioConf_DioChannel_PTE0_GPIO_OUT_MCU_LED1, STD_OFF);
  105. Dio_WriteChannel(DioConf_DioChannel_PTE1_GPIO_OUT_MCU_LED2, STD_OFF);
  106. }
  107. else if(bootreason == MCU_CORE_LOCKUP_RESET)
  108. Dio_WriteChannel(DioConf_DioChannel_PTE7_GPIO_OUT_MCU_LED3, STD_OFF);
  109. else if(bootreason == MCU_JTAG_RESET)
  110. {
  111. Dio_WriteChannel(DioConf_DioChannel_PTE0_GPIO_OUT_MCU_LED1, STD_OFF);
  112. // Dio_WriteChannel(DioConf_DioChannel_PTE1_GPIO_OUT_MCU_LED2, STD_OFF);
  113. Dio_WriteChannel(DioConf_DioChannel_PTE7_GPIO_OUT_MCU_LED3, STD_OFF);
  114. }
  115. else if(bootreason == MCU_POWER_ON_RESET)
  116. {
  117. // Dio_WriteChannel(DioConf_DioChannel_PTE0_GPIO_OUT_MCU_LED1, STD_OFF);
  118. Dio_WriteChannel(DioConf_DioChannel_PTE1_GPIO_OUT_MCU_LED2, STD_OFF);
  119. Dio_WriteChannel(DioConf_DioChannel_PTE7_GPIO_OUT_MCU_LED3, STD_OFF);
  120. }
  121. else if(bootreason == MCU_EXTERNAL_PIN_RESET)
  122. {
  123. Dio_WriteChannel(DioConf_DioChannel_PTE0_GPIO_OUT_MCU_LED1, STD_OFF);
  124. Dio_WriteChannel(DioConf_DioChannel_PTE1_GPIO_OUT_MCU_LED2, STD_OFF);
  125. Dio_WriteChannel(DioConf_DioChannel_PTE7_GPIO_OUT_MCU_LED3, STD_OFF);
  126. }
  127. else if(bootreason == MCU_WATCHDOG_RESET)
  128. {
  129. // Dio_WriteChannel(DioConf_DioChannel_PTE0_GPIO_OUT_MCU_LED1, STD_OFF);
  130. // Dio_WriteChannel(DioConf_DioChannel_PTE1_GPIO_OUT_MCU_LED2, STD_OFF);
  131. // Dio_WriteChannel(DioConf_DioChannel_PTE7_GPIO_OUT_MCU_LED3, STD_OFF);
  132. Dio_WriteChannel(DioConf_DioChannel_PTE8_GPIO_OUT_MCU_LED4, STD_OFF);
  133. }
  134. else if(bootreason == MCU_CMU_LOSS_OF_CLOCK_RESET)
  135. {
  136. Dio_WriteChannel(DioConf_DioChannel_PTE0_GPIO_OUT_MCU_LED1, STD_OFF);
  137. // Dio_WriteChannel(DioConf_DioChannel_PTE1_GPIO_OUT_MCU_LED2, STD_OFF);
  138. // Dio_WriteChannel(DioConf_DioChannel_PTE7_GPIO_OUT_MCU_LED3, STD_OFF);
  139. Dio_WriteChannel(DioConf_DioChannel_PTE8_GPIO_OUT_MCU_LED4, STD_OFF);
  140. }
  141. else if(bootreason == MCU_LOSS_OF_LOCK_RESET)
  142. {
  143. // Dio_WriteChannel(DioConf_DioChannel_PTE0_GPIO_OUT_MCU_LED1, STD_OFF);
  144. Dio_WriteChannel(DioConf_DioChannel_PTE1_GPIO_OUT_MCU_LED2, STD_OFF);
  145. // Dio_WriteChannel(DioConf_DioChannel_PTE7_GPIO_OUT_MCU_LED3, STD_OFF);
  146. Dio_WriteChannel(DioConf_DioChannel_PTE8_GPIO_OUT_MCU_LED4, STD_OFF);
  147. }
  148. else if(bootreason == MCU_LOSS_OF_CLOCK_RESET)
  149. {
  150. Dio_WriteChannel(DioConf_DioChannel_PTE0_GPIO_OUT_MCU_LED1, STD_OFF);
  151. Dio_WriteChannel(DioConf_DioChannel_PTE1_GPIO_OUT_MCU_LED2, STD_OFF);
  152. // Dio_WriteChannel(DioConf_DioChannel_PTE7_GPIO_OUT_MCU_LED3, STD_OFF);
  153. Dio_WriteChannel(DioConf_DioChannel_PTE8_GPIO_OUT_MCU_LED4, STD_OFF);
  154. }
  155. else if(bootreason == MCU_LOW_OR_HIGH_VOLTAGE_DETECT_RESET)
  156. {
  157. // Dio_WriteChannel(DioConf_DioChannel_PTE0_GPIO_OUT_MCU_LED1, STD_OFF);
  158. // Dio_WriteChannel(DioConf_DioChannel_PTE1_GPIO_OUT_MCU_LED2, STD_OFF);
  159. Dio_WriteChannel(DioConf_DioChannel_PTE7_GPIO_OUT_MCU_LED3, STD_OFF);
  160. Dio_WriteChannel(DioConf_DioChannel_PTE8_GPIO_OUT_MCU_LED4, STD_OFF);
  161. }
  162. else if(bootreason == MCU_NO_RESET_REASON)
  163. {
  164. Dio_WriteChannel(DioConf_DioChannel_PTE0_GPIO_OUT_MCU_LED1, STD_OFF);
  165. // Dio_WriteChannel(DioConf_DioChannel_PTE1_GPIO_OUT_MCU_LED2, STD_OFF);
  166. Dio_WriteChannel(DioConf_DioChannel_PTE7_GPIO_OUT_MCU_LED3, STD_OFF);
  167. Dio_WriteChannel(DioConf_DioChannel_PTE8_GPIO_OUT_MCU_LED4, STD_OFF);
  168. }
  169. else if(bootreason == MCU_MULTIPLE_RESET_REASON)
  170. {
  171. // Dio_WriteChannel(DioConf_DioChannel_PTE0_GPIO_OUT_MCU_LED1, STD_OFF);
  172. Dio_WriteChannel(DioConf_DioChannel_PTE1_GPIO_OUT_MCU_LED2, STD_OFF);
  173. Dio_WriteChannel(DioConf_DioChannel_PTE7_GPIO_OUT_MCU_LED3, STD_OFF);
  174. Dio_WriteChannel(DioConf_DioChannel_PTE8_GPIO_OUT_MCU_LED4, STD_OFF);
  175. }
  176. else if(bootreason == MCU_RESET_UNDEFINED)
  177. {
  178. Dio_WriteChannel(DioConf_DioChannel_PTE0_GPIO_OUT_MCU_LED1, STD_OFF);
  179. Dio_WriteChannel(DioConf_DioChannel_PTE1_GPIO_OUT_MCU_LED2, STD_OFF);
  180. Dio_WriteChannel(DioConf_DioChannel_PTE7_GPIO_OUT_MCU_LED3, STD_OFF);
  181. Dio_WriteChannel(DioConf_DioChannel_PTE8_GPIO_OUT_MCU_LED4, STD_OFF);
  182. }
  183. #ifdef SEGGER_SYSTEMVIEW
  184. SEGGER_SYSVIEW_Conf();
  185. #endif
  186. #ifdef SEGGER_RTT_PRINTF
  187. SEGGER_RTT_Init();
  188. cm_backtrace_init(APPNAME,HARDWARE_VERSION,SOFTWARE_VERSION);
  189. SEGGER_RTT_printf("[%d] boot\r\n",__LINE__);
  190. #endif
  191. UartInit();
  192. xTaskCreate(MainTask, (const char *const)"MainTask", 512, (void *)0, main_TASK_PRIORITY + 6, NULL);
  193. // xTaskCreate(Uart0Task, (const char *const)"Uart0_Bms_Task", 512, (void *)0, main_TASK_PRIORITY + 2, NULL);
  194. xTaskCreate(CanTask, (const char *const)"CanTask", 512, (void *)0, main_TASK_PRIORITY + 2, &CanTask_Handle);
  195. xTaskCreate(GpsTask, (const char *const)"GpsTask", 512, (void *)0, main_TASK_PRIORITY + 1, &GpsTask_Handle);
  196. xTaskCreate(Uart_4G_Task, (const char *const)"Uart_4G_Task", 2048, (void *)0, main_TASK_PRIORITY + 0, &Uart_4G_Task_Handle);
  197. vTaskStartScheduler();
  198. for (;;)
  199. {
  200. if (exit_code != 0)
  201. {
  202. break;
  203. }
  204. }
  205. return exit_code;
  206. }
  207. /** @} */