Commit abc3e218 authored by Joshua Supra's avatar Joshua Supra
Browse files

added config file support

parent f335e299
......@@ -19,13 +19,34 @@ unsigned int getIOMuxCfg(char channel) {
void IOMuxAutoConfig(IOCardStruct *IOCard) {
int IsConfig = 0;
FILE *fp;
int buffer[64];
if ((fp = fopen("/home/suprajos/pilc2/pilc2server/iocfg", "rb"))) {
fread(buffer,64*sizeof(int),4,fp);
fclose(fp);
IsConfig = 1;
} else {
IsConfig = 0;
}
for(int i = 0; i<16; i++){
switch(IOCard[i].TypeID) {
case NIM_TTL: setIODDR(0x1<<i, PILC_IO_INPUT);
WriteFPGA(SPI_CS_MUX_OFFSET, i);
WriteIOCard(IOCARD_NIMTTL_WSTATUS, IOCARD_NIMTTL_TTL_IN);
setIOMuxCfg(i, IO_MUX_CFG_CTR);break;
case NIM_TTL: if (IsConfig == 1) {
setIOConfig(i,buffer[4*i+1],buffer[4*i+2],buffer[4*i+3]);
} else {
setIODDR(0x1<<i, PILC_IO_INPUT);
WriteFPGA(SPI_CS_MUX_OFFSET, i);
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;
......
......@@ -97,7 +97,7 @@ int FunctionCall(zmq_data *zmq_data_struct){
case INIT_IO_CARDS: PiLC2InitIOCards();break;
case SPI_WRITE: PiLC2WSPI(funcArg[0],funcArg[1],funcArg[2]);break;
case SPI_READ: value = PiLC2RSPI(funcArg[0],funcArg[1],zmq_data_struct->socket);break;
case SET_IO_CFG: SetIOConfig(funcArg);break;
case SET_IO_CFG: WriteIOConfig(funcArg);break;
}
if(value == 1){
//echo the command
......@@ -537,8 +537,46 @@ void PiLC2WSPI(unsigned int card, unsigned int reg, unsigned int data) {
}
void SetIOConfig(unsigned int *data) {
void WriteIOConfig(unsigned int *data) {
/*for(int i= 0; i <64; i++){
printf("%d\n", data[i]);
}*/
}
printf("---\n");*/
/*struct PiLC2IOConfigStruct {
unsigned int Config;
unsigned int Direction;
unsigned int Level;
};
struct PiLC2IOConfigStruct PiLC2IOConfig[16] = {0};
for (int i = 0; i < 16; i++) {
PiLC2IOConfig[i].Config = data[4*i+1];
PiLC2IOConfig[i].Direction = data[4*i+2];
PiLC2IOConfig[i].Level = data[4*i+3];
}
for(int i= 0; i <16; i++){
printf("%d\n", PiLC2IOConfig[i].Config);
}
*/
FILE *fp;
fp = fopen("/home/suprajos/pilc2/pilc2server/iocfg", "wb");
fwrite(data,64*sizeof(int),1,fp);
fclose(fp);
InitIOCards(IOCards);
for (int i = 0; i < 16; i++) {
if (IOCards[i].TypeID == NIM_TTL) {
//printf("%d %d %d %d \n",i,data[4*i+1],data[4*i+2],data[4*i+3]);
setIOConfig(i,data[4*i+1],data[4*i+2],data[4*i+3]);
}
}
InitIOCards(IOCards);
}
......@@ -50,7 +50,7 @@ int GetDate(zmq_data *zmq_data_struct);
int PiLC2RSPI(unsigned int card, unsigned int reg, void *socket);
void PiLC2WSPI(unsigned int card, unsigned int reg, unsigned int data);
void PiLC2InitIOCards(void);
void SetIOConfig(unsigned int *data);
void WriteIOConfig(unsigned int *data);
void *context;
......
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