我是靠谱客的博主 执着睫毛膏,这篇文章主要介绍systemC全加器建模,现在分享给大家,希望可以做个参考。

博主今天刚看完systemC的时序建模和组合建模部分,就开始写sc代码了,但遇到了很多错误。。。

base.h头文件:

复制代码
1
2
3
4
5
#ifndef _base_ #define _base_ #include "systemc.h" #include <iostream> #endif

关于全加器的定义 full_adder.h :

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include "base.h" #ifndef _full_adder_ #define _full_adder_ SC_MODULE(Full_Adder) {     sc_in<bool>   a , b , carry_in ;     sc_out<bool>  sum , carry_out ;          void Full_Adder_Proc();          SC_CTOR(Full_Adder){         SC_METHOD(Full_Adder_Proc);         sensitive<<a<<b<<carry_in ;     } }; #endif

关于全加器的函数 full_adder.cpp :

复制代码
1
2
3
4
5
#include "full_adder.h" void Full_Adder::Full_Adder_Proc(){     sum = a^b^carry_in ;     carry_out = a&carry_in |  b&carry_in | a&b ; }

关于信号驱动的头文件  driver.h:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include "base.h" #ifndef _driver_ #define _driver_ SC_MODULE(driver) {     sc_out<bool > d_a , d_b , d_cin;          void driver_proc();          SC_CTOR(driver){         SC_METHOD(driver_proc);     } }; #endif

关于信号驱动的实现代码driver.cpp:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include "driver.h" void driver::driver_proc(){     sc_uint<3> temp;            temp = 0 ;            while(1){                   d_a = temp[0];                  d_b = temp[1];                    d_cin = temp[2];                        wait(5,SC_NS);                   temp++;               };     }

关于monitor的头文件:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include "base.h" #ifndef _monitor_ #define _monitor_ SC_MODULE(Monitor){     sc_in<bool> a , b , carry_in , sum , carry_out ;          void Monitor_Proc();          SC_CTOR(Monitor){             SC_METHOD(Monitor_Proc);             sensitive<<a<<b<<carry_in<<sum<<carry_out ;     } }; #endif

关于monitor的实现:

复制代码
1
2
3
4
5
#include "monitor.h" void Monitor::Monitor_Proc(){     std::cout<<" a:"<<a<<" b:"<<b<<" cin:"<<carry_in;     std::cout<<"sum:"<<sum<<" cout:"<<carry_out<<std::endl; }

期间博主犯了两个很傻的错误:

(1)   其中一个文件把#ifndef  写成了 #ifdef

(2)   构造函数SC_CTOR写成了SC_STOR

导致一直编译不能通过。。。。。。。。。。

在解决这些问题后,终于正常通过了,正打算看看结果,却发现:

screenshot from 2018-07-04 20-29-22.png

似乎和systemC内建的关键字冲突了,后来改了Driver,但还是显示相同的警告。

由于还没开始学习如何编写sc测试平台,所以暂时还不知道为什么会这样。。

暂且把问题留在这吧,等博主过段时间再来解答


今天博主看完了systemc的RTL级编程,默然明白错在哪了:

(1)SC_METHOD是一个需要返回的进程方法,不能做无限制的循环,所以需要改成SC_THREAD,只有这种线程方法才可以挂起。

(2)其次测试平台还需要遵循systemC的测试平台编写格式,之前的编写中sc_start语句都没有出现,所以仿真也没有开始。

下面是修改过的main.cpp代码:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
int sc_main(int argc , char * argv[]) {       //    signal defination             sc_signal<bool> a_s , b_s , c_in_s , c_out_s , sum_s;                          //  instance the component             simulus sim("simulus");             sim(a_s,b_s,c_in_s);                          full_adder fa("full_adder");             fa(a_s , b_s , c_in_s , c_out_s , sum_s);                          monitor mon("monitor");             mon(a_s , b_s , c_in_s , c_out_s , sum_s);                          sc_start(1000,SC_NS);                      return 0 ; }

仿真结果:

  SystemC 2.3.1-Accellera --- Jun 22 2016 09:40:28

        Copyright (c) 1996-2014 by all Contributors,

        ALL RIGHTS RESERVED

#     a    b    c_in    c_out    sum 

#     0    0    0        0        0

#     a    b    c_in    c_out    sum 

#     1    0    0        0        1

#     a    b    c_in    c_out    sum 

#     1    1    0        1        0

#     a    b    c_in    c_out    sum 

#     0    0    1        0        1

#     a    b    c_in    c_out    sum 

#     1    0    1        1        0

#     a    b    c_in    c_out    sum 

#     1    1    1        1        1


转载于:https://blog.51cto.com/13824643/2136269

最后

以上就是执着睫毛膏最近收集整理的关于systemC全加器建模的全部内容,更多相关systemC全加器建模内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(111)

评论列表共有 0 条评论

立即
投稿
返回
顶部