From da91bb6d1ec2edda204eb50bb1ec6a0e00a4d557 Mon Sep 17 00:00:00 2001 From: NĂ©lio Laranjeiro Date: Fri, 6 Mar 2009 22:57:57 +0100 Subject: tools/trace: Ended the interpretor part of the trace tool. --- tools/trace/tinter/thost.py | 74 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 72 insertions(+), 2 deletions(-) (limited to 'tools/trace/tinter/thost.py') diff --git a/tools/trace/tinter/thost.py b/tools/trace/tinter/thost.py index 5608874c..bbbdf0d0 100644 --- a/tools/trace/tinter/thost.py +++ b/tools/trace/tinter/thost.py @@ -1,2 +1,72 @@ -def thost_dump_memory(): - return "000000000100000002000301000000020000000300040200FEDA0056789A" +import serial +import time +from proto import * +from utils import * + +FLASH_MEMORY_HIGH = 0x1fffff +FLASH_BUFFER_SIZE = 128 +FLASH_CMD_INIT = 0 +FLASH_CMD_READ = 1 + +def flash_memory_addr (val): + return (val & FLASH_MEMORY_HIGH) + +def log (x): + print x + +class THost: + """Class to connect to the flash memory.""" + 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 + + def __dump_callback (self, *memory): + """Callback call on each data reception""" + for i in range(len (memory)): + self.__memory.append (memory[i]) + + def __flash_status (self, status): + """Get the flash status.""" + print "Flash activate : ", status + self.__status = status + + 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 __flash_log_end (self, *addr): + """Get the flash log end address.""" + addr = reverse_tupple (addr) + self.__addr_end = get_size (addr, 3) + + def dump_memory(self): + """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) + + 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) + self.__proto.wait (lambda: True) + else: + self.__memory = None + + def get_trace (self): + """Return the traces dumped from the flash memory.""" + return reverse_tupple (self.__memory[4:len (self.__memory)]) -- cgit v1.2.3