你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

FreeRTOS在STM32F2平台的移植(后续有更新)  

[复制链接]
caizhiwei 发布时间:2015-3-13 13:56
阅读主题, 点击返回1楼
收藏 3 评论52 发布时间:2015-3-13 13:56
52个回答
af0101 回答时间:2015-4-26 22:15:09

谢谢分享            
dsjsjf 回答时间:2015-4-26 22:53:50
期待更多的分享,谢谢
hmchen 回答时间:2015-4-27 04:08:01
谢谢分享,我想弄一个Nuttx的
qiu-368230 回答时间:2015-4-27 08:46:45
好东西,支持
stary666 回答时间:2015-4-27 09:27:46
支持一下。。。
caizhiwei 回答时间:2015-4-27 13:05:57
通过任务参数传入需要打印输出的文本:
  1. #include "FreeRTOS.h"
  2. #include "task.h"
  3. #include "queue.h"
  4. #include "croutine.h"
  5. #include "bsp.h"


  6. /*
  7. **********************************************************************************************************
  8.                                                                                         函数声明
  9. **********************************************************************************************************
  10. */
  11. static void AppTaskCreate (void);
  12. extern void vSetupTimerTest( void );

  13. /*
  14. **********************************************************************************************************
  15.                                                                                         变量声明
  16. **********************************************************************************************************
  17. */
  18. xTaskHandle xHandleTask3;
  19. int8_t pcWriteBuffer[500];

  20. /*
  21. *********************************************************************************************************
  22. *        函 数 名: main
  23. *        功能说明: 标准c程序入口。
  24. *        形    参:无
  25. *        返 回 值: 无
  26. *********************************************************************************************************
  27. */

  28. static const char *pcTextForTask1 ="Task 1 is running\r\n";
  29. static const char *pcTextForTask2 ="Task 2 is running\t\n";

  30. int main(void)
  31. {
  32.     /* 硬件初始化 */
  33.     bsp_Init();
  34.          
  35.     /* 创建任务 */
  36.     AppTaskCreate();
  37.    
  38.     vSetupTimerTest();
  39.         
  40.     /* 启动调度,开始执行任务 */
  41.     vTaskStartScheduler();

  42.     /*
  43.            If all is well we will never reach here as the scheduler will now be
  44.            running.  If we do reach here then it is likely that there was insufficient
  45.            heap available for the idle task to be created.
  46.         */
  47.     while (1);
  48. }

  49. /*
  50. *********************************************************************************************************
  51. *        函 数 名: vTask1
  52. *        功能说明: LED闪烁               
  53. *        形    参:pvParameters 是在创建该任务时传递的形参
  54. *        返 回 值: 无
  55. *********************************************************************************************************
  56. */
  57. void vTask1( void *pvParameters )
  58. {
  59.     portTickType xDelay, xNextTime;
  60.    
  61.     //char *pcTaskName = (char*)pvParameters;
  62.    
  63.     xNextTime = xTaskGetTickCount () + ( portTickType ) 1000;
  64.         
  65.     while(1)
  66.     {

  67.         bsp_LedToggle(LED1);
  68.         //printf("\r\n%s",pcTaskName);
  69.         printf("\r\n%s",(char*)(pvParameters));
  70.         /* 用vTaskDelay实现vTaskDelayUntil() */        
  71.         xDelay = xNextTime - xTaskGetTickCount ();
  72.         xNextTime += ( portTickType ) 1000;

  73.         if( xDelay <= ( portTickType ) 1000 )
  74.         {
  75.                 vTaskDelay( xDelay );
  76.         }
  77.     }
  78. }

  79. /*
  80. *********************************************************************************************************
  81. *        函 数 名: vTask2
  82. *        功能说明: LED闪烁               
  83. *        形    参:pvParameters 是在创建该任务时传递的形参
  84. *        返 回 值: 无
  85. *********************************************************************************************************
  86. */
  87. void vTask2( void *pvParameters )
  88. {

  89.     portTickType xLastWakeTime;
  90.     const portTickType xFrequency = 100;

  91.     // Initialise the xLastWakeTime variable with the current time.
  92.      xLastWakeTime = xTaskGetTickCount();

  93.     while(1)
  94.     {
  95.         
  96.         bsp_LedToggle(LED2);  // Wait for the next cycle.  
  97.         vTaskDelayUntil( &xLastWakeTime, xFrequency );
  98.     }
  99. }

  100. /*
  101. *********************************************************************************************************
  102. *        函 数 名: vTask3
  103. *        功能说明: LED闪烁               
  104. *        形    参:pvParameters 是在创建该任务时传递的形参
  105. *        返 回 值: 无
  106. *********************************************************************************************************
  107. */
  108. void vTask3( void *pvParameters )
  109. {
  110.     while(1)
  111.     {
  112.           /* 挂起自己,可以写NULL或者xHandleTask3句柄,都可以的 */
  113.           vTaskSuspend( NULL );
  114.           bsp_LedToggle(LED3);
  115.     }
  116. }

  117. /*
  118. *********************************************************************************************************
  119. *        函 数 名: vTask4
  120. *        功能说明: LED闪烁               
  121. *        形    参:pvParameters 是在创建该任务时传递的形参
  122. *        返 回 值: 无
  123. *********************************************************************************************************
  124. */
  125. void vTask4( void *pvParameters )
  126. {
  127.         portTickType xLastWakeTime;
  128.     const portTickType xFrequency = 1000;

  129.          // Initialise the xLastWakeTime variable with the current time.
  130.      xLastWakeTime = xTaskGetTickCount();

  131.     while(1)
  132.     {
  133.         vTaskResume(xHandleTask3);
  134.         vTaskList((char *)&pcWriteBuffer);
  135.         printf("%s\r\n", pcWriteBuffer);

  136.         vTaskGetRunTimeStats(( char *)&pcWriteBuffer);
  137.         printf("%s\r\n", pcWriteBuffer);
  138.         vTaskDelayUntil( &xLastWakeTime, xFrequency );
  139.     }
  140. }


  141. /*
  142. *********************************************************************************************************
  143. *        函 数 名: AppTaskCreate
  144. *        功能说明: 创建应用任务
  145. *        形    参:无
  146. *        返 回 值: 无
  147. *********************************************************************************************************
  148. */
  149. static void AppTaskCreate (void)
  150. {
  151.         /* Create one task. */
  152.     xTaskCreate(    vTask1,     /* Pointer to the function that implements the task.              */
  153.                     "Task 1",   /* Text name for the task.  This is to facilitate debugging only. */
  154.                     500,        /* Stack depth in words.                                          */
  155.                     (void*)pcTextForTask1,       /*通过任务参数传入需要打印输出的文本. */
  156.                     1,          /* This task will run at priority 1.                              */
  157.                     NULL );     /* We are not using the task handle.                              */

  158.     /* Create one task. */
  159.     xTaskCreate(    vTask2,     /* Pointer to the function that implements the task. */
  160.                     "Task 2",   /* Text name for the task.  This is to facilitate debugging only. */
  161.                     500,        /* Stack depth in words.                                          */
  162.                     NULL,       /* We are not using the task parameter.                           */
  163.                     2,          /* This task will run at priority 2.                              */
  164.                     NULL );     /* We are not using the task handle.                              */
  165.         
  166.          /* Create one task. */
  167.     xTaskCreate(    vTask3,     /* Pointer to the function that implements the task. */
  168.                     "Task 3",   /* Text name for the task.  This is to facilitate debugging only. */
  169.                     500,        /* Stack depth in words.                                          */
  170.                     NULL,       /* We are not using the task parameter.                           */
  171.                     3,          /* This task will run at priority 2.                              */
  172.                     &xHandleTask3 );   
  173.         
  174.         /* Create one task. */
  175.     xTaskCreate(    vTask4,     /* Pointer to the function that implements the task. */
  176.                     "Task 4",   /* Text name for the task.  This is to facilitate debugging only. */
  177.                     500,        /* Stack depth in words.                                          */
  178.                     NULL,       /* We are not using the task parameter.                           */
  179.                     4,          /* This task will run at priority 2.                              */
  180.                     NULL );     /* We are not using the task handle.                              */                                
  181. }
