blob: b1fafc543a8a7a4eeaf2397ac99eced13f1bb1e2 [file] [log] [blame]
Vadim Iosevichd50ea462017-03-30 16:19:08 +03001/*
2 * Copyright (c) 2017, The Linux Foundation. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above
10 * copyright notice, this list of conditions and the following
11 * disclaimer in the documentation and/or other materials provided
12 * with the distribution.
13 * * Neither the name of The Linux Foundation nor the names of its
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#include "MemoryAccess.h"
31
32CMemoryAccess::CMemoryAccess(const TCHAR* tchDeviceName, DType devType)
33{
34 //do something with params
35 (void)tchDeviceName;
36 //if (devType == MST_MARLON)
37 //{
38 m_size = WLCT_DEV_MEMORY_SIZE;
39 m_baseAddress = 0x800000;
40 //}
41
42 deviceType = devType;
43 m_pMem = new char[m_size];
Vadim Iosevich82902242018-02-13 14:07:05 +020044 if (!m_pMem)
45 {
46 LOG_MESSAGE_ERROR(_T("Cannot allocate memory access buffer"));
47 exit(1);
48 }
49
50 memset(m_pMem, 0, m_size);
Vadim Iosevichd50ea462017-03-30 16:19:08 +030051}
52
53CMemoryAccess::~CMemoryAccess(void)
54{
55 CloseDevice();
56}
57
58int CMemoryAccess::GetType()
59{
60 return IDeviceAccess::ETypeMEMORY;
61}
62
63int CMemoryAccess::CloseDevice()
64{
65 if (m_pMem != NULL)
66 {
67 delete []m_pMem;
68 m_pMem = NULL;
69 }
70 return 0;
71}
72
73int CMemoryAccess::r32(DWORD addr, DWORD & val)
74{
75 DWORD actualAddr = addr - m_baseAddress;
76
77 if (actualAddr >= m_size)
78 return -1;
79
80 actualAddr = actualAddr >> 2;
81 val = ((DWORD*)m_pMem)[actualAddr];
82 LOG_MESSAGE_DEBUG(_T("ADDR(in bytes): %04X Value: 0x%08X"), addr, val);
83 return 0;
84}
85
86int CMemoryAccess::w32(DWORD addr, DWORD val)
87{
88 DWORD actualAddr = addr - m_baseAddress;
89 if (actualAddr >= m_size)
90 return -1;
91
92 actualAddr = actualAddr >> 2;
93 ((DWORD*)m_pMem)[actualAddr] = val;
94 LOG_MESSAGE_DEBUG(_T("ADDR: %04X Value: 0x%04X"),addr, val);
95 return 0;
96}
97
98int CMemoryAccess::rb(DWORD addr, DWORD blockSize, char *arrBlock)
99{
100 DWORD actualAddr = addr;
101// DWORD val;
102
103 //if (GetDeviceType() == MST_MARLON)
104 //{
105 actualAddr = addr - m_baseAddress;
106 //}
107
108 if ((actualAddr+blockSize) >= m_size)
109 return -1;
110
111 memcpy(arrBlock, &(m_pMem[actualAddr]), blockSize);
112
113// for (int inx = 0; inx < blockSize; inx++)
114// {
115// // wait between each loop
116// DWORD readFromIndex = actualAddr+inx;
117//
118// if (GetDeviceType() == MST_SWIFT)
119// {
120// val = ((USHORT*)m_pMem)[readFromIndex];
121// }
122//
123// if (GetDeviceType() == MST_MARLON)
124// {
125// val = ((DWORD*)m_pMem)[actualAddr];
126// }
127//
128// arrBlock[inx] = val;
129// }
130
131 return 0;
132}
133
134int CMemoryAccess::wb(DWORD addr, DWORD blockSize, const char *arrBlock)
135{
136 //do something with params
137 (void)addr;
138 (void)blockSize;
139 (void)arrBlock;
140
141 return 0;
142}
143
144void CMemoryAccess::rr32(DWORD addr, DWORD num_repeat, DWORD *arrBlock)
145{
146 DWORD* pFrom = &((DWORD*)m_pMem)[addr>>2];
147 for (DWORD loop = 0; loop < num_repeat; loop++)
148 {
149 // wait between each loop
150
151 arrBlock[loop] = *pFrom;
152 }
153}
154
155int CMemoryAccess::rr(DWORD addr, DWORD num_repeat, DWORD *arrBlock)
156{
157 if (!isInitialized())
158 return -1;
159
160 DWORD actualAddr = addr;
161
162 //if (GetDeviceType() == MST_MARLON)
163 //{
164 actualAddr = addr - m_baseAddress;
165 //}
166
167 if (actualAddr >= m_size)
168 return -1;
169
170 //if (GetDeviceType() == MST_MARLON)
171 //{
172 rr32(actualAddr, num_repeat, arrBlock);
173 //}
174 return 0;
175}
176
177int CMemoryAccess::getFwDbgMsg(FW_DBG_MSG** pMsg)
178{
179 //do something with params
180 (void)pMsg;
181
182// LOG_MESSAGE_ERROR(_T("NOT IMPLEMENTED"));
183 return WLCT_OS_ERROR_CALL_NOT_IMPLEMENTED;
184}
185
186int CMemoryAccess::clearAllFwDbgMsg()
187{
188 LOG_MESSAGE_ERROR(_T("NOT IMPLEMENTED"));
189 return WLCT_OS_ERROR_CALL_NOT_IMPLEMENTED;
190}
191
192int CMemoryAccess::do_reset(BOOL bFirstTime)
193{
194 //do something with params
195 (void)bFirstTime;
196 LOG_MESSAGE_ERROR(_T("NOT IMPLEMENTED"));
197 return WLCT_OS_ERROR_CALL_NOT_IMPLEMENTED;
198}
199
200
201int CMemoryAccess::do_sw_reset()
202{
203 LOG_MESSAGE_ERROR(_T("NOT IMPLEMENTED"));
204 return WLCT_OS_ERROR_CALL_NOT_IMPLEMENTED;
205}
206
207
208int CMemoryAccess::do_interface_reset()
209{
210 LOG_MESSAGE_ERROR(_T("NOT IMPLEMENTED"));
211 return WLCT_OS_ERROR_CALL_NOT_IMPLEMENTED;
212}