Commit c19c38ce authored by Alessandro Rubini's avatar Alessandro Rubini

lib: rename files, move code. No tech change

Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent b42fa00f
......@@ -2,15 +2,14 @@
ZIO ?= ../zio
LIB = libfmcadc.a
LOBJ := fmcadc-lib-route.o
LOBJ := route.o
LOBJ += boards.o
LOBJ += fmcadc-lib-zio.o
CFLAGS = -Wall -ggdb -O2 -I../kernel -I$(ZIO)/include
LDFLAGS = -L. -lfmcadc
modules all: lib
lib: $(LIB)
modules all: $(LIB)
%: %.c $(LIB)
......
/*
* All the boards in the library
*
* Copyright (C) 2013 CERN (www.cern.ch)
* Author: Federico Vaga <federico.vaga@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* version 2 as published by the Free Software Foundation or, at your
* option, any later version.
*/
#include <string.h>
#include <errno.h>
#include "fmcadc-lib.h"
#include "fmcadc-lib-int.h"
#define FMCADC_ZIO_TRG_MASK (1LL << FMCADC_CONF_TRG_SOURCE) | \
(1LL << FMCADC_CONF_TRG_SOURCE_CHAN) | \
(1LL << FMCADC_CONF_TRG_THRESHOLD) | \
(1LL << FMCADC_CONF_TRG_POLARITY) | \
(1LL << FMCADC_CONF_TRG_DELAY)
#define FMCADC_ZIO_ACQ_MASK (1LL << FMCADC_CONF_ACQ_N_SHOTS) | \
(1LL << FMCADC_CONF_ACQ_POST_SAMP) | \
(1LL << FMCADC_CONF_ACQ_PRE_SAMP) | \
(1LL << FMCADC_CONF_ACQ_DECIMATION) | \
(1LL << FMCADC_CONF_ACQ_FREQ_HZ) | \
(1LL << FMCADC_CONF_ACQ_N_BITS)
#define FMCADC_ZIO_CHN_MASK (1LL << FMCADC_CONF_CHN_RANGE) | \
(1LL << FMCADC_CONF_CHN_TERMINATION) | \
(1LL << FMCADC_CONF_CHN_OFFSET)
#define FMCADC_ZIO_BRD_MASK (1LL << FMCADC_CONF_BRD_STATE_MACHINE_STATUS) | \
(1LL << FMCADC_CONF_BRD_N_CHAN)
struct fmcadc_op fa_100ms_4ch_14bit_op = {
.open = fmcadc_zio_open,
.open_by_lun = fmcadc_zio_open_by_lun,
.close = fmcadc_zio_close,
.start_acquisition = fmcadc_zio_start_acquisition,
.stop_acquisition = fmcadc_zio_stop_acquisition,
.apply_config = fmcadc_zio_apply_config,
.retrieve_config = fmcadc_zio_retrieve_config,
.request_buffer = fmcadc_zio_request_buffer,
.release_buffer = fmcadc_zio_release_buffer,
};
struct fmcadc_board_type fmcadc_100ms_4ch_14bit = {
.name = "fmcadc_100MS_4ch_14bit",
.devname = "adc-100m14b",
.driver_type = "zio",
.capabilities = {
FMCADC_ZIO_TRG_MASK,
FMCADC_ZIO_ACQ_MASK,
FMCADC_ZIO_CHN_MASK,
FMCADC_ZIO_BRD_MASK,
},
.fa_op = &fa_100ms_4ch_14bit_op,
};
/* fmcadc_open
* @name: name of the device type to open
* @dev_id: device identificator of a particular device connected to the system
*/
struct fmcadc_dev *fmcadc_open(char *name, unsigned int dev_id,
unsigned long buffersize,
unsigned int nbuffer,
unsigned long flags)
{
struct fmcadc_dev *dev = NULL;
int i, found = 0;
/* name cannot be NULL */
if (!name)
return NULL;
/* Look in the list of supported board if the "name" board is there */
for (i = 0; i < __FMCADC_SUPPORTED_BOARDS_LAST_INDEX; ++i) {
if (!strcmp(name, fmcadc_board_types[i]->name)) {
found = 1;
break;
}
}
if (!found) {
errno = ENODEV;
return NULL; /* Not found */
}
/* The library supports this board */
if (fmcadc_board_types[i]->fa_op && fmcadc_board_types[i]->fa_op->open) {
dev = fmcadc_board_types[i]->fa_op->open(fmcadc_board_types[i],
dev_id, flags);
} else {
errno = FMCADC_ENOP;
}
return dev;
}
/*
* fmcadc_open_by_lun
* @name: name of the device type to open
* @lun: Logical Unit Number of the device
*
* TODO
*/
struct fmcadc_dev *fmcadc_open_by_lun(char *name, int lun,
unsigned long buffersize,
unsigned int nbuffer,
unsigned long flags)
{
if (!name)
return NULL;
return NULL;
}
/*
* fmcadc_close
* @dev: the device to close
*/
int fmcadc_close(struct fmcadc_dev *dev)
{
struct fmcadc_gid *b = (void *)dev;
if (!dev) {
/* dev cannot be NULL */
errno = EINVAL;
return -1;
}
if (b->board->fa_op->close) {
return b->board->fa_op->close(dev);
} else {
errno = FMCADC_ENOP;
return -1;
}
}
......@@ -106,4 +106,31 @@ struct fmcadc_gid {
/* Definition of board types */
extern struct fmcadc_board_type fmcadc_100ms_4ch_14bit;
/* The following functions are defined in fmc-adc-zio, at the time being */
struct fmcadc_dev *fmcadc_zio_open(const struct fmcadc_board_type *dev,
unsigned int dev_id,
unsigned int details);
struct fmcadc_dev *fmcadc_zio_open_by_lun(char *name, int lun);
int fmcadc_zio_close(struct fmcadc_dev *dev);
int fmcadc_zio_start_acquisition(struct fmcadc_dev *dev,
unsigned int flags, struct timeval *timeout);
int fmcadc_zio_stop_acquisition(struct fmcadc_dev *dev,
unsigned int flags);
int fmcadc_zio_apply_config(struct fmcadc_dev *dev, unsigned int flags,
struct fmcadc_conf *conf);
int fmcadc_zio_retrieve_config(struct fmcadc_dev *dev,
struct fmcadc_conf *conf);
struct fmcadc_buffer *fmcadc_zio_request_buffer(struct fmcadc_dev *dev,
int nsamples,
void *(*alloc)(size_t),
unsigned int flags,
struct timeval *timeout);
int fmcadc_zio_release_buffer(struct fmcadc_dev *dev,
struct fmcadc_buffer *buf,
void (*free_fn)(void *));
#endif /* FMCADC_LIB_INT_H_ */
/*
* Initializing and cleaning up the fmc adc library
* The ADC library for a ZIO device (100MS-14bit-4-cha by now)
*
* Copyright (C) 2013 CERN (www.cern.ch)
* Author: Federico Vaga <federico.vaga@gmail.com>
......@@ -157,10 +157,10 @@ static int fa_zio_sysfs_set(struct __fmcadc_dev_zio *fa, char *name,
/* * * * * * * * * * Library Operations Implementation * * * * * * * * * * */
static int fmcadc_zio_stop_acquisition(struct fmcadc_dev *dev,
int fmcadc_zio_stop_acquisition(struct fmcadc_dev *dev,
unsigned int flags);
static struct fmcadc_dev *fmcadc_zio_open(const struct fmcadc_board_type *dev,
struct fmcadc_dev *fmcadc_zio_open(const struct fmcadc_board_type *dev,
unsigned int dev_id,
unsigned int details)
{
......@@ -229,12 +229,12 @@ out_fa_stat:
return NULL ;
}
static struct fmcadc_dev *fmcadc_zio_open_by_lun(char *name, int lun)
struct fmcadc_dev *fmcadc_zio_open_by_lun(char *name, int lun)
{
/* TODO implement*/
return NULL ;
}
static int fmcadc_zio_close(struct fmcadc_dev *dev)
int fmcadc_zio_close(struct fmcadc_dev *dev)
{
struct __fmcadc_dev_zio *fa = to_dev_zio(dev);
......@@ -255,7 +255,7 @@ static int fmcadc_zio_close(struct fmcadc_dev *dev)
return 0;
}
/* Handle acquisition */
static int fmcadc_zio_start_acquisition(struct fmcadc_dev *dev,
int fmcadc_zio_start_acquisition(struct fmcadc_dev *dev,
unsigned int flags, struct timeval *timeout)
{
struct __fmcadc_dev_zio *fa = to_dev_zio(dev);
......@@ -291,7 +291,7 @@ static int fmcadc_zio_start_acquisition(struct fmcadc_dev *dev,
return err;
}
}
static int fmcadc_zio_stop_acquisition(struct fmcadc_dev *dev,
int fmcadc_zio_stop_acquisition(struct fmcadc_dev *dev,
unsigned int flags)
{
struct __fmcadc_dev_zio *fa = to_dev_zio(dev);
......@@ -511,7 +511,7 @@ static int fmcadc_zio_config(struct __fmcadc_dev_zio *fa, unsigned int flags,
return 0;
}
static int fmcadc_zio_apply_config(struct fmcadc_dev *dev, unsigned int flags,
int fmcadc_zio_apply_config(struct fmcadc_dev *dev, unsigned int flags,
struct fmcadc_conf *conf)
{
struct __fmcadc_dev_zio *fa = to_dev_zio(dev);
......@@ -519,7 +519,7 @@ static int fmcadc_zio_apply_config(struct fmcadc_dev *dev, unsigned int flags,
return fmcadc_zio_config(fa, flags, conf, FMCADC_CONF_SET);
}
static int fmcadc_zio_retrieve_config(struct fmcadc_dev *dev,
int fmcadc_zio_retrieve_config(struct fmcadc_dev *dev,
struct fmcadc_conf *conf)
{
struct __fmcadc_dev_zio *fa = to_dev_zio(dev);
......@@ -639,7 +639,7 @@ out_ctrl:
return NULL;
}
static int fmcadc_zio_release_buffer(struct fmcadc_dev *dev,
int fmcadc_zio_release_buffer(struct fmcadc_dev *dev,
struct fmcadc_buffer *buf,
void (*free_fn)(void *))
{
......@@ -649,45 +649,3 @@ static int fmcadc_zio_release_buffer(struct fmcadc_dev *dev,
return 0;
}
/* * * * * * * * * * * * * * * * * Boards definition * * * * * * * * * * * * */
#define FMCADC_ZIO_TRG_MASK (1LL << FMCADC_CONF_TRG_SOURCE) | \
(1LL << FMCADC_CONF_TRG_SOURCE_CHAN) | \
(1LL << FMCADC_CONF_TRG_THRESHOLD) | \
(1LL << FMCADC_CONF_TRG_POLARITY) | \
(1LL << FMCADC_CONF_TRG_DELAY)
#define FMCADC_ZIO_ACQ_MASK (1LL << FMCADC_CONF_ACQ_N_SHOTS) | \
(1LL << FMCADC_CONF_ACQ_POST_SAMP) | \
(1LL << FMCADC_CONF_ACQ_PRE_SAMP) | \
(1LL << FMCADC_CONF_ACQ_DECIMATION) | \
(1LL << FMCADC_CONF_ACQ_FREQ_HZ) | \
(1LL << FMCADC_CONF_ACQ_N_BITS)
#define FMCADC_ZIO_CHN_MASK (1LL << FMCADC_CONF_CHN_RANGE) | \
(1LL << FMCADC_CONF_CHN_TERMINATION) | \
(1LL << FMCADC_CONF_CHN_OFFSET)
#define FMCADC_ZIO_BRD_MASK (1LL << FMCADC_CONF_BRD_STATE_MACHINE_STATUS) | \
(1LL << FMCADC_CONF_BRD_N_CHAN)
struct fmcadc_op fa_100ms_4ch_14bit_op = {
.open = fmcadc_zio_open,
.open_by_lun = fmcadc_zio_open_by_lun,
.close = fmcadc_zio_close,
.start_acquisition = fmcadc_zio_start_acquisition,
.stop_acquisition = fmcadc_zio_stop_acquisition,
.apply_config = fmcadc_zio_apply_config,
.retrieve_config = fmcadc_zio_retrieve_config,
.request_buffer = fmcadc_zio_request_buffer,
.release_buffer = fmcadc_zio_release_buffer,
};
struct fmcadc_board_type fmcadc_100ms_4ch_14bit = {
.name = "fmcadc_100MS_4ch_14bit",
.devname = "adc-100m14b",
.driver_type = "zio",
.capabilities = {
FMCADC_ZIO_TRG_MASK,
FMCADC_ZIO_ACQ_MASK,
FMCADC_ZIO_CHN_MASK,
FMCADC_ZIO_BRD_MASK,
},
.fa_op = &fa_100ms_4ch_14bit_op,
};
......@@ -5,6 +5,9 @@
#ifndef FMCADC_LIB_H_
#define FMCADC_LIB_H_
#include <stdint.h>
#include <stdlib.h>
#include <sys/time.h>
/* Error codes start from 1024 to void conflicting with libc codes */
#define __FMCADC_ERRNO_START 1024
......
/*
* Initializing and cleaning up the fmc adc library
* Routing public functions to device-specific code
*
* Copyright (C) 2013 CERN (www.cern.ch)
* Author: Federico Vaga <federico.vaga@gmail.com>
......@@ -28,85 +28,6 @@ const struct fmcadc_board_type
/* * * * * * * * * * * * * * * * * Handle Device * * * * * * * * * * * * * */
/* fmcadc_open
* @name: name of the device type to open
* @dev_id: device identificator of a particular device connected to the system
*/
struct fmcadc_dev *fmcadc_open(char *name, unsigned int dev_id,
unsigned long buffersize,
unsigned int nbuffer,
unsigned long flags)
{
struct fmcadc_dev *dev = NULL;
int i, found = 0;
/* name cannot be NULL */
if (!name)
return NULL;
/* Look in the list of supported board if the "name" board is there */
for (i = 0; i < __FMCADC_SUPPORTED_BOARDS_LAST_INDEX; ++i) {
if (!strcmp(name, fmcadc_board_types[i]->name)) {
found = 1;
break;
}
}
if (!found) {
errno = ENODEV;
return NULL; /* Not found */
}
/* The library supports this board */
if (fmcadc_board_types[i]->fa_op && fmcadc_board_types[i]->fa_op->open) {
dev = fmcadc_board_types[i]->fa_op->open(fmcadc_board_types[i],
dev_id, flags);
} else {
errno = FMCADC_ENOP;
}
return dev;
}
/*
* fmcadc_open_by_lun
* @name: name of the device type to open
* @lun: Logical Unit Number of the device
*
* TODO
*/
struct fmcadc_dev *fmcadc_open_by_lun(char *name, int lun,
unsigned long buffersize,
unsigned int nbuffer,
unsigned long flags)
{
if (!name)
return NULL;
return NULL;
}
/*
* fmcadc_close
* @dev: the device to close
*/
int fmcadc_close(struct fmcadc_dev *dev)
{
struct fmcadc_gid *b = (void *)dev;
if (!dev) {
/* dev cannot be NULL */
errno = EINVAL;
return -1;
}
if (b->board->fa_op->close) {
return b->board->fa_op->close(dev);
} else {
errno = FMCADC_ENOP;
return -1;
}
}
/* * * * * * * * * * * * * * * Handle Acquisition * * * * * * * * * * * * * */
/*
......
Markdown is supported
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