Samsung_tiny4412(驱动笔记04)----volatile,container_of,file_operations,file,inode

发布者:BlissfulWhisper最新更新时间:2025-01-15 来源: cnblogs关键字:Samsung  tiny4412 手机看文章 扫描二维码
随时随地手机看文章

/***********************************************************************************

 *                    

 *                volatile,container_of,file_operations,file,inode

 *

 *  声明:

 *      1. 本系列文档是在vim下编辑,请尽量是用vim来阅读,在其它编辑器下可能会

 *         不对齐,从而影响阅读.

 *      2. 本文的结构体的注释主要是参考网络上的解释,几乎无任何个人理解,主要是为后续

 *         代码编辑提供参考.


 **********************************************************************************/


                        \\\\\\\--*目录*--//////////////

                        |  一. volatile修饰字段:             

                        |  二. container_of:                 

                        |  三. 驱动错误返回值:               

                        |  四. struct file_operations注释:   

                        |  五. struct file注释:              

                        |  六. struct inode注释:             

                        \\\\\\\\\///////////////////


一. volatile修饰字段:

    告诉gcc不要对该类型的数据做优化处理,对它的访问都是对内存的访问,而不是对寄存器的访问.


二. container_of:

    1. container_of定义:

        #define __offset(type, mem)

            ((unsigned long)&(((type *)0)->mem))

        #define container_of(addr, type, mem)   

            ((type *)((void *)addr - __offset(type, mem)))

    2. container_of使用:

        static int test_open(struct inode *inode, struct file *file)

        {

            test_t *p;

            p = container_of(file->f_op, test_t, fops);

            file->private_data = p;


            return 0;

        }


三. 驱动错误返回值:

    #ifnder _ASM_GENERIC_ERRNO_BASE_H

        #define _ASM_GENERIC_ERRNO_BASE_H

        

        #define EPERM       1   /* Operation not permitted      --> 操作不允许                  */

        #define ENOENT      2   /* No such file or directory    --> 找不到对应文件或文件夹      */

        #define ESRCH       3   /* No such process              --> 找不到对应的进程            */

        #define EINTR       4   /* Interrupted system call      --> 被系统调用中断              */

        #define EIO         5   /* I/O error                    --> IO错误                      */

        #define ENXIO       6   /* No such device or address    --> 找不到对应的设备或者地址    */

        #define E2BIG       7   /* Argument list too long       --> 参数列表太长                */

        #define ENOEXEC     8   /* Exec format error            --> 执行格式错误                */

        #define EBADF       9   /* Bad file number              --> 错误的文件数                */

        #define ECHILD      10  /* No child processes           --> 没有子进程                  */

        #define EAGAIN      11  /* Try again                    --> 重新调用该函数调用          */

        #define ENOMEM      12  /* Out of memory                --> 内存溢出                    */

        #define EACCES      13  /* Permission denied            --> 权限被拒绝                  */

        #define EFAULT      14  /* Bad address                  --> 错误地址                    */

        #define ENOTBLK     15  /* Block device required        --> 需要块设备                  */

        #define EBUSY       16  /* Device or resource busy      --> 设备或者资源正在被使用      */

        #define EEXIST      17  /* File exists                  --> 文件已经存在                */

        #define EXDEV       18  /* Cross-device link            --> 交叉设备链接                */

        #define ENODEV      19  /* No such device               --> 找不到设备                  */

        #define ENOTDIR     20  /* Not a directory              --> 不是一个目录                */

        #define EISDIR      21  /* Is a directory               --> 是一个目录                  */

        #define EINVAL      22  /* Invalid argument             --> 非法的参数                  */

        #define ENFILE      23  /* File table overflow          --> 文件表溢出                  */

        #define EMFILE      24  /* Too many open files          --> 打开太多的文件              */

        #define ENOTTY      25  /* Not a typewriter             --> 不是设备命令                */

        #define ETXTBSY     26  /* Text file busy               --> 文本文件忙                  */

        #define EFBIG       27  /* File too large               --> 文件太大                    */

        #define ENOSPC      28  /* No space left on device      --> 设备空间不足                */

        #define ESPIPE      29  /* Illegal seek                 --> 非法的偏移                  */

        #define EROFS       30  /* Read-only file system        --> 只读文件系统                */

        #define EMLINK      31  /* Too many links               --> 链接太多                    */

        #define EPIPE       32  /* Broken pipe                  --> 损坏的管道                  */

        #define EDOM        33  /* Math argument out of domain of func  --> 数字参数超出函数域  */

        #define ERANGE      34  /* Math result not representable        --> 数字结果不能表示    */

    #endif


