| Line 227... |
Line 227... |
| 227 |
|
227 |
|
| 228 |
def i2cwrite(self, index, slaveaddr, startaddr, data):
|
228 |
def i2cwrite(self, index, slaveaddr, startaddr, data):
|
| 229 |
""" Writes data to an i2c slave """
|
229 |
""" Writes data to an i2c slave """
|
| 230 |
size = len(data)
|
230 |
size = len(data)
|
| 231 |
if size > 256 or size < 1:
|
231 |
if size > 256 or size < 1:
|
| 232 |
raise ValueError("Size must be a number between 1 and 256")
|
232 |
raise ArgumentError("Size must be a number between 1 and 256")
|
| 233 |
if size == 256:
|
233 |
if size == 256:
|
| 234 |
size = 0
|
234 |
size = 0
|
| 235 |
return self.lib.monitorcommand(struct.pack("IBBBBII%ds" % size, 9, index, slaveaddr, startaddr, size, 0, 0, data), "III", (None, None, None))
|
235 |
return self.lib.monitorcommand(struct.pack("IBBBBII%ds" % size, 9, index, slaveaddr, startaddr, size, 0, 0, data), "III", (None, None, None))
|
| 236 |
|
236 |
|
| 237 |
def usbcread(self):
|
237 |
def usbcread(self):
|
| Line 369... |
Line 369... |
| 369 |
if threadtype == "user":
|
369 |
if threadtype == "user":
|
| 370 |
threadtype = 0
|
370 |
threadtype = 0
|
| 371 |
elif threadtype == "system":
|
371 |
elif threadtype == "system":
|
| 372 |
threadtype = 1
|
372 |
threadtype = 1
|
| 373 |
else:
|
373 |
else:
|
| 374 |
raise ValueError("Threadtype must be either 'system' or 'user'")
|
374 |
raise ArgumentError("Threadtype must be either 'system' or 'user'")
|
| 375 |
if priority > 256 or priority < 0:
|
375 |
if priority > 256 or priority < 0:
|
| 376 |
raise ValueError("Priority must be a number between 0 and 256")
|
376 |
raise ArgumentError("Priority must be a number between 0 and 256")
|
| 377 |
if state == "ready":
|
377 |
if state == "ready":
|
| 378 |
state = 0
|
378 |
state = 0
|
| 379 |
elif state == "suspended":
|
379 |
elif state == "suspended":
|
| 380 |
state = 1
|
380 |
state = 1
|
| 381 |
else:
|
381 |
else:
|
| 382 |
raise ValueError("State must be either 'ready' or 'suspended'")
|
382 |
raise ArgumentError("State must be either 'ready' or 'suspended'")
|
| 383 |
resp = self.lib.monitorcommand(struct.pack("IIIIIIII", 19, nameptr, entrypoint, stackptr, stacksize, threadtype, priority, state), "III", (id, None, None))
|
383 |
resp = self.lib.monitorcommand(struct.pack("IIIIIIII", 19, nameptr, entrypoint, stackptr, stacksize, threadtype, priority, state), "III", (id, None, None))
|
| 384 |
if resp.id < 0:
|
384 |
if resp.id < 0:
|
| 385 |
raise DeviceError("The device returned the error code "+str(resp.id))
|
385 |
raise DeviceError("The device returned the error code "+str(resp.id))
|
| 386 |
return resp
|
386 |
return resp
|
| 387 |
|
387 |
|
| Line 396... |
Line 396... |
| 396 |
def run(self, app):
|
396 |
def run(self, app):
|
| 397 |
""" Uploads and runs the emBIOS app in the string 'app' """
|
397 |
""" Uploads and runs the emBIOS app in the string 'app' """
|
| 398 |
try:
|
398 |
try:
|
| 399 |
appheader = struct.unpack("<8sIIIIIIIIII", app[:48])
|
399 |
appheader = struct.unpack("<8sIIIIIIIIII", app[:48])
|
| 400 |
except struct.error:
|
400 |
except struct.error:
|
| 401 |
raise ArgumentError("The specified file is not an emBIOS application")
|
401 |
raise ArgumentError("The specified app is not an emBIOS application")
|
| 402 |
header = appheader[0]
|
402 |
header = appheader[0]
|
| 403 |
if header != "emBIexec":
|
403 |
if header != "emBIexec":
|
| 404 |
raise ArgumentError("The specified file is not an emBIOS application")
|
404 |
raise ArgumentError("The specified app is not an emBIOS application")
|
| 405 |
baseaddr = appheader[2]
|
405 |
baseaddr = appheader[2]
|
| 406 |
threadnameptr = appheader[8]
|
406 |
threadnameptr = appheader[8]
|
| 407 |
nameptr = threadnameptr - baseaddr
|
407 |
nameptr = threadnameptr - baseaddr
|
| 408 |
name = ""
|
408 |
name = ""
|
| 409 |
while True:
|
409 |
while True:
|
| 410 |
char = app[nameptr:nameptr+1]
|
410 |
char = app[nameptr:nameptr+1]
|
| 411 |
try:
|
411 |
try:
|
| 412 |
if ord(char) == 0:
|
412 |
if ord(char) == 0:
|
| 413 |
break
|
413 |
break
|
| 414 |
except TypeError:
|
414 |
except TypeError:
|
| 415 |
raise ArgumentError("The specified file is not an emBIOS application")
|
415 |
raise ArgumentError("The specified app is not an emBIOS application")
|
| 416 |
name += char
|
416 |
name += char
|
| 417 |
nameptr += 1
|
417 |
nameptr += 1
|
| 418 |
usermem = self.getusermemrange()
|
418 |
usermem = self.getusermemrange()
|
| 419 |
if usermem.lower > baseaddr or usermem.upper < baseaddr + len(app):
|
419 |
if usermem.lower > baseaddr or usermem.upper < baseaddr + len(app):
|
| 420 |
raise ArgumentError("The baseaddress of the specified emBIOS application is out of range of the user memory range on the device. Are you sure that this application is compatible with your device?")
|
420 |
raise ArgumentError("The baseaddress of the specified emBIOS application is out of range of the user memory range on the device. Are you sure that this application is compatible with your device?")
|