返回首页
当前位置: FPGA主页 > 精彩文章 >

SystemC中的信息和差错报告机制

时间:2010-02-06 16:33来源:芯合科技 作者:admin 点击:
在 SystemC 仿真中,常常需要打印和报告仿真进度信息,发生错误时打印错误原因并停止仿真。 SystemC 中定义了5个默认宏用于打印和报告事件信息以及事件的严重程度,它们是: SC_REPO

      在 SystemC 仿真中,常常需要打印和报告仿真进度信息,发生错误时打印错误原因并停止仿真。 SystemC 中定义了5个默认宏用于打印和报告事件信息以及事件的严重程度,它们是:

      SC_REPORT_INFO( msg_type , msg )
      SC_REPORT_WARNING( msg_type , msg )
      SC_REPORT_ERROR( msg_type , msg )
      SC_REPORT_FATAL( msg_type , msg )
      sc_assert( expr )

      msg_type和msg都是常量字符串,msg_type通常是一个识别ID,而msg则是用户自己定义的打印信息。其中,sc_assert的严重程度FATAL。这几个函数可以用在 SystemC 模块的任何地方。
在 SystemC 中,信息所对应事件的严重程度分为5级,如下面的代码所定义:

  1. enum sc_severity {  
  2. SC_INFO = 0 ,  
  3. SC_WARNING ,  
  4. SC_ERROR ,  
  5. SC_FATAL ,  
  6. SC_MAX_SEVERITY  
  7. }; 


       对于不同严重程度的信息所对应的事件,仿真器采取的行动不同,共分为9个级别,如下面的代码所定义:

  1. enum {  
  2. SC_UNSPECIFIED = 0x0000 ,  
  3. SC_DO_NOTHING = 0x0001 ,  
  4. SC_THROW = 0x0002 ,  
  5. SC_LOG = 0x0004 ,  
  6. SC_DISPLAY = 0x0008 ,  
  7. SC_CACHE_REPORT = 0x0010 ,  
  8. SC_INTERRUPT = 0x0020 ,  
  9. SC_STOP = 0x0040 ,  
  10. SC_ABORT = 0x0080  
  11. }; 


   不同严重程度的信息所对应的缺省行动为:

  1. #define SC_DEFAULT_INFO_ACTIONS ( SC_LOG | SC_DISPLAY )  
  2. #define SC_DEFAULT_WARNING_ACTIONS ( SC_LOG | SC_DISPLAY )  
  3. #define SC_DEFAULT_ERROR_ACTIONS \  
  4. ( SC_LOG | SC_CACHE_REPORT | SC_THROW )  
  5. #define SC_DEFAULT_FATAL_ACTIONS \  
  6. ( SC_LOG | SC_DISPLAY | SC_CACHE_REPORT | SC_ABORT ) 


      我们可以看到,对于信息和警告,缺省的情况只是打印出来,对于出错(ERROR),SystemC仿真器抛出异常,让用户定义的异常处理代码去处理。对于严重错误(FATAL),则直接放弃,并停止仿真。
sc_report_handler和sc_report是SystemC信息和差错报告机制中最重要的两个类。SC_REPO RT_INFO、SC_REPORT_WARNING、SC_REPORT_ERROR、SC_REPORT_FATAL和sc_assert( expr )的定义依赖于sc_report_handler,它们的定义如下:

  1. #define SC_REPORT_INFO( msg_type , msg ) \  
  2. sc_report_handler::report( SC_INFO , msg_type , msg , __FILE__ , __LINE__ )  
  3. #define SC_REPORT_WARNING( msg_type , msg ) \  
  4.  sc_report_handler::report( SC_WARNING , msg_type , msg , __FILE__ , __LINE__ )  
  5. #define SC_REPORT_ERROR( msg_type , msg ) \  
  6. sc_report_handler::report( SC_ERROR , msg_type , msg , __FILE__ , __LINE__ )  
  7. #define SC_REPORT_FATAL( msg_type , msg ) \  
  8. sc_report_handler::report( SC_FATAL , msg_type , msg , __FILE__ , __LINE__ )  
  9. #define sc_assert( expr ) \  
  10.  ( ( void ) ( ( expr ) ? 0 : ( SC_REPORT_FATAL( implementation-defined , #expr ) , 0 ) ) ) 


      在项目最初的调试阶段,总是希望打印出更多的信息,而在后来的调试阶段,总是希望只打印一些关键信息从而达到加快仿真速度和快速定位错误的目的,因此,常常需要修改信息报告函数的行为。SC_REPORT_INFO、SC_REPORT_WARNING、SC_REPORT_ERROR、SC_REPORT _FATAL和sc_assert( expr )的缺省行为可以通过set_actions进行修改,该函数的定义如下:

  1. class sc_report_handler  
  2. {  
  3. public:  
  4.     static sc_actions set_actions( sc_severity , sc_actions = SC_UNSPECIFIED );  
  5.     static sc_actions set_actions( const char * msg_type , sc_actions =        SC_UNSPECIFIED );  
  6.    static sc_actions set_actions( const char * msg_type , sc_severity , sc_actions =SC_UNSPECIFIED );  
  7.   ……  
  8.  } 


     如下面的代码:

  1.  sc_report_handler::set_actions(SC_WARNING, SC_DO_NOTHING);  
  2.  sc_report_handler::set_actions("/Acme_IP", SC_DISPLAY);  
  3.  sc_report_handler::set_actions("/Acme_IP",SC_INFO, SC_DISPLAY|  SC_CACHE_REPORT );  
  4.  
  5.   SC_REPORT_WARNING("""1"); // 不输出任何信息  
  6.   SC_REPORT_WARNING("wb_sram""2"); // 打印“2”到标准输出  
  7.   SC_REPORT_INFO("/sram8x256""3"); //打印“3”到标准输出并且缓存。  
  8.  下文给出一个使用SC_REPORT_INFO的例子。该例子的全部代码见前面章节中的stimulus_gen:  
  9.   #include "systemc.h"  
  10.  SC_MODULE(stimulus_gen)  
  11.  {  
  12.  ……  
  13. void main()  
  14.  {  
  15.     ……  
  16.    SC_REPORT_INFO(“stimulus_gen_main”,” stimulus_gen started”);  
  17.   while(true) {   
  18.        ……  
  19.       }  
  20.  }  
  21.  SC_CTOR(stimulus_gen)  
  22.  {  
  23.      SC_THREAD(main);  
  24.     sensitive<<clk_i.pos();  
  25. };  
  26. }; 
(责任编辑:admin)
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名:密码: 验证码:点击我更换图片
推荐内容