Commit e27613f3 authored by Miguel Gómez Sexto's avatar Miguel Gómez Sexto

Updated read function and added fread one

Signed-off-by: Miguel Gómez Sexto's avatarMiguel Gomez <magomez@igalia.com>
parent 2ef385bb
...@@ -338,34 +338,37 @@ int tdc_read(struct tdc_board *b, int chan, struct tdc_time *t, ...@@ -338,34 +338,37 @@ int tdc_read(struct tdc_board *b, int chan, struct tdc_time *t,
for (i = 0; i < n; ) { for (i = 0; i < n; ) {
j = read(fd, &ctrl, sizeof(ctrl)); j = read(fd, &ctrl, sizeof(ctrl));
if (j < 0 && errno != EAGAIN) /* one register read */
return -1;
if (j == sizeof(ctrl)) { if (j == sizeof(ctrl)) {
/* one sample: pick it */ t[i].utc = ctrl.tstamp.secs;
t->utc = ctrl.tstamp.secs; t[i].ticks = ctrl.tstamp.ticks;
t->ticks = ctrl.tstamp.ticks; t[i]. bins = ctrl.tstamp.bins;
t->bins = ctrl.tstamp.bins;
i++; i++;
continue; continue;
} }
/* some bytes read but not complete structure */
if (j > 0) { if (j > 0) {
/* some bytes read but not complete structure */
errno = EIO; errno = EIO;
return -1; return -1;
} }
/* so, it's EAGAIN: if we already got something, we are done */ /* from here on, an error was returned */
/* real error, so exit */
if (errno != EAGAIN)
return -1;
/* EAGAIN: if we already got something, we are done */
if (i) if (i)
return i; return i;
/* EAGAIN at first sample */ /* EAGAIN and no data yet. If noblock then return */
if (j < 0 && flags == O_NONBLOCK) if (flags == O_NONBLOCK)
return -1; return -1;
/* So, first sample and blocking read. Wait.. */ /* blocking read */
FD_ZERO(&set); FD_ZERO(&set);
FD_SET(fd, &set); FD_SET(fd, &set);
if (select(fd+1, &set, NULL, NULL, NULL) < 0) if (select(fd+1, &set, NULL, NULL, NULL) < 0)
...@@ -375,3 +378,16 @@ int tdc_read(struct tdc_board *b, int chan, struct tdc_time *t, ...@@ -375,3 +378,16 @@ int tdc_read(struct tdc_board *b, int chan, struct tdc_time *t,
return i; 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, n - i, 0);
if (loop < 0)
return -1;
i += loop;
}
return i;
}
...@@ -46,5 +46,6 @@ extern int tdc_get_active_channels(struct tdc_board *b, uint32_t *config); ...@@ -46,5 +46,6 @@ extern int tdc_get_active_channels(struct tdc_board *b, uint32_t *config);
extern int tdc_read(struct tdc_board *b, int chan, struct tdc_time *t, extern int tdc_read(struct tdc_board *b, int chan, struct tdc_time *t,
int n, int flags); int n, int flags);
extern int tdc_fread(struct tdc_board *b, int chan, struct tdc_time *t, int n);
#endif #endif
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