| Index: embios/trunk/tools/embios.py | 
| — | — | @@ -46,6 +46,28 @@ | 
| 47 | 47 | print "    If <force> is 1, the poweroff will be forced, otherwise it will be gracefully," | 
| 48 | 48 | print "    which may take some time." | 
| 49 | 49 | print "" | 
|  | 50 | +  print "  i2crecv <bus> <slave> <addr> <size>" | 
|  | 51 | +  print "    Reads data from an I2C device" | 
|  | 52 | +  print "      <bus> the bus index" | 
|  | 53 | +  print "      <slave> the slave address" | 
|  | 54 | +  print "      <addr> the start address on the I2C device" | 
|  | 55 | +  print "      <size> the number of bytes to read" | 
|  | 56 | +  print "" | 
|  | 57 | +  print "  i2csend <bus> <slave> <addr> <db1> <db2> ... <dbN>" | 
|  | 58 | +  print "    Writes data to an I2C device" | 
|  | 59 | +  print "      <bus> the bus index" | 
|  | 60 | +  print "      <slave> the slave address" | 
|  | 61 | +  print "      <addr> the start address on the I2C device" | 
|  | 62 | +  print "      <db1> ... <dbN> the data in single bytes, seperated by whitespaces, eg. 0x37 0x56 0x45 0x12" | 
|  | 63 | +  print "" | 
|  | 64 | +  print "  getprocessinformation <offset> <size> / getprocinfo <offset> <size>" | 
|  | 65 | +  print "    Fetches data on the currently running processes" | 
|  | 66 | +  print "      <offset> the offset in the data field" | 
|  | 67 | +  print "      <size> the number of bytes to be fetched" | 
|  | 68 | +  print "     ATTENTION: this function will be print the information to the console window." | 
|  | 69 | +  print "                If several threads are running this might overflow the window," | 
|  | 70 | +  print "                causing not everything to be shown." | 
|  | 71 | +  print "" | 
| 50 | 72 | print "  lockscheduler" | 
| 51 | 73 | print "    Locks (freezes) the scheduler" | 
| 52 | 74 | print "" | 
| — | — | @@ -93,10 +115,23 @@ | 
| 94 | 116 | if len(argv) != 3: usage() | 
| 95 | 117 | dev.poweroff(int(argv[2])) | 
| 96 | 118 |  | 
| 97 |  | -  elif argv[1] == "flushcaches":
 | 
| 98 |  | -    if len(argv) != 2: usage()
 | 
| 99 |  | -    dev.flushcaches()
 | 
|  | 119 | +  elif argv[1] == "i2cread": | 
|  | 120 | +    if len(argv) != 6: usage() | 
|  | 121 | +    dev.i2crecv(int(argv[2]), int(argv[3]), int(argv[4]), int(argv[5])) | 
| 100 | 122 |  | 
|  | 123 | +  elif argv[1] == "i2csend": | 
|  | 124 | +    if len(argv) < 6: usage() | 
|  | 125 | +    data = "" | 
|  | 126 | +    ptr = 5 | 
|  | 127 | +    while ptr < lean(argv): | 
|  | 128 | +      data += struct.pack("<B", int(argv[ptr])) | 
|  | 129 | +      ptr += 1 | 
|  | 130 | +    dev.i2csend(int(argv[2]), int(argv[3]), int(argv[4]), data) | 
|  | 131 | + | 
|  | 132 | +  elif argv[1] == "getprocessinformation" or argv[1] == "getprocinfo": | 
|  | 133 | +    if len(argv) != 4: usage() | 
|  | 134 | +    dev.getprocinfo(int(argv[2]), int(argv[3])) | 
|  | 135 | + | 
| 101 | 136 | elif argv[1] == "lockscheduler": | 
| 102 | 137 | if len(argv) != 2: usage() | 
| 103 | 138 | dev.freezescheduler(1) | 
| — | — | @@ -121,6 +156,10 @@ | 
| 122 | 157 | if len(argv) != 9: usage() | 
| 123 | 158 | dev.createthread(int(argv[2]), int(argv[3]), int(argv[4]), int(argv[5]), int(argv[6]), int(argv[7]), int(argv[8])) | 
| 124 | 159 |  | 
|  | 160 | +  elif argv[1] == "flushcaches": | 
|  | 161 | +    if len(argv) != 2: usage() | 
|  | 162 | +    dev.flushcaches() | 
|  | 163 | + | 
| 125 | 164 | else: usage() | 
| 126 | 165 |  | 
| 127 | 166 |  | 
| Index: embios/trunk/tools/libembios.py | 
| — | — | @@ -434,25 +434,27 @@ | 
| 435 | 435 |  | 
| 436 | 436 | self.handle.bulkWrite(self.__coutep, struct.pack("<IBBBBII", 8, bus, slave, addr, size, 0, 0)) | 
| 437 | 437 | data = self.__getbulk(self.handle, self.__cinep, 0x10 + size) | 
| 438 |  | -    self.__checkstatus(data)
 | 
