Netlink: 内核与用户空间传输数据的socket协议
https://en.wikipedia.org/wiki/Netlink
There is a similar question asked here:
Notify gpio interrupt to user space from a kernel module
Please check above question. However, i can provide my approach which i suggested there as well.
You can send a signal to user space thread from kernel API, which can help u run non-blocking:
send_sig(int sig, struct task_struct *p, int priv);
You need to be aware of pid of user thread in Kernel. You can over come this by writing pid of user process via /proc and then kernel reading the pid. With this arrangement, when there is an interrupt, kernel can send signal to user thread. In case your process restarts or gets killed, you will have to update the pid via proc. Just for status notification you can use this method; however if you like to transfer data along with status than Netlink or char driver mechanism is good way.
https://stackoverflow.com/questions/19257624/interrupt-handling-and-user-space-notification
You don't need fancy kernel to userspace communication. A userspace application has access to GPIOs using Sysfs. Read about it in Documentation/gpio.txt.
First, export a GPIO pin like this (the actual number depends on your setup):
# echo 23 > /sys/class/gpio/export
This will export GPIO pin #23, and thus create /sys/class/gpio/gpio23.
Set its direction:
# echo in > /sys/class/gpio/gpio23/direction
If the hardware GPIO controller supports interrupts generation, the driver should also support it and you will see /sys/class/gpio/gpio23/edge. Write either rising, falling or both to this file to indicate the signal edge(s) that will create a "userspace interrupt". Now, to get interrupted, use the poll(2) system call on /sys/class/gpio/gpio23/value. Then, when the poll call unblocks, read the new value (/sys/class/gpio/gpio23/value), which will be '0' or '1' (ASCII).
ASK:
poll(2) on a custom Sysfs entry for your driver. Otherwise, check out Netlink.Netlink: 内核与用户空间传输数据的socket协议的更多相关文章
- Linux启动时间优化-内核和用户空间启动优化实践
关键词:initcall.bootgraph.py.bootchartd.pybootchart等. 启动时间的优化,分为两大部分,分别是内核部分和用户空间两大部分. 从内核timestamp 0.0 ...
- linux内存(三)内核与用户空间交互
来自网址http://www.kerneltravel.net/jiaoliu/005.htm 用户程序和内核的信息交换是双向的,也就是说既可以主动从用户空间向内核空间发送信息,也可以从内核空间向用户 ...
- Linux内核访问用户空间文件:get_fs()/set_fs()的使用
测试环境:Ubuntu 14.04+Kernel 4.4.0-31 关键词:KERNEL_DS.USER_DS.get_fs().set_fs().addr_limit.access_ok. 参考代码 ...
- 用户空间和内核空间通讯之【Netlink 上】
原文地址:用户空间和内核空间通讯之[Netlink 上] 作者:wjlkoorey258 引言 Alan Cox在内核1.3版本的开发阶段最先引入了Netlink,刚开始时Netlink是以字符驱动接 ...
- linux 内核与用户空间通信之netlink使用方法
转自:http://blog.csdn.net/haomcu/article/details/7371835 Linux中的进程间通信机制源自于Unix平台上的进程通信机制.Unix的两大分支AT&a ...
- linux 内核与用户空间通信机制netlink初探
1.Linux进程概述 Linux中的进程间通信机制源自于Unix平台上的进程通信机制.Unix的两大分支AT&T Unix和BSD Unix在进程通信实现机制上各有所不同,前者形成了运行 ...
- 深入理解linux网络技术内幕读书笔记(三)--用户空间与内核的接口
Table of Contents 1 概论 1.1 procfs (/proc 文件系统) 1.1.1 编程接口 1.2 sysctl (/proc/sys目录) 1.2.1 编程接口 1.3 sy ...
- 深入理解Linux网络技术内幕——用户空间与内核空间交互
概述: 内核空间与用户空间经常需要进行交互.举个例子:当用户空间使用一些配置命令如ifconfig或route时,内核处理程序就要响应这些处理请求. 用户空间与内核有多种交互方式,最常 ...
- linux 用户态和内核态以及进程上下文、中断上下文 内核空间用户空间理解
1.特权级 Intel x86架构的cpu一共有0-4四个特权级,0级最高,3级最低,ARM架构也有不同的特权级,硬件上在执行每条指令时都会对指令所具有的特权级做相应的检查.硬件已经提 ...
随机推荐
- IDEA中提示配置jdk1.8
问题描述:运行Java Web项目时,IDEA中提示:Warning:java: 源值1.5已过时, 将在未来所有发行版中删除 解决方法:1. 打开[File]—[Project Structure] ...
- syncronizationcontext
FormDesign.cs 增加变量定义 public string testName { get; set; } TaskWrapper.cs string tmpTest = &qu ...
- Centos7安装文件传输软件rz sz
一直使用Xshell的xftp传输文件,谁知道忽然无法正常使用. 于是,决定用户rz进行传输 安装步骤也比较简单 1.首先安装第三方源(以下源比默认源包含更多安装包,建议添加该源使用) yum ins ...
- mvn-dependencies-vs-dependencyManagement
dependencyManagement里只是声明依赖,并不实现引入,因此子项目需要显式的声明需要用的依赖. dependencies 相对于dependencyManagement,所有声明在dep ...
- centos7如何将docker容器配置成开机自启动
docker 服务器开机自启动: 1.systemctl is-enabled docker.service 检查服务是否开机启动 2.systemctl enable docker.service ...
- RocketMQ 4.5.1 单机环境搭建以及生产消费测试
为了学习和方便测试,总是要启动一个单机版的.下载 http://rocketmq.apache.org/dowloading/releases/ 1. 要先配置环境变量 ROCKETMQ_HOME E ...
- cas sso docker部署service
cas协议: 1. 拉取镜像 docker pull apereo/cas:${tag} 2. 启动容器 docker run --name cas -p : -p : apereo/cas:v5.3 ...
- Spring-AOP切面编程(3)
https://www.jianshu.com/p/be69b874a2a9 目录 1. Web MVC发展史历程2.Spring概要3.Spring-依赖注入概要(IOC)4.属性注入的三种实现方式 ...
- DbParameter关于Like查询的传参数无效问题
用传参方式模糊查询searchName 按常规的思路,我们会这样写 ,代码如下: String searchName ="Sam"; String strSql = "s ...
- python class 中__next__用法
class A(): def __init__(self,b): self.b=b # def __iter__(self): # 这个函数可以用,表示迭代标志,但也可以省略 # return sel ...