summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrahul2019-09-26 15:21:18 +0530
committerrahul2019-09-26 15:21:18 +0530
commit7852873cf0bc8b8082ea847a868ab84930163667 (patch)
treed649b84d09ad7b6017c5439bef0c6112ce525b84 /src
parente43b6221138d30d9b2ea37c708c9521d4ba926af (diff)
downloadnghdl-7852873cf0bc8b8082ea847a868ab84930163667.tar.gz
nghdl-7852873cf0bc8b8082ea847a868ab84930163667.tar.bz2
nghdl-7852873cf0bc8b8082ea847a868ab84930163667.zip
multiple instances (static ip)
Diffstat (limited to 'src')
-rwxr-xr-xsrc/ghdlserver/Vhpi_Package.vhdl7
-rw-r--r--src/ghdlserver/ghdlserver.c65
-rw-r--r--src/ghdlserver/ghdlserver.h2
-rw-r--r--src/model_generation.py87
-rw-r--r--src/outitf.c32
5 files changed, 77 insertions, 116 deletions
diff --git a/src/ghdlserver/Vhpi_Package.vhdl b/src/ghdlserver/Vhpi_Package.vhdl
index 0c0baac..5d3db8d 100755
--- a/src/ghdlserver/Vhpi_Package.vhdl
+++ b/src/ghdlserver/Vhpi_Package.vhdl
@@ -1,4 +1,7 @@
-- author: Madhav P. Desai
+-- modified: Rahul Paknikar
+-- (changed definition of Vhpi_Initialize)
+
library ieee;
use ieee.std_logic_1164.all;
library work;
@@ -8,7 +11,7 @@ package Vhpi_Foreign is
-----------------------------------------------------------------------------
-- foreign Vhpi function
-----------------------------------------------------------------------------
- procedure Vhpi_Initialize(sock_port : in integer);
+ procedure Vhpi_Initialize(sock_port : in integer; sock_ip : in VhpiString);
attribute foreign of Vhpi_Initialize : procedure is "VHPIDIRECT Vhpi_Initialize";
procedure Vhpi_Close; -- close .
@@ -36,7 +39,7 @@ package body Vhpi_Foreign is
-----------------------------------------------------------------------------
-- subprogram bodies for foreign vhpi routines. will never be called
-----------------------------------------------------------------------------
- procedure Vhpi_Initialize(sock_port: in integer) is
+ procedure Vhpi_Initialize(sock_port: in integer; sock_ip : in VhpiString) is
begin
assert false report "fatal: this should never be called" severity failure;
end Vhpi_Initialize;
diff --git a/src/ghdlserver/ghdlserver.c b/src/ghdlserver/ghdlserver.c
index 622c246..0c1a683 100644
--- a/src/ghdlserver/ghdlserver.c
+++ b/src/ghdlserver/ghdlserver.c
@@ -1,6 +1,6 @@
/********************************************************************************
* <ghdlserver.c> FOSSEE, IIT-Bombay
- * 18.Sept.2019 - Rahul Paknikar - Added reading of IP from a file to
+ * 26.Sept.2019 - Rahul Paknikar - Added reading of IP from a file to
* support multiple digital models
* - Reads the ip set by its client to map
* with the same socket with the name of file
@@ -10,6 +10,7 @@
* by its client (cfunc) and stored in /tmp
* directory. It tracks the used IPs for existing
* digital models in current simulation.
+ * - Write PID file in append mode.
* 5.July.2019 - Rahul Paknikar - Added loop to send all port values for
* a given event.
* - Removed bug to terminate multiple testbench
@@ -153,7 +154,7 @@ static void create_pid_file(int sock_port)
sprintf(pid_filename, "/tmp/NGHDL_%d_%s_%d", ngspice_pid, __progname,
sock_port);
- pid_file = fopen(pid_filename, "w");
+ pid_file = fopen(pid_filename, "a"); // 26.Sept.2019 - RP
if (pid_file)
{
pid_file_created = 1;
@@ -234,8 +235,8 @@ static void parse_buffer(int sock_id, char* receive_buffer)
//
//Create Server and listen for client connections.
-//
-static int create_server(int port_number, int max_connections)
+// 26.Sept.2019 - RP - added parameter of socket ip
+static int create_server(int port_number, char my_ip[], int max_connections)
{
int sockfd, reuse = 1;
struct sockaddr_in serv_addr;
@@ -256,29 +257,9 @@ static int create_server(int port_number, int max_connections)
syslog(LOG_ERR, "create_server:setsockopt() failed....");
}
-/* 18.Sept.2019 - RP - Read and set IP of server decided by its client */
- char ip_filename[80];
- sprintf(ip_filename, "NGHDL_IP.txt");
-
- char lo_ip[20];
-
- FILE* fp = fopen(ip_filename, "r");
-
- if (fp)
- {
- if (fscanf(fp, "%s", lo_ip) != EOF)
- {
- fclose(fp);
- }
- } else {
- perror("fopen() - NGHDL_IP file");
- syslog(LOG_ERR, "create_server(): Unable to open NGHDL_IP file in /tmp");
- exit(1);
- }
-
bzero((char *) &serv_addr, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
- serv_addr.sin_addr.s_addr = inet_addr(lo_ip); // 18.Sept.2019 - RP - Bind to specific IP only
+ serv_addr.sin_addr.s_addr = inet_addr(my_ip); // 26.Sept.2019 - RP - Bind to specific IP only
serv_addr.sin_port = htons(port_number);
if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0)
@@ -506,7 +487,8 @@ static void Data_Send(int sockid)
}
-void Vhpi_Initialize(int sock_port)
+// 26.Sept.2019 - RP - added parameter of socket ip
+void Vhpi_Initialize(int sock_port, char sock_ip[])
{
DEFAULT_SERVER_PORT = sock_port;
@@ -519,8 +501,9 @@ void Vhpi_Initialize(int sock_port)
while(try_limit > 0)
{
- // 18.Sept.2019 - RP
- server_socket_id = create_server(DEFAULT_SERVER_PORT, DEFAULT_MAX_CONNECTIONS);
+
+ // 26.Sept.2019 - RP
+ server_socket_id = create_server(DEFAULT_SERVER_PORT, sock_ip, DEFAULT_MAX_CONNECTIONS);
if(server_socket_id > 0)
{
syslog(LOG_INFO,"Started the server on port %d SRV:%d",
@@ -648,30 +631,7 @@ void Vhpi_Listen()
void Vhpi_Send()
{
- int sockid;
- char* out;
-
-// Traverse the list of finished jobs and send out the resulting port values..
// 22.Feb.2017 - RM - Kludge
-// log_server=fopen("server.log","a");
-// fprintf(log_server, "%s Vhpi_Send() called\n", curtim());
-
-// fprintf(log_server,"Vhpi_Send()-------------------\n");
-// print_hash_table();
-// fprintf(log_server,"----------------------------------------\n");
-// HASH_FIND_STR(users,"sock_id",s);
-// if(s)
-// {
-// sockid=atoi(s->val);
-// }
-// else
-// {
-// fprintf(log_server,"%s Socket id not in table - key=%s val=%s\n",
-// curtim(),
-// users->key, users->val);
-// }
-// Data_Send(sockid);
-
if (prev_sendto_sock != sendto_sock)
{
Data_Send(sendto_sock);
@@ -696,8 +656,7 @@ void Vhpi_Exit(int sig)
remove(pid_filename);
}
- // 18.Sept.2019 - RP
- remove("NGHDL_IP.txt");
+ // 26.Sept.2019 - RP
remove("/tmp/NGHDL_COMMON_IP.txt");
syslog(LOG_INFO, "*** Exiting ***");
diff --git a/src/ghdlserver/ghdlserver.h b/src/ghdlserver/ghdlserver.h
index 9dc8afc..082a1af 100644
--- a/src/ghdlserver/ghdlserver.h
+++ b/src/ghdlserver/ghdlserver.h
@@ -21,7 +21,7 @@
int DEFAULT_SERVER_PORT;
//Vhpi Functions.
-void Vhpi_Initialize(int sock_port);
+void Vhpi_Initialize(int sock_port, char sock_ip[]); /* 26.Sept.2019 - RP */
void Vhpi_Close();
void Vhpi_Exit();
void Vhpi_Listen();
diff --git a/src/model_generation.py b/src/model_generation.py
index 40a4b4a..4e986f6 100644
--- a/src/model_generation.py
+++ b/src/model_generation.py
@@ -239,7 +239,7 @@ client_setup_ip='''
/* Client Setup IP Addr */
FILE *fptr;
int ip_count = 0;
- char my_ip[20];
+ char* my_ip = malloc(16);
fptr = fopen("/tmp/NGHDL_COMMON_IP.txt", "r");
if (fptr)
@@ -268,43 +268,15 @@ client_setup_ip='''
exit(1);
}
-
- char ip_filename[300];
-'''
-client_setup_ip +='sprintf(ip_filename,"'+home+'/ngspice-nghdl/src/xspice/icm/ghdl/'+fname.split('.')[0]+'/DUTghdl/NGHDL_IP.txt");'
-client_setup_ip +='''
- fptr = fopen(ip_filename, "w");
- if(fptr)
- {
- fprintf(fptr, "%s\\n", my_ip);
- fclose(fptr);
- } else {
- perror("fopen() - IP file");
- exit(1);
- }
+ STATIC_VAR(my_ip) = my_ip;
'''
client_fetch_ip='''
/* Client Fetch IP Addr */
- char lo_ip[20];
- char ip_filename[300];
-'''
-client_fetch_ip +='sprintf(ip_filename,"'+home+'/ngspice-nghdl/src/xspice/icm/ghdl/'+fname.split('.')[0]+'/DUTghdl/NGHDL_IP.txt");\n'
-client_fetch_ip +='''
- FILE* fp = fopen(ip_filename, "r");
- if (fp)
- {
- if (fscanf(fp, "%s", lo_ip) != EOF)
- {
- fclose(fp);
- }
- } else {
- perror("fopen() - NGHDL_IP file");
- exit(1);
- }
-
- host = gethostbyname(lo_ip);
+ char* my_ip = STATIC_VAR(my_ip);
+
+ host = gethostbyname(my_ip);
printf("Client-Creating Client Socket \\n");
fprintf(log_client,"Creating client socket \\n");
'''
@@ -543,7 +515,7 @@ cfunc.write("\n")
cfunc.write(client_setup_ip)
cfunc.write("\n")
cfunc.write("\t\tchar command[1024];\n")
-cfunc.write('\t\tsnprintf(command,1024,"'+home+'/ngspice-nghdl/src/xspice/icm/ghdl/'+fname.split('.')[0]+'/DUTghdl/start_server.sh %d &",sock_port);\n')
+cfunc.write('\t\tsnprintf(command,1024,"'+home+'/ngspice-nghdl/src/xspice/icm/ghdl/'+fname.split('.')[0]+'/DUTghdl/start_server.sh %d %s &",sock_port, my_ip);')
cfunc.write('\t\tsystem(command);')
cfunc.write("\n\t}")
cfunc.write("\n")
@@ -669,6 +641,16 @@ Null_Allowed: yes no
'''
+static__table='''
+
+STATIC_VAR_TABLE:
+
+Static_Var_Name: my_ip
+Data_Type: pointer
+Description: "connect to ghdlserver through this ip"
+
+'''
+
#Writing all the content in ifspec file
ifspec.write(ifspec_comment)
@@ -684,6 +666,8 @@ for item in out_port_table:
ifspec.write("\n")
ifspec.write(parameter_table)
+ifspec.write("\n")
+ifspec.write(static_table)
ifspec.close()
@@ -693,7 +677,9 @@ print "Starting with testbench file"
testbench=open(fname.split('.')[0]+'_tb.vhdl','w')
print fname.split('.')[0] + '_tb.vhdl'
#comment
-comment_vhdl="--------------------------------------------------------------------------------\n--This testbench has been created by Ambikeshwar Srivastava, FOSSEE, IIT Bombay\n-------------------------------------------------------------------------------"
+comment_vhdl="--------------------------------------------------------------------------------\n--This testbench has been created by Ambikeshwar Srivastava, FOSSEE, IIT Bombay\n--------------------------------------------------------------------------------\n"
+comment_vhdl+="--------------------------------------------------------------------------------\n--Modified by Rahul Paknikar, FOSSEE, IIT Bombay"
+comment_vhdl+="--retrieves the IP-Addr from sock_pkg and forwards it to the ghdlserver\n--------------------------------------------------------------------------------"
#Adding header, entity and architecture statement
tb_header='''
library ieee;
@@ -799,7 +785,7 @@ map.append("\t\t\t);")
tb_clk= "clk_s <= not clk_s after 5 us;\n\n"
#Adding Process block for Vhpi
process_Vhpi=[]
-process_Vhpi.append("\tprocess\n\t\tvariable sock_port : integer;\n\t\tbegin\n\t\tsock_port := sock_pkg_fun;\n\t\tVhpi_Initialize(sock_port);\n\t\twait until clk_s = '1';\n\t\twhile true loop\n\t\t\twait until clk_s = '0';\n\t\t\tVhpi_Listen;\n\t\t\twait for 1 us;\n\t\t\tVhpi_Send;\n\t\tend loop;\n\t\twait;\n\tend process;\n\n")
+process_Vhpi.append("\tprocess\n\t\tvariable sock_port : integer;\n\t\ttype string_ptr is access string;\n\t\tvariable sock_ip : string_ptr;\n\t\tbegin\n\t\tsock_port := sock_port_fun;\n\t\tsock_ip := new string'(sock_ip_fun);\n\t\tVhpi_Initialize(sock_port, Pack_String_To_Vhpi_String(sock_ip.all));\n\t\twait until clk_s = '1';\n\t\twhile true loop\n\t\t\twait until clk_s = '0';\n\t\t\tVhpi_Listen;\n\t\t\twait for 1 us;\n\t\t\tVhpi_Send;\n\t\tend loop;\n\t\twait;\n\tend process;\n\n")
#Adding process block
process=[]
process.append("\tprocess\n\n")
@@ -882,12 +868,9 @@ start_server = open('start_server.sh','w')
start_server.write("#!/bin/bash\n\n")
start_server.write("###This server run ghdl testebench for infinite time till ngspice send END signal to stop it\n\n")
-start_server.write("#gcc -c ghdlserver.c\n")
-start_server.write("#ghdl -a Utility_Package.vhdl &&\n")
-start_server.write("#ghdl -a Vhpi_Package.vhdl &&\n")
start_server.write("cd "+home+"/ngspice-nghdl/src/xspice/icm/ghdl/"+fname.split('.')[0]+"/DUTghdl/\n")
start_server.write("chmod 775 sock_pkg_create.sh &&\n")
-start_server.write("./sock_pkg_create.sh $1 &&\n")
+start_server.write("./sock_pkg_create.sh $1 $2 &&\n")
start_server.write("ghdl -a sock_pkg.vhdl &&\n")
start_server.write("ghdl -a "+fname+" &&\n")
start_server.write("ghdl -a "+fname.split('.')[0]+"_tb.vhdl &&\n")
@@ -901,16 +884,24 @@ start_server.close()
sock_pkg_create = open('sock_pkg_create.sh','w')
sock_pkg_create.write("#!/bin/bash\n\n")
-sock_pkg_create.write("##This file create sock_pkg_create.vhdl file and set the instance id from parameter based on parameter\n\n")
+sock_pkg_create.write("##This file creates sock_pkg.vhdl file and sets the port and ip from parameters passed to it\n\n")
sock_pkg_create.write("echo \"library ieee;\n")
sock_pkg_create.write("package sock_pkg is\n")
-sock_pkg_create.write("\tfunction sock_pkg_fun return integer;\n")
+sock_pkg_create.write("\tfunction sock_port_fun return integer;\n")
+sock_pkg_create.write("\tfunction sock_ip_fun return string;\n")
sock_pkg_create.write("end;\n\n")
-sock_pkg_create.write("\tpackage body sock_pkg is\n")
-sock_pkg_create.write("\t function sock_pkg_fun return integer is")
-sock_pkg_create.write("\t\tvariable sock_id : integer;\n")
+sock_pkg_create.write("package body sock_pkg is\n")
+sock_pkg_create.write("\tfunction sock_port_fun return integer is\n")
+sock_pkg_create.write("\t\tvariable sock_port : integer;\n")
+sock_pkg_create.write("\t\t\tbegin\n")
+sock_pkg_create.write("\t\t\t\tsock_port := $1;\n")
+sock_pkg_create.write("\t\t\t\treturn sock_port;\n")
+sock_pkg_create.write("\t\t\tend function;\n\n")
+sock_pkg_create.write("\tfunction sock_ip_fun return string is\n")
+sock_pkg_create.write("\t\ttype string_ptr is access string;\n")
+sock_pkg_create.write("\t\tvariable sock_ip : string_ptr;\n")
sock_pkg_create.write("\t\t\tbegin\n")
-sock_pkg_create.write("\t\t\t\tsock_id := $1;\n")
-sock_pkg_create.write("\t\t\t\treturn sock_id;\n")
-sock_pkg_create.write("\t\t\tend function;\n")
+sock_pkg_create.write('\t\t\t\tsock_ip := new string\'(\\"$2\\");\n')
+sock_pkg_create.write("\t\t\t\treturn sock_ip.all;\n")
+sock_pkg_create.write("\t\t\tend function;\n\n")
sock_pkg_create.write("\t\tend package body;\" > sock_pkg.vhdl") \ No newline at end of file
diff --git a/src/outitf.c b/src/outitf.c
index ce3e910..df22af2 100644
--- a/src/outitf.c
+++ b/src/outitf.c
@@ -100,30 +100,38 @@ static void nghdl_tb_SIGUSR1(char* pid_file)
int ret;
char line[80];
char* nptr;
+ pid_t pid[256], tmp;
+ int count=0, i;
FILE* fp = fopen(pid_file, "r");
if (fp)
{
- if (fscanf(fp, "%s", line) != EOF)
+ while (fscanf(fp, "%s", line) == 1)
+ {
+ // PID is converted to a decimal value.
+ tmp = (pid_t) strtol(line, &nptr, 10);
+ if ((errno != ERANGE) && (errno!= EINVAL))
+ {
+ pid[count++] = tmp;
+ }
+ }
+
+ fclose(fp);
+ }
+
+ for(i=0; i<count; i++)
{
- fclose(fp);
- pid_t pid = (pid_t) strtol(line, &nptr, 10);
- // PID is converted to a decimal value.
- if ((errno != ERANGE) && (errno!= EINVAL))
- {
- if (pid)
+ if (pid[i])
{
- // Check if a process with this pid really exists.
- ret = kill(pid, 0);
+ // Check if a process with this pid really exists.
+ ret = kill(pid[i], 0);
if (ret == 0)
{
- kill(pid, SIGUSR1);
+ kill(pid[i], SIGUSR1);
}
}
- }
}
- }
}
/* 10.Mar.2017 - RM - Added nghdl_orphan_tb().*/