Mistake on this page?
Report an issue in GitHub or email us
ll_math.h
Go to the documentation of this file.
1 /*************************************************************************************************/
2 /*!
3  * \file
4  *
5  * \brief Link Layer math utilities.
6  *
7  * Copyright (c) 2013-2019 Arm Ltd. All Rights Reserved.
8  *
9  * Copyright (c) 2019 Packetcraft, Inc.
10  *
11  * Licensed under the Apache License, Version 2.0 (the "License");
12  * you may not use this file except in compliance with the License.
13  * You may obtain a copy of the License at
14  *
15  * http://www.apache.org/licenses/LICENSE-2.0
16  *
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permissions and
21  * limitations under the License.
22  */
23 /*************************************************************************************************/
24 #ifndef LL_MATH_H
25 #define LL_MATH_H
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 #include "wsf_types.h"
32 
33 /**************************************************************************************************
34  Macros
35 **************************************************************************************************/
36 
37 /*! \brief Binary divide with 1,000 divisor (n[max]=7,999). */
38 #define LL_MATH_DIV_10E3(n) ((uint32_t)(((uint64_t)(n) * UINT64_C(536871)) >> 29))
39 
40 /*! \brief Binary divide with 1,000,000 divisor (n[max]=0xFFFFFFFF). */
41 #define LL_MATH_DIV_10E6(n) ((uint32_t)(((uint64_t)(n) * UINT64_C(4295)) >> 32))
42 
43 /*! \brief Binary divide with 10 divisor (n[max]=0xFFFFFFFF). */
44 #define LL_MATH_DIV_10(n) ((uint32_t)(((uint64_t)(n) * UINT64_C(419431)) >> 22))
45 
46 /*! \brief Binary divide with 27 divisor (n[max]=55,295). */
47 #define LL_MATH_DIV_27(n) (((n) * UINT32_C(77673)) >> 21)
48 
49 /*! \brief Binary divide with 37 divisor (n[max]=75,776). */
50 #define LL_MATH_DIV_37(n) (((n) * UINT32_C(56680)) >> 21)
51 
52 /*! \brief Binary modulo 37. */
53 #define LL_MATH_MOD_37(n) ((n) - (LL_MATH_DIV_37(n) * 37))
54 
55 /*! \brief Binary divide with 1250 divisor (n[max]=0xFFFFFFFF). */
56 #define LL_MATH_DIV_1250(n) ((uint32_t)(((uint64_t)(n) * UINT64_C(1717987)) >> 31))
57 
58 /*! \brief Binary divide with 625 divisor (n[max]=0xFFFFFFFF). */
59 #define LL_MATH_DIV_625(n) ((uint32_t)(((uint64_t)(n) * UINT64_C(1717987)) >> 30))
60 
61 /*! \brief Binary divide with 30 divisor (n[max]=0xFFFFFFFF). */
62 #define LL_MATH_DIV_30(n) ((uint32_t)(((uint64_t)(n) * UINT64_C(286331154)) >> 33))
63 
64 /*! \brief Binary divide with 300 divisor (n[max]=0x3FFFFFFF). */
65 #define LL_MATH_DIV_300(n) ((uint32_t)(((uint64_t)(n) * UINT64_C(14660155038)) >> 42))
66 
67 /**************************************************************************************************
68  Data Types
69 **************************************************************************************************/
70 
71 /*! \brief ECC service callback. */
72 typedef void (*LlMathEccServiceCback_t)(uint8_t op);
73 
74 /*! \brief ECC operations. */
75 enum
76 {
77  LL_MATH_ECC_OP_GENERATE_P256_KEY_PAIR, /*!< Generate P-256 key pair. */
78  LL_MATH_ECC_OP_GENERATE_DH_KEY /*!< Generate Diffie-Hellman key. */
79 };
80 
81 /**************************************************************************************************
82  Function Declarations
83 **************************************************************************************************/
84 
85 /*************************************************************************************************/
86 /*!
87  * \brief Generate random number.
88  *
89  * \return 32-bit random number.
90  */
91 /*************************************************************************************************/
92 uint32_t LlMathRandNum(void);
93 
94 /*************************************************************************************************/
95 /*!
96  * \brief Return the number of bits which are set.
97  *
98  * \param num Input parameter.
99  *
100  * \return Number of bits which are set.
101  */
102 /*************************************************************************************************/
103 uint8_t LlMathGetNumBitsSet(uint64_t num);
104 
105 /*************************************************************************************************/
106 /*!
107  * \brief Return result of a division.
108  *
109  * \param nu32 Numerator of size 32 bits.
110  * \param de32 Denominator of size 32 bits.
111  *
112  * \return Result of a division.
113  */
114 /*************************************************************************************************/
115 uint32_t LlMathDivideUint32(uint32_t nu32, uint32_t de32);
116 
117 /*************************************************************************************************/
118 /*!
119  * \brief Return result of a division, rounding up.
120  *
121  * \param nu32 Numerator of size 32 bits.
122  * \param de32 Denominator of size 32 bits.
123  *
124  * \return Result of a division.
125  */
126 /*************************************************************************************************/
127 uint32_t LlMathDivideUint32RoundUp(uint32_t nu32, uint32_t de32);
128 
129 #ifdef __cplusplus
130 };
131 #endif
132 
133 #endif /* LL_API_H */
uint32_t LlMathRandNum(void)
Generate random number.
uint8_t LlMathGetNumBitsSet(uint64_t num)
Return the number of bits which are set.
void(* LlMathEccServiceCback_t)(uint8_t op)
ECC service callback.
Definition: ll_math.h:72
Platform-independent data types.
uint32_t LlMathDivideUint32RoundUp(uint32_t nu32, uint32_t de32)
Return result of a division, rounding up.
uint32_t LlMathDivideUint32(uint32_t nu32, uint32_t de32)
Return result of a division.
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.