Пример #1
0
    def update_from_bitsnap(self, info):
        """Update this device with information from a bitsnap container.
        :type self: Snap
        :param info: device information dictionary containing Simulink block information
        """
        def clean_fields(fstr):
            _fstr = fstr.replace('[', '').replace(']', '').strip().replace(
                ', ', ',').replace('  ', ' ')
            if (_fstr.find(' ') > -1) and (_fstr.find(',') > -1):
                LOGGER.error(
                    'Parameter string %s contains spaces and commas as delimiters. This is confusing.'
                    % fstr)
            if _fstr.find(' ') > -1:
                _flist = _fstr.split(' ')
            else:
                _flist = _fstr.split(',')
            _rv = []
            for _fname in _flist:
                if _fname.strip() == '':
                    LOGGER.DEBUG('Throwing away empty field in snapshot %s' %
                                 self.name)
                else:
                    _rv.append(_fname)
            return _rv

        self.block_info = info
        if self.width_bits != int(info['snap_data_width']):
            raise ValueError('Snap and matched bitsnap widths do not match.')
        if self.length_bytes != pow(2, int(
                info['snap_nsamples'])) * (self.width_bits / 8):
            raise ValueError('Snap and matched bitsnap lengths do not match.')
        field_names = clean_fields(info['io_names'])
        field_widths = clean_fields(info['io_widths'])
        field_types = clean_fields(info['io_types'])
        field_bps = clean_fields(info['io_bps'])
        field_names.reverse()
        field_widths.reverse()
        field_types.reverse()
        field_bps.reverse()
        self.fields_clear()
        for n, fn in enumerate(field_names):
            try:
                bitwidth = int(field_widths[n])
            except ValueError:
                bitwidth = eval(field_widths[n])
            field = bitfield.Field(name=fn,
                                   numtype=int(field_types[n]),
                                   width_bits=bitwidth,
                                   binary_pt=int(field_bps[n]),
                                   lsb_offset=-1)
            self.field_add(field, auto_offset=True)
Пример #2
0
    def update_from_bitsnap(self, info):
        """
        Update this device with information from a bitsnap container.

        :type self: Snap
        :param info: device information dictionary containing Simulink block
            information
        """
        clean_fields = bitfield.clean_fields
        self.block_info = info
        if self.width_bits != int(info['snap_data_width']):
            raise ValueError('Snap and matched bitsnap widths do not match.')
        samples_bytes = pow(2, int(
            info['snap_nsamples'])) * (self.width_bits / 8)
        if self.length_bytes != samples_bytes:
            raise ValueError('Snap and matched bitsnap lengths do not match.')
        fields = {
            'names': clean_fields(self.name, 'snapshot', info['io_names']),
            'widths': clean_fields(self.name, 'snapshot', info['io_widths']),
            'types': clean_fields(self.name, 'snapshot', info['io_types']),
            'bps': clean_fields(self.name, 'snapshot', info['io_bps'])
        }
        fields['names'].reverse()
        fields['widths'].reverse()
        fields['types'].reverse()
        fields['bps'].reverse()
        self.fields_clear()
        len_names = len(fields['names'])
        for fld in ['widths', 'types', 'bps']:
            # convert the number-based fields to integers
            for n, val in enumerate(fields[fld]):
                try:
                    intvalue = int(val)
                except ValueError:
                    intvalue = eval(val)
                fields[fld][n] = intvalue
            # accommodate new snapshots where the fields may have length one
            len_fld = len(fields[fld])
            if len_fld != len_names:
                if len_fld != 1:
                    raise RuntimeError('%i names, but %i %s?' %
                                       (len_names, len_fld, fld))
                fields[fld] = [fields[fld][0]] * len_names
        # construct the fields and add them to this BitField
        for ctr, name in enumerate(fields['names']):
            field = bitfield.Field(name=name,
                                   numtype=fields['types'][ctr],
                                   width_bits=fields['widths'][ctr],
                                   binary_pt=fields['bps'][ctr],
                                   lsb_offset=-1)
            self.field_add(field, auto_offset=True)
Пример #3
0
 def _process_info_tabbed(self):
     LOGGER.warn('Tabbed registers are deprecated!')
     numios = int(self.block_info['numios'])
     for ctr in range(numios, 0, -1):
         if self.block_info['arith_type%i' % ctr] == 'Boolean':
             atype = 2
         elif self.block_info['arith_type%i' % ctr] == 'Unsigned':
             atype = 0
         else:
             atype = 1
         field = bitfield.Field(self.block_info['name%i' % ctr], atype,
                                int(self.block_info['bitwidth%i' % ctr]),
                                int(self.block_info['bin_pt%i' % ctr]), -1)
         self.field_add(field, auto_offset=True)
Пример #4
0
 def process_info(self, info):
     """
     Set this Register's extra information.
     """
     if (info is None) or (info == {}):
         return
     self.block_info = info
     self.fields_clear()
     if 'mode' in self.block_info.keys():
         self._process_info_current()
     elif 'numios' in self.block_info.keys():
         # aborted tabbed one
         self._process_info_tabbed()
     elif 'name' in self.block_info.keys():
         # oldest
         LOGGER.error('Old registers are deprecated!')
         self.field_add(bitfield.Field('reg', 0, 32, 0, 0))
     else:
         LOGGER.error(
             'That is a seriously old register - please swap it out!')
         LOGGER.error(self)
         LOGGER.error(self.block_info)
         self.field_add(bitfield.Field('reg', 0, 32, 0, 0))
