📄 gprspower.c
字号:
//written by bcng xiyong,2007-7-1
//set gpj4 to zero to give a kill signal to chip ltc2950
//a guidline about how to use gpio_driver
//p[0] is the address of the iocon of the io
//p[1] is the bit place, from 0 to xx,
//for example, GPJ4, p[1] is 0x4;
//for write function, the 3th parameter, if the second bit is set, them use keep before
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <termios.h>
#include <unistd.h>
#define GPJCON 0x560000d0
#define GPJ2 0x2
#define GPHCON 0x56000070
#define GPH0 0x0
#define GPH1 0x1
#define GPH2 0x2
#define GPH3 0x3
int main(int argc,char *argv[])
{
int fd,FunctionIndex,boolON=1;
unsigned long j[2];
unsigned long h1[2],h2[2],h3[2],h4[2];
char *charon="on";
if ((argc>2)||(argc<2))
{
printf("parameter error\n");
return 0;
}
//printf("param is %s\n",*(argv+1));
if ( !strcmp( *(argv+1),"on") ) boolON=1;
else
if ( !strcmp( *(argv+1),"off") ) boolON=0;
else
{
printf("parameter error\n");
return 0;
}
fd=open("/dev/gpio",O_RDWR | O_NOCTTY);
if (fd < 0)
{
printf("can not open gpio!\n");
return 0;
}
j[0]=GPJCON;
j[1]=GPJ2; //GprsPowerControl
h1[0]=GPHCON;
h1[1]=GPH2; //TXD
h2[0]=GPHCON;
h2[1]=GPH3; //RXD
h3[0]=GPHCON;
h3[1]=GPH0; //nCTS0
h4[0]=GPHCON;
h4[1]=GPH1; //nRTS0
if (boolON)
{
printf("GPRS POWRE ON\n");
write(fd,j,1);
write(fd,h1,2);
write(fd,h2,2);
write(fd,h3,2);
write(fd,h4,2);
}
else
{
printf("GPRS POWER OFF\n");
write(fd,j,0);
write(fd,h1,0);
write(fd,h2,0);
write(fd,h3,0);
write(fd,h4,0);
}
close(fd);
return 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -