久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

標題: FreeRtos STM32工程 代碼帶部分中文注釋 [打印本頁]

作者: 13523698526    時間: 2020-10-16 17:15
標題: FreeRtos STM32工程 代碼帶部分中文注釋
STM32F103C8T6的FreeRtos工程。
帶部分中文注釋。希望可以幫組初學者。

單片機源程序如下:
  1. /* Standard includes. */
  2. #include <stdio.h>

  3. /* Scheduler includes. */
  4. #include "FreeRTOS.h"
  5. #include "task.h"
  6. #include "queue.h"

  7. /* Library includes. */
  8. #include "stm32f10x_it.h"

  9. /* Demo app includes. */
  10. #include "lcd.h"
  11. #include "LCD_Message.h"
  12. #include "BlockQ.h"
  13. #include "death.h"
  14. #include "integer.h"
  15. #include "blocktim.h"
  16. #include "partest.h"
  17. #include "semtest.h"
  18. #include "PollQ.h"
  19. #include "flash.h"
  20. #include "comtest2.h"

  21. /* Task priorities. */
  22. #define mainQUEUE_POLL_PRIORITY                                ( tskIDLE_PRIORITY + 2 )
  23. #define mainCHECK_TASK_PRIORITY                                ( tskIDLE_PRIORITY + 3 )
  24. #define mainSEM_TEST_PRIORITY                                ( tskIDLE_PRIORITY + 1 )
  25. #define mainBLOCK_Q_PRIORITY                                ( tskIDLE_PRIORITY + 2 )
  26. #define mainCREATOR_TASK_PRIORITY           ( tskIDLE_PRIORITY + 3 )
  27. #define mainFLASH_TASK_PRIORITY                                ( tskIDLE_PRIORITY + 1 )
  28. #define mainCOM_TEST_PRIORITY                                ( tskIDLE_PRIORITY + 1 )
  29. #define mainINTEGER_TASK_PRIORITY           ( tskIDLE_PRIORITY )

  30. /* Constants related to the LCD. */
  31. #define mainMAX_LINE                                                ( 240 )
  32. #define mainROW_INCREMENT                                        ( 24 )
  33. #define mainMAX_COLUMN                                                ( 20 )
  34. #define mainCOLUMN_START                                        ( 319 )
  35. #define mainCOLUMN_INCREMENT                                 ( 16 )

  36. /* The maximum number of message that can be waiting for display at any one
  37. time. */
  38. #define mainLCD_QUEUE_SIZE                                        ( 3 )

  39. /* The check task uses the sprintf function so requires a little more stack. */
  40. #define mainCHECK_TASK_STACK_SIZE                        ( configMINIMAL_STACK_SIZE + 50 )

  41. /* Dimensions the buffer into which the jitter time is written. */
  42. #define mainMAX_MSG_LEN                                                25

  43. /* The time between cycles of the 'check' task. */
  44. #define mainCHECK_DELAY                                                ( ( TickType_t ) 5000 / portTICK_PERIOD_MS )

  45. /* The number of nano seconds between each processor clock. */
  46. #define mainNS_PER_CLOCK ( ( unsigned long ) ( ( 1.0 / ( double ) configCPU_CLOCK_HZ ) * 1000000000.0 ) )

  47. /* Baud rate used by the comtest tasks. */
  48. #define mainCOM_TEST_BAUD_RATE                ( 115200 )

  49. /* The LED used by the comtest tasks. See the comtest.c file for more
  50. information. */
  51. #define mainCOM_TEST_LED                        ( 3 )

  52. /*-----------------------------------------------------------*/

  53. /*
  54. * Configure the clocks, GPIO and other peripherals as required by the demo.
  55. */
  56. static void prvSetupHardware( void );

  57. /*
  58. * Configure the LCD as required by the demo.
  59. */
  60. static void prvConfigureLCD( void );

  61. /*
  62. * The LCD is written two by more than one task so is controlled by a
  63. * 'gatekeeper' task.  This is the only task that is actually permitted to
  64. * access the LCD directly.  Other tasks wanting to display a message send
  65. * the message to the gatekeeper.
  66. */
  67. static void vLCDTask( void *pvParameters );

  68. /*
  69. * Retargets the C library printf function to the USART.
  70. */
  71. int fputc( int ch, FILE *f );

  72. /*
  73. * Checks the status of all the demo tasks then prints a message to the
  74. * display.  The message will be either PASS - and include in brackets the
  75. * maximum measured jitter time (as described at the to of the file), or a
  76. * message that describes which of the standard demo tasks an error has been
  77. * discovered in.
  78. *
  79. * Messages are not written directly to the terminal, but passed to vLCDTask
  80. * via a queue.
  81. */
  82. static void vCheckTask( void *pvParameters );

  83. /*
  84. * Configures the timers and interrupts for the fast interrupt test as
  85. * described at the top of this file.
  86. */
  87. extern void vSetupTimerTest( void );

  88. /*-----------------------------------------------------------*/

  89. /* The queue used to send messages to the LCD task. */
  90. QueueHandle_t xLCDQueue;

  91. /*-----------------------------------------------------------*/

  92. int main( void )
  93. {
  94. #ifdef DEBUG
  95.   debug();
  96. #endif

  97.         prvSetupHardware();

  98.         /* Create the queue used by the LCD task.  Messages for display on the LCD
  99.         are received via this queue. */
  100.         xLCDQueue = xQueueCreate( mainLCD_QUEUE_SIZE, sizeof( xLCDMessage ) );   //創建LCD列隊,并返回列隊編號

  101.         /* Start the standard demo tasks. */
  102.         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );                        //創建了6個任務,處理三組參數
  103.     vCreateBlockTimeTasks();                                                 //創建兩個block任務  阻塞任務
  104.     vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );                           //
  105.     vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );                       //創建列隊測試任務   待挖掘
  106.     vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY );                     //
  107.         vStartLEDFlashTasks( mainFLASH_TASK_PRIORITY );                          //創建LED翻轉任務,創建了3個相同的任務,每個對應不同的燈
  108.         vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );                 //創建串口收發任務,收和發是兩個任務

  109.         /* Start the tasks defined within this file/specific to this demo. */
  110.         xTaskCreate( vCheckTask, "Check", mainCHECK_TASK_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );       //創建LCD內容顯示設置任務
  111.                 xTaskCreate( vLCDTask, "LCD", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );                   //創建LCD顯示任務

  112.         /* The suicide tasks must be created last as they need to know how many
  113.         tasks were running prior to their creation in order to ascertain whether
  114.         or not the correct/expected number of tasks are running at any given time. */                             
  115.     vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );                                                                                                                                                                                                                        //創建一批可以自動刪除的任務

  116.         /* Configure the timers used by the fast interrupt timer test. */
  117.         vSetupTimerTest();                                                                                        //初始化定時器

  118.         /* Start the scheduler. */
  119.         vTaskStartScheduler();                                                                                    //啟動調度器,開始操作系統

  120.         /* Will only get here if there was not enough heap space to create the
  121.         idle task. */
  122.         return 0;
  123. }
  124. /*-----------------------------------------------------------*/

  125. void vLCDTask( void *pvParameters )
  126. {
  127. xLCDMessage xMessage;

  128.         /* Initialise the LCD and display a startup message. */
  129.         prvConfigureLCD();
  130.         LCD_DrawMonoPict( ( unsigned long * ) pcBitmap );

  131.         for( ;; )
  132.         {
  133.                 /* Wait for a message to arrive that requires displaying. */
  134.                 while( xQueueReceive( xLCDQueue, &xMessage, portMAX_DELAY ) != pdPASS );  //從序列中讀取數據,返回有沒有

  135.                 /* Display the message.  Print each message to a different position. */
  136.                 printf( ( char const * ) xMessage.pcMessage );
  137.         }
  138. }
  139. /*-----------------------------------------------------------*/

  140. static void vCheckTask( void *pvParameters )
  141. {
  142. TickType_t xLastExecutionTime;
  143. xLCDMessage xMessage;
  144. static signed char cPassMessage[ mainMAX_MSG_LEN ];
  145. extern unsigned short usMaxJitter;

  146.         xLastExecutionTime = xTaskGetTickCount();
  147.         xMessage.pcMessage = cPassMessage;

  148.     for( ;; )
  149.         {
  150.                 /* Perform this check every mainCHECK_DELAY milliseconds. */
  151.                 vTaskDelayUntil( &xLastExecutionTime, mainCHECK_DELAY );    //絕對延時,如果某個延時被任務耽擱了,會在下一次調用時補償回來

  152.                 /* Has an error been found in any task? */

  153.         if( xAreBlockingQueuesStillRunning() != pdTRUE )
  154.                 {
  155.                         xMessage.pcMessage = "ERROR IN BLOCK Q\n";
  156.                 }
  157.                 else if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
  158.                 {
  159.                         xMessage.pcMessage = "ERROR IN BLOCK TIME\n";
  160.                 }
  161.         else if( xAreSemaphoreTasksStillRunning() != pdTRUE )
  162.         {
  163.             xMessage.pcMessage = "ERROR IN SEMAPHORE\n";
  164.         }
  165.         else if( xArePollingQueuesStillRunning() != pdTRUE )
  166.         {
  167.             xMessage.pcMessage = "ERROR IN POLL Q\n";
  168.         }
  169.         else if( xIsCreateTaskStillRunning() != pdTRUE )
  170.         {
  171.             xMessage.pcMessage = "ERROR IN CREATE\n";
  172.         }
  173.         else if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
  174.         {
  175.             xMessage.pcMessage = "ERROR IN MATH\n";
  176.         }
  177.                 else if( xAreComTestTasksStillRunning() != pdTRUE )
  178.                 {
  179.                         xMessage.pcMessage = "ERROR IN COM TEST\n";
  180.                 }
  181.                 else
  182.                 {
  183.                         sprintf( ( char * ) cPassMessage, "PASS [%uns]\n", ( ( unsigned long ) usMaxJitter ) * mainNS_PER_CLOCK );
  184.                 }

  185.                 /* Send the message to the LCD gatekeeper for display. */
  186.                 xQueueSend( xLCDQueue, &xMessage, portMAX_DELAY );
  187.         }
  188. }
  189. /*-----------------------------------------------------------*/

  190. static void prvSetupHardware( void )
  191. {
  192.         /* Start with the clocks in their expected state. */
  193.         RCC_DeInit();

  194. ……………………

  195. …………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼

所有資料51hei提供下載:
FreeRTOS-project STM32.7z (3.09 MB, 下載次數: 57)







歡迎光臨 (http://www.zg4o1577.cn/bbs/) Powered by Discuz! X3.1
主站蜘蛛池模板: 日日摸夜夜爽人人添av | 亚洲人人舔人人 | 本地毛片 | 日韩欧美在线视频观看 | 精品欧美一区二区中文字幕视频 | 久久精品在线免费视频 | 久久久久成人精品亚洲国产 | 日韩精品一区二区三区中文在线 | 国产精品久久久久久久久久久新郎 | 精品国产青草久久久久96 | 亚洲精品一区二区三区在线 | 成人午夜免费福利视频 | 日韩国产精品一区二区三区 | 亚洲精选久久 | 成人网av| 亚洲一区二区三区 | 久草在线青青草 | 国产午夜久久久 | 国产亚洲一区二区三区在线观看 | 韩日av在线 | 欧美日韩电影在线 | 亚洲国产精品一区二区三区 | 国产一二三区免费视频 | 婷婷色国产偷v国产偷v小说 | 久久久91| 亚洲欧美日韩在线不卡 | h片在线免费观看 | 国产97在线看 | 欧美国产视频一区二区 | 亚洲毛片在线观看 | 国产精品美女久久久久aⅴ国产馆 | 日韩国产在线 | 日韩二三区| 国产欧美精品区一区二区三区 | aaa大片免费观看 | 欧美日高清视频 | 国产精品区二区三区日本 | 国产高清美女一级a毛片久久w | 亚洲超碰在线观看 | 精品国产区 | 国产99久久久国产精品 |