CM-FX6: Android: Accessing OS interfaces

From Compulab Mediawiki
Revision as of 14:23, 15 June 2015 by Grinberg (talk | contribs) (See also)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Overview

Being Linux under the hood, Android enables access to OS interfaces such as GPIO, serial port, etc. The interfaces may be accessed from the command line, via terminal emulation application, ADB or start-up script, or programmatically from Android application.
It is assumed that each respective interface pin is multiplexed correctly for the required functionality by the kernel code.

Command line access

GPIO

GPIO control workflow is comprised of

  1. exporting GPIO
  2. setting GPIO direction: in/out
  3. reading or setting GPIO value, according to direction

For example controlling GPIO 206 would look the following way:

# cd /sys/class/gpio
# echo 206 > export
# echo in > gpio206/direction
# cat gpio206/value
0
# echo out > gpio206/direction
# echo 1 > gpio206/value
# echo 206 > unexport

UART

UART configuration can be performed with the aid of stty utility.
For example, reception and transmission via CM-FX6 UART2 (SB-FX6 P32A or Utilite P16 back RS232) connected to 115200 baud rate line:

  • Receiver side:
    1. Setup:
      # busybox stty /dev/ttymxc1 115200
    2. Receive:
      # cat /dev/ttymxc1
  • Transmitter side:
    1. Setup:
      # busybox stty /dev/ttymxc1 115200
    2. Receive:
      # echo "some text" > /dev/ttymxc1

CAN bus

CM-FX6 Android release prepacks some useful CAN utilities:

  • candump
  • cansend
  • cangen
  • canplayer
  • cansniffer

Additional tools of can-utils package may be included by adding the required tool name to the device/compulab/andromeda/andromeda.mk make file, and rebuilding the Android package.
To test CAN bus functionality, two SB-FX6 evaluation boards can be connected to the same bus, running the following commands:

  • Device A - receiver
# ip link set can0 type can bitrate 125000 triple-sampling on
# ifconfig can0 up
# candump can0
  • Device B - transmitter
# ip link set can0 type can bitrate 125000 triple-sampling on
# ifconfig can0 up
# cansend can0 5A1#11.22.33.44.55.66.77.88

The receiver device will receive everything being transmitted.


See also