]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/MSP430X_MSP430FR5969_LaunchPad/driverlib/MSP430FR5xx_6xx/mpy32.c
Rename /Demo/MSP430FR5969_LaunchPad to /Demo/MSP430X_MSP430FR5969_LaunchPad for consi...
[freertos] / FreeRTOS / Demo / MSP430X_MSP430FR5969_LaunchPad / driverlib / MSP430FR5xx_6xx / mpy32.c
1 /* --COPYRIGHT--,BSD\r
2  * Copyright (c) 2014, Texas Instruments Incorporated\r
3  * All rights reserved.\r
4  *\r
5  * Redistribution and use in source and binary forms, with or without\r
6  * modification, are permitted provided that the following conditions\r
7  * are met:\r
8  *\r
9  * *  Redistributions of source code must retain the above copyright\r
10  *    notice, this list of conditions and the following disclaimer.\r
11  *\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
15  *\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
19  *\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
31  * --/COPYRIGHT--*/\r
32 //*****************************************************************************\r
33 //\r
34 // mpy32.c - Driver for the mpy32 Module.\r
35 //\r
36 //*****************************************************************************\r
37 \r
38 //*****************************************************************************\r
39 //\r
40 //! \addtogroup mpy32_api mpy32\r
41 //! @{\r
42 //\r
43 //*****************************************************************************\r
44 \r
45 #include "inc/hw_regaccess.h"\r
46 #include "inc/hw_memmap.h"\r
47 \r
48 #ifdef __MSP430_HAS_MPY32__\r
49 #include "mpy32.h"\r
50 \r
51 #include <assert.h>\r
52 \r
53 void MPY32_setWriteDelay(uint16_t writeDelaySelect)\r
54 {\r
55     HWREG16(MPY32_BASE + OFS_MPY32CTL0) &= ~(MPYDLY32 + MPYDLYWRTEN);\r
56     HWREG16(MPY32_BASE + OFS_MPY32CTL0) |= writeDelaySelect;\r
57 }\r
58 \r
59 void MPY32_enableSaturationMode(void)\r
60 {\r
61     HWREG8(MPY32_BASE + OFS_MPY32CTL0_L) |= MPYSAT;\r
62 }\r
63 \r
64 void MPY32_disableSaturationMode(void)\r
65 {\r
66     HWREG8(MPY32_BASE + OFS_MPY32CTL0_L) &= ~(MPYSAT);\r
67 }\r
68 \r
69 uint8_t MPY32_getSaturationMode(void)\r
70 {\r
71     return (HWREG8(MPY32_BASE + OFS_MPY32CTL0_L) & (MPYSAT));\r
72 }\r
73 \r
74 void MPY32_enableFractionalMode(void)\r
75 {\r
76     HWREG8(MPY32_BASE + OFS_MPY32CTL0_L) |= MPYFRAC;\r
77 }\r
78 \r
79 void MPY32_disableFractionalMode(void)\r
80 {\r
81     HWREG8(MPY32_BASE + OFS_MPY32CTL0_L) &= ~(MPYFRAC);\r
82 }\r
83 \r
84 uint8_t MPY32_getFractionalMode(void)\r
85 {\r
86     return (HWREG8(MPY32_BASE + OFS_MPY32CTL0_L) & (MPYFRAC));\r
87 }\r
88 \r
89 void MPY32_setOperandOne8Bit(uint8_t multiplicationType,\r
90                              uint8_t operand)\r
91 {\r
92     HWREG8(MPY32_BASE + OFS_MPY + multiplicationType) = operand;\r
93 }\r
94 \r
95 void MPY32_setOperandOne16Bit(uint8_t multiplicationType,\r
96                               uint16_t operand)\r
97 {\r
98     HWREG16(MPY32_BASE + OFS_MPY + multiplicationType) = operand;\r
99 }\r
100 \r
101 void MPY32_setOperandOne24Bit(uint8_t multiplicationType,\r
102                               uint32_t operand)\r
103 {\r
104     multiplicationType <<= 1;\r
105     HWREG16(MPY32_BASE + OFS_MPY32L + multiplicationType) = operand;\r
106     HWREG8(MPY32_BASE + OFS_MPY32H + multiplicationType) = (operand >> 16);\r
107 }\r
108 \r
109 void MPY32_setOperandOne32Bit(uint8_t multiplicationType,\r
110                               uint32_t operand)\r
111 {\r
112     multiplicationType <<= 1;\r
113     HWREG16(MPY32_BASE + OFS_MPY32L + multiplicationType) = operand;\r
114     HWREG16(MPY32_BASE + OFS_MPY32H + multiplicationType) = (operand >> 16);\r
115 }\r
116 \r
117 void MPY32_setOperandTwo8Bit(uint8_t operand)\r
118 {\r
119     HWREG8(MPY32_BASE + OFS_OP2) = operand;\r
120 }\r
121 \r
122 void MPY32_setOperandTwo16Bit(uint16_t operand)\r
123 {\r
124     HWREG16(MPY32_BASE + OFS_OP2) = operand;\r
125 }\r
126 \r
127 void MPY32_setOperandTwo24Bit(uint32_t operand)\r
128 {\r
129     HWREG16(MPY32_BASE + OFS_OP2L) = operand;\r
130     HWREG8(MPY32_BASE + OFS_OP2H) = (operand >> 16);\r
131 }\r
132 \r
133 void MPY32_setOperandTwo32Bit(uint32_t operand)\r
134 {\r
135     HWREG16(MPY32_BASE + OFS_OP2L) = operand;\r
136     HWREG16(MPY32_BASE + OFS_OP2H) = (operand >> 16);\r
137 }\r
138 \r
139 uint64_t MPY32_getResult(void)\r
140 {\r
141     uint64_t result;\r
142 \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
147     return (result);\r
148 }\r
149 \r
150 uint16_t MPY32_getSumExtension(void)\r
151 {\r
152     return (HWREG16(MPY32_BASE + OFS_SUMEXT));\r
153 }\r
154 \r
155 uint16_t MPY32_getCarryBitValue(void)\r
156 {\r
157     return (HWREG16(MPY32_BASE + OFS_MPY32CTL0) | MPYC);\r
158 }\r
159 \r
160 void MPY32_clearCarryBitValue(void)\r
161 {\r
162     HWREG16(MPY32_BASE + OFS_MPY32CTL0) &= ~MPYC;\r
163 }\r
164 \r
165 void MPY32_preloadResult(uint64_t result)\r
166 {\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
171 }\r
172 \r
173 #endif\r
174 //*****************************************************************************\r
175 //\r
176 //! Close the doxygen group for mpy32_api\r
177 //! @}\r
178 //\r
179 //*****************************************************************************\r