1 /**
2 * \ingroup MODULMACROS
3 *
4 * \file ReadMemWords.c
5 *
6 * \brief Read words (16bit values) from a memory mapped location
7 *
8 */
9 /*
10 * Copyright (C) 2012 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 "error_def.h"
43 #include "arch.h"
44 #include "edt.h"
45 #include "hal.h"
46 #include "hal_ref.h"
47 #include "stream.h"
48
49 extern unsigned long lAddr;
50 extern unsigned long lLen;
51
52 /**
53 ReadMemWords
54 Read words (16bit values) from a memory mapped location.
55 inData: <addr(32)> <length(32)>
56 outData: <data(16)>{*}
57 addr: the address to start reading from
58 length: number of words to read
59 data: requested data
60 */
61
HAL_FUNCTION(_hal_ReadMemWords)62 HAL_FUNCTION(_hal_ReadMemWords)
63 {
64 unsigned long i;
65 unsigned long lAddr;
66 unsigned long lLen;
67
68 if(STREAM_get_long(&lAddr) != 0)
69 {
70 return HALERR_READ_MEM_WORD_NO_ADDRESS;
71 }
72 if(STREAM_get_long(&lLen) < 0)
73 {
74 return HALERR_READ_MEM_WORD_NO_SIZE;
75 }
76
77 halt_cpu();
78 IHIL_Tclk(0);
79 for(i = 0; i < lLen; i++)
80 {
81 addr_16bit();
82 SetReg_16Bits((unsigned short)lAddr);
83 data_to_addr();
84 IHIL_Tclk(1);
85 IHIL_Tclk(0);
86 STREAM_put_word(SetReg_16Bits(0));
87 lAddr += 2;
88 }
89 IHIL_Tclk(1);
90 release_cpu();
91
92 instrLoad();
93
94 return 0;
95 }
96