Пример #5
0
    def __init__(self, parent, name, width_bits, address, length_bytes,
                 device_info=None):

        super(Snap, self).__init__(name=name, width_bits=width_bits,
                                   address=address, length_bytes=length_bytes)
        self.parent = parent
        self.block_info = device_info
        self.field_add(bitfield.Field(name='data', numtype=0,
                                      width_bits=self.width_bits,
                                      binary_pt=0, lsb_offset=0))
        self.control_registers = {
            'control': {'register': None, 'name': self.name + '_ctrl'},
            'status': {'register': None, 'name': self.name + '_status'},
            'trig_offset': {'register': None,
                            'name': self.name + '_trig_offset'},
            'extra_value': {'register': None, 'name': self.name + '_val'},
            'tr_en_cnt': {'register': None, 'name': self.name + '_tr_en_cnt'}}
        LOGGER.debug('New Snap %s' % self)
Пример #6
0
 def _process_info_current(self):
     # current one
     clean_fields = bitfield.clean_fields
     # a single value may have been used for width, type or binary point
     fields = {
         'names':
         clean_fields(self.name, 'register', self.block_info['names']),
         'widths':
         clean_fields(self.name, 'register', self.block_info['bitwidths']),
         'types':
         clean_fields(self.name, 'register',
                      self.block_info['arith_types']),
         'bps':
         clean_fields(self.name, 'register', self.block_info['bin_pts'])
     }
     fields['names'].reverse()
     fields['widths'].reverse()
     fields['types'].reverse()
     fields['bps'].reverse()
     len_names = len(fields['names'])
     for fld in ['widths', 'types', 'bps']:
         # convert the number-based fields to integers
         for n, val in enumerate(fields[fld]):
             try:
                 intvalue = int(val)
             except ValueError:
                 intvalue = eval(val)
             fields[fld][n] = intvalue
         # accommodate new snapshots where the fields may have length one
         len_fld = len(fields[fld])
         if len_fld != len_names:
             if len_fld != 1:
                 raise RuntimeError('%i names, but %i %s?' %
                                    (len_names, len_fld, fld))
             fields[fld] = [fields[fld][0]] * len_names
     # construct the fields and add them to this BitField
     for ctr, name in enumerate(fields['names']):
         field = bitfield.Field(name, fields['types'][ctr],
                                fields['widths'][ctr], fields['bps'][ctr],
                                -1)
         self.field_add(field, auto_offset=True)
Пример #7
0
    def _process_info_current(self):
        # current one
        def clean_fields(fstr):
            _fstr = fstr.replace('[', '').replace(']', '').strip().replace(
                ', ', ',').replace('  ', ' ')
            if (_fstr.find(' ') > -1) and (_fstr.find(',') > -1):
                LOGGER.error(
                    'Parameter string %s contains spaces and commas as delimiters. '
                    'This is confusing.' % fstr)
            if _fstr.find(' ') > -1:
                _flist = _fstr.split(' ')
            else:
                _flist = _fstr.split(',')
            _rv = []
            for _fname in _flist:
                if _fname.strip() == '':
                    LOGGER.DEBUG('Throwing away empty field in register %s' %
                                 self.name)
                else:
                    _rv.append(_fname)
            return _rv

        # a single value may have been used for width, type or binary point
        field_names = clean_fields(self.block_info['names'])
        field_widths = clean_fields(self.block_info['bitwidths'])
        field_types = clean_fields(self.block_info['arith_types'])
        field_bin_pts = clean_fields(self.block_info['bin_pts'])
        field_names.reverse()
        field_widths.reverse()
        field_types.reverse()
        field_bin_pts.reverse()
        # convert the number-based fields to integers
        for avar in [field_widths, field_bin_pts, field_types]:
            for index, value in enumerate(avar):
                try:
                    intvalue = int(value)
                except ValueError:
                    intvalue = eval(value)
                avar[index] = intvalue
        num_fields = len(field_names)
        if self.block_info['mode'] == 'fields of equal size':
            for avar in [field_widths, field_bin_pts, field_types]:
                if len(avar) != 1:
                    raise RuntimeError(
                        'register %s has equal size fields set, field parameters != 1?',
                        self.name)
                avar[:] = num_fields * avar
        elif self.block_info['mode'] == 'fields of arbitrary size':
            if num_fields == 1:
                if (len(field_widths) != 1) or (len(field_types) != 1) or (
                        len(field_bin_pts) != 1):
                    raise RuntimeError(
                        'register %s has equal size fields set, unequal field parameters?',
                        self.name)
            else:
                for avar in [field_widths, field_bin_pts, field_types]:
                    len_avar = len(avar)
                    if len_avar != num_fields:
                        if len_avar == 1:
                            avar[:] = num_fields * avar
                        else:
                            raise RuntimeError(
                                'register %s: number of fields is %s, given %s',
                                self.name, num_fields, len_avar)
        for ctr, name in enumerate(field_names):
            field = bitfield.Field(name, field_types[ctr], field_widths[ctr],
                                   field_bin_pts[ctr], -1)
            self.field_add(field, auto_offset=True)