1 /**
2 * \ingroup MODULMACROSXV2
3 *
4 * \file LeaSyncConditional.c
5 *
6 * \brief <FILEBRIEF>
7 *
8 */
9 /*
10 * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/
11 *
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 *
17 * Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 *
20 * Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the
23 * distribution.
24 *
25 * Neither the name of Texas Instruments Incorporated nor the names of
26 * its contributors may be used to endorse or promote products derived
27 * from this software without specific prior written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 */
41
42 #include "arch.h"
43 #include "edt.h"
44 #include "hal.h"
45 #include "hal_ref.h"
46 #include "stream.h"
47 #include "JTAG_defs.h"
48 #include "EEM_defs.h"
49 #include "global_variables.h"
50
51 #define LEASCCNF1 0x08
52 #define LEASCBSY 0x01
53
HAL_FUNCTION(_hal_LeaSyncConditional)54 HAL_FUNCTION(_hal_LeaSyncConditional)
55 {
56 unsigned long baseAddres = 0;
57 unsigned short tclkCycles = 20000;
58 volatile unsigned long currentPcAddress = 0;
59 unsigned short leaReg = 0;
60
61 STREAM_get_long(&baseAddres);
62
63 leaReg = ReadMemWordXv2(baseAddres | LEASCCNF1);
64 if(!(leaReg & LEASCBSY))
65 {
66 STREAM_put_word((leaReg & LEASCBSY));
67 return 0;
68 }
69
70 // Set PC to "safe" address
71 SetPcXv2(0x0080, SAFE_PC_ADDRESS);
72 cntrl_sig_16bit();
73 SetReg_16Bits(0x0501);
74 IHIL_Tclk(1);
75 addr_capture();
76
77 cntrl_sig_16bit();
78 SetReg_16Bits(0x1501);
79
80 while(tclkCycles-- > 0)
81 {
82 IHIL_TCLK();
83 }
84 addr_capture();
85 currentPcAddress = SetReg_20Bits(0x0);
86
87 if((currentPcAddress != SAFE_PC_ADDRESS) && (currentPcAddress != SAFE_PC_ADDRESS+2))
88 {
89 return -1;
90 }
91
92 leaReg = ReadMemWordXv2(baseAddres | LEASCCNF1);
93 STREAM_put_word((leaReg & LEASCBSY));
94 return 0;
95 }
96