|  | 438 | +    self.__checkstatus(response) | 
| 439 | 439 |  | 
| 440 |  | -    self.__myprint(" done\n", silent)
 | 
|  | 440 | +    self.__myprint(" done\n data was:\n%s\n" % (self.__gethexviewprintout(data[16:])), silent) | 
| 441 | 441 |  | 
| 442 | 442 | return data[16:] | 
| 443 | 443 |  | 
| 444 | 444 |  | 
| 445 | 445 | def i2csend(self, bus, slave, addr, data, silent = 0): | 
|  | 446 | +    size = len(data) | 
| 446 | 447 | if (size > self.cout_maxsize - 0x10) or (size > 0xFF): | 
| 447 | 448 | raise Exception ("The data exceeds the maximum amount that can be send with this instruction.") | 
| 448 | 449 |  | 
| 449 | 450 | self.__myprint("Writing 0x%2x bytes to 0x%2x at I2C device at bus 0x%2x, slave adress 0x%2x ..." % (size, addr, bus, slave), silent) | 
| 450 | 451 |  | 
| 451 |  | -    self.handle.bulkWrite(self.__coutep, struct.pack("<IBBBBII", 9, bus, slave, addr, len(data), 0, 0) + data)
 | 
| 452 |  | -    self.__checkstatus(self.__readstatus())
 | 
|  | 452 | +    self.handle.bulkWrite(self.__coutep, struct.pack("<IBBBBII", 9, bus, slave, addr, size, 0, 0) + data) | 
|  | 453 | +    response = self.__getbulk(self.handle, self.__cinep, 0x10) | 
|  | 454 | +    self.__checkstatus(response) | 
| 453 | 455 |  | 
| 454 | 456 | self.__myprint(" done\n", silent) | 
| 455 |  | -
 | 
| 456 | 457 |  | 
|  | 458 | + | 
| 457 | 459 | #===================================================================================== | 
| 458 | 460 |  | 
| 459 | 461 | def readusbcon(self, size, outtype = "", file = "", silent = 0): | 
| — | — | @@ -500,10 +502,12 @@ | 
| 501 | 503 | struct.unpack("<IIII", response[:0x10])[2], | 
| 502 | 504 | struct.unpack("<IIII", response[:0x10])[3]) | 
| 503 | 505 | , silent) | 
| 504 |  | -      self.__myprint(self.gethexviewprintout(response[0x10:], "", 1), silent)
 | 
|  | 506 | +      self.__myprint(self.__gethexviewprintout(response[0x10:], "", 1), silent) | 
| 505 | 507 | self.__myprint("\n\n", silent) | 
| 506 |  | -      
 | 
| 507 |  | -    elif (outtype != ""):   # none of the above and also not "" which would be return only
 | 
|  | 508 | + | 
|  | 509 | +    elif (outtype == ""): | 
|  | 510 | +      pass    # return only | 
|  | 511 | +    else: | 
| 508 | 512 | raise Exception ("Invalid argument for <outtype>: '%s'." % (outtype)) | 
| 509 | 513 |  | 
| 510 | 514 | self.__myprint(" done\n", silent) | 
| — | — | @@ -638,11 +642,12 @@ | 
| 639 | 643 |  | 
| 640 | 644 | out = [] | 
| 641 | 645 | out[0] = struct.unpack("<I", response[4:8])[0]    # Process information struct version | 
| 642 |  | -    out[1] = struct.unpack("<I", response[4:8])[0]    # Process information table size
 | 
|  | 646 | +    out[1] = struct.unpack("<I", response[8:12])[0]    # Process information table size | 
|  | 647 | +    out[2] = response     # raw received data | 
| 643 | 648 |  | 
| 644 | 649 | if (struct.unpack("<I", response[4:8])[0] == 1):   # Process information struct version == 1 | 
| 645 | 650 | p = 0x10 | 
| 646 |  | -      process_n = 2   # actually process 0, but there are alread two other elements in out
 | 
