10,10驱动点灯

myled.h

#ifndef __MYLED_H__
#define __MYLED_H__

#define PHY_LED1_MODER 0X50006000
#define PHY_LED1_ODR   0X50006014
#define PHY_LED1_RCC   0X50000A28 

#define PHY_LED2_MODER 0X50007000
#define PHY_LED2_ODR 0X50007014
#define PHY_LED2_RCC 0x50000A28
 
#define PHY_LED3_MODER 0X50006000
#define PHY_LED3_ODR 0X50006014
#define PHY_LED3_RCC 0x50000A28

#endif


mycdev.c

#include
#include
#include
#include
#include
#include"myled.h"
#define CNAME  "mycdev"

int major;//定义变量接收主设备号
char kbuf[128]={};//定义数组用于存放和用户之间拷贝的数据
unsigned int *vir_moder1;
unsigned int *vir_moder2;
unsigned int *vir_odr1;
unsigned int *vir_odr2;
unsigned int *vir_rcc;

//对应的是open()
int mycdev_open(struct inode *inode, struct file *file)
{
      printk("%s:%s:%d\n",__FILE__,__func__,__LINE__);
      return 0;
}
//read()
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("数据从内核向

你可能感兴趣的:(其他)