idx int64 0 63k | question stringlengths 61 4.03k | target stringlengths 6 1.23k |
|---|---|---|
42,000 | def release ( self ) : if not self . acquired : return False os . close ( self . fd ) if os . path . exists ( self . path ) : os . remove ( self . path ) self . acquired = False return True | Cleans up the lockfile if it was acquired . |
42,001 | def calculate_parity ( n ) : if not is_natural ( n ) : raise ValueError ( 'Expected n to be a positive integer.' ) y = 0 n = abs ( n ) while n : y += n & 1 n = n >> 1 return y & 1 | Calculates and returns the parity of a number . |
42,002 | def pack ( value , nbits = None ) : if nbits is None : nbits = pack_size ( value ) * BITS_PER_BYTE elif nbits <= 0 : raise ValueError ( 'Given number of bits must be greater than 0.' ) buf_size = int ( math . ceil ( nbits / float ( BITS_PER_BYTE ) ) ) buf = ( ctypes . c_uint8 * buf_size ) ( ) for ( idx , _ ) in enumerate ( buf ) : buf [ idx ] = ( value >> ( idx * BITS_PER_BYTE ) ) & 0xFF return buf | Packs a given value into an array of 8 - bit unsigned integers . |
42,003 | def long_description ( ) : cwd = os . path . abspath ( os . path . dirname ( __file__ ) ) readme_path = os . path . join ( cwd , 'README.md' ) if not os . path . exists ( readme_path ) : return pylink . __long_description__ try : import pypandoc return pypandoc . convert ( readme_path , 'rst' ) except ( IOError , ImportError ) : pass return open ( readme_path , 'r' ) . read ( ) | Reads and returns the contents of the README . |
42,004 | def finalize_options ( self ) : self . cwd = os . path . abspath ( os . path . dirname ( __file__ ) ) self . build_dirs = [ os . path . join ( self . cwd , 'build' ) , os . path . join ( self . cwd , 'htmlcov' ) , os . path . join ( self . cwd , 'dist' ) , os . path . join ( self . cwd , 'pylink_square.egg-info' ) ] self . build_artifacts = [ '.pyc' , '.o' , '.elf' , '.bin' ] | Populate the attributes . |
42,005 | def finalize_options ( self ) : self . cwd = os . path . abspath ( os . path . dirname ( __file__ ) ) self . test_dir = os . path . join ( self . cwd , 'tests' ) | Finalizes the command s options . |
42,006 | def unlock_kinetis_identified ( identity , flags ) : if flags . version_code != identity . version_code : return False if flags . part_no != identity . part_no : return False return flags . valid | Checks whether the given flags are a valid identity . |
42,007 | def unlock_kinetis_abort_clear ( ) : flags = registers . AbortRegisterFlags ( ) flags . STKCMPCLR = 1 flags . STKERRCLR = 1 flags . WDERRCLR = 1 flags . ORUNERRCLR = 1 return flags . value | Returns the abort register clear code . |
42,008 | def unlock_kinetis_read_until_ack ( jlink , address ) : request = swd . ReadRequest ( address , ap = True ) response = None while True : response = request . send ( jlink ) if response . ack ( ) : break elif response . wait ( ) : continue raise KinetisException ( 'Read exited with status: %s' , response . status ) return response | Polls the device until the request is acknowledged . |
42,009 | def unlock_kinetis_swd ( jlink ) : SWDIdentity = Identity ( 0x2 , 0xBA01 ) jlink . power_on ( ) jlink . coresight_configure ( ) flags = registers . IDCodeRegisterFlags ( ) flags . value = jlink . coresight_read ( 0x0 , False ) if not unlock_kinetis_identified ( SWDIdentity , flags ) : return False flags = registers . ControlStatusRegisterFlags ( ) flags . value = jlink . coresight_read ( 0x01 , False ) if flags . STICKYORUN or flags . STICKYCMP or flags . STICKYERR or flags . WDATAERR : jlink . coresight_write ( 0x0 , unlock_kinetis_abort_clear ( ) , False ) flags = registers . ControlStatusRegisterFlags ( ) flags . value = 0 flags . CSYSPWRUPREQ = 1 flags . CDBGPWRUPREQ = 1 jlink . coresight_write ( 0x01 , flags . value , False ) jlink . set_reset_pin_low ( ) time . sleep ( 1 ) request = swd . WriteRequest ( 0x0 , False , unlock_kinetis_abort_clear ( ) ) request . send ( jlink ) request = swd . WriteRequest ( 0x2 , False , ( 1 << 24 ) ) request . send ( jlink ) try : unlock_kinetis_read_until_ack ( jlink , 0x0 ) flags = registers . MDMAPStatusRegisterFlags ( ) flags . flash_ready = 0 while not flags . flash_ready : flags . value = unlock_kinetis_read_until_ack ( jlink , 0x0 ) . data flags = registers . MDMAPControlRegisterFlags ( ) flags . flash_mass_erase = 1 request = swd . WriteRequest ( 0x1 , True , flags . value ) request . send ( jlink ) unlock_kinetis_read_until_ack ( jlink , 0x0 ) flags = registers . MDMAPStatusRegisterFlags ( ) flags . flash_mass_erase_ack = 0 while not flags . flash_mass_erase_ack : flags . value = unlock_kinetis_read_until_ack ( jlink , 0x0 ) . data unlock_kinetis_read_until_ack ( jlink , 0x1 ) flags = registers . MDMAPControlRegisterFlags ( ) flags . flash_mass_erase = 1 while flags . flash_mass_erase : flags . value = unlock_kinetis_read_until_ack ( jlink , 0x1 ) . data except KinetisException as e : jlink . set_reset_pin_high ( ) return False jlink . set_reset_pin_high ( ) time . sleep ( 1 ) jlink . reset ( ) return True | Unlocks a Kinetis device over SWD . |
42,010 | def unlock_kinetis ( jlink ) : if not jlink . connected ( ) : raise ValueError ( 'No target to unlock.' ) method = UNLOCK_METHODS . get ( jlink . tif , None ) if method is None : raise NotImplementedError ( 'Unsupported target interface for unlock.' ) return method ( jlink ) | Unlock for Freescale Kinetis K40 or K60 device . |
42,011 | def minimum_required ( version ) : def _minimum_required ( func ) : @ functools . wraps ( func ) def wrapper ( self , * args , ** kwargs ) : if list ( self . version ) < list ( version ) : raise errors . JLinkException ( 'Version %s required.' % version ) return func ( self , * args , ** kwargs ) return wrapper return _minimum_required | Decorator to specify the minimum SDK version required . |
42,012 | def open_required ( func ) : @ functools . wraps ( func ) def wrapper ( self , * args , ** kwargs ) : if not self . opened ( ) : raise errors . JLinkException ( 'J-Link DLL is not open.' ) elif not self . connected ( ) : raise errors . JLinkException ( 'J-Link connection has been lost.' ) return func ( self , * args , ** kwargs ) return wrapper | Decorator to specify that the J - Link DLL must be opened and a J - Link connection must be established . |
42,013 | def connection_required ( func ) : @ functools . wraps ( func ) def wrapper ( self , * args , ** kwargs ) : if not self . target_connected ( ) : raise errors . JLinkException ( 'Target is not connected.' ) return func ( self , * args , ** kwargs ) return wrapper | Decorator to specify that a target connection is required in order for the given method to be used . |
42,014 | def interface_required ( interface ) : def _interface_required ( func ) : @ functools . wraps ( func ) def wrapper ( self , * args , ** kwargs ) : if self . tif != interface : raise errors . JLinkException ( 'Unsupported for current interface.' ) return func ( self , * args , ** kwargs ) return wrapper return _interface_required | Decorator to specify that a particular interface type is required for the given method to be used . |
42,015 | def log_handler ( self , handler ) : if not self . opened ( ) : handler = handler or util . noop self . _log_handler = enums . JLinkFunctions . LOG_PROTOTYPE ( handler ) self . _dll . JLINKARM_EnableLog ( self . _log_handler ) | Setter for the log handler function . |
42,016 | def detailed_log_handler ( self , handler ) : if not self . opened ( ) : handler = handler or util . noop self . _detailed_log_handler = enums . JLinkFunctions . LOG_PROTOTYPE ( handler ) self . _dll . JLINKARM_EnableLogCom ( self . _detailed_log_handler ) | Setter for the detailed log handler function . |
42,017 | def error_handler ( self , handler ) : if not self . opened ( ) : handler = handler or util . noop self . _error_handler = enums . JLinkFunctions . LOG_PROTOTYPE ( handler ) self . _dll . JLINKARM_SetErrorOutHandler ( self . _error_handler ) | Setter for the error handler function . |
42,018 | def warning_handler ( self , handler ) : if not self . opened ( ) : handler = handler or util . noop self . _warning_handler = enums . JLinkFunctions . LOG_PROTOTYPE ( handler ) self . _dll . JLINKARM_SetWarnOutHandler ( self . _warning_handler ) | Setter for the warning handler function . |
42,019 | def connected_emulators ( self , host = enums . JLinkHost . USB ) : res = self . _dll . JLINKARM_EMU_GetList ( host , 0 , 0 ) if res < 0 : raise errors . JLinkException ( res ) num_devices = res info = ( structs . JLinkConnectInfo * num_devices ) ( ) num_found = self . _dll . JLINKARM_EMU_GetList ( host , info , num_devices ) if num_found < 0 : raise errors . JLinkException ( num_found ) return list ( info ) [ : num_found ] | Returns a list of all the connected emulators . |
42,020 | def supported_device ( self , index = 0 ) : if not util . is_natural ( index ) or index >= self . num_supported_devices ( ) : raise ValueError ( 'Invalid index.' ) info = structs . JLinkDeviceInfo ( ) result = self . _dll . JLINKARM_DEVICE_GetInfo ( index , ctypes . byref ( info ) ) return info | Gets the device at the given index . |
42,021 | def close ( self ) : self . _dll . JLINKARM_Close ( ) if self . _lock is not None : del self . _lock self . _lock = None return None | Closes the open J - Link . |
42,022 | def sync_firmware ( self ) : serial_no = self . serial_number if self . firmware_newer ( ) : try : self . invalidate_firmware ( ) self . update_firmware ( ) except errors . JLinkException as e : pass res = self . open ( serial_no = serial_no ) if self . firmware_newer ( ) : raise errors . JLinkException ( 'Failed to sync firmware version.' ) return res elif self . firmware_outdated ( ) : try : self . update_firmware ( ) except errors . JLinkException as e : pass if self . firmware_outdated ( ) : raise errors . JLinkException ( 'Failed to sync firmware version.' ) return self . open ( serial_no = serial_no ) return None | Syncs the emulator s firmware version and the DLL s firmware . |
42,023 | def exec_command ( self , cmd ) : err_buf = ( ctypes . c_char * self . MAX_BUF_SIZE ) ( ) res = self . _dll . JLINKARM_ExecCommand ( cmd . encode ( ) , err_buf , self . MAX_BUF_SIZE ) err_buf = ctypes . string_at ( err_buf ) . decode ( ) if len ( err_buf ) > 0 : raise errors . JLinkException ( err_buf . strip ( ) ) return res | Executes the given command . |
42,024 | def jtag_configure ( self , instr_regs = 0 , data_bits = 0 ) : if not util . is_natural ( instr_regs ) : raise ValueError ( 'IR value is not a natural number.' ) if not util . is_natural ( data_bits ) : raise ValueError ( 'Data bits is not a natural number.' ) self . _dll . JLINKARM_ConfigJTAG ( instr_regs , data_bits ) return None | Configures the JTAG scan chain to determine which CPU to address . |
42,025 | def coresight_configure ( self , ir_pre = 0 , dr_pre = 0 , ir_post = 0 , dr_post = 0 , ir_len = 0 , perform_tif_init = True ) : if self . tif == enums . JLinkInterfaces . SWD : res = self . _dll . JLINKARM_CORESIGHT_Configure ( '' ) if res < 0 : raise errors . JLinkException ( res ) return None config_string = 'IRPre=%s;DRPre=%s;IRPost=%s;DRPost=%s;IRLenDevice=%s;' config_string = config_string % ( ir_pre , dr_pre , ir_post , dr_post , ir_len ) if not perform_tif_init : config_string = config_string + ( 'PerformTIFInit=0;' ) res = self . _dll . JLINKARM_CORESIGHT_Configure ( config_string . encode ( ) ) if res < 0 : raise errors . JLinkException ( res ) return None | Prepares target and J - Link for CoreSight function usage . |
42,026 | def connect ( self , chip_name , speed = 'auto' , verbose = False ) : if verbose : self . exec_command ( 'EnableRemarks = 1' ) self . exec_command ( 'Device = %s' % chip_name ) if speed == 'auto' : self . set_speed ( auto = True ) elif speed == 'adaptive' : self . set_speed ( adaptive = True ) else : self . set_speed ( speed ) result = self . _dll . JLINKARM_Connect ( ) if result < 0 : raise errors . JLinkException ( result ) try : self . halted ( ) except errors . JLinkException : pass for index in range ( self . num_supported_devices ( ) ) : device = self . supported_device ( index ) if device . name . lower ( ) == chip_name . lower ( ) : self . _device = device break else : raise errors . JLinkException ( 'Unsupported device was connected to.' ) return None | Connects the J - Link to its target . |
42,027 | def compile_date ( self ) : result = self . _dll . JLINKARM_GetCompileDateTime ( ) return ctypes . cast ( result , ctypes . c_char_p ) . value . decode ( ) | Returns a string specifying the date and time at which the DLL was translated . |
42,028 | def version ( self ) : version = int ( self . _dll . JLINKARM_GetDLLVersion ( ) ) major = version / 10000 minor = ( version / 100 ) % 100 rev = version % 100 rev = '' if rev == 0 else chr ( rev + ord ( 'a' ) - 1 ) return '%d.%02d%s' % ( major , minor , rev ) | Returns the device s version . |
42,029 | def compatible_firmware_version ( self ) : identifier = self . firmware_version . split ( 'compiled' ) [ 0 ] buf_size = self . MAX_BUF_SIZE buf = ( ctypes . c_char * buf_size ) ( ) res = self . _dll . JLINKARM_GetEmbeddedFWString ( identifier . encode ( ) , buf , buf_size ) if res < 0 : raise errors . JLinkException ( res ) return ctypes . string_at ( buf ) . decode ( ) | Returns the DLL s compatible J - Link firmware version . |
42,030 | def firmware_outdated ( self ) : datefmt = ' %b %d %Y %H:%M:%S' compat_date = self . compatible_firmware_version . split ( 'compiled' ) [ 1 ] compat_date = datetime . datetime . strptime ( compat_date , datefmt ) fw_date = self . firmware_version . split ( 'compiled' ) [ 1 ] fw_date = datetime . datetime . strptime ( fw_date , datefmt ) return ( compat_date > fw_date ) | Returns whether the J - Link s firmware version is older than the one that the DLL is compatible with . |
42,031 | def hardware_info ( self , mask = 0xFFFFFFFF ) : buf = ( ctypes . c_uint32 * 32 ) ( ) res = self . _dll . JLINKARM_GetHWInfo ( mask , ctypes . byref ( buf ) ) if res != 0 : raise errors . JLinkException ( res ) return list ( buf ) | Returns a list of 32 integer values corresponding to the bitfields specifying the power consumption of the target . |
42,032 | def hardware_status ( self ) : stat = structs . JLinkHardwareStatus ( ) res = self . _dll . JLINKARM_GetHWStatus ( ctypes . byref ( stat ) ) if res == 1 : raise errors . JLinkException ( 'Error in reading hardware status.' ) return stat | Retrieves and returns the hardware status . |
42,033 | def hardware_version ( self ) : version = self . _dll . JLINKARM_GetHardwareVersion ( ) major = version / 10000 % 100 minor = version / 100 % 100 return '%d.%02d' % ( major , minor ) | Returns the hardware version of the connected J - Link as a major . minor string . |
42,034 | def firmware_version ( self ) : buf = ( ctypes . c_char * self . MAX_BUF_SIZE ) ( ) self . _dll . JLINKARM_GetFirmwareString ( buf , self . MAX_BUF_SIZE ) return ctypes . string_at ( buf ) . decode ( ) | Returns a firmware identification string of the connected J - Link . |
42,035 | def extended_capabilities ( self ) : buf = ( ctypes . c_uint8 * 32 ) ( ) self . _dll . JLINKARM_GetEmuCapsEx ( buf , 32 ) return list ( buf ) | Gets the capabilities of the connected emulator as a list . |
42,036 | def features ( self ) : buf = ( ctypes . c_char * self . MAX_BUF_SIZE ) ( ) self . _dll . JLINKARM_GetFeatureString ( buf ) result = ctypes . string_at ( buf ) . decode ( ) . strip ( ) if len ( result ) == 0 : return list ( ) return result . split ( ', ' ) | Returns a list of the J - Link embedded features . |
42,037 | def product_name ( self ) : buf = ( ctypes . c_char * self . MAX_BUF_SIZE ) ( ) self . _dll . JLINKARM_EMU_GetProductName ( buf , self . MAX_BUF_SIZE ) return ctypes . string_at ( buf ) . decode ( ) | Returns the product name of the connected J - Link . |
42,038 | def oem ( self ) : buf = ( ctypes . c_char * self . MAX_BUF_SIZE ) ( ) res = self . _dll . JLINKARM_GetOEMString ( ctypes . byref ( buf ) ) if res != 0 : raise errors . JLinkException ( 'Failed to grab OEM string.' ) oem = ctypes . string_at ( buf ) . decode ( ) if len ( oem ) == 0 : return None return oem | Retrieves and returns the OEM string of the connected J - Link . |
42,039 | def set_speed ( self , speed = None , auto = False , adaptive = False ) : if speed is None : speed = 0 elif not util . is_natural ( speed ) : raise TypeError ( 'Expected positive number for speed, given %s.' % speed ) elif speed > self . MAX_JTAG_SPEED : raise ValueError ( 'Given speed exceeds max speed of %d.' % self . MAX_JTAG_SPEED ) elif speed < self . MIN_JTAG_SPEED : raise ValueError ( 'Given speed is too slow. Minimum is %d.' % self . MIN_JTAG_SPEED ) if auto : speed = speed | self . AUTO_JTAG_SPEED if adaptive : speed = speed | self . ADAPTIVE_JTAG_SPEED self . _dll . JLINKARM_SetSpeed ( speed ) return None | Sets the speed of the JTAG communication with the ARM core . |
42,040 | def speed_info ( self ) : speed_info = structs . JLinkSpeedInfo ( ) self . _dll . JLINKARM_GetSpeedInfo ( ctypes . byref ( speed_info ) ) return speed_info | Retrieves information about supported target interface speeds . |
42,041 | def licenses ( self ) : buf_size = self . MAX_BUF_SIZE buf = ( ctypes . c_char * buf_size ) ( ) res = self . _dll . JLINK_GetAvailableLicense ( buf , buf_size ) if res < 0 : raise errors . JLinkException ( res ) return ctypes . string_at ( buf ) . decode ( ) | Returns a string of the built - in licenses the J - Link has . |
42,042 | def custom_licenses ( self ) : buf = ( ctypes . c_char * self . MAX_BUF_SIZE ) ( ) result = self . _dll . JLINK_EMU_GetLicenses ( buf , self . MAX_BUF_SIZE ) if result < 0 : raise errors . JLinkException ( result ) return ctypes . string_at ( buf ) . decode ( ) | Returns a string of the installed licenses the J - Link has . |
42,043 | def add_license ( self , contents ) : buf_size = len ( contents ) buf = ( ctypes . c_char * ( buf_size + 1 ) ) ( * contents . encode ( ) ) res = self . _dll . JLINK_EMU_AddLicense ( buf ) if res == - 1 : raise errors . JLinkException ( 'Unspecified error.' ) elif res == - 2 : raise errors . JLinkException ( 'Failed to read/write license area.' ) elif res == - 3 : raise errors . JLinkException ( 'J-Link out of space.' ) return ( res == 0 ) | Adds the given contents as a new custom license to the J - Link . |
42,044 | def supported_tifs ( self ) : buf = ctypes . c_uint32 ( ) self . _dll . JLINKARM_TIF_GetAvailable ( ctypes . byref ( buf ) ) return buf . value | Returns a bitmask of the supported target interfaces . |
42,045 | def set_tif ( self , interface ) : if not ( ( 1 << interface ) & self . supported_tifs ( ) ) : raise errors . JLinkException ( 'Unsupported target interface: %s' % interface ) res = self . _dll . JLINKARM_TIF_Select ( interface ) if res != 0 : return False self . _tif = interface return True | Selects the specified target interface . |
42,046 | def gpio_properties ( self ) : res = self . _dll . JLINK_EMU_GPIO_GetProps ( 0 , 0 ) if res < 0 : raise errors . JLinkException ( res ) num_props = res buf = ( structs . JLinkGPIODescriptor * num_props ) ( ) res = self . _dll . JLINK_EMU_GPIO_GetProps ( ctypes . byref ( buf ) , num_props ) if res < 0 : raise errors . JLinkException ( res ) return list ( buf ) | Returns the properties of the user - controllable GPIOs . |
42,047 | def gpio_get ( self , pins = None ) : if pins is None : pins = range ( 4 ) size = len ( pins ) indices = ( ctypes . c_uint8 * size ) ( * pins ) statuses = ( ctypes . c_uint8 * size ) ( ) result = self . _dll . JLINK_EMU_GPIO_GetState ( ctypes . byref ( indices ) , ctypes . byref ( statuses ) , size ) if result < 0 : raise errors . JLinkException ( result ) return list ( statuses ) | Returns a list of states for the given pins . |
42,048 | def gpio_set ( self , pins , states ) : if len ( pins ) != len ( states ) : raise ValueError ( 'Length mismatch between pins and states.' ) size = len ( pins ) indices = ( ctypes . c_uint8 * size ) ( * pins ) states = ( ctypes . c_uint8 * size ) ( * states ) result_states = ( ctypes . c_uint8 * size ) ( ) result = self . _dll . JLINK_EMU_GPIO_SetState ( ctypes . byref ( indices ) , ctypes . byref ( states ) , ctypes . byref ( result_states ) , size ) if result < 0 : raise errors . JLinkException ( result ) return list ( result_states ) | Sets the state for one or more user - controllable GPIOs . |
42,049 | def unlock ( self ) : if not unlockers . unlock ( self , self . _device . manufacturer ) : raise errors . JLinkException ( 'Failed to unlock device.' ) return True | Unlocks the device connected to the J - Link . |
42,050 | def erase ( self ) : try : if not self . halted ( ) : self . halt ( ) except errors . JLinkException : pass res = self . _dll . JLINK_EraseChip ( ) if res < 0 : raise errors . JLinkEraseException ( res ) return res | Erases the flash contents of the device . |
42,051 | def reset ( self , ms = 0 , halt = True ) : self . _dll . JLINKARM_SetResetDelay ( ms ) res = self . _dll . JLINKARM_Reset ( ) if res < 0 : raise errors . JLinkException ( res ) elif not halt : self . _dll . JLINKARM_Go ( ) return res | Resets the target . |
42,052 | def halt ( self ) : res = int ( self . _dll . JLINKARM_Halt ( ) ) if res == 0 : time . sleep ( 1 ) return True return False | Halts the CPU Core . |
42,053 | def halted ( self ) : result = int ( self . _dll . JLINKARM_IsHalted ( ) ) if result < 0 : raise errors . JLinkException ( result ) return ( result > 0 ) | Returns whether the CPU core was halted . |
42,054 | def core_name ( self ) : buf_size = self . MAX_BUF_SIZE buf = ( ctypes . c_char * buf_size ) ( ) self . _dll . JLINKARM_Core2CoreName ( self . core_cpu ( ) , buf , buf_size ) return ctypes . string_at ( buf ) . decode ( ) | Returns the name of the target ARM core . |
42,055 | def scan_chain_len ( self , scan_chain ) : res = self . _dll . JLINKARM_MeasureSCLen ( scan_chain ) if res < 0 : raise errors . JLinkException ( res ) return res | Retrieves and returns the number of bits in the scan chain . |
42,056 | def register_list ( self ) : num_items = self . MAX_NUM_CPU_REGISTERS buf = ( ctypes . c_uint32 * num_items ) ( ) num_regs = self . _dll . JLINKARM_GetRegisterList ( buf , num_items ) return buf [ : num_regs ] | Returns a list of the indices for the CPU registers . |
42,057 | def register_name ( self , register_index ) : result = self . _dll . JLINKARM_GetRegisterName ( register_index ) return ctypes . cast ( result , ctypes . c_char_p ) . value . decode ( ) | Retrives and returns the name of an ARM CPU register . |
42,058 | def cpu_speed ( self , silent = False ) : res = self . _dll . JLINKARM_MeasureCPUSpeedEx ( - 1 , 1 , int ( silent ) ) if res < 0 : raise errors . JLinkException ( res ) return res | Retrieves the CPU speed of the target . |
42,059 | def cpu_halt_reasons ( self ) : buf_size = self . MAX_NUM_MOES buf = ( structs . JLinkMOEInfo * buf_size ) ( ) num_reasons = self . _dll . JLINKARM_GetMOEs ( buf , buf_size ) if num_reasons < 0 : raise errors . JLinkException ( num_reasons ) return list ( buf ) [ : num_reasons ] | Retrives the reasons that the CPU was halted . |
42,060 | def jtag_send ( self , tms , tdi , num_bits ) : if not util . is_natural ( num_bits ) or num_bits <= 0 or num_bits > 32 : raise ValueError ( 'Number of bits must be >= 1 and <= 32.' ) self . _dll . JLINKARM_StoreBits ( tms , tdi , num_bits ) return None | Sends data via JTAG . |
42,061 | def swd_read8 ( self , offset ) : value = self . _dll . JLINK_SWD_GetU8 ( offset ) return ctypes . c_uint8 ( value ) . value | Gets a unit of 8 bits from the input buffer . |
42,062 | def swd_read16 ( self , offset ) : value = self . _dll . JLINK_SWD_GetU16 ( offset ) return ctypes . c_uint16 ( value ) . value | Gets a unit of 16 bits from the input buffer . |
42,063 | def swd_read32 ( self , offset ) : value = self . _dll . JLINK_SWD_GetU32 ( offset ) return ctypes . c_uint32 ( value ) . value | Gets a unit of 32 bits from the input buffer . |
42,064 | def swd_sync ( self , pad = False ) : if pad : self . _dll . JLINK_SWD_SyncBytes ( ) else : self . _dll . JLINK_SWD_SyncBits ( ) return None | Causes a flush to write all data remaining in output buffers to SWD device . |
42,065 | def flash_write ( self , addr , data , nbits = None , flags = 0 ) : self . _dll . JLINKARM_BeginDownload ( flags ) self . memory_write ( addr , data , nbits = nbits ) bytes_flashed = self . _dll . JLINKARM_EndDownload ( ) if bytes_flashed < 0 : raise errors . JLinkFlashException ( bytes_flashed ) return bytes_flashed | Writes data to the flash region of a device . |
42,066 | def code_memory_read ( self , addr , num_bytes ) : buf_size = num_bytes buf = ( ctypes . c_uint8 * buf_size ) ( ) res = self . _dll . JLINKARM_ReadCodeMem ( addr , buf_size , buf ) if res < 0 : raise errors . JLinkException ( res ) return list ( buf ) [ : res ] | Reads bytes from code memory . |
42,067 | def num_memory_zones ( self ) : count = self . _dll . JLINK_GetMemZones ( 0 , 0 ) if count < 0 : raise errors . JLinkException ( count ) return count | Returns the number of memory zones supported by the target . |
42,068 | def memory_zones ( self ) : count = self . num_memory_zones ( ) if count == 0 : return list ( ) buf = ( structs . JLinkMemoryZone * count ) ( ) res = self . _dll . JLINK_GetMemZones ( buf , count ) if res < 0 : raise errors . JLinkException ( res ) return list ( buf ) | Gets all memory zones supported by the current target . |
42,069 | def memory_read ( self , addr , num_units , zone = None , nbits = None ) : buf_size = num_units buf = None access = 0 if nbits is None : buf = ( ctypes . c_uint8 * buf_size ) ( ) access = 0 elif nbits == 8 : buf = ( ctypes . c_uint8 * buf_size ) ( ) access = 1 elif nbits == 16 : buf = ( ctypes . c_uint16 * buf_size ) ( ) access = 2 buf_size = buf_size * access elif nbits == 32 : buf = ( ctypes . c_uint32 * buf_size ) ( ) access = 4 buf_size = buf_size * access else : raise ValueError ( 'Given bit size is invalid: %s' % nbits ) args = [ addr , buf_size , buf , access ] method = self . _dll . JLINKARM_ReadMemEx if zone is not None : method = self . _dll . JLINKARM_ReadMemZonedEx args . append ( zone . encode ( ) ) units_read = method ( * args ) if units_read < 0 : raise errors . JLinkReadException ( units_read ) return buf [ : units_read ] | Reads memory from a target system or specific memory zone . |
42,070 | def memory_read8 ( self , addr , num_bytes , zone = None ) : return self . memory_read ( addr , num_bytes , zone = zone , nbits = 8 ) | Reads memory from the target system in units of bytes . |
42,071 | def memory_read16 ( self , addr , num_halfwords , zone = None ) : return self . memory_read ( addr , num_halfwords , zone = zone , nbits = 16 ) | Reads memory from the target system in units of 16 - bits . |
42,072 | def memory_read32 ( self , addr , num_words , zone = None ) : return self . memory_read ( addr , num_words , zone = zone , nbits = 32 ) | Reads memory from the target system in units of 32 - bits . |
42,073 | def memory_read64 ( self , addr , num_long_words ) : buf_size = num_long_words buf = ( ctypes . c_ulonglong * buf_size ) ( ) units_read = self . _dll . JLINKARM_ReadMemU64 ( addr , buf_size , buf , 0 ) if units_read < 0 : raise errors . JLinkException ( units_read ) return buf [ : units_read ] | Reads memory from the target system in units of 64 - bits . |
42,074 | def memory_write ( self , addr , data , zone = None , nbits = None ) : buf_size = len ( data ) buf = None access = 0 if nbits is None : packed_data = map ( lambda d : reversed ( binpacker . pack ( d ) ) , data ) packed_data = list ( itertools . chain ( * packed_data ) ) buf_size = len ( packed_data ) buf = ( ctypes . c_uint8 * buf_size ) ( * packed_data ) access = 0 elif nbits == 8 : buf = ( ctypes . c_uint8 * buf_size ) ( * data ) access = 1 elif nbits == 16 : buf = ( ctypes . c_uint16 * buf_size ) ( * data ) access = 2 buf_size = buf_size * access elif nbits == 32 : buf = ( ctypes . c_uint32 * buf_size ) ( * data ) access = 4 buf_size = buf_size * access else : raise ValueError ( 'Given bit size is invalid: %s' % nbits ) args = [ addr , buf_size , buf , access ] method = self . _dll . JLINKARM_WriteMemEx if zone is not None : method = self . _dll . JLINKARM_WriteMemZonedEx args . append ( zone . encode ( ) ) units_written = method ( * args ) if units_written < 0 : raise errors . JLinkWriteException ( units_written ) return units_written | Writes memory to a target system or specific memory zone . |
42,075 | def memory_write8 ( self , addr , data , zone = None ) : return self . memory_write ( addr , data , zone , 8 ) | Writes bytes to memory of a target system . |
42,076 | def memory_write16 ( self , addr , data , zone = None ) : return self . memory_write ( addr , data , zone , 16 ) | Writes half - words to memory of a target system . |
42,077 | def memory_write32 ( self , addr , data , zone = None ) : return self . memory_write ( addr , data , zone , 32 ) | Writes words to memory of a target system . |
42,078 | def memory_write64 ( self , addr , data , zone = None ) : words = [ ] bitmask = 0xFFFFFFFF for long_word in data : words . append ( long_word & bitmask ) words . append ( ( long_word >> 32 ) & bitmask ) return self . memory_write32 ( addr , words , zone = zone ) | Writes long words to memory of a target system . |
42,079 | def register_read_multiple ( self , register_indices ) : num_regs = len ( register_indices ) buf = ( ctypes . c_uint32 * num_regs ) ( * register_indices ) data = ( ctypes . c_uint32 * num_regs ) ( 0 ) statuses = ( ctypes . c_uint8 * num_regs ) ( 0 ) res = self . _dll . JLINKARM_ReadRegs ( buf , data , statuses , num_regs ) if res < 0 : raise errors . JLinkException ( res ) return list ( data ) | Retrieves the values from the registers specified . |
42,080 | def register_write ( self , reg_index , value ) : res = self . _dll . JLINKARM_WriteReg ( reg_index , value ) if res != 0 : raise errors . JLinkException ( 'Error writing to register %d' % reg_index ) return value | Writes into an ARM register . |
42,081 | def register_write_multiple ( self , register_indices , values ) : if len ( register_indices ) != len ( values ) : raise ValueError ( 'Must be an equal number of registers and values' ) num_regs = len ( register_indices ) buf = ( ctypes . c_uint32 * num_regs ) ( * register_indices ) data = ( ctypes . c_uint32 * num_regs ) ( * values ) statuses = ( ctypes . c_uint8 * num_regs ) ( 0 ) res = self . _dll . JLINKARM_WriteRegs ( buf , data , statuses , num_regs ) if res != 0 : raise errors . JLinkException ( res ) return None | Writes to multiple CPU registers . |
42,082 | def ice_register_write ( self , register_index , value , delay = False ) : self . _dll . JLINKARM_WriteICEReg ( register_index , int ( value ) , int ( delay ) ) return None | Writes a value to an ARM ICE register . |
42,083 | def etm_supported ( self ) : res = self . _dll . JLINKARM_ETM_IsPresent ( ) if ( res == 1 ) : return True info = ctypes . c_uint32 ( 0 ) index = enums . JLinkROMTable . ETM res = self . _dll . JLINKARM_GetDebugInfo ( index , ctypes . byref ( info ) ) if ( res == 1 ) : return False return True | Returns if the CPU core supports ETM . |
42,084 | def etm_register_write ( self , register_index , value , delay = False ) : self . _dll . JLINKARM_ETM_WriteReg ( int ( register_index ) , int ( value ) , int ( delay ) ) return None | Writes a value to an ETM register . |
42,085 | def set_vector_catch ( self , flags ) : res = self . _dll . JLINKARM_WriteVectorCatch ( flags ) if res < 0 : raise errors . JLinkException ( res ) return None | Sets vector catch bits of the processor . |
42,086 | def step ( self , thumb = False ) : method = self . _dll . JLINKARM_Step if thumb : method = self . _dll . JLINKARM_StepComposite res = method ( ) if res != 0 : raise errors . JLinkException ( "Failed to step over instruction." ) return None | Executes a single step . |
42,087 | def num_available_breakpoints ( self , arm = False , thumb = False , ram = False , flash = False , hw = False ) : flags = [ enums . JLinkBreakpoint . ARM , enums . JLinkBreakpoint . THUMB , enums . JLinkBreakpoint . SW_RAM , enums . JLinkBreakpoint . SW_FLASH , enums . JLinkBreakpoint . HW ] set_flags = [ arm , thumb , ram , flash , hw ] if not any ( set_flags ) : flags = enums . JLinkBreakpoint . ANY else : flags = list ( f for i , f in enumerate ( flags ) if set_flags [ i ] ) flags = functools . reduce ( operator . __or__ , flags , 0 ) return self . _dll . JLINKARM_GetNumBPUnits ( flags ) | Returns the number of available breakpoints of the specified type . |
42,088 | def breakpoint_info ( self , handle = 0 , index = - 1 ) : if index < 0 and handle == 0 : raise ValueError ( 'Handle must be provided if index is not set.' ) bp = structs . JLinkBreakpointInfo ( ) bp . Handle = int ( handle ) res = self . _dll . JLINKARM_GetBPInfoEx ( index , ctypes . byref ( bp ) ) if res < 0 : raise errors . JLinkException ( 'Failed to get breakpoint info.' ) return bp | Returns the information about a set breakpoint . |
42,089 | def breakpoint_set ( self , addr , thumb = False , arm = False ) : flags = enums . JLinkBreakpoint . ANY if thumb : flags = flags | enums . JLinkBreakpoint . THUMB elif arm : flags = flags | enums . JLinkBreakpoint . ARM handle = self . _dll . JLINKARM_SetBPEx ( int ( addr ) , flags ) if handle <= 0 : raise errors . JLinkException ( 'Breakpoint could not be set.' ) return handle | Sets a breakpoint at the specified address . |
42,090 | def software_breakpoint_set ( self , addr , thumb = False , arm = False , flash = False , ram = False ) : if flash and not ram : flags = enums . JLinkBreakpoint . SW_FLASH elif not flash and ram : flags = enums . JLinkBreakpoint . SW_RAM else : flags = enums . JLinkBreakpoint . SW if thumb : flags = flags | enums . JLinkBreakpoint . THUMB elif arm : flags = flags | enums . JLinkBreakpoint . ARM handle = self . _dll . JLINKARM_SetBPEx ( int ( addr ) , flags ) if handle <= 0 : raise errors . JLinkException ( 'Software breakpoint could not be set.' ) return handle | Sets a software breakpoint at the specified address . |
42,091 | def watchpoint_info ( self , handle = 0 , index = - 1 ) : if index < 0 and handle == 0 : raise ValueError ( 'Handle must be provided if index is not set.' ) wp = structs . JLinkWatchpointInfo ( ) res = self . _dll . JLINKARM_GetWPInfoEx ( index , ctypes . byref ( wp ) ) if res < 0 : raise errors . JLinkException ( 'Failed to get watchpoint info.' ) for i in range ( res ) : res = self . _dll . JLINKARM_GetWPInfoEx ( i , ctypes . byref ( wp ) ) if res < 0 : raise errors . JLinkException ( 'Failed to get watchpoint info.' ) elif wp . Handle == handle or wp . WPUnit == index : return wp return None | Returns information about the specified watchpoint . |
42,092 | def watchpoint_set ( self , addr , addr_mask = 0x0 , data = 0x0 , data_mask = 0x0 , access_size = None , read = False , write = False , privileged = False ) : access_flags = 0x0 access_mask_flags = 0x0 if access_size is None : access_mask_flags = access_mask_flags | enums . JLinkAccessMaskFlags . SIZE elif access_size == 8 : access_flags = access_flags | enums . JLinkAccessFlags . SIZE_8BIT elif access_size == 16 : access_flags = access_flags | enums . JLinkAccessFlags . SIZE_16BIT elif access_size == 32 : access_flags = access_flags | enums . JLinkAccessFlags . SIZE_32BIT else : raise ValueError ( 'Invalid access size given: %d' % access_size ) if read and write : access_mask_flags = access_mask_flags | enums . JLinkAccessMaskFlags . DIR elif read : access_flags = access_flags | enums . JLinkAccessFlags . READ elif write : access_flags = access_flags | enums . JLinkAccessFlags . WRITE if privileged : access_flags = access_flags | enums . JLinkAccessFlags . PRIV else : access_mask_flags = access_mask_flags | enums . JLinkAccessMaskFlags . PRIV wp = structs . JLinkDataEvent ( ) wp . Addr = addr wp . AddrMask = addr_mask wp . Data = data wp . DataMask = data_mask wp . Access = access_flags wp . AccessMask = access_mask_flags handle = ctypes . c_uint32 ( ) res = self . _dll . JLINKARM_SetDataEvent ( ctypes . pointer ( wp ) , ctypes . pointer ( handle ) ) if res < 0 : raise errors . JLinkDataException ( res ) return handle . value | Sets a watchpoint at the given address . |
42,093 | def disassemble_instruction ( self , instruction ) : if not util . is_integer ( instruction ) : raise TypeError ( 'Expected instruction to be an integer.' ) buf_size = self . MAX_BUF_SIZE buf = ( ctypes . c_char * buf_size ) ( ) res = self . _dll . JLINKARM_DisassembleInst ( ctypes . byref ( buf ) , buf_size , instruction ) if res < 0 : raise errors . JLinkException ( 'Failed to disassemble instruction.' ) return ctypes . string_at ( buf ) . decode ( ) | Disassembles and returns the assembly instruction string . |
42,094 | def strace_configure ( self , port_width ) : if port_width not in [ 1 , 2 , 4 ] : raise ValueError ( 'Invalid port width: %s' % str ( port_width ) ) config_string = 'PortWidth=%d' % port_width res = self . _dll . JLINK_STRACE_Config ( config_string . encode ( ) ) if res < 0 : raise errors . JLinkException ( 'Failed to configure STRACE port' ) return None | Configures the trace port width for tracing . |
42,095 | def strace_read ( self , num_instructions ) : if num_instructions < 0 or num_instructions > 0x10000 : raise ValueError ( 'Invalid instruction count.' ) buf = ( ctypes . c_uint32 * num_instructions ) ( ) buf_size = num_instructions res = self . _dll . JLINK_STRACE_Read ( ctypes . byref ( buf ) , buf_size ) if res < 0 : raise errors . JLinkException ( 'Failed to read from STRACE buffer.' ) return list ( buf ) [ : res ] | Reads and returns a number of instructions captured by STRACE . |
42,096 | def strace_data_access_event ( self , operation , address , data , data_mask = None , access_width = 4 , address_range = 0 ) : cmd = enums . JLinkStraceCommand . TRACE_EVENT_SET event_info = structs . JLinkStraceEventInfo ( ) event_info . Type = enums . JLinkStraceEvent . DATA_ACCESS event_info . Op = operation event_info . AccessSize = int ( access_width ) event_info . Addr = int ( address ) event_info . Data = int ( data ) event_info . DataMask = int ( data_mask or 0 ) event_info . AddrRangeSize = int ( address_range ) handle = self . _dll . JLINK_STRACE_Control ( cmd , ctypes . byref ( event_info ) ) if handle < 0 : raise errors . JLinkException ( handle ) return handle | Sets an event to trigger trace logic when data access is made . |
42,097 | def strace_data_store_event ( self , operation , address , address_range = 0 ) : cmd = enums . JLinkStraceCommand . TRACE_EVENT_SET event_info = structs . JLinkStraceEventInfo ( ) event_info . Type = enums . JLinkStraceEvent . DATA_STORE event_info . Op = operation event_info . Addr = int ( address ) event_info . AddrRangeSize = int ( address_range ) handle = self . _dll . JLINK_STRACE_Control ( cmd , ctypes . byref ( event_info ) ) if handle < 0 : raise errors . JLinkException ( handle ) return handle | Sets an event to trigger trace logic when data write access is made . |
42,098 | def strace_clear ( self , handle ) : data = ctypes . c_int ( handle ) res = self . _dll . JLINK_STRACE_Control ( enums . JLinkStraceCommand . TRACE_EVENT_CLR , ctypes . byref ( data ) ) if res < 0 : raise errors . JLinkException ( 'Failed to clear STRACE event.' ) return None | Clears the trace event specified by the given handle . |
42,099 | def strace_clear_all ( self ) : data = 0 res = self . _dll . JLINK_STRACE_Control ( enums . JLinkStraceCommand . TRACE_EVENT_CLR_ALL , data ) if res < 0 : raise errors . JLinkException ( 'Failed to clear all STRACE events.' ) return None | Clears all STRACE events . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.