嵌入式软件工程师&&太极拳
全部博文(548)
分类: LINUX
2011-02-20 20:25:10
学习模块: old: register_chrdev: struct: struct file_operations, struct file, struct node init: register_chrdev exit: unregister_chrdev use: note: new: register_chrdev: struct: struct cdev init: cdev_init cdev_add exit: cdev_del use: note: cdev_add要放到最后 region: struct: init: register_chrdev_region alloc_chrdev_region exit: unregister_chrdev_region use: note: error: linux/errno.h 带参数检查的拷贝函数(地址检查): asm/uaccess.h use: copy_to_user/copy_from_user 阻塞I/O: struct: wait_queue_head_t init: init_waitqueue_head wait_event_interruptible exit: use: wake_up note: 睡眠机制 轮询: linux/poll.h struct: struct poll_table_struct init: poll exit: use: poll_wait note: POLLIN/POLLOUT (read/write) 异步通知: struct: struct fasync_struct init: fasync_helper fasync(file_operations) exit: 调用自己的fasync函数: test_fasync(-1, filp, 0); use: kill_fasync note: 并发和竞态(互斥): 进程与进程之间: preempt 进程和中断之间 local_irq 中断和中断之间 可重入性好,会保护现场 local_irq_save; local_irq_restore; CPU自旋: _raw_write_lock spin_lock: struct: struct spinlock_t init: spin_lock_init exit: use: spin_lock/spin_unlock note: 不能睡眠(引起睡眠函数:copy_from_user sleep, kmalloc) semaphore: struct : struct semaphore init: init_MUTEX exit: use: down/up/down_interruptible note: if (down_ifterruptible(struct semaphore *sem)) return -ERESTARTSYS; down_interruptible要加判断 分配内存: linux/slab.h kmalloc flags GPF_ATOMIC 不会睡眠, GPF_KERNEL 常用 I/O访问: asm/io.h mem_region: struct: struct resource init: request_mem_region exit: release_resource use: note: 动态映射物理地址: ioremap / iounmap 静态映射物理地址: arch/arm/mach-s3c2410/mach-bit2440.c 编译内核生效 操作I/O: ioread8/iowrite8 v为值,p为地址 中断: asm/irq.h linux/interrupt.h struct: struct irqdesc init: exit: free_irq use: request_irq set_urq_type note: SA_SHIRQ为共享中断可以执行多个函数,SA_INTERRUPT 底半部: tasklet: struct: struct tasklet_struct init: tasklet_init exit: use: tasklet_schedule note: 不可以睡眠 struct_work: struct: struct work_struct init: INT_WORK 是宏 exit: use: schedule_work note: 可以睡眠 timer: struct : struct timer_list (文档,此知识点的主角对象,结构体) init: init_timer(struct timer_list *); (初始化函数) add_timer(struct timer_list *); exit: del_timer(struct timer_list *); (退出函数) use: mod_timer(struct timer_list *, unsigned long); (用法) note: 在add_timer之间要先给struct timer_list成员赋值。 (注意事项) linux设备模型组件: struct kobject 属于所有的基类,可以把所有的对象连接起来 struct kset 同一类kobject的容器 struct subsystem 子系统 struct attribute 属性就是文件 总线驱动: 总线: struct: struct bus_type init: bus_register exit: bus_unregister use: note: 设备: struct: struct device init: device_register exit: device_unregister use: note: 驱动: struct: struct device_driver init: driver_register exit: driver_unregister use: note: platform: 平台类总线设备,bus一般都是写好的 struct : struct platform_device init: platform_device_register exit: platform_device_unregister use: note: 静态映射平台类设备资源: 1. arch/arm/mach-s3c2410/mach-bit2440.c struct platform_device *bit2440_devices[] __initdata 里加一句自己的设备资源 2. arch/arm/mach-s3c2410/devs.c 加一个 struct platform_device s3c_*_resource[] 这个结构体 再加一个 struct platform_device s3c_device* 结构体,模仿上面的结构体写 EXPORT_SYMBOL 再打出 3. arch/arm/mach-s3c2410/devs.h extern struct platform_device s3c* 导出 class: 类 struct: struct class init: class_create 给系统调试用,在sys/class创建目录 class_device_create 创建相对于sys/class目录里设备的设备文件 exit: class_device_destroy class_destroy use: note: misc:做的事就是cdev + class struct: struct miscdevice init: misc_register exit: misc_deregister use: note: 初始化struct miscdevice, file_operations要的是指针 input: struct: init: input_register_device exit: input_unregister_device use: input_report_key input_sync 按键不需要用 note: 核心EVENT事件 EV_KEY 按键 EV_ABS 触摸屏 EV_REL 鼠标