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

📄 gsm.c

📁 虚拟示波器
💻 C
字号:
#include <linux/config.h>#include <linux/utsname.h>#include <linux/kernel.h>#include <linux/major.h>#include <linux/string.h>#include <linux/fcntl.h>#include <linux/malloc.h>#include <linux/timer.h>#include <linux/sched.h>#include <linux/tty.h>#include <linux/module.h>#include <linux/init.h>#include <asm/mach/irq.h>#include <asm/hardware.h>#include <asm/io.h>#include <asm/irq.h>#include <asm/system.h>#include <linux/poll.h>#include <asm/arch/io.h>#include "dsp_arm_table.h"//#include <asm/44b.h>#define GSM_MAJOR 52/*#define   GM450RL       (*(volatile unsigned char *)CS0)#define   GM450RH       (*(volatile unsigned char *)(CS0+1))#define   LCR            (*(volatile unsigned char *)(CS0+3))#define   LSR            (*(volatile unsigned char *)(CS0+5))*//****清除状态*********/void ClearStatu(void){  char ch;  ch=LSR;  ch=GM450RL;} /************初始化*****************/ void Init_GM160(void){    char temp;    LCR = 0x80;    // DLAB=1       	GM450RL=0x0c;		GM450RH=0x0;			LCR = 0x03;	// 8bit data , 1 stop bit	GM450RH=0x0;   //no use the interrupt;		temp=LSR;			temp=GM450RL;	}/************发送字符*****************/void sendch(char ch){  while ((LSR&0x20)==0);  //maybe have problem  GM450RL=ch;}/***********接收字符*****************/void recestatu(char *receive){  char ch;  int i,time=1000000;  //time=600000;     for (i=0;i<128;i++)  {     while ((LSR&0x01)==0 && (time--)!=0); //判断是否为空以及时间是否到   if (time>0)     {      *receive++=GM450RL;      time=1000000;      }    else break;   //ClearStatu();  }    *receive='\0'; }void CMGFCMD1(void){   sendch('A');   sendch('T');   sendch('+');   sendch('C');   sendch('M');   sendch('G');   sendch('F');   sendch('=');   sendch('1');   sendch(0x0d);}void CMGL(void){   sendch('A');   sendch('T');   sendch('+');   sendch('C');   sendch('M');   sendch('G');   sendch('L');   sendch('=');   sendch('"');   sendch('R');   sendch('E');   sendch('C');   sendch(' ');   sendch('U');   sendch('N');   sendch('R');   sendch('E');   sendch('A');   sendch('D');   sendch('"');   sendch(0x0d);}/**********read message************/void CMGR(void){   sendch('A');   sendch('T');   sendch('+');   sendch('C');   sendch('M');   sendch('G');   sendch('R');   sendch('=');   sendch('2');   sendch(0x0d);}/**************************************************************************************************************- 函数名称 : GSM_Close- 函数说明 : 关闭键盘设备- 输入参数 : 无- 输出参数 : 0**************************************************************************************************************/static int GSM_Close(struct inode * inode, struct file * file){        printk("GSM Close successful\n");	return 0;}/**************************************************************************************************************- 函数名称 : GSM_Open- 函数说明 : 打开键盘设备- 输入参数 : 无- 输出参数 : 0**************************************************************************************************************/static int GSM_Open(struct inode * inode, struct file * file){ printk("GSM Open successful\n");	 return 0;}/**************************************************************************************************************- 函数名称 : GSM_Read- 函数说明 : 打开键盘设备- 输入参数 : 无- 输出参数 : 0**************************************************************************************************************/static int GSM_Read(struct file *fp, char *buf, size_t count,loff_t *ppos){   int i,j,n=0,m=0,count,flag=0;   ssize_t result=0;   char tmp[128],readback[128],ok[3],back[128];   char phonenum[12],date[18],data[64];   char phone[] = "对方号码:",dat[] = "时间:",content[] = "内容:";   char nomess[2]="ok";                              Init_GM160();    //初始化GM160   ClearStatu();   for(i=0;i<127;i++)   readback[i]=0;   readback[i]='\0';               CMGFCMD1();   for(i=0;i<3000;i++);   recestatu(readback);   CMGFCMD1();   for(i=0;i<3000;i++);   recestatu(readback);   CMGL();   //for(i=0;i<40000;i++);   recestatu(readback);      printk("%s",readback); /*********Get the Information************/   i=0;   for(i=0;i<128;i++)   { if (readback[i]==':')     break;   }   for(j=0;readback[i] != '\0';i++,j++)   tmp[j]=readback[i];   tmp[j]='\0';     count = j;   for(i=0;i<count;i++)   {     if(tmp[i]=='"')     {     n++;     switch(n)       {          case 3:                for (j=0;j<11;j++)                phonenum[j]=tmp[i+j+3];                phonenum[j] = '\0';                break;          case 5:                for(j=0;j<17;j++)                date[j] = tmp[i+j+1];                date[j] = '\0';                break;          default : break;        }      }              if((tmp[i]==0x0D) && (tmp[i+1]==0x0A))      {        j=i+2;        while(tmp[j]!=0x0D)         {  data[m] = tmp[j];            m++;            j++;         }          data[m]='\0';         break;       }                }  if (readback[23]=='O' && readback[24]=='K'){ result = copy_to_user(buf,nomess,count);}else { sprintf(back,"%s %s\n%s %s\n%s %s",phone,phonenum,dat,date,content,data); result = copy_to_user(buf,back,count);}return  result;}/**************************************************************************************************************- 函数名称 : Setup_kbd7279- 函数说明 : 键盘设备的硬件初始化函数- 输入参数 : 无- 输出参数 : 无**************************************************************************************************************//*void Setup_GSM(void){}*//**************************************************************************************************************- 函数名称 : struct file_operations Uart2_fops- 函数说明 : 文件结构- 输入参数 : 无- 输出参数 : 无**************************************************************************************************************/struct file_operations GSM_fops = {	open:	  GSM_Open,  //打开设备文件	//ioctl:	  GSM_Ioctl, //设备文件其他操作	release:    GSM_Close, //关闭设备文件        read:	  GSM_Read,  //读取设备文件};/**************************************************************************************************************- 函数名称 : int GSMInit(void)- 函数说明 : 注册键盘设备,调用初始化函数- 输入参数 : 无- 输出参数 : -1**************************************************************************************************************/int GSM_Init(void){   	int     result;	printk("Registering Gsm Device\t--- >\t");	result = register_chrdev(GSM_MAJOR, "gsm", &GSM_fops);//注册设备		if (result<0)	{		printk(KERN_INFO"[FALLED: Cannot register GSM_driver!]\n");		return result;	}	else		printk("[OK]\n");		printk("Initializing GSM Device\t--- >\t");	//Setup_GSM();		printk("GSM Driver Installed.\n");	return 0;} /***************************************************************************************************************-						结束文件                                                   -***************************************************************************************************************/

⌨️ 快捷键说明

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