硬汉嵌入式论坛

 找回密码
 立即注册
查看: 5477|回复: 2
收起左侧

[FreeRTOS] FreeRTOS中打印任务执行情况的portALT_GET_RUN_TIME_COUNTER_VALUE实现方法

[复制链接]

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106746
QQ
发表于 2015-8-25 23:52:33 | 显示全部楼层 |阅读模式
portALT_GET_RUN_TIME_COUNTER_VALUE的实现在例子:CORTEX_STM32L152_IAR中有函数。
实际测试了一下这种方法,不好用,测试出来CPU利用率不正确,估计哪里有bug
=====================================================

1.jpg

2.jpg
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106746
QQ
 楼主| 发表于 2015-8-25 23:56:11 | 显示全部楼层
最近做的V4板子里面的FreeRTOS例子我一直用的是:
portGET_RUN_TIME_COUNTER_VALUE
portALT_GET_RUN_TIME_COUNTER_VALUE和portGET_RUN_TIME_COUNTER_VALUE只能二选一:
3.jpg
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106746
QQ
 楼主| 发表于 2015-8-26 00:01:49 | 显示全部楼层
使用1楼的实现方法可以让系统更少的进入定时器中断:
  1. void vConfigureTimerForRunTimeStats( void )
  2. {
  3. TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
  4. NVIC_InitTypeDef NVIC_InitStructure;
  5.     /* The time base for the run time stats is generated by the 16 bit timer 6.
  6.     Each time the timer overflows ulTIM6_OverflowCount is incremented.
  7.     Therefore, when converting the total run time to a 32 bit number, the most
  8.     significant two bytes are given by ulTIM6_OverflowCount and the least
  9.     significant two bytes are given by the current TIM6 counter value.  Care
  10.     must be taken with data    consistency when combining the two in case a timer
  11.     overflow occurs as the value is being read.
  12.     The portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() macro (in FreeRTOSConfig.h) is
  13.     defined to call this function, so the kernel will call this function
  14.     automatically at the appropriate time. */
  15.     /* TIM6 clock enable */
  16.     RCC_APB1PeriphClockCmd( RCC_APB1Periph_TIM6, ENABLE );
  17.     /* The 32MHz clock divided by 5000 should tick (very) approximately every
  18.     150uS and overflow a 16bit timer (very) approximately every 10 seconds. */
  19.     TIM_TimeBaseStructure.TIM_Period = 65535;
  20.     TIM_TimeBaseStructure.TIM_Prescaler = 5000;
  21.     TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
  22.     TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
  23.     TIM_TimeBaseInit( TIM6, &TIM_TimeBaseStructure );
  24.     /* Only interrupt on overflow events. */
  25.     TIM6->CR1 |= TIM_CR1_URS;
  26.     /* Enable the interrupt. */
  27.     TIM_ITConfig( TIM6, TIM_IT_Update, ENABLE );
  28.     /* Enable the TIM6 global Interrupt */
  29.     NVIC_InitStructure.NVIC_IRQChannel = TIM6_IRQn;
  30.     NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = configLIBRARY_LOWEST_INTERRUPT_PRIORITY;
  31.     NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x00; /* Not used as 4 bits are used for the pre-emption priority. */
  32.     NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  33.     NVIC_Init(&NVIC_InitStructure);
  34.     TIM_ClearITPendingBit( TIM6, TIM_IT_Update );
  35.     TIM_Cmd( TIM6, ENABLE );
  36. }
  37. /*-----------------------------------------------------------*/
  38. void TIM6_IRQHandler( void )
  39. {
  40.     /* Interrupt handler for TIM 6
  41.     The time base for the run time stats is generated by the 16 bit timer 6.
  42.     Each time the timer overflows ulTIM6_OverflowCount is incremented.
  43.     Therefore, when converting the total run time to a 32 bit number, the most
  44.     significant two bytes are given by ulTIM6_OverflowCount and the least
  45.     significant two bytes are given by the current TIM6 counter value.  Care
  46.     must be taken with data    consistency when combining the two in case a timer
  47.     overflow occurs as the value is being read. */
  48.     if( TIM_GetITStatus( TIM6, TIM_IT_Update) != RESET)
  49.     {
  50.         ulTIM6_OverflowCount++;
  51.         TIM_ClearITPendingBit( TIM6, TIM_IT_Update );
  52.     }
  53. }
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2024-5-3 18:36 , Processed in 0.211697 second(s), 28 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表