当前位置: 首页 > news >正文

day4 驱动开发 c语言学习

不利用系统提供的register_chrdev,自己实现字符设备的注册

底层代码

led.c

#include <linux/init.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/uaccess.h>
#include <linux/io.h>
#include "head.h"struct cdev *mycdev;
struct class *my_cls;
struct device *my_dev;
dev_t devno;
unsigned int major = 0; //定义一个变量保存主设备号
char kbuf[128] = { 0 }; //定义一个内核中的buffer
unsigned int *vir_gpioe_moder = NULL;
unsigned int *vir_gpioe_odr = NULL;
unsigned int *vir_gpiof_moder = NULL;
unsigned int *vir_gpiof_odr = NULL;
unsigned int *vir_rcc = NULL;
//封装注册设备方法
int mycdev_regist(void)
{int res = 0;int i = 0;//为驱动对象申请空间 cdev_alloc()mycdev = cdev_alloc();if (mycdev == NULL) {return -EFAULT;}//对象的初始化 cdev_init()cdev_init(mycdev, &fops);//申请设备号 register_chrdev_region()/alloc_chrdev_region()res = alloc_chrdev_region(&devno, 0, 3, "my_cdev");if (res != 0) {goto out;}//注册驱动对象 cdev_add()res = cdev_add(mycdev, devno, 3);if (res != 0) {goto out2;}major = MAJOR(devno);//向上提交目录 class_create()my_cls = class_create(THIS_MODULE, "my_cdev");if (my_cls == NULL) {goto out3;}//向上提交设备节点信息 device_create()for(i = 0; i < 3; i++){my_dev = device_create(my_cls, NULL, MKDEV(major, i), NULL, "LED%d", i);if (IS_ERR(my_dev)) {goto out4;}}return 0;out4:for(i--; i >= 0; i-- ){device_destroy(my_dev,MKDEV(major,i));}class_destroy(my_cls);
out3:cdev_del(mycdev);
out2:unregister_chrdev_region(devno, 3);
out:kfree(mycdev);return -PTR_ERR(res);
}
//封装操作方法
int mycdev_open(struct inode *inode, struct file *file)
{devno = inode->i_rdev;file->private_data = (void *)MINOR(devno);printk("%s:%s:%d\n", __FILE__, __func__, __LINE__);return 0;
}long mycdev_ioctl(struct file *file, unsigned int request, unsigned long args)
{unsigned int minor = (unsigned int)file->private_data;if (minor = 0) {//开led1if (request == LED1_ON) {*vir_gpioe_odr |= 0x1 << 10;}//关led1else if (request == LED1_OFF) {*vir_gpioe_odr &= ~(0x1 << 10);}} else if (minor == 1) {//开led2if (request == LED2_ON) {*vir_gpiof_odr |= 0x1 << 10;}//关led2else if (request == LED2_OFF) {*vir_gpiof_odr &= ~(0x1 << 10);}} else if (minor == 2) {//开led3if (request == LED3_ON){*vir_gpioe_odr |= 0x1 << 8;}//关led3else if (request == LED3_OFF){*vir_gpioe_odr &= ~(0x1 << 8);}}return 0;
}int mycdev_close(struct inode *inode, struct file *file)
{printk("%s:%s:%d\n", __FILE__, __func__, __LINE__);return 0;
}struct file_operations fops = {.open = mycdev_open,.unlocked_ioctl = mycdev_ioctl,.release = mycdev_close,
};static int __init mycdev_init(void)
{   mycdev_regist();//定义一个long类型(匹配ioremap函数第一个参数),用来保存每个寄存器的地址信息volatile unsigned long tmp = 0;//初始化几个寄存器,将物理地址映射到虚拟地址,以方便用户空间进行读写操作//将地址信息强转为long类型方便tmp保存tmp = (long)&GPIOE->MODER;//将寄存器的物理地址映射到虚拟地址并保存vir_gpioe_moder = ioremap(tmp, 4);if (vir_gpioe_moder == NULL) {printk("映射物理内存失败");return -EFAULT;}//将地址信息强转为long类型方便tmp保存tmp = (long)&GPIOF->MODER;//将寄存器的物理地址映射到虚拟地址并保存vir_gpiof_moder = ioremap(tmp, 4);if (vir_gpioe_moder == NULL) {printk("映射物理内存失败");return -EFAULT;}//将地址信息强转为long类型方便tmp保存tmp = (long)&GPIOE->ODR;//将寄存器的物理地址映射到虚拟地址并保存vir_gpioe_odr = ioremap(tmp, 4);if (vir_gpioe_odr == NULL) {printk("映射物理内存失败");return -EFAULT;}//将地址信息强转为long类型方便tmp保存tmp = (long)&GPIOF->ODR;//将寄存器的物理地址映射到虚拟地址并保存vir_gpiof_odr = ioremap(tmp, 4);if (vir_gpiof_odr == NULL) {printk("映射物理内存失败");return -EFAULT;}//将地址信息强转为long类型方便tmp保存tmp = (long)&RCC->MP_AHB4ENSETR;//将寄存器的物理地址映射到虚拟地址并保存vir_rcc = ioremap(tmp, 4);if (vir_rcc == NULL) {printk("映射物理内存失败");return -EFAULT;}//初始化几个寄存器的值//设置RCC_MP_AHB4ENSETR寄存器第4第5两个引脚为1,使能GPIOE,GPIOF*vir_rcc |= (0b11 << 4);//设置GPIOE_MODER第20-21位为01*vir_gpioe_moder &= ~(0b11 << 20);*vir_gpioe_moder |= (0b01 << 20);//设置GPIOF_MODER第20-21位为01*vir_gpiof_moder &= ~(0b11 << 20);*vir_gpiof_moder |= (0b01 << 20);//设置GPIOE_MODER第16-17位为01*vir_gpioe_moder &= ~(0b11 << 16);*vir_gpioe_moder |= (0b01 << 16);//设置GPIOE_ODR第10位为0*vir_gpioe_odr &= ~(0b1 << 10);//设置GPIOF_ODR第10位为0*vir_gpiof_odr &= ~(0b1 << 10);//设置GPIOE_ODR第8位为0*vir_gpiof_odr &= ~(0b1 << 8);return 0;
}static void __exit mycdev_exit(void)
{//取消物理内存映射iounmap(vir_gpioe_moder);iounmap(vir_gpiof_moder);iounmap(vir_gpioe_odr);iounmap(vir_gpiof_odr);iounmap(vir_rcc);printk("设备卸载\n");unregister_chrdev(MAJOR(devno), "mychrdev");
}module_init(mycdev_init);
module_exit(mycdev_exit);
MODULE_LICENSE("GPL");

应用层代码

app.c

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <string.h>
#include <sys/ioctl.h>
#include "head.h"int main()
{int dev = 0;char buf[128] = {0};fprintf(stdout,"调用open\n");int fd_led0 = open("/dev/LED0",O_RDWR);if( fd_led0 < 0){perror("");exit(-1);}int fd_led1 = open("/dev/LED1",O_RDWR);if( fd_led1 < 0){perror("");exit(-1);}int fd_led2 = open("/dev/LED2",O_RDWR);if( fd_led2 < 0){perror("");exit(-1);}while(1){fprintf(stdout,"请输入开关选项:\n");fprintf(stdout,"11开1号灯,10关1号灯以此类推\n");fprintf(stdout,"输入q来结束\n");fgets(buf,sizeof(buf),stdin);buf[strlen(buf) - 1] = '\0';//如果输入的是q或Q,结束循环if(buf[0] == 'q' || buf[0] == 'Q'){break;}else if(buf[0] == '0'){if(buf[1] == '1' && buf[2] == '0'){ioctl(fd_led0, LED1_OFF, dev);}else if(buf[1] == '1' && buf[2] == '1'){ioctl(fd_led0, LED1_ON, dev);}else if(buf[1] == '2' && buf[2] == '0'){ioctl(fd_led1, LED2_OFF, dev);}else if(buf[1] == '2' && buf[2] == '1'){ioctl(fd_led1, LED2_ON, dev);}else if(buf[1] == '3' && buf[2] == '0'){ioctl(fd_led2, LED3_OFF, dev);}else if(buf[1] == '3' && buf[2] == '1'){ioctl(fd_led2, LED3_ON, dev);}}}close(fd_led0);close(fd_led1);close(fd_led2);return 0;
}

头文件

head.h

#ifndef __LED_H__
#define __LED_H__typedef struct {volatile unsigned int TZCR;     	// 0x000volatile unsigned int res1[2]; 		// 0x004-0x008volatile unsigned int OCENSETR;     // 0x00Cvolatile unsigned int OCENCLRR;  	// 0x010volatile unsigned int res2[1]; 		// 0x014volatile unsigned int HSICFGR; 		// 0x018volatile unsigned int CSICFGR; 		// 0x01Cvolatile unsigned int MPCKSELR; 	// 0x020volatile unsigned int ASSCKSELR; 	// 0x024volatile unsigned int PCK12SELR; 	// 0x028volatile unsigned int MPCKDIVR; 	// 0x02Cvolatile unsigned int AXIDIVR; 		// 0x030volatile unsigned int res3[2];      volatile unsigned int APB4DIVR; 	// 0x03Cvolatile unsigned int APB5DIVR; 	// 0x040volatile unsigned int RTCDIVR; 		// 0x044volatile unsigned int MSSCKSELR;    // 0x048volatile unsigned int res4[13];volatile unsigned int PLL1CR; 		// 0x080volatile unsigned int PLL1CFGR1; 	// 0x084volatile unsigned int PLL1CFGR2; 	// 0x088volatile unsigned int PLL1FRACR; 	// 0x08Cvolatile unsigned int PLL1CSGR;     // 0x090volatile unsigned int PLL2CR; 		// 0x094volatile unsigned int PLL2CFGR1; 	// 0x098volatile unsigned int PLL2CFGR2; 	// 0x09Cvolatile unsigned int PLL2FRACR;    // 0x0A0volatile unsigned int PLL2CSGR;     // 0x0A4volatile unsigned int res5[6];volatile unsigned int I2C46CKSELR;  // 0x0C0volatile unsigned int SPI6CKSELR;   // 0x0C4volatile unsigned int UART1CKSELR;  // 0x0C8volatile unsigned int RNG1CKSELR;   // 0x0CCvolatile unsigned int CPERCKSELR;   // 0x0D0volatile unsigned int STGENCKSELR;  // 0x0D4volatile unsigned int DDRITFCR; 	// 0x0D8volatile unsigned int res6[9];volatile unsigned int MP_BOOTCR;  	// 0x100volatile unsigned int MP_SREQSETR;  // 0x104volatile unsigned int MP_SREQCLRR;  // 0x108volatile unsigned int MP_GCR;  		// 0x10Cvolatile unsigned int MP_APRSTCR; 	// 0x110 volatile unsigned int MP_APRSTSR;   // 0x114volatile unsigned int res7[10];volatile unsigned int BDCR; 		// 0x140volatile unsigned int RDLSICR;  	// 0x144volatile unsigned int res8[14];volatile unsigned int APB4RSTSETR; 	// 0x180volatile unsigned int APB4RSTCLRR; 	// 0x184volatile unsigned int APB5RSTSETR;  // 0x188volatile unsigned int APB5RSTCLRR;  // 0x18Cvolatile unsigned int AHB5RSTSETR;  // 0x190volatile unsigned int AHB5RSTCLRR;  // 0x194volatile unsigned int AHB6RSTSETR;  // 0x198volatile unsigned int AHB6RSTCLRR;  // 0x19Cvolatile unsigned int TZAHB6RSTSELR;// 0x1A0volatile unsigned int TZAHB6RSTCLRR;// 0x1A4volatile unsigned int res9[22];volatile unsigned int MP_APB4ENSETR;// 0x200volatile unsigned int MP_APB4ENCLRR;// 0x204volatile unsigned int MP_APB5ENSETR;// 0x208volatile unsigned int MP_APB5ENCLRR;// 0x20Cvolatile unsigned int MP_AHB5ENSETR;// 0x210volatile unsigned int MP_AHB5ENCLRR;// 0x214volatile unsigned int MP_AHB6ENSETR;// 0x218volatile unsigned int MP_AHB6ENCLRR;// 0x21Cvolatile unsigned int MP_TZAHB6ENSELR;// 0x220volatile unsigned int MP_TZAHB6ENCLRR;// 0x224volatile unsigned int res10[22];volatile unsigned int MC_APB4ENSETR; // 0x280volatile unsigned int MC_APB4ENCLRR; // 0x284volatile unsigned int MC_APB5ENSETR; // 0x288volatile unsigned int MC_APB5ENCLRR; // 0x28Cvolatile unsigned int MC_AHB5ENSETR; // 0x290volatile unsigned int MC_AHB5ENCLRR; // 0x294volatile unsigned int MC_AHB6ENSETR; // 0x298volatile unsigned int MC_AHB6ENCLRR; // 0x29Cvolatile unsigned int res11[24];volatile unsigned int MP_APB4LPENSETR; // 0x300volatile unsigned int MP_APB4LPENCLRR; // 0x304volatile unsigned int MP_APB5LPENSETR; // 0x308volatile unsigned int MP_APB5LPENCLRR; // 0x30Cvolatile unsigned int MP_AHB5LPENSETR; // 0x310volatile unsigned int MP_AHB5LPENCLRR; // 0x314volatile unsigned int MP_AHB6LPENSETR; // 0x318volatile unsigned int MP_AHB6LPENCLRR; // 0x31Cvolatile unsigned int MP_TZAHB6LPENSETR; // 0x320volatile unsigned int MP_TZAHB6LPENCLRR; // 0x324volatile unsigned int res12[22];volatile unsigned int MC_APB4LPENSETR; // 0x380volatile unsigned int MC_APB4LPENCLRR; // 0x384volatile unsigned int MC_APB5LPENSETR; // 0x388volatile unsigned int MC_APB5LPENCLRR; // 0x38Cvolatile unsigned int MC_AHB5LPENSETR; // 0x390volatile unsigned int MC_AHB5LPENCLRR; // 0x394volatile unsigned int MC_AHB6LPENSETR; // 0x398volatile unsigned int MC_AHB6LPENCLRR; // 0x39Cvolatile unsigned int res13[24];volatile unsigned int BR_RSTSCLRR; 		// 0x400volatile unsigned int MP_GRSTCSETR; 	// 0x404volatile unsigned int MP_RSTSR; 		// 0x408 volatile unsigned int MP_IWDGFZSETR; 	// 0x40Cvolatile unsigned int MP_IWDGFZCLRR;  	// 0x410volatile unsigned int MP_CIER; 			// 0x414volatile unsigned int MP_CIFR; 			// 0x418volatile unsigned int PWRLPDLYCR; 		// 0x41Cvolatile unsigned int MP_RSTSS; 		// 0x420volatile unsigned int res14[247];volatile unsigned int MCO1CFGR; 		// 0x800volatile unsigned int MCO2CFGR; 		// 0x804 volatile unsigned int OCRDYR; 			// 0x808volatile unsigned int DBGCFGR; 			// 0x80Cvolatile unsigned int res15[4];volatile unsigned int RCK3SELR; 		// 0x820volatile unsigned int RCK4SELR; 		// 0x824volatile unsigned int TIMG1PRER;  		// 0x828volatile unsigned int TIMG2PRER; 		// 0x82Cvolatile unsigned int MCUDIVR; 			// 0x830volatile unsigned int APB1DIVR; 		// 0x834volatile unsigned int APB2DIVR; 		// 0x838volatile unsigned int APB3DIVR; 		// 0x83Cvolatile unsigned int res16[16];volatile unsigned int PLL3CR;   		// 0x880volatile unsigned int PLL3CFGR1; 		// 0x884volatile unsigned int PLL3CFGR2; 		// 0x888volatile unsigned int PLL3FRACR; 		// 0x88Cvolatile unsigned int PLL3CSGR; 		// 0x890volatile unsigned int PLL4CR; 			// 0x894volatile unsigned int PLL4CFGR1; 		// 0x898volatile unsigned int PLL4CFGR2; 		// 0x89Cvolatile unsigned int PLL4FRACR; 		// 0x8A0volatile unsigned int PLL4CSGR; 		// 0x8A4volatile unsigned int res17[6];volatile unsigned int I2C12CKSELR; 		// 0x8C0volatile unsigned int I2C35CKSELR;  	// 0x8C4volatile unsigned int SAI1CKSELR; 		// 0x8C8volatile unsigned int SAI2CKSELR; 		// 0x8CCvolatile unsigned int SAI3CKSELR; 		// 0x8D0volatile unsigned int SAI4CKSELR; 		// 0x8D4volatile unsigned int SPI2S1CKSELR; 	// 0x8D8volatile unsigned int SPI2S23CKSELR; 	// 0x8DCvolatile unsigned int SPI45CKSELR; 		// 0x8E0volatile unsigned int UART6CKSELR; 		// 0x8E4volatile unsigned int UART24CKSELR; 	// 0x8E8volatile unsigned int UART35CKSELR; 	// 0x8ECvolatile unsigned int UART78CKSELR; 	// 0x8F0volatile unsigned int SDMMC12CKSELR; 	// 0x8F4volatile unsigned int SDMMC3CKSELR; 	// 0x8F8volatile unsigned int ETHCKSELR; 		// 0x8FCvolatile unsigned int QSPICKSELR; 		// 0x900volatile unsigned int FMCCKSELR; 		// 0x904volatile unsigned int res18[1];volatile unsigned int FDCANCKSELR; 		// 0x90Cvolatile unsigned int res19[1];volatile unsigned int SPDIFCKSELR; 		// 0x914volatile unsigned int CECCKSELR; 		// 0x918volatile unsigned int USBCKSELR; 		// 0x91Cvolatile unsigned int RNG2CKSELR;  		// 0x920volatile unsigned int DSICKSELR; 		// 0x924volatile unsigned int ADCCKSELR; 		// 0x928volatile unsigned int LPTIM45CKSELR; 	// 0x92Cvolatile unsigned int LPTIM23CKSELR;    // 0x930volatile unsigned int LPTIM1CKSELR; 	// 0x934volatile unsigned int res20[18];volatile unsigned int APB1RSTSETR; 		// 0x980volatile unsigned int APB1RSTCLRR; 		// 0x984volatile unsigned int APB2RSTSETR; 		// 0x988volatile unsigned int APB2RSTCLRR; 		// 0x98Cvolatile unsigned int APB3RSTSETR; 		// 0x990volatile unsigned int APB3RSTCLRR; 		// 0x994volatile unsigned int AHB2RSTSETR; 		// 0x998volatile unsigned int AHB2RSTCLRR;  	// 0x99Cvolatile unsigned int AHB3RSTSETR; 		// 0x9A0volatile unsigned int AHB3RSTCLRR; 		// 0x9A4volatile unsigned int AHB4RSTSETR; 		// 0x9A8volatile unsigned int AHB4RSTCLRR; 		// 0x9ACvolatile unsigned int res21[20];volatile unsigned int MP_APB1ENSETR; 	// 0xA00volatile unsigned int MP_APB1ENCLRR; 	// 0xA04volatile unsigned int MP_APB2ENSETR; 	// 0xA08volatile unsigned int MP_APB2ENCLRR;  	// 0xA0Cvolatile unsigned int MP_APB3ENSETR; 	// 0xA10volatile unsigned int MP_APB3ENCLRR; 	// 0xA14volatile unsigned int MP_AHB2ENSETR; 	// 0xA18volatile unsigned int MP_AHB2ENCLRR; 	// 0xA1Cvolatile unsigned int MP_AHB3ENSETR; 	// 0xA20volatile unsigned int MP_AHB3ENCLRR; 	// 0xA24volatile unsigned int MP_AHB4ENSETR; 	// 0xA28volatile unsigned int MP_AHB4ENCLRR; 	// 0xA2Cvolatile unsigned int res22[2];volatile unsigned int MP_MLAHBENSETR; 	// 0xA38volatile unsigned int MP_MLAHBENCLRR; 	// 0xA3Cvolatile unsigned int res23[16];volatile unsigned int MC_APB1ENSETR; 	// 0xA80volatile unsigned int MC_APB1ENCLRR; 	// 0xA84volatile unsigned int MC_APB2ENSETR; 	// 0xA88volatile unsigned int MC_APB2ENCLRR; 	// 0xA8Cvolatile unsigned int MC_APB3ENSETR; 	// 0xA90volatile unsigned int MC_APB3ENCLRR; 	// 0xA94volatile unsigned int MC_AHB2ENSETR; 	// 0xA98volatile unsigned int MC_AHB2ENCLRR; 	// 0xA9Cvolatile unsigned int MC_AHB3ENSETR; 	// 0xAA0volatile unsigned int MC_AHB3ENCLRR; 	// 0xAA4volatile unsigned int MC_AHB4ENSETR; 	// 0xAA8volatile unsigned int MC_AHB4ENCLRR; 	// 0xAACvolatile unsigned int MC_AXIMENSETR; 	// 0xAB0volatile unsigned int MC_AXIMENCLRR; 	// 0xAB4volatile unsigned int MC_MLAHBENSETR; 	// 0xAB8volatile unsigned int MC_MLAHBENCLRR; 	// 0xABCvolatile unsigned int res24[16];volatile unsigned int MP_APB1LPENSETR; 	// 0xB00volatile unsigned int MP_APB1LPENCLRR; 	// 0xB04volatile unsigned int MP_APB2LPENSETR;  // 0xB08volatile unsigned int MP_APB2LPENCLRR; 	// 0xB0Cvolatile unsigned int MP_APB3LPENSETR; 	// 0xB10volatile unsigned int MP_APB3LPENCLRR;  // 0xB14volatile unsigned int MP_AHB2LPENSETR;  // 0xB18volatile unsigned int MP_AHB2LPENCLRR;  // 0xB1Cvolatile unsigned int MP_AHB3LPENSETR;  // 0xB20volatile unsigned int MP_AHB3LPENCLRR;  // 0xB24volatile unsigned int MP_AHB4LPENSETR;  // 0xB28volatile unsigned int MP_AHB4LPENCLRR;  // 0xB2Cvolatile unsigned int MP_AXIMLPENSETR;  // 0xB30volatile unsigned int MP_AXIMLPENCLRR;  // 0xB34volatile unsigned int MP_MLAHBLPENSETR; // 0xB38volatile unsigned int MP_MLAHBLPENCLRR; // 0xB3Cvolatile unsigned int res25[16];volatile unsigned int MC_APB1LPENSETR;  // 0xB80volatile unsigned int MC_APB1LPENCLRR; 	// 0xB84volatile unsigned int MC_APB2LPENSETR;  // 0xB88volatile unsigned int MC_APB2LPENCLRR;  // 0xB8Cvolatile unsigned int MC_APB3LPENSETR;  // 0xB90 volatile unsigned int MC_APB3LPENCLRR;  // 0xB94volatile unsigned int MC_AHB2LPENSETR;  // 0xB98volatile unsigned int MC_AHB2LPENCLRR;  // 0xB9Cvolatile unsigned int MC_AHB3LPENSETR;  // 0xBA0 volatile unsigned int MC_AHB3LPENCLRR;  // 0xBA4volatile unsigned int MC_AHB4LPENSETR;  // 0xBA8volatile unsigned int MC_AHB4LPENCLRR;  // 0xBACvolatile unsigned int MC_AXIMLPENSETR;  // 0xBB0volatile unsigned int MC_AXIMLPENCLRR;  // 0xBB4volatile unsigned int MC_MLAHBLPENSETR; // 0xBB8volatile unsigned int MC_MLAHBLPENCLRR; // 0xBBCvolatile unsigned int res26[16];volatile unsigned int MC_RSTSCLRR;  	// 0xC00volatile unsigned int res27[4];volatile unsigned int MC_CIER;  		// 0xC14volatile unsigned int MC_CIFR; 			// 0xC18volatile unsigned int res28[246];volatile unsigned int VERR; 			// 0xFF4volatile unsigned int IDR; 				// 0xFF8volatile unsigned int SIDR; 			// 0xFFC
}rcc_t;#define RCC   ((rcc_t *)0x50000000)typedef struct {volatile unsigned int MODER;   // 0x00volatile unsigned int OTYPER;  // 0x04volatile unsigned int OSPEEDR; // 0x08volatile unsigned int PUPDR;   // 0x0Cvolatile unsigned int IDR;     // 0x10volatile unsigned int ODR;     // 0x14volatile unsigned int BSRR;    // 0x18volatile unsigned int LCKR;    // 0x1C volatile unsigned int AFRL;    // 0x20 volatile unsigned int AFRH;    // 0x24volatile unsigned int BRR;     // 0x28volatile unsigned int res;volatile unsigned int SECCFGR; // 0x30}gpio_t;#define  GPIOA   ((gpio_t *)0x50002000)
#define  GPIOB   ((gpio_t *)0x50003000)
#define  GPIOC   ((gpio_t *)0x50004000)
#define  GPIOD   ((gpio_t *)0x50005000)
#define  GPIOE   ((gpio_t *)0x50006000)
#define  GPIOF   ((gpio_t *)0x50007000)
#define  GPIOG   ((gpio_t *)0x50008000)
#define  GPIOH   ((gpio_t *)0x50009000)
#define  GPIOI   ((gpio_t *)0x5000A000)
#define  GPIOJ   ((gpio_t *)0x5000B000)
#define  GPIOK   ((gpio_t *)0x5000C000)
#define  GPIOZ   ((gpio_t *)0x54004000)#define LED1_ON _IOW('l',11,int)
#define LED1_OFF _IOW('l',10,int)
#define LED2_ON _IOW('l',21,int)
#define LED2_OFF _IOW('l',20,int)
#define LED3_ON _IOW('l',31,int)
#define LED3_OFF _IOW('l',30,int)
#define FAN_ON _IOW('f',1,int)
#define FAN_OFF _IOW('f',0,int)
#define BUZ_ON _IOW('b',1,int)
#define BUZ_OFF _IOW('b',0,int)
#define MOT_ON _IOW('m',1,int)
#define MOT_OFF _IOW('m',0,int)
#endif

相关文章:

day4 驱动开发 c语言学习

不利用系统提供的register_chrdev&#xff0c;自己实现字符设备的注册 底层代码 led.c #include <linux/init.h> #include <linux/module.h> #include <linux/fs.h> #include <linux/uaccess.h> #include <linux/io.h> #include "head.h…...

history命令:显示命令执行时间

1.修改配置文件 vim /etc/profile 添加内容 export HISTTIMEFORMAT"%Y-%m-%d %H:%M:%S " ​ #注意&#xff1a;在末尾的“引号”与“S”之间&#xff0c;加入一位空格&#xff0c;将日期时间和历史命令用空格相隔开来。 你也可以换一种清晰的形式&#xff0c;效果…...

Django接口返回JSON格式数据报文

目录 遇到问题 Django返回json结构报文 不可行方式python json 可行方式JsonResponseQuerySet.values()。 python的两个web框架&#xff0c;flask和django&#xff0c;两者都具有view 模板的章节&#xff0c;但是当前开发一个应用&#xff0c;大部分采用前后端分离的合作方式。…...

OBS 迁移--华为云

一、创建迁移i任务 1. 登录管理控制台。 2. 单击管理控制台左上角的 在下拉框中选择区域。 3. 单击“ 服务列表 ”&#xff0c;选择“ 迁移 > 对象存储迁移服务 OMS ”&#xff0c;进入“ 对象存储迁移服务 ”页面。 4. 单击页面右上角“ 创建迁移任务 ”。 5. 仔细阅读…...

【Docker consul的容器服务更新与发现】

文章目录 一、Consul 的简介&#xff08;1&#xff09;什么是服务注册与发现&#xff08;2&#xff09;什么是consul 二、consul 部署1、consul服务器1. 建立 Consul 服务2. 查看集群信息3. 通过 http api 获取集群信息 2、registrator服务器1. 安装 Gliderlabs/Registrator2. …...

MFC第二十天 数值型关联变量 和单选按钮与复选框的开发应用

文章目录 数值型关联变量数值型关联变量的种类介绍 单选按钮与复选框单选按钮的组内选择原理解析单选按钮和复选框以及应用数值型关联变量的开发CMainDlg.cppCInputDlg.hCInputDlg.cpp 附录 数值型关联变量 数值型关联变量的种类介绍 1、 数值型关联变量&#xff1a; a)控件型…...

服务器 Docker Alist挂载到本地磁盘(Mac版)夸克网盘

1.服务器下载alist 默认有docker环境 docker pull xhofe/alist2.生成容器 -v /home/alist:/opt/alist/data 这段意思是alist中的数据映射到docker 主机的文件夹&#xff0c;/home/alist就是我主机的文件夹&#xff0c;这个文件夹必须先创建 docker run -d --restartalways…...

EMP-SSL: TOWARDS SELF-SUPERVISED LEARNING IN ONETRAINING EPOCH

Recently, self-supervised learning (SSL) has achieved tremendous success in learning image representation. Despite the empirical success, most self-supervised learning methods are rather “inefficient” learners, typically taking hundreds of training epoch…...

注解和反射01--什么是注解

注解 什么是注解内置注解元注解自定义注解 什么是注解 1、注解是从JDK5.0开始引入的新技术 2、注解的作用 &#xff08;1&#xff09;不是程序本身&#xff0c;可以对程序做出解释&#xff08;和注释相同&#xff09; &#xff08;2&#xff09;可以被其他程序读取&#xff0c…...

虚拟机 RHEL8 安装 MySQL 8.0.34

目录 安装步骤一、清除所有残留的旧MySQL二、安装MySQL 报错问题1. 提示未找到匹配的参数&#xff1a; mysql-community-server2. 公钥问题 安装步骤 一、清除所有残留的旧MySQL 1. 关闭MySQL [rootlocalhost /]# service mysqld stop Redirecting to /bin/systemctl stop …...

kafka 总结宝典

...

跨平台力量:探索C++Qt框架的未来前景

卓越的跨平台支持&#xff1a;CQt可以在多个平台上运行&#xff0c;包括Windows、Mac、Linux、Android和iOS等。这使得开发者能够使用同一份代码构建跨平台的应用程序&#xff0c;从而显著降低了开发成本和时间投入。 丰富的类库和工具&#xff1a;CQt提供了广泛的类库和工具&…...

基于长短期神经网络LSTM的位移监测,基于长短期神经网络的位移预测,LSTM的详细原理

目录 背影 摘要 LSTM的基本定义 LSTM实现的步骤 基于长短期神经网络LSTM的位移监测 完整代码: https://download.csdn.net/download/abc991835105/88098131 效果图 结果分析 展望 参考论文 背影 路径追踪预测,对实现自动飞行驾驶拥有重要意义,长短期神经网络是一种改进党的…...

ChatGPT漫谈(二)

ChatGPT“脱胎”于OpenAI在2020年发布的GPT-3,任何外行都可以使用GPT-3,在几分钟内提供示例,并获得所需的文本输出。GPT-3被认为是当时最强大的语言模型,但现在,ChatGPT模型似乎更强大。ChatGPT能进行天马行空的长对话,可以回答问题,它具备了类人的逻辑、思考与沟通的能…...

【LangChain】检索器之MultiQueryRetriever

MultiQueryRetriever 概要内容总结 概要 基于距离的向量数据库检索在高维空间中嵌入查询&#xff0c;并根据“距离”查找相似的嵌入文档。 但是&#xff0c;如果查询措辞发生细微变化&#xff0c;或者嵌入不能很好地捕获数据的语义&#xff0c;检索可能会产生不同的结果。有时…...

教师ChatGPT的23种用法

火爆全网的ChatGPT&#xff0c;作为教师应该如何正确使用&#xff1f;本文梳理了教师ChatGPT的23种用法&#xff0c;一起来看看吧&#xff01; 1、回答问题 ChatGPT可用于实时回答问题&#xff0c;使其成为需要快速获取信息的学生的有用工具。 从这个意义上说&#xff0c;Cha…...

【libevent】http客户端1:转存http下载的数据

read_http_input // // HTTP endpoint: GET /rpc/1 (list methods) or POST /rpc/1 (execute RPC) // // JSON-RPC API endpoint. Handles all JSON-RPC method calls. // static void rpc_jsonrpc(evhttp_request *req, void *opaque) {RpcApiInfo *ap =...

Pytorch学习笔记 | 数据类型 | mnist数据集

数据类型 python中数据类型和pytorch中的对应关系 注意:pytorch是没有没有string类型的 例1:创建一个3行4列的随机数数组,符合均值为0,方差为1的正态分布 import torch a=torch.Tensor(3,4) a Out[17]: tensor([[0....

Linux虚拟机(lvm)报Unmount and run xfs_repair

问题 linux系统没有正常关机&#xff0c;今天启动虚拟机无法进入系统&#xff0c;提示metadata corruption deleted at xxxx&#xff1b; Unmount and run xfs_repair 分析 主机异常掉电后里面的虚拟机无法启动&#xff0c;主要是损坏的分区 解决 看出来应该是dm-0分区损坏…...

【ESP32】Espressif-IDE及ESP-IDF安装

一、下载Espressif-IDE 2.10.0 with ESP-IDF v5.0.2 1.打开ESP-IDF 编程指南 2.点击快速入门–>安装–>手动安装–>Windows Installer–>Windows Installer Download 3.点击下载Espressif-IDE 2.10.0 with ESP-IDF v5.0.2 二、安装Espressif-IDE 2.10.0 wit…...

从零开始打造 OpenSTLinux 6.6 Yocto 系统(基于STM32CubeMX)(九)

设备树移植 和uboot设备树修改的内容同步到kernel将设备树stm32mp157d-stm32mp157daa1-mx.dts复制到内核源码目录下 源码修改及编译 修改arch/arm/boot/dts/st/Makefile&#xff0c;新增设备树编译 stm32mp157f-ev1-m4-examples.dtb \stm32mp157d-stm32mp157daa1-mx.dtb修改…...

k8s业务程序联调工具-KtConnect

概述 原理 工具作用是建立了一个从本地到集群的单向VPN&#xff0c;根据VPN原理&#xff0c;打通两个内网必然需要借助一个公共中继节点&#xff0c;ktconnect工具巧妙的利用k8s原生的portforward能力&#xff0c;简化了建立连接的过程&#xff0c;apiserver间接起到了中继节…...

如何在最短时间内提升打ctf(web)的水平?

刚刚刷完2遍 bugku 的 web 题&#xff0c;前来答题。 每个人对刷题理解是不同&#xff0c;有的人是看了writeup就等于刷了&#xff0c;有的人是收藏了writeup就等于刷了&#xff0c;有的人是跟着writeup做了一遍就等于刷了&#xff0c;还有的人是独立思考做了一遍就等于刷了。…...

ip子接口配置及删除

配置永久生效的子接口&#xff0c;2个IP 都可以登录你这一台服务器。重启不失效。 永久的 [应用] vi /etc/sysconfig/network-scripts/ifcfg-eth0修改文件内内容 TYPE"Ethernet" BOOTPROTO"none" NAME"eth0" DEVICE"eth0" ONBOOT&q…...

Pinocchio 库详解及其在足式机器人上的应用

Pinocchio 库详解及其在足式机器人上的应用 Pinocchio (Pinocchio is not only a nose) 是一个开源的 C 库&#xff0c;专门用于快速计算机器人模型的正向运动学、逆向运动学、雅可比矩阵、动力学和动力学导数。它主要关注效率和准确性&#xff0c;并提供了一个通用的框架&…...

无人机侦测与反制技术的进展与应用

国家电网无人机侦测与反制技术的进展与应用 引言 随着无人机&#xff08;无人驾驶飞行器&#xff0c;UAV&#xff09;技术的快速发展&#xff0c;其在商业、娱乐和军事领域的广泛应用带来了新的安全挑战。特别是对于关键基础设施如电力系统&#xff0c;无人机的“黑飞”&…...

Linux部署私有文件管理系统MinIO

最近需要用到一个文件管理服务&#xff0c;但是又不想花钱&#xff0c;所以就想着自己搭建一个&#xff0c;刚好我们用的一个开源框架已经集成了MinIO&#xff0c;所以就选了这个 我这边对文件服务性能要求不是太高&#xff0c;单机版就可以 安装非常简单&#xff0c;几个命令就…...

《Docker》架构

文章目录 架构模式单机架构应用数据分离架构应用服务器集群架构读写分离/主从分离架构冷热分离架构垂直分库架构微服务架构容器编排架构什么是容器&#xff0c;docker&#xff0c;镜像&#xff0c;k8s 架构模式 单机架构 单机架构其实就是应用服务器和单机服务器都部署在同一…...

Windows 下端口占用排查与释放全攻略

Windows 下端口占用排查与释放全攻略​ 在开发和运维过程中&#xff0c;经常会遇到端口被占用的问题&#xff08;如 8080、3306 等常用端口&#xff09;。本文将详细介绍如何通过命令行和图形化界面快速定位并释放被占用的端口&#xff0c;帮助你高效解决此类问题。​ 一、准…...

SQL注入篇-sqlmap的配置和使用

在之前的皮卡丘靶场第五期SQL注入的内容中我们谈到了sqlmap&#xff0c;但是由于很多朋友看不了解命令行格式&#xff0c;所以是纯手动获取数据库信息的 接下来我们就用sqlmap来进行皮卡丘靶场的sql注入学习&#xff0c;链接&#xff1a;https://wwhc.lanzoue.com/ifJY32ybh6vc…...