1 /*
2 * hal.c
3 *
4 * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/
5 *
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 *
14 * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the
17 * distribution.
18 *
19 * Neither the name of Texas Instruments Incorporated nor the names of
20 * its contributors may be used to endorse or promote products derived
21 * from this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */
35
36 //! \ingroup MODULHAL
37 //! \file hal.c
38 //!
39
40 #include "hw_compiler_specific.h"
41 #include "HalGlobalVars.h"
42 #include "edt.h"
43 #include "hal.h"
44 #include "hal_ref.h"
45 #include "stream.h"
46 #include "string.h"
47
48
49 // global variables to handle JTAG chain
50 unsigned short activeDevice;
51 REQUIRED(activeDevice)
52
53 unsigned char numOfDevices;
54 REQUIRED(numOfDevices)
55
56 unsigned short TCE;
57 REQUIRED(TCE)
58
59 DevicePowerSettings devicePowerSettings;
60 REQUIRED(devicePowerSettings)
61
62 DeviceSettings deviceSettings;
63 REQUIRED(deviceSettings)
64
65 // global variables to handle Emulation clock control
66 unsigned long _hal_mclkCntrl0;
67 REQUIRED(_hal_mclkCntrl0)
68
69 HalRec hal_functions_[HAL_FUNCTIONS_SIZE];
70
71 unsigned short setPCclockBeforeCapture = 0;
72 REQUIRED(setPCclockBeforeCapture)
73
74 unsigned short altRomAddressForCpuRead;
75 REQUIRED(altRomAddressForCpuRead)
76
77 unsigned short wdtctlAddress5xx = 0x15C;
78 REQUIRED(wdtctlAddress5xx)
79
80 unsigned short enhancedPsa = 0;
81 REQUIRED(enhancedPsa)
82
83 char traceBuffer[256]; ///< Trace buffer used to print out JTAG IR and DR shofts to debug port
84
85 // global variables use for JTAG/SWD DAP
86 unsigned long cswValues[4];
REQUIRED(cswValues)87 REQUIRED(cswValues)
88
89 ARMConfigSettings armConfigSettings;
90 REQUIRED(armConfigSettings)
91
92 #ifndef __data20
93 #define __data20
94 #endif
95
96 #define MACRO(x) {ID_##x, (void __data20 *)_hal_##x },
97 HalRec hal_functions_default_[HAL_FUNCTIONS_DEFAULT_SIZE] =
98 {
99 MACRO(Zero)
100 MACRO_LIST
101 };
102 #undef MACRO
103
REQUIRED(_init_Hal)104 REQUIRED(_init_Hal)
105
106
107 void _init_Hal(void)
108 {
109 unsigned char i;
110
111 for(i=0; i < (sizeof(hal_functions_)/sizeof(HalRec)); i++)
112 {
113 if(i < (sizeof(hal_functions_default_)/sizeof(HalRec)))
114 {
115 hal_functions_[i].id = hal_functions_default_[i].id;
116 hal_functions_[i].function = hal_functions_default_[i].function;
117 }
118 else
119 {
120 hal_functions_[i].id = 0xFFFF;
121 hal_functions_[i].function = NULL;
122 }
123 }
124 }
125
HAL_FUNCTION(_hal_Zero)126 HAL_FUNCTION(_hal_Zero)
127 {
128 return 0;
129 }
130
HAL_FUNCTION(_hal_Init)131 HAL_FUNCTION(_hal_Init)
132 {
133 //EDT_Init();
134 return 0;
135 }
136
137 extern unsigned int LPMx5_DEVICE_STATE;
138 extern int intstate;
139 extern unsigned long long prevJState;
140 extern unsigned short lastTraceWritePos;
141
142
HAL_FUNCTION(_hal_ResetStaticGlobalVars)143 HAL_FUNCTION(_hal_ResetStaticGlobalVars)
144 {
145 LPMx5_DEVICE_STATE = 1;
146 intstate = 0;
147 prevJState = 0x0000000000000000;
148 lastTraceWritePos = 0;
149 return 0;
150 }
151
HAL_FUNCTION(_hal_SetVcc)152 HAL_FUNCTION(_hal_SetVcc)
153 {
154 unsigned short vcc;
155 STREAM_get_word(&vcc);
156 IHIL_SetVcc(vcc);
157 return 0;
158 }
159
160
HAL_FUNCTION(_hal_SwitchMosfet)161 HAL_FUNCTION(_hal_SwitchMosfet)
162 {
163 #ifdef MSP_FET
164 unsigned short on = 0;
165 STREAM_get_word(&on);
166 if (on)
167 {
168 IHIL_SwitchVccFET(1);
169 }
170 else
171 {
172 IHIL_SwitchVccFET(0);
173 }
174 return 0;
175 #else
176 return -1;
177 #endif
178 }
179
180
HAL_FUNCTION(_hal_GetVcc)181 HAL_FUNCTION(_hal_GetVcc)
182 {
183 double vcc = 0;
184 double ext_vcc = 0;
185
186 IHIL_GetVcc(&vcc, &ext_vcc);
187 STREAM_put_word((unsigned short)vcc);
188 STREAM_put_word((unsigned short)ext_vcc);
189 return 0;
190 }
191
HAL_FUNCTION(_hal_GetFuses)192 HAL_FUNCTION(_hal_GetFuses)
193 {
194 config_fuses();
195 STREAM_put_byte((unsigned char)SetReg_8Bits(0));
196 return 0;
197 }
198
HAL_FUNCTION(_hal_DummyMacro)199 HAL_FUNCTION(_hal_DummyMacro)
200 {
201 return -1;
202 }
203 /* EOF */
204