openVSM  1.0
 All Data Structures Files Functions Variables Pages
c_bind.c
Go to the documentation of this file.
1 
9 #include <vsm_api.h>
10 
17 const char *state_to_string (STATE pinstate)
18 {
19  switch (pinstate)
20  {
21  case UNDEFINED:
22  return "UNDEFINED";
23  case TSTATE:
24  return "TSTATE";
25  case FSTATE:
26  return "FSTATE";
27  case PLO:
28  return "PLO";
29  case ILO:
30  return "ILO";
31  case SLO:
32  return "SLO";
33  case WLO:
34  return "WLO";
35  case FLT:
36  return "FLT";
37  case WHI:
38  return "WHI";
39  case SHI:
40  return "SHI";
41  case IHI:
42  return "IHI";
43  case PHI:
44  return "PHI";
45  case WUD:
46  return "WUD";
47  case SUD:
48  return "SUD";
49  default:
50  return "wrong state";
51  }
52 }
53 
54 int popup_id = 0;
55 
61 bool vsm_register ( ILICENCESERVER* ils )
62 {
63 
64  if ( FALSE == ils->vtable->authorize ( ils, 0, model_key, VSM_API_VERSION ) )
65  {
66  return FALSE;
67  }
68  return TRUE;
69 }
70 
76 void set_pin_state ( VSM_PIN pin, STATE state )
77 {
78  ABSTIME curtime = 0;
79  systime ( &curtime );
80  pin.pin->vtable->setstate2 ( pin.pin, 0, curtime, pin.on_time, state );
81 }
82 
88 void set_pin_bool ( VSM_PIN pin, bool level )
89 {
90  ABSTIME curtime = 0;
91  systime ( &curtime );
92  pin.pin->vtable->setstate2 ( pin.pin, 0, curtime, pin.on_time, level ? SHI : SLO );
93 }
94 
99 void systime ( ABSTIME* at )
100 {
101  model_dsim->vtable->sysvar ( model_dsim, 0, ( DOUBLE* ) at, DSIMTIMENOW );
102 }
103 
109 char* get_string_param ( char* field_name )
110 {
111  return model_instance->vtable->getstrval ( model_instance, 0, field_name, "?" );
112 }
113 
119 bool get_bool_param ( char* field_name )
120 {
121  return model_instance->vtable->getboolval ( model_instance, 0, field_name, FALSE );
122 }
123 
129 double get_num_param ( char* field_name )
130 {
131  double result = 0;
132  model_instance->vtable->getnumval ( model_instance, 0, &result, field_name, 0.0 );
133  return result;
134 }
135 
141 int32_t get_hex_param ( char* field_name )
142 {
143  return ( int32_t ) model_instance->vtable->gethexval ( model_instance, 0, field_name, 0 );
144 }
145 
151 int64_t get_init_param ( char* field_name )
152 {
153  return ( int64_t ) model_instance->vtable->getinitval ( model_instance, 0, field_name, 0 );
154 }
155 
162 void load_image ( char* filename, uint8_t* buffer, size_t buffer_size )
163 {
164  model_instance->vtable->loadmemory ( model_instance, 0, filename, buffer, buffer_size, 0, 0 );
165 }
166 
172 IPOPUP* create_popup ( CREATEPOPUPSTRUCT* cps )
173 {
174  return ( ( IPOPUP* ) model_instance->vtable->createpopup ( model_instance, 0, cps ) );
175 }
176 
183 IMEMORYPOPUP* create_memory_popup ( const char* title, const int32_t id )
184 {
185  CREATEPOPUPSTRUCT* cps = malloc ( sizeof *cps );
186  cps->caption = ( char* ) title;
187  cps->flags = PWF_VISIBLE | PWF_HIDEONANIMATE | PWF_SIZEABLE| PWF_AUTOREFRESH ;
188  cps->type = PWT_MEMORY;
189  cps->height = 32;
190  cps->width = 16;
191  cps->id = id;
192  IMEMORYPOPUP* popup = ( IMEMORYPOPUP* ) create_popup ( cps );
193  free ( cps );
194  return popup;
195 }
196 
203 IDEBUGPOPUP* create_debug_popup ( const char* title, const int32_t id )
204 {
205  CREATEPOPUPSTRUCT* cps = malloc ( sizeof *cps );
206  cps->caption = ( char* ) title;
207  cps->flags = PWF_VISIBLE | PWF_HIDEONANIMATE | PWF_SIZEABLE| PWF_AUTOREFRESH ;
208  cps->type = PWT_DEBUG;
209  cps->height = 200;
210  cps->width = 640;
211  cps->id = id;
212  IDEBUGPOPUP* popup = create_popup ( cps );
213  free ( cps );
214  return popup;
215 }
216 
223 IDEBUGPOPUP* create_source_popup ( const char* title, const int32_t id )
224 {
225  CREATEPOPUPSTRUCT* cps = malloc ( sizeof *cps );
226  cps->caption = ( char* ) title;
227  cps->flags = PWF_VISIBLE | PWF_HIDEONANIMATE | PWF_SIZEABLE| PWF_AUTOREFRESH ;
228  cps->type = PWT_SOURCE;
229  cps->height = 200;
230  cps->width = 640;
231  cps->id = id;
232  IDEBUGPOPUP* popup = create_popup ( cps );
233  free ( cps );
234  return popup;
235 }
236 
243 IDEBUGPOPUP* create_status_popup ( const char* title, const int32_t id )
244 {
245  CREATEPOPUPSTRUCT* cps = malloc ( sizeof *cps );
246  cps->caption = ( char* ) title;
247  cps->flags = PWF_VISIBLE | PWF_HIDEONANIMATE | PWF_SIZEABLE | PWF_AUTOREFRESH ;
248  cps->type = PWT_STATUS;
249  cps->height = 200;
250  cps->width = 200;
251  cps->id = id;
252  IDEBUGPOPUP* popup = create_popup ( cps );
253  free ( cps );
254  return popup;
255 }
256 
263 IDEBUGPOPUP* create_var_popup ( const char* title, const int32_t id )
264 {
265  CREATEPOPUPSTRUCT* cps = malloc ( sizeof *cps );
266  cps->caption = ( char* ) title;
267  cps->flags = PWF_VISIBLE | PWF_HIDEONANIMATE | PWF_SIZEABLE| PWF_AUTOREFRESH ;
268  cps->type = PWT_VAR;
269  cps->height = 200;
270  cps->width = 200;
271  cps->id = id;
272  IDEBUGPOPUP* popup = create_popup ( cps );
273  free ( cps );
274  return popup;
275 }
276 
281 void delete_popup ( POPUPID id )
282 {
283  model_instance->vtable->deletepopup ( model_instance, 0, id );
284 }
285 
293 void set_memory_popup ( IMEMORYPOPUP* popup, size_t offset, void* buffer, size_t size )
294 {
295  popup->vtable->setmemory ( popup, 0, offset, buffer, size );
296 }
297 
305 bool add_source_file ( ISOURCEPOPUP* popup, char* filename, bool lowlevel )
306 {
307  bool result = popup->vtable->addsrcfile ( popup, 0, filename, lowlevel );
308  popup->vtable->setpcaddress ( popup, 0, 0 );
309  return result;
310 }
311 
316 bool set_vdm_handler ( void )
317 {
318  return model_instance->vtable->setvdmhlr ( model_instance, 0, &ICPU_DEVICE );
319 }
320 
326 void set_pc_address ( ISOURCEPOPUP* popup, size_t address )
327 {
328  popup->vtable->setpcaddress ( popup, 0, address );
329 }
330 
335 void repaint_memory_popup ( IMEMORYPOPUP* popup )
336 {
337  popup->vtable->repaint ( popup, 0 );
338 }
339 
345 void print_to_debug_popup ( IDEBUGPOPUP* popup, const char* message )
346 {
347  popup->vtable->print ( popup, ( char* ) message );
348 }
349 
357 void dump_to_debug_popup ( IDEBUGPOPUP* popup, const uint8_t* buf, uint32_t offset, uint32_t size )
358 {
359  popup->vtable->dump ( popup, 0, buf + offset, size, 16 );
360 }
361 
366 void toggle_pin_state ( VSM_PIN pin )
367 {
368  STATE pinstate = get_pin_state ( pin.pin );
369  if ( SHI == pinstate )
370  {
371  set_pin_state ( pin, SLO );
372  }
373  else if ( SLO == pinstate )
374  {
375  set_pin_state ( pin, SHI );
376  }
377 }
378 
384 STATE get_pin_state ( IDSIMPIN* pin )
385 {
386  return pin->vtable->istate ( pin, 0 );
387 }
388 
394 inline int32_t get_pin_bool ( VSM_PIN pin)
395 {
396  STATE pinstate = pin.pin->vtable->istate ( pin.pin, 0 );
397  if ( SLO == pinstate || WLO == pinstate || ILO == pinstate || PLO == pinstate)
398  {
399  return 0;
400  }
401  else if ( SHI == pinstate || WHI == pinstate || IHI == pinstate || PHI == pinstate)
402  {
403  return 1;
404  }
405  return -1;
406 }
407 
413 bool is_pin_active ( IDSIMPIN* pin )
414 {
415  return pin->vtable->isactive ( pin, 0 );
416 }
417 
423 bool is_pin_posedge ( IDSIMPIN* pin )
424 {
425  return pin->vtable->isposedge ( pin, 0 );
426 }
427 
433 bool is_pin_negedge ( IDSIMPIN* pin )
434 {
435  return pin->vtable->isnegedge ( pin, 0 );
436 }
437 
443 bool is_pin_edge ( IDSIMPIN* pin )
444 {
445  return pin->vtable->isedge ( pin, 0 );
446 }
447 
453 void set_callback ( RELTIME picotime, EVENTID id )
454 {
455  model_dsim->vtable->setcallback ( model_dsim, 0, picotime, &VSM_DEVICE, id );
456 }
457 
462 void out_log ( const char* format, ... )
463 {
464  char* string;
465  va_list args;
466  va_start ( args, format );
467  if ( 0 > vasprintf ( &string, ( char* ) format, args ) ) string = NULL;
468  va_end ( args );
469  model_instance->vtable->log ( model_instance, string );
470  free ( string );
471 }
472 
477 void out_message ( const char* format, ... )
478 {
479  char* string;
480  va_list args;
481  va_start ( args, format );
482  if ( 0 > vasprintf ( &string, ( char* ) format, args ) ) string = NULL;
483  va_end ( args );
484  model_instance->vtable->message ( model_instance, string );
485  free ( string );
486 }
487 
492 void out_warning ( const char* format, ... )
493 {
494  char* string;
495  va_list args;
496  va_start ( args, format );
497  if ( 0 > vasprintf ( &string, ( char* ) format, args ) ) string = NULL;
498  va_end ( args );
499  model_instance->vtable->warning ( model_instance, string );
500  free ( string );
501 }
502 
507 void out_error ( const char* format, ... )
508 {
509  char* string;
510  va_list args;
511  va_start ( args, format );
512  if ( 0 > vasprintf ( &string, ( char* ) format, args ) ) string = NULL;
513  va_end ( args );
514  model_instance->vtable->error ( model_instance, string );
515  free ( string );
516 }
517 
523 IDSIMPIN* get_pin ( char* pin_name )
524 {
525  return model_instance->vtable->getdsimpin ( model_instance, 0, pin_name, TRUE );
526 }
527 
533 bool is_pin_low ( IDSIMPIN* pin )
534 {
535  return islow ( pin->vtable->istate ( pin, 0 ) );
536 }
537 
543 bool is_pin_high ( IDSIMPIN* pin )
544 {
545  return ishigh ( pin->vtable->istate ( pin, 0 ) );
546 }
547 
553 bool is_pin_floating ( IDSIMPIN* pin )
554 {
555  return isfloating ( pin->vtable->istate ( pin, 0 ) );
556 }
557 
563 bool is_pin_steady ( IDSIMPIN* pin )
564 {
565  return pin->vtable->issteady ( pin, 0 );
566 }
567 
573 inline bool islow ( STATE pinstate )
574 {
575  return ( pinstate & SP_MASK ) == SP_LOW;
576 }
577 inline bool
578 ishigh ( STATE pinstate )
579 {
580  return ( pinstate & SP_MASK ) == SP_HIGH;
581 }
582 inline bool
583 isfloating ( STATE pinstate )
584 {
585  return ( pinstate & SP_MASK ) == SP_FLOAT;
586 }
587 inline bool
588 iscontention ( STATE pinstate )
589 {
590  return pinstate & SF_CONTENTION;
591 }
592 inline bool
593 isdefined ( STATE pinstate )
594 {
595  return pinstate != SP_UNDEFINED;
596 }
597 inline bool
598 ishighlow ( STATE pinstate )
599 {
600  return pinstate & 1;
601 }
602 inline INT
603 polarity ( STATE pinstate )
604 {
605  return pinstate & SP_MASK;
606 }
607 inline INT
608 strength ( STATE pinstate )
609 {
610  return pinstate & SS_MASK;
611 }
612 
bool is_pin_posedge(IDSIMPIN *pin)
Definition: c_bind.c:423
void toggle_pin_state(VSM_PIN pin)
Definition: c_bind.c:366
bool is_pin_steady(IDSIMPIN *pin)
Definition: c_bind.c:563
IDEBUGPOPUP * create_source_popup(const char *title, const int32_t id)
Definition: c_bind.c:223
int64_t get_init_param(char *field_name)
Definition: c_bind.c:151
STATE get_pin_state(IDSIMPIN *pin)
Definition: c_bind.c:384
bool is_pin_edge(IDSIMPIN *pin)
Definition: c_bind.c:443
bool is_pin_active(IDSIMPIN *pin)
Definition: c_bind.c:413
void set_memory_popup(IMEMORYPOPUP *popup, size_t offset, void *buffer, size_t size)
Definition: c_bind.c:293
bool is_pin_low(IDSIMPIN *pin)
Definition: c_bind.c:533
void set_pin_state(VSM_PIN pin, STATE state)
Definition: c_bind.c:76
void out_message(const char *format,...)
Definition: c_bind.c:477
IPOPUP * create_popup(CREATEPOPUPSTRUCT *cps)
Definition: c_bind.c:172
bool vsm_register(ILICENCESERVER *ils)
Definition: c_bind.c:61
void out_error(const char *format,...)
Definition: c_bind.c:507
void print_to_debug_popup(IDEBUGPOPUP *popup, const char *message)
Definition: c_bind.c:345
void out_warning(const char *format,...)
Definition: c_bind.c:492
int32_t get_pin_bool(VSM_PIN pin)
Definition: c_bind.c:394
int32_t get_hex_param(char *field_name)
Definition: c_bind.c:141
void set_pc_address(ISOURCEPOPUP *popup, size_t address)
Definition: c_bind.c:326
void delete_popup(POPUPID id)
Definition: c_bind.c:281
bool get_bool_param(char *field_name)
Definition: c_bind.c:119
IDEBUGPOPUP * create_debug_popup(const char *title, const int32_t id)
Definition: c_bind.c:203
char * get_string_param(char *field_name)
Definition: c_bind.c:109
void dump_to_debug_popup(IDEBUGPOPUP *popup, const uint8_t *buf, uint32_t offset, uint32_t size)
Definition: c_bind.c:357
bool add_source_file(ISOURCEPOPUP *popup, char *filename, bool lowlevel)
Definition: c_bind.c:305
IDEBUGPOPUP * create_var_popup(const char *title, const int32_t id)
Definition: c_bind.c:263
bool set_vdm_handler(void)
Definition: c_bind.c:316
IDSIMPIN * get_pin(char *pin_name)
Definition: c_bind.c:523
bool is_pin_floating(IDSIMPIN *pin)
Definition: c_bind.c:553
IDEBUGPOPUP * create_status_popup(const char *title, const int32_t id)
Definition: c_bind.c:243
void systime(ABSTIME *at)
Definition: c_bind.c:99
void set_callback(RELTIME picotime, EVENTID id)
Definition: c_bind.c:453
bool is_pin_high(IDSIMPIN *pin)
Definition: c_bind.c:543
bool islow(STATE pinstate)
Definition: c_bind.c:573
void load_image(char *filename, uint8_t *buffer, size_t buffer_size)
Definition: c_bind.c:162
IMEMORYPOPUP * create_memory_popup(const char *title, const int32_t id)
Definition: c_bind.c:183
void set_pin_bool(VSM_PIN pin, bool level)
Definition: c_bind.c:88
const char * state_to_string(STATE pinstate)
[Convert pin state to string]
Definition: c_bind.c:17
void repaint_memory_popup(IMEMORYPOPUP *popup)
Definition: c_bind.c:335
double get_num_param(char *field_name)
Definition: c_bind.c:129
int popup_id
Global pop identificator. Should be unique.
Definition: c_bind.c:54
void out_log(const char *format,...)
Definition: c_bind.c:462
bool is_pin_negedge(IDSIMPIN *pin)
Definition: c_bind.c:433