blob: 294314c4000274e1e8b155e36bb88b22be33c46a [file] [log] [blame]
Kévin Redon78bb8852019-06-06 17:48:10 +02001/**
2 * \file
3 *
4 * \brief Recursion macro.
5 *
6 * Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.
7 *
8 * \asf_license_start
9 *
10 * \page License
11 *
12 * Subject to your compliance with these terms, you may use Microchip
13 * software and any derivatives exclusively with Microchip products.
14 * It is your responsibility to comply with third party license terms applicable
15 * to your use of third party software (including open source software) that
16 * may accompany Microchip software.
17 *
18 * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
19 * WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
20 * INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
21 * AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
22 * LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
23 * LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
24 * SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
25 * POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
26 * ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
27 * RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
28 * THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
29 *
30 * \asf_license_stop
31 *
32 */
33
34#ifndef _UTILS_RECURSION_MACRO_H
35#define _UTILS_RECURSION_MACRO_H
36
37#ifdef __cplusplus
38extern "C" {
39#endif
40
41/*
42 * \brief Macro recursion
43 *
44 * \param[in] macro Macro to be repeated recursively
45 * \param[in] arg A recursive threshold, building on this to decline by times
46 * defined with parameter n
47 * \param[in] n The number of repetitious calls to macro
48 */
49#define RECURSION_MACRO(macro, arg, n) RECURSION_MACRO_I(macro, arg, n)
50
51/*
52 * \brief Second level is needed to get integer literal from "n" if it is
53 * defined as macro
54 */
55#define RECURSION_MACRO_I(macro, arg, n) RECURSION##n(macro, arg)
56
57#define RECURSION0(macro, arg)
58#define RECURSION1(macro, arg) RECURSION0(macro, DEC_VALUE(arg)) macro(arg, 0)
59#define RECURSION2(macro, arg) RECURSION1(macro, DEC_VALUE(arg)) macro(arg, 1)
60#define RECURSION3(macro, arg) RECURSION2(macro, DEC_VALUE(arg)) macro(arg, 2)
61#define RECURSION4(macro, arg) RECURSION3(macro, DEC_VALUE(arg)) macro(arg, 3)
62#define RECURSION5(macro, arg) RECURSION4(macro, DEC_VALUE(arg)) macro(arg, 4)
63
64#ifdef __cplusplus
65}
66#endif
67
68#include <utils_decrement_macro.h>
69#endif /* _UTILS_RECURSION_MACRO_H */