/* Autogenerated by /usr/bin/halcompile on Mon Feb 12 10:06:34 2018 -- do not edit */ #include "rtapi.h" #ifdef RTAPI #include "rtapi_app.h" #endif #include "rtapi_string.h" #include "rtapi_errno.h" #include "hal.h" #include "rtapi_math64.h" static int comp_id; #ifdef MODULE_INFO MODULE_INFO(linuxcnc, "component:flipflop:D type flip-flop"); MODULE_INFO(linuxcnc, "pin:data_:bit:0:in:data input:None:None"); MODULE_INFO(linuxcnc, "pin:clk:bit:0:in:clock, rising edge writes data to out:None:None"); MODULE_INFO(linuxcnc, "pin:set:bit:0:in:when true, force out true:None:None"); MODULE_INFO(linuxcnc, "pin:reset:bit:0:in:when true, force out false; overrides set:None:None"); MODULE_INFO(linuxcnc, "pin:out:bit:0:io:output:None:None"); MODULE_INFO(linuxcnc, "funct:_:0:"); MODULE_INFO(linuxcnc, "license:GPL"); MODULE_LICENSE("GPL"); #endif // MODULE_INFO struct __comp_state { struct __comp_state *_next; hal_bit_t *data_; hal_bit_t *clk; hal_bit_t *set; hal_bit_t *reset; hal_bit_t *out; void *_data; }; struct __comp_state *__comp_first_inst=0, *__comp_last_inst=0; static void _(struct __comp_state *__comp_inst, long period); static int __comp_get_data_size(void); #undef TRUE #define TRUE (1) #undef FALSE #define FALSE (0) #undef true #define true (1) #undef false #define false (0) static int export(char *prefix, long extra_arg) { char buf[HAL_NAME_LEN + 1]; int r = 0; int sz = sizeof(struct __comp_state) + __comp_get_data_size(); struct __comp_state *inst = hal_malloc(sz); memset(inst, 0, sz); inst->_data = (char*)inst + sizeof(struct __comp_state); r = hal_pin_bit_newf(HAL_IN, &(inst->data_), comp_id, "%s.data", prefix); if(r != 0) return r; r = hal_pin_bit_newf(HAL_IN, &(inst->clk), comp_id, "%s.clk", prefix); if(r != 0) return r; r = hal_pin_bit_newf(HAL_IN, &(inst->set), comp_id, "%s.set", prefix); if(r != 0) return r; r = hal_pin_bit_newf(HAL_IN, &(inst->reset), comp_id, "%s.reset", prefix); if(r != 0) return r; r = hal_pin_bit_newf(HAL_IO, &(inst->out), comp_id, "%s.out", prefix); if(r != 0) return r; rtapi_snprintf(buf, sizeof(buf), "%s", prefix); r = hal_export_funct(buf, (void(*)(void *inst, long))_, inst, 0, 0, comp_id); if(r != 0) return r; if(__comp_last_inst) __comp_last_inst->_next = inst; __comp_last_inst = inst; if(!__comp_first_inst) __comp_first_inst = inst; return 0; } static int default_count=1, count=0; char *names[16] = {0,}; RTAPI_MP_INT(count, "number of flipflop"); RTAPI_MP_ARRAY_STRING(names, 16, "names of flipflop"); int rtapi_app_main(void) { int r = 0; int i; comp_id = hal_init("flipflop"); if(comp_id < 0) return comp_id; if(count && names[0]) { rtapi_print_msg(RTAPI_MSG_ERR,"count= and names= are mutually exclusive\n"); return -EINVAL; } if(!count && !names[0]) count = default_count; if(count) { for(i=0; idata_) #undef clk #define clk (0+*__comp_inst->clk) #undef set #define set (0+*__comp_inst->set) #undef reset #define reset (0+*__comp_inst->reset) #undef out #define out (*__comp_inst->out) #undef data #define data (*(flipflop_data*)(__comp_inst->_data)) #line 12 "flipflop.comp" 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; } static int __comp_get_data_size(void) { return sizeof(flipflop_data); }