systemC的同步时序建模

systemC的时序逻辑建模

systemc的时序逻辑方法分为两种:
1)  静态时序逻辑:
    使用关键字sensitive,sensitive_pos , sensitive_neg :使得触发为值触发,正跳边沿触发,负跳变沿触发
    这种触发方式为静态触发方式。
2) 动态时序逻辑:
    在挂起的线程函数的wait语句中使用。
    条件为port.posedge_event()  port.negedge_event()  port.value_changed_event() ,
    并且可以结合逻辑操作符和时间表示复杂的逻辑关系。

一般在不复杂的时序逻辑中,都使用静态时序逻辑,并且同组合逻辑相组合。

下面是一个关于检测序列的sc程序,只有当检测到3个连续的1时,流水检测才输出为1:

#include "base.h"
#ifndef STREAMCHECK
#define STREAMCHECK
const int size = 3 ;
SC_MODULE(streamcheck){
    sc_in<bool >stream_in , clk ;
    sc_out<bool> check ;
    sc_signal<sc_uint<size> > reg ;
    void move();
    void getcheck();
    SC_CTOR(streamcheck){
        reg = 0 ;
        SC_METHOD(move);
        sensitive_pos<<clk;    //  sequential logic  ,   triggered by the clk !!!
        sc_METHOD(check);
        sensitive<<reg ;       //  combinational logic ,  determine by the reg .
                       //  Hold one thing ! the sc_signal is equal to the reg type in the verilog hdl .
    }
};
#endif
#include "streamcheck.h"
void streamcheck::move(){
    sc_uint<size> reg_temp = reg.read();
    reg_temp = (reg_temp>>1,stream_in.read());
    reg = reg_temp ;
}
    
void streamcheck::getcheck(){
    sc_uint<size> temp = reg.read();
    check = temp[0] & temp[1] & temp[2] ;
    //   when checked the instream all are "1" , get the check port 1 !!!
}


在这种同步的时序下,可以添加只由端口跳变触发的进程函数来达到异步的目的。
同时注意一点:在进程或线程函数的条件分支没有完全覆盖时会产生不必要的锁存器,这时需要通过对其取默认值的方式进行解决。

猜你喜欢

转载自blog.51cto.com/13824643/2137263