Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
FS-ELAB
pilc2server_old
Commits
63b60d1d
Commit
63b60d1d
authored
Jan 24, 2022
by
Joshua Supra
Browse files
Merge branch 'trash' into 'master'
x See merge request fs-elab/pilc2server!1
parents
108bc676
a6782def
Changes
5
Hide whitespace changes
Inline
Side-by-side
Makefile
View file @
63b60d1d
...
...
@@ -4,7 +4,7 @@
DIR
=
pilc2_functions/
CFLAGS
=
-Wall
-std
=
gnu99
-O0
CFLAGS
=
-Wall
-std
=
gnu99
-O0
-g
LDFLAGS
=
-L
$(DIR)
-lpilc2
-lpthread
-lzmq
-lrt
...
...
main.c
View file @
63b60d1d
...
...
@@ -20,15 +20,16 @@
#include
"pilc2_functions/pilc2_IO_mux.h"
int
thread_nr
;
int
main
(
int
argc
,
char
*
argv
[]){
thread_nr
=
0
;
unsigned
int
front_LED_update_ctr
=
0
;
initContCounterDone
=
0
;
zmq_data
*
zmq_recive_data
[
2
];
int
NrOfBytesReceived
[
2
];
//NrOfBytesReceived[0] = -1;
pilcIOGpioStruct
PilcIoGpios
;
STOP
=
false
;
...
...
@@ -48,79 +49,77 @@ int main (int argc, char *argv[]){
GetIOCards
(
IOCards
);
/* Initalize the network communication */
zmq_recive_data
[
1
]
=
malloc
(
sizeof
(
zmq_data
));
zmq_recive_data
[
1
]
->
data
=
(
unsigned
int
*
)
malloc
(
256
*
sizeof
(
char
));
/* Initalize the network communication */
zmq_recive_data
[
0
]
=
malloc
(
sizeof
(
zmq_data
));
zmq_recive_data
[
0
]
->
data
=
(
unsigned
int
*
)
malloc
(
256
*
sizeof
(
char
));
//zmq_recive_data[0]->NrOfBytes = (unsigned int *) malloc (sizeof(unsigned int));
init_network
();
while
(
1
)
{
while
(
1
)
{
zmq_recive_data
[
0
]
=
malloc
(
sizeof
(
zmq_data
));
zmq_recive_data
[
0
]
->
data
=
(
char
*
)
malloc
(
256
*
sizeof
(
char
));
zmq_recive_data
[
0
]
->
NrOfBytes
=
zmq_recv
(
client_responder
,
while
(
1
)
{
NrOfBytesReceived
[
0
]
=
zmq_recv
(
client_responder
,
zmq_recive_data
[
0
]
->
data
,
255
,
ZMQ_DONTWAIT
);
zmq_recive_data
[
0
]
->
socket
=
client_responder
;
if
(
zmq_r
ecive
_data
[
0
]
->
NrOfBytes
!=
-
1
)
{
//printf("1\n")
;
zmq_recive_data
[
0
]
->
socket
=
client_responder
;
if
(
NrOfBytesR
ec
e
ive
d
[
0
]
!=
-
1
)
{
zmq_recive_data
[
0
]
->
NrOfBytes
=
NrOfBytesReceived
[
0
]
;
pthread_mutex_lock
(
&
lock
);
pthread_create
(
&
thread_network
[
0
],
NULL
,
network
,
(
void
*
)
zmq_recive_data
[
0
]);
pthread_
join
(
thread_network
[
0
],
NULL
);
pthread_mutex_unlock
(
&
lock
);
pthread_create
(
&
thread_network
[
0
],
NULL
,
network
,
(
void
*
)
zmq_recive_data
[
0
]);
pthread_
mutex_unlock
(
&
lock
);
}
else
else
{
break
;
}
}
free
(
zmq_recive_data
[
0
]
->
data
);
free
(
zmq_recive_data
[
0
]);
while
(
1
)
{
zmq_recive_data
[
1
]
=
malloc
(
sizeof
(
zmq_data
));
zmq_recive_data
[
1
]
->
data
=
(
char
*
)
malloc
(
256
*
sizeof
(
char
));
zmq_recive_data
[
1
]
->
NrOfBytes
=
zmq_recv
(
gui_responder
,
zmq_recive_data
[
1
]
->
data
,
255
,
ZMQ_DONTWAIT
);
// NrOfBytesReceived[0] = -1;
NrOfBytesReceived
[
1
]
=
zmq_recv
(
gui_responder
,
zmq_recive_data
[
1
]
->
data
,
255
,
ZMQ_DONTWAIT
);
zmq_recive_data
[
1
]
->
socket
=
gui_responder
;
if
(
zmq_recive_data
[
1
]
->
NrOfBytes
!=
-
1
)
{
if
(
NrOfBytesReceived
[
1
]
!=
-
1
)
{
//printf("2\n");
zmq_recive_data
[
1
]
->
NrOfBytes
=
NrOfBytesReceived
[
1
];
pthread_mutex_lock
(
&
lock
);
pthread_create
(
&
thread_network
[
1
],
NULL
,
network
,
(
void
*
)
zmq_recive_data
[
1
]);
pthread_join
(
thread_network
[
1
],
NULL
);
pthread_mutex_unlock
(
&
lock
);
pthread_mutex_unlock
(
&
lock
);
}
else
else
{
break
;
}
}
if
(
front_LED_update_ctr
==
0
)
{
pthread_create
(
&
thread_led_update
,
NULL
,
updateIOLeds
,
(
void
*
)
IOCards
);
pthread_join
(
thread_led_update
,
NULL
);
front_LED_update_ctr
=
20
;
}
free
(
zmq_recive_data
[
1
]
->
data
);
free
(
zmq_recive_data
[
1
]);
pthread_join
(
thread_network
[
0
],
NULL
);
pthread_join
(
thread_network
[
1
],
NULL
);
pthread_join
(
thread_led_update
,
NULL
);
front_LED_update_ctr
--
;
usleep
(
10000
);
/* debugging */
/*GetIOCardRegister(IOCards);
//PiLC2GetIOCards(NULL);*/
/*for (int i=0; i< 16; i++){
printf("IOCards[%d] : %.8x\n", i, IOCards[i].Register_value);
}*/
//printf("%2.3f \n",getADCvalue(PILC_ADC_DATA_CH_0)*152.588e-6);
//printf("%d \n",getADCvalue(PILC_ADC_DATA_CH_0));
//printf("%.8x \n",ReadFPGA(0x3040>>2));
/*************************/
if
(
STOP
)
{
break
;
}
}
//free(zmq_recive_data[0]->NrOfBytes);
free
(
zmq_recive_data
[
0
]
->
data
);
free
(
zmq_recive_data
[
0
]);
pthread_mutex_destroy
(
&
lock
);
/* Deinit the continous counter mode only when it has been initialized */
...
...
@@ -128,8 +127,11 @@ int main (int argc, char *argv[]){
deinitContCounter
();
}
pthread_join
(
thread_network
[
0
],
NULL
);
free
(
zmq_recive_data
[
1
]
->
data
);
free
(
zmq_recive_data
[
1
]);
deinit_network
();
deinit_IOleds
();
deinitpilc2
();
...
...
@@ -138,34 +140,32 @@ int main (int argc, char *argv[]){
}
void
*
network
(
void
*
args
){
zmq_data
*
zmq_recive_data
=
(
zmq_data
*
)
args
;
zmq_data
*
zmq_rec_data
=
(
zmq_data
*
)
args
;
printf
(
"%i
\n
"
,
zmq_rec_data
->
NrOfBytes
);
unsigned
int
command
;
unsigned
int
nbytes
;
int
status
;
command
=
(
unsigned
int
)
zmq_recive_data
->
data
[
0
];
nbytes
=
zmq_recive_data
->
NrOfBytes
;
//printf("nbytes: 0x%.8x\n", nbytes);
//printf("command: 0x%.8x\n", command);
/*for (int i = 0; i< nbytes; i++){
printf("%.2x ", zmq_recive_data->data[i]);
}
printf("\n");*/
command
=
zmq_rec_data
->
data
[
0
];
//printf("command: %.8x\n", command);
nbytes
=
zmq_rec_data
->
NrOfBytes
;
//printf("%i\n", &zmq_rec_data->NrOfBytes);
switch
(
command
){
case
0x0
:
status
=
RegtoNetwork
(
zmq_rec
ive
_data
);
break
;
case
0x1
:
status
=
NetworktoReg
(
zmq_rec
ive
_data
);
break
;
case
0x2
:
status
=
BurstRegtoNetwork
(
zmq_rec
ive
_data
);
break
;
case
0x3
:
status
=
BurstNetworktoReg
(
zmq_rec
ive
_data
);
break
;
case
0x4
:
status
=
FunctionCall
(
zmq_rec
ive
_data
);
break
;
case
0x0
:
status
=
RegtoNetwork
(
zmq_rec_data
);
break
;
case
0x1
:
status
=
NetworktoReg
(
zmq_rec_data
);
break
;
case
0x2
:
status
=
BurstRegtoNetwork
(
zmq_rec_data
);
break
;
case
0x3
:
status
=
BurstNetworktoReg
(
zmq_rec_data
);
break
;
case
0x4
:
status
=
FunctionCall
(
zmq_rec_data
);
break
;
}
//printf("2\n");
if
(
status
!=
0
){
SendBuffer
[
0
]
=
status
;
SendBuffer
[
1
]
=
0x00
;
nbytes
=
2
;
zmq_send
(
zmq_rec
ive
_data
->
socket
,
SendBuffer
,
nbytes
,
0
);
zmq_send
(
zmq_rec_data
->
socket
,
SendBuffer
,
nbytes
,
0
);
}
pthread_exit
(
NULL
);
}
...
...
pilc2_functions/libpilc2.a
View file @
63b60d1d
No preview for this file type
pilc2_functions/pilc2_network.c
View file @
63b60d1d
...
...
@@ -92,20 +92,20 @@ int BurstNetworktoReg(zmq_data *zmq_data_struct){
unsigned
int
addr32
;
unsigned
int
NrofRegs32
;
int
status
;
unsigned
int
command
=
*
zmq_data_struct
->
data
;
unsigned
int
command
=
zmq_data_struct
->
data
[
0
]
;
unsigned
int
nbytes
=
0
;
unsigned
int
*
receiveBuffer
;
zmq_data_struct
->
data
+=
4
;
addr32
=
*
(
unsigned
int
*
)
zmq_data_struct
->
data
;
addr32
=
zmq_data_struct
->
data
[
1
];
/* check if the start address is valid */
status
=
CheckValidBaseAddr
(
addr32
);
if
(
status
!=
0
)
{
return
status
;
}
zmq_data_struct
->
data
+=
4
;
NrofRegs32
=
*
(
unsigned
int
*
)
zmq_data_struct
->
data
;
NrofRegs32
=
zmq_data_struct
->
data
[
2
]
;
/* check if the address range is valid */
status
=
CheckValidAddrRange
(
addr32
,
NrofRegs32
);
if
(
status
!=
0
)
{
...
...
@@ -120,7 +120,7 @@ int BurstNetworktoReg(zmq_data *zmq_data_struct){
/* wait for data from client */
nbytes
=
zmq_recv
(
zmq_data_struct
->
socket
,
receiveBuffer
,
4
*
NrofRegs32
,
0
);
/* write data to addressed registers */
WriteFPGABurst
(
receiveBuffer
,
addr32
,
nbytes
>>
2
);
...
...
@@ -134,28 +134,26 @@ int BurstNetworktoReg(zmq_data *zmq_data_struct){
}
int
BurstRegtoNetwork
(
zmq_data
*
zmq_data_struct
){
unsigned
int
NrOfRegister
;
unsigned
int
*
buffer
;
int
status
;
unsigned
int
addr32
=
zmq_data_struct
->
data
[
1
];
zmq_data_struct
->
data
+=
4
;
unsigned
int
*
addr32
=
(
unsigned
int
*
)
zmq_data_struct
->
data
;
status
=
CheckValidBaseAddr
(
*
addr32
);
status
=
CheckValidBaseAddr
(
addr32
);
if
(
status
!=
0
)
{
return
status
;
}
zmq_data_struct
->
data
+=
4
;
NrOfRegister
=
*
(
unsigned
int
*
)
zmq_data_struct
->
data
;
//NrOfRegister = *(unsigned int*)
zmq_data_struct->data;
NrOfRegister
=
zmq_data_struct
->
data
[
2
]
;
buffer
=
(
unsigned
int
*
)
malloc
(
NrOfRegister
*
sizeof
(
int
));
ReadFPGABurst
(
buffer
,
*
addr32
,
NrOfRegister
);
ReadFPGABurst
(
buffer
,
addr32
,
NrOfRegister
);
zmq_send
(
zmq_data_struct
->
socket
,
buffer
,
NrOfRegister
*
4
,
0
);
free
(
buffer
);
return
0
;
...
...
@@ -181,22 +179,22 @@ int BurstRegtoNetwork(zmq_data *zmq_data_struct){
*/
int
NetworktoReg
(
zmq_data
*
zmq_data_struct
){
int
status
;
unsigned
int
command
=
*
zmq_data_struct
->
data
;
unsigned
int
command
=
zmq_data_struct
->
data
[
0
]
;
unsigned
int
nbytes
=
4
;
zmq_data_struct
->
data
+=
4
;
//
zmq_data_struct->data += 4;
unsigned
int
*
addr32
=
(
unsigned
int
*
)
zmq_data_struct
->
data
;
unsigned
int
addr32
=
zmq_data_struct
->
data
[
1
]
;
//printf("addr: 0x%.8x\n", *addr32);
//check if address is in range
status
=
CheckValidBaseAddr
(
*
addr32
);
status
=
CheckValidBaseAddr
(
addr32
);
if
(
status
!=
0
)
{
return
status
;
}
unsigned
int
*
data32
=
(
unsigned
int
*
)(
zmq_data_struct
->
data
+
4
)
;
unsigned
int
data32
=
zmq_data_struct
->
data
[
2
]
;
WriteFPGA
(
*
addr32
,
*
data32
);
WriteFPGA
(
addr32
,
data32
);
//echo the command if write FPGA was successful
zmq_send
(
zmq_data_struct
->
socket
,
&
command
,
nbytes
,
0
);
...
...
@@ -219,19 +217,18 @@ int NetworktoReg(zmq_data *zmq_data_struct){
int
RegtoNetwork
(
zmq_data
*
zmq_data_struct
){
int
status
;
unsigned
int
buffer
;
unsigned
int
*
addr32
;
unsigned
int
addr32
;
unsigned
int
nbytes
=
4
;
zmq_data_struct
->
data
+=
4
;
addr32
=
(
unsigned
int
*
)
zmq_data_struct
->
data
;
//printf("addr: 0x%.8x\n", *addr32);
addr32
=
zmq_data_struct
->
data
[
1
];
//Check if address is in range
status
=
CheckValidBaseAddr
(
*
addr32
);
status
=
CheckValidBaseAddr
(
addr32
);
if
(
status
!=
0
)
{
return
status
;
}
buffer
=
ReadFPGA
(
*
addr32
);
buffer
=
ReadFPGA
(
addr32
);
zmq_send
(
zmq_data_struct
->
socket
,
&
buffer
,
nbytes
,
0
);
return
0
;
...
...
pilc2_functions/pilc2_network.h
View file @
63b60d1d
...
...
@@ -26,7 +26,7 @@
typedef
struct
{
void
*
socket
;
unsigned
int
NrOfBytes
;
char
*
data
;
unsigned
int
*
data
;
}
zmq_data
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment