📄 testdriver.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>
#define Non_Cache_Start (0x2000000)
#define Non_Cache_End (0xc000000)
#define BEEP_CMD_SIGNAL 0
int test_major=254;
/************************* PORTS ****************************/
static int ledman_ioctl(struct inode * inode, struct file * file,unsigned int cmd, unsigned long arg);
void Port_Init(void)
{
(*(volatile unsigned *)S3C44B0X_PCONA)=0x1ff;
(*(volatile unsigned *)S3C44B0X_PDATB)=0x3ff;
(*(volatile unsigned *)S3C44B0X_PCONB)=0x3ff;
(*(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
(*(volatile unsigned *)S3C44B0X_PDATD)=0xff;
(*(volatile unsigned *)S3C44B0X_PCOND)= 0x0;
(*(volatile unsigned *)S3C44B0X_PUPD) = 0x0;
(*(volatile unsigned *)S3C44B0X_PDATE)=0x1ff;
(*(volatile unsigned *)S3C44B0X_PCONE)=0x25568;
(*(volatile unsigned *)S3C44B0X_PUPE)=0x0df; //pull-up resistor.
(*(volatile unsigned *)S3C44B0X_PDATF)=0x1ff; //All I/O Is High
(*(volatile unsigned *)S3C44B0X_PCONF)=0x20900a;//All NC is INPUT
(*(volatile unsigned *)S3C44B0X_PUPF)=0x163;
(*(volatile unsigned *)S3C44B0X_PDATG)=0xff;
(*(volatile unsigned *)S3C44B0X_PCONG)=0x00ff;
(*(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
(*(volatile unsigned *)S3C44B0X_NCACHBE0)=0;//((Non_Cache_End>>12)<<16)|(Non_Cache_Start>>12);
}
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 int ledman_ioctl(struct inode * inode,struct file * file,unsigned int cmd,unsigned long arg)
{
int i;
if (cmd == BEEP_CMD_SIGNAL)
{
printk("beep 0\n");
Beep(BEEP_CMD_SIGNAL);
return(0);
}
else
{
printk("beep 1\n");
Beep(1);
}
return 0;
}
struct file_operations test_fops =
{
ioctl: ledman_ioctl, /* ledman_ioctl */
};
int test_init(void)
{
int result;
result=register_chrdev(test_major,"test",&test_fops);
if(result<0)
{
printk("test:can not 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 + -