|  | 651 | +      process_n = 3   # actually process 0, but there are alread three other elements in out | 
| 647 | 652 | while True: | 
| 648 | 653 | # regs ================================================== | 
| 649 | 654 | keylen = 16 | 
| — | — | @@ -829,14 +834,47 @@ | 
| 830 | 835 |  | 
| 831 | 836 | process_n += 1 | 
| 832 | 837 |  | 
|  | 838 | +    procinfoprint = "" | 
| 833 | 839 |  | 
|  | 840 | +    try: | 
|  | 841 | +      i = 0 | 
|  | 842 | +      while (out[0] == 1) and (!silent):      # Process information struct version == 1 && !silent | 
|  | 843 | +        processinfoprint += "--------------------------------------------------------------------------------" | 
|  | 844 | +        processinfoprint += "R0: 0x%08x,  R1: 0x%08x,  R2: 0x%08x,  R3: 0x%08x,\n\ | 
|  | 845 | +                             R4: 0x%08x,  R5: 0x%08x,  R6: 0x%08x,  R7: 0x%08x,\n\ | 
|  | 846 | +                             R8: 0x%08x,  R9: 0x%08x,  R10: 0x%08x, R11: 0x%08x,\n\ | 
|  | 847 | +                             R12: 0x%08x, R13: 0x%08x, LR: 0x%08x,  PC: 0x%08x\n" \ | 
|  | 848 | +                             % (out[i+3]['regs'][0], out[i+3]['regs'][1], out[i+3]['regs'][2], out[i+3]['regs'][3], \ | 
|  | 849 | +                                out[i+3]['regs'][4], out[i+3]['regs'][5], out[i+3]['regs'][6], out[i+3]['regs'][7], \ | 
|  | 850 | +                                out[i+3]['regs'][8], out[i+3]['regs'][9], out[i+3]['regs'][10], out[i+3]['regs'][11], \ | 
|  | 851 | +                                out[i+3]['regs'][12], out[i+3]['regs'][13], out[i+3]['regs'][14], out[i+3]['regs'][15] ) | 
|  | 852 | +        processinfoprint += "cpsr: 0b%032b      " % (out[i+3]['cpsr']) | 
|  | 853 | +        states = ["THREAD_FREE", "THREAD_SUSPENDED", "THREAD_READY", "THREAD_RUNNING", "THREAD_BLOCKED", "THREAD_DEFUNCT", "THREAD_DEFUNCT_ACK"] | 
|  | 854 | +        processinfoprint += "state: %s      " % (states[out[i+3]['state']]) | 
|  | 855 | +        processinfoprint += "nameptr: 0x%08x\n" % (out[i+3]['namepointer']) | 
|  | 856 | +        processinfoprint += "current cpu time: 0x%08x      " % (out[i+3]['cputime_current']) | 
|  | 857 | +        processinfoprint += "total cpu time: 0x%016x\n" % (out[i+3]['cputime_total']) | 
|  | 858 | +        processinfoprint += "startusec: 0x%08x      " % (out[i+3]['startusec']) | 
|  | 859 | +        processinfoprint += "queue next ptr: 0x%08x\n" % (out[i+3]['queue_next_pointer']) | 
|  | 860 | +        processinfoprint += "timeout: 0x%08x\n" % (out[i+3]['timeout']) | 
|  | 861 | +        processinfoprint += "blocked since: 0x%08x      " % (out[i+3]['blocked_since']) | 
|  | 862 | +        processinfoprint += "blocked by ptr: 0x%08x\n" % (out[i+3]['blocked_by_pointer']) | 
|  | 863 | +        processinfoprint += "stackptr: 0x%08x      " % (out[i+3]['stackpointer']) | 
|  | 864 | +        blocktype = ["THREAD_NOT_BLOCKED", "THREAD_BLOCK_SLEEP", "THREAD_BLOCK_MUTEX", "THREAD_BLOCK_WAKEUP", "THREAD_DEFUNCT_STKOV", "THREAD_DEFUNCT_PANIC"] | 
|  | 865 | +        processinfoprint += "block type: %s\n" % (blocktype[out[i+3]['block_type']]) | 
|  | 866 | +        threadtype = ["USER_THREAD", "SYSTEM_THREAD"] | 
|  | 867 | +        processinfoprint += "thread type: %s\n" % (threadtype[out[i+3]['thread_type']]) | 
|  | 868 | +        processinfoprint += "priority: 0x%02x      " % (out[i+3]['priority']) | 
|  | 869 | +        processinfoprint += "cpu load: 0x%02x\n" % (out[i+3]['cpuload']) | 
|  | 870 | + | 
|  | 871 | +    except IndexError: | 
|  | 872 | +      processinfoprint += "--------------------------------------------------------------------------------" | 
| 834 | 873 |  | 
| 835 |  | -    
 | 
| 836 | 874 | self.__myprint(" done\n\ | 
| 837 | 875 | Process information struct version: 0x%8x\n\ | 
| 838 | 876 | Total size of process information table: 0x%8x\n\ | 
| 839 | 877 | %s" | 
| 840 |  | -                  % (struct.unpack("<I", response[4:8]), struct.unpack("<I", response[8:12]), hexprint)
 | 
|  | 878 | +                  % (out[0], out[1], procinfoprint) | 
| 841 | 879 | , silent) | 
| 842 | 880 |  | 
| 843 | 881 | return out |