Commit 041b46d3 authored by Joshua Supra's avatar Joshua Supra
Browse files

added some comments

parent abc3e218
......@@ -28,7 +28,10 @@
int thread_nr;
/**
* Starting main below
*
*/
int main (int argc, char *argv[]){
// sleep(10);
......
......@@ -11,7 +11,6 @@
/***************************** Include Files *********************************/
#include <stdlib.h>
//#include <main.h>
#include <stdio.h>
#include <unistd.h>
#include <pthread.h>
......@@ -118,10 +117,22 @@ int GetGpioConfig(pilcIOGpioStruct *pilcIOcfg){
}
/*****************************************************************************/
/**
*
* @brief This function reads every IO card slot via SPI and stores the card
* infomation in the IO card struct.
*
* @param *IOCard is the pointer to the IOCardStruct array
*
* @return The number of found IO cards.
*
* @note None.
*
******************************************************************************/
void setIODDR(unsigned int channel, unsigned int config) {
int IODDRCfg = ReadFPGA(PILC_IO_GPIOS_OFFSET+PILC_IODDR_CFG_REG);
//printf("channel %.8x\n", IODDRCfg);
if(config == PILC_IO_INPUT){
WriteFPGA(PILC_IO_GPIOS_OFFSET+PILC_IODDR_CFG_REG, IODDRCfg&~channel);
......@@ -165,22 +176,20 @@ 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.
* @brief This function reads every IO card slot via SPI and stores the card
* infomation in the IO card struct.
*
*
* @param *IOCard is the pointer to the IOCardStruct array
*
* @return The number of found IO cards.
*
* @note None.
*
*****************************************************************************/
char InitIOCards (IOCardStruct *IOCard){
unsigned char num_IO_cards = 0;
******************************************************************************/
int InitIOCards (IOCardStruct *IOCard){
/* check each card slot for HW version */
for (int i = 0; i<16; i++){
......@@ -200,11 +209,6 @@ char InitIOCards (IOCardStruct *IOCard){
}else if(IOCard[i].TypeID == PT100){
IOCard[i].AdditionalData = ReadIOCard(IOCARD_PT_SENSOR);
}
/* if a card is present the card information will be printed */
if (IOCard[i].TypeID != 0x00 && IOCard[i].TypeID != 0xFF){
//printf("IOCard[%i].TypeID: %.2x\n",i, IOCard[i].TypeID);
num_IO_cards++;
}
}
for (int i = 0; i<16; i++){
if (IOCard[i].TypeID == ADAPTER) {
......@@ -219,26 +223,57 @@ char InitIOCards (IOCardStruct *IOCard){
}
}
}
return num_IO_cards;
return 0;
}
int GetIOCardStatus(IOCardStruct *IOCard) {
/*****************************************************************************/
/**
*
* @brief This function reads the status of each IO card.
*
* @param *IOCard is the pointer to the IOCardStruct array
*
* @return 0
*
* @note None.
*
******************************************************************************/
int GetIOCardStatus(IOCardStruct *IOCard)
{
unsigned int mask = 0x1;
unsigned int status;
status = ReadFPGA(PILC_IO_GPIOS_OFFSET + PiLC_IOSTR);
for (int i = 0; i <16; i++){
IOCard[i].IOStatus = (status & mask) >> (i);
mask = mask<<1;
}
return 0;
}
int GetIOCardRegister(IOCardStruct *IOCard) {
/*****************************************************************************/
/**
*
* @brief This function reads the register of each card depending on their
* purpose.
*
* @param *IOCard is the pointer to the IOCardStruct array
*
* @return The number of found IO cards.
*
* @note None.
*
******************************************************************************/
int GetIOCardRegister(IOCardStruct *IOCard)
{
for (int i = 0; i<16; i++){
if (IOCard[i].TypeID != 0x00 && IOCard[i].TypeID != 0xFF){
//printf("IOCarc[%d]: %.2x\n", i, IOCard[i].TypeID);
switch(IOCard[i].TypeID) {
case NIM_TTL: break;
......@@ -246,8 +281,7 @@ int GetIOCardRegister(IOCardStruct *IOCard) {
case DAC: IOCard[i].Register_value = getDACvalue(i);break;
case DIFF_ADC: IOCard[i].Register_value = getDADCvalue(i/2);;break;
//printf("%i: %.x8\n",i+1, IOCard[i].Register_value);break;
case DIFF_ADC: IOCard[i].Register_value = getDADCvalue(i/2);;break;
case ADAPTER: if (IOCard[i-1].TypeID == DIFF_ADC) {
IOCard[i].Register_value = getDADCRawvalue((i-1)/2);
......@@ -257,14 +291,12 @@ int GetIOCardRegister(IOCardStruct *IOCard) {
IOCard[i].Register_value = getPT100RawValue(((i-1)/4+16));
} else if (IOCard[i+1].TypeID == PT100){
IOCard[i].Register_value = getPT100RawValue(((i+1)/4+16));
}
//printf("%i: %.x8\n",i+1, IOCard[i].Register_value);
break;
} break;
case THERMO: IOCard[i].Register_value = getThermoRawvalue(((i)/2+16));break;
case PT100: IOCard[i].Register_value = getPT100RawValue(((i)/4+16));break;
}
}else {
IOCard[i].Register_value = 0;
}
......@@ -273,6 +305,27 @@ int GetIOCardRegister(IOCardStruct *IOCard) {
}
/*****************************************************************************/
/**
*
* @brief This function sets the IO config of the selected channel, including
* data direction, function and level and configuring the inserted IO
* card.
*
* @param channel is the channel to be addressed
*
* direction is the set direction, 0: input 1: output
*
* function sets the IO multiplexer
*
* level can be either NIM or TTL
*
* @return 0
*
* @note None.
*
******************************************************************************/
int setIOConfig(unsigned int channel, unsigned int direction,
unsigned int function, unsigned int level) {
......@@ -324,10 +377,15 @@ void *updateIOLeds(void *vargp) {
led_color.Green = 0;
}else {
getNIMTTLcolour(i, &led_color);
led_color.Red = 0;
led_color.Green = led_color.Green+IOCard[i].IOStatus*42;
//printf("IOCard[%d] %d\n",i, led_color.Green);
led_color.Red = 0;
if (led_color.Green != 0) {
led_color.Green = led_color.Green+IOCard[i].IOStatus*42;
}
//printf("[%d] %d\n",i, led_color.Green);
}
led_color.Blue = 0;break;
led_color.Blue = 0;break;
case ADC: value_float = ((float)getADCvalue(i)/65535)*42;
led_brightness = ((unsigned int)value_float)+0.5;
......@@ -455,6 +513,7 @@ void getNIMTTLcolour(int card_slot, led_color_struct *led_color) {
break;
case 1:
if ((logicfg & ABmask) != 0) {
led_color->Green = 8;
}else {
led_color->Green = 0;
......
......@@ -79,7 +79,7 @@ void initpilc2(IOCardStruct *IOCard);
int GetGpioConfig(pilcIOGpioStruct *pilcIOcfg);
void setIODDR(unsigned int channel, unsigned int config);
/**PILC2 Selftest IO card functions**/
char InitIOCards (IOCardStruct *IOCard);
int InitIOCards (IOCardStruct *IOCard);
int SelftestIOCards (IOCardStruct *IOCard);
int TestNIMTTLCard (IOCardStruct *IOCard);
int GetIOCardStatus(IOCardStruct *IOCard);
......
......@@ -538,29 +538,7 @@ void PiLC2WSPI(unsigned int card, unsigned int reg, 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");
......@@ -573,7 +551,7 @@ void WriteIOConfig(unsigned int *data) {
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]);
}
}
......
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