GEX core repository.

freertos.c 8.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. //
  2. // FreeRTOS setup
  3. //
  4. /**
  5. ******************************************************************************
  6. * File Name : freertos.c
  7. * Description : Code for freertos applications
  8. ******************************************************************************
  9. * This notice applies to any and all portions of this file
  10. * that are not between comment pairs USER CODE BEGIN and
  11. * USER CODE END. Other portions of this file, whether
  12. * inserted by the user or by software development tools
  13. * are owned by their respective copyright owners.
  14. *
  15. * Copyright (c) 2017 STMicroelectronics International N.V.
  16. * All rights reserved.
  17. *
  18. * Redistribution and use in source and binary forms, with or without
  19. * modification, are permitted, provided that the following conditions are met:
  20. *
  21. * 1. Redistribution of source code must retain the above copyright notice,
  22. * this list of conditions and the following disclaimer.
  23. * 2. Redistributions in binary form must reproduce the above copyright notice,
  24. * this list of conditions and the following disclaimer in the documentation
  25. * and/or other materials provided with the distribution.
  26. * 3. Neither the name of STMicroelectronics nor the names of other
  27. * contributors to this software may be used to endorse or promote products
  28. * derived from this software without specific written permission.
  29. * 4. This software, including modifications and/or derivative works of this
  30. * software, must execute solely and exclusively on microcontroller or
  31. * microprocessor devices manufactured by or for STMicroelectronics.
  32. * 5. Redistribution and use of this software other than as permitted under
  33. * this license is void and will automatically terminate your rights under
  34. * this license.
  35. *
  36. * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
  37. * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
  38. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  39. * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
  40. * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
  41. * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  42. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  43. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  44. * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  45. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  46. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  47. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  48. *
  49. ******************************************************************************
  50. */
  51. /* Includes ------------------------------------------------------------------*/
  52. #include "FreeRTOS.h"
  53. #include "cmsis_os.h"
  54. /* USER CODE BEGIN Includes */
  55. #include "platform.h"
  56. #include "tasks/sched_queue.h"
  57. #include "stacksmon.h"
  58. /* USER CODE END Includes */
  59. /* Variables -----------------------------------------------------------------*/
  60. osThreadId tskMainHandle;
  61. uint32_t mainTaskStack[ TSK_STACK_MAIN ];
  62. osStaticThreadDef_t mainTaskControlBlock;
  63. osThreadId tskMsgJobHandle;
  64. uint32_t msgJobQueTaskStack[ TSK_STACK_MSG ];
  65. osStaticThreadDef_t msgJobQueTaskControlBlock;
  66. osMessageQId queMsgJobHandle;
  67. uint8_t msgJobQueBuffer[ RX_QUE_CAPACITY * sizeof( struct rx_sched_combined_que_item ) ];
  68. osStaticMessageQDef_t msgJobQueControlBlock;
  69. osMutexId mutTinyFrameTxHandle;
  70. osStaticMutexDef_t mutTinyFrameTxControlBlock;
  71. osSemaphoreId semVcomTxReadyHandle;
  72. osStaticSemaphoreDef_t semVcomTxReadyControlBlock;
  73. osMutexId mutScratchBufferHandle;
  74. osStaticMutexDef_t mutScratchBufferControlBlock;
  75. /* USER CODE BEGIN Variables */
  76. /* USER CODE END Variables */
  77. /* Function prototypes -------------------------------------------------------*/
  78. void TaskMain(void const * argument);
  79. extern void TaskMsgJob(void const *argument);
  80. void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */
  81. /* USER CODE BEGIN FunctionPrototypes */
  82. /* USER CODE END FunctionPrototypes */
  83. /* GetIdleTaskMemory prototype (linked to static allocation support) */
  84. void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize );
  85. /* Hook prototypes */
  86. void vApplicationStackOverflowHook(TaskHandle_t xTask, signed char *pcTaskName);
  87. /* USER CODE BEGIN 4 */
  88. __weak void vApplicationStackOverflowHook(TaskHandle_t xTask, signed char *pcTaskName)
  89. {
  90. /* Run time stack overflow checking is performed if
  91. configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook function is
  92. called if a stack overflow is detected. */
  93. }
  94. /* USER CODE END 4 */
  95. /* USER CODE BEGIN GET_IDLE_TASK_MEMORY */
  96. static StaticTask_t xIdleTaskTCBBuffer;
  97. static StackType_t xIdleStack[TSK_STACK_IDLE];
  98. void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize )
  99. {
  100. *ppxIdleTaskTCBBuffer = &xIdleTaskTCBBuffer;
  101. *ppxIdleTaskStackBuffer = &xIdleStack[0];
  102. *pulIdleTaskStackSize = TSK_STACK_IDLE;
  103. /* place for user code */
  104. }
  105. /* USER CODE END GET_IDLE_TASK_MEMORY */
  106. /* USER CODE BEGIN GET_IDLE_TASK_MEMORY */
  107. static StaticTask_t xTimersTaskTCBBuffer;
  108. static StackType_t xTimersStack[TSK_STACK_TIMERS];
  109. void vApplicationGetTimerTaskMemory( StaticTask_t **ppxTimersTaskTCBBuffer, StackType_t **ppxTimersTaskStackBuffer, uint32_t *pulTimersTaskStackSize )
  110. {
  111. *ppxTimersTaskTCBBuffer = &xTimersTaskTCBBuffer;
  112. *ppxTimersTaskStackBuffer = &xTimersStack[0];
  113. *pulTimersTaskStackSize = TSK_STACK_TIMERS;
  114. /* place for user code */
  115. }
  116. /* USER CODE END GET_IDLE_TASK_MEMORY */
  117. /* Init FreeRTOS */
  118. void MX_FREERTOS_Init(void) {
  119. /* USER CODE BEGIN Init */
  120. stackmon_register("Main", mainTaskStack, sizeof(mainTaskStack));
  121. stackmon_register("Job+Msg", msgJobQueTaskStack, sizeof(msgJobQueTaskStack));
  122. stackmon_register("Idle", xIdleStack, sizeof(xIdleStack));
  123. // stackmon_register("Timers", xTimersStack, sizeof(xTimersStack));
  124. /* USER CODE END Init */
  125. /* Create the mutex(es) */
  126. /* definition and creation of mutTinyFrameTx */
  127. osMutexStaticDef(mutTinyFrameTx, &mutTinyFrameTxControlBlock);
  128. mutTinyFrameTxHandle = osMutexCreate(osMutex(mutTinyFrameTx));
  129. osMutexStaticDef(mutScratchBuffer, &mutScratchBufferControlBlock);
  130. mutScratchBufferHandle = osMutexCreate(osMutex(mutScratchBuffer));
  131. /* USER CODE BEGIN RTOS_MUTEX */
  132. /* add mutexes, ... */
  133. /* USER CODE END RTOS_MUTEX */
  134. /* Create the semaphores(s) */
  135. /* definition and creation of semVcomTxReady */
  136. osSemaphoreStaticDef(semVcomTxReady, &semVcomTxReadyControlBlock);
  137. semVcomTxReadyHandle = osSemaphoreCreate(osSemaphore(semVcomTxReady), 1);
  138. /* USER CODE BEGIN RTOS_SEMAPHORES */
  139. /* add semaphores, ... */
  140. xSemaphoreGive(semVcomTxReadyHandle);
  141. /* USER CODE END RTOS_SEMAPHORES */
  142. /* USER CODE BEGIN RTOS_TIMERS */
  143. /* start timers, add new ones, ... */
  144. /* USER CODE END RTOS_TIMERS */
  145. /* Create the thread(s) */
  146. /* definition and creation of tskMain */
  147. osThreadStaticDef(tskMain, TaskMain, TSK_MAIN_PRIO, 0, TSK_STACK_MAIN, mainTaskStack, &mainTaskControlBlock);
  148. tskMainHandle = osThreadCreate(osThread(tskMain), NULL);
  149. /* definition and creation of TaskMessaging */
  150. osThreadStaticDef(tskMsg, TaskMsgJob, TSK_JOBS_PRIO, 0, TSK_STACK_MSG, msgJobQueTaskStack, &msgJobQueTaskControlBlock);
  151. tskMsgJobHandle = osThreadCreate(osThread(tskMsg), NULL);
  152. /* USER CODE BEGIN RTOS_THREADS */
  153. /* add threads, ... */
  154. /* USER CODE END RTOS_THREADS */
  155. /* Create the queue(s) */
  156. /* definition and creation of queRxData */
  157. osMessageQStaticDef(queMsgJob, RX_QUE_CAPACITY, struct rx_sched_combined_que_item, msgJobQueBuffer, &msgJobQueControlBlock);
  158. queMsgJobHandle = osMessageCreate(osMessageQ(queMsgJob), NULL);
  159. /* USER CODE BEGIN RTOS_QUEUES */
  160. /* add queues, ... */
  161. /* USER CODE END RTOS_QUEUES */
  162. }
  163. /* TaskMain function */
  164. __weak void TaskMain(void const * argument)
  165. {
  166. /* USER CODE BEGIN TaskMain */
  167. /* Infinite loop */
  168. for(;;)
  169. {
  170. osDelay(1);
  171. }
  172. /* USER CODE END TaskMain */
  173. }
  174. /* USER CODE BEGIN Application */
  175. /* USER CODE END Application */
  176. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/