xref: /freebsd/sys/contrib/alpine-hal/al_hal_common.h (revision 6be3386466ab79a84b48429ae66244f21526d3df)
1 /*-
2 ********************************************************************************
3 Copyright (C) 2015 Annapurna Labs Ltd.
4 
5 This file may be licensed under the terms of the Annapurna Labs Commercial
6 License Agreement.
7 
8 Alternatively, this file can be distributed under the terms of the GNU General
9 Public License V2 as published by the Free Software Foundation and can be
10 found at http://www.gnu.org/licenses/gpl-2.0.html
11 
12 Alternatively, redistribution and use in source and binary forms, with or
13 without modification, are permitted provided that the following conditions are
14 met:
15 
16     *     Redistributions of source code must retain the above copyright notice,
17 this list of conditions and the following disclaimer.
18 
19     *     Redistributions in binary form must reproduce the above copyright
20 notice, this list of conditions and the following disclaimer in
21 the documentation and/or other materials provided with the
22 distribution.
23 
24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
25 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
28 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
31 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 
35 *******************************************************************************/
36 
37 /**
38  * @defgroup group_common HAL Common Layer
39  * Includes all common header files used by HAL
40  *  @{
41  * @file   al_hal_common.h
42  *
43  */
44 
45 #ifndef __AL_HAL_COMMON_H__
46 #define __AL_HAL_COMMON_H__
47 
48 #include "al_hal_plat_types.h"
49 #include "al_hal_plat_services.h"
50 
51 #include "al_hal_types.h"
52 #include "al_hal_reg_utils.h"
53 
54 /* Get the maximal value out of two typed values */
55 #define al_max_t(type, x, y) ({		\
56 	type __max1 = (x);			\
57 	type __max2 = (y);			\
58 	__max1 > __max2 ? __max1 : __max2; })
59 
60 /* Get the minimal value out of two typed values */
61 #define al_min_t(type, x, y) ({		\
62 	type __min1 = (x);			\
63 	type __min2 = (y);			\
64 	__min1 < __min2 ? __min1 : __min2; })
65 
66 /* Get the number of elements in an array */
67 #define AL_ARR_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
68 
69 /** @} end of Common group */
70 #endif				/* __AL_HAL_COMMON_H__ */
71