Wei Dongshan uboot_kernel_root file system study notes 5.4~5.5-Lesson 005_Character device driver_Section 004~005__Character device driver LED driver_Operation LED

A few knowledge points of writing actual driver

  1. Virtual address mapping-ioremap function/iounmap

Virtual address and MMU:

eg:
分配地址代码gpio_va = ioremap(0x56000000, 0x100000);//0x56000000起始地址,0x100000长度
释放地址代码iounmap(gpio_va);//
  1. Value transfer between user program and driver
eg:
char __user *buf;//用户空间变量
static unsigned char key_val;//内核空间变量
//向用户程序传值函数
copy_to_user(buf, &key_val, count);//count表示字符长度
//向内核空间传值函数
copy_from_user(&key_val,buf,count)
  1. User program main function entry parameter description

int argc: The number of parameters passed in. eg: When calling the program, the input ./app onis two parameters
char **argv: the character array stored by the incoming parameter.

int main(int argc, char **argv)
  1. Use of
    minor device number The function corresponding to the minor device number is controlled by the driver's open/read/write function. See the full source code:JZ2440V3\drivers_and_test\leds

(1) Usage of driver open function

//struct inode *inode:次设备号
static int first_drv_open(struct inode *inode, struct file *file)
{
	//获取次设备号,其对应的功能由驱动程序控制
	int minor = MINOR(inode->i_rdev);
	return 0;
}

(2) Usage of driver init The
following code iis the sub-device number, and the name of the sub-device number is 100ask_led%d.

for (i = 0; i < LED_NUM; i++)
	device_create(led_class, NULL, MKDEV(major, i), NULL, "100ask_led%d", i); /* /dev/100ask_led0,1,... */

(3) After the development board is loaded with the driver program, a /dev/folder corresponding to each minor device number appears in the directory
Insert picture description here

  1. top command The
    top command is a commonly used performance analysis tool under Linux, which can display the resource occupancy status of each process in the system in real time, similar to the task manager of Windows.

Guess you like

Origin blog.csdn.net/xiaoaojianghu09/article/details/104244487