gpio_request

概述Linux内核驱动之GPIO子系统API接口 在嵌入式Linux开发中,对嵌入式SoC中的GPIO进行控制非常重要,Linux内核中提供了GPIO子系统,驱动开发者在驱动代码中使用GPIO子系统提供的API函数,便可以达到对GPIO控制的效果,例如将IO口的方向设置为输入或输出,当IO口的方向为输入时,可以通过调用API函数获取相应的IO口电平,当IO口设置为输出方向时,可以调用相关的API函数去设置IO口电平,本文将简单描述如何去使用Linux内核中GPIO子系统的API接口。 阅读详情

gpio_request()其原型为 int gpio_request(unsigned gpio, const char *label)先说说其参数,gpio则为你要申请的哪一个管脚,label则是为其取一个名字。

其具体实现如下:

int gpio_request(unsigned gpio, const char *label)
{
 struct gpio_desc *desc;//这个自己看源码
 struct gpio_chip *chip;//这个自己看源码
 int   status = -EINVAL;
 unsigned long  flags;

 spin_lock_irqsave(&gpio_lock, flags);//屏蔽中断

 if (!gpio_is_valid(gpio))//判断是否有效,也就是参数的取值范围判断
  goto done;
 desc = &gpio_desc[gpio];//这个是关键gpio_desc为定义的一个全局的数组变量,这个函数的实值也就是,用gpio_desc里面的一个变量来表示数组中的这个元素

                                              已经被申请了,而这个变量就是下面会看到的desc->flags。
 chip = desc->chip;按理说这个这个全局的gpio_desc如果没有初始化的话,这个chip就为空了,随后就直接返回-EINVAL了。
 if (chip == NULL)如果不为空继续往下走
  goto done;

 if (!try_module_get(chip->owner))
  goto done;

 /* NOTE:  gpio_request() can be called in early boot,
  * before IRQs are enabled, for non-sleeping (SOC) GPIOs.
  */

 if (test_and_set_bit(FLAG_REQUESTED, &desc->flags) == 0) {这里测试并设置flags的第FLAG_REQUESTED位,如果没有被申请就返回该位的原值0,分析到这儿,

                                                                                                                 也差不多满足了我的个人要求。
  desc_set_label(desc, label ? : "?");
  status = 0;
 } else {
  status = -EBUSY;
  module_put(chip->owner);
  goto done;
 }

 if (chip->request) {
  /* chip->request may sleep */
  spin_unlock_irqrestore(&gpio_lock, flags);
  status = chip->request(chip, gpio - chip->base);
  spin_lock_irqsave(&gpio_lock, flags);

  if (status < 0) {
   desc_set_label(desc, NULL);
   module_put(chip->owner);
   clear_bit(FLAG_REQUESTED, &desc->flags);
  }
 }

done:
 if (status)
  pr_debug("gpio_request: gpio-%d (%s) status %d\n",
   gpio, label ? : "?", status);
 spin_unlock_irqrestore(&gpio_lock, flags);
 return status;
}


devm_gpio_request_one申请gpio失败,错误代码 在驱动中调用devm_gpio_request_one()函数失败,返回错误值是-16 如下是错误码对应的描述 EBUSY 16 Device or resource busy 说明这个接口处于繁忙状态,大致推测是在被使用了。 通过搜索设备树,发现这个gpio号确实被另一个驱动调用了,先把他注销掉,释放出来给我试用 下面是linux错误代码含义,方便下次查询 C Name Value Description EPERM 1 Operation not permitted E. 阅读详情

相关推荐

Python量化交易实战:如何用pytdx库快速解析通达信.day文件(附完整代码)

本文详细介绍了如何使用Python的pytdx库高效解析通达信.day本地数据文件,构建免费、稳定的量化交易数据源。文章提供了从环境配置、基础数据读取、复权处理到板块信息获取的完整实战代码,并演示了如何将处理后的数据无缝接入Backtrader等回测框架,为量化策略开发提供可靠的数据基础。

ppp33的博客 1142

【BSP开发学习5】GPIO子系统

gpio_request 函数用于申请一个 GPIO 管脚,在使用一个 GPIO 之前一定要使用 gpio_request。如果不使用某个 GPIO 了,那么就可以调用 gpio_free 函数进行释放。因为权限问题,所以没有办法手动添加设备节点,也没有mdev,udev进行设备节点的管理,可以使用echo 8 > /proc/sys/kernel/printk调整打印等级。此函数用于设置某个 GPIO 的值,此函数是个宏,定义如下。所以需要手动添加设备节点。打印问题,默认打印等级很低。...

