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

標題: 嵌入式c語言調試開關 [打印本頁]

作者: 51黑黑黑    時間: 2016-2-22 23:07
標題: 嵌入式c語言調試開關
本帖最后由 51黑黑黑 于 2016-2-22 23:09 編輯

調試程序時,經常會用到assert和printf之類的函數,我最近做的這個工程里就有幾百個assert,在你自認為程序已經沒有bug的時候,就要除去這些調試代碼,應為系統在正常運行時這些用于調試的信息是無用的,而且會占用時間和空間。怎么刪除呢,俺以前都是用笨方法,一個一個注釋,能用注釋也是經過改進的方法,俺最早都是刪掉之后出了問題再重新寫的,但是這次幾百個一個一個刪除的話可是要了俺的小命了,一首mp3聽完,還不到一百個。以前看過st的函數庫,老外的代碼就是規范,俺現在的代碼好多都是在st和ti那里照搬的,呵呵。
下面給出最簡單的一種方法:
  1. #define DEBUG
  2. #ifdef DEBUG
  3. #define PRINTF(x) printf x
  4. #else
  5. #define PRINTF(x)         ((void)0)
  6. #endif
復制代碼
使用時,PRINTF(( "Hello World!\n\r" ));
注意這里是兩個括號,一個會報錯的
不使用時,直接將"#define DEBUG"屏蔽掉
另外一個調試時常用的方法是assert,還是在一個頭文件里,這里用的是STM32函數庫的例子
  1. #ifdef DEBUG 1
  2. /*******************************************************************************
  3. * Macro Name : assert_param
  4. * Description : The assert_param macro is used for function's parameters check.
  5. * It is used only if the library is compiled in DEBUG mode.
  6. * Input : - expr: If expr is false, it calls assert_failed function
  7. * which reports the name of the source file and the source
  8. * line number of the call that failed.
  9. * If expr is true, it returns no value.
  10. * Return : None
  11. *******************************************************************************/

  12. #define assert_param(expr) ((expr) ? (void)0 : assert_failed((u8 *)__FILE__, __LINE__))

  13. /* Exported functions ------------------------------------------------------- */

  14. void assert_failed(u8* file, u32 line);
  15. #else
  16. #define assert_param(expr) ((void)0)
  17. #endif/* DEBUG */

  18. //assert_failed此函數要自己定義
  19. #ifdef DEBUG
  20. /*******************************************************************************
  21. * Function Name : assert_failed
  22. * Description : Reports the name of the source file and the source line number
  23. * where the assert_param error has occurred.
  24. * Input : - file: pointer to the source file name
  25. * - line: assert_param error line source number
  26. * Output : None
  27. * Return : None
  28. *******************************************************************************/
  29. void assert_failed(u8* file, u32 line)
  30. {

  31. /* User can add his own implementation to report the file name and line number,
  32. ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  33. /* Infinite loop */
  34.     while (1){
  35.     }

  36. }
  37. #endif
復制代碼







歡迎光臨 (http://www.zg4o1577.cn/bbs/) Powered by Discuz! X3.1
主站蜘蛛池模板: 国产高清精品在线 | 欧美黄色小视频 | 国产a区 | 日韩精品久久久久 | 久久久久久久久久性 | 亚洲高清在线 | 999免费网站 | 黄色片网此 | 国产亚洲欧美在线 | 国产日韩欧美一区二区 | 国产视频一区二区 | 国产精品美女视频 | 久久婷婷麻豆国产91天堂 | 国产乱码精品1区2区3区 | 日韩精品一区二区三区中文在线 | 99久久电影 | 99久久婷婷国产精品综合 | 看片国产 | 亚洲视频二区 | 天天综合永久入口 | 在线国产视频 | 亚洲一二三区av | 欧美一级做a爰片免费视频 国产美女特级嫩嫩嫩bbb片 | 日本欧美视频 | ww 255hh 在线观看 | 久久精彩视频 | 337p日本欧洲亚洲大胆鲁鲁 | 欧美v片 | 亚洲一区毛片 | 很黄很污的网站 | 色婷婷av777 av免费网站在线 | 国产精品一区二区不卡 | 欧美区在线 | 69精品久久久久久 | 国产精品久久久久久模特 | 精品久久久久香蕉网 | 亚洲精品久久久久久首妖 | 国产精品国产成人国产三级 | 91看片免费版 | 老司机成人在线 | 在线免费看91 |