Hardware platform: TI am335x Starter Kit
Development Source: Ti-android-ics-4.0.3-devkit-evm-sk-3.0.1.bin
Host system: Ubuntu 10.04
This write "Android from hardware to Application" is to try to start from the bottom of the simplest GPIO hardware driver, step-by-step upward, through the hardware abstraction Layer HAL, Jni method, etc., finally write out the app, to achieve the purpose of hardware calls, The period will add some Android under the C program to test the underlying driver details. Since it is a zero-write driver, it is necessary to break away from some of the API functions already in the source package, starting with the hardware circuit. Find the EVM board GPIO schematic:
I want to control the status of LED D1, as shown, D1 connected to the Q4, that is, Bss138,n channel MOS device, am335x_gpio_led4 for high power, Q4 Gate drain pole conduction, D1 for bright, conversely, off. First set the Gpio clock:
First, Cm_per_gpio1_clkctrl: Address 0x44e000ac The value to be loaded is 0x00040002
Then set the GPIO1 output to enable:
Second, Gpio_oe: Address 0x4804c134 The value to be loaded is 0x0
Then set the output GPIO1:
Gpio_dataout: Address 0x4804c13c to load a value of 0x00000010 or 0x00000000, so that the am335x_gpio_led4 pin is high or low, so D1 can be lit off
Write driver android_gpio.c: Move to the Drivers/char directory
#include <linux/module.h> #include <linux/kernel.h> #include <linux/fs.h> #include <linux/ uaccess.h>/* copy_to_user,copy_from_user * * #include <linux/miscdevice.h> #include <linux/device.h> #i Nclude <asm/io.h> static struct class *gpio_class; volatile unsigned long *dir; volatile unsigned long *dat; volatile unsigned long *clk; int Gpio_open (struct inode *inode,struct file *filp) {*clk = 0x00040002;//enable *dir = (*dir) &0xffffffe F Output return 0; } ssize_t gpio_read (struct file *filp, char __user *buf, size_t count,loff_t *f_pos) {return 0; } ssize_t gpio_write (struct file *filp, const char __user *buf, size_t count,loff_t *f_pos) {char val_buf[2]; int ret; ret = Copy_from_user (val_buf,buf,count); Switch (val_buf[0]) {case 0X31: *dat = (*dat) |0x00000010; Break Case 0x30: *dat = (*dat) &amP;0XFFFFFFEF; Break Default:break; } return count; } struct File_operations gpio_fops = {. Owner = This_module,. Open = Gpio_open,. Read = Gpio_re AD,. Write = Gpio_write,}; int major; int Gpio_init (void) {major = Register_chrdev (0, "Android_gpio", &gpio_fops); Gpio_class = Class_create (This_module, "Android_gpio"); Device_create (Gpio_class,null,mkdev (major,0), NULL, "Adrio"); DIR = (volatile unsigned long *) Ioremap (0x4804c134,4); DAT = (volatile unsigned long *) Ioremap (0x4804c13c,4); CLK = (volatile unsigned long *) Ioremap (0x44e000ac,4); PRINTK ("Gpio is ready\n"); return 0; } void Gpio_exit (void) {Unregister_chrdev (Major, "Android_gpio"); Device_destroy (Gpio_class,mkdev (major,0)); Class_destroy (Gpio_class); Iounmap (DIR); Iounmap (DAT); Iounmap (CLK); PRINTK ("module exit\n"); return; } MODule_license ("GPL"); Module_init (Gpio_init); Module_exit (Gpio_exit);Open the makefile in the Drivers/char directory, adding:
obj-$ (config_android_gpio) + = ANDROID_GPIO.O
Open the Kconfig in the Drivers/char directory, adding:
Config Android_gpio tristate "ANDROID GPIO enable" default Y
Under Source directory execution:
Make Arch=arm Cross_compile=arm-eabi-uimage
Build Uimage, restart the new system, Ls/dev view the device:
# Ls/dev adrio alarm android_adb ashmem Binder Block
Discover the Adrio device, the first step is done, note that when you operate the physical address, you must operate on the bit, otherwise
The GPIO1 will affect the LCD display of the am335x Starter Kit, and the next step is to execute the C program to test the driver.
Android from hardware to application: Step by Step 1--write the underlying hardware driver from scratch