aboutsummaryrefslogtreecommitdiffstats
path: root/src/hal/components/flipflop.comp
blob: 235709db199cc7f07bdc04d9c9ae61e2fabb8084 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
component flipflop "D type flip-flop";
pin in bit data_ "data input";
pin in bit clk "clock, rising edge writes data to out";
pin in bit set "when true, force out true";
pin in bit reset "when true, force out false; overrides set";
pin io bit out "output";
pin io bit out-not "inverted output";
option data flipflop_data;

function _ nofp;
license "GPL";
author "John Kasunich";
;;

typedef struct { int oldclk; } flipflop_data;

FUNCTION(_) {
    int c;

    c = clk;
    if ( reset ) {
	out = 0;
    } else if ( set ) {
	out = 1;
    } else if ( c && ! data.oldclk ) {
	out = data_;
    }
    out_not = !out;
    data.oldclk = c;
}
bues.ch cgit interface