yy197696的博客 8924

手把手教你用STM32F103C8T6驱动HUB75 LED点阵屏(附74HC595级联代码)

本文详细介绍了如何使用STM32F103C8T6开发板驱动HUB75接口的LED点阵屏,包括硬件连接、74HC595级联代码、时序控制及灰度显示实现。通过实战案例展示动态文字显示和性能优化技巧,帮助开发者快速掌握LED点阵屏驱动技术。

weixin_42623010的博客 341

gpio_request()

今天再次学习SD卡驱动,遇到gpio_request这个函数,始终不知道其什么意思,看了几遍源代码才有了点感觉。现将其关键部分再此说明一下,以备自己以后复习,或是路客参考。   一般gpio_request封装了mem_request(),起保护作用,最后要调用mem_free之类的。主要是告诉内核这地址被占用了。当其它地方调用同一地址的gpio_request就会报告错误,该地址已被申请。在

wosiwozaiwhy的专栏 4035

基于深度强化学习的无地图移动机器人导航:让机器人在未知环境中智能前行

虽然仍然面临sim-to-real差距、安全性保证等挑战,但随着算法的不断改进和计算能力的提升,基于DRL的无地图导航技术将在服务机器人、工业自动化、太空探索等领域发挥越来越重要的作用,为人类生产和生活带来更大便利和价值。对于复杂环境下的动态目标导航问题,研究人员提出了多智能体协同控制算法(如Teamwork-Net算法),通过多个智能体分别控制机器人的运动速度与运动方向,协同实现更高效、更稳定的导航性能。深度强化学习结合了深度学习的感知能力和强化学习的决策能力,非常适合解决无地图导航问题。

weixin_45131592的博客 901

DPO(Direct Preference Optimization)实战全流程指南

《DPO实战全流程指南》摘要 本文提供了端到端的DPO(直接偏好优化)实战方案,包含数据准备、模型训练、评估部署全流程。核心内容包括: 数据构建:推荐UltraFeedback等高质量数据集,提供数据预处理代码 训练配置:基于HuggingFace TRL库的DPO实现,详解beta值等关键参数调优 工业优化:显存节省技巧(LoRA、梯度检查点)、领域自适应方法和在线学习架构 效果评估:量化对比显示DPO可降低86%有害回复率,提升24%用户满意度 常见问题:针对灾难性遗忘、过度安全化等问题给出解决方案 附

技术引领业务创新 1466

Linux GPIO驱动部分函数

Linux GPIO端口驱动部分函数

weixin_61810331的博客 4478

阿里平头哥与华为芯片的比较

阿里平头哥与华为芯片代表了中国AI芯片领域的两种典型发展路径:平头哥通过兼容CUDA生态快速切入市场,以较低成本提供接近国际水平的AI算力;华为则坚持全栈自研路线,构建从芯片到框架的完整技术体系,更注重供应链安全和自主可控。从短期来看,平头哥PPU在单卡性能参数上全面超越昇腾910B,接近英伟达H20水平,且成本优势明显,有望在云服务和互联网应用领域取得更大市场份额。而华为昇腾则凭借全栈自研和端边云协同优势,在政企市场和科研领域更具竞争力。

shao.bing的专栏 3971

gpio_request()函数

