国产毛片a精品毛-国产毛片黄片-国产毛片久久国产-国产毛片久久精品-青娱乐极品在线-青娱乐精品

查看: 3885|回復: 0
打印 上一主題 下一主題

FreeRTOS 定時器精度研究

[復制鏈接]
跳轉到指定樓層
樓主
發表于 2016-10-11 10:52:51 | 只看該作者 |只看大圖 回帖獎勵 |倒序瀏覽 |閱讀模式

背景介紹                       
FreeRTOS 以其移植方便,高度可定制,footprint 小,使其在嵌入式操作系統中的份額不容小覷! 尤以免費 license,頗受開發者青睞。

問題描述
客戶在基于cortex-m3的平臺上使用FreeRTOS系統提供的定時器功能時,意外發現定時器的精確度不夠高。譬如,設置1秒鐘的定時器,理論上1秒超時,并且執行相應的回調函數。但是調試卻發現,有時回調函數是在1.4秒后被執行!這對于精度要求較高的實時系統,是不能接受的!

問題復現與分析
首先在stm32f407-discovery平臺移植FreeRTOS,并創建一個定時器,在其回調函數里toggle led燈,并測量被執行的時間。鑒于FreeRTOS是一個多任務可搶占式系統,這個問題需要在多種情況下分析。
Case 1 :
單任務,即系統里僅有timertask和idle task。整個系統最高優先級為4,Timer task的優先級為默認優先級2。
在這種環境下,回調函數能精確的以1秒的時長超時執行回調函數。雖然此刻精度能滿足要求,但是實際的系統一般會包含多個task。
以下為測試的日志,顯而易見,該定時器嚴格1秒鐘超時。
expired 1000
expired 2000
expired 3000
expired 4000
expired 5000
expired 6000
Case 2 :
多任務,即系統里不僅有timertask和idle task,還有用戶創建的task。整個系統最高優先級為4,Timer task的優先級為默認優先級2。
以下為測試的日志。
UART Printf Example:retarget the C library printf function to the UART
UART Printf Example:retarget the C library printf function to the UART
UART Printf Example:retarget the C library printf function to the UART
expired 1000
UART Printf Example:retarget the C library printf function to the UART
UART Printf Example:retarget the C library printf function to the UART
UART Printf Example:retarget the C library printf function to the UART
UART Printf Example:retarget the C library printf function to the UART
UART Printf Example:retarget the C library printf function to the UART
expired 3000
UART Printf Example:retarget the C library printf function to the UART
UART Printf Example:retarget the C library printf function to the UART
UART Printf Example:retarget the C library printf function to the UART
expired 4000
UART Printf Example:retarget the C library printf function to the UART
UART Printf Example:retarget the C library printf function to the UART
expired 5000
UART Printf Example:retarget the C library printf function to the UART
UART Printf Example:retarget the C library printf function to the UART
UART Printf Example:retarget the C library printf function to the UART
expired 6000
此時定時器回調函數有時能準確地被調度執行,有時則偏差較大,與期望值整整延遲了1秒鐘。
Case 3 :
多任務,即系統里不僅有timer task和idle task,還有用戶創建的task。整個系統最高優先級為4,Timertask的優先級為默認優先級4。這樣設置優先級,是希望能通過將timer task設置為最高優先級,以期望調度器能優先調度執行timer task。
以下為實測的日志。
UART Printf Example:retarget the C library printf function to the UART
UART Printf Example:retarget the C library printf function to the UART
UART Printf Example:retarget the C library printf function to the UART
expired 1000
UART Printf Example:retarget the C library printf function to the UART
UART Printf Example:retarget the C library printf function to the UART
UART Printf Example:retarget the C library printf function to the UART
UART Printf Example:retarget the C library printf function to the UART
UART Printf Example:retarget the C library printf function to the UART
expired 3000
UART Printf Example:retarget the C library printf function to the UART
UART Printf Example:retarget the C library printf function to the UART
UART Printf Example:retarget the C library printf function to the UART
expired 4000
UART Printf Example:retarget the C library printf function to the UART
UART Printf Example:retarget the C library printf function to the UART
expired 5000
UART Printf Example:retarget the C library printf function to the UART
UART Printf Example:retarget the C library printf function to the UART
UART Printf Example:retarget the C library printf function to the UART
expired 6000
雖然調整了timertask的優先級至最高,但是依然會出現嚴重的偏差。

解決方案   
考慮到FreeRTOS定時器的精準性不高,建議客戶使用SysTick或者MCU的外設硬件定時器。
重要通知 - 請仔細閱讀
意法半導體公司及其子公司(“ST”)保留隨時對ST 產品和/ 或本文檔進行變更、更正、增強、修改和改進的權利,恕不另行通知。買方訂貨之前應獲取關于ST 產品的最新信息。ST 產品的銷售依照訂單確認時的相關ST 銷售條款。
買方自行負責對ST 產品的選擇和使用, ST 概不承擔與應用協助或買方產品設計相關的任何責任。
ST 不對任何知識產權進行任何明示或默示的授權或許可。
轉售的ST 產品如有不同于此處提供的信息的規定,將導致ST 針對該產品授予的任何保證失效。
ST 和ST 徽標是ST 的商標。所有其他產品或服務名稱均為其各自所有者的財產。
本文檔中的信息取代本文檔所有早期版本中提供的信息。




文章來源:微信公眾號  融創芯城(一站式電子元器件、PCB、PCBA購買服務平臺,項目眾包平臺)


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

本版積分規則

關于我們  -  服務條款  -  使用指南  -  站點地圖  -  友情鏈接  -  聯系我們
電子工程網 © 版權所有   京ICP備16069177號 | 京公網安備11010502021702
快速回復 返回頂部 返回列表
主站蜘蛛池模板: 亚洲卡一卡2卡三卡4麻豆 | 天堂网| 国产网站精品 | 久久婷婷色香五月综合激情 | 四虎最新网址在线观看 | 亚洲欧美在线一区二区 | 亚洲人视频在线观看 | 精品影视网站入口 | 波多野结衣四虎精品影库 | 欧美成一级 | 两个人日本免费完整版在线观看1 | 日日噜 | 苦咖啡电视剧剧情全集免费 | 亚洲一级毛片中文字幕 | 成人精品视频在线观看播放 | jav008.app| 日本视频免费观看 | 在线观看中文字幕一区 | 亚洲最新视频在线观看 | 在线看一区二区 | 日韩国产中文字幕 | 91人前露出精品国产 | 99这里只有精品视频 | 亚洲欧美在线一区二区 | 青青青草国产 | 卡通动漫亚洲综合 | 国产欧美日韩中文字幕 | 国产精品视频福利一区二区 | 免费观看欧美成人1314色 | 欧美久在线观看在线观看 | 中文字幕免费在线播放 | 四虎永久免费影院 | 大伊香蕉精品二区视频在线 | 在线观看视频亚洲 | 幸福宝8008app隐藏入口 | 欧美性另类高清极品 | 成人免费高清视频 | 一区二区三区视频 | 粉嫩极品国产在线观看 | 亚洲欧美日韩激情在线观看 | 精品国产97在线观看 |