1 /* --COPYRIGHT--,BSD 2 * Copyright (c) 2017, Texas Instruments Incorporated 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * * Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 12 * * Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * * Neither the name of Texas Instruments Incorporated nor the names of 17 * its contributors may be used to endorse or promote products derived 18 * from this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 * --/COPYRIGHT--*/ 32 #ifndef __FPU_H__ 33 #define __FPU_H__ 34 35 //***************************************************************************** 36 // 37 //! 38 //! \addtogroup fpu_api 39 //! @{ 40 // 41 //***************************************************************************** 42 43 //***************************************************************************** 44 // 45 // If building with a C++ compiler, make all of the definitions in this header 46 // have a C binding. 47 // 48 //***************************************************************************** 49 #ifdef __cplusplus 50 extern "C" 51 { 52 #endif 53 54 #include <stdint.h> 55 #include <ti/devices/msp432p4xx/inc/msp.h> 56 57 //***************************************************************************** 58 // 59 // Values that can be passed to FPUHalfPrecisionSet as the mode parameter. 60 // 61 //***************************************************************************** 62 #define FPU_HALF_IEEE 0x00000000 63 #define FPU_HALF_ALTERNATE 0x04000000 64 65 //***************************************************************************** 66 // 67 // Values that can be passed to FPU_setNaNMode as the mode parameter. 68 // 69 //***************************************************************************** 70 #define FPU_NAN_PROPAGATE 0x00000000 71 #define FPU_NAN_DEFAULT 0x02000000 72 73 //***************************************************************************** 74 // 75 // Values that can be passed to FPU_setFlushToZeroMode as the mode parameter. 76 // 77 //***************************************************************************** 78 #define FPU_FLUSH_TO_ZERO_DIS 0x00000000 79 #define FPU_FLUSH_TO_ZERO_EN 0x01000000 80 81 //***************************************************************************** 82 // 83 // Values that can be passed to FPU_setRoundingMode as the mode parameter. 84 // 85 //***************************************************************************** 86 #define FPU_ROUND_NEAREST 0x00000000 87 #define FPU_ROUND_POS_INF 0x00400000 88 #define FPU_ROUND_NEG_INF 0x00800000 89 #define FPU_ROUND_ZERO 0x00c00000 90 91 //***************************************************************************** 92 // 93 //! Enables the floating-point unit. 94 //! 95 //! This function enables the floating-point unit, allowing the floating-point 96 //! instructions to be executed. This function must be called prior to 97 //! performing any hardware floating-point operations; failure to do so results 98 //! in a NOCP usage fault. 99 //! 100 //! \return None. 101 // 102 //***************************************************************************** 103 extern void FPU_enableModule(void); 104 105 //***************************************************************************** 106 // 107 //! Disables the floating-point unit. 108 //! 109 //! This function disables the floating-point unit, preventing floating-point 110 //! instructions from executing (generating a NOCP usage fault instead). 111 //! 112 //! \return None. 113 // 114 //***************************************************************************** 115 extern void FPU_disableModule(void); 116 117 //***************************************************************************** 118 // 119 //! Enables the stacking of floating-point registers. 120 //! 121 //! This function enables the stacking of floating-point registers s0-s15 when 122 //! an interrupt is handled. When enabled, space is reserved on the stack for 123 //! the floating-point context and the floating-point state is saved into this 124 //! stack space. Upon return from the interrupt, the floating-point context is 125 //! restored. 126 //! 127 //! If the floating-point registers are not stacked, floating-point 128 //! instructions cannot be safely executed in an interrupt handler because the 129 //! values of s0-s15 are not likely to be preserved for the interrupted code. 130 //! On the other hand, stacking the floating-point registers increases the 131 //! stacking operation from 8 words to 26 words, also increasing the interrupt 132 //! response latency. 133 //! 134 //! \return None. 135 // 136 //***************************************************************************** 137 extern void FPU_enableStacking(void); 138 139 //***************************************************************************** 140 // 141 //! Enables the lazy stacking of floating-point registers. 142 //! 143 //! This function enables the lazy stacking of floating-point registers s0-s15 144 //! when an interrupt is handled. When lazy stacking is enabled, space is 145 //! reserved on the stack for the floating-point context, but the 146 //! floating-point state is not saved. If a floating-point instruction is 147 //! executed from within the interrupt context, the floating-point context is 148 //! first saved into the space reserved on the stack. On completion of the 149 //! interrupt handler, the floating-point context is only restored if it was 150 //! saved (as the result of executing a floating-point instruction). 151 //! 152 //! This method provides a compromise between fast interrupt response (because 153 //! the floating-point state is not saved on interrupt entry) and the ability 154 //! to use floating-point in interrupt handlers (because the floating-point 155 //! state is saved if floating-point instructions are used). 156 //! 157 //! \return None. 158 // 159 //***************************************************************************** 160 extern void FPU_enableLazyStacking(void); 161 162 //***************************************************************************** 163 // 164 //! Disables the stacking of floating-point registers. 165 //! 166 //! This function disables the stacking of floating-point registers s0-s15 when 167 //! an interrupt is handled. When floating-point context stacking is disabled, 168 //! floating-point operations performed in an interrupt handler destroy the 169 //! floating-point context of the main thread of execution. 170 //! 171 //! \return None. 172 // 173 //***************************************************************************** 174 extern void FPU_disableStacking(void); 175 176 //***************************************************************************** 177 // 178 //! Selects the format of half-precision floating-point values. 179 //! 180 //! \param mode is the format for half-precision floating-point value, which 181 //! is either \b FPU_HALF_IEEE or \b FPU_HALF_ALTERNATE. 182 //! 183 //! This function selects between the IEEE half-precision floating-point 184 //! representation and the Cortex-M processor alternative representation. The 185 //! alternative representation has a larger range but does not have a way to 186 //! encode infinity (positive or negative) or NaN (quiet or signalling). The 187 //! default setting is the IEEE format. 188 //! 189 //! \note Unless this function is called prior to executing any floating-point 190 //! instructions, the default mode is used. 191 //! 192 //! \return None. 193 // 194 //***************************************************************************** 195 extern void FPU_setHalfPrecisionMode(uint32_t mode); 196 197 //***************************************************************************** 198 // 199 //! Selects the NaN mode. 200 //! 201 //! \param mode is the mode for NaN results; which is 202 //! either \b FPU_NAN_PROPAGATE or \b FPU_NAN_DEFAULT. 203 //! 204 //! This function selects the handling of NaN results during floating-point 205 //! computations. NaNs can either propagate (the default), or they can return 206 //! the default NaN. 207 //! 208 //! \note Unless this function is called prior to executing any floating-point 209 //! instructions, the default mode is used. 210 //! 211 //! \return None. 212 // 213 //***************************************************************************** 214 extern void FPU_setNaNMode(uint32_t mode); 215 216 //***************************************************************************** 217 // 218 //! Selects the flush-to-zero mode. 219 //! 220 //! \param mode is the flush-to-zero mode; which is either 221 //! \b FPU_FLUSH_TO_ZERO_DIS or \b FPU_FLUSH_TO_ZERO_EN. 222 //! 223 //! This function enables or disables the flush-to-zero mode of the 224 //! floating-point unit. When disabled (the default), the floating-point unit 225 //! is fully IEEE compliant. When enabled, values close to zero are treated as 226 //! zero, greatly improving the execution speed at the expense of some accuracy 227 //! (as well as IEEE compliance). 228 //! 229 //! \note Unless this function is called prior to executing any floating-point 230 //! instructions, the default mode is used. 231 //! 232 //! \return None. 233 // 234 //***************************************************************************** 235 extern void FPU_setFlushToZeroMode(uint32_t mode); 236 237 //***************************************************************************** 238 // 239 //! Selects the rounding mode for floating-point results. 240 //! 241 //! \param mode is the rounding mode. 242 //! 243 //! This function selects the rounding mode for floating-point results. After 244 //! a floating-point operation, the result is rounded toward the specified 245 //! value. The default mode is \b FPU_ROUND_NEAREST. 246 //! 247 //! The following rounding modes are available (as specified by \e mode): 248 //! 249 //! - \b FPU_ROUND_NEAREST - round toward the nearest value 250 //! - \b FPU_ROUND_POS_INF - round toward positive infinity 251 //! - \b FPU_ROUND_NEG_INF - round toward negative infinity 252 //! - \b FPU_ROUND_ZERO - round toward zero 253 //! 254 //! \note Unless this function is called prior to executing any floating-point 255 //! instructions, the default mode is used. 256 //! 257 //! \return None. 258 // 259 //***************************************************************************** 260 extern void FPU_setRoundingMode(uint32_t mode); 261 262 //***************************************************************************** 263 // 264 // Mark the end of the C bindings section for C++ compilers. 265 // 266 //***************************************************************************** 267 #ifdef __cplusplus 268 } 269 #endif 270 271 272 //***************************************************************************** 273 // 274 // Close the Doxygen group. 275 //! @} 276 // 277 //***************************************************************************** 278 279 280 #endif // __FPU_H__ 281