diff --git a/beautiful-racket/br/demo/hdl/DMux.hdl.rkt b/beautiful-racket/br/demo/hdl/DMux.hdl.rkt index 189558b..fc3bc99 100644 --- a/beautiful-racket/br/demo/hdl/DMux.hdl.rkt +++ b/beautiful-racket/br/demo/hdl/DMux.hdl.rkt @@ -16,6 +16,7 @@ CHIP DMux { OUT a, b; PARTS: - And(a=in, b=sel, out=a); + Not(in=sel, out=not-sel); + And(a=in, b=not-sel, out=a); And(a=in, b=sel, out=b); } diff --git a/beautiful-racket/br/demo/hdl/DMux4Way-test.rkt b/beautiful-racket/br/demo/hdl/DMux4Way-test.rkt new file mode 100644 index 0000000..404fc95 --- /dev/null +++ b/beautiful-racket/br/demo/hdl/DMux4Way-test.rkt @@ -0,0 +1,28 @@ +#lang racket +(require "DMux4Way.hdl.rkt") +(require rackunit) + +(DMux4Way-in (random 2)) +(DMux4Way-sel #b00) +(check-equal? (DMux4Way-a) (DMux4Way-in)) +(check-equal? (DMux4Way-b) 0) +(check-equal? (DMux4Way-c) 0) +(check-equal? (DMux4Way-d) 0) + +(DMux4Way-sel #b01) +(check-equal? (DMux4Way-a) 0) +(check-equal? (DMux4Way-b) (DMux4Way-in)) +(check-equal? (DMux4Way-c) 0) +(check-equal? (DMux4Way-d) 0) + +(DMux4Way-sel #b10) +(check-equal? (DMux4Way-a) 0) +(check-equal? (DMux4Way-b) 0) +(check-equal? (DMux4Way-c) (DMux4Way-in)) +(check-equal? (DMux4Way-d) 0) + +(DMux4Way-sel #b11) +(check-equal? (DMux4Way-a) 0) +(check-equal? (DMux4Way-b) 0) +(check-equal? (DMux4Way-c) 0) +(check-equal? (DMux4Way-d) (DMux4Way-in)) diff --git a/beautiful-racket/br/demo/hdl/Dmux-test.rkt b/beautiful-racket/br/demo/hdl/Dmux-test.rkt new file mode 100644 index 0000000..f1dc0dc --- /dev/null +++ b/beautiful-racket/br/demo/hdl/Dmux-test.rkt @@ -0,0 +1,23 @@ +#lang racket +(require "DMux.hdl.rkt") +(require rackunit) + +(DMux-in 0) +(DMux-sel 0) +(check-equal? (DMux-a) 0) +(check-equal? (DMux-b) 0) + +(DMux-in 0) +(DMux-sel 1) +(check-equal? (DMux-a) 0) +(check-equal? (DMux-b) 0) + +(DMux-in 1) +(DMux-sel 0) +(check-equal? (DMux-a) 1) +(check-equal? (DMux-b) 0) + +(DMux-in 1) +(DMux-sel 1) +(check-equal? (DMux-a) 0) +(check-equal? (DMux-b) 1) diff --git a/beautiful-racket/br/demo/hdl/Dmux4Way.hdl.rkt b/beautiful-racket/br/demo/hdl/Dmux4Way.hdl.rkt index dd941c8..3d5ccfd 100644 --- a/beautiful-racket/br/demo/hdl/Dmux4Way.hdl.rkt +++ b/beautiful-racket/br/demo/hdl/Dmux4Way.hdl.rkt @@ -14,9 +14,11 @@ */ CHIP DMux4Way { + // todo: how should sel subscripting work? IN in, sel[2]; - OUT out; + OUT a, b, c, d; PARTS: - Not(in=sel[0], out=out); + DMux(in=in, sel[0]=sel, a=a, b=b); + DMux(in=in, sel[1]=sel, a=c, b=d); } \ No newline at end of file diff --git a/beautiful-racket/br/demo/hdl/expander.rkt b/beautiful-racket/br/demo/hdl/expander.rkt index e2404af..850fd0b 100644 --- a/beautiful-racket/br/demo/hdl/expander.rkt +++ b/beautiful-racket/br/demo/hdl/expander.rkt @@ -17,7 +17,7 @@ (define-input-bus _input-pin _input-width ...) ... _part ... (provide prefixed-output-pin ...) - (define-output-bus prefixed-output-pin (λ () (_output-pin)) _output-width ...) ...))) + (define-output-bus prefixed-output-pin _output-pin _output-width ...) ...))) (define #'(part _prefix [_suffix . _args] ...) diff --git a/beautiful-racket/br/demo/hdl/parser.rkt b/beautiful-racket/br/demo/hdl/parser.rkt index f560ebf..5b22dd9 100644 --- a/beautiful-racket/br/demo/hdl/parser.rkt +++ b/beautiful-racket/br/demo/hdl/parser.rkt @@ -20,7 +20,7 @@ part : partname /"(" pin-val-pair [/"," pin-val-pair]* /")" /";" /pin-val-pair : ID [/"[" bus-range /"]"] /"=" pin-val -@bus-range : NUMBER [/"." /"." NUMBER] +@bus-range : (NUMBER | BINARY-NUMBER) [/"." /"." (NUMBER | BINARY-NUMBER)] @pin-val : ID | BINARY-NUMBER