• No.6 Verilog 其他论题


    (1)任务
     **任务类似于一段程序,可以提供一种能力,使设计者可以从设计描述的不同位置执行共同的代码段。任务可以包含时序控制,
     可以调用其它任务和函数。
     
     任务的定义格式:
     task[automatic] task_id;
      [declarations]
      procedural_statement
     endtask

    **任务可以没有参变量,也可以有多个参变量,包括input,output,inout。

     示例:
     module esoc;
      parameter MAX = 8;
      task reverse_bits;
       input [MAX-1:0] data_in;
       output [MAX-1:0] data_out;
      integer k;
     
       begin 
        for(k=0; k<MAX; k=k+1)
        data_out[MAX-1-k] = data_in[k];
       end
      endtask
      ...
     endmodule

     **任务可以在其范围内声明任何变量,但仅限于其范围内使用,为局部变量。

     **关于automatic:
      任务可以被声明为automatic类型。在这样的任务中,任务内部声明的所有局部变量在每一次任务调用时都进行动态分配,
     即在任务调用中的局部变量不会对两个单独或者并发的任务调用产生影响。而在静态(非自动类型)任务中,在每一次任
     务调用中的局部变量都使用同一个存储空间。借助于关键字automatic就可以把任务指定为automatic类型。
    task automatic rotate;
      integer mac;
      ...;
     endtask
     **任务的调用:
     格式:task_id[(expr1, expr2, expr3, ...)]; 必须按定义的顺序匹配。
     示例:
    module golobal_var;
      reg[0:7]qram[0:63];
      integer index;
      reg check_bit;
      
      task get_parity;
       input [7:0]address;
       output parity_bit;
       parity_bit = ^qram[address];
      endtask
      
      initial
       for(index=0; index<=63; index = index+1)
        begin
         get_parity(index, check_bit);
         $display("Parity bit of memory word %d is %b.",index, check_bit);
        end
     endmodule
     **系统任务
     
     *显示任务:
      (a)显示、读写 :$display, $write
      (b)选通:$strobe
      (c)监控:$monitor
     
     *文件传输
      (a)打开、关闭文件:$fopen, $fclose
         输出到文件:$fdisplay, $fwrite, $fstrobe, $fmonitor, $fflush
         从文件读取数据:$readmemb, $fread...
     integer file_pointer = $fopen(file_name, mode); 
     $fclose(file_pointer);

    mode:

       "r","rb":打开文件并从文件的头开始读。如果文件不存在就报的错。
       "w","wb":打开文件并从文件的头开始写。如果文件不存在就创建文件。
       "a","ab":打开文件并从文件的末尾开始写。如果文件不存在就创建文件。
       "r+","r+b","rb":打开文件并从文件的头开始读写。如果文件不存在就报的错。
       "w+","w+b","wb":打开文件并从文件的头开始读写。如果文件不存在就创建文。
       "a+","a+b","ab":打开文件并从文件的末尾开始读写。如果文件不存在就创建文件。
       "b"是在打开二进制文件时引用。
      
      (b)时间标度:
       显示模块的时间单位和时间精度:$printtimescale
       指定如何报告时间信息:$timeformat
      $timeformat(units_number, precision, suffix, numeric_filed_width);

      (c)仿真任务:

       使仿真器退出仿真环境:$finish
       仿真中止:$stop
     

    (2)函数
     **类似于任务,可以在不同位置执行共同的代码段,不同的是,函数只能返回一个值,不能包含任何延迟,必须立即执行,
    不能调用任何其它任务,输入必须至少有一个,不允许有inout,output的声明;可以调用其它函数。
     
     **定义:
     function [automatic][signed]
      [range_of_type] function_id; //function_id为返回的值
      input_declaration
      other_declarations
      procedural_statement
     endfunction
     //
     function [automatic][signed]
      [range_of_type] function_id(input_declaration);
      other_declarations
      procedural_statement
     endfunction
     **函数的调用:
     格式:func_id(expr1, expr2, expr3, ...)
     
     **系统函数
     (a)仿真时间函数:$time, $stime, $realtime; // 返回64位,32位,实型仿真时间
     
     (b)转换函数:
      $rtoi(real_value)        $itor(integer_value),
      $realtobits(real_value)  $bitstoreal(bit_value),
      $signed(value)           $unsigned(value)
     
     (c)概率分布函数:$random ...
     
     (d)字符串格式化:$swrite, $sformat, $sscanf
     

    (3)禁止语句
     
     **禁止语句是过程性语句,只能出现在always和initial中,禁止语句可以终止任务或程序块的执行,能够用于硬件中断和全局复位的建模。
     
     *格式:
      disable task_id;
      disable bolck_id;
    (4)命名事件
     
     命名事件是Verilog的另一种数据类型(其他两种是变量和线网)。
     声明格式:event ready, done;
     使用格式:->ready; ->done;
     
     示例:异步状态机
     event state1, state2, state3;
     //复位状态
     initial begin
      ->state1;
      end
     always@(state1)begin
      ->state2;
      end
     always@(state2)begin
      ->state3;
      end
     always@(state3)begin
      if(input_a) ->state2;
      else ->state1;
      end
  • 相关阅读:
    20Spring_JdbcTemplatem模板工具类
    19Spring_AOP编程(AspectJ)_使用@Pointcut注解来定义切点
    18Spring_AOP编程(AspectJ)_AspectJ的各种通知总结
    17Spring_AOP编程(AspectJ)_AspectJ的注解编程
    14Spring_AOP编程(AspectJ)_环绕通知
    android ViewPager滑动事件讲解
    为listview的item中的元素设置onclick事件
    Android EditText光标颜色 与inputType
    【Android】Android内存溢出问题---用自行开辟的空间进行对内存管理
    【Android】eclipse打不开的解决办法和“Jar mismatch! Fix your dependencies”的解决
  • 原文地址:https://www.cnblogs.com/vilicute/p/11614595.html
Copyright © 2020-2023  润新知