diff options
Diffstat (limited to 'include/util.h')
-rw-r--r-- | include/util.h | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/include/util.h b/include/util.h index a25bbbd77a..21603484bb 100644 --- a/include/util.h +++ b/include/util.h @@ -328,6 +328,37 @@ static inline uint64_t mulaa32(uint32_t a, uint32_t b, uint32_t c, uint32_t d) */ void wait_for_ready(volatile uint32_t *reg, uint32_t enable, uint32_t ready); +/** + * Convert the ternary bit array (each element is either 0, 1, or 2) to a + * non-standard ternary number system where the first 2^n natural numbers are + * represented as they would be in a binary system (without any Z digits) and + * the following 3^n-2^n numbers use the remaining ternary representations in + * the normal ternary system order (skipping the values that were already used + * up). + * + * This function is useful for converting BOARd ID, which is initially used a + * binary and later decided to switch to tri-state after some revisions have + * already been built. + * + * Example: For nbits = 2 we get the following representation: + * + * Number X1 X0 + * 0 0 0 + * 1 0 1 + * 2 1 0 + * 3 1 1 // Start counting ternaries back at 0 after this + * 4 0 2 // Skipping 00 and 01 which are already used up + * 5 1 2 // Skipping 10 and 11 which are already used up + * 6 2 0 + * 7 2 1 + * 8 2 2 + * + * @param bits Array of ternary bits (LSB first). + * @param nbits Total number of bits. + * @return Number in the binary-first ternary number system. + */ +int binary_first_base3_from_bits(int *bits, int nbits); + #ifdef __cplusplus } #endif |