From 27b67041656e08f6db6dce6e2daf01249839920c Mon Sep 17 00:00:00 2001 From: David Monniaux Date: Wed, 8 May 2019 23:10:11 +0200 Subject: carlightV2 example from Lustre V6 --- .../lustre-carlightV2/carlightV2_carlight_loop.c | 112 +++++---------------- test/monniaux/lustre-carlightV2/lustre_consts.c | 4 + test/monniaux/lustre-carlightV2/lustre_consts.h | 9 ++ test/monniaux/lustre-carlightV2/lustre_types.h | 75 ++++++++++++++ 4 files changed, 111 insertions(+), 89 deletions(-) create mode 100644 test/monniaux/lustre-carlightV2/lustre_consts.c create mode 100644 test/monniaux/lustre-carlightV2/lustre_consts.h create mode 100644 test/monniaux/lustre-carlightV2/lustre_types.h (limited to 'test') diff --git a/test/monniaux/lustre-carlightV2/carlightV2_carlight_loop.c b/test/monniaux/lustre-carlightV2/carlightV2_carlight_loop.c index 5040a5c6..2276d24b 100644 --- a/test/monniaux/lustre-carlightV2/carlightV2_carlight_loop.c +++ b/test/monniaux/lustre-carlightV2/carlightV2_carlight_loop.c @@ -5,9 +5,9 @@ #include #include #include -#include "carlightV2_carlight.h" -/* Print a promt ? ************************/ -static int ISATTY; +#include "carlightV2_carlight.h" +#include "../clock.h" + /* MACROS DEFINITIONS ****************/ #ifndef TT #define TT "1" @@ -22,88 +22,23 @@ static int ISATTY; /* set this macro for testing output clocks */ #endif +static uint32_t dm_random_uint32(void) { + static uint32_t current=UINT32_C(0xDEADBEEF); + current = ((uint64_t) current << 6) % UINT32_C(4294967291); + return current; +} + /* Standard Input procedures **************/ _boolean _get_bool(char* n){ - char b[512]; - _boolean r = 0; - int s = 1; - char c; - do { - if(ISATTY) { - if((s != 1)||(r == -1)) printf("\a"); - // printf("%s (1,t,T/0,f,F) ? ", n); - } - if(scanf("%s", b)==EOF) exit(0); - if (*b == 'q') exit(0); - s = sscanf(b, "%c", &c); - r = -1; - if((c == '0') || (c == 'f') || (c == 'F')) r = 0; - if((c == '1') || (c == 't') || (c == 'T')) r = 1; - } while((s != 1) || (r == -1)); - return r; + return dm_random_uint32() & 1; } _integer _get_int(char* n){ - char b[512]; - _integer r; - int s = 1; - do { - if(ISATTY) { - if(s != 1) printf("\a"); - //printf("%s (integer) ? ", n); - } - if(scanf("%s", b)==EOF) exit(0); - if (*b == 'q') exit(0); - s = sscanf(b, "%d", &r); - } while(s != 1); - return r; + return (_integer) (dm_random_uint32() % 21) - 10; } -#define REALFORMAT ((sizeof(_real)==8)?"%lf":"%f") _real _get_real(char* n){ - char b[512]; - _real r; - int s = 1; - do { - if(ISATTY) { - if(s != 1) printf("\a"); - //printf("%s (real) ? ", n); - } - if(scanf("%s", b)==EOF) exit(0); - if (*b == 'q') exit(0); - s = sscanf(b, REALFORMAT, &r); - } while(s != 1); - return r; -} -/* Standard Output procedures **************/ -void _put_bottom(char* n){ - if(ISATTY) printf("%s = ", n); - printf("%s ", BB); - if(ISATTY) printf("\n"); -} -void _put_bool(char* n, _boolean _V){ - if(ISATTY) printf("%s = ", n); - printf("%s ", (_V)? TT : FF); - if(ISATTY) printf("\n"); -} -void _put_int(char* n, _integer _V){ - if(ISATTY) printf("%s = ", n); - printf("%d ", _V); - if(ISATTY) printf("\n"); -} -void _put_real(char* n, _real _V){ - if(ISATTY) printf("%s = ", n); - printf("%f ", _V); - if(ISATTY) printf("\n"); -} -/* Output procedures **********************/ -#ifdef CKCHECK -void %s_BOT_n(void* cdata){ - _put_bottom("n"); -} -#endif -/* Output procedures **********************/ -void carlightV2_carlight_O_n(void* cdata, _integer _V) { - _put_int("n", _V); + return ((_integer) (dm_random_uint32() % 2000001) - 1000000)*1E-6; } + /* Main procedure *************************/ int main(){ int _s = 0; @@ -112,22 +47,21 @@ int main(){ _boolean is_on; carlightV2_carlight_ctx_type* ctx = carlightV2_carlight_ctx_new_ctx(NULL); - printf("#inputs \"switch_pos\":int \"intensity\":real\n"); - printf("#outputs \"is_on\":bool\n"); - /* Main loop */ - ISATTY = isatty(0); - while(1){ - if (ISATTY) printf("#step %d \n", _s+1); - else if(_s) printf("\n"); - fflush(stdout); + clock_prepare(); + clock_start(); + + for(int count=0; count<1000; count++){ ++_s; switch_pos = _get_int("switch_pos"); intensity = _get_real("intensity"); carlightV2_carlight_step(switch_pos,intensity,&is_on,ctx); // printf("%d %f #outs %d\n",switch_pos,intensity,is_on); - printf("%d\n",is_on); + // printf("%d\n",is_on); } - return 1; - + + clock_stop(); + print_total_clock(); + + return 0; } diff --git a/test/monniaux/lustre-carlightV2/lustre_consts.c b/test/monniaux/lustre-carlightV2/lustre_consts.c new file mode 100644 index 00000000..e1a77c9e --- /dev/null +++ b/test/monniaux/lustre-carlightV2/lustre_consts.c @@ -0,0 +1,4 @@ +/* This file was generated by lv6 version master.737 (2727a7744111c84f7984634d2bd3ad6f7c6c7ff9). */ +/* lv6 carlightV2.lus -n carlight --to-c */ +/* on vanoise the 08/05/2019 at 22:54:09 */ +#include "lustre_consts.h" \ No newline at end of file diff --git a/test/monniaux/lustre-carlightV2/lustre_consts.h b/test/monniaux/lustre-carlightV2/lustre_consts.h new file mode 100644 index 00000000..9d651d25 --- /dev/null +++ b/test/monniaux/lustre-carlightV2/lustre_consts.h @@ -0,0 +1,9 @@ +/* This file was generated by lv6 version master.737 (2727a7744111c84f7984634d2bd3ad6f7c6c7ff9). */ +/* lv6 carlightV2.lus -n carlight --to-c */ +/* on vanoise the 08/05/2019 at 22:54:09 */ + +// Constant definitions +#define carlightV2_AUTO 2 +#define carlightV2_OFF 1 +#define carlightV2_ON 0 +#define carlightV2_period 0.5 diff --git a/test/monniaux/lustre-carlightV2/lustre_types.h b/test/monniaux/lustre-carlightV2/lustre_types.h new file mode 100644 index 00000000..e1cfb463 --- /dev/null +++ b/test/monniaux/lustre-carlightV2/lustre_types.h @@ -0,0 +1,75 @@ +/* This file was generated by lv6 version master.737 (2727a7744111c84f7984634d2bd3ad6f7c6c7ff9). */ +/* lv6 carlightV2.lus -n carlight --to-c */ +/* on vanoise the 08/05/2019 at 22:54:09 */ + +#ifndef _SOC2C_PREDEF_TYPES +#define _SOC2C_PREDEF_TYPES +typedef int _boolean; +typedef int _integer; +typedef char* _string; +typedef double _real; +typedef double _double; +typedef float _float; +#define _false 0 +#define _true 1 +#endif +// end of _SOC2C_PREDEF_TYPES +// User typedef +#ifndef _carlightV2_carlight_TYPES +#define _carlightV2_carlight_TYPES +typedef _integer carlightV2_SwitchMode; +#endif // enf of _carlightV2_carlight_TYPES +// Memoryless soc ctx typedef +// Memoryfull soc ctx typedef +/* Lustre_pre_ctx */ +typedef struct { + /*Memory cell*/ + _boolean _memory ; +} Lustre_pre_ctx_type; + +/* Lustre_arrow_ctx */ +typedef struct { + /*Memory cell*/ + _boolean _memory ; +} Lustre_arrow_ctx_type; + +/* carlightV2_front_montant_ctx */ +typedef struct { + /*INSTANCES*/ + Lustre_pre_ctx_type Lustre_pre_ctx_tab[1]; + Lustre_arrow_ctx_type Lustre_arrow_ctx_tab[1]; +} carlightV2_front_montant_ctx_type; + +/* Lustre_pre_2_ctx */ +typedef struct { + /*Memory cell*/ + _real _memory ; +} Lustre_pre_2_ctx_type; + +/* Lustre_arrow_2_ctx */ +typedef struct { + /*Memory cell*/ + _boolean _memory ; +} Lustre_arrow_2_ctx_type; + +/* carlightV2_vrai_depuis_n_secondes_ctx */ +typedef struct { + /*INSTANCES*/ + Lustre_pre_2_ctx_type Lustre_pre_2_ctx_tab[1]; + Lustre_arrow_2_ctx_type Lustre_arrow_2_ctx_tab[1]; +} carlightV2_vrai_depuis_n_secondes_ctx_type; + +/* carlightV2_carlight_auto_ctx */ +typedef struct { + /*INSTANCES*/ + carlightV2_vrai_depuis_n_secondes_ctx_type carlightV2_vrai_depuis_n_secondes_ctx_tab[2]; +} carlightV2_carlight_auto_ctx_type; + +/* carlightV2_carlight_ctx */ +typedef struct { + /*INSTANCES*/ + carlightV2_front_montant_ctx_type carlightV2_front_montant_ctx_tab[1]; + carlightV2_carlight_auto_ctx_type carlightV2_carlight_auto_ctx_tab[1]; + Lustre_pre_ctx_type Lustre_pre_ctx_tab[1]; +} carlightV2_carlight_ctx_type; + -- cgit