2020-2021 Sunseeker Telemetry and Lighting System
mpy32.c
Go to the documentation of this file.
1 //*****************************************************************************
2 //
3 // mpy32.c - Driver for the mpy32 Module.
4 //
5 //*****************************************************************************
6 
7 //*****************************************************************************
8 //
11 //
12 //*****************************************************************************
13 
14 #include "inc/hw_memmap.h"
15 
16 #ifdef __MSP430_HAS_MPY32__
17 #include "mpy32.h"
18 
19 #include <assert.h>
20 
21 void MPY32_setWriteDelay (uint16_t writeDelaySelect)
22 {
23  HWREG16(MPY32_BASE + OFS_MPY32CTL0) &= ~(MPYDLY32 + MPYDLYWRTEN);
24  HWREG16(MPY32_BASE + OFS_MPY32CTL0) |= writeDelaySelect;
25 }
26 
27 void MPY32_enableSaturationMode (void)
28 {
29  HWREG8(MPY32_BASE + OFS_MPY32CTL0_L) |= MPYSAT;
30 }
31 
32 void MPY32_disableSaturationMode (void)
33 {
34  HWREG8(MPY32_BASE + OFS_MPY32CTL0_L) &= ~(MPYSAT);
35 }
36 
37 uint8_t MPY32_getSaturationMode (void)
38 {
39  return (HWREG8(MPY32_BASE + OFS_MPY32CTL0_L) &(MPYSAT));
40 }
41 
42 void MPY32_enableFractionalMode (void)
43 {
44  HWREG8(MPY32_BASE + OFS_MPY32CTL0_L) |= MPYFRAC;
45 }
46 
47 void MPY32_disableFractionalMode (void)
48 {
49  HWREG8(MPY32_BASE + OFS_MPY32CTL0_L) &= ~(MPYFRAC);
50 }
51 
52 uint8_t MPY32_getFractionalMode (void)
53 {
54  return (HWREG8(MPY32_BASE + OFS_MPY32CTL0_L) &(MPYFRAC));
55 }
56 
57 void MPY32_setOperandOne8Bit (uint8_t multiplicationType,
58  uint8_t operand)
59 {
60  HWREG8(MPY32_BASE + OFS_MPY + multiplicationType) = operand;
61 }
62 
63 void MPY32_setOperandOne16Bit (uint8_t multiplicationType,
64  uint16_t operand)
65 {
66  HWREG16(MPY32_BASE + OFS_MPY + multiplicationType) = operand;
67 }
68 
69 void MPY32_setOperandOne24Bit (uint8_t multiplicationType,
70  uint32_t operand)
71 {
72  multiplicationType <<= 1;
73  HWREG16(MPY32_BASE + OFS_MPY32L + multiplicationType) = operand;
74  HWREG8(MPY32_BASE + OFS_MPY32H + multiplicationType) = (operand >> 16);
75 }
76 
77 void MPY32_setOperandOne32Bit (uint8_t multiplicationType,
78  uint32_t operand)
79 {
80  multiplicationType <<= 1;
81  HWREG16(MPY32_BASE + OFS_MPY32L + multiplicationType) = operand;
82  HWREG16(MPY32_BASE + OFS_MPY32H + multiplicationType) = (operand >> 16);
83 }
84 
85 void MPY32_setOperandTwo8Bit (uint8_t operand)
86 {
87  HWREG8(MPY32_BASE + OFS_OP2) = operand;
88 }
89 
90 void MPY32_setOperandTwo16Bit (uint16_t operand)
91 {
92  HWREG16(MPY32_BASE + OFS_OP2) = operand;
93 }
94 
95 void MPY32_setOperandTwo24Bit (uint32_t operand)
96 {
97  HWREG16(MPY32_BASE + OFS_OP2L) = operand;
98  HWREG8(MPY32_BASE + OFS_OP2H) = (operand >> 16);
99 }
100 
101 void MPY32_setOperandTwo32Bit (uint32_t operand)
102 {
103  HWREG16(MPY32_BASE + OFS_OP2L) = operand;
104  HWREG16(MPY32_BASE + OFS_OP2H) = (operand >> 16);
105 }
106 
107 uint64_t MPY32_getResult (void)
108 {
109  uint64_t result;
110 
111  result = HWREG16(MPY32_BASE + OFS_RES0);
112  result += ((uint64_t)HWREG16(MPY32_BASE + OFS_RES1) << 16);
113  result += ((uint64_t)HWREG16(MPY32_BASE + OFS_RES2) << 32);
114  result += ((uint64_t)HWREG16(MPY32_BASE + OFS_RES3) << 48);
115  return ( result );
116 }
117 
118 uint16_t MPY32_getSumExtension (void)
119 {
120  return ( HWREG16(MPY32_BASE + OFS_SUMEXT) );
121 }
122 
123 uint16_t MPY32_getCarryBitValue (void)
124 {
125  return ( HWREG16(MPY32_BASE + OFS_MPY32CTL0) | MPYC);
126 }
127 void MPY32_clearCarryBitValue (void)
128 {
129  HWREG16(MPY32_BASE + OFS_MPY32CTL0) &= ~MPYC;
130 }
131 void MPY32_preloadResult (uint64_t result)
132 {
133  HWREG16(MPY32_BASE + OFS_RES0) = (result & 0xFFFF);
134  HWREG16(MPY32_BASE + OFS_RES1) = ((result >> 16) & 0xFFFF);
135  HWREG16(MPY32_BASE + OFS_RES2) = ((result >> 32) & 0xFFFF);
136  HWREG16(MPY32_BASE + OFS_RES3) = ((result >> 48) & 0xFFFF);
137 }
138 
139 #endif
140 //*****************************************************************************
141 //
144 //
145 //*****************************************************************************
#define HWREG8(x)
Definition: hw_memmap.h:41
#define HWREG16(x)
Definition: hw_memmap.h:39