shangzheng的个人空间 https://blog.eetop.cn/188374 [收藏] [复制] [分享] [RSS]

空间首页 动态 记录 日志 相册 主题 分享 留言板 个人资料

日志

summary of <systemveriog_for_verification> (day9_continue)

已有 783 次阅读| 2008-1-29 22:11

7 program automatic unsynchronized;
class Producer;
task run;
for (int i=1; i<4; i++) begin
$display("Producer: before put(%0d)", i);
mbx.put(i);
end
endtask
endclass
206 Systemverilog for Verification
Example 7-30 Producer–consumer without synchronization, continued
class Consumer;
task run;
int i;
repeat (3) begin
mbx.get(i); // Get integer from mbx
$display("Consumer: after get(%0d)", i);
end
endtask
endclass
mailbox mbx;
Producer p;
Consumer c;
initial begin
// Construct mailbox, producer, consumer
mbx = new;
p = new;
c = new;
// Run the producer and consumer in parallel
fork
p.run;
c.run;
join
end
endprogram

so the Producer puts all three integers into the mailbox before the Consumer can get the first one. This is
because a thread continues running until there is a blocking statement, and the
Producer has none.


This is done by adding a blocking statement to the Producer such as an event, a semaphore, or a second mailbox. Example 7-32 uses an event to block the Producer after it puts data in the mailbox. The Consumer triggers the event after it consumes the data

If you use wait(handshake.triggered) in a loop, be
sure to advance the time before waiting again. This wait
blocks only once in a given time slot, so you need move into
another.

uses the edge-sensitive blocking
statement @handshake instead to ensure that the Producer stops after sending
the transaction.The edge-sensitive statement works multiple times in a time
slot but may have ordering problems if the trigger and block happen in the
same time slot.

program automatic mbx_evt;
event handshake;
class Producer;
task run;
for (int i=1; i<4; i++) begin
$display("Producer: before put(%0d)", i);
mbx.put(i);
@handshake;
$display("Producer: after put(%0d)", i);
end
endtask
endclass

class Consumer;
task run;
int i;
repeat (3) begin
mbx.get(i);
$display("Consumer: after get(%0d)", i);
->handshake;
end
endtask
endclass
...
endprogram
//because of no time information , so we use the @ not the wait(xxxx.triggered)

An event is the simplest construct, followed by blocking on a
variable. A semaphore is comparable to using a second mailbox, but no
information is exchanged.

class Agent;
mailbox gen2agt, agt2drv;
Transaction tr;
function new(mailbox gen2agt, agt2drv);
this.gen2agt = gen2agt;
this.agt2drv = agt2drv;
endfunction
function build;
// Empty for now
endfunction
task run;
forever begin
// Get transaction from upstream block
gen2agt.get(tr);
// Do some processing
// Send it to downstream block
agt2drv.put(tr);
end
endfunction
task wrapup;
// Empty for now
endtask
endclass


class Environment;
Generator gen;
Agent agt;
Driver drv;
Monitor mon;
Checker chk;
Scoreboard scb;
Config cfg;
mailbox gen2agt, agt2drv, mon2chk;
extern function new;
extern function void gen_cfg;
extern function void build;
extern task run;
extern task wrapup;
endclass
function Environment::new;
// Initialize mailboxes
gen2agt = new;
agt2drv = new;
mon2chk = new;
// Initialize transactors
gen = new(gen2agt);
agt = new(gen2agt, agt2drv);
drv = new(agt2drv);
mon = new(mon2chk);
chk = new(mon2chk);
scb = new;
cfg = new;
endfunction
function void Environment::gen_cfg;
assert(cfg.randomize);
endfunction
function void Environment::build;
gen.build;
agt.build;
drv.build;
mon.build;
Chapter 7: Threads and Interprocesses Communication 213
chk.build;
scb.build;
endfunction
task Environment::run;
fork
gen.run(run_for_n_trans);
agt.run;
drv.run;
mon.run;
chk.run;
scb.run(run_for_n_trans);
join
endtask
task Environment::wrapup;
fork
gen.wrapup;
agt.wrapup;
drv.wrapup;
mon.wrapup;
chk.wrapup;
scb.wrapup;
join
endtask

program automatic test;
Environment env;
initial begin
env = new;
env.gen_cfg;
env.build;
env.run;
env.wrapup;
end
endprogram




点赞

评论 (0 个评论)

facelist

您需要登录后才可以评论 登录 | 注册

  • 关注TA
  • 加好友
  • 联系TA
  • 0

    周排名
  • 0

    月排名
  • 0

    总排名
  • 0

    关注
  • 1

    粉丝
  • 0

    好友
  • 0

    获赞
  • 2

    评论
  • 139

    访问数
关闭

站长推荐 上一条 /1 下一条

小黑屋| 手机版| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-11-16 22:22 , Processed in 0.012164 second(s), 6 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
返回顶部