android 2.3 GPS 移植实战 二

来源:互联网 发布:照片拼贴软件 java 编辑:程序博客网 时间:2024/05/16 09:36

通过 实战一 的设置GPS的通讯已经通了,问题是 GPS 的电源控制还没有实现。

希望在 android 打开 GPS 的时候才打开电源,关闭 GPS 时关闭电源。

就得增加 GPS 电源控制的节点。

制作 GPS_POWER 节点源文件。

根据 GPIO 实例做 gps_power.c 文件,我的文件内容如下:

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <linux/spinlock.h>
#include <linux/device.h>
#include <linux/err.h>
#include <linux/debugfs.h>
#include <linux/seq_file.h>
#include <linux/gpio.h>
#include <linux/idr.h>
#include <linux/slab.h>
#include <linux/miscdevice.h>


#define DEVICE_NAME "gps_power"




static int gps_power_ioctl(
struct inode *inode, 
struct file *file, 
unsigned int cmd, 
unsigned long arg)
{
return 0;
}


static int gps_power_open(struct inode *inode, struct file *filp)
{
int i;
printk (DEVICE_NAME": open\n");


gpio_set_value(S5PV210_GPJ1(0),1);




return 0;
}


static ssize_t gps_power_read(struct file *filp, char __user *buffer, size_t count, loff_t *ppos)
{
printk (DEVICE_NAME": read\n");
return 0;
}


static int gps_power_release(struct inode *inode, struct file *filp)
{
printk (DEVICE_NAME": release\n");
gpio_set_value(S5PV210_GPJ1(0),0);
return 0;
}




static struct file_operations dev_fops = {
.owner = THIS_MODULE,
.ioctl = gps_power_ioctl,
.open =gps_power_open,
.read =gps_power_read,


.release= gps_power_release,
};


static struct miscdevice misc = {
.minor = MISC_DYNAMIC_MINOR,
.name = DEVICE_NAME,
.fops = &dev_fops,
};




static int __init dev_init(void)
{
int ret;



s3c_gpio_cfgpin(S5PV210_GPJ1(0), S3C_GPIO_SFN(1));
s3c_gpio_setpull(S5PV210_GPJ1(0),S3C_GPIO_PULL_NONE);

gpio_set_value(S5PV210_GPJ1(0),0);
ret = misc_register(&misc);
printk (DEVICE_NAME":init\n");
return ret;
}


static void __exit dev_exit(void)
{
printk (DEVICE_NAME":exit\n");
gpio_set_value(S5PV210_GPJ1(0),0);
misc_deregister(&misc);
}




module_init(dev_init);
module_exit(dev_exit);
MODULE_LICENSE("GPS");
MODULE_AUTHOR("Payen");


修改 makefile 增加 gps_power.c 

这样编译内核后在目标板 dev/ 目录下就有 gps_power 的节点了。

然后修改android HAL 层GPS文件  gps_qemu.c 打开设备。

#define GPS_Power_Ctrl  "/dev/gps_power"

static void gps_state_init( GpsState*  state ) 打开设备

state->fPower = open(GPS_Power_Ctrl, 0 );
    if (state->fPower < 0) {
        D("gps Open power %s fail %d\n",GPS_Power_Ctrl,state->fPower);
 state->init       = 0;
close(state->fd);
state->fd = -1 ;
        return;
    }

static voidgps_state_done( GpsState*  s ) 关闭设备

close( s->fPower ); s->fPower = -1;


到这里发现 打开设备失败,找了 gps_power 节点,发现节点存在啊~!

看看 节点权, 发现是 CRW    ,改权限试试,把权限改成 777

再打开 节点。

这时候GPS电供上了

关闭节点 GPS 电关闭了。

控制部分已经完成了,最后要把这个设置权限放到系统 init.rc 里面

device/samsung/smdkv210/init.rc

增加 

chmod 0777 /dev/gps_power


一切搞定。



原创粉丝点击