复制代码
caizhiwei 回答时间:2015-4-27 13:06:52
Jason-252755 回答时间:2015-4-27 22:40:45
多谢分享,学习了。、
pamhood 回答时间:2015-4-29 13:55:04
多谢分享,好东西啊
caizhiwei 回答时间:2015-4-29 16:58:45
  1. /*
  2. *********************************************************************************************************
  3. *        函 数 名: vTask3
  4. *        功能说明: 接收队列信息               
  5. *        形    参:pvParameters 是在创建该任务时传递的形参
  6. *        返 回 值: 无
  7. *********************************************************************************************************
  8. */
  9. void vTask3( void *pvParameters )
  10. {
  11.    uint8_t Count[5];
  12.     while(1)
  13.     {
  14.                                 
  15.         /* 从队列中获取内容 */     
  16.         xQueueReceive( xQueue, &Count[0], portMAX_DELAY); //任务中断并等待队列中可用空间的最大时间
  17.         xQueueReceive( xQueue, &Count[1], portMAX_DELAY);
  18.         xQueueReceive( xQueue, &Count[2], portMAX_DELAY);
  19.         xQueueReceive( xQueue, &Count[3], portMAX_DELAY);
  20.         xQueueReceive( xQueue, &Count[4], portMAX_DELAY);
  21.         
  22.         printf("Count0 =  %d\r\n", Count[0]);
  23.         printf("Count1 =  %d\r\n", Count[1]);
  24.         printf("Count2 =  %d\r\n", Count[2]);
  25.         printf("Count3 =  %d\r\n", Count[3]);
  26.         printf("Count4 =  %d\r\n", Count[4]);
  27.     }
  28. }

  29. /*
  30. *********************************************************************************************************
  31. *        函 数 名: vTask4
  32. *        功能说明: 向队列中填充内容        
  33. *        形    参:pvParameters 是在创建该任务时传递的形参
  34. *        返 回 值: 无
  35. *********************************************************************************************************
  36. */
  37. void vTask4( void *pvParameters )
  38. {
  39.     portTickType xLastWakeTime;
  40.     const portTickType xFrequency = 1000;
  41.     uint8_t ucVar[5] = {0};

  42.          // Initialise the xLastWakeTime variable with the current time.
  43.      xLastWakeTime = xTaskGetTickCount();

  44.     while(1)
  45.     {
  46.                 ucVar[0]++;
  47.                 ucVar[1]++;
  48.                 ucVar[2]++;
  49.                 ucVar[3]++;
  50.                 ucVar[4]++;
  51.                
  52.                 if( xQueue ) //!=NULL 如果队列创建成功
  53.                 {

  54.                         //当队列满时,则等待 xTicksToWait个滴答周期后再传递
  55.                         xQueueSend( xQueue, ( void * ) &ucVar[0], ( portTickType ) 10 );
  56.                         xQueueSend( xQueue, ( void * ) &ucVar[1], ( portTickType ) 10 );
  57.                         xQueueSend( xQueue, ( void * ) &ucVar[2], ( portTickType ) 10 );
  58.                         xQueueSend( xQueue, ( void * ) &ucVar[3], ( portTickType ) 10 );
  59.                         xQueueSend( xQueue, ( void * ) &ucVar[4], ( portTickType ) 10 );
  60.                 }
  61.         vTaskDelayUntil( &xLastWakeTime, xFrequency );
  62.     }
  63. }
复制代码

所属标签

STM32团队

意法半导体微控制器和微处理器拥有广泛的产品线,包含低成本的8位单片机和基于ARM® Cortex®-M0、M0+、M3、M4、M33、M7及A7内核并具备丰富外设选择的32位微控制器及微处理器


最新内容

相似分享

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
st-img 微信公众号
st-img 手机版