2 * Copyright (c) 2014, Texas Instruments Incorporated
\r
3 * All rights reserved.
\r
5 * Redistribution and use in source and binary forms, with or without
\r
6 * modification, are permitted provided that the following conditions
\r
9 * * Redistributions of source code must retain the above copyright
\r
10 * notice, this list of conditions and the following disclaimer.
\r
12 * * Redistributions in binary form must reproduce the above copyright
\r
13 * notice, this list of conditions and the following disclaimer in the
\r
14 * documentation and/or other materials provided with the distribution.
\r
16 * * Neither the name of Texas Instruments Incorporated nor the names of
\r
17 * its contributors may be used to endorse or promote products derived
\r
18 * from this software without specific prior written permission.
\r
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
\r
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
\r
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
\r
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
\r
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
\r
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
\r
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
\r
27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
\r
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
\r
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
\r
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
32 //*****************************************************************************
\r
34 // mpy32.h - Driver for the MPY32 Module.
\r
36 //*****************************************************************************
\r
38 #ifndef __MSP430WARE_MPY32_H__
\r
39 #define __MSP430WARE_MPY32_H__
\r
41 #include "inc/hw_memmap.h"
\r
43 #ifdef __MSP430_HAS_MPY32__
\r
45 //*****************************************************************************
\r
47 // If building with a C++ compiler, make all of the definitions in this header
\r
48 // have a C binding.
\r
50 //*****************************************************************************
\r
56 #include "inc/hw_regaccess.h"
\r
58 //*****************************************************************************
\r
60 // The following are values that can be passed to the writeDelaySelect
\r
61 // parameter for functions: MPY32_setWriteDelay().
\r
63 //*****************************************************************************
\r
64 #define MPY32_WRITEDELAY_OFF (!(MPYDLY32 + MPYDLYWRTEN))
\r
65 #define MPY32_WRITEDELAY_32BIT (MPYDLYWRTEN)
\r
66 #define MPY32_WRITEDELAY_64BIT (MPYDLY32 + MPYDLYWRTEN)
\r
68 //*****************************************************************************
\r
70 // The following are values that can be passed to the multiplicationType
\r
71 // parameter for functions: MPY32_setOperandOne8Bit(),
\r
72 // MPY32_setOperandOne16Bit(), MPY32_setOperandOne24Bit(), and
\r
73 // MPY32_setOperandOne32Bit().
\r
75 //*****************************************************************************
\r
76 #define MPY32_MULTIPLY_UNSIGNED (0x00)
\r
77 #define MPY32_MULTIPLY_SIGNED (0x02)
\r
78 #define MPY32_MULTIPLYACCUMULATE_UNSIGNED (0x04)
\r
79 #define MPY32_MULTIPLYACCUMULATE_SIGNED (0x06)
\r
81 //*****************************************************************************
\r
83 // The following are values that can be passed toThe following are values that
\r
84 // can be returned by the MPY32_getSaturationMode() function.
\r
86 //*****************************************************************************
\r
87 #define MPY32_SATURATION_MODE_DISABLED 0x00
\r
88 #define MPY32_SATURATION_MODE_ENABLED MPYSAT
\r
90 //*****************************************************************************
\r
92 // The following are values that can be passed toThe following are values that
\r
93 // can be returned by the MPY32_getFractionalMode() function.
\r
95 //*****************************************************************************
\r
96 #define MPY32_FRACTIONAL_MODE_DISABLED 0x00
\r
97 #define MPY32_FRACTIONAL_MODE_ENABLED MPYFRAC
\r
99 //*****************************************************************************
\r
101 // Prototypes for the APIs.
\r
103 //*****************************************************************************
\r
105 //*****************************************************************************
\r
107 //! \brief Sets the write delay setting for the MPY32 module.
\r
109 //! This function sets up a write delay to the MPY module's registers, which
\r
110 //! holds any writes to the registers until all calculations are complete.
\r
111 //! There are two different settings, one which waits for 32-bit results to be
\r
112 //! ready, and one which waits for 64-bit results to be ready. This prevents
\r
113 //! unpredicatble results if registers are changed before the results are
\r
116 //! \param writeDelaySelect delays the write to any MPY32 register until the
\r
117 //! selected bit size of result has been written.
\r
118 //! Valid values are:
\r
119 //! - \b MPY32_WRITEDELAY_OFF [Default] - writes are not delayed
\r
120 //! - \b MPY32_WRITEDELAY_32BIT - writes are delayed until a 32-bit
\r
121 //! result is available in the result registers
\r
122 //! - \b MPY32_WRITEDELAY_64BIT - writes are delayed until a 64-bit
\r
123 //! result is available in the result registers
\r
124 //! \n Modified bits are \b MPYDLY32 and \b MPYDLYWRTEN of \b MPY32CTL0
\r
129 //*****************************************************************************
\r
130 extern void MPY32_setWriteDelay(uint16_t writeDelaySelect);
\r
132 //*****************************************************************************
\r
134 //! \brief Enables Saturation Mode.
\r
136 //! This function enables saturation mode. When this is enabled, the result
\r
137 //! read out from the MPY result registers is converted to the most-positive
\r
138 //! number in the case of an overflow, or the most-negative number in the case
\r
139 //! of an underflow. Please note, that the raw value in the registers does not
\r
140 //! reflect the result returned, and if the saturation mode is disabled, then
\r
141 //! the raw value of the registers will be returned instead.
\r
146 //*****************************************************************************
\r
147 extern void MPY32_enableSaturationMode(void);
\r
149 //*****************************************************************************
\r
151 //! \brief Disables Saturation Mode.
\r
153 //! This function disables saturation mode, which allows the raw result of the
\r
154 //! MPY result registers to be returned.
\r
159 //*****************************************************************************
\r
160 extern void MPY32_disableSaturationMode(void);
\r
162 //*****************************************************************************
\r
164 //! \brief Gets the Saturation Mode.
\r
166 //! This function gets the current saturation mode.
\r
169 //! \return Gets the Saturation Mode
\r
170 //! Return one of the following:
\r
171 //! - \b MPY32_SATURATION_MODE_DISABLED
\r
172 //! - \b MPY32_SATURATION_MODE_ENABLED
\r
173 //! \n Gets the Saturation Mode
\r
175 //*****************************************************************************
\r
176 extern uint8_t MPY32_getSaturationMode(void);
\r
178 //*****************************************************************************
\r
180 //! \brief Enables Fraction Mode.
\r
182 //! This function enables fraction mode.
\r
187 //*****************************************************************************
\r
188 extern void MPY32_enableFractionalMode(void);
\r
190 //*****************************************************************************
\r
192 //! \brief Disables Fraction Mode.
\r
194 //! This function disables fraction mode.
\r
199 //*****************************************************************************
\r
200 extern void MPY32_disableFractionalMode(void);
\r
202 //*****************************************************************************
\r
204 //! \brief Gets the Fractional Mode.
\r
206 //! This function gets the current fractional mode.
\r
209 //! \return Gets the fractional mode
\r
210 //! Return one of the following:
\r
211 //! - \b MPY32_FRACTIONAL_MODE_DISABLED
\r
212 //! - \b MPY32_FRACTIONAL_MODE_ENABLED
\r
213 //! \n Gets the Fractional Mode
\r
215 //*****************************************************************************
\r
216 extern uint8_t MPY32_getFractionalMode(void);
\r
218 //*****************************************************************************
\r
220 //! \brief Sets an 8-bit value into operand 1.
\r
222 //! This function sets the first operand for multiplication and determines what
\r
223 //! type of operation should be performed. Once the second operand is set, then
\r
224 //! the operation will begin.
\r
226 //! \param multiplicationType is the type of multiplication to perform once the
\r
227 //! second operand is set.
\r
228 //! Valid values are:
\r
229 //! - \b MPY32_MULTIPLY_UNSIGNED
\r
230 //! - \b MPY32_MULTIPLY_SIGNED
\r
231 //! - \b MPY32_MULTIPLYACCUMULATE_UNSIGNED
\r
232 //! - \b MPY32_MULTIPLYACCUMULATE_SIGNED
\r
233 //! \param operand is the 8-bit value to load into the 1st operand.
\r
237 //*****************************************************************************
\r
238 extern void MPY32_setOperandOne8Bit(uint8_t multiplicationType,
\r
241 //*****************************************************************************
\r
243 //! \brief Sets an 16-bit value into operand 1.
\r
245 //! This function sets the first operand for multiplication and determines what
\r
246 //! type of operation should be performed. Once the second operand is set, then
\r
247 //! the operation will begin.
\r
249 //! \param multiplicationType is the type of multiplication to perform once the
\r
250 //! second operand is set.
\r
251 //! Valid values are:
\r
252 //! - \b MPY32_MULTIPLY_UNSIGNED
\r
253 //! - \b MPY32_MULTIPLY_SIGNED
\r
254 //! - \b MPY32_MULTIPLYACCUMULATE_UNSIGNED
\r
255 //! - \b MPY32_MULTIPLYACCUMULATE_SIGNED
\r
256 //! \param operand is the 16-bit value to load into the 1st operand.
\r
260 //*****************************************************************************
\r
261 extern void MPY32_setOperandOne16Bit(uint8_t multiplicationType,
\r
264 //*****************************************************************************
\r
266 //! \brief Sets an 24-bit value into operand 1.
\r
268 //! This function sets the first operand for multiplication and determines what
\r
269 //! type of operation should be performed. Once the second operand is set, then
\r
270 //! the operation will begin.
\r
272 //! \param multiplicationType is the type of multiplication to perform once the
\r
273 //! second operand is set.
\r
274 //! Valid values are:
\r
275 //! - \b MPY32_MULTIPLY_UNSIGNED
\r
276 //! - \b MPY32_MULTIPLY_SIGNED
\r
277 //! - \b MPY32_MULTIPLYACCUMULATE_UNSIGNED
\r
278 //! - \b MPY32_MULTIPLYACCUMULATE_SIGNED
\r
279 //! \param operand is the 24-bit value to load into the 1st operand.
\r
283 //*****************************************************************************
\r
284 extern void MPY32_setOperandOne24Bit(uint8_t multiplicationType,
\r
287 //*****************************************************************************
\r
289 //! \brief Sets an 32-bit value into operand 1.
\r
291 //! This function sets the first operand for multiplication and determines what
\r
292 //! type of operation should be performed. Once the second operand is set, then
\r
293 //! the operation will begin.
\r
295 //! \param multiplicationType is the type of multiplication to perform once the
\r
296 //! second operand is set.
\r
297 //! Valid values are:
\r
298 //! - \b MPY32_MULTIPLY_UNSIGNED
\r
299 //! - \b MPY32_MULTIPLY_SIGNED
\r
300 //! - \b MPY32_MULTIPLYACCUMULATE_UNSIGNED
\r
301 //! - \b MPY32_MULTIPLYACCUMULATE_SIGNED
\r
302 //! \param operand is the 32-bit value to load into the 1st operand.
\r
306 //*****************************************************************************
\r
307 extern void MPY32_setOperandOne32Bit(uint8_t multiplicationType,
\r
310 //*****************************************************************************
\r
312 //! \brief Sets an 8-bit value into operand 2, which starts the multiplication.
\r
314 //! This function sets the second operand of the multiplication operation and
\r
315 //! starts the operation.
\r
317 //! \param operand is the 8-bit value to load into the 2nd operand.
\r
321 //*****************************************************************************
\r
322 extern void MPY32_setOperandTwo8Bit(uint8_t operand);
\r
324 //*****************************************************************************
\r
326 //! \brief Sets an 16-bit value into operand 2, which starts the
\r
327 //! multiplication.
\r
329 //! This function sets the second operand of the multiplication operation and
\r
330 //! starts the operation.
\r
332 //! \param operand is the 16-bit value to load into the 2nd operand.
\r
336 //*****************************************************************************
\r
337 extern void MPY32_setOperandTwo16Bit(uint16_t operand);
\r
339 //*****************************************************************************
\r
341 //! \brief Sets an 24-bit value into operand 2, which starts the
\r
342 //! multiplication.
\r
344 //! This function sets the second operand of the multiplication operation and
\r
345 //! starts the operation.
\r
347 //! \param operand is the 24-bit value to load into the 2nd operand.
\r
351 //*****************************************************************************
\r
352 extern void MPY32_setOperandTwo24Bit(uint32_t operand);
\r
354 //*****************************************************************************
\r
356 //! \brief Sets an 32-bit value into operand 2, which starts the
\r
357 //! multiplication.
\r
359 //! This function sets the second operand of the multiplication operation and
\r
360 //! starts the operation.
\r
362 //! \param operand is the 32-bit value to load into the 2nd operand.
\r
366 //*****************************************************************************
\r
367 extern void MPY32_setOperandTwo32Bit(uint32_t operand);
\r
369 //*****************************************************************************
\r
371 //! \brief Returns an 64-bit result of the last multiplication operation.
\r
373 //! This function returns all 64 bits of the result registers
\r
376 //! \return The 64-bit result is returned as a uint64_t type
\r
378 //*****************************************************************************
\r
379 extern uint64_t MPY32_getResult(void);
\r
381 //*****************************************************************************
\r
383 //! \brief Returns the Sum Extension of the last multiplication operation.
\r
385 //! This function returns the Sum Extension of the MPY module, which either
\r
386 //! gives the sign after a signed operation or shows a carry after a multiply-
\r
387 //! and-accumulate operation. The Sum Extension acts as a check for overflows
\r
391 //! \return The value of the MPY32 module Sum Extension.
\r
393 //*****************************************************************************
\r
394 extern uint16_t MPY32_getSumExtension(void);
\r
396 //*****************************************************************************
\r
398 //! \brief Returns the Carry Bit of the last multiplication operation.
\r
400 //! This function returns the Carry Bit of the MPY module, which either gives
\r
401 //! the sign after a signed operation or shows a carry after a multiply- and-
\r
402 //! accumulate operation.
\r
405 //! \return The value of the MPY32 module Carry Bit 0x0 or 0x1.
\r
407 //*****************************************************************************
\r
408 extern uint16_t MPY32_getCarryBitValue(void);
\r
410 //*****************************************************************************
\r
412 //! \brief Clears the Carry Bit of the last multiplication operation.
\r
414 //! This function clears the Carry Bit of the MPY module
\r
417 //! \return The value of the MPY32 module Carry Bit 0x0 or 0x1.
\r
419 //*****************************************************************************
\r
420 extern void MPY32_clearCarryBitValue(void);
\r
422 //*****************************************************************************
\r
424 //! \brief Preloads the result register
\r
426 //! This function Preloads the result register
\r
428 //! \param result value to preload the result register to
\r
432 //*****************************************************************************
\r
433 extern void MPY32_preloadResult(uint64_t result);
\r
435 //*****************************************************************************
\r
437 // Mark the end of the C bindings section for C++ compilers.
\r
439 //*****************************************************************************
\r
445 #endif // __MSP430WARE_MPY32_H__
\r