From abc3cd72f7efe4d2e81941a9f047474524ea5800 Mon Sep 17 00:00:00 2001 From: David Monniaux Date: Mon, 8 Apr 2019 11:15:56 +0200 Subject: from Tacle Bench --- test/monniaux/tacle-bench-lift/liftlibio.c | 65 ++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 test/monniaux/tacle-bench-lift/liftlibio.c (limited to 'test/monniaux/tacle-bench-lift/liftlibio.c') diff --git a/test/monniaux/tacle-bench-lift/liftlibio.c b/test/monniaux/tacle-bench-lift/liftlibio.c new file mode 100644 index 00000000..f61df2d0 --- /dev/null +++ b/test/monniaux/tacle-bench-lift/liftlibio.c @@ -0,0 +1,65 @@ +#include "liftlibio.h" + +/* Global variables */ +int lift_ctrl_io_in[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +int lift_ctrl_io_out[4] = {0, 0, 0, 0}; +int lift_ctrl_io_analog[4] = {0, 0, 0, 0}; +int lift_ctrl_io_led[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +int lift_ctrl_dly1; +int lift_ctrl_dly2; + +/* Simulated hardware */ +volatile int lift_simio_in; +volatile int lift_simio_out; +volatile int lift_simio_led; +volatile int lift_simio_adc1; +volatile int lift_simio_adc2; +volatile int lift_simio_adc3; + +void lift_io_init() +{ + lift_ctrl_dly1 = 0; + lift_ctrl_dly2 = 0; +} + + +void lift_ctrl_set_vals() +{ + int val = 0, i; + _Pragma( "loopbound min 4 max 4" ) + for ( i = 4 - 1; i >= 0; --i ) { + val <<= 1; + val |= lift_ctrl_io_out[i] ? 1 : 0; + } + lift_simio_out = val; + _Pragma( "loopbound min 16 max 16" ) + for ( i = 14 - 1; i >= 0; --i ) { + val <<= 1; + val |= lift_ctrl_io_led[i] ? 1 : 0; + } + lift_simio_led = val; + lift_checksum += val; +} + + +void lift_ctrl_get_vals() +{ + int i; + unsigned short int in0 = lift_simio_in; + unsigned short int in1 = lift_ctrl_dly1; + unsigned short int in2 = lift_ctrl_dly2; + lift_ctrl_dly2 = lift_ctrl_dly1; + lift_ctrl_dly1 = in0; + /* majority voting for input values + delays input value change by one period */ + _Pragma( "loopbound min 10 max 10" ) + for ( i = 0; i < 10; ++i ) { + lift_ctrl_io_in[i] = ( ( in0 & 1 ) + ( in1 & 1 ) + ( in2 & 1 ) ) > 1; + in0 >>= 1; + in1 >>= 1; + in2 >>= 1; + } + lift_ctrl_io_analog[0] = lift_simio_adc1; + lift_ctrl_io_analog[1] = lift_simio_adc2; + lift_ctrl_io_analog[2] = lift_simio_adc3; +} -- cgit