⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test.c

📁 基于ARM的44B0开发板的嵌入式LINUX驱动程序的原代码
💻 C
字号:
#include <linux/module.h>#include <linux/kernel.h>#include <linux/types.h>#include <linux/fs.h>#include <linux/mm.h>#include <linux/errno.h>#include <asm/uaccess.h>#include <asm/arch/s3c44b0x.h>int test_major=254;#define Non_Cache_Start	(0x2000000)
#define Non_Cache_End 	(0xc000000)#define BEEP_CMD_SIGNAL 0/************************* PORTS ****************************/
static int  ledman_ioctl(struct inode * inode, struct file * file,unsigned int cmd, unsigned long arg);
void Port_Init(void)
{
    //ADB V1.0 B/D Status
    //USB D12SUSPD 
    //    PC0
    //LED D0  D1  D2
    //	  PC1 PC2 PC3
    //KEY K0  K1  K2  K3
    //	  PG4 PG5 PG6 PG7

    //CAUTION:Follow the configuration order for setting the ports. 
    // 1) setting value 
    // 2) setting control register 
    // 3) configure pull-up resistor.  
	     
    //16bit data bus configuration  
    //PORT A GROUP
    //(*(volatile unsigned *)S3C44B0X_PCONA[9:0]
    //|BIT9  |.......................................................|BIT0
    //|ADDR24|ADDR23|ADDR22|ADDR21|ADDR20|ADDR19|ADDR18|ADDR17|ADDR16|ADDR0		      
    //|     0|     1|	  1|     1|     1|     1|     1|	 1|     1|    1
    (*(volatile unsigned *)S3C44B0X_PCONA)=0x1ff;	

    //PORT B GROUP
    //(*(volatile unsigned *)S3C44B0X_PCONB[10:0]
    //|BIT10|....................................................|BIT0
    //|nGCS5|nGCS4|nGCS3|nGCS2|nGCS1|nWBE3|nWBE2|nSRAS|nSCAS|SCLK|SCKE
    //|    1|    1|    1|	 1|    1|    1|    1|	 1|    1|   1|   1
    (*(volatile unsigned *)S3C44B0X_PDATB)=0x3ff;
    (*(volatile unsigned *)S3C44B0X_PCONB)=0x3ff;
    
    //PORT C GROUP
    //BUSWIDTH=16
    //PORT C GROUP
    //(*(volatile unsigned *)S3C44B0X_PCONC[31:0]
    //|GPC15|....................................................................|    GPC0
    //|BIT31|....................................................................|    BIT0
    //|nCTS0|nRTS0|RXD1|TXD1|nCTS1|nRTS1|nEL|nDISP|VD4|VD6|VD5|VD7|LED2|LED1|LED0|D12SUSPD
    //|   00|   00|  11|  11|   00|   00| 01|   01| 11| 11| 11| 11|  01|  01|  01|      01
    //(*(volatile unsigned *)S3C44B0X_PUPC[15:0]
    //|    0|    0|   1|   1|    0|    0|  0|    0|  1|  1|  1|  1|   0|   0|   0|       0
    (*(volatile unsigned *)S3C44B0X_PDATC)=0xffff;	//All I/O Is High
    (*(volatile unsigned *)S3C44B0X_PCONC)=0x0f05ff55;	
    (*(volatile unsigned *)S3C44B0X_PUPC)=0x30f0;	//PULL UP RESISTOR should be enabled to I/O

    //PORT D GROUP
    //(*(volatile unsigned *)S3C44B0X_PCOND
    //| BIT15|.........................|BIT0 
    //|VFRAME|VM|VLINE|VCLK|VD3|VD2|VD1|VD0
    //|    10|10|   10|	 10| 10| 10| 10| 10  
    (*(volatile unsigned *)S3C44B0X_PDATD)=0xff;
    (*(volatile unsigned *)S3C44B0X_PCOND)= 0x0;
	(*(volatile unsigned *)S3C44B0X_PUPD) = 0x0;
//These pins must be set only after CPU's internal LCD controller is enable
	
	//(*(volatile unsigned *)S3C44B0X_PCOND=0xaaaa;	
    //(*(volatile unsigned *)S3C44B0X_PUPD=0xff;

    //PORT E GROUP
    //(*(volatile unsigned *)S3C44B0X_PCONE
    //| BIT17 |..............................|BIT0
    //|CODECLK|PE7|PE6|BEEP|PE4|PE3|RXD0|TXD0| PE0
    //|     10| 01| 01|  01| 01| 01|  10|  10|  00
    //|(*(volatile unsigned *)S3C44B0X_PUPE[7:0]
    //        |  0|  0|   0|  0|  0|   1|   1|   0
    (*(volatile unsigned *)S3C44B0X_PDATE)=0x1ff;  	//All I/O Is High
    (*(volatile unsigned *)S3C44B0X_PCONE)=0x25568;	//All NC is INPUT	
    (*(volatile unsigned *)S3C44B0X_PUPE)=0x0df;	//PE8 do not have programmable pull-up resistor.  

    //PORT F GROUP
    //(*(volatile unsigned *)S3C44B0X_PCONF[21:0]
    //| BIT21|....................................|  BIT0
    //|IISCLK|PF7|IISDO|IISLRCK|PF4|PF3|PF2|IICSDA|IICSCL
    //|   100|000|  100|    100| 00| 00| 00|    10|    10
    //(*(volatile unsigned *)S3C44B0X_PUPF[8:0]
    //|     1|  0|    1|      1|  0|  0|  0|     1|     1
    (*(volatile unsigned *)S3C44B0X_PDATF)=0x1ff;	//All I/O Is High
    (*(volatile unsigned *)S3C44B0X_PCONF)=0x20900a;//All NC is INPUT
    (*(volatile unsigned *)S3C44B0X_PUPF)=0x163;

    //PORT G GROUP
    //(*(volatile unsigned *)S3C44B0X_PCONG[15:0]
    //|BIT15|....................................|   BIT0
    //| KEY3|KEY2|KEY1|KEY0|EXINT3|EXINT2|NET_INT|USB_INT
    //|   11|  11|  11|  11|    11|    11|     11|     11
    (*(volatile unsigned *)S3C44B0X_PDATG)=0xff;
    (*(volatile unsigned *)S3C44B0X_PCONG)=0x00ff;	//KEY0~KEY3¶šÒåΪI/O,²ÉÓòéѯ·œÊœ
    			//(*(volatile unsigned *)S3C44B0X_PCONG=0xffff,KEY0~KEY3¶šÒåΪÖжÏ,	
    			
    (*(volatile unsigned *)S3C44B0X_PUPG)=0x0;		//should be enabled  
    
    (*(volatile unsigned *)S3C44B0X_SPUCR)=0x7; 	//D15-D0 pull-up disable
    
(*(volatile unsigned *)S3C44B0X_EXTINT)=0x0;	//All EXTINT0-7 Low level interrupt
	//Define the Non_Cache area
(*(volatile unsigned *)S3C44B0X_NCACHBE0)=0;//((Non_Cache_End>>12)<<16)|(Non_Cache_Start>>12); 
}

void Delay(int time)
{
    int i;
	int delayLoopCount=400;

    for(;time>0;time--)
	for(i=0;i<delayLoopCount;i++);
}

void Beep(int BeepStatus)
{
	//PE5 Low available
	if (BeepStatus==0)
	(*(volatile unsigned *)S3C44B0X_PDATE)=(*(volatile unsigned *)S3C44B0X_PDATE)&0x1df;
	else
	(*(volatile unsigned *)S3C44B0X_PDATE)=(*(volatile unsigned *)S3C44B0X_PDATE)|0x020;
}static intledman_ioctl(	struct inode * inode,	struct file * file,	unsigned int cmd,	unsigned long arg){		int		i;	if (cmd == BEEP_CMD_SIGNAL) {		printk("beep0\n");                Beep(0);		return(0);	}        else{         printk("beep1\n");         Beep(1);        }		return  0;}struct file_operations test_fops={ioctl: ledman_ioctl,	/* ledman_ioctl */};int test_init(void){int result;result=register_chrdev(254,"test",&test_fops);if(result<0){printk("test:cannot get major number!\n");return result;}return 0;}void cleanup_module(void){unregister_chrdev(test_major,"test");}

⌨️ 快捷键说明

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