main.c 5.9 KB

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