Email: bknpk@hotmail.com Phone: +972-54-7649119

 

ASIC/FPGA Design and Verification Out Source Services

A memory model, for VHDL design, build in c code and Glib.


  1. This code is written with the help of this tutorial as well as on some examples in this web site:
    GHDL c interfaces,
    A very simple example to Manage C data.

  2. This example is made of three files: makefile, vhdl test-bench and c code for memory model.

  3. Makefiles are discussed in this web site and this one follows the same guide lines:
    random number generation.
    GHDL c interfaces.

    As in the former cases the makefile supports run, with and without VCD waves as well as GDB invokation:
    make run
    make run GDB=gdb
    make vcd

    This makefile passes different switches to the compiler and linker:
    GLIBCC = -I/usr/include/glib-2.0 -I/usr/lib/i386-linux-gnu/glib-2.0/include
    GLIBLL = -lglib-2.0
    ...
    EFLAGS = -m -Wl,mem_model.o -Wl,$(GLIBLL)
    ...
    .PHONY : tb_vec
    tb_vec : work-obj93.cf
      $(GG) $(EFLAGS) --workdir=work --ieee=synopsys tb_vec
    ...

  4. The c code uses Glib. Parts of the code is listed below:

    1. ...
    2. #include <glib.h>;
    3. ...
    4. //memory model
    5. typedef struct {
    6.   int addr;
    7.   int data;
    8. } c_mem_model;
    9. GSList* list = NULL;
    10. int mem_arr_44_wr_c(int mem_free, int addr, struct ghdl_string *s) {
    11. ...
    12.   //memory model
    13.   GSList* iterator = NULL;
    14.   c_mem_model* t_mem = NULL;
    15.   //memory free
    16.   if(mem_free == 1) {
    17.     if(g_slist_length(list) > 0) {
    18.       g_slist_free(list);
    19.       g_free(t_mem);
    20.     }
    21.     return 0;
    22.   }
    23. ...
    24.   //update memory
    25.   //if already exists, update.
    26.   for (iterator = list; iterator; iterator = iterator->next) {
    27.     if( ((c_mem_model*)iterator->data)->addr == addr ) {
    28.       flg = 1;
    29.       ((c_mem_model*)iterator->data)->data = res;
    30.       break;
    31.     }
    32.   }
    33.   //new entry
    34.   if(flg == 0) {
    35.     t_mem = g_new(c_mem_model, 1);//allocate
    36.     t_mem->addr = addr;
    37.     t_mem->data = res;
    38.     list = g_slist_append(list, t_mem);
    39.   }
    40. ...

  5. For more info send mail with the subject c code memory model using Glib.