OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [orpsocv2/] [bench/] [verilog/] [vpi/] [c/] [jp_vpi.c] - Diff between revs 40 and 46

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 40 Rev 46
Line 215... Line 215...
void return_response();
void return_response();
 
 
 
 
#include <time.h>
#include <time.h>
 
 
int vpi_to_rsp_pipe[2]; // [0] - read, [1] - write
uint32_t vpi_to_rsp_pipe[2]; // [0] - read, [1] - write
int rsp_to_vpi_pipe[2]; // [0] - read, [1] - write
uint32_t rsp_to_vpi_pipe[2]; // [0] - read, [1] - write
int command_pipe[2]; // RSP end writes, VPI end reads ONLY
uint32_t command_pipe[2]; // RSP end writes, VPI end reads ONLY
 
 
/* Global static to store the child rsp server PID if we want to kill it */
/* Global static to store the child rsp server PID if we want to kill it */
static pid_t rsp_server_child_pid = (pid_t) 0; // pid_t is just a signed int
static pid_t rsp_server_child_pid = (pid_t) 0; // pid_t is just a signed int
 
 
 
 
Line 280... Line 280...
 
 
  // Fork. Let the child run the RSP server
  // Fork. Let the child run the RSP server
  pid_t pid;
  pid_t pid;
  int rv;
  int rv;
 
 
  if(DBG_ON) printf("jp_vpi: init_rsp_server\n");
  if(DBG_JP_VPI) printf("jp_vpi: init_rsp_server\n");
 
 
  // Setup pipes
  // Setup pipes
  if(pipe(vpi_to_rsp_pipe) == -1)
  if(pipe(vpi_to_rsp_pipe) == -1)
    {
    {
      perror("jp_vpi: init_rsp_server pipes");
      perror("jp_vpi: init_rsp_server pipes");
Line 378... Line 378...
      break;
      break;
    case 0x6 :
    case 0x6 :
      printf("  CPU reg read\n");
      printf("  CPU reg read\n");
      break;
      break;
    case 0x7 :
    case 0x7 :
      printf("  WB write 32\n");
      printf("  WB write\n");
      break;
      break;
    case 0x8 :
    case 0x8 :
      printf("  WB read 32\n");
      printf("  WB read 32\n");
      break;
      break;
    case 0x9 :
    case 0x9 :
Line 412... Line 412...
 
 
  int n;
  int n;
 
 
  unsigned char data;
  unsigned char data;
 
 
  //if(DBG_ON) printf("check_for_command\n");
  //if(DBG_JP_VPI) printf("check_for_command\n");
 
 
  //n = read(rsp_to_vpi_pipe[0], &data, 1);
  //n = read(rsp_to_vpi_pipe[0], &data, 1);
 
 
  n = read(command_pipe[0], &data, 1);
  n = read(command_pipe[0], &data, 1);
 
 
Line 431... Line 431...
      perror("check_for_command");
      perror("check_for_command");
 
 
      exit(1);
      exit(1);
    }
    }
 
 
  if (DBG_ON)
  if (DBG_JP_VPI)
  {
  {
    printf("jp_vpi: c = %x:",data);
    printf("jp_vpi: c = %x:",data);
    print_command_string(data);
    print_command_string(data);
    fflush(stdout);
    fflush(stdout);
  }
  }
