1 /*
2 * \ingroup MODULMACROS
3 *
4 * \file WaitForDebugHaltArm.c
5 *
6 * \brief <FILEBRIEF>
7 *
8 *
9 * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/
10 *
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 *
16 * Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 *
19 * Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the
22 * distribution.
23 *
24 * Neither the name of Texas Instruments Incorporated nor the names of
25 * its contributors may be used to endorse or promote products derived
26 * from this software without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 */
40
41 #include "arch.h"
42 #include "edt.h"
43 #include "hal.h"
44 #include "stream.h"
45 #include "error_def.h"
46 #include "global_variables.h"
47
48 /**
49 WaitForDebugHalt
50 Test the DHCSR register for specific bits and
51 return if one of them is set.
52 This is best used with the ExecLoop command type.
53 inData: <Mask(16)>
54 outData: <Ctrl(16)>
55 Mask: the bits to look for
56 Ctrl: the read DHCSR register
57 */
58 #if defined(MSP430_UIF) || defined(MSP_FET)
59 extern ARMConfigSettings armConfigSettings;
60 #endif
61
checkDhcsrRegForBbHit()62 short checkDhcsrRegForBbHit()
63 {
64 unsigned long dhcsrValue = 0;
65 unsigned short* syncWithRunVarAddress = getTargetRunningVar();
66
67 if(syncWithRunVarAddress)
68 {
69 if(!(*syncWithRunVarAddress))
70 {
71 return 2;
72 }
73 }
74
75 if(IHIL_Write_Read_Mem_Ap(0, DHCSR, &dhcsrValue, READ) == -1)
76 {
77 return HALERR_UNDEFINED_ERROR;
78 }
79 if(dhcsrValue & S_HALT)
80 {
81
82 STREAM_put_long(dhcsrValue);
83 if(syncWithRunVarAddress)
84 {
85 *syncWithRunVarAddress = 0x0000;
86 }
87 return 1;
88 }
89 return 2;
90 }
91
92
HAL_FUNCTION(_hal_WaitForDebugHaltArm)93 HAL_FUNCTION(_hal_WaitForDebugHaltArm)
94 {
95 short RetState = HALERR_UNDEFINED_ERROR;
96 #if defined(MSP430_UIF) || defined(MSP_FET)
97 unsigned long val = 0;
98 if(armConfigSettings.ulpDebug)
99 {
100 IHIL_Write_Read_Dp(DP_CTRL_STAT, &val, READ);
101
102 if(val & DP_CTRL_STAT_CDBGPWRUPACK )
103 {
104 if( powerUpArm() != 0)
105 {
106 return RetState = 2;
107 }
108 if(checkWakeup() != 0)
109 {
110 return RetState = 2;
111 }
112 RetState = checkDhcsrRegForBbHit();
113 }
114 }
115 else // high power force
116 {
117 RetState = checkDhcsrRegForBbHit();
118 }
119 #endif
120 return RetState;
121 }
122