SystemC Modules
来源:互联网 发布:国家c语言考试时间 编辑:程序博客网 时间:2024/05/15 13:24
SystemC
int sc_main(int argc,char * argv[])
{
sc_start(); //simulation begin
}
systemc provide access to argc and argv thoroughout the model hierarchy by providing the functions as follow:
int sc_argc();//access to argc
const sc_argv();//access to argv
说明systemc支持通过特定的函数访问,获取两个参数的值。
复杂的系统是由许多独立的功能组件组成。
SC_MODULE是一个简单的cpp宏:
#define SC_MODULE(module_name) \
struct module_name :public sc_module
两种不同的方式应用SystemC macros:
1.传统的方式
#ifndef NAME_H
#define NAME_H
#include "submodule.h"
...
SC_MODULE(NAME){
port declerations
channel /submodule instance
SC_CTOR(NAME){
connnectivity
process registrations
}
process declerations
helper declerations
};
#endif
//NAME.cpp
#include "systemc.h"
#include "NAME.h"
NAME::process {implementation}
NAME::helper {implemention}
2.建议类型
//NAME.h
#ifndef NAME_H
#define NAME_H
submodule forword class declerations
SC_MODULE(NAME){
port declerations
channel /submodule definitions
//constructors declerations
SC_CTOR(NAME);
process declerations
Helper declerations
}
//NAME.cpp
#include "NAME.h"
SC_HAS_PROCESS(NAME);
NAME::NAME(sc_module_name nm):sc_module(nm)
Initializations
{
channel allocations
submodule allocations
process registations
}
NAME::process{implementions }
NAME::Helper{implementions }
{{Macro SC_CTOR includes definitions used by the macros SC_METHOD, SC_THREAD and
SC_CTHREAD. These same definitions are introduced by the macro SC_HAS_PROCESS. If a process
macro is invoked from the constructor body of a module but macro SC_CTOR is not used within the module
class definition, macro SC_HAS_PROCESS shall be invoked within the class definition or the constructor
body of the module. If a process macro is invoked from the before_end_of_elaboration or
end_of_elaboration callbacks of a module but macro SC_CTOR is not used within the module class
definition, macro SC_HAS_PROCESS shall be invoked within the class definition of the module or from
that same callback.
Macro SC_HAS_PROCESS shall only be used within the class definition, constructor body, or member
function body of a module. The name of the module cl ass being constructed shall be passed as the argument
to the macro. The macr o invocation shall be terminated with a semicolon.IE标准-1666-2011}}
一.
模块作为一个特定功能的基本单元,可以包含一些其它的SystemC解基本元素,如端口,信号,子模块,进程,构造函数。
定义类型有如下三种:
1.
SC_MODULE(MM){
//Design..
};
2.
class MM:public sc_module{
//Desigin..
sc_HAS_PROCESS(MM);//sc_HAS_PROCESS 是一个宏声明
//Design..
};
3.
struct MM:public sc_module{ //design..
};
二.顶层模块和模块连接
一个模块实际上是一个类,一个模块实例的建立,就像c++中声明一对象。顶层模块的作用是将各个子模块连接起来。子模块中的端口是通过顶层模块中定义的信号(sc_signal<type<width> > name)进行关联或连接的。
模块连接有位置和名字关联(一般不容易产生错误,设计者可以任意顺序的创建信号和端口间的连接而不会产生错误最好用这个)。
三.模块的内部数据
设计者可以通过声明内部数据来保存模块内部的数据。内部数据存储类型可以是任何合法的systemc类型,c++类型和用户自定义类型。一般地,在模块外部是看不到模块内部的数据的,一个模块只可以通过端口来访问另一模块。实际上,如果使用SC_MODULE(module_name_)来定义模块,则默认情况下,所有的数据成员都是公有的,其它模块可以通过直接访问module.name.varible_named的方式来读写一个模块的内部数据。除非是极特殊情况,这种方法最好不要用。
systemc user guid 2.01 example:
//count.h
#include "systemc.h"
SC_MODULE(count){
sc_in<bool>load;
sc_in<int>din;
sc_in<bool>clock;
sc_out<int>dout;
int count_val;//internel data storage 模块内部数据类型
void count_up();
SC_CTOR(count){
SC_METHOD(count_up);
sensitive_pos<<clock;
}
};
//count.cpp
#include "count.h"
void count::count_up(){
if(load){
count_val = din;
}
else{
count_val = count_val + 1;
}
dout.write(count_val); //or dout = count_val;
}
通过显示的私有声明会更有利于数据的保护,这在行为建模中非常有用。
eg:
class count:public sc_module{
........
private:
int count_val;
}
四.模块的构造函数和析构函数
模块的构造函数完成创建模和初始化一个模块的最初工作,它在一个模块的实例被创建时就被执行。c++中的构造函数创建模块内部数据结构,并把这些数据结构初始化为已知的值。在systemc中,除了完成c++中所要求的基本功能外,模块构造函数还用于初始化进程的类型并创建进程的敏感列表。SC_CTOR表示构造函数,
eg:SC_CTOR(MM){
SC_METHOD(..);
sensitive<<...;
}
析构函数在特殊情况下才被使用,SystemC中没有定义专门的类似SC_CTOR的宏来处理析构函数,析构函数按照传统的c++的模式声明。析构函数的作用是清除构造函数申请的内存单元。
- SystemC Modules
- SystemC教程-模块和进程(Modules and Processes)
- Use FeatureC++ to develop SystemC modules —— a case study
- modules
- Modules
- Modules
- modules
- fuck systemc
- SystemC 数据类型
- systemc学习
- SystemC概述
- SystemC Install
- Why SystemC
- SystemC 初始化步骤
- SystemC 初始化步骤
- SystemC 初始化步骤
- SystemC 初始化步骤
- SystemC 初始化步骤
- xargs 的用法
- poj3162 Walking Race
- 中国云计算现状:糟糕的公有云服务阻碍了中国云计算的进一步发展
- poj1016-Numbers That Count
- 南洋理工 55 懒省事的小明
- SystemC Modules
- 往死里写——SDO处理2-2
- Java基础知识_自动装箱/享元/枚举
- 《数据通信与网络》笔记--广域网SONET/SDH
- <s:property>的用法
- ubuntu-server无线网设置
- 简析STUN协议
- SecureCRT设置
- 魔塔源码