您当前的位置:五五电子网电子知识电子学习基础知识电脑-单片机-自动控制SystemC中的信息和差错报告机制 正文
SystemC中的信息和差错报告机制

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

点击数:7224 次   录入时间:03-04 12:04:03   整理:http://www.55dianzi.com   电脑-单片机-自动控制

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

  1. SC_REPORT_INFO( msg_type , msg )  
  2. SC_REPORT_WARNING( msg_type , msg )  
  3. SC_REPORT_ERROR( msg_type , msg )  
  4. SC_REPORT_FATAL( msg_type , msg )   
  5. 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
  3.  , msg , __FILE__ , __LINE__ )  
  4. #define SC_REPORT_WARNING( msg_type , msg ) \  
  5.  sc_report_handler::report( SC_WARNING , msg_type 
  6. , msg , __FILE__ , __LINE__ )  
  7. #define SC_REPORT_ERROR( msg_type , msg ) \  
  8. sc_report_handler::report( SC_ERROR , msg_type 
  9. , msg , __FILE__ , __LINE__ )  
  10. #define SC_REPORT_FATAL( msg_type , msg ) \  
  11. sc_report_handler::report( SC_FATAL , msg_type 
  12. , msg , __FILE__ , __LINE__ )  
  13. #define sc_assert( expr ) \  
  14.  ( ( void ) ( ( expr ) ? 0 : ( SC_REPORT_FATAL( 
  15. 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 , 
  5. sc_actions = SC_UNSPECIFIED );  
  6.     static sc_actions set_actions( const char * msg_type 
  7. , sc_actions =        SC_UNSPECIFIED );  
  8.    static sc_actions set_actions( const char * msg_type ,
  9.  sc_severity , sc_actions =SC_UNSPECIFIED );  
  10.   ……  
  11.  } 

     如下面的代码:
 

  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, 
  4. SC_DISPLAY|  SC_CACHE_REPORT );  
  5.  
  6.   SC_REPORT_WARNING("", "1"); // 不输出任何信息  
  7.   SC_REPORT_WARNING("wb_sram", "2"); // 打印“2”到标准输出  
  8.   SC_REPORT_INFO("/sram8x256", "3"); //打印“3”到标准输出并且缓存。  
  9.  下文给出一个使用SC_REPORT_INFO的例子。该例子的全部代码见前面章节中的stimulus_gen:  
  10.   #include "systemc.h"  
  11.  SC_MODULE(stimulus_gen)  
  12.  {  
  13.  ……  
  14. void main()  
  15.  {  
  16.     ……  
  17.    SC_REPORT_INFO(“stimulus_gen_main”,” stimulus_gen started”);  
  18.   while(true) {   
  19.        ……  
  20.       }  
  21.  }  
  22.  SC_CTOR(stimulus_gen)  
  23.  {  
  24.      SC_THREAD(main);  
  25.     sensitive<<clk_i.pos();  
  26. };  
  27. }; 




 

(


本文关键字:信息  电脑-单片机-自动控制电子学习 - 基础知识 - 电脑-单片机-自动控制