Commit 0300cf4a authored by Miguel Gómez Sexto's avatar Miguel Gómez Sexto

Removed fread and updated read

Signed-off-by: Miguel Gómez Sexto's avatarMiguel Gomez <magomez@igalia.com>
parent 84842d13
......@@ -370,13 +370,9 @@ int tdc_read(struct tdc_board *b, int chan, struct tdc_time *t,
if (errno != EAGAIN)
return -1;
/* EAGAIN: if we already got something, we are done */
if (i)
return i;
/* EAGAIN and no data yet. If noblock then return */
/* EAGAIN: if we can't block, return elements read */
if (flags == O_NONBLOCK)
return -1;
return i;
/* blocking read */
FD_ZERO(&set);
......@@ -388,16 +384,3 @@ int tdc_read(struct tdc_board *b, int chan, struct tdc_time *t,
return i;
}
int tdc_fread(struct tdc_board *b, int chan, struct tdc_time *t, int n)
{
int i, loop;
for (i = 0; i < n; ) {
loop = tdc_read(b, chan, t + i, 1, 0);
if (loop < 0)
return -1;
i += loop;
}
return i;
}
......@@ -59,6 +59,5 @@ extern int tdc_clear_dacapo_flag(struct tdc_board *b);
extern int tdc_read(struct tdc_board *b, int chan, struct tdc_time *t,
int n, int flags);
extern int tdc_fread(struct tdc_board *b, int chan, struct tdc_time *t, int n);
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include "libtdc.h"
int main(int argc, char **argv)
{
struct tdc_board *b;
struct tdc_time t[10];
uint32_t set, get;
int res;
b = tdc_open(1);
if (!b) {
......@@ -59,7 +62,7 @@ int main(int argc, char **argv)
else
printf("Timestamps threshold functions OK\n");
/* set/get active channels with general activation */
/* set/get channel activation */
tdc_activate_all_channels(b);
set = CHAN0 | CHAN2 | CHAN4;
if (tdc_set_active_channels(b, set))
......@@ -109,6 +112,39 @@ int main(int argc, char **argv)
else
printf("Channel activation functions OK\n");
/* read from invalid chan */
tdc_activate_all_channels(b);
set = CHAN0;
if (tdc_set_active_channels(b, set))
printf("Error setting active channels\n");
res = tdc_read(b, 6, t, 10, O_NONBLOCK);
if (res == -1 && errno == EINVAL)
printf("Read from invalid chan OK");
else
printf("Reda from invalid chan wrong");
/* read from disabled chan */
tdc_activate_all_channels(b);
set = CHAN0;
if (tdc_set_active_channels(b, set))
printf("Error setting active channels\n");
res = tdc_read(b, 1, t, 10, O_NONBLOCK);
if (res == -1 && errno == EINVAL)
printf("Read from disabled chan OK");
else
printf("Read from disabled chan wrong");
/* read with all chans disabled */
tdc_deactivate_all_channels(b);
set = CHAN0;
if (tdc_set_active_channels(b, set))
printf("Error setting active channels\n");
res = tdc_read(b, 0, t, 10, O_NONBLOCK);
if (res == -1 && errno == EINVAL)
printf("Read with disabled chans OK");
else
printf("Read with disabled chans wrong");
tdc_close(b);
......
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