Commit 810ed3a3 authored by Joshua Supra's avatar Joshua Supra
Browse files

.

parent c857bdbc
......@@ -19,14 +19,19 @@
#include "pilc2_functions/pilc2_adc.h"
#include "pilc2_functions/pilc2_IO_mux.h"
#include "pilc2_functions/pilc2_encoder.h"
int thread_nr;
int main (int argc, char *argv[]){
int main (int argc, char *argv[]){
// sleep(10);
WorkLEDcounter = 0;
unsigned int front_LED_update_ctr = 0;
initContCounterDone = 0;
......@@ -50,11 +55,26 @@ int main (int argc, char *argv[]){
* */
IOMuxAutoConfig(IOCards);
/*setIOMuxCfg(PILC_IO_MUX_CFG_CH_0, IO_MUX_CFG_ENCODER);
setIOMuxCfg(PILC_IO_MUX_CFG_CH_1, IO_MUX_CFG_ENCODER);
setIOMuxCfg(PILC_IO_MUX_CFG_CH_2, IO_MUX_CFG_ENCODER);
setIOMuxCfg(PILC_IO_MUX_CFG_CH_3, IO_MUX_CFG_ENCODER);
setIOMuxCfg(PILC_IO_MUX_CFG_CH_4, IO_MUX_CFG_ENCODER);
setIOMuxCfg(PILC_IO_MUX_CFG_CH_5, IO_MUX_CFG_ENCODER);
setIOMuxCfg(PILC_IO_MUX_CFG_CH_6, IO_MUX_CFG_ENCODER);
setIOMuxCfg(PILC_IO_MUX_CFG_CH_7, IO_MUX_CFG_ENCODER);
setIOMuxCfg(PILC_IO_MUX_CFG_CH_8, IO_MUX_CFG_ENCODER);
setIOMuxCfg(PILC_IO_MUX_CFG_CH_9, IO_MUX_CFG_ENCODER);
setIOMuxCfg(PILC_IO_MUX_CFG_CH_10, IO_MUX_CFG_ENCODER);
setIOMuxCfg(PILC_IO_MUX_CFG_CH_11, IO_MUX_CFG_ENCODER);
setIOMuxCfg(PILC_IO_MUX_CFG_CH_12, IO_MUX_CFG_ENCODER);
setIOMuxCfg(PILC_IO_MUX_CFG_CH_13, IO_MUX_CFG_ENCODER);
setIOMuxCfg(PILC_IO_MUX_CFG_CH_14, IO_MUX_CFG_ENCODER);
setIOMuxCfg(PILC_IO_MUX_CFG_CH_15, IO_MUX_CFG_ENCODER);*/
InitIOCards(IOCards);
zmq_recive_data[1] = malloc (sizeof(zmq_data));
zmq_recive_data[1]->data = (unsigned int *) malloc (256*sizeof(char));
/* Initalize the network communication */
......@@ -62,6 +82,8 @@ int main (int argc, char *argv[]){
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) {
......@@ -107,7 +129,7 @@ int main (int argc, char *argv[]){
pthread_create(&thread_led_update, NULL, updateIOLeds, (void *)IOCards);
front_LED_update_ctr = 20;
front_LED_update_ctr = 25;
}
......
......@@ -19,7 +19,8 @@ DEPENDENCIES= \
pilc2_dadc.h \
pilc2_IO_mux.h \
pilc2_pt100.h \
pilc2_thermo.h
pilc2_thermo.h \
pilc2_encoder.h
OBJ= \
pilc2_SPI_func.o \
pilc2_register_func.o \
......@@ -38,7 +39,8 @@ OBJ= \
pilc2_dadc.o \
pilc2_IO_mux.o \
pilc2_pt100.o \
pilc2_thermo.o
pilc2_thermo.o \
pilc2_encoder.o
all: $(OBJ)
ar vrcs $(TARGETLIB) $(OBJ)
......
......@@ -167,8 +167,7 @@ const char* IOCardType(unsigned char IOCard_ID){
/**
*
* This function reads every IO card slot via SPI and stores the card infomation
* in the IO card struct. If a card is inserted in the checked slot, the card
* information will be printed.
* in the IO card struct.
*
*
* @param *IOCard is the pointer to the IOCardStruct array
......@@ -271,6 +270,13 @@ int GetIOCardRegister(IOCardStruct *IOCard) {
return 0;
}
int setIOConfig(unsigned int channel, unsigned int config) {
return 0;
}
void *updateIOLeds(void *vargp) {
IOCardStruct *IOCard = (IOCardStruct *)vargp;
......@@ -280,7 +286,20 @@ void *updateIOLeds(void *vargp) {
unsigned int mask = 0x1;
float value_float;
int value_int;
WorkLEDcounter ++;
if (WorkLEDcounter == 2) {
WorkLEDcounter = 0;
}
if (WorkLEDcounter < 1){
WriteFrontLED(16, 0,5,0);
WriteFrontLED(17, 0,0,0);
}else {
WriteFrontLED(16, 0,0,0);
WriteFrontLED(17, 0,5,0);
}
unsigned int led_brightness;
//unsigned int IO_status_mask_result;
for (int i = 0; i<16; i++){
......
......@@ -78,7 +78,9 @@ int TestNIMTTLCard (IOCardStruct *IOCard);
int GetIOCardStatus(IOCardStruct *IOCard);
int GetIOCardRegister(IOCardStruct *IOCard);
void *updateIOLeds(void *vargp);
int setIOConfig(unsigned int channel, unsigned int config);
IOCardStruct IOCards[16];
IOCardStruct IOCards[16];
unsigned int WorkLEDcounter;
#endif
......@@ -22,12 +22,13 @@ void IOMuxAutoConfig(IOCardStruct *IOCard) {
for(int i = 0; i<16; i++){
switch(IOCard[i].TypeID) {
case NIM_TTL: if (i == 15) {
case NIM_TTL: /*if (i == 15) {
setIODDR(0x1<<i, PILC_IO_OUTPUT);
WriteIOCard(IOCARD_NIMTTL_WSTATUS, IOCARD_NIMTTL_TTL_OUT);
}else {
}else {*/
setIODDR(0x1<<i, PILC_IO_INPUT);
}
WriteIOCard(IOCARD_NIMTTL_WSTATUS, IOCARD_NIMTTL_TTL_IN);
//}
setIOMuxCfg(i, IO_MUX_CFG_CTR);break;
case ADC: setIODDR(0x1<<i, PILC_IO_INPUT);
setIOMuxCfg(i, IO_MUX_CFG_ADC);break;
......
......@@ -13,12 +13,12 @@
#define PILC_IO_MUX_CFG_CH_7 0x7
#define PILC_IO_MUX_CFG_CH_8 0x8
#define PILC_IO_MUX_CFG_CH_9 0x9
#define PILC_IO_MUX_CFG_CH_10 0x10
#define PILC_IO_MUX_CFG_CH_11 0x11
#define PILC_IO_MUX_CFG_CH_12 0x12
#define PILC_IO_MUX_CFG_CH_13 0x13
#define PILC_IO_MUX_CFG_CH_14 0x14
#define PILC_IO_MUX_CFG_CH_15 0x15
#define PILC_IO_MUX_CFG_CH_10 0xA
#define PILC_IO_MUX_CFG_CH_11 0xB
#define PILC_IO_MUX_CFG_CH_12 0xC
#define PILC_IO_MUX_CFG_CH_13 0xD
#define PILC_IO_MUX_CFG_CH_14 0xE
#define PILC_IO_MUX_CFG_CH_15 0xF
#define IO_MUX_CFG_CTR 0x1
#define IO_MUX_CFG_ADC 0x2
......@@ -27,6 +27,7 @@
#define IO_MUX_CFG_ADAPTER_CARD 0x5
#define IO_MUX_CFG_DADC 0x7
#define IO_MUX_CFG_THERMO 0x8
#define IO_MUX_CFG_ENCODER 0x9
void setIOMuxCfg(char channel, unsigned int config);
unsigned int getIOMuxCfg(char channel);
......
......@@ -20,6 +20,7 @@
#include "pilc2_axi_gpio.h"
#include "pilc2_cdma.h"
#include "pilc2_continous_counter.h"
#include "pilc2_IO_mux.h"
#include <sys/types.h>
#include <sys/socket.h>
......@@ -32,14 +33,14 @@ int init_network(void){
//create 0mq context and responder
context = zmq_ctx_new ();
int keep_alive = 1;
/*int keep_alive = 1;
int keep_alive_idle = 300;
int keep_alive_intvl = 300;
int keep_alive_intvl = 300;*/
/* create and bind socket for client connection */
client_responder = zmq_socket (context, ZMQ_REP);
zmq_setsockopt (client_responder, ZMQ_TCP_KEEPALIVE, &keep_alive, sizeof(keep_alive));
/*zmq_setsockopt (client_responder, ZMQ_TCP_KEEPALIVE, &keep_alive, sizeof(keep_alive));
zmq_setsockopt (client_responder, ZMQ_TCP_KEEPALIVE_IDLE, &keep_alive_idle, sizeof(keep_alive_idle));
zmq_setsockopt (client_responder, ZMQ_TCP_KEEPALIVE, &keep_alive_intvl, sizeof(keep_alive_intvl));
zmq_setsockopt (client_responder, ZMQ_TCP_KEEPALIVE, &keep_alive_intvl, sizeof(keep_alive_intvl));*/
zmq_bind (client_responder, "tcp://eth1:4444");
/* create and bind socket for gui connection */
......@@ -57,7 +58,20 @@ int deinit_network(void){
}
//int FunctionCall(char *data, char numberofbytes){
/*
* Function: FunctionCall
* --------------------
* Performes a PiLC2 function called by zmq. Depending on the function number
* the according function will be called. If a function has no own zmq_send
* function, FunctionCall will send back an echo of the command of the called
* function, when the function call was successful.
*
* See function description for more information about the called function.
*
* *zmq_data_struct: pointer to the zmq struct of the calling socket.
*
* returns: 0 if OK
*/
int FunctionCall(zmq_data *zmq_data_struct){
unsigned int FunctionNumber;
unsigned int funcArg[zmq_data_struct->NrOfBytes-2];
......@@ -66,13 +80,9 @@ int FunctionCall(zmq_data *zmq_data_struct){
int value = 1;
FunctionNumber = zmq_data_struct->data[1];
//printf("bytes: %d\n", zmq_data_struct->NrOfBytes);
//printf("func nr: %.8x\n", FunctionNumber);
//zmq_data_struct->data +=4;
for(int i = 0; i < ((zmq_data_struct->NrOfBytes)>>2)-2; i++){
funcArg[i] = zmq_data_struct->data[2+i];
//printf("%d ", funcArg[i]);
}
switch (FunctionNumber){
......@@ -95,6 +105,16 @@ int FunctionCall(zmq_data *zmq_data_struct){
return 0;
}
/*
* Function: BurstRegtoNetwork
* --------------------
* Performes a burst register read on the FPGA.
*
* *zmq_data_struct: pointer to the zmq struct of the calling socket.
*
* returns: 0 if OK, returns -1 if address is out of range
*/
int BurstNetworktoReg(zmq_data *zmq_data_struct){
unsigned int addr32;
unsigned int NrofRegs32;
......@@ -140,6 +160,17 @@ int BurstNetworktoReg(zmq_data *zmq_data_struct){
return 0;
}
/*
* Function: BurstRegtoNetwork
* --------------------
* Performes a burst register write on the FPGA.
*
* *zmq_data_struct: pointer to the zmq struct of the calling socket.
*
* returns: 0 if OK, returns -1 if address is out of range
*/
int BurstRegtoNetwork(zmq_data *zmq_data_struct){
unsigned int NrOfRegister;
......@@ -154,7 +185,8 @@ int BurstRegtoNetwork(zmq_data *zmq_data_struct){
}
//NrOfRegister = *(unsigned int*)zmq_data_struct->data;
NrOfRegister = zmq_data_struct->data[2];
/* Allocate memory for sending data */
buffer = (unsigned int *)malloc(NrOfRegister*sizeof(int));
ReadFPGABurst(buffer,addr32, NrOfRegister);
......@@ -174,13 +206,7 @@ int BurstRegtoNetwork(zmq_data *zmq_data_struct){
* Writes a 32-bit register with a certain value, transmitted
* by the network
*
* *data: the receive data buffer for network communication,
* containing the address of the register and the value to be
* written.
*
* *returnBuffer: the send data buffer for network communication,
* echoes the command, like read/write etc. to be able to check
* a successful operation.
* *zmq_data_struct: pointer to the zmq struct of the calling socket.
*
* returns: 0 if OK, returns -1 if address is out of range
*/
......@@ -189,10 +215,7 @@ int NetworktoReg(zmq_data *zmq_data_struct){
unsigned int command = zmq_data_struct->data[0];
unsigned int nbytes = 4;
//zmq_data_struct->data += 4;
unsigned int addr32 = zmq_data_struct->data[1];
//printf("addr: 0x%.8x\n", *addr32);
//check if address is in range
status = CheckValidBaseAddr(addr32);
if (status != 0) {
......@@ -214,10 +237,7 @@ int NetworktoReg(zmq_data *zmq_data_struct){
* --------------------
* Reads a single 32-bit register value and sends it to the requestor
*
* *data: the receive data buffer for network communication,
* containing the address of the register
*
* *returnBuffer: the transmit buffer for network communication
* * zmq_data_struct: pointer to the zmq struct of the calling socket.
*
* returns: 0 if OK, returns -1 if address is out of range
*/
......@@ -281,8 +301,9 @@ int CheckValidAddrRange(unsigned int BaseAddr, unsigned int NRofRegs){
* Reads the current write RAM address, read RAM address and the last valid
* RAM address.
*
* * zmq_data_struct: pointer to the zmq struct of the calling socket.
*
* returns: 1 to inform network thread to not send answer string
* returns: 0 to inform network thread to not send answer string
*/
int GetNrOfData(zmq_data *zmq_data_struct)
{
......@@ -305,27 +326,29 @@ int GetNrOfData(zmq_data *zmq_data_struct)
}
/*
* Function: CheckValidAddrRange
* Function: PiLC2GetRamData
* --------------------
* Checks if the read/write address exceeds the momory bonds.
* Send RAM data to requestor.
*
* RAMBaseAddress: read RAM address offset
*
* numofdata: Number of integer values to be send via network
*
* returns: 1 to inform network thread to not send answer string
* *socket: pointer to the zmq socket to send back data.
*
* returns: 0 to inform network thread to not send answer string
*/
int PiLC2GetRamData(unsigned int RAMBaseAddress, unsigned int numofdata, void *socket)
{
pthread_mutex_lock(&lock);
/* Send RAM data according to the number of register */
zmq_send(socket, ps_mem_dest_base_addr+RAMBaseAddress, numofdata*4, 0);
read_ram_base_addr = read_ram_base_addr +numofdata*4;
//read_ram_base_addr = read_ram_base_addr +numofdata;
/*printf("%.8x ", *(ps_mem_dest_base_addr+RAMBaseAddress));
printf("%.8x ", *(ps_mem_dest_base_addr+RAMBaseAddress+1));
printf("%.8x\n", *(ps_mem_dest_base_addr+RAMBaseAddress+2));*/
/* If the last valid RAM address has been exceeded, start back from addrss
* 0 */
if(read_ram_base_addr == last_valid_ram_addr){
read_ram_base_addr = 0x00000000;
......@@ -337,13 +360,27 @@ int PiLC2GetRamData(unsigned int RAMBaseAddress, unsigned int numofdata, void *s
return 0;
}
/*
* Function: PiLC2GetIOCards
* --------------------
* Transmits the IO cad information to the requester.
*
* * zmq_data_struct: pointer to the zmq struct of the calling socket.
*
* returns: 0 to inform network thread to not send answer string
*/
int PiLC2GetIOCards(zmq_data *zmq_data_struct) {
unsigned char *buffer;
buffer = (unsigned char *)malloc(10*16*sizeof(char));
/* Read the status of the IO card input/output */
GetIOCardStatus(IOCards);
/* Read the cards data register and write it into IO card struct register*/
GetIOCardRegister(IOCards);
/* Create a buffer for zmq containing all needed card informaiton */
for (int i = 0; i<16; i++){
buffer[i*10] = IOCards[i].TypeID;
buffer[i*10+1] = IOCards[i].HWVersion;
......@@ -355,8 +392,6 @@ int PiLC2GetIOCards(zmq_data *zmq_data_struct) {
buffer[i*10+7] = IOCards[i].Register_value>>16 & 0XFF;
buffer[i*10+8] = IOCards[i].Register_value>>24 & 0xFF;
buffer[i*10+9] = IOCards[i].AdditionalData;
//printf("send %i: %.x2 ",i+1, IOCards[i].TypeID);
//printf("%.x8\n", IOCards[i].Register_value);
}
zmq_send (zmq_data_struct->socket, buffer,10*16, 0);
......@@ -365,21 +400,35 @@ int PiLC2GetIOCards(zmq_data *zmq_data_struct) {
return 0;
}
/*
* Function: getPiLCinet
* --------------------
* Reads ethernet interface 1 (external ethernet) hostname, MAC- and IP-address
* and transmits it back to requester via zmq.
*
* * zmq_data_struct: pointer to the zmq struct of the calling socket.
*
* returns: 0 to inform network thread to not send answer string
*/
int getPiLCinet(zmq_data *zmq_data_struct){
unsigned int *buffer;
int len;
char hostname[50];
/* Get the PiLC2 hostname */
gethostname(hostname, sizeof(hostname));
/* Get the PilC2 external mac address */
char mac[18];
FILE * file =fopen("/sys/class/net/eth1/address", "r");
fscanf( file, "%s", &mac[0] );
fclose(file);
/* Get the PilC2 external IP address */
int fd;
struct ifreq ifr;
char iface[] = "eth1";
......@@ -388,7 +437,7 @@ int getPiLCinet(zmq_data *zmq_data_struct){
fd = socket(AF_INET, SOCK_DGRAM, 0);
ifr.ifr_addr.sa_family = AF_INET;
//Copy the interface name in the ifreq structure
/* Copy the interface name in the ifreq structure */
strncpy(ifr.ifr_name , iface , IFNAMSIZ-1);
ioctl(fd, SIOCGIFADDR, &ifr);
......@@ -397,6 +446,7 @@ int getPiLCinet(zmq_data *zmq_data_struct){
strncpy(ipaddr, inet_ntoa(( (struct sockaddr_in *)&ifr.ifr_addr )->sin_addr) , IFNAMSIZ-1);
/* Append mac and IP address to hostname */
strcat(hostname, ";");
strcat(hostname, mac);
strcat(hostname, ";");
......@@ -413,17 +463,39 @@ int getPiLCinet(zmq_data *zmq_data_struct){
return 0;
}
/*
* Function: LedSetInhibit
* --------------------
* Network function for calling the front panel led inhibit.
*
* * zmq_data_struct: pointer to the zmq struct of the calling socket.
*
*/
void LedSetInhibit(zmq_data *zmq_data_struct) {
unsigned int inhibit;
/* Extract LED inhibit mask */
inhibit = zmq_data_struct->data[2];
/* Write LED inhibit register */
InhibitFrontLED(inhibit);
}
/*
* Function: PiLC2InitIOCards
* --------------------
* (Re)Initialize the IO cards.
*
*/
void PiLC2InitIOCards(void) {
InitIOCards(IOCards);
IOMuxAutoConfig(IOCards);
InitIOCards(IOCards);
}
......@@ -3,7 +3,7 @@
#define PILC_REG_START_ADDR 0x80000000
#define PILC_REG_END_ADDR 0x80008FFF
#define PILC_REG_END_ADDR 0x80009FFF
#define PILC_REG_SIZE ( PILC_REG_END_ADDR - PILC_REG_START_ADDR )
......
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