1 /* USER CODE BEGIN Header */
2 /**
3   ******************************************************************************
4   * @file    app_common.h
5   * @author  MCD Application Team
6   * @brief   App Common application configuration file for STM32WPAN Middleware.
7   ******************************************************************************
8   * @attention
9   *
10   * Copyright (c) 2022 STMicroelectronics.
11   * All rights reserved.
12   *
13   * This software is licensed under terms that can be found in the LICENSE file
14   * in the root directory of this software component.
15   * If no LICENSE file comes with this software, it is provided AS-IS.
16   *
17   ******************************************************************************
18   */
19 /* USER CODE END Header */
20 /* Define to prevent recursive inclusion -------------------------------------*/
21 #ifndef APP_COMMON_H
22 #define APP_COMMON_H
23 
24 #ifdef __cplusplus
25 extern "C"{
26 #endif
27 
28 #include <stdint.h>
29 #include <string.h>
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <stdarg.h>
33 
34 #include "app_conf.h"
35 #include "hw.h"
36 #include "ll_sys.h"
37 
38 /* -------------------------------- *
39  *  Basic definitions               *
40  * -------------------------------- */
41 #undef NULL
42 #define NULL                    0
43 
44 #undef FALSE
45 #define FALSE                   0
46 
47 #undef TRUE
48 #define TRUE                    (!0)
49 
50 /* -------------------------------- *
51  *  Critical Section definition     *
52  * -------------------------------- */
53 #define BACKUP_PRIMASK()    uint32_t primask_bit= __get_PRIMASK()
54 #define DISABLE_IRQ()       __disable_irq()
55 #define RESTORE_PRIMASK()   __set_PRIMASK(primask_bit)
56 
57 /* -------------------------------- *
58  *  Macro delimiters                *
59  * -------------------------------- */
60 #define M_BEGIN     do {
61 
62 #define M_END       } while(0)
63 
64 /* -------------------------------- *
65  *  Some useful macro definitions   *
66  * -------------------------------- */
67 #ifndef MAX
68 #define MAX( x, y )          (((x)>(y))?(x):(y))
69 #endif
70 
71 #ifndef MIN
72 #define MIN( x, y )          (((x)<(y))?(x):(y))
73 #endif
74 
75 #define MODINC( a, m )       M_BEGIN  (a)++;  if ((a)>=(m)) (a)=0;  M_END
76 
77 #define MODDEC( a, m )       M_BEGIN  if ((a)==0) (a)=(m);  (a)--;  M_END
78 
79 #define MODADD( a, b, m )    M_BEGIN  (a)+=(b);  if ((a)>=(m)) (a)-=(m);  M_END
80 
81 #define MODSUB( a, b, m )    MODADD( a, (m)-(b), m )
82 
83 #define PAUSE( t )           M_BEGIN \
84                                __IO int _i; \
85                                for ( _i = t; _i > 0; _i -- ); \
86                              M_END
87 
88 #define DIVF( x, y )         ((x)/(y))
89 
90 #define DIVC( x, y )         (((x)+(y)-1)/(y))
91 
92 #define DIVR( x, y )         (((x)+((y)/2))/(y))
93 
94 #define SHRR( x, n )         ((((x)>>((n)-1))+1)>>1)
95 
96 #define BITN( w, n )         (((w)[(n)/32] >> ((n)%32)) & 1)
97 
98 #define BITNSET( w, n, b )   M_BEGIN (w)[(n)/32] |= ((U32)(b))<<((n)%32); M_END
99 
100 /* -------------------------------- *
101  *  Compiler                         *
102  * -------------------------------- */
103 #define PLACE_IN_SECTION( __x__ )  __attribute__((section (__x__)))
104 
105 #ifdef WIN32
106 #define ALIGN(n)
107 #else
108 #define ALIGN(n)             __attribute__((aligned(n)))
109 #endif
110 
111 #ifdef __cplusplus
112 } /* extern "C" */
113 #endif
114 
115 #endif /*APP_COMMON_H */
116