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

.

parent 4f6ddc0f
/*****************************************************************************/
/******************************************************************************/
/**
*
* @file pilc_2func.c
* @file pilc_IO_GPIO.c
*
* This file contains the implementation of initialisation of the PiLC2 and the
* IO card functions.
*
******************************************************************************/
*******************************************************************************/
/***************************** Include Files *********************************/
/***************************** Include Files **********************************/
#include <stdlib.h>
#include <stdio.h>
......@@ -28,7 +28,7 @@
/****************************************************************************/
/******************************************************************************/
/**
*
* Initialisation function for the PiLC 2. Calling the function will initialize
......@@ -40,7 +40,7 @@
*
* @note None.
*
*****************************************************************************/
*******************************************************************************/
void initpilc2(IOCardStruct *IOCard){
int status;
/*Initialize SPI */
......@@ -63,17 +63,16 @@ void initpilc2(IOCardStruct *IOCard){
}
/****************************************************************************/
/******************************************************************************/
/**
*
* Deinitialisation function for the PiLC 2. Calling the function will
* deinitialize the connectionto the FPGA Register space.
* checked.
*
*
* @return None
*
*****************************************************************************/
*******************************************************************************/
void deinitpilc2(void){
int status;
......@@ -85,19 +84,18 @@ void deinitpilc2(void){
}
}
/****************************************************************************/
/******************************************************************************/
/**
*
* This function reads the project config from the GPIO block in the FPGA
*
*
* @param *pilcIOcfg pointer to project config struct
* @param *pilcIOcfg - Pointer to project config struct
*
* @return 0 on success
*
* @note maybe deprecated
*
*****************************************************************************/
*******************************************************************************/
int GetGpioConfig(pilcIOGpioStruct *pilcIOcfg){
......@@ -112,17 +110,16 @@ int GetGpioConfig(pilcIOGpioStruct *pilcIOcfg){
}
/*****************************************************************************/
/******************************************************************************/
/**
*
* 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
* This function sets the IO card data direction register.
*
* @return The number of found IO cards.
* @param *IOCard - Pointer to the IOCardStruct array
*
* @return none
*
******************************************************************************/
*******************************************************************************/
void setIODDR(unsigned int channel, unsigned int config) {
int IODDRCfg = ReadFPGA(PILC_IO_GPIOS_OFFSET+PILC_IODDR_CFG_REG);
......@@ -140,15 +137,15 @@ void setIODDR(unsigned int channel, unsigned int config) {
/*****************************************************************************/
/**
*
* @brief This function reads every IO card slot via SPI and stores the card
* infomation in the IO card struct.
* 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
* @param *IOCard - Pointer to the IOCardStruct array
*
* @return The number of found IO cards.
*
*
******************************************************************************/
*******************************************************************************/
int InitIOCards (IOCardStruct *IOCard){
/* check each card slot for HW version */
......@@ -187,17 +184,17 @@ int InitIOCards (IOCardStruct *IOCard){
}
/*****************************************************************************/
/******************************************************************************/
/**
*
* @brief This function reads the status of each IO card.
*
* @param *IOCard is the pointer to the IOCardStruct array
* @param *IOCard - Pointer to the IOCardStruct array
*
* @return 0
*
*
******************************************************************************/
*******************************************************************************/
int GetIOCardStatus(IOCardStruct *IOCard)
{
unsigned int mask = 0x1;
......@@ -215,18 +212,18 @@ int GetIOCardStatus(IOCardStruct *IOCard)
}
/*****************************************************************************/
/******************************************************************************/
/**
*
* This function reads the register of each inserted card depending on their
* type and stores the value in the IOCardStruct.
*
* @param *IOCard is the pointer to the IOCardStruct array
* @param *IOCard - Pointer to the IOCardStruct array
*
* @return The number of found IO cards.
*
*
******************************************************************************/
*******************************************************************************/
int GetIOCardRegister(IOCardStruct *IOCard)
{
for (int i = 0; i<16; i++){
......@@ -263,25 +260,23 @@ int GetIOCardRegister(IOCardStruct *IOCard)
}
/*****************************************************************************/
/******************************************************************************/
/**
*
* 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
* @param channel - The IO channel to be addressed
*
* - direction is the set direction, 0: input 1: output
* @param direction - The set direction, 0: input 1: output
*
* - function sets the IO multiplexer
* @param function - Address for the IO multiplexer to assign the IP to IO
*
* - level can be either NIM or TTL
* @param level - Logic level standard of the IO card: NIM or TTL
*
* @return 0
*
* @note None.
*
******************************************************************************/
*******************************************************************************/
int setIOConfig(unsigned int channel, unsigned int direction,
unsigned int function, unsigned int level) {
......@@ -293,6 +288,18 @@ int setIOConfig(unsigned int channel, unsigned int direction,
return 0;
}
/******************************************************************************/
/**
*
* This function sets the IO leds according to the inserted IO card and its
* current register value.
*
* @param vargp - Pointer to the IOCardStruct passed by thread creation.
*
* @return none
*
*******************************************************************************/
void *updateIOLeds(void *vargp) {
IOCardStruct *IOCard = (IOCardStruct *)vargp;
......@@ -318,29 +325,24 @@ void *updateIOLeds(void *vargp) {
unsigned int led_brightness;
//unsigned int IO_status_mask_result;
for (int i = 0; i<16; i++){
for (int i = 0; i<16; i++){
/* if a card is present the card information will be printed */
led_color.Red = 0;
led_color.Blue = 0;
led_color.Green = 0;
if (IOCard[i].TypeID != 0x00 && IOCard[i].TypeID != 0xFF){
//printf("IOCard[%d]: %.2x\n", i, IOCard[i].TypeID);
switch(IOCard[i].TypeID) {
case NIM_TTL: if(IOCard[i].DataDirection ) {
led_color.Red = 8+IOCard[i].IOStatus*42;
led_color.Green = 0;
}else {
getNIMTTLcolour(i, &led_color);
//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;
case ADC: value_float = ((float)getADCvalue(i)/65535)*42;
......@@ -367,7 +369,6 @@ void *updateIOLeds(void *vargp) {
led_color.Blue = 8;break;
}
case ADAPTER: if (IOCard[i-1].TypeID == DIFF_ADC) {
//value_float = ((float)getDADCvalue((i-1)/2)/65535)*42;
value_int = getDADCvalue((i-1)/2)-131072;
if (value_int < 0 ) {
value_float = ((float)value_int/(-131072))*42;
......@@ -443,14 +444,25 @@ void *updateIOLeds(void *vargp) {
pthread_exit(NULL);
}
/******************************************************************************/
/**
*
* If a NIM/TTL card is inserted, this function checks the IO mux config to
* display the LED color correctly
*
* @param card_slot is the selected card slot
* @param *led_color pointer to the led_color_struct
*
* @return none
*
*******************************************************************************/
void getNIMTTLcolour(int card_slot, led_color_struct *led_color) {
unsigned int muxcfg;
unsigned int ABmask = 0xFF00;
unsigned int ABCmask = 0xFF0000;
unsigned int logicfg;
muxcfg = getIOMuxCfg(card_slot);
switch (muxcfg) {
case IO_MUX_CFG_CTR:
led_color->Green = 8;
......@@ -458,6 +470,8 @@ void getNIMTTLcolour(int card_slot, led_color_struct *led_color) {
case IO_MUX_CFG_ENCODER:
led_color->Green = 8;
break;
/* If logic mode is selected it is possible to not use all inputs,
* therefore only leds for enabled inputs have to be enabled */
case IO_MUX_CFG_LOGIC:
if (card_slot < 16) logicfg = GetLogicCfg(LOGIC_CFG_CH_3);
if (card_slot < 12) logicfg = GetLogicCfg(LOGIC_CFG_CH_2);
......
/******************************************************************************/
/**
*
* @file pilc_IO_GPIO.h
*
* This file contains the functions declariation for the PiLC IO GPIO.
*
*******************************************************************************/
#ifndef PILC2_FUNC_H
#define PILC2_FUNC_H
/*************************** Constant Definitions *****************************/
#define PILC_IO_GPIOS_OFFSET (0x000>>2)
#define PiLC_IOSTR 0x00
......@@ -43,12 +55,6 @@
#define PILC_IO_OUTPUT 0x1
void deinitpilc2(void);
int IOCardSelftest (void);
typedef struct {
unsigned char TypeID;
unsigned char HWVersion;
......@@ -74,10 +80,15 @@ typedef struct {
unsigned char Blue;
} led_color_struct;
IOCardStruct IOCards[16];
unsigned int WorkLEDcounter;
/*************************** Function Prototypes ******************************/
void initpilc2(IOCardStruct *IOCard);
void deinitpilc2(void);
int GetGpioConfig(pilcIOGpioStruct *pilcIOcfg);
void setIODDR(unsigned int channel, unsigned int config);
/**PILC2 Selftest IO card functions**/
int InitIOCards (IOCardStruct *IOCard);
int SelftestIOCards (IOCardStruct *IOCard);
int TestNIMTTLCard (IOCardStruct *IOCard);
......@@ -88,6 +99,5 @@ int setIOConfig(unsigned int channel, unsigned int direction,
unsigned int function, unsigned int level);
void getNIMTTLcolour(int card_slot, led_color_struct *led_color);
IOCardStruct IOCards[16];
unsigned int WorkLEDcounter;
#endif
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