main.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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 "cm_backtrace.h"
  62. #define APPNAME "S32K146_4G"
  63. #define HARDWARE_VERSION "V1.0.0"
  64. #define SOFTWARE_VERSION "V0.0.1"
  65. int main(void)
  66. {
  67. volatile int exit_code = 0;
  68. coreInit();
  69. /* Initialize all pins*/
  70. #if (PORT_PRECOMPILE_SUPPORT == STD_ON)
  71. Port_Init(NULL_PTR);
  72. #elif (PORT_PRECOMPILE_SUPPORT == STD_OFF)
  73. Port_Init(&Port_Config_VS_0);
  74. #endif
  75. SystemModulesInit();
  76. //4G module power on
  77. Dio_WriteChannel(DioConf_DioChannel_PTA6_GPIO_OUT_MCU_4G_POW_EN, STD_ON);
  78. Dio_WriteChannel(DioConf_DioChannel_PTA7_GPIO_OUT_MCU_4G_PWRKEY, STD_ON);
  79. //GPS module power on
  80. Dio_WriteChannel(DioConf_DioChannel_PTD1_GPIO_OUT_MCU_GPS_POW_EN, STD_ON);
  81. // // this function should be called in ADC Task at once
  82. // Adc_CalibrationStatusType CalibStatus;
  83. // Adc_Calibrate(AdcHwUnit_0, &CalibStatus);
  84. // if (CalibStatus.Adc_UnitSelfTestStatus == E_NOT_OK)
  85. // {
  86. // // if so, the adc is failed to Calibrate;
  87. // }
  88. // ADC_ReadValue();
  89. // Boot_CheckDownlaodAPPStatus();
  90. // Dio_WriteChannel(DioConf_DioChannel_PTE0_GPIO_OUT_MCU_LED1, STD_OFF);
  91. // Dio_WriteChannel(DioConf_DioChannel_PTE1_GPIO_OUT_MCU_LED2, STD_OFF);
  92. // Dio_WriteChannel(DioConf_DioChannel_PTE7_GPIO_OUT_MCU_LED3, STD_OFF);
  93. // Dio_WriteChannel(DioConf_DioChannel_PTE8_GPIO_OUT_MCU_LED4, STD_OFF);
  94. // Dio_WriteChannel(DioConf_DioChannel_PTE9_GPIO_OUT_MCU_LED5, STD_OFF);
  95. Mcu_ResetType bootreason;
  96. bootreason = Mcu_GetResetReason();
  97. if(bootreason == MCU_STOP_ACKNOWLEDGE_ERROR_RESET)
  98. Dio_WriteChannel(DioConf_DioChannel_PTE0_GPIO_OUT_MCU_LED1, STD_OFF);
  99. else if(bootreason == MCU_MDM_AP_SYSTEM_RESET)
  100. Dio_WriteChannel(DioConf_DioChannel_PTE1_GPIO_OUT_MCU_LED2, STD_OFF);
  101. else if(bootreason == MCU_SW_RESET)
  102. {
  103. Dio_WriteChannel(DioConf_DioChannel_PTE0_GPIO_OUT_MCU_LED1, STD_OFF);
  104. Dio_WriteChannel(DioConf_DioChannel_PTE1_GPIO_OUT_MCU_LED2, STD_OFF);
  105. }
  106. else if(bootreason == MCU_CORE_LOCKUP_RESET)
  107. Dio_WriteChannel(DioConf_DioChannel_PTE7_GPIO_OUT_MCU_LED3, STD_OFF);
  108. else if(bootreason == MCU_JTAG_RESET)
  109. {
  110. Dio_WriteChannel(DioConf_DioChannel_PTE0_GPIO_OUT_MCU_LED1, STD_OFF);
  111. // Dio_WriteChannel(DioConf_DioChannel_PTE1_GPIO_OUT_MCU_LED2, STD_OFF);
  112. Dio_WriteChannel(DioConf_DioChannel_PTE7_GPIO_OUT_MCU_LED3, STD_OFF);
  113. }
  114. else if(bootreason == MCU_POWER_ON_RESET)
  115. {
  116. // Dio_WriteChannel(DioConf_DioChannel_PTE0_GPIO_OUT_MCU_LED1, STD_OFF);
  117. Dio_WriteChannel(DioConf_DioChannel_PTE1_GPIO_OUT_MCU_LED2, STD_OFF);
  118. Dio_WriteChannel(DioConf_DioChannel_PTE7_GPIO_OUT_MCU_LED3, STD_OFF);
  119. }
  120. else if(bootreason == MCU_EXTERNAL_PIN_RESET)
  121. {
  122. Dio_WriteChannel(DioConf_DioChannel_PTE0_GPIO_OUT_MCU_LED1, STD_OFF);
  123. Dio_WriteChannel(DioConf_DioChannel_PTE1_GPIO_OUT_MCU_LED2, STD_OFF);
  124. Dio_WriteChannel(DioConf_DioChannel_PTE7_GPIO_OUT_MCU_LED3, STD_OFF);
  125. }
  126. else if(bootreason == MCU_WATCHDOG_RESET)
  127. {
  128. // Dio_WriteChannel(DioConf_DioChannel_PTE0_GPIO_OUT_MCU_LED1, STD_OFF);
  129. // Dio_WriteChannel(DioConf_DioChannel_PTE1_GPIO_OUT_MCU_LED2, STD_OFF);
  130. // Dio_WriteChannel(DioConf_DioChannel_PTE7_GPIO_OUT_MCU_LED3, STD_OFF);
  131. Dio_WriteChannel(DioConf_DioChannel_PTE8_GPIO_OUT_MCU_LED4, STD_OFF);
  132. }
  133. else if(bootreason == MCU_CMU_LOSS_OF_CLOCK_RESET)
  134. {
  135. Dio_WriteChannel(DioConf_DioChannel_PTE0_GPIO_OUT_MCU_LED1, STD_OFF);
  136. // Dio_WriteChannel(DioConf_DioChannel_PTE1_GPIO_OUT_MCU_LED2, STD_OFF);
  137. // Dio_WriteChannel(DioConf_DioChannel_PTE7_GPIO_OUT_MCU_LED3, STD_OFF);
  138. Dio_WriteChannel(DioConf_DioChannel_PTE8_GPIO_OUT_MCU_LED4, STD_OFF);
  139. }
  140. else if(bootreason == MCU_LOSS_OF_LOCK_RESET)
  141. {
  142. // Dio_WriteChannel(DioConf_DioChannel_PTE0_GPIO_OUT_MCU_LED1, STD_OFF);
  143. Dio_WriteChannel(DioConf_DioChannel_PTE1_GPIO_OUT_MCU_LED2, STD_OFF);
  144. // Dio_WriteChannel(DioConf_DioChannel_PTE7_GPIO_OUT_MCU_LED3, STD_OFF);
  145. Dio_WriteChannel(DioConf_DioChannel_PTE8_GPIO_OUT_MCU_LED4, STD_OFF);
  146. }
  147. else if(bootreason == MCU_LOSS_OF_CLOCK_RESET)
  148. {
  149. Dio_WriteChannel(DioConf_DioChannel_PTE0_GPIO_OUT_MCU_LED1, STD_OFF);
  150. Dio_WriteChannel(DioConf_DioChannel_PTE1_GPIO_OUT_MCU_LED2, STD_OFF);
  151. // Dio_WriteChannel(DioConf_DioChannel_PTE7_GPIO_OUT_MCU_LED3, STD_OFF);
  152. Dio_WriteChannel(DioConf_DioChannel_PTE8_GPIO_OUT_MCU_LED4, STD_OFF);
  153. }
  154. else if(bootreason == MCU_LOW_OR_HIGH_VOLTAGE_DETECT_RESET)
  155. {
  156. // Dio_WriteChannel(DioConf_DioChannel_PTE0_GPIO_OUT_MCU_LED1, STD_OFF);
  157. // Dio_WriteChannel(DioConf_DioChannel_PTE1_GPIO_OUT_MCU_LED2, STD_OFF);
  158. Dio_WriteChannel(DioConf_DioChannel_PTE7_GPIO_OUT_MCU_LED3, STD_OFF);
  159. Dio_WriteChannel(DioConf_DioChannel_PTE8_GPIO_OUT_MCU_LED4, STD_OFF);
  160. }
  161. else if(bootreason == MCU_NO_RESET_REASON)
  162. {
  163. Dio_WriteChannel(DioConf_DioChannel_PTE0_GPIO_OUT_MCU_LED1, STD_OFF);
  164. // Dio_WriteChannel(DioConf_DioChannel_PTE1_GPIO_OUT_MCU_LED2, STD_OFF);
  165. Dio_WriteChannel(DioConf_DioChannel_PTE7_GPIO_OUT_MCU_LED3, STD_OFF);
  166. Dio_WriteChannel(DioConf_DioChannel_PTE8_GPIO_OUT_MCU_LED4, STD_OFF);
  167. }
  168. else if(bootreason == MCU_MULTIPLE_RESET_REASON)
  169. {
  170. // Dio_WriteChannel(DioConf_DioChannel_PTE0_GPIO_OUT_MCU_LED1, STD_OFF);
  171. Dio_WriteChannel(DioConf_DioChannel_PTE1_GPIO_OUT_MCU_LED2, STD_OFF);
  172. Dio_WriteChannel(DioConf_DioChannel_PTE7_GPIO_OUT_MCU_LED3, STD_OFF);
  173. Dio_WriteChannel(DioConf_DioChannel_PTE8_GPIO_OUT_MCU_LED4, STD_OFF);
  174. }
  175. else if(bootreason == MCU_RESET_UNDEFINED)
  176. {
  177. Dio_WriteChannel(DioConf_DioChannel_PTE0_GPIO_OUT_MCU_LED1, STD_OFF);
  178. Dio_WriteChannel(DioConf_DioChannel_PTE1_GPIO_OUT_MCU_LED2, STD_OFF);
  179. Dio_WriteChannel(DioConf_DioChannel_PTE7_GPIO_OUT_MCU_LED3, STD_OFF);
  180. Dio_WriteChannel(DioConf_DioChannel_PTE8_GPIO_OUT_MCU_LED4, STD_OFF);
  181. }
  182. #ifdef SEGGER_RTT_PRINTF
  183. SEGGER_RTT_Init();
  184. cm_backtrace_init(APPNAME,HARDWARE_VERSION,SOFTWARE_VERSION);
  185. SEGGER_RTT_printf("[%d] boot\r\n",__LINE__);
  186. #endif
  187. UartInit();
  188. xTaskCreate(MainTask, (const char *const)"MainTask", 512, (void *)0, main_TASK_PRIORITY + 6, NULL);
  189. // xTaskCreate(Uart0Task, (const char *const)"Uart0_Bms_Task", 512, (void *)0, main_TASK_PRIORITY + 2, NULL);
  190. xTaskCreate(CanTask, (const char *const)"CanTask", 512, (void *)0, main_TASK_PRIORITY + 2, &CanTask_Handle);
  191. xTaskCreate(GpsTask, (const char *const)"GpsTask", 512, (void *)0, main_TASK_PRIORITY + 1, &GpsTask_Handle);
  192. xTaskCreate(Uart_4G_Task, (const char *const)"Uart_4G_Task", 2048, (void *)0, main_TASK_PRIORITY + 0, &Uart_4G_Task_Handle);
  193. vTaskStartScheduler();
  194. for (;;)
  195. {
  196. if (exit_code != 0)
  197. {
  198. break;
  199. }
  200. }
  201. return exit_code;
  202. }
  203. /** @} */