Hardware/Software Codesign with SystemC

Post on 11-Jan-2016

53 views 3 download

description

Hardware/Software Codesign with SystemC. HM-ES-th1 Les 3. SystemC Module. Elementary building blocks. event. i n port. module. trigger. process. Beschrijft gedrag. read. write. Bijvoorbeeld: waarde op in port wijzigt. out port. SystemC SC_MODULE. - PowerPoint PPT Presentation

Transcript of Hardware/Software Codesign with SystemC

HM-ES-th1 Les 3

Hardware/Software Codesign with SystemC

SystemC ModuleElementary building blocks

2

in port

out port

module

process

read

write

event

trigger

Beschrijft gedrag

Bijvoorbeeld: waarde op in port

wijzigt

SystemC SC_MODULEEen module wordt gedefinieerd als een class m.b.v. de

macro SC_MODULE(…).Een input port worden gedefinieerd als sc_in<…>.Een output port worden gedefinieerd als sc_out<…>.Een process wordt gedefinieerd als memberfunctie en geregistreerd in de constructor met de macro SC_METHOD. (Er zijn ook nog andere soorten processen.)

De constructor wordt gedefinieerd m.b.v. de macro SC_CTOR(…).

De events waardoor de SC_METHOD start worden in de constructor gedefinieerd m.b.v. sensitive.

3

1 bit full adderSchema op poortniveau

4

1 bit full adderSC_MODULE(Adder) { sc_out<sc_logic> S, Cout; sc_in<sc_logic> A, B, Cin; SC_CTOR(Adder) { SC_METHOD(add); sensitive << A << B << Cin; }private: void add() { sc_logic tempC, tempD, tempE; tempC = A.read() & B.read(); tempD = A.read() ^ B.read(); tempE = Cin.read() & tempD; S.write(tempD ^ Cin.read()); Cout.write(tempC | tempE); }};

5

sc_logic is een 4-value type. Een variabele van het type sc_logic kan de waarde SC_LOGIC_0, SC_LOGIC_1, SC_LOGIC_X of SC_LOGIC_Z hebben.

tempC

tempD

tempE

1 bit full adderSC_MODULE(Adder) { sc_out<sc_logic> S, Cout; sc_in<sc_logic> A, B, Cin; SC_CTOR(Adder) { SC_METHOD(add); sensitive << A << B << Cin; }private: void add() { // zonder lokale variabelen S.write(A.read() ^ B.read() ^ Cin.read()); Cout.write(A.read() & B.read() |

Cin.read() & (A.read() ^ B.read())); }};

6

1 bit full adderSC_MODULE(Adder) { sc_out<sc_logic> S, Cout; sc_in<sc_logic> A, B, Cin; SC_CTOR(Adder) { SC_METHOD(add); sensitive << A << B << Cin; }private: void add() { // m.b.v. impliciete type conversies en operator overloading S = A ^ B ^ Cin; Cout = A & B | Cin & (A ^ B); }};

7

Raad ik niet aan

TestbenchWe gebruiken een testbench om (één of meerdere)

module(s) te testen.

8

AdderA B Cin

S Cout

Testbench

TA TB TCin

WachtenIn de beschrijving van de testbench willen we kunnen

wachten.Dit kan niet in een SC_METHOD maar wel in een SC_THREAD. Een SC_THREAD wordt slechts 1x aangeroepen door de SystemC kernel. Namelijk aan het begin van de simulatie.

9

Testbench voor 1 bit full adderSC_MODULE(Testbench) { sc_out<sc_logic> TA, TB, TCin; SC_CTOR(Testbench) { SC_THREAD(testprocess); }private: void testprocess() { TA.write(SC_LOGIC_0); TB.write(SC_LOGIC_0); TCin.write(SC_LOGIC_0); wait(10, SC_NS); TA.write(SC_LOGIC_1); wait(10, SC_NS); TB.write(SC_LOGIC_1); wait(10, SC_NS); TCin.write(SC_LOGIC_1); wait(10, SC_NS); TA.write(SC_LOGIC_0); TB.write(SC_LOGIC_0); TCin.write(SC_LOGIC_0); }};

10

Programma voor 1 bit full adderint sc_main(int argc, char *argv[]) { sc_signal<sc_logic> A, B, Cin; sc_signal<sc_logic> S, Cout; Adder adder("adder"); adder.A(A); adder.B(B); adder.Cin(Cin); adder.S(S); adder.Cout(Cout); Testbench tb("tb"); tb.TA(A); tb.TB(B); tb.TCin(Cin);

11

channels

channels

A B Cin

S Cout

adderA B Cin

S Cout

tb

TA TB TCin

Programma voor 1 bit full adder // Record (trace) signals for verification auto tf = sc_create_vcd_trace_file("trace"); tf->set_time_unit(1, SC_NS); sc_trace(tf, A, "A"); sc_trace(tf, B, "B"); sc_trace(tf, Cin, "Cin"); sc_trace(tf, S, "S"); sc_trace(tf, Cout, "Cout");

// Start the simulation for 200ns sc_start(200, SC_NS);

sc_close_vcd_trace_file(tf); return 0;}

12

Output in GTKWave

13

Betere testbenchGeautomatiseerde module test (unit test).

14

AdderA B Cin

S Cout

Testbench

Rapporteert fout of OK Huiswerk:

Schrijf een automatische testbench voor SC_MODULE(Adder)