Line 455... Line 455...
  argval.format = vpiIntVal;
  argval.format = vpiIntVal;
 
 
  // Now set the command value
  // Now set the command value
  vpi_get_value(argh, &argval);
  vpi_get_value(argh, &argval);
 
 
  argval.value.integer = (unsigned int) data;
  argval.value.integer = (uint32_t) data;
 
 
  // And vpi_put_value() it back into the sim
  // And vpi_put_value() it back into the sim
  vpi_put_value(argh, &argval, NULL, vpiNoDelay);
  vpi_put_value(argh, &argval, NULL, vpiNoDelay);
 
 
  // Cleanup and return
  // Cleanup and return
  vpi_free_object(args_iter);
  vpi_free_object(args_iter);
 
 
  n = write(vpi_to_rsp_pipe[1],&data,1);
  n = write(vpi_to_rsp_pipe[1],&data,1);
  if (DBG_ON) printf("jp_vpi: r");
  if (DBG_JP_VPI) printf("jp_vpi: r");
 
 
  if (DBG_ON) printf("\n");
  if (DBG_JP_VPI) printf("\n");
 
 
  return;
  return;
}
}
 
 
void get_command_address(char *userdata){
void get_command_address(char *userdata){
Line 481... Line 481...
 
 
  int value,i;
  int value,i;
 
 
  int n;
  int n;
 
 
  unsigned int data;
  uint32_t data;
 
 
  char* recv_buf;
  char* recv_buf;
 
 
  recv_buf = (char *) &data; // cast data as our receive char buffer
  recv_buf = (char *) &data; // cast data as our receive char buffer
 
 
Line 495... Line 495...
      //client has closed connection
      //client has closed connection
      //attempt to close and return gracefully
      //attempt to close and return gracefully
      return;
      return;
    }
    }
 
 
  if (DBG_ON) printf("jp_vpi: get_command_address adr=0x%.8x\n",data);
  if (DBG_JP_VPI) printf("jp_vpi: get_command_address adr=0x%.8x\n",data);
 
 
  // now put the address into the argument passed to the task
  // now put the address into the argument passed to the task
 
 
  // Obtain a handle to the argument list
  // Obtain a handle to the argument list
  systfref = vpi_handle(vpiSysTfCall, NULL);
  systfref = vpi_handle(vpiSysTfCall, NULL);
Line 513... Line 513...
  // now store the command value back in the sim
  // now store the command value back in the sim
  argval.format = vpiIntVal;
  argval.format = vpiIntVal;
 
 
  // Now set the address value
  // Now set the address value
  vpi_get_value(argh, &argval);
  vpi_get_value(argh, &argval);
  argval.value.integer = (unsigned int) data;
  argval.value.integer = (uint32_t) data;
 
 
  // And vpi_put_value() it back into the sim
  // And vpi_put_value() it back into the sim
  vpi_put_value(argh, &argval, NULL, vpiNoDelay);
  vpi_put_value(argh, &argval, NULL, vpiNoDelay);
 
 
  // Cleanup and return
  // Cleanup and return
Line 535... Line 535...
 
 
  int value,i;
  int value,i;
 
 
  int n = 0;
  int n = 0;
 
 
  unsigned int data;
  uint32_t data;
 
 
  char* recv_buf;
  char* recv_buf;
 
 
  recv_buf = (char *) &data; // cast data as our receive char buffer
  recv_buf = (char *) &data; // cast data as our receive char buffer
 
 
Line 551... Line 551...
  else if (n < 4)
  else if (n < 4)
    {
    {
      printf("jp_vpi: get_command_data errno: %d\n",errno);
      printf("jp_vpi: get_command_data errno: %d\n",errno);
      perror("jp_vpi: get_command_data read failed");
      perror("jp_vpi: get_command_data read failed");
    }
    }
  if (DBG_ON) printf("jp_vpi: get_command_data = 0x%.8x\n",data);
  if (DBG_JP_VPI) printf("jp_vpi: get_command_data = 0x%.8x\n",data);
 
 
  // Obtain a handle to the argument list
  // Obtain a handle to the argument list
  systfref = vpi_handle(vpiSysTfCall, NULL);
  systfref = vpi_handle(vpiSysTfCall, NULL);
 
 
  // Now call iterate with the vpiArgument parameter
  // Now call iterate with the vpiArgument parameter
