summaryrefslogtreecommitdiff
path: root/src/hal/components/flipflop.comp
blob: db3877e7e552c2eaaaec5a4db6469e25c6cec33a (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
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";
option data flipflop_data;

function _ nofp;
license "GPL";
;;

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_;
    }
    data.oldclk = c;
}