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.c - Driver for the mpy32 Module.
\r
36 //*****************************************************************************
\r
38 //*****************************************************************************
\r
40 //! \addtogroup mpy32_api mpy32
\r
43 //*****************************************************************************
\r
45 #include "inc/hw_regaccess.h"
\r
46 #include "inc/hw_memmap.h"
\r
48 #ifdef __MSP430_HAS_MPY32__
\r
53 void MPY32_setWriteDelay(uint16_t writeDelaySelect)
\r
55 HWREG16(MPY32_BASE + OFS_MPY32CTL0) &= ~(MPYDLY32 + MPYDLYWRTEN);
\r
56 HWREG16(MPY32_BASE + OFS_MPY32CTL0) |= writeDelaySelect;
\r
59 void MPY32_enableSaturationMode(void)
\r
61 HWREG8(MPY32_BASE + OFS_MPY32CTL0_L) |= MPYSAT;
\r
64 void MPY32_disableSaturationMode(void)
\r
66 HWREG8(MPY32_BASE + OFS_MPY32CTL0_L) &= ~(MPYSAT);
\r
69 uint8_t MPY32_getSaturationMode(void)
\r
71 return (HWREG8(MPY32_BASE + OFS_MPY32CTL0_L) & (MPYSAT));
\r
74 void MPY32_enableFractionalMode(void)
\r
76 HWREG8(MPY32_BASE + OFS_MPY32CTL0_L) |= MPYFRAC;
\r
79 void MPY32_disableFractionalMode(void)
\r
81 HWREG8(MPY32_BASE + OFS_MPY32CTL0_L) &= ~(MPYFRAC);
\r
84 uint8_t MPY32_getFractionalMode(void)
\r
86 return (HWREG8(MPY32_BASE + OFS_MPY32CTL0_L) & (MPYFRAC));
\r
89 void MPY32_setOperandOne8Bit(uint8_t multiplicationType,
\r
92 HWREG8(MPY32_BASE + OFS_MPY + multiplicationType) = operand;
\r
95 void MPY32_setOperandOne16Bit(uint8_t multiplicationType,
\r
98 HWREG16(MPY32_BASE + OFS_MPY + multiplicationType) = operand;
\r
101 void MPY32_setOperandOne24Bit(uint8_t multiplicationType,
\r
104 multiplicationType <<= 1;
\r
105 HWREG16(MPY32_BASE + OFS_MPY32L + multiplicationType) = operand;
\r
106 HWREG8(MPY32_BASE + OFS_MPY32H + multiplicationType) = (operand >> 16);
\r
109 void MPY32_setOperandOne32Bit(uint8_t multiplicationType,
\r
112 multiplicationType <<= 1;
\r
113 HWREG16(MPY32_BASE + OFS_MPY32L + multiplicationType) = operand;
\r
114 HWREG16(MPY32_BASE + OFS_MPY32H + multiplicationType) = (operand >> 16);
\r
117 void MPY32_setOperandTwo8Bit(uint8_t operand)
\r
119 HWREG8(MPY32_BASE + OFS_OP2) = operand;
\r
122 void MPY32_setOperandTwo16Bit(uint16_t operand)
\r
124 HWREG16(MPY32_BASE + OFS_OP2) = operand;
\r
127 void MPY32_setOperandTwo24Bit(uint32_t operand)
\r
129 HWREG16(MPY32_BASE + OFS_OP2L) = operand;
\r
130 HWREG8(MPY32_BASE + OFS_OP2H) = (operand >> 16);
\r
133 void MPY32_setOperandTwo32Bit(uint32_t operand)
\r
135 HWREG16(MPY32_BASE + OFS_OP2L) = operand;
\r
136 HWREG16(MPY32_BASE + OFS_OP2H) = (operand >> 16);
\r
139 uint64_t MPY32_getResult(void)
\r
143 result = HWREG16(MPY32_BASE + OFS_RES0);
\r
144 result += ((uint64_t)HWREG16(MPY32_BASE + OFS_RES1) << 16);
\r
145 result += ((uint64_t)HWREG16(MPY32_BASE + OFS_RES2) << 32);
\r
146 result += ((uint64_t)HWREG16(MPY32_BASE + OFS_RES3) << 48);
\r
150 uint16_t MPY32_getSumExtension(void)
\r
152 return (HWREG16(MPY32_BASE + OFS_SUMEXT));
\r
155 uint16_t MPY32_getCarryBitValue(void)
\r
157 return (HWREG16(MPY32_BASE + OFS_MPY32CTL0) | MPYC);
\r
160 void MPY32_clearCarryBitValue(void)
\r
162 HWREG16(MPY32_BASE + OFS_MPY32CTL0) &= ~MPYC;
\r
165 void MPY32_preloadResult(uint64_t result)
\r
167 HWREG16(MPY32_BASE + OFS_RES0) = (result & 0xFFFF);
\r
168 HWREG16(MPY32_BASE + OFS_RES1) = ((result >> 16) & 0xFFFF);
\r
169 HWREG16(MPY32_BASE + OFS_RES2) = ((result >> 32) & 0xFFFF);
\r
170 HWREG16(MPY32_BASE + OFS_RES3) = ((result >> 48) & 0xFFFF);
\r
174 //*****************************************************************************
\r
176 //! Close the doxygen group for mpy32_api
\r
179 //*****************************************************************************
\r