| Line 86... |
Line 86... |
| 86 |
tailaddr = (end - min(end - bodyaddr, blksize) + align - 1) & ~(align - 1)
|
86 |
tailaddr = (end - min(end - bodyaddr, blksize) + align - 1) & ~(align - 1)
|
| 87 |
else: tailaddr = end
|
87 |
else: tailaddr = end
|
| 88 |
tailsize = end - tailaddr
|
88 |
tailsize = end - tailaddr
|
| 89 |
return (headsize, tailaddr - bodyaddr, tailsize)
|
89 |
return (headsize, tailaddr - bodyaddr, tailsize)
|
| 90 |
|
90 |
|
| - |
|
91 |
def _readmem(self, addr, size):
|
| - |
|
92 |
""" Reads the memory from location 'addr' with size 'size'
|
| - |
|
93 |
from the device.
|
| - |
|
94 |
"""
|
| - |
|
95 |
resp = self.lib.monitorcommand(struct.pack("IIII", 4, addr, size, 0), "III%ds" % size, (None, None, None, "data"))
|
| - |
|
96 |
return resp.data
|
| - |
|
97 |
|
| - |
|
98 |
def _writemem(self, addr, data):
|
| - |
|
99 |
""" Writes the data in 'data' to the location 'addr'
|
| - |
|
100 |
in the memory of the device.
|
| - |
|
101 |
"""
|
| - |
|
102 |
return self.lib.monitorcommand(struct.pack("IIII%ds" % len(data), 5, addr, len(data), 0, data), "III", (None, None, None))
|
| - |
|
103 |
|
| - |
|
104 |
def _readdma(self, addr, size):
|
| - |
|
105 |
""" Reads the memory from location 'addr' with size 'size'
|
| - |
|
106 |
from the device. This uses DMA and the data in endpoint.
|
| - |
|
107 |
"""
|
| - |
|
108 |
self.lib.monitorcommand(struct.pack("IIII", 6, addr, size, 0), "III", (None, None, None))
|
| - |
|
109 |
return struct.unpack("%ds" % size, self.lib.dev.din(size))[0]
|
| - |
|
110 |
|
| - |
|
111 |
def _writedma(self, addr, data):
|
| - |
|
112 |
""" Writes the data in 'data' to the location 'addr'
|
| - |
|
113 |
in the memory of the device. This uses DMA and the data out endpoint.
|
| - |
|
114 |
"""
|
| - |
|
115 |
self.lib.monitorcommand(struct.pack("IIII", 7, addr, len(data), 0), "III", (None, None, None))
|
| - |
|
116 |
return self.lib.dev.dout(data)
|
| - |
|
117 |
|
| 91 |
def getversioninfo(self):
|
118 |
def getversioninfo(self):
|
| 92 |
""" This returns the emBIOS version and device information. """
|
119 |
""" This returns the emBIOS version and device information. """
|
| 93 |
return self.lib.monitorcommand(struct.pack("IIII", 1, 0, 0, 0), "IBBBBI", ("revision", "majorv", "minorv", "patchv", "swtypeid", "hwtypeid"))
|
120 |
return self.lib.monitorcommand(struct.pack("IIII", 1, 0, 0, 0), "IBBBBI", ("revision", "majorv", "minorv", "patchv", "swtypeid", "hwtypeid"))
|
| 94 |
|
121 |
|
| 95 |
def getpacketsizeinfo(self):
|
122 |
def getpacketsizeinfo(self):
|
| Line 129... |
Line 156... |
| 129 |
cin_maxsize = self.lib.dev.packetsizelimit["cin"] - self.lib.headersize
|
156 |
cin_maxsize = self.lib.dev.packetsizelimit["cin"] - self.lib.headersize
|
| 130 |
din_maxsize = self.lib.dev.packetsizelimit["din"]
|
157 |
din_maxsize = self.lib.dev.packetsizelimit["din"]
|
| 131 |
data = ""
|
158 |
data = ""
|
| 132 |
(headsize, bodysize, tailsize) = self._alignsplit(addr, size, cin_maxsize, 16)
|
159 |
(headsize, bodysize, tailsize) = self._alignsplit(addr, size, cin_maxsize, 16)
|
| 133 |
if headsize != 0:
|
160 |
if headsize != 0:
|
| 134 |
data += self.readmem(addr, headsize)
|
161 |
data += self._readmem(addr, headsize)
|
| 135 |
addr += headsize
|
162 |
addr += headsize
|
| 136 |
while bodysize > 0:
|
163 |
while bodysize > 0:
|
| 137 |
if bodysize >= 2 * cin_maxsize:
|
164 |
if bodysize >= 2 * cin_maxsize:
|
| 138 |
readsize = min(bodysize, din_maxsize)
|
165 |
readsize = min(bodysize, din_maxsize)
|
| 139 |
data += self.readdma(addr, readsize)
|
166 |
data += self._readdma(addr, readsize)
|
| 140 |
else:
|
167 |
else:
|
| 141 |
readsize = min(bodysize, cin_maxsize)
|
168 |
readsize = min(bodysize, cin_maxsize)
|
| 142 |
data += self.readmem(addr, readsize)
|
169 |
data += self._readmem(addr, readsize)
|
| 143 |
addr += readsize
|
170 |
addr += readsize
|
| 144 |
bodysize -= readsize
|
171 |
bodysize -= readsize
|
| 145 |
if tailsize != 0:
|
172 |
if tailsize != 0:
|
| 146 |
data += self.readmem(addr, tailsize)
|
173 |
data += self._readmem(addr, tailsize)
|
| 147 |
return data
|
174 |
return data
|
| 148 |
|
175 |
|
| 149 |
def write(self, addr, data):
|
176 |
def write(self, addr, data):
|
| 150 |
""" Writes the data in 'data' to the location 'addr'
|
177 |
""" Writes the data in 'data' to the location 'addr'
|
| 151 |
in the memory of the device. This cares about too long packages
|
178 |
in the memory of the device. This cares about too long packages
|
| Line 154... |
Line 181... |
| 154 |
cout_maxsize = self.lib.dev.packetsizelimit["cout"] - self.lib.headersize
|
181 |
cout_maxsize = self.lib.dev.packetsizelimit["cout"] - self.lib.headersize
|
| 155 |
dout_maxsize = self.lib.dev.packetsizelimit["dout"]
|
182 |
dout_maxsize = self.lib.dev.packetsizelimit["dout"]
|
| 156 |
(headsize, bodysize, tailsize) = self._alignsplit(addr, len(data), cout_maxsize, 16)
|
183 |
(headsize, bodysize, tailsize) = self._alignsplit(addr, len(data), cout_maxsize, 16)
|
| 157 |
offset = 0
|
184 |
offset = 0
|
| 158 |
if headsize != 0:
|
185 |
if headsize != 0:
|
| 159 |
self.writemem(addr, data[offset:offset+headsize])
|
186 |
self._writemem(addr, data[offset:offset+headsize])
|
| 160 |
offset += headsize
|
187 |
offset += headsize
|
| 161 |
addr += headsize
|
188 |
addr += headsize
|
| 162 |
while bodysize > 0:
|
189 |
while bodysize > 0:
|
| 163 |
if bodysize >= 2 * cout_maxsize:
|
190 |
if bodysize >= 2 * cout_maxsize:
|
| 164 |
writesize = min(bodysize, dout_maxsize)
|
191 |
writesize = min(bodysize, dout_maxsize)
|
| 165 |
self.writedma(addr, data[offset:offset+writesize])
|
192 |
self._writedma(addr, data[offset:offset+writesize])
|
| 166 |
else:
|
193 |
else:
|
| 167 |
writesize = min(bodysize, cout_maxsize)
|
194 |
writesize = min(bodysize, cout_maxsize)
|
| 168 |
self.writemem(addr, data[offset:offset+writesize])
|
195 |
self._writemem(addr, data[offset:offset+writesize])
|
| 169 |
offset += writesize
|
196 |
offset += writesize
|
| 170 |
addr += writesize
|
197 |
addr += writesize
|
| 171 |
bodysize -= writesize
|
198 |
bodysize -= writesize
|
| 172 |
if tailsize != 0:
|
199 |
if tailsize != 0:
|
| 173 |
self.writemem(addr, data[offset:offset+tailsize])
|
200 |
self._writemem(addr, data[offset:offset+tailsize])
|
| 174 |
return data
|
201 |
return data
|
| 175 |
|
202 |
|
| 176 |
def readmem(self, addr, size):
|
- |
|
| 177 |
""" Reads the memory from location 'addr' with size 'size'
|
- |
|
| 178 |
from the device.
|
- |
|
| 179 |
"""
|
- |
|
| 180 |
resp = self.lib.monitorcommand(struct.pack("IIII", 4, addr, size, 0), "III%ds" % size, (None, None, None, "data"))
|
- |
|
| 181 |
return resp.data
|
- |
|
| 182 |
|
- |
|
| 183 |
def writemem(self, addr, data):
|
- |
|
| 184 |
""" Writes the data in 'data' to the location 'addr'
|
- |
|
| 185 |
in the memory of the device.
|
- |
|
| 186 |
"""
|
- |
|
| 187 |
return self.lib.monitorcommand(struct.pack("IIII%ds" % len(data), 5, addr, len(data), 0, data), "III", (None, None, None))
|
- |
|
| 188 |
|
- |
|
| 189 |
def readdma(self, addr, size):
|
- |
|
| 190 |
""" Reads the memory from location 'addr' with size 'size'
|
- |
|
| 191 |
from the device. This uses DMA and the data in endpoint.
|
- |
|
| 192 |
"""
|
- |
|
| 193 |
self.lib.monitorcommand(struct.pack("IIII", 6, addr, size, 0), "III", (None, None, None))
|
- |
|
| 194 |
return struct.unpack("%ds" % size, self.lib.dev.din(size))[0]
|
- |
|
| 195 |
|
- |
|
| 196 |
def writedma(self, addr, data):
|
- |
|
| 197 |
""" Writes the data in 'data' to the location 'addr'
|
- |
|
| 198 |
in the memory of the device. This uses DMA and the data out endpoint.
|
- |
|
| 199 |
"""
|
- |
|
| 200 |
self.lib.monitorcommand(struct.pack("IIII", 7, addr, len(data), 0), "III", (None, None, None))
|
- |
|
| 201 |
return self.lib.dev.dout(data)
|
- |
|
| 202 |
|
- |
|
| 203 |
def readstring(self, addr, maxlength = 256):
|
203 |
def readstring(self, addr, maxlength = 256):
|
| 204 |
""" Reads a zero terminated string from memory
|
204 |
""" Reads a zero terminated string from memory
|
| 205 |
Reads only a maximum of 'maxlength' chars.
|
205 |
Reads only a maximum of 'maxlength' chars.
|
| 206 |
"""
|
206 |
"""
|
| 207 |
cin_maxsize = self.lib.dev.packetsizelimit["cin"] - self.lib.headersize
|
207 |
cin_maxsize = self.lib.dev.packetsizelimit["cin"] - self.lib.headersize
|
| 208 |
string = ""
|
208 |
string = ""
|
| 209 |
while (len(string) < maxlength or maxlength < 0):
|
209 |
while (len(string) < maxlength or maxlength < 0):
|
| 210 |
data = self.readmem(addr, min(maxlength - len(string), cin_maxsize))
|
210 |
data = self._readmem(addr, min(maxlength - len(string), cin_maxsize))
|
| 211 |
length = data.find("\0")
|
211 |
length = data.find("\0")
|
| 212 |
if length >= 0:
|
212 |
if length >= 0:
|
| 213 |
string += data[:length]
|
213 |
string += data[:length]
|
| 214 |
break
|
214 |
break
|
| 215 |
else:
|
215 |
else:
|
| Line 340... |
Line 340... |
| 340 |
info.priority = threaddata[30]
|
340 |
info.priority = threaddata[30]
|
| 341 |
info.cpuload = threaddata[31]
|
341 |
info.cpuload = threaddata[31]
|
| 342 |
threads.append(info)
|
342 |
threads.append(info)
|
| 343 |
id += 1
|
343 |
id += 1
|
| 344 |
return threads
|
344 |
return threads
|
| 345 |
|
- |
|
| 346 |
|
- |
|
| 347 |
return self.lib.monitorcommand(struct.pack("IIII", 15, offset, size, 0), "III%ds" % size, ("structver", "tablesize", None, "data"))
|
- |
|
| 348 |
|
345 |
|
| 349 |
def lockscheduler(self, freeze=True):
|
346 |
def lockscheduler(self, freeze=True):
|
| 350 |
""" Freezes/Unfreezes the scheduler """
|
347 |
""" Freezes/Unfreezes the scheduler """
|
| 351 |
resp = self.lib.monitorcommand(struct.pack("IIII", 16, 1 if freeze else 0, 0, 0), "III", ("before", None, None))
|
348 |
resp = self.lib.monitorcommand(struct.pack("IIII", 16, 1 if freeze else 0, 0, 0), "III", ("before", None, None))
|
| 352 |
return True if resp.before == 1 else False
|
349 |
return True if resp.before == 1 else False
|