Commit 52a1e3ff authored by Joshua Supra's avatar Joshua Supra
Browse files

added documentation

parent 6fca5770
/******************************************************************************/
/**
*
* @file pilc_IO_GPIO.c
* @file pilc2_IO_GPIO.c
*
* This file contains the implementation of initialisation of the PiLC2 and the
* IO card functions.
......@@ -26,8 +26,6 @@
#include "pilc2_IO_mux.h"
#include "pilc2_logic.h"
/******************************************************************************/
/**
*
......
/******************************************************************************/
/**
*
* @file pilc_IO_GPIO.h
* @file pilc2_IO_GPIO.h
*
* This file contains the functions declariation for the PiLC IO GPIO.
*
......@@ -84,6 +84,7 @@ unsigned int WorkLEDcounter;
/*************************** Function Prototypes ******************************/
void initpilc2(IOCardStruct *IOCard);
void deinitpilc2(void);
int GetGpioConfig(pilcIOGpioStruct *pilcIOcfg);
......
/******************************************************************************/
/**
*
* @file pilc2_IO_Leds.c
*
* This file contains the implementation of the driver for the PiLC2 IO LEDs.
*
*******************************************************************************/
/***************************** Include Files **********************************/
#include "pilc2_IO_Leds.h"
#include "pilc2_register_func.h"
#include <pthread.h>
#include <unistd.h>
#include <stdio.h>
void WriteFrontLED (unsigned char LED, unsigned char Red, unsigned char Green, unsigned char Blue){
/******************************************************************************/
/**
*
* This function sets the color of the addressed front panel LED to the value
* defined by Red, Green and Blue.
*
* @param LED - Selected front panel LED
* @param Red - value for the color red
* @param Green - value for the color green
* @param Blue - value for the color blue
*
* @return None.
*
*
*******************************************************************************/
void WriteFrontLED (unsigned char LED, unsigned char Red, unsigned char Green,
unsigned char Blue)
{
WriteFPGA(FP_LED_OFFSET+LED, Blue<<16|Red<<8|Green);
//printf("0x%.8X, 0x%.2X, 0x%.2X, 0x%.2X\n",FP_LED_OFFSET+LED, Blue, Red, Green);
}
void RGBFadeLEDs (int fadetime, char status){
if(status == FADE_ON){
pthread_t thread_id;
pthread_create(&thread_id, NULL, FadeLEDsThreadRGB, NULL);
}else{
//pthread_cancel(&thread_id);
}
}
int deinit_IOleds(void){
/******************************************************************************/
/**
*
* This function sets the color of all panel LEDs to zero.
*
* @return 0.
*
*
*******************************************************************************/
int deinit_IOleds(void)
{
for (int i = 0; i < NUMBER_OF_LEDS; i++){
WriteFrontLED(i, 0, 0, 0);
}
return 0;
}
void InhibitFrontLED(unsigned int led_mask) {
//printf("%.8x %.8x\n", FP_LED_OFFSET+FP_LED_INHIBIT, led_mask);
/******************************************************************************/
/**
*
* This function sets the inhibit bit for front panel LEDs addressed by the led
* mask. Every LED can be addressed individually.
*
* @param led_mask - Inhibit mask for the front panel LEDs
*
* @return None.
*
*
*******************************************************************************/
void InhibitFrontLED(unsigned int led_mask)
{
WriteFPGA(FP_LED_OFFSET+FP_LED_INHIBIT, led_mask);
}
void *FadeLEDsThreadRGB (void *vargp){
while(1){
for(int k = 0; k < MAX_BRIGHTNESS; k++){
for (int i = 0; i<=17; i++){
WriteFrontLED(i, MAX_BRIGHTNESS , 0, k);
}
usleep(100000);
}
for(int k = MAX_BRIGHTNESS; k > 0; k--){
for (int i = 0; i<=17; i++){
WriteFrontLED(i, k , 0, MAX_BRIGHTNESS);
}
usleep(100000);
}
for(int k = 0; k < MAX_BRIGHTNESS; k++){
for (int i = 0; i<=17; i++){
WriteFrontLED(i, 0 , k, MAX_BRIGHTNESS);
}
usleep(100000);
}
for(int k = MAX_BRIGHTNESS; k>0; k--){
for (int i = 0; i<=17; i++){
WriteFrontLED(i, 0 , MAX_BRIGHTNESS, k);
}
usleep(100000);
}
for(int k = 0; k< MAX_BRIGHTNESS; k++){
for (int i = 0; i<=17; i++){
WriteFrontLED(i, k , MAX_BRIGHTNESS, 0);
}
usleep(100000);
}
for(int k = MAX_BRIGHTNESS; k>0; k--){
for (int i = 0; i<=17; i++){
WriteFrontLED(i, MAX_BRIGHTNESS , k, 0);
}
usleep(100000);
}
}
}
/******************************************************************************/
/**
*
* @file pilc2_IO_Leds.h
*
* This file contains the functions declariation for the PiLC IO Leds.
*
*******************************************************************************/
/*************************** Constant Definitions *****************************/
/**Frontpanel LEDs**/
#define FP_LED_OFFSET (0x300>>2)
#define FP_LED_0 FP_LED_OFFSET+0x0
......@@ -22,20 +31,12 @@
#define FP_LED_17 FP_LED_OFFSET+0x11
#define FP_LED_INHIBIT 0x12
#define FADE_ON 0x01
#define FADE_OFF 0x00
#define NUMBER_OF_LEDS 18
#define MAX_BRIGHTNESS 20
/*************************** Function Prototypes ******************************/
void WriteFrontLED (unsigned char LED, unsigned char Red, unsigned char Green, unsigned char Blue);
void RGBFadeLEDs (int fadetime, char status);
void *FadeLEDsThreadMonoCol (void *vargp);
void *FadeLEDsThreadRGB (void *vargp);
void WriteFrontLED (unsigned char LED, unsigned char Red, unsigned char Green,
unsigned char Blue);
int deinit_IOleds(void);
void InhibitFrontLED(unsigned int led_mask);
/******************************************************************************/
/**
*
* @file pilc2_IO_mux.c
*
* This file contains the implementation of the driver for the PiLC2 IO
* multiplexer.
*
*******************************************************************************/
/***************************** Include Files **********************************/
#include "pilc2_IO_mux.h"
#include "pilc2_register_func.h"
#include "pilc2_IO_GPIOs.h"
#include "pilc2_SPI_func.h"
#include <stdio.h>
/******************************************************************************/
/**
*
* Sets the config to the addressed IO channel.
*
* @param channel - Selected IOchannel
* @param config - config to be written for the selected IO channel
*
* @return None.
*
*
*******************************************************************************/
void setIOMuxCfg(char channel, unsigned int config) {
WriteFPGA(PILC_IO_MUX_OFFSET+channel, config);
}
/******************************************************************************/
/**
*
* Read the config of the addressed IO channel.
*
* @param channel - Selected IOchannel
*
* @return Ćonfig of the selected IO channel
*
*
*******************************************************************************/
unsigned int getIOMuxCfg(char channel) {
int IOMuxCfg = ReadFPGA(PILC_IO_MUX_OFFSET+channel);
......@@ -17,11 +52,27 @@ unsigned int getIOMuxCfg(char channel) {
return IOMuxCfg;
}
/******************************************************************************/
/**
*
* Autoconfig configures the IO multiplexer according to the inserted IO card in
* each channel. If a NIM TTL card is inserted additional config may be required.
* If there is no valid config for a NIM TTL card available the default config
* (input TTL counter module) will be loaded for this channel.
*
* @param *IOCard - Pointer to the IOCardStruct struct.
*
* @return None.
*
*
*******************************************************************************/
void IOMuxAutoConfig(IOCardStruct *IOCard) {
int IsConfig = 0;
FILE *fp;
int buffer[64];
/* Check if a valid config is available on the PiLC2 */
if ((fp = fopen("/home/suprajos/pilc2/pilc2server/iocfg", "rb"))) {
fread(buffer,64*sizeof(int),4,fp);
......@@ -35,6 +86,10 @@ void IOMuxAutoConfig(IOCardStruct *IOCard) {
IsConfig = 0;
}
/* Write the config to the IO mux depending on the inserted card. If no
* config is available and inserted card is type NIM TTL it will be
* configured as TTL input for the counter moduel */
for(int i = 0; i<16; i++){
switch(IOCard[i].TypeID) {
......
/******************************************************************************/
/**
*
* @file pilc2_IO_mux.h
*
* This file contains the functions declariation for the PiLC IO multiplexer.
*
*******************************************************************************/
/***************************** Include Files **********************************/
#include "pilc2_IO_GPIOs.h"
/*************************** Constant Definitions *****************************/
#define PILC_IO_MUX_OFFSET (0x8000>>2)
#define PILC_IO_MUX_CFG_CH_0 0x0
......@@ -30,6 +40,8 @@
#define IO_MUX_CFG_ENCODER 0x9
#define IO_MUX_CFG_LOGIC 0xA
/*************************** Function Prototypes ******************************/
void setIOMuxCfg(char channel, unsigned int config);
unsigned int getIOMuxCfg(char channel);
void IOMuxAutoConfig(IOCardStruct *IOCard);
/*****************************************************************************/
/**
*
* @file pilc2_bram_controller.h
*
* This file contains he functions declariation for the driver functions of the
* PiLC2 BRAM controller.
*
******************************************************************************/
/************************** Constant Definitions *****************************/
......
/******************************************************************************/
/**
*
* @file pilc_cdma.c
*
* This file contains the implementation the PiLC2 cdma driver.
*
*******************************************************************************/
/***************************** Include Files **********************************/
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
#include "pilc2_cdma.h"
/*****************************************************************************/
/**
*
* Initialisatoin function for the axi gpio. The gpio will be granted access
* Initialisatoin function for the cdma. The cdma will be granted access
* in the user and the device will be memory mapped to user space.
*
*
* @param uiod pointer to the UIO device file
*
* gpio_ptr pointer to mmap device in user space
* @param cdma_ptr pointer to mmap device in user space
*
* @return None.
*
* @note None.
*
******************************************************************************/
int PiLC2CDMAInit(char *uiod, void **cdma_ptr){
int PiLC2CDMAInit(char *uiod, void **cdma_ptr)
{
unsigned int fd;
/* open the UIO device file to allow access to the device in user
......@@ -52,14 +57,12 @@ int PiLC2CDMAInit(char *uiod, void **cdma_ptr){
/**
*
* Function to write a 32 bit value into the specified register of the axi
* GPIO.
* cdma.
*
*
* @param axi_gpio_base is the base address of the axi gpio.
*
* offset is the register offset where value will be written.
*
* value the 32 bit value to be written at specified address.
* @param cdma_base is the base address of the axi cdma.
* @param offset is the register offset where the value will be written.
* @param value the 32 bit value to be written at specified address.
*
* @return None.
*
......@@ -76,13 +79,12 @@ void PiLC2CDMAWrite(void *cdma_base, unsigned int offset,
/*****************************************************************************/
/**
*
* FThis function reads a 32 bit value from a specified register of the axi
* gpio.
* This function reads a 32 bit value from a specified register of the axi
* cdma.
*
*
* @param axi_gpio_base is the base address of the axi gpio.
*
* offset is the register offset where value will be read.
* @param cdma_base is the base address of the axi cdma.
* @param offset is the register offset where value will be read.
*
* @return The value of the specified register.
*
......@@ -95,12 +97,26 @@ unsigned int PiLC2CDMARead(void *cdma_base, unsigned int offset)
}
int dma_sync(void *cdma_base){
unsigned int cdma_status = PiLC2CDMARead(cdma_base, CDMA_STATUS_REGISTER_OFFSET);
//while(!(cdma_status & 1<<12) || !(cdma_status & 1<<1)){
/*****************************************************************************/
/**
*
* Synchronisation function for the cdma engine. This function checks if data
* copy is still in progress.
*
*
* @param cdma_base is the base address of the axi cdma.
* @param offset is the register offset where value will be read.
*
* @return The value of the specified register.
*
* @note None.
*
******************************************************************************/
int dma_sync(void *cdma_base)
{
unsigned int cdma_status = PiLC2CDMARead(cdma_base,
CDMA_STATUS_REGISTER_OFFSET);
while(!(cdma_status & 1<<1)){
//dma_status(dma_virtual_address);
cdma_status = PiLC2CDMARead(cdma_base, CDMA_STATUS_REGISTER_OFFSET);
}
......
/******************************************************************************/
/**
*
* @file pilc2_cdma.h
*
* This file contains the functions declariation for the PiLC2 cdma driver.
*
*******************************************************************************/
#ifndef PILC2_CMDA_H
#define PILC2_CMDA_H
/*************************** Constant Definitions *****************************/
#define CDMA_MAP_SIZE 0x1000
#define CDMA_CONTROL_REGISTER_OFFSET 0x0
#define CDMA_STATUS_REGISTER_OFFSET 0x4
......@@ -11,15 +22,18 @@
char *uiod_cdma;
unsigned int dma_set(unsigned int* dma_virtual_address, int offset, unsigned int value);
unsigned int dma_set(unsigned int* dma_virtual_address, int offset,
unsigned int value);
unsigned int dma_get(unsigned int* dma_virtual_address, int offset);
void dma_status(unsigned int* dma_virtual_address);
/*************************** Function Prototypes ******************************/
int PiLC2CDMAInit(char *uiod, void **cdma_ptr);
void PiLC2CDMAWrite(void *cdma_base, unsigned int offset,
unsigned int value);
unsigned int PiLC2CDMARead(void *cdma_base, unsigned int offset);
int dma_sync(void *cdma_base);
#endif
......@@ -22,13 +22,10 @@
* generation DDS and the if set the internal gate counter.
*
*
* @param NrOfCounter number of used counter in the PiLC2
*
* config the counter module mode of operation
*
* internal_gate_counter is the number of gates to be counted
*
* int_gate_gen_dds tuning word for the internal gate generator DDS
* @param NrOfCounter number of used counter in the PiLC2
* @param config the counter module mode of operation
* @param internal_gate_counter is the number of gates to be counted
* @param int_gate_gen_dds tuning word for the internal gate generator DDS
*
* @return None
*
......@@ -239,7 +236,18 @@ void PiLC2CounterDisableCounter(void){
WriteFPGA(PILC2_CTR_MOD_OFFSET+PILC2_CTR_MOD_CTRLREG_OFFSET, reg&~mask);
}
/*****************************************************************************/
/**
*
* This function disables the PiLC2 counter module by setting the counter enable
* bit to 0.
*
*
* @return The status of the counter module control register
*
* @note None.
*
******************************************************************************/
unsigned int PiLC2CounterGetStatus(void){
unsigned int value;
......
/******************************************************************************/
/**
*
* @file pilc2_dac.c
*
* This file contains the implementation of initialisation of the PiLC2 DAC.
*
*******************************************************************************/
/***************************** Include Files **********************************/
#include "pilc2_dac.h"
#include "pilc2_register_func.h"
/******************************************************************************/
/**
*
* This function sets the DAC value for the adressed dac channel.
*
* @param DACchannel - Selected DAC channel
* @param value - value to be written in selected dac channel output
*
* @return None.
*
*
*******************************************************************************/
void setDACvalue(unsigned int DACchannel, unsigned int value) {
WriteFPGA(PILC_DAC_OFFSET+DACchannel, value);
}
/******************************************************************************/
/**
*
* Reads the current setpoint for the addressed DAC channel.
*
* @param DACchannel - Selected DAC channel
*
* @return Setpoint value of the selected DAC channel
*
*
*******************************************************************************/
unsigned int getDACvalue(unsigned int DACchannel) {
unsigned int value = ReadFPGA(PILC_DAC_OFFSET+DACchannel);
......
/******************************************************************************/
/**
*
* @file pilc2_dac.h
*
* This file contains the functions declariation for the PiLC dac.
*
*******************************************************************************/
/*************************** Constant Definitions *****************************/
#define PILC_DAC_OFFSET (0x4000>>2)
#define PILC_DAC_CH_0 0x0
......@@ -18,7 +27,7 @@
#define PILC_DAC_CH_14 0x14
#define PILC_DAC_CH_15 0x15
/*************************** Function Prototypes ******************************/
void setDACvalue(unsigned int DACchannel, unsigned int value);
unsigned int getDACvalue(unsigned int DACchannel);
/******************************************************************************/
/**
*
* @file pilc_dadc.c
*
* This file contains the implementation of initialisation of the PiLC2 DADC.
*
*******************************************************************************/
/***************************** Include Files **********************************/
#include "pilc2_dadc.h"
#include "pilc2_register_func.h"
/******************************************************************************/
/**
*
* This function reads the DADC value for the adressed dac channel.
*
* @param DADCchannel - Selected DAC channel
*
* @return The current value of the addressed DADC channel
*
*
*******************************************************************************/
int getDADCvalue(char DADCchannel) {
int dadc_value = ReadFPGA(PILC_DADC_OFFSET+PILC_DADC_VAL_OFFSET+DADCchannel);
return dadc_value;
}