summaryrefslogtreecommitdiff
path: root/src/hal/components/estop_latch.comp
blob: b50f633c60e93020181c1f6c2a5c19bc1272cecd (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
31
32
33
34
35
component estop_latch "ESTOP latch which sets ok-out true and fault-out false only if ok-in is true, fault-in is false, and a rising edge is seen on reset.  While ok-out is true, watchdog toggles, and can be used for chargepumps or similar needs.";
pin in bit ok_in;
pin in bit fault_in;
pin in bit reset;
pin out bit ok_out;
pin out bit fault_out;
pin out bit watchdog;
function _ nofp;
option data estop_data;
license "GPL";
;;

typedef struct { int old_reset; } estop_data;

FUNCTION(_) {
    /* check inputs */
    if ( ok_in && !fault_in) {
	/* no fault conditions, check for reset edge */
	if ( reset && !data.old_reset ) {
	    /* got a rising edge, indicate "OK" on outputs */
	    ok_out = 1;
	    fault_out = 0;
	}
	if( ok_out ) {
	    /* toggle watchdog */
	    watchdog = !watchdog;
	}
    } else {
	/* fault condition exists, trip */
	ok_out = 0;
	fault_out = 1;
    }
    /* store state of reset input for next pass (for edge detect) */
    data.old_reset = reset;
}