1 /*
2  * \ingroup MODULMACROS
3  *
4  * \file ScanAPArm.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 "JTAG_defs.h"
46 #include "error_def.h"
47 
48 /**
49   ScanAP: Scan access port and provide back nil terminated list
50 */
51 #if defined(MSP430_UIF) || defined(MSP_FET)
52     extern unsigned long cswValues[4];
53 #endif
54 
HAL_FUNCTION(_hal_ScanApArm)55 HAL_FUNCTION(_hal_ScanApArm)
56 {
57 #if defined(MSP430_UIF) || defined(MSP_FET)
58     unsigned long val = 0;
59     unsigned long apsel = 0;
60 
61     // Set system and debug power up if cleared
62     if( powerUpArm() != 0)
63     {
64         return HALERR_UNDEFINED_ERROR;
65     }
66 
67     IHIL_Write_Read_Ap(AP_IDR | apsel, &val, READ);
68     if(val)
69     {
70         STREAM_put_long(val); // IDR value
71 
72         IHIL_Write_Read_Ap(AP_BASE | apsel, &val, READ);
73         STREAM_put_long(val); // BASE value
74 
75         IHIL_Write_Read_Ap(AP_CFG | apsel, &val, READ);
76         STREAM_put_long(val); // CFG value
77 
78         STREAM_put_byte(apsel >> 24); // Port number
79 
80         // Read and save CSW value
81         IHIL_Write_Read_Ap(AP_CSW | apsel, &val, READ);
82         cswValues[(apsel >> 24) & 0x3] = val & ~(AP_CSW_SIZE_MASK | AP_CSW_ADDRINC_MASK);
83     }
84     STREAM_put_long(val);
85 #endif
86     return 0;
87 }
88