Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
F
FMC TDC 1ns 5cha
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
FMC TDC 1ns 5cha
Commits
d7352716
Commit
d7352716
authored
Aug 17, 2013
by
Tomasz Wlostowski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
kernel, lib: reindented code according to kernel style
parent
f813f1e7
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
151 additions
and
144 deletions
+151
-144
fmc-tdc.h
kernel/fmc-tdc.h
+7
-7
ft-core.c
kernel/ft-core.c
+16
-16
ft-irq.c
kernel/ft-irq.c
+4
-3
ft-time.c
kernel/ft-time.c
+9
-7
ft-zio.c
kernel/ft-zio.c
+17
-15
onewire.c
kernel/onewire.c
+30
-28
fmctdc-lib-private.h
lib/fmctdc-lib-private.h
+6
-6
fmctdc-lib.c
lib/fmctdc-lib.c
+48
-50
fmctdc-lib.h
lib/fmctdc-lib.h
+14
-12
No files found.
kernel/fmc-tdc.h
View file @
d7352716
...
...
@@ -56,18 +56,18 @@ enum ft_zattr_in_idx {
};
enum
ft_command
{
FT_CMD_WR_ENABLE
=
0
,
/* Enable White Rabbit */
FT_CMD_WR_DISABLE
,
/* Disable it */
FT_CMD_WR_QUERY
,
/* Check if WR is locked */
FT_CMD_SET_HOST_TIME
,
/* Set board time to current host time */
FT_CMD_IDENTIFY_ON
,
/* Identify card by blinking status LEDs, reserved for future use. */
FT_CMD_WR_ENABLE
=
0
,
/* Enable White Rabbit */
FT_CMD_WR_DISABLE
,
/* Disable it */
FT_CMD_WR_QUERY
,
/* Check if WR is locked */
FT_CMD_SET_HOST_TIME
,
/* Set board time to current host time */
FT_CMD_IDENTIFY_ON
,
/* Identify card by blinking status LEDs, reserved for future use. */
FT_CMD_IDENTIFY_OFF
};
/* rest of the file is kernel-only */
#ifdef __KERNEL__
#define FT_USER_OFFSET_RANGE 1000000000
/* picoseconds */
#define FT_USER_OFFSET_RANGE 1000000000
/* picoseconds */
enum
ft_channel_flags
{
FT_FLAG_CH_TERMINATED
=
0
,
...
...
@@ -209,7 +209,7 @@ void ft_ts_sub(struct ft_wr_timestamp *a, struct ft_wr_timestamp *b);
int
ft_set_tai_time
(
struct
fmctdc_dev
*
ft
,
uint64_t
seconds
,
uint32_t
coarse
);
int
ft_get_tai_time
(
struct
fmctdc_dev
*
ft
,
uint64_t
*
seconds
,
uint32_t
*
coarse
);
int
ft_set_host_time
(
struct
fmctdc_dev
*
ft
);
int
ft_set_host_time
(
struct
fmctdc_dev
*
ft
);
int
ft_enable_wr_mode
(
struct
fmctdc_dev
*
ft
,
int
enable
);
int
ft_check_wr_mode
(
struct
fmctdc_dev
*
ft
);
...
...
kernel/ft-core.c
View file @
d7352716
...
...
@@ -70,7 +70,7 @@ static int ft_init_channel(struct fmctdc_dev *ft, int channel)
return
0
;
}
static
void
ft_reset_channel
(
struct
fmctdc_dev
*
ft
,
int
channel
)
static
void
ft_reset_channel
(
struct
fmctdc_dev
*
ft
,
int
channel
)
{
struct
ft_channel_state
*
st
=
&
ft
->
channels
[
channel
-
FT_CH_1
];
...
...
@@ -81,7 +81,7 @@ static void ft_reset_channel (struct fmctdc_dev *ft, int channel)
st
->
cur_seq_id
=
0
;
st
->
expected_edge
=
1
;
clear_bit
(
FT_FLAG_CH_INPUT_READY
,
&
st
->
flags
);
ft_zio_kill_buffer
(
ft
,
channel
);
ft_zio_kill_buffer
(
ft
,
channel
);
}
int
ft_enable_termination
(
struct
fmctdc_dev
*
ft
,
int
channel
,
int
enable
)
...
...
@@ -116,8 +116,8 @@ void ft_enable_acquisition(struct fmctdc_dev *ft, int enable)
uint32_t
ien
,
cmd
;
int
i
;
if
(
ft
->
acquisition_on
==
(
enable
?
1
:
0
))
return
;
if
(
ft
->
acquisition_on
==
(
enable
?
1
:
0
))
return
;
ien
=
ft_readl
(
ft
,
TDC_REG_INPUT_ENABLE
);
...
...
@@ -129,7 +129,7 @@ void ft_enable_acquisition(struct fmctdc_dev *ft, int enable)
cmd
=
TDC_CTRL_DIS_ACQ
;
}
spin_lock
(
&
ft
->
lock
);
spin_lock
(
&
ft
->
lock
);
ft_writel
(
ft
,
ien
,
TDC_REG_INPUT_ENABLE
);
ft_writel
(
ft
,
TDC_CTRL_CLEAR_DACAPO_FLAG
,
TDC_REG_CTRL
);
...
...
@@ -137,21 +137,21 @@ void ft_enable_acquisition(struct fmctdc_dev *ft, int enable)
ft
->
acquisition_on
=
enable
;
if
(
!
enable
)
{
/* when disabling acquisition, clear the FIFOs, reset width validation state
machine and sequence IDs */
if
(
!
enable
)
{
/* when disabling acquisition, clear the FIFOs, reset width validation state
machine and sequence IDs */
for
(
i
=
FT_CH_1
;
i
<=
FT_NUM_CHANNELS
;
i
++
)
ft_reset_channel
(
ft
,
i
);
for
(
i
=
FT_CH_1
;
i
<=
FT_NUM_CHANNELS
;
i
++
)
ft_reset_channel
(
ft
,
i
);
ft
->
prev_wr_ptr
=
ft
->
cur_wr_ptr
=
0
;
ft
->
prev_wr_ptr
=
ft
->
cur_wr_ptr
=
0
;
}
spin_unlock
(
&
ft
->
lock
);
spin_unlock
(
&
ft
->
lock
);
if
(
ft
->
verbose
)
dev_info
(
&
ft
->
fmc
->
dev
,
"acquisition is %s
\n
"
,
enable
?
"on"
:
"off"
);
if
(
ft
->
verbose
)
dev_info
(
&
ft
->
fmc
->
dev
,
"acquisition is %s
\n
"
,
enable
?
"on"
:
"off"
);
}
static
int
ft_channels_init
(
struct
fmctdc_dev
*
ft
)
...
...
@@ -335,7 +335,7 @@ int ft_probe(struct fmc_device *fmc)
ft
->
initialized
=
1
;
return
0
;
err:
err:
while
(
--
m
,
--
i
>=
0
)
if
(
m
->
exit
)
m
->
exit
(
ft
);
...
...
kernel/ft-irq.c
View file @
d7352716
...
...
@@ -153,8 +153,9 @@ static inline void process_timestamp(struct fmctdc_dev *ft,
(
diff
.
seconds
||
diff
.
coarse
>
12
||
(
diff
.
coarse
==
12
&&
diff
.
frac
>=
2048
)))
{
ft_ts_apply_offset
(
&
ts
,
ft
->
calib
.
zero_offset
[
channel
-
1
]);
ft
->
calib
.
zero_offset
[
channel
-
1
]);
if
(
st
->
user_offset
)
ft_ts_apply_offset
(
&
ts
,
...
...
@@ -282,7 +283,7 @@ static void ft_readout_tasklet(unsigned long arg)
}
}
out:
out:
/* ack the irq */
fmc_writel
(
ft
->
fmc
,
TDC_IRQ_TDC_TSTAMP
<<
ft
->
irq_shift
,
ft
->
ft_irq_base
+
TDC_REG_IRQ_STATUS
);
...
...
kernel/ft-time.c
View file @
d7352716
...
...
@@ -85,15 +85,17 @@ void ft_ts_apply_offset(struct ft_wr_timestamp *ts, int32_t offset_picos)
int
ft_set_tai_time
(
struct
fmctdc_dev
*
ft
,
uint64_t
seconds
,
uint32_t
coarse
)
{
if
(
ft
->
acquisition_on
)
/* can't change time when inputs are enabled */
return
-
EAGAIN
;
if
(
ft
->
acquisition_on
)
/* can't change time when inputs are enabled */
return
-
EAGAIN
;
if
(
ft
->
verbose
)
dev_info
(
&
ft
->
fmc
->
dev
,
"Setting TAI time to %lld:%d
\n
"
,
seconds
,
coarse
);
if
(
coarse
!=
0
)
dev_warn
(
&
ft
->
fmc
->
dev
,
"Warning: ignoring sub-second part (%d) when setting time.
\n
"
,
coarse
);
if
(
coarse
!=
0
)
dev_warn
(
&
ft
->
fmc
->
dev
,
"Warning: ignoring sub-second part (%d) when setting time.
\n
"
,
coarse
);
ft_writel
(
ft
,
seconds
&
0xffffffff
,
TDC_REG_START_UTC
);
ft_writel
(
ft
,
TDC_CTRL_LOAD_UTC
,
TDC_REG_CTRL
);
...
...
@@ -108,12 +110,12 @@ int ft_get_tai_time(struct fmctdc_dev *ft, uint64_t * seconds,
return
0
;
}
int
ft_set_host_time
(
struct
fmctdc_dev
*
ft
)
int
ft_set_host_time
(
struct
fmctdc_dev
*
ft
)
{
struct
timespec
local_ts
;
if
(
ft
->
acquisition_on
)
/* can't change time when inputs are enabled */
return
-
EAGAIN
;
if
(
ft
->
acquisition_on
)
/* can't change time when inputs are enabled */
return
-
EAGAIN
;
getnstimeofday
(
&
local_ts
);
...
...
kernel/ft-zio.c
View file @
d7352716
...
...
@@ -73,7 +73,7 @@ static enum ft_devtype __ft_get_type(struct device *dev)
void
ft_zio_kill_buffer
(
struct
fmctdc_dev
*
ft
,
int
channel
)
{
zio_trigger_abort_disable
(
&
ft
->
zdev
->
cset
[
channel
-
FT_CH_1
],
0
);
zio_trigger_abort_disable
(
&
ft
->
zdev
->
cset
[
channel
-
FT_CH_1
],
0
);
}
/* TDC input attributes: only the user offset is special */
...
...
@@ -145,7 +145,9 @@ static int ft_zio_info_get(struct device *dev, struct zio_attribute *zattr,
attr
[
FT_ATTR_DEV_COARSE
].
value
=
coarse
;
attr
[
FT_ATTR_DEV_SECONDS
].
value
=
(
uint32_t
)
seconds
;
*
usr_val
=
(
zattr
->
id
==
FT_ATTR_DEV_COARSE
?
coarse
:
(
uint32_t
)
seconds
);
*
usr_val
=
(
zattr
->
id
==
FT_ATTR_DEV_COARSE
?
coarse
:
(
uint32_t
)
seconds
);
return
0
;
}
case
FT_ATTR_DEV_ENABLE_INPUTS
:
...
...
@@ -176,8 +178,9 @@ static int ft_zio_conf_channel(struct device *dev, struct zio_attribute *zattr,
case
FT_ATTR_TDC_USER_OFFSET
:
user_offs
=
usr_val
;
if
(
user_offs
<
-
FT_USER_OFFSET_RANGE
||
user_offs
>
FT_USER_OFFSET_RANGE
)
return
-
EINVAL
;
if
(
user_offs
<
-
FT_USER_OFFSET_RANGE
||
user_offs
>
FT_USER_OFFSET_RANGE
)
return
-
EINVAL
;
spin_lock
(
&
ft
->
lock
);
st
->
user_offset
=
usr_val
;
spin_unlock
(
&
ft
->
lock
);
...
...
@@ -207,12 +210,12 @@ static int ft_zio_input(struct zio_cset *cset)
/* Ready for input. If there's already something, return it now */
if
(
ft_read_sw_fifo
(
ft
,
cset
->
index
+
1
,
cset
->
chan
)
==
0
)
{
return
0
;
/* don't call data_done, let the caller do it */
return
0
;
/* don't call data_done, let the caller do it */
}
/* Mark the active block is valid, and return EAGAIN */
set_bit
(
FT_FLAG_CH_INPUT_READY
,
&
st
->
flags
);
set_bit
(
FT_FLAG_CH_INPUT_READY
,
&
st
->
flags
);
return
-
EAGAIN
;
}
...
...
@@ -235,15 +238,14 @@ static int ft_zio_conf_set(struct device *dev, struct zio_attribute *zattr,
if
(
zattr
->
id
==
FT_ATTR_DEV_SECONDS
)
{
attr
[
FT_ATTR_DEV_SECONDS
].
value
=
usr_val
;
return
ft_set_tai_time
(
ft
,
attr
[
FT_ATTR_DEV_SECONDS
].
value
,
attr
[
FT_ATTR_DEV_COARSE
].
value
);
return
ft_set_tai_time
(
ft
,
attr
[
FT_ATTR_DEV_SECONDS
].
value
,
attr
[
FT_ATTR_DEV_COARSE
].
value
);
return
-
ENOTSUPP
;
}
else
if
(
zattr
->
id
==
FT_ATTR_DEV_ENABLE_INPUTS
)
{
attr
[
FT_ATTR_DEV_ENABLE_INPUTS
].
value
=
usr_val
?
1
:
0
;
ft_enable_acquisition
(
ft
,
usr_val
);
attr
[
FT_ATTR_DEV_ENABLE_INPUTS
].
value
=
usr_val
?
1
:
0
;
ft_enable_acquisition
(
ft
,
usr_val
);
}
/* Not command, nothing to do */
...
...
@@ -252,7 +254,7 @@ static int ft_zio_conf_set(struct device *dev, struct zio_attribute *zattr,
switch
(
usr_val
)
{
case
FT_CMD_SET_HOST_TIME
:
return
ft_set_host_time
(
ft
);
return
ft_set_host_time
(
ft
);
case
FT_CMD_WR_ENABLE
:
case
FT_CMD_WR_DISABLE
:
case
FT_CMD_WR_QUERY
:
...
...
kernel/onewire.c
View file @
d7352716
...
...
@@ -52,7 +52,7 @@
#define CMD_RECALL_EEPROM 0xB8
#define CMD_READ_POWER_SUPPLY 0xB4
#define FT_OW_PORT 0
/* what is this slow? */
#define FT_OW_PORT 0
/* what is this slow? */
static
void
ow_writel
(
struct
fmctdc_dev
*
ft
,
uint32_t
val
,
unsigned
long
reg
)
{
...
...
@@ -69,10 +69,10 @@ static int ow_reset(struct fmctdc_dev *ft, int port)
uint32_t
reg
,
data
;
data
=
((
port
<<
CSR_SEL_OFS
)
&
CSR_SEL_MSK
)
|
CSR_CYC_MSK
|
CSR_RST_MSK
;
|
CSR_CYC_MSK
|
CSR_RST_MSK
;
ow_writel
(
ft
,
data
,
R_CSR
);
while
(
ow_readl
(
ft
,
R_CSR
)
&
CSR_CYC_MSK
)
/* FIXME: timeout */
;
while
(
ow_readl
(
ft
,
R_CSR
)
&
CSR_CYC_MSK
)
/* FIXME: timeout */
;
reg
=
ow_readl
(
ft
,
R_CSR
);
return
~
reg
&
CSR_DAT_MSK
;
}
...
...
@@ -81,11 +81,11 @@ static int slot(struct fmctdc_dev *ft, int port, int bit)
{
uint32_t
reg
,
data
;
data
=
((
port
<<
CSR_SEL_OFS
)
&
CSR_SEL_MSK
)
|
CSR_CYC_MSK
|
(
bit
&
CSR_DAT_MSK
);
data
=
((
port
<<
CSR_SEL_OFS
)
&
CSR_SEL_MSK
)
|
CSR_CYC_MSK
|
(
bit
&
CSR_DAT_MSK
);
ow_writel
(
ft
,
data
,
R_CSR
);
while
(
ow_readl
(
ft
,
R_CSR
)
&
CSR_CYC_MSK
)
/* FIXME: timeout */
;
while
(
ow_readl
(
ft
,
R_CSR
)
&
CSR_CYC_MSK
)
/* FIXME: timeout */
;
reg
=
ow_readl
(
ft
,
R_CSR
);
return
reg
&
CSR_DAT_MSK
;
}
...
...
@@ -104,7 +104,7 @@ static int ow_read_byte(struct fmctdc_dev *ft, int port)
{
int
byte
=
0
,
i
;
for
(
i
=
0
;
i
<
8
;
i
++
)
for
(
i
=
0
;
i
<
8
;
i
++
)
byte
|=
(
read_bit
(
ft
,
port
)
<<
i
);
return
byte
;
}
...
...
@@ -114,34 +114,37 @@ static int ow_write_byte(struct fmctdc_dev *ft, int port, int byte)
int
data
=
0
;
int
i
;
for
(
i
=
0
;
i
<
8
;
i
++
){
for
(
i
=
0
;
i
<
8
;
i
++
)
{
data
|=
write_bit
(
ft
,
port
,
(
byte
&
0x1
))
<<
i
;
byte
>>=
1
;
}
return
0
;
/* success */
return
0
;
/* success */
}
static
int
ow_write_block
(
struct
fmctdc_dev
*
ft
,
int
port
,
uint8_t
*
block
,
int
len
)
static
int
ow_write_block
(
struct
fmctdc_dev
*
ft
,
int
port
,
uint8_t
*
block
,
int
len
)
{
int
i
;
for
(
i
=
0
;
i
<
len
;
i
++
)
for
(
i
=
0
;
i
<
len
;
i
++
)
ow_write_byte
(
ft
,
port
,
block
[
i
]);
return
0
;
}
static
int
ow_read_block
(
struct
fmctdc_dev
*
ft
,
int
port
,
uint8_t
*
block
,
int
len
)
static
int
ow_read_block
(
struct
fmctdc_dev
*
ft
,
int
port
,
uint8_t
*
block
,
int
len
)
{
int
i
;
for
(
i
=
0
;
i
<
len
;
i
++
)
for
(
i
=
0
;
i
<
len
;
i
++
)
block
[
i
]
=
ow_read_byte
(
ft
,
port
);
return
0
;
}
static
int
ds18x_read_serial
(
struct
fmctdc_dev
*
ft
)
{
if
(
!
ow_reset
(
ft
,
0
))
{
dev_err
(
&
ft
->
fmc
->
dev
,
"Failure in resetting one-wire channel
\n
"
);
if
(
!
ow_reset
(
ft
,
0
))
{
dev_err
(
&
ft
->
fmc
->
dev
,
"Failure in resetting one-wire channel
\n
"
);
return
-
EIO
;
}
...
...
@@ -151,7 +154,7 @@ static int ds18x_read_serial(struct fmctdc_dev *ft)
static
int
ds18x_access
(
struct
fmctdc_dev
*
ft
)
{
if
(
!
ow_reset
(
ft
,
0
))
if
(
!
ow_reset
(
ft
,
0
))
goto
out
;
if
(
0
)
{
...
...
@@ -175,7 +178,7 @@ static void __temp_command_and_next_t(struct fmctdc_dev *ft, int cfg_reg)
ds18x_access
(
ft
);
ow_write_byte
(
ft
,
FT_OW_PORT
,
CMD_CONVERT_TEMP
);
/* The conversion takes some time, so mark when will it be ready */
ms
=
94
*
(
1
<<
(
cfg_reg
>>
5
));
ms
=
94
*
(
1
<<
(
cfg_reg
>>
5
));
ft
->
next_t
=
jiffies
+
msecs_to_jiffies
(
ms
);
}
...
...
@@ -188,7 +191,7 @@ int ft_read_temp(struct fmctdc_dev *ft, int verbose)
/* If first conversion, ask for it first */
if
(
ft
->
next_t
==
0
)
__temp_command_and_next_t
(
ft
,
0x7f
/* we ignore: max time */
);
__temp_command_and_next_t
(
ft
,
0x7f
/* we ignore: max time */
);
/* Wait for it to be ready: (FIXME: we need a time policy here) */
j
=
jiffies
;
...
...
@@ -209,16 +212,16 @@ int ft_read_temp(struct fmctdc_dev *ft, int verbose)
printk
(
"%02x%c"
,
data
[
i
],
i
==
8
?
'\n'
:
':'
);
}
temp
=
((
int
)
data
[
1
]
<<
8
)
|
((
int
)
data
[
0
]);
if
(
temp
&
0x1000
)
if
(
temp
&
0x1000
)
temp
=
-
0x10000
+
temp
;
ft
->
temp
=
temp
;
ft
->
temp_ready
=
1
;
if
(
verbose
)
{
dev_info
(
dev
,
"%s: Temperature 0x%x (%i bits: %i.%03i)
\n
"
,
__func__
,
temp
,
9
+
(
data
[
4
]
>>
5
)
,
temp
/
16
,
(
temp
&
0xf
)
*
1000
/
16
);
dev_info
(
dev
,
"%s: Temperature 0x%x (%i bits: %i.%03i)
\n
"
,
__func__
,
temp
,
9
+
(
data
[
4
]
>>
5
),
temp
/
16
,
(
temp
&
0xf
)
*
1000
/
16
);
}
__temp_command_and_next_t
(
ft
,
data
[
4
]);
/* start next conversion */
...
...
@@ -230,10 +233,9 @@ int ft_onewire_init(struct fmctdc_dev *ft)
int
i
;
ow_writel
(
ft
,
((
CLK_DIV_NOR
&
CDR_NOR_MSK
)
|
((
CLK_DIV_OVD
<<
CDR_OVD_OFS
)
&
CDR_OVD_MSK
)),
R_CDR
);
|
((
CLK_DIV_OVD
<<
CDR_OVD_OFS
)
&
CDR_OVD_MSK
)),
R_CDR
);
if
(
ds18x_read_serial
(
ft
)
<
0
)
if
(
ds18x_read_serial
(
ft
)
<
0
)
return
-
EIO
;
if
(
ft
->
verbose
)
{
...
...
lib/fmctdc-lib-private.h
View file @
d7352716
...
...
@@ -27,8 +27,8 @@ struct __fmctdc_board {
int
dev_id
;
char
*
devbase
;
char
*
sysbase
;
int
fdc
[
5
];
/* The 5 control channels */
int
fdd
[
5
];
/* The 5 data channels */
int
fdc
[
5
];
/* The 5 control channels */
int
fdd
[
5
];
/* The 5 data channels */
};
static
inline
int
fmctdc_is_verbose
(
void
)
...
...
@@ -39,7 +39,7 @@ static inline int fmctdc_is_verbose(void)
#define __define_board(b, ub) struct __fmctdc_board *b = (void *)(ub)
/* These two from ../tools/fdelay-raw.h, used internally */
static
inline
int
__fmctdc_sysfs_get
(
char
*
path
,
uint32_t
*
resp
)
static
inline
int
__fmctdc_sysfs_get
(
char
*
path
,
uint32_t
*
resp
)
{
FILE
*
f
=
fopen
(
path
,
"r"
);
...
...
@@ -56,7 +56,7 @@ static inline int __fmctdc_sysfs_get(char *path, uint32_t *resp)
return
0
;
}
static
inline
int
__fmctdc_sysfs_set
(
char
*
path
,
uint32_t
*
value
)
static
inline
int
__fmctdc_sysfs_set
(
char
*
path
,
uint32_t
*
value
)
{
char
s
[
16
];
int
fd
,
ret
,
len
;
...
...
@@ -77,7 +77,7 @@ static inline int __fmctdc_sysfs_set(char *path, uint32_t *value)
/* And these two for the board structure */
static
inline
int
fmctdc_sysfs_get
(
struct
__fmctdc_board
*
b
,
char
*
name
,
uint32_t
*
resp
)
uint32_t
*
resp
)
{
char
pathname
[
128
];
...
...
@@ -86,7 +86,7 @@ static inline int fmctdc_sysfs_get(struct __fmctdc_board *b, char *name,
}
static
inline
int
fmctdc_sysfs_set
(
struct
__fmctdc_board
*
b
,
char
*
name
,
uint32_t
*
value
)
uint32_t
*
value
)
{
char
pathname
[
128
];
...
...
lib/fmctdc-lib.c
View file @
d7352716
...
...
@@ -49,8 +49,8 @@ int fmctdc_init(void)
glob
(
"/dev/zio/zio-ft-*-0-0-ctrl"
,
GLOB_APPEND
,
NULL
,
&
glob_dev
);
/* And look in /sys as well */
glob
(
"/sys/bus/zio/devices/ft-*"
,
0
,
NULL
,
&
glob_sys
);
glob
(
"/sys/bus/zio/devices/zio-ft-*"
,
GLOB_APPEND
,
NULL
,
&
glob_sys
);
glob
(
"/sys/bus/zio/devices/ft-*"
,
0
,
NULL
,
&
glob_sys
);
glob
(
"/sys/bus/zio/devices/zio-ft-*"
,
GLOB_APPEND
,
NULL
,
&
glob_sys
);
assert
(
glob_dev
.
gl_pathc
==
glob_sys
.
gl_pathc
);
/* Allocate as needed */
...
...
@@ -126,7 +126,7 @@ void fmctdc_exit(void)
free
(
b
->
sysbase
);
free
(
b
->
devbase
);
}
if
(
ft_nboards
)
if
(
ft_nboards
)
free
(
ft_boards
);
}
...
...
@@ -224,7 +224,7 @@ int fmctdc_set_termination(struct fmctdc_board *userb, int channel, int on)
uint32_t
val
;
char
attr
[
32
];
if
(
channel
<
FMCTDC_CH_1
||
channel
>
FMCTDC_NUM_CHANNELS
)
if
(
channel
<
FMCTDC_CH_1
||
channel
>
FMCTDC_NUM_CHANNELS
)
return
-
EINVAL
;
snprintf
(
attr
,
sizeof
(
attr
),
"ft-ch%d/termination"
,
channel
);
...
...
@@ -240,13 +240,13 @@ int fmctdc_get_termination(struct fmctdc_board *userb, int channel)
char
attr
[
32
];
int
ret
;
if
(
channel
<
FMCTDC_CH_1
||
channel
>
FMCTDC_NUM_CHANNELS
)
if
(
channel
<
FMCTDC_CH_1
||
channel
>
FMCTDC_NUM_CHANNELS
)
return
-
EINVAL
;
snprintf
(
attr
,
sizeof
(
attr
),
"ft-ch%d/termination"
,
channel
);
ret
=
fmctdc_sysfs_get
(
b
,
attr
,
&
val
);
if
(
ret
)
if
(
ret
)
return
ret
;
return
val
;
}
...
...
@@ -258,7 +258,7 @@ int fmctdc_get_acquisition(struct fmctdc_board *userb)
int
ret
;
ret
=
fmctdc_sysfs_get
(
b
,
"enable_inputs"
,
&
val
);
if
(
ret
)
if
(
ret
)
return
ret
;
return
val
;
}
...
...
@@ -272,12 +272,12 @@ int fmctdc_set_acquisition(struct fmctdc_board *userb, int on)
return
fmctdc_sysfs_set
(
b
,
"enable_inputs"
,
&
val
);
}
static
int
__fmctdc_open_channel
(
struct
__fmctdc_board
*
b
,
int
channel
)
{
char
fname
[
128
];
if
(
b
->
fdc
[
channel
-
1
]
<=
0
)
{
snprintf
(
fname
,
sizeof
(
fname
),
"%s-%d-0-ctrl"
,
b
->
devbase
,
channel
-
1
);
snprintf
(
fname
,
sizeof
(
fname
),
"%s-%d-0-ctrl"
,
b
->
devbase
,
channel
-
1
);
b
->
fdc
[
channel
-
1
]
=
open
(
fname
,
O_RDONLY
|
O_NONBLOCK
);
}
return
b
->
fdc
[
channel
-
1
];
...
...
@@ -290,8 +290,8 @@ int fmctdc_fileno_channel(struct fmctdc_board *userb, int channel)
}
/* "read" behaves like the system call and obeys O_NONBLOCK */
int
fmctdc_read
(
struct
fmctdc_board
*
userb
,
int
channel
,
struct
fmctdc_time
*
t
,
int
n
,
int
flags
)
int
fmctdc_read
(
struct
fmctdc_board
*
userb
,
int
channel
,
struct
fmctdc_time
*
t
,
int
n
,
int
flags
)
{
__define_board
(
b
,
userb
);
struct
zio_control
ctrl
;
...
...
@@ -299,12 +299,12 @@ int fmctdc_read(struct fmctdc_board *userb, int channel, struct fmctdc_time *t,
int
i
,
j
,
fd
;
fd_set
set
;
if
(
channel
<
FMCTDC_CH_1
||
channel
>
FMCTDC_NUM_CHANNELS
)
if
(
channel
<
FMCTDC_CH_1
||
channel
>
FMCTDC_NUM_CHANNELS
)
return
-
EINVAL
;
fd
=
__fmctdc_open_channel
(
b
,
channel
);
if
(
fd
<
0
)
return
fd
;
/* errno already set */
return
fd
;
/* errno already set */
for
(
i
=
0
;
i
<
n
;)
{
j
=
read
(
fd
,
&
ctrl
,
sizeof
(
ctrl
));
...
...
@@ -334,7 +334,7 @@ int fmctdc_read(struct fmctdc_board *userb, int channel, struct fmctdc_time *t,
/* So, first sample and blocking read. Wait.. */
FD_ZERO
(
&
set
);
FD_SET
(
fd
,
&
set
);
if
(
select
(
fd
+
1
,
&
set
,
NULL
,
NULL
,
NULL
)
<
0
)
if
(
select
(
fd
+
1
,
&
set
,
NULL
,
NULL
,
NULL
)
<
0
)
return
-
1
;
continue
;
}
...
...
@@ -342,11 +342,12 @@ int fmctdc_read(struct fmctdc_board *userb, int channel, struct fmctdc_time *t,
}
/* "fread" behaves like stdio: it reads all the samples */
int
fmctdc_fread
(
struct
fmctdc_board
*
userb
,
int
channel
,
struct
fmctdc_time
*
t
,
int
n
)
int
fmctdc_fread
(
struct
fmctdc_board
*
userb
,
int
channel
,
struct
fmctdc_time
*
t
,
int
n
)
{
int
i
,
loop
;
for
(
i
=
0
;
i
<
n
;
)
{
for
(
i
=
0
;
i
<
n
;)
{
loop
=
fmctdc_read
(
userb
,
channel
,
t
+
i
,
n
-
i
,
0
);
if
(
loop
<
0
)
return
-
1
;
...
...
@@ -366,48 +367,46 @@ int fmctdc_set_time(struct fmctdc_board *userb, struct fmctdc_time *t)
attrs
[
0
]
=
t
->
seconds
&
0xffffffff
;
attrs
[
1
]
=
t
->
coarse
;
for
(
i
=
ARRAY_SIZE
(
names
)
-
1
;
i
>=
0
;
i
--
)
{
ret
=
fmctdc_sysfs_set
(
b
,
names
[
i
],
attrs
+
i
);
if
(
ret
<
0
)
return
ret
;
for
(
i
=
ARRAY_SIZE
(
names
)
-
1
;
i
>=
0
;
i
--
)
{
ret
=
fmctdc_sysfs_set
(
b
,
names
[
i
],
attrs
+
i
);
if
(
ret
<
0
)
return
ret
;
}
return
0
;
}
int
fmctdc_get_time
(
struct
fmctdc_board
*
userb
,
struct
fmctdc_time
*
t
)
{
__define_board
(
b
,
userb
);
uint32_t
attrs
[
ARRAY_SIZE
(
names
)];
int
i
,
ret
;
for
(
i
=
0
;
i
<
ARRAY_SIZE
(
names
);
i
++
)
{
ret
=
fmctdc_sysfs_get
(
b
,
names
[
i
],
attrs
+
i
);
if
(
ret
<
0
)
return
ret
;
}
t
->
seconds
=
attrs
[
0
];
t
->
coarse
=
attrs
[
1
];
t
->
frac
=
0
;
return
0
;
__define_board
(
b
,
userb
);
uint32_t
attrs
[
ARRAY_SIZE
(
names
)];
int
i
,
ret
;
for
(
i
=
0
;
i
<
ARRAY_SIZE
(
names
);
i
++
)
{
ret
=
fmctdc_sysfs_get
(
b
,
names
[
i
],
attrs
+
i
);
if
(
ret
<
0
)
return
ret
;
}
t
->
seconds
=
attrs
[
0
];
t
->
coarse
=
attrs
[
1
];
t
->
frac
=
0
;
return
0
;
}
int
fmctdc_set_host_time
(
struct
fmctdc_board
*
userb
)
{
__define_board
(
b
,
userb
);
return
__fmctdc_command
(
b
,
FT_CMD_SET_HOST_TIME
);
__define_board
(
b
,
userb
);
return
__fmctdc_command
(
b
,
FT_CMD_SET_HOST_TIME
);
}
int
fmctdc_wr_mode
(
struct
fmctdc_board
*
userb
,
int
on
)
{
__define_board
(
b
,
userb
);
if
(
on
)
return
__fmctdc_command
(
b
,
FT_CMD_WR_ENABLE
);
return
__fmctdc_command
(
b
,
FT_CMD_WR_ENABLE
);
else
return
__fmctdc_command
(
b
,
FT_CMD_WR_DISABLE
);
return
__fmctdc_command
(
b
,
FT_CMD_WR_DISABLE
);
}
extern
int
fmctdc_check_wr_mode
(
struct
fmctdc_board
*
userb
)
...
...
@@ -416,13 +415,12 @@ extern int fmctdc_check_wr_mode(struct fmctdc_board *userb)
__define_board
(
b
,
userb
);
ret
=
__fmctdc_command
(
b
,
FT_CMD_WR_QUERY
);
switch
(
ret
)
{
case
0
:
return
1
;
/* no error: locked to WR */
case
-
EAGAIN
:
return
0
;
/* EAGAIN: not locked yet */
default:
return
ret
;
/* other error code: just an error ;) */
}
switch
(
ret
)
{
case
0
:
return
1
;
/* no error: locked to WR */
case
-
EAGAIN
:
return
0
;
/* EAGAIN: not locked yet */
default:
return
ret
;
/* other error code: just an error ;) */
}
}
lib/fmctdc-lib.h
View file @
d7352716
...
...
@@ -16,13 +16,13 @@
#include <stdint.h>
enum
fmctdc_channel
{
FMCTDC_CH_1
=
1
,
FMCTDC_CH_2
=
2
,
FMCTDC_CH_3
=
3
,
FMCTDC_CH_4
=
4
,
FMCTDC_CH_5
=
5
,
FMCTDC_CH_LAST
=
5
,
FMCTDC_NUM_CHANNELS
=
5
FMCTDC_CH_1
=
1
,
FMCTDC_CH_2
=
2
,
FMCTDC_CH_3
=
3
,
FMCTDC_CH_4
=
4
,
FMCTDC_CH_5
=
5
,
FMCTDC_CH_LAST
=
5
,
FMCTDC_NUM_CHANNELS
=
5
};
/* Opaque data type used as token */
...
...
@@ -49,17 +49,19 @@ extern int fmctdc_set_host_time(struct fmctdc_board *b);
extern
int
fmctdc_set_acquisition
(
struct
fmctdc_board
*
b
,
int
enable
);
extern
int
fmctdc_get_acquisition
(
struct
fmctdc_board
*
b
);
extern
int
fmctdc_set_termination
(
struct
fmctdc_board
*
b
,
int
channel
,
int
enable
);
extern
int
fmctdc_set_termination
(
struct
fmctdc_board
*
b
,
int
channel
,
int
enable
);
extern
int
fmctdc_get_termination
(
struct
fmctdc_board
*
b
,
int
channel
);
extern
int
fmctdc_fread
(
struct
fmctdc_board
*
b
,
int
channel
,
struct
fmctdc_time
*
t
,
int
n
);
extern
int
fmctdc_fread
(
struct
fmctdc_board
*
b
,
int
channel
,
struct
fmctdc_time
*
t
,
int
n
);
extern
int
fmctdc_fileno_channel
(
struct
fmctdc_board
*
b
,
int
channel
);
extern
int
fmctdc_read
(
struct
fmctdc_board
*
b
,
int
channel
,
struct
fmctdc_time
*
t
,
int
n
,
int
flags
);
extern
int
fmctdc_read
(
struct
fmctdc_board
*
b
,
int
channel
,
struct
fmctdc_time
*
t
,
int
n
,
int
flags
);
extern
float
fmctdc_read_temperature
(
struct
fmctdc_board
*
b
);
extern
int
fmctdc_wr_mode
(
struct
fmctdc_board
*
b
,
int
on
);
extern
int
fmctdc_check_wr_mode
(
struct
fmctdc_board
*
b
);
#endif
/* __FMCTDC_LIB_H__ */
\ No newline at end of file
#endif
/* __FMCTDC_LIB_H__ */
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment