3 * Copyright (c) 2020 Project CHIP Authors
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
21 * This file defines constants and macros for introspecting and
22 * manipulating CHIP versions.
24 * !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!!
26 * DO NOT EDIT THIS FILE! This file is automatically-generated by
27 * the '${program}' script.
29 * The constants and macros defined here may be used to, for ,
30 * example, conditionally-compile older, newer, or changed CHIP
31 * APIs based on the CHIP version. For example:
34 * #if CHIP_VERSION_CODE >= CHIP_VERSION_CODE_ENCODE(1, 5, 0)
43 #ifndef CHIP_VERSION_H_
44 #define CHIP_VERSION_H_
46 #define _CHIP_VERSION_CODE_MAJOR_WIDTH 8
47 #define _CHIP_VERSION_CODE_MINOR_WIDTH 8
48 #define _CHIP_VERSION_CODE_PATCH_WIDTH 8
50 #define _CHIP_VERSION_CODE_MAJOR_MASK ((1 << _CHIP_VERSION_CODE_MAJOR_WIDTH) - 1)
51 #define _CHIP_VERSION_CODE_MINOR_MASK ((1 << _CHIP_VERSION_CODE_MINOR_WIDTH) - 1)
52 #define _CHIP_VERSION_CODE_PATCH_MASK ((1 << _CHIP_VERSION_CODE_PATCH_WIDTH) - 1)
54 #define _CHIP_VERSION_CODE_MAJOR_SHIFT 24
55 #define _CHIP_VERSION_CODE_MINOR_SHIFT 16
56 #define _CHIP_VERSION_CODE_PATCH_SHIFT 8
59 * \@def CHIP_VERSION_CODE_ENCODE(major, minor, patch)
62 * Encode a CHIP version code from its constituent \@a major, \@a minor, and \@a patch
65 * This macro may be used in conjunction with CHIP_VERSION_CODE to, for
66 * example, conditionally-compile older, newer, or changed CHIP APIs based
67 * on the CHIP version. For example:
70 * #if CHIP_VERSION_CODE >= CHIP_VERSION_CODE_ENCODE(1, 5, 0)
78 #define CHIP_VERSION_CODE_ENCODE(major, minor, patch) \
79 ((((major) & _CHIP_VERSION_CODE_MAJOR_MASK) << _CHIP_VERSION_CODE_MAJOR_SHIFT) | \
80 (((minor) & _CHIP_VERSION_CODE_MINOR_MASK) << _CHIP_VERSION_CODE_MINOR_SHIFT) | \
81 (((patch) & _CHIP_VERSION_CODE_PATCH_MASK) << _CHIP_VERSION_CODE_PATCH_SHIFT))
84 * \@def CHIP_VERSION_CODE_DECODE_MAJOR(code)
87 * Decode a CHIP major version component from a CHIP version \@a code.
90 #define CHIP_VERSION_CODE_DECODE_MAJOR(code) (((code) >> _CHIP_VERSION_CODE_MAJOR_SHIFT) & _CHIP_VERSION_CODE_MAJOR_MASK)
93 * \@def CHIP_VERSION_CODE_DECODE_MINOR(code)
96 * Decode a CHIP minor version component from a CHIP version \@a code.
99 #define CHIP_VERSION_CODE_DECODE_MINOR(code) (((code) >> _CHIP_VERSION_CODE_MINOR_SHIFT) & _CHIP_VERSION_CODE_MINOR_MASK)
102 * \@def CHIP_VERSION_CODE_DECODE_PATCH(code)
105 * Decode a CHIP patch version component from a CHIP version \@a code.
108 #define CHIP_VERSION_CODE_DECODE_PATCH(code) (((code) >> _CHIP_VERSION_CODE_PATCH_SHIFT) & _CHIP_VERSION_CODE_PATCH_MASK)
111 * \@def CHIP_VERSION_MAJOR
114 * The CHIP version major component, as an unsigned integer.
117 #define CHIP_VERSION_MAJOR 0
120 * \@def CHIP_VERSION_MINOR
123 * The CHIP version minor component, as an unsigned integer.
126 #define CHIP_VERSION_MINOR 0
129 * \@def CHIP_VERSION_PATCH
132 * The CHIP version patch component, as an unsigned integer.
135 #define CHIP_VERSION_PATCH 0
138 * \@def CHIP_VERSION_EXTRA
141 * The CHIP version extra component, as a quoted C string.
144 #define CHIP_VERSION_EXTRA ""
147 * \@def CHIP_VERSION_STRING
150 * The CHIP version, as a quoted C string.
153 #define CHIP_VERSION_STRING "0.0.0"
156 * \@def CHIP_VERSION_CODE
159 * The CHIP version, including the major, minor, and patch components,
160 * encoded as an unsigned integer.
162 * This macro may be used in conjunction with CHIP_VERSION_CODE_ENCODE
163 * to, for example, conditionally-compile older, newer, or changed CHIP
164 * APIs based on the CHIP version. For example:
167 * #if CHIP_VERSION_CODE >= CHIP_VERSION_CODE_ENCODE(1, 5, 0)
175 #define CHIP_VERSION_CODE CHIP_VERSION_CODE_ENCODE( \
176 CHIP_VERSION_MAJOR, \
177 CHIP_VERSION_MINOR, \
181 #endif /* CHIP_VERSION_H_ */