Skip to content

Commit 141c035

Browse files
author
Robert Schöftner
committed
add hal_extend_int function
helper function to deal with wrap around and extension of lower-width counters to 64bit ints.
1 parent fcd8ed1 commit 141c035

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

src/hal/hal.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,24 @@ extern int hal_get_signal_value_by_name(
692692
extern int hal_get_param_value_by_name(
693693
const char *name, hal_type_t *type, hal_data_u **data);
694694

695+
/***********************************************************************
696+
* MISC HELPER FUNCTIONS *
697+
************************************************************************/
698+
699+
/** hal_extend_counter() extends a counter value with nbits to 64 bits.
700+
701+
For some hardware counters it may be desireable to extend their
702+
range beyond their native width.
703+
704+
This function maintains a 64bit counter value and deals with wrap
705+
arounds. Increments between updates need to be less than 2**(nbits-1).
706+
Call with current 64bit counter value to be updated as @param old,
707+
new lower-bit counter value read from hardware as @param newlow
708+
and width of counter as @param nbits.
709+
@returns new counter 64bit counter value.
710+
Code by Jeff Epler. */
711+
extern rtapi_s64 hal_extend_int(rtapi_s64 old, rtapi_s64 newlow, int nbits);
712+
695713
/***********************************************************************
696714
* EXECUTION RELATED FUNCTIONS *
697715
************************************************************************/

0 commit comments

Comments
 (0)