以下代码节选自2410板的GSM可扩展模块驱动,敢问哪位前辈明白如何写他的应用程序?比如发短信啦、打电话啦什么的。
#define RTHR (*(volatile unsigned char *)(0xd3000000 +0x30))
#define IER (*(volatile unsigned char *)(0xd3000000 +0x31))
#define INTR (*(volatile unsigned char *)(0xd3000000 +0x32))
#define LCR (*(volatile unsigned char *)(0xd3000000 +0x33))
#define MCR (*(volatile unsigned char *)(0xd3000000 +0x34))
#define LSR (*(volatile unsigned char *)(0xd3000000 +0x35))
#define MSR (*(volatile unsigned char *)(0xd3000000 +0x36))
#define INPUT (*(volatile unsigned char *)(0xd3000016))
#define OUTPUT (*(volatile unsigned char *)(0xd3000000))
#define MYGSM_MAJOR 254
static int gsm_Ioctl(struct inode *inode,struct file *file, unsigned int cmd, unsigned long arg);
static int gsm_Close(struct inode * inode, struct file * file);
static int gsm_Open(struct inode * inode, struct file * file);
static int gsm_Read(struct file *fp, char *buf, size_t count);
static int gsm_Write(struct file *fp, char *buf, size_t count);
static unsigned char readback[500];
static unsigned char phonenum[15],data[50];
//====================应用接口==================
struct file_operations gsm_fops =
{
write: gsm_Write,
open: gsm_Open, //打开设备文件
ioctl: gsm_Ioctl, //设备文件其他操作
release: gsm_Close, //关闭设备文件
read: gsm_Read, //读取设备文件
};
//========================读设备文件==============
static int gsm_Read(struct file *fp, char *buf, size_t count)
{
int i = 0;
while(readback != 0x0) *buf++ = readback[i++];
*buf=0x0;
return i;
}
//========================写设备文件==============
static int gsm_Write(struct file *fp, char *buf, size_t count)
{
int i;
i=0;
printk("Getting data:%s",buf);
for(i=0;i<11;i++) if(0x0 == (phonenum=*buf++)) break;
phonenum=0x0;
i=0;
while((i<40) && (*buf != 0x0)&& (i
data=0x0;
printk("\n to Phone:%s and mess:%s\n",phonenum,data);
SendShortMessage(phonenum,data);
return i;
}
//========================其他设备操作==============
static int gsm_Ioctl(struct inode *inode,struct file *file, unsigned int cmd, unsigned long arg)
{
if(cmd==0) Call_Out((char *)arg); //拨打电话
if(cmd==1) WriteCmdToGSM((char*)arg); //Write Command to GSM
if(cmd==2) Message((char *)arg); //发送短信内容
if(cmd==3) Timer3((short)arg,0); //启动定时器3
if(cmd==4) Timer3(0,0); //关闭定时器3
if(cmd==5) Set1();
if(cmd==6) Set0();
if(cmd==7) return getad();
if(cmd==8) return RunDS1820();
if(cmd==9) return wirelesssend((unsigned char)(arg&0xff));
if(cmd==10) return (int)wirelessrece();
if(cmd==11) return GetHall();
if(cmd==12) return RunSonic();
if(cmd==13) RunModem();
if(cmd==14) ModemRec(readback);
if(cmd==15) return gps();
if(cmd==16) ICCARDW((unsigned char) (arg>>16)&0xff,(unsigned char)arg&0xff);
if(cmd==17) return (int)ICCARDR((unsigned char)(0xff&arg));
if(cmd==18) cmd7279(arg);
if(cmd==19) return (int)read7279();
if(cmd==20) return icl7135();
if(cmd==21) return speed();
if(cmd==22) rs232((unsigned char)(0xff&arg));
if(cmd==23) pwm(); //Start Timer3
if(cmd==24) stepmotor(( int)(arg));
if(cmd==25) SetUart1();
if(cmd==26) SendUart1(arg);
if(cmd==27) pwm_set((arg>>16) & 0xffff, arg&0xffff); //Generate PWM control signal
if(cmd==28) Adc_Init(0); //Initial ADC on 2410chip
if(cmd==29) return Adc_Sample(0); //Sample temperature in pid_temp
if(cmd==30) iocontrol(); //
if(cmd==31) Gsm_Cmd((char *)arg); //接听或挂断
if(cmd==32) WriteToRtl16c450((char *)arg); //直接向450写入数据,不等回应
if(cmd==33) ReadFromRrl16c450((char *)arg); //直接从450读出数据
return 0;
}
//========================初始化设备
int __init gsm_Init(void)
{
int result;
int i;
printk("Registering GSM Device\n");
result = register_chrdev(MYGSM_MAJOR, "myGSM", &gsm_fops);//注册设备
BWSCON = (BWSCON & ~(BWSCON_ST4 | BWSCON_WS4 | BWSCON_DW4)) |
(BWSCON_ST4 | BWSCON_WS4 | BWSCON_DW(4, BWSCON_DW_8));
BANKCON4= BANKCON_Tacs4 | BANKCON_Tcos4 | BANKCON_Tacc14 |
BANKCON_Toch4 | BANKCON_Tcah4 | BANKCON_Tacp6 | BANKCON_PMC4;
if (result<0)
{
printk(KERN_INFO"[FALLED: Cannot register gsm_driver!]\n");
return result;
}
set_gpio_ctrl(GPIO_F0|GPIO_MODE_EINT);
//set EINT MODE
set_external_irq(IRQ_EINT0,2,0); //set falling edge triger
for(i=0;i<100;i++);
if (request_irq(IRQ_EINT0,Exint0_ISR,0,"myGSM","external INT"))
{
printk(KERN_INFO"[FALLED: Cannot register myGSM_Interrupt!]\n");
return -EBUSY;
}
if (request_irq(13,timer3_ISR,0,"myGSM","timer3"))
{
printk(KERN_INFO"[FALLED: Cannot register myGSM timer3!]\n");
}
printk("GSM Driver Installed.\n");
pt=0;
return 0;
}
void __exit gsm_Exit(void)
{
unregister_chrdev(MYGSM_MAJOR, "myGSM");
printk("You have uninstall The myGSM Driver succesfully,\n if you want to install again,please use the insmod command \n");
}
module_init(gsm_Init);
module_exit(gsm_Exit);
MODULE_LICENSE("GPL");
//=================其他略=========================
//=================end===========================
以下是我试过的,失败了。。。。。。。
int main()
{
int fd,i;
fd=open("/dev/myGSM");
if(fd<0)
{
printf("\ncann't open /dev/myGSM\n");
exit(0);
}
i=write(fd,"158****4729hello!",17);
if(i<0)
{
printf("\nERROR/\n");
exit(0);
}
return 0;
}
运行结果 ERROR
使用write接口之前是不是还需要设置什么呢,还是。。。。。。。。。。。