KM3NeT CLB
2.0
KM3NeT CLB v2 Embedded Software
Main Page
Related Pages
Modules
Data Structures
Files
Examples
File List
Globals
All
Data Structures
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Groups
Pages
func.h
Go to the documentation of this file.
1
/*
2
* KM3NeT CLB v2 Firmware
3
* ----------------------
4
*
5
* Copyright 2012-2014 KM3NeT Collaboration
6
*
7
* All Rights Reserved.
8
*
9
*
10
* File : func.h
11
* Created : 17 sep. 2014
12
* Author : Vincent van Beveren
13
*/
14
15
#ifndef FUNC_H_
16
#define FUNC_H_
17
18
/**
19
* @file
20
*
21
* @ingroup util
22
*
23
* Various useful functions.
24
*
25
*/
26
27
#include <stdint.h>
28
#include <stdbool.h>
29
#include <string.h>
30
31
static
inline
int
firstBitPos(uint32_t value) {
32
if
(value == 0)
return
0;
33
int
pos = 0;
34
uint32_t mask = 0xFFFF;
35
36
int
inc = 16;
37
while
(inc > 0) {
38
if
((value & mask) == 0) {
39
pos += inc;
40
value >>= inc;
41
}
42
43
inc >>= 1;
44
mask >>= inc;
45
}
46
return
pos;
47
}
48
49
/**
50
* Simple compares two strings for equality.
51
*
52
* @param one The one string
53
* @param other The other sting
54
*
55
* @retval true They equal
56
* @retval false They do not equal
57
*/
58
static
inline
bool
streq
(
const
char
* one,
char
* other) {
59
return
strcmp(one, other) == 0;
60
}
61
62
/**
63
* Count the leading zero's.
64
*
65
* @param val Input integer
66
* @return Number of leading zeros.
67
*/
68
int
clz
(uint32_t val);
69
70
typedef
union
71
{
72
uint16_t uint;
73
int16_t sint;
74
uint8_t bytes[2];
75
}
b16_t
;
76
77
typedef
union
78
{
79
uint32_t u32;
80
int32_t i32;
81
uint16_t words[2];
82
uint8_t bytes[4];
83
}
b32_t
;
84
85
86
#endif
/* FUNC_H_ */
b32_t
Definition:
func.h:77
streq
static bool streq(const char *one, char *other)
Simple compares two strings for equality.
Definition:
func.h:58
clz
int clz(uint32_t val)
Count the leading zero's.
Definition:
func.c:17
b16_t
Definition:
func.h:70
src
common
util
func.h
Generated on Mon Mar 15 2021 09:06:53 for KM3NeT CLB by
1.8.5