Posts /

IIO Dummy Experiment Two: Play with IIO Events

Twitter Facebook Google+
26 Feb 2017

This post represents another part of the series of work related to the iio_dummy module. Before you read this post, I recommend to first read:

  1. The iio_simple_dummy Anatomy
  2. IIO Dummy module Experiment One: Play with iio_dummy
  3. The iio_simple_dummy_event Events Anatomy

In this post, we want to accomplish the following tasks:

  1. Compile the iio_event_monitor.c and others;
  2. Running the iio_event_monitor;
  3. Running and see some events generated by iio_simple_dummy_event.

Finally, for this post, I suppose you already have iio_dummy compiled, loaded, and with a device configured via configfs (again, these subjects were explained in the recommended posts).

Command summary

Compile IIO tools

Linux Kernel has a directory named tools/ which have many different tools (e.g., perf and objtool). The IIO subsystem also has a directory in tools/ that have some useful tools to illustrate the use of IIO in the user space. If you want to compile any program related to iio, you just need to type:

$ make -C tools/iio

Take a look at the directory after the compilation; you should see iio_event_monitor, iio_generic_buffer, and lsiio. See:

$ ls tools/iio/
Build              iio_event_monitor.c     iio_event_monitor.o  iio_generic_buffer.c     iio_generic_buffer.o  iio_utils.h  include  lsiio.c     lsiio.o
iio_event_monitor  iio_event_monitor-in.o  iio_generic_buffer   iio_generic_buffer-in.o  iio_utils.c           iio_utils.o  lsiio    lsiio-in.o  Makefile

The execution of the binary is straightforward, for example, you can try to execute the lsiio tool as follows:

$ ./tools/iio/lsiio 
Device 000: my_glorious_dummy_device

The lsiio tool identifies all the available iio devices in your system. In the case of this tutorial, we just have my_glorious_dummy_device.

Running iio_evet_monitor

The iio_event_monitor is a tool that reads the current buffer setup from sysfs and starts a short capture from the specified device [1]. If you just execute the program, you will get:

$ ./tools/iio/iio_event_monitor 
Usage: ./tools/iio/iio_event_monitor <device_name>

As you can see, the program expects a device name. Use the lsiio to see the device name (in our case it is my_glorious_dummy_device), open another terminal, and type:

$ sudo ./tools/iio/iio_event_monitor my_glorious_dummy_device
Found IIO device with name my_glorious_dummy_device with device number 0

You will notice that the program start, but nothing happens. Do not cancel the execution, just go to the next section.

Generating a series of events

Now that you have iio_event_monitor running, open another terminal and type:

 echo 0 > /sys/bus/iio/devices/iio_evgen poke_ev0
 echo 1 > /sys/bus/iio/devices/iio_evgen poke_ev0
 echo 2 > /sys/bus/iio/devices/iio_evgen poke_ev0
 echo 3 > /sys/bus/iio/devices/iio_evgen poke_ev0
Code 1: Set of commands to activate event

Going back to the terminal with the iio_event_monitor running, you should see an output similar to:

$ sudo ./tools/iio/iio_event_monitor my_glorious_dummy_device
Found IIO device with name my_glorious_dummy_device with device number 0
Event: time: 1520102773326469013, type: voltage, channel: 0, evtype: thresh, direction: rising
Event: time: 1520102776145258970, type: activity(running), channel: 0, evtype: thresh, direction: rising
Event: time: 1520102778636096750, type: activity(walking), channel: 0, evtype: thresh, direction: falling
Event: time: 1520102781584365213, type: steps, channel: 0, evtype: change

Try the echo command from Code 5 with different values; you will notice that nothing happens. The question is: why? If you read the “The iio_simple_dummy_event Events Anatomy” you should remember the handling function explanation. There, we saw a switch case with a range of options from 0 to 3. Each option represents an event, and we are making them execute here.

References

  1. tools/iio/iio_event_monitor.c the source code has many useful comments.
  2. The iio_simple_dummy_event Events Anatomy

Twitter Facebook Google+