四. struct file_operations注释:

    struct file_operations {

        /* 指向拥有这个结构模块的指针,当模块被使用时,阻止模块被卸载,它被简单初始化为THIS_MODULE */

        struct module *owner;

[1] [2] [3]
关键字:Samsung  tiny4412 引用地址:Samsung_tiny4412(驱动笔记04)----volatile,container_of,file_operations,file,inode

上一篇:Samsung_tiny4412(驱动笔记05)----Makefile,open,read,write,lseek,poll,ioctl,fasync
下一篇:Samsung_tiny4412(驱动笔记03)----字符设备驱动基本操作及调用流程

推荐阅读最新更新时间:2026-03-25 11:00

Samsung_tiny4412(驱动笔记03)----字符设备驱动基本操作及调用流程
/*********************************************************************************** * * 字符设备驱动基本操作及调用流程 * * 声明: * 1. 本系列文档是在vim下编辑,请尽量是用vim来阅读,在其它编辑器下可能会 * 不对齐,从而影响阅读. * 2. 以下所有的shell命令都是在root权限下运行的; *******************************************************************************
[单片机]
Samsung_tiny4412(驱动笔记10)----mdev,bus,device,driver,platform
/*********************************************************************************** * * mdev,bus,device,driver,platform * * 声明: * 1. 本系列文档是在vim下编辑,请尽量是用vim来阅读,在其它编辑器下可能会 * 不对齐,从而影响阅读. * 2. 由于本人水平有限,很难阐述清楚bus device driver platform的关系 * 所以强烈要求您详细参考本次提供的预热文章. * **********
[单片机]
Samsung_tiny4412(驱动笔记02)----ASM with C,MMU,Exception,GIC
/**************************************************************************** * * ASM with C,MMU,Exception,GIC * * 声明: * 1. 本系列文档是在vim下编辑,请尽量是用vim来阅读,在其它编辑器下可能会 * 不对齐,从而影响阅读. * 2. 以下所有的shell命令都是在root权限下运行的; * 3. 文中在需要往文件中写入内容的时候使用了如下2方式: * 1.如果文件不存在,创建文件;如果存在,以覆盖的方式往文件中添加内容: *
[单片机]
Tiny4412 支持 adb reboot-bootloader
硬件版本: Tiny4412ADK + S700 4GB u-boot 版本: u-boot-2010-12 linux版本: Linux-3.0.8 版本一 支持 adb reboot bootloader patch:http://pan.baidu.com/s/1i3KfCI5 版本二 支持按住K1键,然后开机,进入fastboot模式 patch: http://pan.baidu.com/s/1hqgmnQ0
[单片机]
tiny4412 串口驱动分析一 --- u-boot中的串口驱动
开发板:tiny4412ADK+S700 4GB Flash 主机:Wind7 64位 虚拟机:Vmware+Ubuntu12_04 u-boot:U-Boot 2010.12 Linux内核版本:linux-3.0.31 Android版本:android-4.1.2 我们以tiny4412为例分析串口驱动,下面我们从u-boot开始分析,然后再分析到Linux。 串口初始化 关于这部分代码流程参考件: tiny4412 u-boot 启动.pdf ,这里主要分析函数:uart_asm_init 在初始化串口驱动之前已经进行了系统时钟以及内存的初始化。下面的代码取自board/samsung/tiny441
[单片机]
<font color='red'>tiny4412</font> 串口<font color='red'>驱动</font>分析一 --- u-boot中的串口<font color='red'>驱动</font>
基于tiny4412的Linux内核移植 ---- 調試方法
平臺 Linux-4.4.4 uboot使用的是友善自帶的(爲了支持uImage和設備樹做了稍許修改) 概述 這篇博客主要用於匯總一下調試方法。 正文 1. dnw下載 目前我將uboot燒寫到SD卡中,然後使用dnw將kernel、根文件系統以及設備樹鏡像下載到內存中,爲了提高效率,可以使用下面的方法: 在uboot中添加環境變量: setenv dnw_up 'dnw 0x40600000; dnw 0x41000000; dnw 0x42000000; bootm 0x40600000 0x41000000 0x42000000' 進入uboot終端後,執行如下命令: run d
[单片机]
基于tiny4412的Linux内核移植 -- PWM子系统学习(八)
平台简介 开发板:tiny4412ADK + S700 + 4GB Flash 要移植的内核版本:Linux-4.4.0 (支持device tree) u-boot版本:友善之臂自带的 U-Boot 2010.12 (为支持uImage启动,做了少许改动) busybox版本:busybox 1.25 交叉编译工具链: arm-none-linux-gnueabi-gcc (gcc version 4.8.3 20140320 (prerelease) (Sourcery CodeBench Lite 2014.05-29)) 实验二、用蜂鸣器测试backlight 一般LCD的背光的亮度调节都是通过控制输入给背光控制
[单片机]
串口编程(基于tiny4412
参考: http://www.cnblogs.com/wblyuyang/archive/2011/11/21/2257544.html http://www.cppblog.com/amazon/archive/2010/01/28/106644.html serial_demo.c #include stdio.h #include stdlib.h #include unistd.h #include sys/types.h #include sys/stat.h #include fcntl.h //文件控制定义 #include termios.h //终端控制定义 #include errno
[单片机]
小广播
最新单片机文章
何立民专栏 单片机及嵌入式宝典

北京航空航天大学教授,20余年来致力于单片机与嵌入式系统推广工作。

厂商技术中心

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

 
机器人开发圈

电子工程世界版权所有 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2026 EEWORLD.com.cn, Inc. All rights reserved