示例#1
0
class MIXBMUWidthSwitcherSGR(object):
    '''
    MIXBMUWidthSwitcherSGR function class to measure the time difference between edge signals

    ClassType = MIXBMUWidthSwitcherSGR

    Args:
        axi4_bus: instance(AXI4LiteBus)/string,   Class instance or dev path of AXI4 bus.

    Examples:
        width_measure = MIXBMUWidthSwitcherSGR('/dev/MIX_Signal_Meter_0')

    '''

    rpc_public_api = ['start_measure', 'stop_measure', 'open', 'close']

    def __init__(self, axi4_bus):
        if isinstance(axi4_bus, basestring):
            # device path; create axi4lite instance
            self.axi4_bus = AXI4LiteBus(axi4_bus,
                                        MIXBMUWidthSwitcherSGRDef.REG_SIZE)
        else:
            self.axi4_bus = axi4_bus

        axi4_gpio = AXI4LiteSubBus(
            self.axi4_bus, MIXBMUWidthSwitcherSGRDef.MIX_GPIO_IPCORE_ADDR,
            MIXBMUWidthSwitcherSGRDef.GPIO_REG_SIZE)
        axi4_widthmeasure = AXI4LiteSubBus(
            self.axi4_bus, MIXBMUWidthSwitcherSGRDef.MIX_WM_IPCORE_ADDR,
            MIXBMUWidthSwitcherSGRDef.WM_REG_SIZE)

        self.gpio = MIXGPIOSG(axi4_gpio)
        self.widthmeasure = MIXWidthMeasureSG(axi4_widthmeasure)
        self.gpio.set_pin_dir(MIXBMUWidthSwitcherSGRDef.CHANNEL_SELECT_BIT0,
                              'output')
        self.gpio.set_pin_dir(MIXBMUWidthSwitcherSGRDef.CHANNEL_SELECT_BIT1,
                              'output')
        self.gpio.set_pin_dir(MIXBMUWidthSwitcherSGRDef.CHANNEL_SELECT_BIT2,
                              'output')

    def close(self):
        self.gpio.set_pin(MIXBMUWidthSwitcherSGRDef.CHANNEL_SELECT_BIT0, 0)
        self.gpio.set_pin(MIXBMUWidthSwitcherSGRDef.CHANNEL_SELECT_BIT1, 0)
        self.gpio.set_pin(MIXBMUWidthSwitcherSGRDef.CHANNEL_SELECT_BIT2, 0)
        self.widthmeasure.stop_measure()

    def open(self):
        self.gpio.set_pin(MIXBMUWidthSwitcherSGRDef.CHANNEL_SELECT_BIT0, 0)
        self.gpio.set_pin(MIXBMUWidthSwitcherSGRDef.CHANNEL_SELECT_BIT1, 0)
        self.gpio.set_pin(MIXBMUWidthSwitcherSGRDef.CHANNEL_SELECT_BIT2, 0)

    def start_measure(self, channel_select, start_status, stop_status):
        '''
        MIXBMUWidthSwitcherSGR module enable the corresponding register, then can get result

        Args:
            channel_select: int,  select the channel to measure.
            start_status:   int,  start trigger signal, details in class TriggarSignalDef.
            stop_status:    int,  stop trigger signal, details in class TriggarSignalDef.

        Returns:
            "done"

        '''
        assert isinstance(channel_select, int)

        a = bin(channel_select)
        a = a[2:]
        a = list(a)
        a.reverse()
        if 3 - len(a) == 0:
            a = a
        else:
            for i in range(3 - len(a)):
                a.append('0')
        a.reverse()
        self.gpio.set_pin(MIXBMUWidthSwitcherSGRDef.CHANNEL_SELECT_BIT0,
                          int(a[2]))
        self.gpio.set_pin(MIXBMUWidthSwitcherSGRDef.CHANNEL_SELECT_BIT1,
                          int(a[1]))
        self.gpio.set_pin(MIXBMUWidthSwitcherSGRDef.CHANNEL_SELECT_BIT2,
                          int(a[0]))

        self.widthmeasure.config(start_triggar_signal=start_status,
                                 stop_triggar_signal=stop_status)
        self.widthmeasure.start_measure()
        return "done"

    def stop_measure(self, time_out):
        '''
        MIXWidthMeasureSG module disable the corresponding register, and then get time measure result.

        Args:
            time_out: int,  overtime of measure, unit:ms.

        Returns:
            list,  list of width values.

        '''
        self.time_out = time_out * 1000

        start_time = time.time() * 1000
        while 1:
            try:
                wid = self.widthmeasure.get_width()
                result = []
                for i in range(len(wid)):
                    result.append(wid[i].width)
                return result
            except Exception as e:
                if time.time() * 1000 - start_time > self.time_out:
                    raise MIXBMUWidthSwitcherSGRException("Timeout: {}".format(
                        e.message))
            finally:
                self.widthmeasure.stop_measure()
