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

📄 s7600a.c

📁 S7600 TCP_IP网络协议接口芯片资料
💻 C
📖 第 1 页 / 共 2 页
字号:
    // Confirm 0 of S_DAV(0X08_BIT7) of S-7600A time of CYATA_COUNT                 cyata1 = 0;                         //Serial Port Data Register(0x0b)                echo = x_read(0x0b);       //Read 1 char                putch(echo);                continue;            }        }        else{            cyata1 = 0;            cyata0++;            if(cyata0 >= MAX_TRY){                                                                  // Confirm 0 of S_DAV(0X08_BIT7) of S-7600A time of MAX_TRY                break;                                          //Trial&error reaches the times of MAX_TRY            }                                                   //Break by judging there is no invalid data        }    }    strcpy(buf, atc);    len = strlen(buf);    timer(GARD_TIME);                                                                           //Wait only for GRAD_TIME for guard time of escape code    for(i = 0; i < len; i++){                       //Write ones left urgently        x_write(0x0b, (BYTE)(buf[i]));    }    timer(GARD_TIME);                           //Wait only for GRAD_TIME for guard time of escape code    cyata0 = 0;    cyata1 = 0;    while(1){                                   //Modem sends back OK result when the write of escape code        stat = x_read(0x08) & 0x80;        if(stat != 0){            cyata1++;            if(cyata1 >= CYATA_COUNT){          // Confirm 1 of S_DAV(0X08_BIT7) of S-7600A time of CYATA_COUNT                 echo = x_read(0x0b);                        //Serial Port Data Register(0x0b)                putch(echo);                                // Read 1 char                continue;            }        }        else{            cyata0++;            cyata1 = 0;            if(cyata0 >= MAX_TRY){;             // Confirm 0 of S_DAV(0X08_BIT7) of S-7600A time of MAX_TRY                break;                          //Trial&error reaches the times of MAX_TRY            }                                   //Return by judging sequence has been ended         }    }}/********************************************************//*                  HwSocketInit                        *//********************************************************///PPP connectionvoid HwSocketInit(char * name, char * password){    BYTE addr;    printf("PAP Negotiations.....");//Make serial port to hardware control when the dial line connected    x_write( 0x08, 0x21 );                      //SCTL = Hardware ccontrol, HWFC = active    x_write( 0x62, 0x0a );             //PPP_Max_Retry = 0x0a    x_write( 0x60, 0x60 );             //PPP_Control_Status setting//Write of PAP strings    x_write( 0x64, (BYTE) strlen(name) ); //username    while( *name )      x_write( 0x64, *name++ );        timer(1);    x_write( 0x64, (BYTE) strlen(password) ); //password    while( *password )      x_write( 0x64, *password++ );     x_write( 0x64, 0  );               //Null Termination    x_write( 0x60, 0x62 );             //PPP Enable    while ( ( x_read( 0x60 ) & 0x01 ) == 0x00 ){        if(kbhit() != 0){                                                          //Confirming PPP_Up                getch();                                                                            //If something is input before PPP\Up confirmed                 abort();                                    //Disconnect PPP and dial line,End         }    }    printf("Done. PPP Connction Established. \n");	printf("ISP assigned our IP Address = ");    for(addr = 0x13; addr >= 0x10; addr--){                                        //PPP_Up confirmed        if(addr == 0x10){                           //Display IP address allocated by server            printf("%d\n", x_read(addr));        }        else{            printf("%d.", x_read(addr));        }    }}/********************************************************//*                          HwSocketClose               *//********************************************************///Close PPPvoid HwSocketClose(void){    printf("PPP Disable.....");    x_write( 0x60, 0x00 );                  //PPP Disenable    while ( ( x_read( 0x60 ) & 0x01 ) != 0x00 )        ;                                                                               //Confirming PPP_Down    printf("Done. PPP Connction Down.\n");                                              //PPP_Down confirmed}/********************************************************//*                      HwTcpOpen                       *//********************************************************///Require TCP connection as serverint HwTcpOpen(void){    BYTE addr;		printf("Tcp Connect.....");    x_write( 0x20, 0x00 );                                                         //Select Socket 0    x_write( 0x22, 0x10 );                                                         //Reset Socket 0    x_write( 0x3c, 101);               //Destination IP address    x_write( 0x3d, 4);                                                    //Select DAYTIME server    x_write( 0x3e, 163);    x_write( 0x3f, 132);    x_write( 0x36, 13);                //Destination port    x_write( 0x37, 0);                                                  //Port number of DAYTIME    x_write( 0x22, 02);                //TCP Clinet Mode    x_write( 0x24, 01);                                                            //Activate Socket 0    while ((x_read(0x23) & 0x10) != 0x10){                                         //Confirming TCP connection        if(nstep() == FALSE){                       // If something is input before TCP connection            return(FALSE);                              //Get instruction for procedure followed        }    }    printf("Done. TCP Connection Established.\n\n");	printf("Time Server IP address = ");	 for(addr = 0x3f; addr >= 0x3c; addr--)	 {                                               if(addr == 0x3c)	//Display IP address of server		{                                printf("%d\n", x_read(addr));        }        else		{            printf("%d.", x_read(addr));        }	 }    return(TRUE);                               //TCP connection confirmed}/********************************************************//*                      HwTcpClose                      *//********************************************************///From CLOSE_WAIT status of TCP to CLOSE statusint HwTcpClose(void){    printf("Tcp Close....");    x_write( 0x20, 0x00 );                                                        //Select Socket 0    x_write(0x24,0x00);                                                           //Deactivate Socket 0    while (x_read(0x23) & 0x10){                                                  //Confirming TCP No connection        if(nstep() == FALSE){                                                             //If something input before TCP No connection confirmed            return(FALSE);                              // Get instruction of procedure followed        }    }                                                                             //Confirming TCP No connection    x_write( 0x22, 0x10 );                                                        //Reset Socket 0    printf("Done. TCP No Connection Established. \n");    return(TRUE);                                                                 //TCP CLOSE status}/********************************************************//*                      HwTcpState                      *//********************************************************///Obtain TCP Stateint HwTcpState(int disp){//disp : Displayed or not    BYTE stat;    stat = x_read(0x23);    if(disp == TRUE){        printf("TCP State is %02X ", stat);        stat = stat & 0x0f;        switch(stat){            case(0x0):printf("CLOSED.\n");      break;            case(0x1):printf("SYN_SENT.\n");    break;            case(0x2):printf("ESTABLISHED.\n"); break;            case(0x3):printf("CLOSE_WAIT.\n");  break;            case(0x4):printf("LAST_ACK.\n");    break;            case(0x5):printf("FIN_WAIT1.\n");   break;            case(0x6):printf("FIN_WAIT2.\n");   break;            case(0x7):printf("CLOSING.\n");     break;            case(0x8):printf("TIME_WAIT.\n");   break;            case(0x9):printf("LISTEN.\n");      break;            case(0xa):printf("SYN_RECVD.\n");   break;            default:                            break;        }    }    return(stat & 0x0f);}/********************************************************//*                      HwTcpRcv                        *//********************************************************///Display Socket data//S-7600A goes CLOSE_WAIT state since DAYTIME server sends FIN after the service finishedint HwTcpRcv(void){    while(1){        if(nstep() == FALSE){                       //If something input before display ended            return(FALSE);                              //Get instruction for procedure followed        }        if(x_read(0x22) & 0x10){                    //When validity of Socket data is confirmed            putch(x_read(0x2e));                        //Read 1 char from Socket data Resister            continue;                                   //Display        }        else if(HwTcpState(FALSE) == 3){            //If the Socket data is invalid and            break;                                      //TCP is CLOSE_WAIT state        }                                       //it returns because it judges the all the data are displayed    }    return(TRUE);      }/********************************************************//*                      nstep                           *//********************************************************///Get instruction for procedure followedint nstep(void){    int keyPressed;    if(kbhit() != 0){                               //If something is input, execute following statement        //printf("User key in for next step.\n");         //If there's no input, return immediately        getch();        while(1){            //printf("Push Key!!  C : Continue    E : Exit    > ");            //keyPressed = toupper(getch()); 			keyPressed = 'C';                                            //Display menu            printf("\n");            if (keyPressed == 'C'){                                                             //Return when C is input                return(FALSE);            }            else if (keyPressed == 'E'){                                                        //If E is input                abort();                                            //Disconnect PPP and Dial line and End            }        }    }    return(TRUE);}/********************************************************//*                      x_write(S7600A)                 *//********************************************************///Driver of 1byte data write for S-7600A SDK Board for ISA BUS  void x_write( BYTE addr, BYTE data ){    BYTE busyx;    do {                                                        //Confirming busyx=1         busyx = ReadPCPort( HW_PORT_BUSYX ) & 0x80;    }while (busyx == 0);                                                                                        //busyx = 1 is confirmed    WritePCPort( HW_PORT_INDEX, addr );                     //Set index register address    WritePCPort( HW_PORT_DATA, data );        //Write data at S-7600A index register}/********************************************************//*                      x_read(S7600A)                  *//********************************************************///Driver of 1byte data read for S-7600A SDK Board for ISA BUS  BYTE x_read ( BYTE addr ){    BYTE busyx;    do {                                                        //Confirming busyx = 1        busyx = ReadPCPort( HW_PORT_BUSYX ) & 0x80;    }while (busyx == 0);                                                                                         //busyx = 1 is confirmed    WritePCPort( HW_PORT_INDEX, addr );                     //Set index register address    ReadPCPort( HW_PORT_INDEX );                            //Read index register    do {                                                                                                           //Confirming busyx = 1        busyx = ReadPCPort( HW_PORT_BUSYX ) & 0x80;    }while (busyx == 0);                                    //busyx = 1 is confirmed    return(ReadPCPort( HW_PORT_DATA ));                     //Read data at S-7600A index register}/********************************************************//*                     timer                            *//********************************************************/void timer(int sec){//sec : Wait time. Unit is Sec. And there's +1 Sec tolerance at max    long    oldtime, newtime;    int i = -1;        time(&oldtime);    while(1){       time(&newtime);       if(newtime != oldtime){          oldtime = newtime;          i++;//        printf("%ds-",i);       }       if(i >= sec){//        printf("\n");          return;       }    }}

⌨️ 快捷键说明

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