Esempio n. 1
0
    def _cleanup(self):

        while sysfs_interface.get_state() != "idle":
            try:
                sysfs_interface.set_stop()
            except Exception as e:
                print(e)
            try:
                sysfs_interface.wait_for_state("idle", 3.0)
            except SysfsInterfaceException:
                logger.warning("CleanupRoutine - send stop-command and waiting for PRU to go to idle")

        if self.shared_mem is not None:
            self.shared_mem.__exit__()

        if self.rpmsg_fd is not None:
            os.close(self.rpmsg_fd)

        try:
            self.set_ldo_voltage(False)
            self.ldo.__exit__()
        except Exception as e:
            print(e)

        self.set_mppt(False)
        self.set_harvester(False)
        self.set_lvl_conv(False)
        self._adc_set_power(False)
        self._set_power(False)
        logger.debug("Shepherd hardware is powered down")
Esempio n. 2
0
    def wait_for_start(timeout: float) -> NoReturn:
        """Waits until shepherd has started sampling.

        Args:
            timeout (float): Time to wait in seconds
        """
        sysfs_interface.wait_for_state("running", timeout)
Esempio n. 3
0
    def __enter__(self):
        try:

            for name, pin in gpio_pin_nums.items():
                self.gpios[name] = GPIO(pin, "out")

            self._set_shepherd_pcb_power(True)
            self.set_target_io_level_conv(False)

            logger.debug("Shepherd hardware is powered up")

            # If shepherd hasn't been terminated properly
            if sysfs_interface.get_state() != "idle":
                sysfs_interface.set_stop()

            sysfs_interface.wait_for_state("idle", 5)
            logger.debug(f"Switching to '{ self.mode }'-mode")
            sysfs_interface.write_mode(self.mode)

            # clean up msg-channel provided by kernel module
            self._flush_msgs()

            # Ask PRU for base address of shared mem (reserved with remoteproc)
            mem_address = sysfs_interface.get_mem_address()
            # Ask PRU for size of shared memory (reserved with remoteproc)
            mem_size = sysfs_interface.get_mem_size()

            logger.debug(
                f"Shared memory address: \t0x{mem_address:08X}, size: {mem_size} byte"
            )

            # Ask PRU for size of individual buffers
            samples_per_buffer = sysfs_interface.get_samples_per_buffer()
            logger.debug(f"Samples per buffer: \t{ samples_per_buffer }")

            self.n_buffers = sysfs_interface.get_n_buffers()
            logger.debug(f"Number of buffers: \t{ self.n_buffers }")

            self.buffer_period_ns = sysfs_interface.get_buffer_period_ns()
            logger.debug(f"Buffer period: \t\t{ self.buffer_period_ns } ns")

            self.shared_mem = SharedMem(
                mem_address, mem_size, self.n_buffers, samples_per_buffer
            )

            self.shared_mem.__enter__()

        except Exception:
            self._cleanup()
            raise

        sysfs_interface.wait_for_state("idle", 3)
        return self
Esempio n. 4
0
    def _cleanup(self):
        logger.debug("ShepherdIO is commanded to power down / cleanup")
        while sysfs_interface.get_state() != "idle":
            try:
                sysfs_interface.set_stop()
            except Exception as e:
                print(e)
            try:
               sysfs_interface.wait_for_state("idle", 3.0)
            except SysfsInterfaceException:
                logger.warning("CleanupRoutine - send stop-command and waiting for PRU to go to idle")
        self.set_aux_target_voltage(None, 0.0)

        if self.shared_mem is not None:
            self.shared_mem.__exit__()

        self.set_target_io_level_conv(False)
        self._set_shepherd_pcb_power(False)
        logger.debug("Shepherd hardware is now powered down")
Esempio n. 5
0
def test_start_delayed(shepherd_up):
    start_time = time.time() + 5
    sysfs_interface.start(start_time)

    sysfs_interface.wait_for_state("armed", 1)
    with pytest.raises(sysfs_interface.SysfsInterfaceException):
        sysfs_interface.wait_for_state("running", 3)

    sysfs_interface.wait_for_state("running", 3)

    with pytest.raises(sysfs_interface.SysfsInterfaceException):
        sysfs_interface.start()
Esempio n. 6
0
def shepherd_running(shepherd_up):
    sysfs_interface.start()
    sysfs_interface.wait_for_state("running", 5)
Esempio n. 7
0
def test_wait_for_state(shepherd_up):
    sysfs_interface.start()
    assert sysfs_interface.wait_for_state("running", 3) < 3
    sysfs_interface.stop()
    assert sysfs_interface.wait_for_state("idle", 3) < 3
Esempio n. 8
0
    def __enter__(self):
        try:

            for name, pin in gpio_pin_nums.items():
                self.gpios[name] = GPIO(pin, "out")

            self._set_power(True)
            self.set_mppt(False)
            self.set_harvester(False)
            self.set_lvl_conv(False)

            self._adc_set_power(True)

            logger.debug("Shepherd hardware is powered up")

            # If shepherd hasn't been terminated properly
            if sysfs_interface.get_state() != "idle":
                sysfs_interface.set_stop()

            sysfs_interface.wait_for_state("idle", 5)
            logger.debug(f"Switching to '{ self.mode }' mode")
            sysfs_interface.set_mode(self.mode)

            # Open the RPMSG channel provided by rpmsg_pru kernel module
            rpmsg_dev = Path("/dev/rpmsg_pru0")
            self.rpmsg_fd = os.open(str(rpmsg_dev), os.O_RDWR | os.O_SYNC)
            os.set_blocking(self.rpmsg_fd, False)
            self._flush_msgs()

            # Ask PRU for base address of shared mem (reserved with remoteproc)
            mem_address = sysfs_interface.get_mem_address()
            # Ask PRU for size of shared memory (reserved with remoteproc)
            mem_size = sysfs_interface.get_mem_size()

            logger.debug(
                f"Shared memory address: \t0x{mem_address:08X}, size: {mem_size} byte"
            )

            # Ask PRU for size of individual buffers
            samples_per_buffer = sysfs_interface.get_samples_per_buffer()
            logger.debug(f"Samples per buffer: \t{ samples_per_buffer }")

            self.n_buffers = sysfs_interface.get_n_buffers()
            logger.debug(f"Number of buffers: \t{ self.n_buffers }")

            self.buffer_period_ns = sysfs_interface.get_buffer_period_ns()
            logger.debug(f"Buffer period: \t\t{ self.buffer_period_ns } ns")

            self.shared_mem = SharedMem(
                mem_address, mem_size, self.n_buffers, samples_per_buffer
            )

            self.shared_mem.__enter__()

            logger.debug(f"Setting load to '{ self.load }'")
            self.set_load(self.load)

            self.ldo.__enter__()
            self.set_ldo_voltage(False)

        except Exception:
            self._cleanup()
            raise

        sysfs_interface.wait_for_state("idle", 3)
        return self