完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
|
|
相关推荐
1个回答
|
|
1、在kernel/drivers目录下新建ioctrl的文件夹
# cd kernel/driver # mkdir ioctrl 在/driver/ioctrl目录下,新建ioctrl.c ,ioctrl.h , Kconfig, Makefile 等4个文件。 2、在Kconfig下添加代码: config IOCTRL tristate "io Control" default y help 系统设置时,在Makefile中改变io状态 下添加代码: obj-$(CONFIG_IOCTRL) += ioctrl.o 在ioctrl.c中添加: /* * Firefly 板 ioctrl 上 pwm 演示的驱动程序。 * * Copyright (C) 2022, 中山天芯智能科技有限公司 * 版权所有 2006 Sam Chan * * 本程序为免费软件;您可以根据自由软件基金会发布 的 GNU 通用公共许可证第 2 版的条款重新分发和/或修改它。*/ /******************************************************* *********************** * 版本控制**版本:v1.0.0_20191022 * 创建者:dulc * 创建日期:2019.10.22 * 更改者:* chang日期:*/ #include #include #include #include #include #include #包括 #include #define IOCTRL_MAJOR 97 struct firefly_ioctrl_info { int gpio_wireless_en; // 3g/4g 功率控制 int gpio_we_value; }; 静态 int firefly_ioctrl_probe(struct platform_device *pdev); // ioctrl 操作 ssize_t ioctrl_read( struct file * file, char * buf, size_t count, loff_t * f_ops ); ssize_t ioctrl_write( struct file * file, const char * buf, size_t count, loff_t *f_ops ); long ioctrl_ioctl( struct file *file, unsigned int cmd, unsigned long arg); int ioctrl_open( struct inode * inode, struct file *file ); int ioctrl_release(struct inode *inode, struct file *file); int ioctrl_led_control(char cmd, char subcmd); /************************************GPIO****************** ************************/ static struct of_device_id firefly_ioctrl_match_table[] = { { .compatible = "firefly,rk3399-gpio1",}, {}, }; 静态结构平台驱动程序 firefly_ioctrl_driver = { .driver = { .name = "firefly-ioctrl", .owner = THIS_MODULE, .of_match_table = firefly_ioctrl_match_table, }, .probe = firefly_ioctrl_probe, }; /************************************GPIO****************** ************************/ // ioctrl 操作设备 static const struct file_operations io_ctrl_ops = { .owner = THIS_MODULE, .open = ioctrl_open, .read = ioctrl_read , .write = ioctrl_write, .unlocked_ioctl = ioctrl_ioctl, .release = ioctrl_release, }; // gpio 设备 结构 firefly_ioctrl_info *ioctrl_device_ctrl = NULL; ssize_t ioctrl_read( struct file * file, char * buf, size_t count, loff_t * f_ops ) { ssize_t size = 0; 返回大小; } ssize_t ioctrl_write(struct file * file, const char * buf, size_t count, loff_t *f_ops ) { ssize_t size = 0; 返回大小; } long ioctrl_ioctl( struct file *file, unsigned int cmd, unsigned long arg) { long ret = 0; 如果 ( cmd == 0 ) { gpio_direction_output(ioctrl_device_ctrl->gpio_wireless_en, false); } else { gpio_direction_output(ioctrl_device_ctrl->gpio_wireless_en, true); } 返回 ret; } int ioctrl_open( struct inode * inode, struct file *file ) { 返回0; } int ioctrl_release(struct inode *inode, struct file *file) { return 0; } 静态 int firefly_ioctrl_probe(struct platform_device *pdev) { int gpio; 枚举 of_gpio_flags 标志; 结构 firefly_ioctrl_info *gpio_info; 结构设备节点 *firefly_ioctrl_node = pdev->dev.of_node; gpio_info = devm_kzalloc(&pdev->dev,sizeof(struct firefly_ioctrl_info *), GFP_KERNEL); if (!gpio_info) { dev_err(&pdev->dev, "devm_kzalloc 失败!n"); 返回-ENOMEM; } // 3g/4g 功率控制 gpio = of_get_named_gpio_flags(firefly_ioctrl_node, "firefly-gpio-wireless", 0, &flag); if (!gpio_is_valid(gpio)) { dev_err(&pdev->dev, "firefly-gpio-wireless: %d is invalidn", gpio); 返回-ENODEV; } if (gpio_request(gpio, "firefly-gpio-wireless")) { dev_err(&pdev->dev, "firefly-gpio-wireless: %d request failed!n", gpio); gpio_free(gpio); 返回-ENODEV; } printk("ioctrl驱动注册成功!n"); gpio_info->gpio_wireless_en = gpio; // gpio_info->gpio_pe_value = (flag == OF_GPIO_ACTIVE_LOW) ? 0:1; gpio_direction_output(gpio_info->gpio_wireless_en, ioctrl_device_ctrl = gpio_info; 返回0; } // 初始化 ioctrl 驱动程序 static int ioctrl_init(void) { int ret = -ENODEV; int ret_val = 0xFFFFFFFF; 结构类 *ioctrl_dev_class; // 注册 GPIO 驱动 platform_driver_register(&firefly_ioctrl_driver); // 注册驱动 ret = register_chrdev( IOCTRL_MAJOR, "ioctrldrive", &io_ctrl_ops ); if ( ret < 0 ) { printk("注册ioctrl驱动错误!n"); 返回 ret; } // 创建类 ioctrl_dev_class = class_create( THIS_MODULE, "ioctrldrive" ); 如果(IS_ERR(ioctrl_dev_class)) { unregister_chrdev(IOCTRL_MAJOR,“capi20”); 返回 PTR_ERR(ioctrl_dev_class); } // 创建节点 device_create(ioctrl_dev_class, NULL, MKDEV(IOCTRL_MAJOR,0),NULL, "ioctrl"); 返回 ret_val; } 模块初始化(ioctrl_init); 静态无效 ioctrl_exit(void) { platform_driver_unregister(&firefly_ioctrl_driver); } module_exit(ioctrl_exit); MODULE_AUTHOR("dulc < service@t-firefly.com >"); MODULE_DESCRIPTION(" MODULE_ALIAS("平台:firefly-ioctrl"); MODULE_LICENSE("GPL"); 在kernel/drivers目录下的Makefile文件下,添加以下代码: obj-$(CONFIG_IOCTRL) += ioctrl/ 在kernel/drivers目录下的Kconfig文件下,以下代码: source "drivers /ioctrl/Kconfig”这段 代码默认就编译到了kernel中,在kernel文件夹下(*),执行指令#make menuconfig 选择Device Drivers,可以编译进去的 (默认为检测状态,是因为看到ioctrl文件夹下的Kconfig配置为tristate "io Control" default y,io Control是,default y是默认开启,关闭用默认名称) 3、编写C语言测试程序。 在your_android_src/external目录下,默认文件夹 # mkdiroctrltest在该文件夹下i 添加两个文件:Androidmk 、ioctrltest.c 在Android.mk文件中: LOCAL_PATH:=$(call my-dir) include $(CLEAR_VARS) LOCAL_SRC_FILES:=octrltest.c LOCAL_MODULE:=ioctrlapp include $(BUILD_EXECUTABLE) 其中LOCAL_SRC_FILES为源文件,LOCAL_MODULE为生成测试程序的代码文件。 在ioctrltest.c中添加 #include #include #include #include #include #define DEVICE_NAME "/dev/ioctrl" int main( int argc, char ** argv ) { int fd; 字符命令,子命令; 诠释我; printf("n -----开启3g电源-----n"); fd = 打开(设备名称,O_RDWR); printf("fd = %d n", fd ); if ( fd == -1 ) { printf("打开设备 %s 错误 n", 设备名称 ); } else { // 开启 3g 电源 ioctl(fd, 1, 0); 在安卓目录下,执行#make ioctrlapp 会在out/target/product/ rk3399_firefly_box /system/bin/启动ioctrlapp 生成相应的ioctrlapp(目录可能不同,根据自己实际情况操作)把ioctrlapp复制到优盘中,rk33999 ,将优盘插件3399,然后在调试模式下,执行如下操作,可以运行程序$su #cp mnt/medea_rw/(upan_name)/ioctrlapp /mnt/ioctrlapp #cd mnt ./ioctrlapp注:在dev下该生成的ioctrl,要获取权限才可打开,临时获取权限,使用以下指令:# chmod 777 /devioctrl永久获取权限,参照以下链接执行激活:https://blog.csdn.net/d4l6c8/article/ details/101345756 4、开启启动该程序ioctrlapp。在device/rockchip/rk3399/device.mk中下面添加语句:PRODUCT_COPY_FILES += out/target/product/rk3399_firefly_aiojd4_mipi_box/system/bin/ioctrlapp:system/bin/ioctrlapp 在/device/rockchip/rk3399/rk3399_firefly_aiojd4_mipi_box目录下的init.rc下添加语句: #dlc add service service_ioctrl /system/bin/ioctrlapp user root group root disabled oneshot on property:sys.boot_completed=1 注意service_ioctrl这个服务名称不能超过16个字节,否则认为该服务有问题,不会启动该服务。 在/device/rockchip/common/sepolicy目录下新增文件service_ioctrl.te,添加如下代码: type service_ioctrl, domain; 类型 service_ioctrl_exec、exec_type、file_type; 许可服务_ioctrl; init_daemon_domain(service_ioctrl) 在/device/rockchip/common/sepolicy目录下新增文件ioctrl_device.te,添加如下代码: type ioctrl_device,file_type,dev_type; 在file_contexts文件中添加如下代码: #service_ioctrl /system/bin/ioctrlapp u:object_r:service_ioctrl_exec:s0 /dev/ioctrl u:object_r:ioctrl_device:s0 到这里基本完成,路径根据自己的工程修改。 |
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
1906 浏览 1 评论
synopsys 的design ware:DW_fpv_div,浮点数除法器,默认32位下,想提升覆盖率(TMAX),如果用功能case去提升覆盖率呢?
2382 浏览 1 评论
RK3588 GStreamer调试四路鱼眼摄像头四宫格显示报错
5175 浏览 1 评论
【飞凌嵌入式OK3576-C开发板体验】RKNN神经网络-YOLO图像识别
254 浏览 0 评论
【飞凌嵌入式OK3576-C开发板体验】SSH远程登录网络配置及CAN通讯
1336 浏览 0 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-22 02:14 , Processed in 0.595296 second(s), Total 70, Slave 53 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号