示例#1
0
    def test_gpio_freeze(self):
        """Simple test to demonstrate freeze on close.

           For now, it requires a logic analyzer to verify the output,
           this is not automatically validated by SW
        """
        direction = 0xFF & ~((1 << 4) - 1)  # 4 Out, 4 In
        gpio = GpioAsyncController()
        gpio.configure(self.url,
                       direction=direction,
                       frequency=1e3,
                       initial=0x0)
        port = gpio.get_gpio()
        # emit a sequence as a visual marker on b3,b2,b1,b0
        port.write([x << 4 for x in range(16)])
        sleep(0.01)
        # write 0b0110 to the port
        port.write(0x6 << 4)
        sleep(0.001)
        # close w/o freeze: all the outputs should be reset (usually 0b1111)
        # it might need pull up (or pull down) to observe the change as
        # output are not high-Z.
        gpio.close()
        sleep(0.01)
        gpio.configure(self.url,
                       direction=direction,
                       frequency=1e3,
                       initial=0x0)
        port = gpio.get_gpio()
        # emit a sequence as a visual marker with on b3 and b1
        port.write([(x << 4) & 0x90 for x in range(16)])
        sleep(0.01)
        # write 0b0110 to the port
        port.write(0x6 << 4)
        sleep(0.01)
        # close w/ freeze: outputs should not be reset (usually 0b0110)
        gpio.close(True)
示例#2
0
 def test_gpio_values(self):
     """Simple test to demonstrate bit-banging.
     """
     if self.skip_loopback:
         raise SkipTest('Skip loopback test on multiport device')
     direction = 0xFF & ~((1 << 4) - 1)  # 4 Out, 4 In
     gpio = GpioAsyncController()
     gpio.configure(self.url,
                    direction=direction,
                    frequency=1e6,
                    initial=0x0)
     port = gpio.get_gpio()  # useless, for API duck typing
     # legacy API: peek mode, 1 byte
     ingress = port.read()
     self.assertIsInstance(ingress, int)
     # peek mode always gives a single byte output
     ingress = port.read(peek=True)
     self.assertIsInstance(ingress, int)
     # stream mode always gives a bytes buffer
     port.write([0xaa for _ in range(256)])
     ingress = port.read(100, peek=False, noflush=False)
     self.assertIsInstance(ingress, bytes)
     if not VirtLoader:
         # the virtual task may sometimes not be triggered soon enough
         self.assertGreater(len(ingress), 2)
     # direct mode is not available with multi-byte mode
     self.assertRaises(ValueError, port.read, 3, True)
     ingress = port.read(3)
     self.assertIsInstance(ingress, bytes)
     if not VirtLoader:
         # the virtual task may sometimes not be triggered soon enough
         self.assertGreater(len(ingress), 0)
     self.assertLessEqual(len(ingress), 3)
     port.write(0x00)
     port.write(0xFF)
     # only 8 bit values are accepted
     self.assertRaises(ValueError, port.write, 0x100)
     port.write([0x00, 0xFF, 0x00])
     port.write(bytes([0x00, 0xFF, 0x00]))
     # only 8 bit values are accepted
     self.assertRaises(ValueError, port.write, [0x00, 0x100, 0x00])
     # check direction API
     port.set_direction(0xFF, 0xFF & ~direction)
     gpio.close()