writeled.c

来自「uClinux下的一个驱动程序例子」· C语言 代码 · 共 43 行

C
43
字号
#include <stdio.h>#include <string.h>#include <malloc.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <unistd.h>#include <signal.h>#include <sys/ioctl.h>#define GET_DATA 0x4800int main(void){   int fd,count;   unsigned long rgcon;   int *spinfo=(int *)malloc(4);  printf("entered main\n");   if((fd=open("/dev/leddrv",O_RDWR))==-1)     {       perror("open eror");       exit(1);     }    rgcon=0xffffff20;    printf("open ok\n");    if((count=write(fd,(char *)&rgcon,4))!=4)       {         perror("write error");         exit(1);       }    printf("write ok\n");    if(ioctl(fd,GET_DATA,spinfo)!=0)       {         perror("ioctl erreor");         exit(1);       }   printf("spinfo=%d\n",*spinfo);   for(;;);  close(fd);  return 0;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?