ZIPLinux异步通知机制-系统掉电保存文件 1.9KB

weixin_43956937需要积分:5(1积分=1元)

资源文件列表:

poweroffSave.zip 大约有2个文件
  1. poweroffSave.c 1.12KB
  2. poweroffSave_drv.c 2.49KB

资源介绍:

掉电保存驱动与应用
#include <linux/module.h> #include <linux/slab.h> #include <linux/interrupt.h> #include <linux/of_device.h> #include <linux/of.h> #include <linux/of_gpio.h> #include <linux/delay.h> #include <linux/miscdevice.h> #include <linux/fs.h> #define DEVICE_NAME "poweroffSave" static struct fasync_struct *async; /*poweroffSave struct save dts device node and irq num/line*/ struct poweroffSave { const struct device_node *devNode; int irq; }; struct poweroffSave poweroff; /*irq fun: * irq run , driver send async siganl to app * */ static irqreturn_t powerOff_irq(int irq, void *devid) { /*SIGIO:signal POLL_IN:only read*/ kill_fasync(&async,SIGIO,POLL_IN); return (IRQ_HANDLED); } static int poweroff_fasync (int fd, struct file *filp,int mode) { /*init fasync_struct*/ return fasync_helper(fd,filp,mode,&async); } /*sys call function:fasync*/ static struct file_operations poweroff_ops = { .owner = THIS_MODULE, .fasync = poweroff_fasync, }; static struct miscdevice poweroff_ops_dev = { .minor = MISC_DYNAMIC_MINOR, .name = DEVICE_NAME, .fops = &poweroff_ops, }; static int poweroffSave_probe(struct platform_device *device) { int ret; poweroff.devNode = of_find_node_by_path("/poweroffSave"); if(poweroff.devNode == NULL) { printk("poweroffSave node find fail\r\n"); return -1; } of_property_read_u32_array(poweroff.devNode,"irq",&poweroff.irq,1); /*request irq:ensure dts to irq line、irq mode*/ ret = request_irq(poweroff.irq,powerOff_irq,IRQ_TYPE_EDGE_FALLING,"poweroffIRQ",&poweroff); if(ret < 0) { printk("Failed to request irq %d\r\n",poweroff.irq); return ret; } /*register misc devcie*/ ret = misc_register(&poweroff_ops_dev); if(ret < 0) { printk("regitser misc_device error\r\n"); return -1; } return 0; } static int poweroffSave_remove(struct platform_device *device) { misc_deregister(&poweroff_ops_dev); free_irq(poweroff.irq,&poweroff); return 0; } static struct of_device_id poweroffSave_id[] = { {.compatible = "poweroffSave"}, {} }; static struct platform_driver powerOffSave_driver = { .probe = poweroffSave_probe, .remove = poweroffSave_remove, .driver ={ .owner = THIS_MODULE, .name = "poweroffSave", .of_match_table = poweroffSave_id, }, }; static int __init poweroffsave_init(void) { int err; err = platform_driver_register(&powerOffSave_driver); return 0; } static void __exit poweroffsave_exit(void) { platform_driver_unregister(&powerOffSave_driver); } module_init(poweroffsave_init); module_exit(poweroffsave_exit); MODULE_LICENSE("GPL");
100+评论
captcha
    类型标题大小时间
    ZIP嵌入式单片机开发 STM32HAL库 NRF24L01模块收发数据4.63KB5月前
    ZIP根据表格内容来重命名表格文件名V1.0.0.zip7.77MB5月前
    ZIPPython实现给文件批量添加前缀.zip14.88KB5月前
    ZIPQt QChart+Eigen库 绘制线性回归图表,源代码和库都在压缩包里1.23MB5月前
    ZIPagv daochu1118.zip1018.7KB5月前
    ZIPSM2258XT三星SSV4量产TOOL4.81MB5月前
    ZIP02_源码资料.zip28.88MB5月前
    ZIPinputCircle.zip442B5月前