perform a reset and stop the core on the reset handler

def reset_and_halt(self, reset_type=None):
        """
        perform a reset and stop the core on the reset handler
        """
        
        delegateResult = self.call_delegate('set_reset_catch', core=self, reset_type=reset_type)
        
        # halt the target
        if not delegateResult:
            self.halt()

        # Save CortexM.DEMCR
        demcr = self.read_memory(CortexM.DEMCR)

        # enable the vector catch
        if not delegateResult:
            self.write_memory(CortexM.DEMCR, demcr | CortexM.DEMCR_VC_CORERESET)

        self.reset(reset_type)

        # wait until the unit resets
        with timeout.Timeout(2.0) as t_o:
            while t_o.check():
                if self.get_state() not in (Target.TARGET_RESET, Target.TARGET_RUNNING):
                    break
                sleep(0.01)

        # Make sure the thumb bit is set in XPSR in case the reset handler
        # points to an invalid address.
        xpsr = self.read_core_register('xpsr')
        if xpsr & self.XPSR_THUMB == 0:
            self.write_core_register('xpsr', xpsr | self.XPSR_THUMB)

        self.call_delegate('clear_reset_catch', core=self, reset_type=reset_type)

        # restore vector catch setting
        self.write_memory(CortexM.DEMCR, demcr)