示例#2
0
class MIXBMUPWMSGR(object):
    '''
    Mix BMU PWM function class

    ClassType = MIXBMUPWMSGR

    Args:
        axi4_bus:    instance(AXI4LiteBus)/string, AXI4LiteBus class intance or device path.

    Examples:
        bmu_pwm = MIXBMUPWMSGR('/dev/MIX_SignalSource_SG')

    '''

    rpc_public_api = ['signal_output', 'open', 'close']

    def __init__(self, axi4_bus):
        if isinstance(axi4_bus, basestring):
            # device path; create axi4lite instance
            self.axi4_bus = AXI4LiteBus(axi4_bus, MIXBMUPWMSGRDef.REG_SIZE)
        else:
            self.axi4_bus = axi4_bus

        axi4_gpio = AXI4LiteSubBus(self.axi4_bus,
                                   MIXBMUPWMSGRDef.MIX_GPIO_IPCORE_ADDR,
                                   MIXBMUPWMSGRDef.GPIO_REG_SIZE)
        axi4_signalsource = AXI4LiteSubBus(self.axi4_bus,
                                           MIXBMUPWMSGRDef.MIX_SS_IPCORE_ADDR,
                                           MIXBMUPWMSGRDef.SS_REG_SIZE)

        self.gpio = MIXGPIOSG(axi4_gpio)
        self.signalsource = MIXSignalSourceSG(axi4_signalsource)
        self.gpio.set_pin_dir(MIXBMUPWMSGRDef.CHANNEL_SELECT_BIT0, 'output')
        self.gpio.set_pin_dir(MIXBMUPWMSGRDef.CHANNEL_SELECT_BIT1, 'output')

    def close(self):
        '''
        Disable mix BMU PWM function class

        Examples:
            bmu_pwm.close()

        '''
        self.signalsource.close()
        self.gpio.set_pin(MIXBMUPWMSGRDef.CHANNEL_SELECT_BIT0, 0)
        self.gpio.set_pin(MIXBMUPWMSGRDef.CHANNEL_SELECT_BIT1, 0)

    def open(self):
        '''
        Enable mix BMU PWM function class

        Examples:
            bmu_pwm.open()

        '''
        self.signalsource.open()
        self.gpio.set_pin(MIXBMUPWMSGRDef.CHANNEL_SELECT_BIT0, 0)
        self.gpio.set_pin(MIXBMUPWMSGRDef.CHANNEL_SELECT_BIT1, 0)

    def signal_output(self,
                      signal_frequency,
                      square_duty,
                      signal_time=0xffffffff):
        '''
        Set mix BMU PWM parameters and output.

        Args:
            signal_frequency:   int, unit Hz,              output signal frequency.
            square_duty:        float, [0.001~0.999],      duty of square.
            signal_time:        int, unit us, signal time of signal source.

        Return:
            "done"

        '''
        assert 1 >= square_duty >= 0
        self.signal_time = signal_time
        self.signal_frequency = signal_frequency
        self.square_duty = square_duty

        if square_duty == MIXBMUPWMSGRDef.PWM_OUTPUT_LOW:
            self.gpio.set_pin(MIXBMUPWMSGRDef.CHANNEL_SELECT_BIT0, 0)
            self.gpio.set_pin(MIXBMUPWMSGRDef.CHANNEL_SELECT_BIT1, 0)
        elif square_duty == MIXBMUPWMSGRDef.PWM_OUTPUT_HIGH:
            self.gpio.set_pin(MIXBMUPWMSGRDef.CHANNEL_SELECT_BIT0, 0)
            self.gpio.set_pin(MIXBMUPWMSGRDef.CHANNEL_SELECT_BIT1, 1)
        else:
            self.gpio.set_pin(MIXBMUPWMSGRDef.CHANNEL_SELECT_BIT0, 1)
            self.signalsource.set_signal_type('square')
            self.signalsource.set_signal_time(self.signal_time)
            self.signalsource.set_swg_paramter(
                sample_rate=125000000,
                signal_frequency=self.signal_frequency,
                vpp_scale=0.5,
                square_duty=self.square_duty)
            self.signalsource.output_signal()
        return "done"