Line 567... Line 567...
  // now store the command value back in the sim
  // now store the command value back in the sim
  argval.format = vpiIntVal;
  argval.format = vpiIntVal;
 
 
  // Now set the data value
  // Now set the data value
  vpi_get_value(argh, &argval);
  vpi_get_value(argh, &argval);
  argval.value.integer = (unsigned int) data;
  argval.value.integer = (uint32_t) data;
 
 
  // And vpi_put_value() it back into the sim
  // And vpi_put_value() it back into the sim
  vpi_put_value(argh, &argval, NULL, vpiNoDelay);
  vpi_put_value(argh, &argval, NULL, vpiNoDelay);
 
 
  // Cleanup and return
  // Cleanup and return
Line 590... Line 590...
 
 
  int value,i;
  int value,i;
 
 
  int n;
  int n;
 
 
  unsigned int data;
  uint32_t data;
  unsigned int length;
  uint32_t length;
 
 
  char* recv_buf;
  char* recv_buf;
 
 
  // Now setup the handles to verilog objects and check things
  // Now setup the handles to verilog objects and check things
  // Obtain a handle to the argument list
  // Obtain a handle to the argument list
Line 615... Line 615...
  // now set length
  // now set length
  length = argval.value.integer;
  length = argval.value.integer;
 
 
  int num_words = length/4;
  int num_words = length/4;
 
 
  if((length % 4) != 0) vpi_printf("length of %d bytes is not exactly word-aligned\n",length);
  //if((length % 4) != 0) vpi_printf("length of %d bytes is not exactly word-aligned\n",length);
  // If non-word aligned we throw away remainder
  // If non-word aligned we throw away remainder
  int throw_away_bytes = length %4;
  int throw_away_bytes = length %4;
 
 
  int loaded_words = 0;
  int loaded_words = 0;
 
 
  if(DBG_ON)printf("jp_vpi: get_command_block_data: length=%d, num_words=%d\n",length,num_words);
  if(DBG_JP_VPI)printf("jp_vpi: get_command_block_data: length=%d, num_words=%d\n",length,num_words);
 
 
  // now get a handle on the next object (memory array)
  // now get a handle on the next object (memory array)
  argh = vpi_scan(args_iter);
  argh = vpi_scan(args_iter);
 
 
  // check we got passed a memory (array of regs)
  // check we got passed a memory (array of regs)
Line 656... Line 656...
    // now get a handle on the current word we want in the array that was passed to us
    // now get a handle on the current word we want in the array that was passed to us
    array_word = vpi_handle_by_index(argh, loaded_words);
    array_word = vpi_handle_by_index(argh, loaded_words);
 
 
    if (array_word != NULL)
    if (array_word != NULL)
      {
      {
        argval.value.integer = (unsigned int) data;
        argval.value.integer = (uint32_t) data;
 
 
        // And vpi_put_value() it back into the sim
        // And vpi_put_value() it back into the sim
        vpi_put_value(array_word, &argval, NULL, vpiNoDelay);
        vpi_put_value(array_word, &argval, NULL, vpiNoDelay);
      }
      }
    else
    else
Line 710... Line 710...
  argval.format = vpiIntVal;
  argval.format = vpiIntVal;
 
 
  // Now set the data value
  // Now set the data value
  vpi_get_value(argh, &argval);
  vpi_get_value(argh, &argval);
 
 
  data = (unsigned int) argval.value.integer;
  data = (uint32_t) argval.value.integer;
 
 
  // Cleanup and return
  // Cleanup and return
  vpi_free_object(args_iter);
  vpi_free_object(args_iter);
 
 
  if (DBG_ON) printf("jp_vpi: return_command_data 0x%.8x\n",data);
  if (DBG_JP_VPI) printf("jp_vpi: return_command_data 0x%.8x\n",data);
 
 
  send_buf = (char *) &data; //cast our long as a char buf
  send_buf = (char *) &data; //cast our long as a char buf
 
 
  // write the data back
  // write the data back
  n = write(vpi_to_rsp_pipe[1],send_buf,4);
  n = write(vpi_to_rsp_pipe[1],send_buf,4);
