Commit 9b785d70 authored by Joshua Supra's avatar Joshua Supra
Browse files

.

parent ccec20ad
......@@ -74,10 +74,10 @@ void IOMuxAutoConfig(IOCardStruct *IOCard) {
/* Check if a valid config is available on the PiLC2 */
if ((fp = fopen("/home/suprajos/pilc2/pilc2server/iocfg", "rb"))) {
if ((fp = fopen("/home/pilc/pilc2server/iocfg", "rb"))) {
fread(buffer,80*sizeof(int),4,fp);
fclose(fp);
IsConfig = 1;
......
/******************************************************************************/
/**
*
* @file pilc2_network.c
* @author Joshua Supra (joshua.supra@desy.de)
* @brief This file contains the implementation of the ZMQ network communication
* @version 0.1
* @date 2022-05-09
*
* @copyright Copyright (c) 2022 Deutsches Elektronen-Synchrotron DESY
*
*
*
*******************************************************************************/
/***************************** Include Files **********************************/
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
......@@ -30,7 +45,15 @@
#include <net/if.h>
#include <arpa/inet.h>
/******************************************************************************/
/**
*
* @brief Initialization function for the ZMQ network connection
*
* @return 0
*
*
*******************************************************************************/
int init_network(void){
//create 0mq context and responder
......@@ -46,6 +69,16 @@ int init_network(void){
return 0;
}
/******************************************************************************/
/**
*
* @brief Deinitialization function for the ZMQ network
*
* @return 0
*
*
*******************************************************************************/
int deinit_network(void){
//Clean up 0mq
zmq_close(client_responder);
......@@ -75,15 +108,11 @@ int FunctionCall(zmq_data *zmq_data_struct){
unsigned int command = zmq_data_struct->data[0];
int nbytes = 0;
int value = 1;
/*for (int i = 0; i< zmq_data_struct->NrOfBytes >> 2; i++){
printf("%d\n",zmq_data_struct->data[i]);
}*/
FunctionNumber = zmq_data_struct->data[1];
//printf("%d\n",((zmq_data_struct->NrOfBytes)>>2)-2);
for(int i = 0; i < ((zmq_data_struct->NrOfBytes)>>2)-2; i++){
funcArg[i] = zmq_data_struct->data[2+i];
//printf("%.8x\n",funcArg[i]);
//printf("%d\n",funcArg[i]);
}
switch (FunctionNumber){
......@@ -187,7 +216,7 @@ int BurstRegtoNetwork(zmq_data *zmq_data_struct){
if (status != 0) {
return status;
}
//NrOfRegister = *(unsigned int*)zmq_data_struct->data;
NrOfRegister = zmq_data_struct->data[2];
/* Allocate memory for sending data */
......@@ -323,7 +352,7 @@ int GetNrOfData(zmq_data *zmq_data_struct)
buffer[0] = (current_ram_address);
buffer[1] = (read_ram_base_addr);
buffer[2] = (last_valid_ram_addr);
//printf("%i \n", buffer[1]);
/* Unlock the mutex */
pthread_mutex_unlock(&lock);
......@@ -353,12 +382,9 @@ int PiLC2GetRamData(unsigned int RAMBaseAddress, unsigned int numofdata, void *s
pointer = (unsigned int *)malloc(numofdata*sizeof(int));
/* Send RAM data according to the number of register */
//zmq_send(socket, pointer, numofdata*4, 0);
//zmq_send(socket, pointer, numofdata*4, 0);
for (int i= 0; i<numofdata; i++){
//printf("%.8x\n", *(ps_mem_dest_base_addr+RAMBaseAddress+i));
pointer[i] = *(ps_mem_dest_base_addr+RAMBaseAddress+i);
}
......@@ -500,13 +526,27 @@ void PiLC2InitIOCards(void) {
InitIOCards(IOCards);
}
/******************************************************************************/
/**
*
* @brief Get the Date / time of the PiLC and the network status of the eth1
* connection (client/data connection)
*
* @param zmq_data_struct pointer to the zmq struct of the calling socket.
* @return
*
*
*******************************************************************************/
int GetDate(zmq_data *zmq_data_struct) {
unsigned int *buffer;
buffer = (unsigned int *)malloc(7*sizeof(int));
/* read the sys time and date */
time_t rawtime = time(NULL);
/* format to date struct*/
struct tm *ptm = localtime(&rawtime);
buffer[0] = ptm->tm_year+1900;
......@@ -517,19 +557,15 @@ int GetDate(zmq_data *zmq_data_struct) {
buffer[5] = ptm->tm_sec;
char *ifname ="eth1";
/* get the socked ID and check for up status */
int socId = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
struct ifreq if_req;
(void) strncpy(if_req.ifr_name, ifname, sizeof(if_req.ifr_name));
ioctl(socId, SIOCGIFFLAGS, &if_req);
close(socId);
buffer[6] = (if_req.ifr_flags & IFF_UP) && (if_req.ifr_flags & IFF_RUNNING);
//printf("%i \n", buffer[1]);
zmq_send (zmq_data_struct->socket, buffer, 28, 0);
free(buffer);
......@@ -537,6 +573,19 @@ int GetDate(zmq_data *zmq_data_struct) {
return 0;
}
/******************************************************************************/
/**
*
* @brief ZMQ SPI read function for the SPI connected to the IO card
*
* @param card addressed IO card
* @param reg selected register of the addressed IO card
* @param socket of the calling ZMQ connection
* @return 0
*
*
*******************************************************************************/
int PiLC2RSPI(unsigned int card, unsigned int reg, void *socket) {
unsigned int value;
WriteFPGA(SPI_CS_MUX_OFFSET, card);
......@@ -548,6 +597,18 @@ int PiLC2RSPI(unsigned int card, unsigned int reg, void *socket) {
return 0;
}
/******************************************************************************/
/**
*
* @brief ZMQ SPI write function for the SPI connected to the IO card
*
* @param card addressed IO card
* @param reg selected register of the addressed IO card
* @param data data to be written in selected register
*
*
*******************************************************************************/
void PiLC2WSPI(unsigned int card, unsigned int reg, unsigned int data) {
WriteFPGA(SPI_CS_MUX_OFFSET, card);
......@@ -556,6 +617,17 @@ void PiLC2WSPI(unsigned int card, unsigned int reg, unsigned int data) {
}
/******************************************************************************/
/**
*
* @brief Writes a valid IO config transmitted by a client to the PiLC and stores
* it into a binary
*
* @param data array containing the valid IO config
*
*
*******************************************************************************/
void WriteIOConfig(unsigned int *data) {
FILE *fp;
......@@ -572,12 +644,10 @@ void WriteIOConfig(unsigned int *data) {
if (IOCards[i].TypeID == NIM_TTL) {
setIOConfig(i,data[5*i+1],data[5*i+2],data[5*i+3]);
//printf("%d, %d, %d, %d, %d\n",i,data[5*i+1],data[5*i+2],data[5*i+3],data[5*i+4]);
}
if (data[5*i+4] == 1) {
setFifoSerChCfg(i, data[5*i+2]);
//printf("%d %d \n", i, data[5*i+2]);
} else {
setFifoSerChCfg(i, 0);
}
......@@ -586,18 +656,39 @@ void WriteIOConfig(unsigned int *data) {
InitIOCards(IOCards);
}
/******************************************************************************/
/**
*
* @brief reads if available the IO config of the PiLC and transmits it back to
* client.
*
* @param zmq_data_struct pointer to the zmq struct of the calling socket.
* @return 0
*
*
*******************************************************************************/
int GetIOConfig(zmq_data *zmq_data_struct)
{
FILE *fp;
char *buffer;
int filelen;
/* open the IO config file */
fp = fopen("/home/pilc/pilc2server/iocfg", "rb");
/* go to the end of the file*/
fseek(fp, 0, SEEK_END);
/* copy the length of the file */
filelen = ftell(fp);
/* head back to the beginning of the file */
rewind(fp);
buffer = (char *)malloc(filelen * sizeof(char));
/* read the file and send it to the client */
fread(buffer, filelen, 1, fp);
zmq_send (zmq_data_struct->socket, buffer, filelen, 0);
......
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