1.传递字符数组
char arr[128]
要求:在内核空间打印字符数组信息内容
#define UACCESS_BUF _IOW('a',1,char [128])
2.传递结构体
typedef struct{
int width;
int high;
}image_t;
用户空间: width = 10 high = 200
将用户空间数据传递给内核空间,在内核空间进行打印,打印之后需要每个变量+10,在传递给用户空间,在用户空间打印增加后的值
头文件
#ifndef __MYLED_H__
#define __MYLED_H__
typedef struct {
volatile unsigned int MODER; // 0x00
volatile unsigned int OTYPER; // 0x04
volatile unsigned int OSPEEDR; // 0x08
volatile unsigned int PUPDR; // 0x0C
volatile unsigned int IDR; // 0x10
volatile unsigned int ODR; // 0x14
volatile unsigned int BSRR; // 0x18
volatile unsigned int LCKR; // 0x1C
volatile unsigned int AFRL; // 0x20
volatile unsigned int AFRH; // 0x24
volatile unsigned int BRR; // 0x28
volatile unsigned int res;
volatile unsigned int SECCFGR; // 0x30
}gpio_t;
typedef struct{
int width;
int high;
}image_t;
//GPIOE基地址
#define PHY_GPIOE_ADDR 0x50006000
#define PHY_GPIOF_ADDR 0x50007000
//RCC基地址:0x50000A28
#define PHY_RCC_LED1 0x50000A28
#define LED_ON _IOW('a',1,int)
#define LED_OFF _IOW('a',0,int)
#define UACCESS_BUF _IOW('a',1,char [128])
#define WID_AND_HIGH _IOW('a',1,image_t)
enum{
LED1,
LED2,
LED3,
};
#endif
内核源文件
#include <linux/init.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/uaccess.h>
#include <linux/io.h>
#include "myled.h"
#define CNAME "myled"
int major;
char kbuf[128] = {0};
gpio_t* virt_gpioe = N