From ee5a468417fb6810a5bbe4d46617618a9ddb588a Mon Sep 17 00:00:00 2001 From: NĂ©lio Laranjeiro Date: Thu, 7 May 2009 10:07:49 +0200 Subject: * digital/avr/modules/trace: (See #67) * Adapted the trace module to: * Find the last trace in order to start the new one, trace_i = trace_i-1 + 1 * A quarter of the flash is completely erased on the trace init to be used in the future. * Removed the start code useless from now. * tools/trace: * Update the python scripts to use the new trace implementation. --- tools/trace/tinter/thost.py | 77 ++++++++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 35 deletions(-) (limited to 'tools/trace/tinter/thost.py') diff --git a/tools/trace/tinter/thost.py b/tools/trace/tinter/thost.py index bbbdf0d0..885fbbb3 100644 --- a/tools/trace/tinter/thost.py +++ b/tools/trace/tinter/thost.py @@ -1,9 +1,11 @@ import serial import time +import sys from proto import * from utils import * FLASH_MEMORY_HIGH = 0x1fffff +FLASH_PAGE = 0x80000 FLASH_BUFFER_SIZE = 128 FLASH_CMD_INIT = 0 FLASH_CMD_READ = 1 @@ -19,54 +21,59 @@ class THost: def __init__(self): self.__proto = Proto (serial.Serial ('/dev/ttyACM0'), time.time, 0.1) self.__memory = list() - self.__status = False - self.__addr_init = 0 - self.__addr_end = 0 + self.__traces = [] def __dump_callback (self, *memory): """Callback call on each data reception""" for i in range(len (memory)): self.__memory.append (memory[i]) + sys.stderr.write (".") - def __flash_status (self, status): - """Get the flash status.""" - print "Flash activate : ", status - self.__status = status + def __trace_present (self, val): + """Get the trace value and the first byte following.""" + self.__traces.append (val) - def __flash_log_init (self, *addr): - """Get the flash log start address.""" - # Don't request the code start - addr = reverse_tupple (addr) - self.__addr_init = get_size (addr, 3) + def trace_list (self): + """Read the flash memory and return the addresses of the traces + present with the trace value in a array.""" + self.__proto.register ('r', 'B', self.__trace_present) + self.__proto.send ('l', 'b', FLASH_CMD_INIT) + self.__proto.send ('l', 4*'b', FLASH_CMD_READ, 0x0, 0x0, 0x0) + self.__proto.send ('l', 4*'b', FLASH_CMD_READ, 0x8, 0x0, 0x0) + self.__proto.send ('l', 4*'b', FLASH_CMD_READ, 0x10, 0x0, 0x0) + self.__proto.send ('l', 4*'b', FLASH_CMD_READ, 0x18, 0x0, 0x0) + self.__proto.wait (lambda: True) - def __flash_log_end (self, *addr): - """Get the flash log end address.""" - addr = reverse_tupple (addr) - self.__addr_end = get_size (addr, 3) + return self.__traces - def dump_memory(self): + def dump_memory(self, val): """Dump the flash memory.""" # Initialise the flash access. - self.__proto.register ('r', FLASH_BUFFER_SIZE * 'B', self.__dump_callback) - self.__proto.register ('s', 'b', self.__flash_status) - self.__proto.register ('i', 3*'B', self.__flash_log_init) - self.__proto.register ('e', 3*'B', self.__flash_log_end) - print "Callback registered" - print "Initialise the Flash memory" - self.__proto.send ('l', 'b', FLASH_CMD_INIT) - self.__proto.wait (lambda: True) + self.__proto.register ('r', FLASH_BUFFER_SIZE * 'B', + self.__dump_callback) + self.__proto.register ('r', 'B', self.__trace_present) - if self.__status == True: - print "Dumping from " + str (self.__addr_init) + " to " + str (self.__addr_end) - - i = self.__addr_init - while i != self.__addr_end: - self.__proto.send ('l', 'bI', FLASH_CMD_READ, (i << 8) | FLASH_BUFFER_SIZE) - i = flash_memory_addr (i + FLASH_BUFFER_SIZE) + i = 0 + self.__traces.append (0x100) + while self.__traces[0] != val and i < FLASH_MEMORY_HIGH: + self.__traces = [] + addr = i >> 16 + self.__proto.send ('l', 4*'b', FLASH_CMD_READ, addr, 0, 0) self.__proto.wait (lambda: True) - else: - self.__memory = None + i += FLASH_PAGE + i -= FLASH_PAGE + + start_addr = i + end_addr = start_addr + FLASH_PAGE + print "Dump memory from address : " + hex(start_addr) + " to " + \ + hex(end_addr) + + for i in range (start_addr, end_addr, FLASH_BUFFER_SIZE): + self.__proto.send ('l', 'bI', FLASH_CMD_READ, (i << 8) | \ + FLASH_BUFFER_SIZE) + self.__proto.wait (lambda: True) + sys.stderr.write ("\nDump ended\n") def get_trace (self): """Return the traces dumped from the flash memory.""" - return reverse_tupple (self.__memory[4:len (self.__memory)]) + return self.__memory[1:] -- cgit v1.2.3