-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdvfs.c
122 lines (119 loc) · 3.51 KB
/
dvfs.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include "portable.h"
#ifdef __TOOLS_MSP__
#include "driverlib.h"
#endif
#include "dvfs.h"
#ifdef __MSP430__
unsigned int FreqLevel = 8;
#elif defined(__MSP432__)
unsigned int FreqLevel = 10;
#endif
/*
* 10 level of CPU frequency for MSP430 and MSP432
*
* Level: 1: 1MHz
* 2: 2.67MHz
* 3: 3.33MHz
* 4: 4MHz
* 5: 5.33MHz
* 6: 6.67MHz
* 7: 8MHz
* 8: 16MHz
* 9: 12MHz
* 10: 24MHz
* 11: 48MHz
*
*/
void setFrequency(int level)
{
switch(level)
{
#ifdef __MSP430__
case 1:// Set DCO frequency to 1 MHz
CS_setDCOFreq(CS_DCORSEL_0, CS_DCOFSEL_0);
FreqLevel = 1;
break;
case 2:// Set DCO frequency to 2.67 MHz
CS_setDCOFreq(CS_DCORSEL_0, CS_DCOFSEL_1);
FreqLevel = 2;
break;
case 3:// Set DCO frequency to 3.5 MHz
CS_setDCOFreq(CS_DCORSEL_0, CS_DCOFSEL_2);
FreqLevel = 3;
break;
case 4:// Set DCO frequency to 4 MHz
CS_setDCOFreq(CS_DCORSEL_0, CS_DCOFSEL_3);
FreqLevel = 4;
break;
case 5:// Set DCO frequency to 5.33 MHz
CS_setDCOFreq(CS_DCORSEL_0, CS_DCOFSEL_4);
FreqLevel = 5;
break;
case 6:// Set DCO frequency to 7 MHz
CS_setDCOFreq(CS_DCORSEL_0, CS_DCOFSEL_5);
FreqLevel = 6;
break;
case 7:// Set DCO frequency to 8 MHz
CS_setDCOFreq(CS_DCORSEL_0, CS_DCOFSEL_6);
FreqLevel = 7;
break;
case 8:// Set DCO frequency to 16 MHz
FRCTL0 = FRCTLPW | NWAITS_1; //Up to 16Mhz
CS_setDCOFreq(CS_DCORSEL_1, CS_DCOFSEL_4);
FreqLevel = 8;
break;
#elif defined(__MSP432__)
case 9: // Set DCO to 12MHz
CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_12);
FreqLevel = 9;
break;
case 10: // set DCO to 24MHz
CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_24);
FreqLevel = 10;
break;
case 11: // set DCO to 48MHz
// Before we start we have to change VCORE to 1 to support the 48MHz frequency
// The board will be bricked and require a factory reset without adjusting VCORE!
// https://e2e.ti.com/support/microcontrollers/msp430/f/msp-low-power-microcontroller-forum/610691/ccs-msp432p401r-_bricked_-launchpad-cannot-program-the-device-anymore-after-using-cs_setdcofrequency
PCM_setCoreVoltageLevel(PCM_AM_LDO_VCORE1);
FlashCtl_setWaitState(FLASH_BANK0, 1);
FlashCtl_setWaitState(FLASH_BANK1, 1);
CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_48);
FreqLevel = 11;
break;
#endif
default:
while (1);
}
}
unsigned long getFrequency(int level)
{
switch(level)
{
case 1:// Set DCO frequency to 1 MHz
return 1000000;
case 2:// Set DCO frequency to 2.67 MHz
return 2670000;
case 3:// Set DCO frequency to 3.33 MHz
return 3330000;
case 4:// Set DCO frequency to 4 MHz
return 4000000;
case 5:// Set DCO frequency to 5.33 MHz
return 5330000;
case 6:// Set DCO frequency to 6.67 MHz
return 6670000;
case 7:// Set DCO frequency to 8 MHz
return 8000000;
case 8:// Set DCO frequency to 16 MHz
return 16000000;
case 9: // Set DCO frequency to 12MHz
return 12000000;
case 10: // set DCO frequency to 24MHz
return 24000000;
case 11: // set DCO frequency to 48MHz
return 48000000;
default:
while (1);
}
return 0;
}