def waitForCompletion(self):
        while(self.target.getState() == Target.TARGET_RUNNING):
            pass

        if self.flash_algo_debug:
            analyzer_supported = self.flash_algo['analyzer_supported']

            expected_fp = self.flash_algo['static_base']
            expected_sp = self.flash_algo['begin_stack']
            expected_pc = self.flash_algo['load_address']
            expected_flash_algo = self.flash_algo['instructions']
            if analyzer_supported:
                expected_analyzer = analyzer
            final_fp = self.target.readCoreRegister('r9')
            final_sp = self.target.readCoreRegister('sp')
            final_pc = self.target.readCoreRegister('pc')
            #TODO - uncomment if Read/write and zero init sections can be moved into a separate flash algo section
            #final_flash_algo = self.target.readBlockMemoryAligned32(self.flash_algo['load_address'], len(self.flash_algo['instructions']))
            #if analyzer_supported:
            #    final_analyzer = self.target.readBlockMemoryAligned32(self.flash_algo['analyzer_address'], len(analyzer))

            error = False
            if final_fp != expected_fp:
                # Frame pointer should not change
                logging.error("Frame pointer should be 0x%x but is 0x%x" % (expected_fp, final_fp))
                error = True
            if final_sp != expected_sp:
                # Stack pointer should return to original value after function call
                logging.error("Stack pointer should be 0x%x but is 0x%x" % (expected_sp, final_sp))
                error = True
            if final_pc != expected_pc:
                # PC should be pointing to breakpoint address
                logging.error("PC should be 0x%x but is 0x%x" % (expected_pc, final_pc))
                error = True
            #TODO - uncomment if Read/write and zero init sections can be moved into a separate flash algo section
            #if not _same(expected_flash_algo, final_flash_algo):
            #    logging.error("Flash algorithm overwritten!")
            #    error = True
            #if analyzer_supported and not _same(expected_analyzer, final_analyzer):
            #    logging.error("Analyzer overwritten!")
            #    error = True
            assert error == False
            self.target.setVectorCatchFault(self._vector_catch_enabled)
            self.target.setVectorCatchReset(self._reset_catch_enabled)

        return self.target.readCoreRegister('r0')
dataset/ETHPy150Open mbedmicro/pyOCD/pyOCD/flash/flash.py/Flash.waitForCompletion/original