Commit 71bffb95 authored by Joshua Supra's avatar Joshua Supra
Browse files

x

x
parent 108bc676
......@@ -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
......
......@@ -20,9 +20,9 @@
#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;
......@@ -48,79 +48,80 @@ 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));
while (1) {
zmq_recive_data[0]->NrOfBytes = zmq_recv (client_responder,
zmq_recive_data[0]->data, 255, ZMQ_DONTWAIT);
zmq_recive_data[0]->socket = client_responder;
zmq_recive_data[0]->socket = client_responder;
if (zmq_recive_data[0]->NrOfBytes != -1) {
//printf("1\n");
printf("%i\n", &zmq_recive_data[0]->NrOfBytes);
printf("%i\n", zmq_recive_data[0]->NrOfBytes);
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_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);
printf("bla\n");
zmq_recive_data[1]->socket = gui_responder;
if (zmq_recive_data[1]->NrOfBytes != -1) {
//printf("2\n");
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_detach(thread_network[1]);
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 );
//pthread_detach(thread_led_update);
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 +129,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 +142,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_recive_data);break;
case 0x1: status = NetworktoReg(zmq_recive_data);break;
case 0x2: status = BurstRegtoNetwork(zmq_recive_data);break;
case 0x3: status = BurstNetworktoReg(zmq_recive_data);break;
case 0x4: status = FunctionCall(zmq_recive_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_recive_data->socket, SendBuffer, nbytes, 0);
zmq_send (zmq_rec_data->socket, SendBuffer, nbytes, 0);
}
pthread_exit(NULL);
}
......
......@@ -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;
......
......@@ -26,7 +26,7 @@
typedef struct {
void *socket;
unsigned int NrOfBytes;
char *data;
unsigned int *data;
}zmq_data;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment