You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

193 lines
6.8 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * File Name : freertos.c
  5. * Description : Code for freertos applications
  6. ******************************************************************************
  7. * This notice applies to any and all portions of this file
  8. * that are not between comment pairs USER CODE BEGIN and
  9. * USER CODE END. Other portions of this file, whether
  10. * inserted by the user or by software development tools
  11. * are owned by their respective copyright owners.
  12. *
  13. * Copyright (c) 2019 STMicroelectronics International N.V.
  14. * All rights reserved.
  15. *
  16. * Redistribution and use in source and binary forms, with or without
  17. * modification, are permitted, provided that the following conditions are met:
  18. *
  19. * 1. Redistribution of source code must retain the above copyright notice,
  20. * this list of conditions and the following disclaimer.
  21. * 2. Redistributions in binary form must reproduce the above copyright notice,
  22. * this list of conditions and the following disclaimer in the documentation
  23. * and/or other materials provided with the distribution.
  24. * 3. Neither the name of STMicroelectronics nor the names of other
  25. * contributors to this software may be used to endorse or promote products
  26. * derived from this software without specific written permission.
  27. * 4. This software, including modifications and/or derivative works of this
  28. * software, must execute solely and exclusively on microcontroller or
  29. * microprocessor devices manufactured by or for STMicroelectronics.
  30. * 5. Redistribution and use of this software other than as permitted under
  31. * this license is void and will automatically terminate your rights under
  32. * this license.
  33. *
  34. * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
  35. * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
  36. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  37. * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
  38. * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
  39. * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  40. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  42. * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  43. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  44. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  45. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  46. *
  47. ******************************************************************************
  48. */
  49. /* USER CODE END Header */
  50. /* Includes ------------------------------------------------------------------*/
  51. #include "FreeRTOS.h"
  52. #include "task.h"
  53. #include "main.h"
  54. #include "cmsis_os.h"
  55. /* Private includes ----------------------------------------------------------*/
  56. /* USER CODE BEGIN Includes */
  57. #include <stdio.h>
  58. #include "config.h"
  59. /* USER CODE END Includes */
  60. /* Private typedef -----------------------------------------------------------*/
  61. /* USER CODE BEGIN PTD */
  62. /* USER CODE END PTD */
  63. /* Private define ------------------------------------------------------------*/
  64. /* USER CODE BEGIN PD */
  65. /* USER CODE END PD */
  66. /* Private macro -------------------------------------------------------------*/
  67. /* USER CODE BEGIN PM */
  68. /* USER CODE END PM */
  69. /* Private variables ---------------------------------------------------------*/
  70. /* USER CODE BEGIN Variables */
  71. osThreadId mainTaskHandle;
  72. /* USER CODE END Variables */
  73. osThreadId defaultTaskHandle;
  74. /* Private function prototypes -----------------------------------------------*/
  75. /* USER CODE BEGIN FunctionPrototypes */
  76. void StartMainTask(void const * argument);
  77. extern void MX_LWIP_STATIC_Init(void);
  78. /* USER CODE END FunctionPrototypes */
  79. void StartDefaultTask(void const * argument);
  80. extern void MX_LWIP_Init(void);
  81. void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */
  82. /* GetIdleTaskMemory prototype (linked to static allocation support) */
  83. void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize );
  84. /* USER CODE BEGIN GET_IDLE_TASK_MEMORY */
  85. static StaticTask_t xIdleTaskTCBBuffer;
  86. static StackType_t xIdleStack[configMINIMAL_STACK_SIZE];
  87. void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize )
  88. {
  89. *ppxIdleTaskTCBBuffer = &xIdleTaskTCBBuffer;
  90. *ppxIdleTaskStackBuffer = &xIdleStack[0];
  91. *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
  92. /* place for user code */
  93. }
  94. /* USER CODE END GET_IDLE_TASK_MEMORY */
  95. /**
  96. * @brief FreeRTOS initialization
  97. * @param None
  98. * @retval None
  99. */
  100. void MX_FREERTOS_Init(void) {
  101. /* USER CODE BEGIN Init */
  102. config_init();
  103. /* USER CODE END Init */
  104. /* USER CODE BEGIN RTOS_MUTEX */
  105. /* add mutexes, ... */
  106. /* USER CODE END RTOS_MUTEX */
  107. /* USER CODE BEGIN RTOS_SEMAPHORES */
  108. /* add semaphores, ... */
  109. /* USER CODE END RTOS_SEMAPHORES */
  110. /* USER CODE BEGIN RTOS_TIMERS */
  111. /* start timers, add new ones, ... */
  112. /* USER CODE END RTOS_TIMERS */
  113. /* USER CODE BEGIN RTOS_QUEUES */
  114. /* add queues, ... */
  115. /* USER CODE END RTOS_QUEUES */
  116. /* Create the thread(s) */
  117. /* definition and creation of defaultTask */
  118. osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 512);
  119. defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
  120. /* USER CODE BEGIN RTOS_THREADS */
  121. /* add threads, ... */
  122. /* USER CODE END RTOS_THREADS */
  123. }
  124. /* USER CODE BEGIN Header_StartDefaultTask */
  125. /**
  126. * @brief Function implementing the defaultTask thread.
  127. * @param argument: Not used
  128. * @retval None
  129. */
  130. /* USER CODE END Header_StartDefaultTask */
  131. void StartDefaultTask(void const * argument)
  132. {
  133. /* init code for LWIP */
  134. if (config_get()->obtaining_ip_mode == OBTAINING_IP_MODE_STATIC){
  135. MX_LWIP_STATIC_Init();
  136. }else if (config_get()->obtaining_ip_mode == OBTAINING_IP_MODE_DHCP){
  137. MX_LWIP_Init();
  138. }else{
  139. printf("lwip error\r\n");
  140. }
  141. /* USER CODE BEGIN StartDefaultTask */
  142. osThreadDef(mainTask, StartMainTask, osPriorityNormal, 0, 1024);
  143. mainTaskHandle = osThreadCreate(osThread(mainTask), NULL);
  144. if (mainTaskHandle == NULL){
  145. printf("create mainTaskHandle error\r\n");
  146. while (1)
  147. {
  148. /* code */
  149. }
  150. }
  151. /* Infinite loop */
  152. for(;;)
  153. {
  154. osDelay(1);
  155. }
  156. /* USER CODE END StartDefaultTask */
  157. }
  158. /* Private application code --------------------------------------------------*/
  159. /* USER CODE BEGIN Application */
  160. void StartMainTask(void const * argument)
  161. {
  162. extern void user_main();
  163. user_main();
  164. }
  165. /* USER CODE END Application */