summaryrefslogtreecommitdiff
path: root/src/hal/components/conv.comp.in
blob: f7ff07e4fb9497b4de4104c0269e741560c30823 (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
component conv_@IN@_@OUT@ "Convert a value from @IN@ to @OUT@";
pin in @IN@ in_;
pin out @OUT@ out;
@CC@ pin out bit out_of_range "TRUE when 'in' is not in the range of @OUT@";
@CC@ param rw bit clamp """If TRUE, then clamp to the range of @OUT@.  If FALSE, then allow the value to "wrap around".""";
function _ @FP@ "Update 'out' based on 'in'";
license "GPL";

;;
FUNCTION(_) {
    hal_@IN@_t in = in_;
@CC@    if(clamp) {
#if @MAX@ != 0
@CC@	if(in > @MAX@) { out = @MAX@; out_of_range = 1; return; }
#endif
#if @MIN@ != -1
@CC@	if(in < @MIN@) { out = @MIN@; out_of_range = 1; return; }
#endif
@CC@	out = in; out_of_range = 0;
@CC@    } else {
	out = in;
@CC@	if(out != in) out_of_range = 1;
@CC@    }
}