def ReadHexFile(self): print "Reading HexFile" extAddr = 0 lines = self.file.readlines() for line in lines: (byteCount, addr, recordType) = sscanf(line[1:], "%2x%4x%2x") if (recordType == 0): addr = (addr + extAddr) / 2 for count in range(0, byteCount*2, 4): if addr < 0xF80000: bInserted = self.memory[addr/(FlashMem.PM_ROW_SIZE*2)].InsertData(addr,line[9+count:13+count]) else: print "Configuration Codes - Address: 0x%x, Data: %s" %(addr, line[9+count:13+count]) if bInserted is True: #print "Hex File: 0x%x Address: %s" %(addr, line[9+count:13+count]) addr = addr + 1 else: print "Bad HexFile: 0x%x Address out of range: %s" %(addr, line[9+count:13+count]) elif (recordType == 1): "It means EOF, just do nothing" elif (recordType == 4): extAddr = sscanf(line[9:], "%4x") extAddr = extAddr[0] << 16 else: print "Unknown hex record type" return
def InsertData(self, address, data): # debug("... 0x%06x, 0x%06x" %(address, self.address) ) if (address < self.address) or (address >= (self.address + self.PM_ROW_SIZE*2)): return False if self.empty is True: if self.type is self.PROGRAM: self.buffer = array.array('c', chr(0xff)*self.PM_ROW_SIZE*3) else: self.buffer = array.array('c', chr(0xff)*3) self.empty = False addr = address - self.address # debug( "address received: 0x%06x, self.address: 0x%06x" %(address, self.address)) # debug("At 0x%06x, %s is inserted" %(address, data) ) (value,) = sscanf(data, "%4x") if addr%2 is 0: self.buffer[(addr>>1)*3 + 0] = chr((value >> 8) & 0x00FF) self.buffer[(addr>>1)*3 + 1] = chr(value & 0x00FF) else: self.buffer[(addr>>1)*3 + 2] = chr((value >> 8) & 0x00FF) # print "Data at Address: 0x%x Data: 0x%02x%02x%02x" %(addr-1, # ord(self.buffer[(addr>>1)*3+2]), # ord(self.buffer[(addr>>1)*3+1]), ord(self.buffer[(addr>>1)*3])) return True
def InsertData(self, address, data): # debug("... 0x%06x, 0x%06x" %(address, self.address) ) if (address < self.address) or (address >= (self.address + self.PM_ROW_SIZE * 2)): return False if self.empty is True: if self.type is self.PROGRAM: self.buffer = array.array('c', chr(0xff) * self.PM_ROW_SIZE * 3) else: self.buffer = array.array('c', chr(0xff) * 3) self.empty = False addr = address - self.address # debug( "address received: 0x%06x, self.address: 0x%06x" %(address, self.address)) # debug("At 0x%06x, %s is inserted" %(address, data) ) (value, ) = sscanf(data, "%4x") if addr % 2 is 0: self.buffer[(addr >> 1) * 3 + 0] = chr((value >> 8) & 0x00FF) self.buffer[(addr >> 1) * 3 + 1] = chr(value & 0x00FF) else: self.buffer[(addr >> 1) * 3 + 2] = chr((value >> 8) & 0x00FF) # print "Data at Address: 0x%x Data: 0x%02x%02x%02x" %(addr-1, # ord(self.buffer[(addr>>1)*3+2]), # ord(self.buffer[(addr>>1)*3+1]), ord(self.buffer[(addr>>1)*3])) return True
def ReadHexFile(self): print "Reading HexFile" extAddr = 0 lines = self.file.readlines() for line in lines: (byteCount, addr, recordType) = sscanf(line[1:], "%2x%4x%2x") if (recordType == 0): addr = (addr + extAddr) / 2 for count in range(0, byteCount * 2, 4): if addr < 0xF80000: bInserted = self.memory[addr / (FlashMem.PM_ROW_SIZE * 2)].InsertData( addr, line[9 + count:13 + count]) else: print "Configuration Codes - Address: 0x%x, Data: %s" % ( addr, line[9 + count:13 + count]) if bInserted is True: #print "Hex File: 0x%x Address: %s" %(addr, line[9+count:13+count]) addr = addr + 1 else: print "Bad HexFile: 0x%x Address out of range: %s" % ( addr, line[9 + count:13 + count]) elif (recordType == 1): "It means EOF, just do nothing" elif (recordType == 4): extAddr = sscanf(line[9:], "%4x") extAddr = extAddr[0] << 16 else: print "Unknown hex record type" return