| Line 197... |
Line 197... |
| 197 |
in the memory of the device. This uses DMA and the data out endpoint.
|
197 |
in the memory of the device. This uses DMA and the data out endpoint.
|
| 198 |
"""
|
198 |
"""
|
| 199 |
self.lib.monitorcommand(struct.pack("IIII", 7, addr, len(data), 0), "III", (None, None, None))
|
199 |
self.lib.monitorcommand(struct.pack("IIII", 7, addr, len(data), 0), "III", (None, None, None))
|
| 200 |
return self.lib.dev.dout(data)
|
200 |
return self.lib.dev.dout(data)
|
| 201 |
|
201 |
|
| - |
|
202 |
def readstring(self, addr, maxlength = 256):
|
| - |
|
203 |
""" Reads a zero terminated string from memory
|
| - |
|
204 |
Reads only a maximum of 'maxlength' chars.
|
| - |
|
205 |
"""
|
| - |
|
206 |
cin_maxsize = self.lib.dev.packetsizelimit["cin"] - 0x10
|
| - |
|
207 |
string = ""
|
| - |
|
208 |
while (len(string) < maxlength or maxlength < 0):
|
| - |
|
209 |
data = self.readmem(addr, min(maxlength - len(string), cin_maxsize))
|
| - |
|
210 |
length = data.find("\0")
|
| - |
|
211 |
if length >= 0:
|
| - |
|
212 |
string += data[:length]
|
| - |
|
213 |
break
|
| - |
|
214 |
else:
|
| - |
|
215 |
string += data
|
| - |
|
216 |
addr += cin_maxsize
|
| - |
|
217 |
return string
|
| - |
|
218 |
|
| 202 |
def i2cread(self, index, slaveaddr, startaddr, size):
|
219 |
def i2cread(self, index, slaveaddr, startaddr, size):
|
| 203 |
""" Reads data from an i2c slave """
|
220 |
""" Reads data from an i2c slave """
|
| 204 |
|
221 |
|
| 205 |
def i2cwrite(self, index, slaveaddr, startaddr, data):
|
222 |
def i2cwrite(self, index, slaveaddr, startaddr, data):
|
| 206 |
""" Writes data to an i2c slave """
|
223 |
""" Writes data to an i2c slave """
|
| Line 223... |
Line 240... |
| 223 |
|
240 |
|
| 224 |
def cflush(self, bitmask):
|
241 |
def cflush(self, bitmask):
|
| 225 |
""" Flushes the consoles specified with 'bitmask' """
|
242 |
""" Flushes the consoles specified with 'bitmask' """
|
| 226 |
return self.lib.monitorcommand(struct.pack("IIII", 14, bitmask, 0, 0), "III", (None, None, None))
|
243 |
return self.lib.monitorcommand(struct.pack("IIII", 14, bitmask, 0, 0), "III", (None, None, None))
|
| 227 |
|
244 |
|
| 228 |
def getprocinfo(self, offset, size):
|
245 |
def getprocinfo(self):
|
| 229 |
""" Gets current state of the scheduler """
|
246 |
""" Gets current state of the scheduler """
|
| - |
|
247 |
cin_maxsize = self.lib.dev.packetsizelimit["cin"] - 0x10
|
| - |
|
248 |
# Get the size
|
| - |
|
249 |
schedulerstate = self.lockscheduler()
|
| - |
|
250 |
resp = self.lib.monitorcommand(struct.pack("IIII", 15, 0, 0, 0), "III", ("structver", "tablesize", None))
|
| - |
|
251 |
tablesize = resp.tablesize
|
| - |
|
252 |
size = tablesize
|
| - |
|
253 |
structver = resp.structver
|
| - |
|
254 |
offset = 0
|
| - |
|
255 |
data = ""
|
| - |
|
256 |
while size > 0:
|
| - |
|
257 |
if size > cin_maxsize:
|
| - |
|
258 |
readsize = cin_maxsize
|
| - |
|
259 |
else:
|
| - |
|
260 |
readsize = size
|
| - |
|
261 |
resp = self.lib.monitorcommand(struct.pack("IIII", 15, offset, readsize, 0), "III%ds" % readsize, ("structver", "tablesize", None, "data"))
|
| - |
|
262 |
data += resp.data
|
| - |
|
263 |
offset += readsize
|
| - |
|
264 |
size -= readsize
|
| - |
|
265 |
self.lockscheduler(schedulerstate)
|
| - |
|
266 |
threadstructsize = 120
|
| - |
|
267 |
registersize = 32
|
| - |
|
268 |
if len(data) % threadstructsize != 0:
|
| - |
|
269 |
raise DeviceError("The thread struct is not a multiple of "+str(threadsturcsize)+"!")
|
| - |
|
270 |
threadcount = len(data) / threadstructsize
|
| - |
|
271 |
threads = []
|
| - |
|
272 |
id = 0
|
| - |
|
273 |
for thread in range(threadcount):
|
| - |
|
274 |
offset = threadstructsize * thread
|
| - |
|
275 |
threaddata = struct.unpack("<16IIIIIQIIIIIIIBBBB", data[offset:offset+threadstructsize])
|
| - |
|
276 |
info = Bunch()
|
| - |
|
277 |
info.id = id
|
| - |
|
278 |
state = threaddata[17]
|
| - |
|
279 |
info.state = libembiosdata.thread_state[state]
|
| - |
|
280 |
if info.state == "THREAD_FREE":
|
| - |
|
281 |
id += 1
|
| - |
|
282 |
continue
|
| - |
|
283 |
info.regs = Bunch()
|
| - |
|
284 |
for register in range(16):
|
| - |
|
285 |
info.regs["r"+str(register)] = threaddata[register]
|
| - |
|
286 |
info.regs.cpsr = threaddata[16]
|
| - |
|
287 |
info.nameptr = threaddata[18]
|
| - |
|
288 |
if info.nameptr == 0:
|
| - |
|
289 |
info.name = "Thread %d" % info.id
|
| - |
|
290 |
else:
|
| - |
|
291 |
info.name = self.readstring(info.nameptr)
|
| - |
|
292 |
info.cputime_current = threaddata[19]
|
| - |
|
293 |
info.cputime_total = threaddata[20]
|
| - |
|
294 |
info.startusec = threaddata[21]
|
| - |
|
295 |
info.queue_next_ptr = threaddata[22]
|
| - |
|
296 |
info.timeout = threaddata[23]
|
| - |
|
297 |
info.blocked_since = threaddata[24]
|
| - |
|
298 |
info.blocked_by_ptr = threaddata[25]
|
| - |
|
299 |
info.stackaddr = threaddata[26]
|
| - |
|
300 |
info.err_no = threaddata[27]
|
| - |
|
301 |
info.block_type = libembiosdata.thread_block[threaddata[28]]
|
| - |
|
302 |
info.type = libembiosdata.thread_type[threaddata[29]]
|
| - |
|
303 |
info.priority = threaddata[30]
|
| - |
|
304 |
info.cpuload = threaddata[31]
|
| - |
|
305 |
threads.append(info)
|
| - |
|
306 |
id += 1
|
| - |
|
307 |
return threads
|
| - |
|
308 |
|
| - |
|
309 |
|
| - |
|
310 |
return self.lib.monitorcommand(struct.pack("IIII", 15, offset, size, 0), "III%ds" % size, ("structver", "tablesize", None, "data"))
|
| 230 |
|
311 |
|
| 231 |
def freezescheduler(self, freeze=True):
|
312 |
def lockscheduler(self, freeze=True):
|
| 232 |
""" Freezes/Unfreezes the scheduler """
|
313 |
""" Freezes/Unfreezes the scheduler """
|
| 233 |
return self.lib.monitorcommand(struct.pack("IIII", 16, 1 if freeze else 0, 0, 0), "III", ("before", None, None))
|
314 |
resp = self.lib.monitorcommand(struct.pack("IIII", 16, 1 if freeze else 0, 0, 0), "III", ("before", None, None))
|
| - |
|
315 |
return True if resp.before == 1 else False
|
| 234 |
|
316 |
|
| 235 |
def unfreezescheduler(self):
|
317 |
def unlockscheduler(self):
|
| 236 |
""" Unfreezes the scheduler """
|
318 |
""" Unfreezes the scheduler """
|
| 237 |
return self.lib.monitorcommand(struct.pack("IIII", 16, 0, 0, 0), "III", ("before", None, None))
|
319 |
return self.lib.monitorcommand(struct.pack("IIII", 16, 0, 0, 0), "III", ("before", None, None))
|
| 238 |
|
320 |
|
| 239 |
def suspendthread(self, id, suspend=True):
|
321 |
def suspendthread(self, id, suspend=True):
|
| 240 |
""" Suspends the thread with the specified id """
|
322 |
""" Suspends the thread with the specified id """
|
| 241 |
return self.lib.monitorcommand(struct.pack("IIII", 17, 1 if suspend else 0, id, 0), "III", ("before", None, None))
|
323 |
resp = self.lib.monitorcommand(struct.pack("IIII", 17, 1 if suspend else 0, id, 0), "III", ("before", None, None))
|
| - |
|
324 |
return True if resp.before == 1 else False
|
| 242 |
|
325 |
|
| 243 |
def unsuspendthread(self, id):
|
326 |
def resumethread(self, id):
|
| 244 |
""" Suspends the thread with the specified id """
|
327 |
""" Resumes the thread with the specified id """
|
| 245 |
return self.lib.monitorcommand(struct.pack("IIII", 17, 0, id, 0), "III", ("before", None, None))
|
328 |
return self.lib.monitorcommand(struct.pack("IIII", 17, 0, id, 0), "III", ("before", None, None))
|
| 246 |
|
329 |
|
| 247 |
def killthread(self, id):
|
330 |
def killthread(self, id):
|
| 248 |
""" Kills the thread with the specified id """
|
331 |
""" Kills the thread with the specified id """
|
| 249 |
return self.lib.monitorcommand(struct.pack("IIII", 18, id, 0, 0), "III", ("before", None, None))
|
332 |
return self.lib.monitorcommand(struct.pack("IIII", 18, id, 0, 0), "III", ("before", None, None))
|