Minu Posted May 26, 2022 Report Posted May 26, 2022 I am beginner in SystemC. I have implemented add() function using SC_THREAD(while loop and wait()).I am printing output on log after 2ns.How can I achieve this using SC_METHOD and next_trigger? Code link using SC_THREAD:https://www.edaplayground.com/x/JSU8 Code link using SC_METHOD: https://www.edaplayground.com/x/wsBv Please help I am stuck over this. Quote
David Black Posted May 26, 2022 Report Posted May 26, 2022 void add() { next_trigger(2,SC_NS); y=a+b; } or void add() { y=a+b; next_trigger(2,SC_NS); } because next_trigger is non-blocking Quote
Minu Posted May 27, 2022 Author Report Posted May 27, 2022 Hi @David Black, Thanks for answering my question. This I have implemented earlier but in this way I am not getting correct out. MY testbench input is @0ns a=0 b=0. Out=0 @5ns a=5. b=0. Out=5 @8ns a=5. b=10 out=15 @15ns a=7. b=7 out=14 And I should get output after 2ns so the output will be appear at @0ns a=0 b=0. Out=0 @7ns a=5. b=0. Out=5 @10ns a=5. b=10 out=15 @17ns a=7. b=7 out=14 Above code is not fulfilling this requirement. It would be great if you provide some insights on this requirement. Quote
karthickg Posted June 17, 2022 Report Posted June 17, 2022 The code that uses SC_THREAD has two waits: while(1){ wait();//wait for sensitive list to occur wait(2,SC_NS); cout<<"\nWriting on out,at time"<<sc_time_stamp(); out.write(a.read()+b.read()); } The first `wait` blocks until one of the entries in its static sensitivity fires: SC_THREAD(adding); sensitive<<a; sensitive<<b; The SC_METHOD replacement has only a single `next_trigger` - so it is not equivalent to the earlier implementation: int c; c=a.read()+b.read(); out.write(c); next_trigger(2,SC_NS); You need to implement a state machine in the SC_METHOD using next_triggers if you want the same behavior. Check this post for example: Minu 1 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.