main.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. /* User includes */
  51. #include <string.h>
  52. #include "hal_adapter.h"
  53. #include "Lpuart_Uart_Ip.h"
  54. #include "AppTaskMain.h"
  55. #include "AppTaskUart0.h"
  56. #include "AppTaskUart1.h"
  57. #include "AppTaskCan.h"
  58. #include "AppTaskGps.h"
  59. #include "Hal_Fls.h"
  60. #include "SEGGER_SYSVIEW.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. /* Initialize the Mcu driver */
  69. #if (MCU_PRECOMPILE_SUPPORT == STD_ON)
  70. Mcu_Init(NULL_PTR);
  71. #elif (MCU_PRECOMPILE_SUPPORT == STD_OFF)
  72. Mcu_Init(&Mcu_Config_VS_0);
  73. #endif /* (MCU_PRECOMPILE_SUPPORT == STD_ON) */
  74. Mcu_InitClock(McuClockSettingConfig_0);
  75. /* Wait until PLL is locked */
  76. while (MCU_PLL_LOCKED != Mcu_GetPllStatus())
  77. {
  78. /* Busy wait until the System PLL is locked */
  79. }
  80. Mcu_DistributePllClock();
  81. /* Initialize Mcl module */
  82. Mcl_Init(NULL_PTR);
  83. Mcu_SetMode(McuModeSettingConf_Run);
  84. OsIf_Init(NULL_PTR);
  85. Platform_Init(NULL_PTR);
  86. /* Initialize all pins*/
  87. #if (PORT_PRECOMPILE_SUPPORT == STD_ON)
  88. Port_Init(NULL_PTR);
  89. #elif (PORT_PRECOMPILE_SUPPORT == STD_OFF)
  90. Port_Init(&Port_Config_VS_0);
  91. #endif
  92. /* Initializes an UART driver*/
  93. #if (UART_PRECOMPILE_SUPPORT == STD_ON)
  94. Uart_Init(NULL_PTR);
  95. #elif (UART_PRECOMPILE_SUPPORT == STD_OFF)
  96. Uart_Init(&Uart_xConfig_VS_0);
  97. #endif
  98. #if 1 /* Initialize Platform driver */
  99. #if (CAN_PRECOMPILE_SUPPORT == STD_ON)
  100. Can_Init(NULL_PTR);
  101. #elif (CAN_PRECOMPILE_SUPPORT == STD_OFF)
  102. Can_Init(&Can_Config_VS_0);
  103. #endif
  104. Can_SetControllerMode(CanController_0, CAN_CS_STARTED);
  105. Can_SetControllerMode(CanController_1, CAN_CS_STARTED);
  106. #endif
  107. #if (ADC_PRECOMPILE_SUPPORT == STD_ON)
  108. Adc_Init(NULL_PTR);
  109. #else
  110. Adc_Init(&Adc_Config_VS_0);
  111. #endif /* ADC_PRECOMPILE_SUPPORT == STD_ON */
  112. /* Partition only if it was not partitioned before for EERAM with code 0x4 */
  113. // Eep_DepartParitition(T_EEEPROM_SIZE);
  114. /* Initialize Eep driver */
  115. #if defined (EEP_PRECOMPILE_SUPPORT)
  116. Eep_Init(NULL_PTR);
  117. #else
  118. Eep_Init(&Eep_Config_VS_0);
  119. #endif
  120. //Init Flash Driver
  121. #if defined (FLS_PRECOMPILE_SUPPORT)
  122. Fls_Init(NULL_PTR);
  123. #else
  124. Fls_Init(&Fls_Config_VS_0);
  125. while(MEMIF_IDLE == Fls_GetStatus())
  126. {
  127. ;
  128. }
  129. #endif
  130. // this function should be called in ADC Task at once
  131. Adc_CalibrationStatusType CalibStatus;
  132. Adc_Calibrate(AdcHwUnit_0, &CalibStatus);
  133. if (CalibStatus.Adc_UnitSelfTestStatus == E_NOT_OK)
  134. {
  135. // if so, the adc is failed to Calibrate;
  136. }
  137. ADC_ReadValue();
  138. Boot_CheckDownlaodAPPStatus();
  139. Spi_Init(NULL_PTR);
  140. /* Initialize the Gpt driver */
  141. Gpt_Init(&Gpt_Config_VS_0);
  142. /* Enable the Gpt notification to periodically service the Wdg */
  143. Gpt_EnableNotification(GptConf_GptChannelConfiguration_GptChannelConfiguration_0);
  144. WdgInit();
  145. IP_LPUART0->CTRL |= LPUART_CTRL_ILT(1);
  146. IP_LPUART1->CTRL |= LPUART_CTRL_ILT(1);
  147. IP_LPUART2->CTRL |= LPUART_CTRL_ILT(1);
  148. IP_LPUART0->CTRL |= LPUART_CTRL_IDLECFG(5);
  149. IP_LPUART1->CTRL |= LPUART_CTRL_IDLECFG(3);
  150. IP_LPUART2->CTRL |= LPUART_CTRL_IDLECFG(3);
  151. Dio_WriteChannel(DioConf_DioChannel_PTE0_GPIO_OUT_MCU_LED1, STD_OFF);
  152. Dio_WriteChannel(DioConf_DioChannel_PTE1_GPIO_OUT_MCU_LED2, STD_OFF);
  153. Dio_WriteChannel(DioConf_DioChannel_PTE7_GPIO_OUT_MCU_LED3, STD_OFF);
  154. Dio_WriteChannel(DioConf_DioChannel_PTE8_GPIO_OUT_MCU_LED4, STD_OFF);
  155. Dio_WriteChannel(DioConf_DioChannel_PTE9_GPIO_OUT_MCU_LED5, STD_OFF);
  156. #ifdef SEGGER_SYSTEMVIEW
  157. SEGGER_SYSVIEW_Conf();
  158. SEGGER_SYSVIEW_Start();
  159. #endif
  160. #ifdef SEGGER_RTT_PRINTF
  161. SEGGER_RTT_Init();
  162. cm_backtrace_init(APPNAME,HARDWARE_VERSION,SOFTWARE_VERSION);
  163. SEGGER_RTT_printf("[%d] boot\r\n",__LINE__);
  164. #endif
  165. UartInit();
  166. xTaskCreate(MainTask, (const char *const)"MainTask", 256, (void *)0, main_TASK_PRIORITY + 6, NULL);
  167. xTaskCreate(Uart0Task, (const char *const)"Uart0_Bms_Task", 1024, (void *)0, main_TASK_PRIORITY + 2, NULL);
  168. xTaskCreate(CanTask, (const char *const)"CanTask", 512, (void *)0, main_TASK_PRIORITY + 2, NULL);
  169. xTaskCreate(GpsTask, (const char *const)"GpsTask", 512, (void *)0, main_TASK_PRIORITY + 1, NULL);
  170. xTaskCreate(Uart_4G_Task, (const char *const)"Uart_4G_Task", 2048, (void *)0, main_TASK_PRIORITY + 0, NULL);
  171. vTaskStartScheduler();
  172. for (;;)
  173. {
  174. if (exit_code != 0)
  175. {
  176. break;
  177. }
  178. }
  179. return exit_code;
  180. }
  181. /** @} */