TI平台使用SIRF GPS
1.底层驱动的实现
GPS厂商提供的库通过echo sysfs的方式控制gps的onoff和reset,这需要linux实现GPS的sysfs模型驱动,在driver文件夹中增加gps.c文件
(1)填充一个bin_attribute的结构体,驱动加载后就会在系统的/sys/module目录下创建sirf文件
- static struct bin_attribute sirf_mode_attr = {
- .attr = {
- .name = "sirf",
- .owner = THIS_MODULE,
- .mode = S_IRUGO | S_IWUGO,
- },
- .size = 0,
- .read = readcmd,
- .write = writecmd,
- };
(2)probe函数
- static int __init gps_probe(struct platform_device *pdev)
- {
- int ret;
- ret = sysfs_create_bin_file(&(module_kset->kobj), &sirf_mode_attr);
- if (ret) {
- printk(KERN_ERR " Failed to create sys file\n");
- return -ENOMEM;
- }
- return 0;
- }
(3)remove函数
- static int __init gps_remove(struct platform_device *pdev)
- {
- sysfs_remove_bin_file(&(module_kset->kobj), &sirf_mode_attr);
- return 0;
- }
(4)平台驱动的注册
- static struct platform_driver gps_driver = {
- .probe = gps_probe,
- .remove = gps_remove,
- .driver = {
- .name = "gps",
- },
- };
- static int __init gps_init(void)
- {
- return platform_driver_register(&gps_driver);
- }
- static void __exit gps_exit(void)
- {
- platform_driver_unregister(&gps_driver);
- }
- late_initcall(gps_init);
- module_exit(gps_exit);
(5)write和read函数(read暂时为空,没有用到)
- static ssize_t readcmd(struct kobject *kobj,
- struct bin_attribute *attr,
- char *buf, loff_t off, size_t count)
- {
- }
- static ssize_t writecmd(struct kobject *kobj,
- struct bin_attribute *attr,
- char *buf, loff_t off, size_t count)
- {
- char *tail;
- int op;
- op = simple_strtol(buf, &tail, 10);
- switch(op) {
- case 1:
- case 2:
- break;
- case 3:
- printk(KERN_BUG " Chip running...\n");
- set_power_on();
- run_mode = RUN_MODE;
- break;
- case 4:
- printk(KERN_BUG " Chip stopped...\n");
- set_power_off();
- run_mode = STOP_MODE;
- break;
- case 5:
- printk(KERN_BUG " Chip reset on high...\n");
- set_reset(1);
- break;
- case 6:
- printk(KERN_BUG " Chip reset on low...\n");
- set_reset(0);
- break;
- default:
- printk(KERN_BUG " Unknown operation %d\n", op);
- break;
- }
- return count;
- }
现在通过echo number > /sys/module/sirf就能控制GPS的power on/off和reset。
阅读(3546) | 评论(0) | 转发(0) |