main.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 "Platform.h"
  40. #include "Lpuart_Uart_Ip_Irq.h"
  41. #include "Flexio_Uart_Ip_Irq.h"
  42. #include "Dma_Ip.h"
  43. #include "Dma_Ip_Irq.h"
  44. #include "Lpuart_Uart_Ip.h"
  45. /* User includes */
  46. #include <string.h>
  47. #include "hal_adapter.h"
  48. #include "Lpuart_Uart_Ip.h"
  49. #include "AppTaskMain.h"
  50. #include "AppTaskUart0.h"
  51. #include "AppTaskUart1.h"
  52. #include "AppTaskCan.h"
  53. #include "AppTaskGps.h"
  54. int main(void)
  55. {
  56. volatile int exit_code = 0;
  57. /* Initialize the Mcu driver */
  58. #if (MCU_PRECOMPILE_SUPPORT == STD_ON)
  59. Mcu_Init(NULL_PTR);
  60. #elif (MCU_PRECOMPILE_SUPPORT == STD_OFF)
  61. Mcu_Init(&Mcu_Config_VS_0);
  62. #endif /* (MCU_PRECOMPILE_SUPPORT == STD_ON) */
  63. Mcu_InitClock(McuClockSettingConfig_0);
  64. /* Wait until PLL is locked */
  65. while (MCU_PLL_LOCKED != Mcu_GetPllStatus())
  66. {
  67. /* Busy wait until the System PLL is locked */
  68. }
  69. Mcu_DistributePllClock();
  70. /* Initialize Mcl module */
  71. Mcl_Init(NULL_PTR);
  72. Mcu_SetMode(McuModeSettingConf_Run);
  73. OsIf_Init(NULL_PTR);
  74. Platform_Init(NULL_PTR);
  75. /* Initialize all pins*/
  76. #if (PORT_PRECOMPILE_SUPPORT == STD_ON)
  77. Port_Init(NULL_PTR);
  78. #elif (PORT_PRECOMPILE_SUPPORT == STD_OFF)
  79. Port_Init(&Port_Config_VS_0);
  80. #endif
  81. /* Initializes an UART driver*/
  82. #if (UART_PRECOMPILE_SUPPORT == STD_ON)
  83. Uart_Init(NULL_PTR);
  84. #elif (UART_PRECOMPILE_SUPPORT == STD_OFF)
  85. Uart_Init(&Uart_xConfig_VS_0);
  86. #endif
  87. #if 1 /* Initialize Platform driver */
  88. #if (CAN_PRECOMPILE_SUPPORT == STD_ON)
  89. Can_Init(NULL_PTR);
  90. #elif (CAN_PRECOMPILE_SUPPORT == STD_OFF)
  91. Can_Init(&Can_Config_VS_0);
  92. #endif
  93. Can_SetControllerMode(CanController_0, CAN_CS_STARTED);
  94. Can_SetControllerMode(CanController_1, CAN_CS_STARTED);
  95. #endif
  96. #if (ADC_PRECOMPILE_SUPPORT == STD_ON)
  97. Adc_Init(NULL_PTR);
  98. #else
  99. Adc_Init(&Adc_Config_VS_0);
  100. #endif /* ADC_PRECOMPILE_SUPPORT == STD_ON */
  101. // this function should be called in ADC Task at once
  102. Adc_CalibrationStatusType CalibStatus;
  103. Adc_Calibrate(AdcHwUnit_0, &CalibStatus);
  104. if (CalibStatus.Adc_UnitSelfTestStatus == E_NOT_OK)
  105. {
  106. // if so, the adc is failed to Calibrate;
  107. }
  108. TP_Value_Type value = 0;
  109. for (ADC_TP_Channel_Type channel = 0; channel < ChannelCounter; channel++)
  110. {
  111. ADC_ReadValue(channel, &value);
  112. }
  113. IP_LPUART0->CTRL |= LPUART_CTRL_ILT(1);
  114. IP_LPUART1->CTRL |= LPUART_CTRL_ILT(1);
  115. IP_LPUART2->CTRL |= LPUART_CTRL_ILT(1);
  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. Dio_WriteChannel(DioConf_DioChannel_PTE8_GPIO_OUT_MCU_LED4, STD_OFF);
  120. xTaskCreate(MainTask, (const char *const)"MainTask", 128, (void *)0, main_TASK_PRIORITY + 3, NULL);
  121. xTaskCreate(Uart_4G_Task, (const char *const)"Uart_4G_Task", 2048, (void *)0, main_TASK_PRIORITY + 0, NULL);
  122. #ifdef APP_UART0_ENABLE
  123. xTaskCreate(Uart0Task, (const char *const)"Uart0_Bms_Task", 256, (void *)0, main_TASK_PRIORITY + 1, NULL);
  124. #endif
  125. #ifdef APP_CAN_ENABLE
  126. xTaskCreate(CanTask, (const char *const)"CanTask", 512, (void *)0, main_TASK_PRIORITY + 2, NULL);
  127. #endif
  128. xTaskCreate(GpsTask, (const char *const)"GpsTask", 512, (void *)0, main_TASK_PRIORITY + 1, NULL);
  129. vTaskStartScheduler();
  130. for (;;)
  131. {
  132. if (exit_code != 0)
  133. {
  134. break;
  135. }
  136. }
  137. return exit_code;
  138. }
  139. /** @} */