Commit bae3761b authored by Federico Vaga's avatar Federico Vaga

lib: getter and setter for user-offset

Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@cern.ch>
parent 0a96741d
......@@ -918,3 +918,58 @@ int fmctdc_flush(struct fmctdc_board *userb, unsigned int channel)
/* Re-enable if it was enable */
return fmctdc_channel_status_set(userb, channel, en);
}
/**
* It sets the user offset to be applied on incoming timestamps. All the
* timestamps read from the driver (this means also from this library) will
* be already corrected using this offset.
* @param[in] userb TDC board instance token
* @param[in] channel target channel [0, 4]
* @param[in] offset the number of pico-seconds to be added
* @return 0 on success, otherwise -1 and errno is set appropriately
*/
int fmctdc_set_offset_user(struct fmctdc_board *userb,
unsigned int channel, int32_t offset)
{
__define_board(b, userb);
uint32_t val = (uint32_t)offset;
char attr[64];
if (channel >= FMCTDC_NUM_CHANNELS) {
errno = EINVAL;
return -1;
}
snprintf(attr, sizeof(attr), "ft-ch%d/user-offset", channel + 1);
return fmctdc_sysfs_set(b, attr, &val);
}
/**
* It get the current user offset applied to the incoming timestamps
* @param[in] userb TDC board instance token
* @param[in] channel target channel [0, 4]
* @param[out] offset the number of pico-seconds to be added
* @return 0 on success, otherwise -1 and errno is set appropriately
*/
int fmctdc_get_offset_user(struct fmctdc_board *userb,
unsigned int channel, int32_t *offset)
{
struct __fmctdc_board *b = (void *)(userb);
uint32_t val;
char path[64];
int err;
if (channel >= FMCTDC_NUM_CHANNELS) {
errno = EINVAL;
return -1;
}
snprintf(path, sizeof(path), "ft-ch%d/user-offset", channel + 1);
err = fmctdc_sysfs_get(b, path, &val);
if (err)
return -1;
*offset = (int32_t)val;
return 0;
}
......@@ -136,6 +136,10 @@ extern int fmctdc_reference_set(struct fmctdc_board *userb,
extern int fmctdc_reference_get(struct fmctdc_board *userb,
unsigned int ch_target);
extern int fmctdc_reference_clear(struct fmctdc_board *userb, int ch_target);
extern int fmctdc_set_offset_user(struct fmctdc_board *userb,
unsigned int channel, int32_t offset);
extern int fmctdc_get_offset_user(struct fmctdc_board *userb,
unsigned int channel, int32_t *offset);
/**@}*/
......
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