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

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2445|回復: 0
打印 上一主題 下一主題
收起左側

FreeRtos STM32工程 代碼帶部分中文注釋

[復制鏈接]
跳轉到指定樓層
樓主
ID:830386 發表于 2020-10-16 17:15 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
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)


評分

參與人數 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎勵!

查看全部評分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 欧美a级成人淫片免费看 | 在线观看国产视频 | 欧美极品一区二区 | 亚洲精品一二三区 | 欧美精品在线播放 | 日本a视频 | 国内精品视频免费观看 | 91在线精品秘密一区二区 | 99精品视频免费在线观看 | 亚洲精品成人免费 | 精品视频一区二区三区在线观看 | 国产免费看 | 中文字幕在线视频精品 | 日韩在线观看中文字幕 | 日韩欧美国产精品 | 欧美久久精品一级黑人c片 91免费在线视频 | 美女精品一区 | 亚洲三区在线 | 久久人人爽人人爽人人片av免费 | 免费一区二区三区 | 亚洲国产成人精品女人久久久 | 一区二区三区国产好 | 日本爱爱| 黄色毛片一级 | 亚洲日日操 | 欧美精品在线观看 | 成人在线一区二区 | 精品一区二区电影 | 亚洲福利在线观看 | 一级一级一级毛片 | 91精品www | 毛片黄片免费看 | 日韩免费看视频 | 精品久久久久久亚洲精品 | 欧美日韩精选 | 国产福利资源在线 | 奇米四色在线观看 | 国产99久久精品一区二区永久免费 | 韩国理论电影在线 | 国产真实精品久久二三区 | 国产精品久久国产精品 |