To be submitted by 25th April 2014
This assignment is about writing a simple device driver for the goldfish platform.
Goldfish is the platform used by the Android emulator and is a simple ARM based device. The paper website has a modified version of the emulator executable (for linux x86) which includes some extra hardware for three sensors, an accelerometer, a compass and a gyroscope. The hardware is memory mapped with 10 registers and one interrupt. The registers and their offsets are as follows:
INT_ENABLE: Offset 0x0
A write to this register enables interrupts for each of the sensors:
Bit 0 controls the accelerometer.
Bit 1 controls the compass.
Bit 2 controls the gyroscope.
A read from this register shows which sensor caused an interrupt and also acknowledges the interrupt.
ACCEL_X: Offset 0x04
ACCEL_Y: Offset 0x08
ACCEL_Z: Offset 0x0c
These registers return the X,Y and Z values for the accelerometer.
COMPASS_X: Offset 0x10
COMPASS_Y: Offset 0x14
COMPASS_Z: Offset 0x18
These registers return the X,Y and Z values for the compass.
GYRO_X: Offset 0x1c
GYRO_Y: Offset 0x20
GYRO_Z: Offset 0x24
These registers return the X,Y and Z values for the gyroscope.
You need to write a linux kernel driver for this hardware on the goldfish platform.
You will need a linux machine to compile the kernel and run the emulator. 64 bit Ubuntu (or Kubuntu) version 12.04 should work, run it in a virtual machine if you have to.
First you must decide on a userspace interface to your driver using a /dev entry or entries with ioctls and/or reads and writes to access the sensors. Document this interface in your driver source code.
Use git to clone the kernel at http://android.googlesource.com/kernel/goldfish and checkout branch android-goldfish-3.4
Add a new driver for the sensors to arch/arm/mach-goldfish and add your driver name to the Makefile. Your driver must be called “goldfish_sensor” for the goldfish bus driver to find it.
To test your driver, use printk in the device driver. You can control the emulated hardware from the console reached using "telnet localhost 5554" For example, "sensor accel 10 20 30" will update the accelerometer values and cause a sensor interrupt.
You do not need to write a userspace library for the sensors but if you use ioctls you may want to write a simple test program.
Your driver must be a single file (no header file) and you should submit your driver source code electronically from the paper web page. Marks will be awarded for well written drivers with a good userspace interface. This is an individual assignment, obviously plagiarised submissions will be awarded zero marks.