驱动开发(LED点灯实验)

终端输入1亮LED1

2-》LED2

3->LED3

0->关灯

 demo.c

#include 
#include 
#include 
#include 
#include 
#include "myled.h"
#define CNAME "mycdev"
int major;
char kbuf[128]={};
unsigned int *vir_moder;
unsigned int *vir_odr;
unsigned int *vir_rcc;

unsigned int *vir2_moder;
unsigned int *vir2_odr;

int mycdev_open(struct inode *inode, struct file *file)
{
      printk("%s:%s:%d\n",__FILE__,__func__,__LINE__);
      return 0;
}
ssize_t mycdev_read(struct file *file,char __user *ubuf,size_t size,loff_t *loff)
{
//size参数是用户期待读到的字节长度
    int ret;
    if(size>sizeof(kbuf))
    size=sizeof(kbuf);
    ret=copy_to_user(ubuf,kbuf,size);
    if(ret)
    {
        printk("数据从内核向用户拷贝失败\n");
        return -EIO;
    }
     
       return size;
};
ssize_t mycdev_write(struct file *file, co

你可能感兴趣的:(驱动开发,单片机,stm32)