其原型为 int gpio_request(unsigned gpio, const char *label) 先说说其参数,gpio则为你要申请的哪一个管脚,label则是为其取一个名字。其具体实现如下: [cpp] view plaincopyprint? int gpio_request(unsigned gpio, const char *label)     {

lingran07的专栏 7321

桑基图实战指南:Excel/Python/R三工具高效绘制方法

桑基图是一种以线条宽度编码流量大小、以节点位置表达流程阶段、以连接关系呈现数据流向的专项可视化技术,其核心原理在于‘宽即量、位即序、连即逻辑’。它并非装饰性图表,而是面向业务诊断的分析前置工具,尤其适用于预算分配、能源损耗、用户转化等存在明确单向流动与显著数值差异的场景。相比传统柱状图或漏斗图,桑基图能天然暴露系统瓶颈与隐性损耗,大幅提升决策效率。本文聚焦工程落地,覆盖Excel插件快速交付、Python Plotly交互开发、R networkD3生态集成三大主流路径,兼顾数据准备铁律、索引映射规范与中文

cuml0912的博客 486

【75】OpenCV C++实战篇——OpenCV 图像拼接、全景拼接(教程合集)

本文整理了OpenCV实现图像拼接的技术教程合集,涵盖C++和Python两种语言实现方案。图像拼接技术旨在将多张重叠图像融合为无缝全景图,既扩大视角又保持高分辨率。内容包含水平矫正等关键步骤(附对比效果图),提供多个实战案例的完整代码和详细讲解,涉及单应性矩阵、图像变换等核心技术。不同案例展示了从两张到多张图像的拼接效果,适合不同层次的学习者参考实践。

程序员,他们想的是什么?他们想的永远都是技术,他们崇尚的也永远都是技术。 528

devm_gpio_request_one 函数

devm_gpio_request_one 函数

qq_23174771的博客 4482

Oracle EBS Interface/API(49)- AP付款取消API

Oracle EBS AP付款取消API介绍和简单实例

陈显平的专栏-Oracle EBS 849

linux使用gpio开一个线程,LINUX的gpio_request_one作用

一直习惯使用gpio_request来申请一个GPIO,然后用gpio_direction_input、gpio_direction_output等函数来配置对应的GPIO,用gpio_free来释放申请。后来看到别人也会用gpio_request_one来申请和配置一个GPIO,然后就去看看看这个接口的实现,发现这个函数就是对一个GPIO的申请和配置的组合而已。但是看到这个函数最终还会释放GPI...

weixin_36028342的博客 2636

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

gpio被其他模块占用 gpio_request

gpio_request()简单分析 2015年01月28日 10:38:00 阅读数:3950 一、软件环境 Andorid Version:5.0 Cpu &amp; Arch:Intel X86_64   二、File Path include/linux/gpio.h include/asm-generic/gpio.h drivers/gpio/gpiolib.c ...

u010388659的博客 8390

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

gpio_request的使用

1、一般gpio_request封装了mem_request(),起保护作用,最后要调用mem_free之类的。主要是告诉内核这地址被占用了。当其它地方调用同一地址的gpio_request就会报告错误,该地址已被申请。在/proc/mem应该会有地址占用表描述。 这种用法的保护作用前提是大家都遵守先申请再访问,有一个地方没遵守这个规则,这功能就失效了。好比进程互斥,必需大家在访问临界资源的时候

slowpig的专栏 4057

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

gpio_request .

今天再次学习SD卡驱动,遇到pgio_request这个函数,始终不知道其什么意思,看了几遍源代码才有了点感觉。现将其关键部分再此说明一下,以备自己以后复习,或是路客参考。 其原型为 int gpio_request(unsigned gpio, const char *label)先说说其参数,gpio则为你要申请的哪一个管脚,label则是为其取一个名字。 其具体实现如下:

dingkaich的专栏 476

gpio_request 原形代码

其原型为 int gpio_request(unsigned gpio, const char *label) 先说说其参数,gpio则为你要申请的哪一个管脚,label则是为其取一个名字。其具体实现如下: [cpp] view plaincopyprint? int gpio_request(unsigned gpio, const char *label)

maopig的专栏 2万+

gpio_request gpio_direction_output gpio_set_value

遇到pgio_request这个函数,始终不知道其什么意思,看了几遍源代码才有了点感觉。现将其关键部分再此说明一下,以备自己以后复习,或是路客参考。   一般gpio_request封装了mem_request(),起保护作用,最后要调用mem_free之类的。主要是告诉内核这地址被占用了。当其它地方调用同一地址的gpio_request就会报告错误,该地址已被申请。在/proc/mem应该会

wxie的Linux人生 4710

gpio_request函数

gpio_request     一般gpio_request封装了mem_request(),起保护作用,最后要调用mem_free之类的。主要是告诉内核这地址被占用了。当其它地方调用同一地址的gpio_request就会报告错误,该地址已被申请。在/proc/mem应该会有地址占用表描述。 这种用法的保护作用前提是大家都遵守先申请再访问,有一个地方没遵守这个规则,这功能就失效了。

2140
上一篇: grep 搜索目录中的文件
下一篇: Linux内核spin_lock与spin_lock_irq分析
计算机与认知
博客等级 码龄14年 31粉丝 19原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值