Linux嵌入式
孙太忙
stay hungry,stay foolish
展开
-
字符设备控制
main()函数的参数 main 函数作为应用程序的入口,在头文件#include<stdio.h>中。 main 函数需要传参数的时候完整的定义为int main(int argc,char **argv) 参数 argc,表示参数的个数 参数**argv,存储输入字符的数组 argv[0]表示程序名称 argv[1]——argv[n]输入的参数 Led灯 Led 灯...原创 2018-09-17 14:41:21 · 129 阅读 · 0 评论 -
Linux嵌入式开发(12)——ioremap控制寄存器
ioremap函数可以实现物理地址到虚拟地址的转化 void gpl2_device_init(void) { //物理地址起始地址0x11000100→0x11000108 phys_addr = 0x11000100; //0x11000100是GPL2CON的物理地址 virt_addr =(unsigned long)ioremap(phys_addr,0x10); //指定需要...原创 2018-10-31 14:57:26 · 667 阅读 · 0 评论 -
Linux驱动开发(11)——GPIO读
static int read_gpio_probe(struct platform_device *pdv){ int ret; printk(KERN_EMERG "\tinitialized\n"); //申请GPIO ret = gpio_request(EXYNOS4_GPC0(3),"SWITCH3"); if(ret < 0){ printk(KERN...原创 2018-10-31 14:51:09 · 389 阅读 · 0 评论 -
Linux驱动开发(8)——静态和动态申请字符设备
先贴一段demo #include &lt;linux/init.h&gt; /*包含初始化宏定义的头文件,代码中的module_init和module_exit在此文件中*/ #include &lt;linux/module.h&gt; /*包含初始化加载模块的头文件,代码中的MODULE_LICENSE在此头文件中*/ /*定义module_param module_param_array...原创 2018-10-26 16:09:18 · 328 阅读 · 0 评论 -
Linux驱动开发(7)——驱动模块传参
头文件在include/linux/moduleparam.h 传递单个参数:module_param(name,type,perm) - name:模块参数的名称 - type: 模块参数的数据类型(支持int long short uint ulong ushort类型) - perm: 模块参数的访问权限(S_IRUSR参数表示所有文件所有者可读) 例如:module_param(modu...原创 2018-10-26 15:44:17 · 177 阅读 · 0 评论 -
Linux驱动开发(10)——生成字符类设备节点
static struct class *myclass; myclass = class_create(THIS_MODULE,DEVICE_NAME); /*创建设备节点*/ device_create(myclass,NULL,MKDEV(numdev_major,numdev_minor+i),NULL,DEVICE_NAME"%d",i); /*释放设备class*/ class_des...原创 2018-10-31 11:46:12 · 187 阅读 · 0 评论 -
Linux驱动开发(9)——注册字符设备
static int scdev_init(void) { int ret = 0,i; dev_t num_dev; printk(KERN_EMERG "numdev_major is %d!\n",numdev_major); printk(KERN_EMERG "numdev_minor is %d!\n",numdev_minor); if(numdev_major...原创 2018-10-31 11:40:31 · 174 阅读 · 0 评论 -
Linux驱动开发(6)——GPIO初始化
gpio-exynos4.c文件的最后一行core_initcall(exynos4_gpiolib_init); core_initcall代表在linux初始化过程中会调用 exynos4_gpiolib_init函数中包括chip = exynos4_gpio_common_4bit exynos4_gpio_common_4bit为结构体,如下: .base = (S5P_VA...原创 2018-10-26 14:52:53 · 597 阅读 · 0 评论 -
Linux驱动开发(4)——驱动注册
结构体platform_driver struct platform_driver { int (*probe)(struct platform_device *);//初始化 int (*remove)(struct platform_device *);//移除 void (*shutdown)(struct platform_device *)...原创 2018-10-16 16:02:50 · 144 阅读 · 0 评论 -
Linux驱动开发(3)——以module方式注册设备
通过 s3c_device_leds_ctl->*smdk4x12_devices[]->platform_add_devices()->platform_device_register() 可以直接使用“platform_device_register()”来注册设备 #include <linux/init.h> #include <linux/modul...原创 2018-10-16 15:40:57 · 293 阅读 · 0 评论 -
Linux驱动开发(2)——设备注册
结构体platform_device 注册设备使用结构体platform_device,源码路径include/linux/platform_device.h struct platform_device { const char * name;//设备名称,在sys/devices显示 int id;//设备id,用于插入总线并且...原创 2018-10-16 14:50:21 · 149 阅读 · 0 评论 -
Linux驱动开发(1)——最简Linux驱动
#include <linux/init.h> #include <linux/module.h> MODULE_LICENSE("Dual BSD/GPL"); MODULE_AUTHOR("TOPEET"); static int hello_init(void) { printk(KERN_EMERG "HELLO WORLD enter!\n"); retu...原创 2018-10-16 11:48:37 · 322 阅读 · 0 评论 -
Linux驱动开发(5)——生成设备节点
项设备可以说是对一部分字符设备的封装,还有一部分不好归类驱 动也归到杂项设备 杂项设备初始化部分源文件“drivers/char/ misc.c”,这一部分通过 Makefile可知,是强制编译的。 杂项设备注册头文件include/linux/miscdevice.h 结构体miscdevice以及注册函数 struct miscdevice { int minor;//设...原创 2018-10-18 14:42:33 · 296 阅读 · 0 评论 -
折腾tftp和nfs服务器
关于折腾tftp和nfs传输文件 前言tftp传输建立 TFTP 的配置文件搭建NFS服务器在最小局域网搭建tftp和nfs ) 前言 由于没有多余的网线,没有将开发板连接到路由器,直接用网线连接到了笔记本的网口上,折腾了一天半终于调通了,真是费劲 tftp传输 首先搭建tftp服务器 sudo apt-get install xinetd sudo apt-get install tftp t...原创 2018-09-19 16:05:24 · 282 阅读 · 0 评论 -
Linux文件IO操作
Linux文件IO操作包括打开(open),创建(create),读(read),写(write) 打开open int open(const char *path, int oflags); int open(const char *path, int oflags,mode_t mode); 参数path表示:路径名或者文件名。路径名为绝对路径名。 参数oflags表示:打开文件所...原创 2018-09-13 15:54:12 · 583 阅读 · 0 评论 -
Linux串口编程
串口通信是指一次只传送一个数据位。虽然在通信的时候串口有 8 位或者 9 位等,但是在物理层面传输的时候,它仍然是以单个 bit 的方式传输的 一般特指 RS232 标准的接口 在 linux 下串口编程流程如下: 打开串口 核心是用open函数打开串口 if((fd = open(uart3,O_RDWR|O_CREAT,0777))<0){ printf...原创 2018-09-17 14:59:01 · 141 阅读 · 0 评论 -
Linux驱动开发(13)——并发与原子操作
并发 并发的概念 多个执行单元同时、并行被执行。Linux系统是多任务的,很多任务会同时执行。 假如有三个执行单元ABC,共享了内存资源。 执行单元A对Buffer写1000个“a”; 执行单元B对Buffer写1000个“b”; 执行单元C从buffer中读取数据。 如果按照A写→C读→B写→C读,当然没有问题。但是如果A写→B写→C读,执行单元C就出问题了。当然比这个复杂更多,更加混乱的并发...原创 2018-11-01 09:40:34 · 147 阅读 · 0 评论