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 * ======== hal.c ========\r
34 *\r
35 */\r
36 #include "msp430.h"\r
37 \r
38 #include "driverlib.h"\r
39 \r
40 #include "USB_API/USB_Common/device.h"\r
41 #include "USB_config/descriptors.h"\r
42 \r
43 #include "hal.h"\r
44 \r
45 #define GPIO_ALL GPIO_PIN0|GPIO_PIN1|GPIO_PIN2|GPIO_PIN3| \\r
46 GPIO_PIN4|GPIO_PIN5|GPIO_PIN6|GPIO_PIN7\r
47 \r
48 \r
49 \r
50 /*\r
51 * This function drives all the I/O's as output-low, to avoid floating inputs\r
52 * (which cause extra power to be consumed). This setting is compatible with\r
53 * TI FET target boards, the F5529 Launchpad, and F5529 Experimenters Board;\r
54 * but may not be compatible with custom hardware, which may have components\r
55 * attached to the I/Os that could be affected by these settings. So if using\r
56 * other boards, this function may need to be modified.\r
57 */\r
58 void initPorts(void)\r
59 {\r
60 PMAPPWD = PMAPKEY; // Enable Write-access to modify port mapping registers\r
61 PMAPCTL = PMAPRECFG; // Allow reconfiguration during runtime\r
62 PMAPPWD = 0; // Disable Write-access to port mapping registers\r
63 \r
64 #ifdef __MSP430_HAS_PORT1_R__\r
65 GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_ALL);\r
66 GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_ALL);\r
67 #endif\r
68 \r
69 #ifdef __MSP430_HAS_PORT2_R__\r
70 GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_ALL);\r
71 GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_ALL);\r
72 #endif\r
73 \r
74 #ifdef __MSP430_HAS_PORT3_R__\r
75 GPIO_setOutputLowOnPin(GPIO_PORT_P3, GPIO_ALL);\r
76 GPIO_setAsOutputPin(GPIO_PORT_P3, GPIO_ALL);\r
77 #endif\r
78 \r
79 #ifdef __MSP430_HAS_PORT4_R__\r
80 GPIO_setOutputLowOnPin(GPIO_PORT_P4, GPIO_ALL);\r
81 GPIO_setAsOutputPin(GPIO_PORT_P4, GPIO_ALL);\r
82 #endif\r
83 \r
84 #ifdef __MSP430_HAS_PORT5_R__\r
85 GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_ALL);\r
86 GPIO_setAsOutputPin(GPIO_PORT_P5, GPIO_ALL);\r
87 #endif\r
88 \r
89 #ifdef __MSP430_HAS_PORT6_R__\r
90 GPIO_setOutputLowOnPin(GPIO_PORT_P6, GPIO_ALL);\r
91 GPIO_setAsOutputPin(GPIO_PORT_P6, GPIO_ALL);\r
92 #endif\r
93 \r
94 #ifdef __MSP430_HAS_PORT7_R__\r
95 GPIO_setOutputLowOnPin(GPIO_PORT_P7, GPIO_ALL);\r
96 GPIO_setAsOutputPin(GPIO_PORT_P7, GPIO_ALL);\r
97 #endif\r
98 \r
99 #ifdef __MSP430_HAS_PORT8_R__\r
100 GPIO_setOutputLowOnPin(GPIO_PORT_P8, GPIO_ALL);\r
101 GPIO_setAsOutputPin(GPIO_PORT_P8, GPIO_ALL);\r
102 #endif\r
103 \r
104 #ifdef __MSP430_HAS_PORT9_R__\r
105 GPIO_setOutputLowOnPin(GPIO_PORT_P9, GPIO_ALL);\r
106 GPIO_setAsOutputPin(GPIO_PORT_P9, GPIO_ALL);\r
107 #endif\r
108 \r
109 #ifdef __MSP430_HAS_PORTJ_R__\r
110 GPIO_setOutputLowOnPin(GPIO_PORT_PJ, GPIO_ALL);\r
111 GPIO_setAsOutputPin(GPIO_PORT_PJ, GPIO_ALL);\r
112 #endif\r
113 }\r
114 \r
115 /* Configures the system clocks:\r
116 * MCLK = SMCLK = DCO/FLL = mclkFreq (expected to be expressed in Hz)\r
117 * ACLK = FLLref = REFO=32kHz\r
118 *\r
119 * XT2 is not configured here. Instead, the USB API automatically starts XT2\r
120 * when beginning USB communication, and optionally disables it during USB\r
121 * suspend. It's left running after the USB host is disconnected, at which\r
122 * point you're free to disable it. You need to configure the XT2 frequency\r
123 * in the Descriptor Tool (currently set to 4MHz in this example).\r
124 * See the Programmer's Guide for more information.\r
125 */\r
126 void initClocks(uint32_t mclkFreq)\r
127 {\r
128 #ifndef DRIVERLIB_LEGACY_MODE\r
129 UCS_clockSignalInit(\r
130 UCS_FLLREF,\r
131 UCS_REFOCLK_SELECT,\r
132 UCS_CLOCK_DIVIDER_1);\r
133 \r
134 UCS_clockSignalInit(\r
135 UCS_ACLK,\r
136 UCS_XT2CLK_SELECT,\r
137 UCS_CLOCK_DIVIDER_1);\r
138 \r
139 UCS_initFLLSettle(\r
140 mclkFreq/1000,\r
141 mclkFreq/32768);\r
142 #else\r
143 UCS_clockSignalInit(\r
144 UCS_BASE,\r
145 UCS_FLLREF,\r
146 UCS_REFOCLK_SELECT,\r
147 UCS_CLOCK_DIVIDER_1);\r
148 \r
149 UCS_clockSignalInit(\r
150 UCS_BASE,\r
151 UCS_ACLK,\r
152 UCS_REFOCLK_SELECT,\r
153 UCS_CLOCK_DIVIDER_1);\r
154 \r
155 UCS_initFLLSettle(\r
156 UCS_BASE,\r
157 mclkFreq/1000,\r
158 mclkFreq/32768);\r
159 \r
160 #endif\r
161 \r
162 }\r
163 //Released_Version_4_10_02\r