Line 736... Line 736...
 
 
  int value,i;
  int value,i;
 
 
  int n;
  int n;
 
 
  unsigned int data;
  uint32_t data;
  unsigned int length;
  uint32_t length;
 
 
 
  char *block_data_buf;
 
  uint32_t *block_word_data_buf_ptr;
 
 
  char* recv_buf;
  int num_words;
 
  int sent_words = 0;
 
 
 
  vpiHandle array_word;
 
 
  // Now setup the handles to verilog objects and check things
  // Now setup the handles to verilog objects and check things
  // Obtain a handle to the argument list
  // Obtain a handle to the argument list
  systfref = vpi_handle(vpiSysTfCall, NULL);
  systfref = vpi_handle(vpiSysTfCall, NULL);
 
 
Line 769... Line 775...
    {
    {
      vpi_printf("jp_vpi: ERROR: did not pass a memory to return_command_block_data\n");
      vpi_printf("jp_vpi: ERROR: did not pass a memory to return_command_block_data\n");
      return;
      return;
    }
    }
 
 
  vpiHandle array_word;
  // We have to alloc memory here for lengths > 4
 
  if (length > 4);
 
  {
 
    block_data_buf = (char*) malloc(length * sizeof(char));
 
    if (block_data_buf == NULL)
 
      {
 
        vpi_printf("jp_vpi: return_command_block_data: Error. Could not allocate memory\n");
 
        // Cleanup and return
 
        vpi_free_object(args_iter);
 
        return;
 
      }
 
 
  int num_words = length/4;
    // Now cast it as a uint32_t array
 
    block_word_data_buf_ptr = (uint32_t *) block_data_buf;
 
  }
 
 
  int sent_words = 0;
  num_words = length / 4; // We're always going to be dealing with whole words here
 
 
 
  if (DBG_JP_VPI) printf("jp_vpi: return_command_block_data: num_words %d\n",
 
                         num_words);
 
 
  // Loop to load the words
  // Loop to load the words
  while (sent_words < num_words) {
  while (sent_words < num_words) {
 
 
    // now get a handle on the current word we want in the array that was passed to us
    // Get a handle on the current word we want in the array that was passed to us
    array_word = vpi_handle_by_index(argh, sent_words);
    array_word = vpi_handle_by_index(argh, sent_words);
 
 
    if (array_word != NULL)
    if (array_word != NULL)
      {
      {
        vpi_get_value(array_word, &argval);
        vpi_get_value(array_word, &argval);
 
 
        data = (unsigned int) argval.value.integer;
        data = (uint32_t) argval.value.integer;
 
 
 
        block_word_data_buf_ptr[sent_words] = data;
      }
      }
    else
    else
      return;
      return;
 
 
    recv_buf = (char *) &data;
    if (DBG_JP_VPI) printf ( "jp_vpi: return_command_block_data: word %d 0x%.8x\n",
 
                             sent_words, data);
 
    sent_words++;
 
  }
 
 
    n = write(vpi_to_rsp_pipe[1],recv_buf,4);
  if (!(length > 4))
 
    {
 
      block_data_buf = (char *) &data;
 
    }
 
 
    sent_words++;
  n = write(vpi_to_rsp_pipe[1],block_data_buf,length);
 
 
 
 
 
  if (length > 4)
 
    {
 
      // Free the array
 
      free(block_data_buf);
  }
  }
 
 
 
 
  // Cleanup and return
  // Cleanup and return
  vpi_free_object(args_iter);
  vpi_free_object(args_iter);
 
 
  return;
  return;
 
 
Line 816... Line 851...
  char resp = 0;
  char resp = 0;
 
 
  // send a response byte
  // send a response byte
  n = write(vpi_to_rsp_pipe[1],&resp,1);
  n = write(vpi_to_rsp_pipe[1],&resp,1);
 
 
  if (DBG_ON) printf("jp_vpi: ret\n\n");
  if (DBG_JP_VPI) printf("jp_vpi: ret\n\n");
 
 
  return;
  return;
 
 
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.