#include #include #include #include #include "tty\rs232\rs232.h" #include "tty\tty.h" #include "kernel\proc_pub.h" #define ESC 27 #define TILDA 126 #define ZAVORKA 91 int stav_aut; int poslat=1; //1 -> muzeme poslat znak int konstanta; //konstanta pro pricteni.Nemusi se delat // zvlast procedury pro com1 a com2 char predch_znak; int vypocti_del(int rychlost_prenosu); //prepocet na delitele void init(int port,int stop_bity,int rychlost_prenosu,int druh_parity) { int del_rychlost_prenosu; char kons_and; //port je RS232LINE.1 pro com1 a 2 pro com2 if (port==1) konstanta=0x100; else konstanta=0; asm { mov al,0x83 //prenosova rychlost mov dx,0x2fb //port 3fb=>dlab=1 add dx,konstanta out dx,al } del_rychlost_prenosu=vypocti_del(rychlost_prenosu); asm { mov ax,del_rychlost_prenosu mov dx,0x2f8 add dx,konstanta out dx,al mov al,0x0 //nejmensi rychlost bude 600 bd mov dx,0x2f9 //=>3f9 je nulovy add dx,konstanta out dx,al mov al,0x3 //dlab do nuly mov dx,0x2fb add dx,konstanta out dx,al mov al,0x3 shl byte ptr stop_bity,1 shl byte ptr stop_bity,1 or al,byte ptr stop_bity shl byte ptr druh_parity,1 shl byte ptr druh_parity,1 shl byte ptr druh_parity,1 or al,byte ptr druh_parity mov dx,0x2fb //stop bity, parita, atd. add dx,konstanta out dx,al mov al,0x8 mov dx,0x2fc add dx,konstanta in al,dx or al,0x8 //preruseni out dx,al mov al,0x1 //po prijeti znaku mov dx,0x2f9 add dx,konstanta out dx,al } if (port==2) kons_and=0xf7; else kons_and=0xef; //maskovaci konstanta pro 8259 asm { mov dx,0x21 //povoleni preruseni na obvodu 8259 in al,dx and al,kons_and out dx,al } /* if (port==2) kons_and=0xf7; else kons_and=0xef; //maskovaci konstanta pro 8259 asm { mov dx,0x21 //povoleni preruseni na obvodu 8259 in al,dx and al,kons_and out dx,al }*/ } //Funkce vrati rychlost prepocitanou na delitele hodin pro porty prenosu int vypocti_del(int rychlost_prenosu) { switch (rychlost_prenosu){ case 19200:return 0x06; case 9600: return 0x0c; case 4800: return 24; case 2400: return 48; case 1200: return 96; case 600 : return 192; default :return 0x03; //vetsi rychlost bude jen 38800 } } void receive_rs232_com1() { receive_rs232(1); } void receive_rs232_com2() { receive_rs232(2); } void receive_rs232(int line) { int port; unsigned char c; int i; message msg; // ty it struct tty_struct *s; if (line==RS232LINE1) port=0x3f8; else port=0x2f8; /* precteni ascii kodu ze serioveho portu do bufferu */ asm mov dx,port asm in al,dx asm mov [c], al asm mov al, 0x20 asm out 0x20, al i = tty_driver_buf.count; if (i < TTY_DRIVER_BUF_SIZE) { tty_driver_buf.terminal_nr[i] = line; //do bufferu znak a prislusny com tty_driver_buf.code[i] = c; tty_driver_buf.count++; msg.m_source = HARDWARE; msg.m_type = TTY_CHAR_INT; k_interrupt(TTY, &msg); } // try it // s=tty_addr(RS232LINE2); // *(s->tty_outhead) = c; // s->tty_outhead++; // send_rs232(s, 2); //try end } /*#if defined(RS23_TTY_1) void send_rs232_com1(struct tty_struct * tp) { //v tele ukazatel na frontu send_rs232(tp,1); } #endif #if defined(RS232_TTY_2) void send_rs232_com2(struct tty_struct * tp) { send_rs232(tp,2); } #endif*/ void send_rs232(struct tty_struct * tp,int line) { char znak; int zbytek=100; int countm,i,moc, hl; int nula = 1; //zruseni pocatecnich nul 1~stale neslojine cislo while (tp->tty_outcount) //t.j. dokud outtail nedozene outhead { znak=*tp->tty_outtail; if (znak==ESC && stav_aut==0) { stav_aut=1; poslat=0; } else { switch (stav_aut) { case 1: { switch (znak) { case TILDA:stav_aut=2;predch_znak=znak;break; case 'Z': case 'z':stav_aut=3;predch_znak=znak;break; default: { /** if ((znak>=32) && (znak <=112)) { stav_aut=0; poslat=1; } else {*/ stav_aut=4; predch_znak=znak; /// } break; } //end default } //switch znak break; } //case 1 case 2: { switch (znak) { case '0': //escape sekvence pro scroll o 1 send_rs232_znak(ESC,line); send_rs232_znak(ZAVORKA,line); send_rs232_znak('1',line); // send_rs232_znak('A',line); znak='A'; stav_aut = 0; poslat=1;break; case '1': //escape sekvence pro vymaz od aktualni pozice kurzoru send_rs232_znak(ESC,line); send_rs232_znak(ZAVORKA,line); znak='K'; stav_aut = 0; poslat=1;break; default:send_rs232_znak(predch_znak,line);stav_aut=0;poslat=1;break; } // end switch (znak) break; }//end case 2 case 3: { /// if (znak >= 32 && znak <= 112/*neni pozice*/) { /// stav_aut=0; /// send_rs232_znak(predch_znak,line); /// poslat=1; /// } /// else { //escape sekvence pro set atribut send_rs232_znak(ESC,line); send_rs232_znak(ZAVORKA,line); //ve znaku uz je atribut // prevod binarni reprezentace na znakovou countm = 2; nula = 1; while (countm != 0) { moc = 1; for (i=1;i<=countm;i++) { moc = moc * 10; } if ((znak/moc) > 0) { nula = 0; //jiz je jine cislo } if (nula != 1) { send_rs232_znak(((znak/moc)+'0'), line); } znak = znak % moc; countm--; } //while send_rs232_znak(((znak/1)+'0'), line); znak = 'm'; poslat=1; stav_aut = 0; /// } // end if a else break; } // end case 3 case 4: { /// if (znak <=32 && znak >=112 /*neni escape sekvence*/) { /// send_rs232_znak(predch_znak,line); /// stav_aut=0; /// poslat=1; /// } /// else { send_rs232_znak(ESC,line); send_rs232_znak(ZAVORKA,line); /// send_rs232_znak(predch_znak,line); countm = 2; nula = 1; while (countm != 0) { moc = 1; for (i=1;i<=countm;i++) { moc = moc * 10; } if ((predch_znak/moc) > 0) { nula = 0; //jiz je jine cislo } if (nula != 1) { send_rs232_znak(((predch_znak/moc)+'0'), line); } predch_znak = predch_znak % moc; countm--; } //while send_rs232_znak(((predch_znak/1)+'0'), line); send_rs232_znak(';',line); /// send_rs232_znak(znak,line); countm = 2; nula = 1; while (countm != 0) { moc = 1; for (i=1;i<=countm;i++) { moc = moc * 10; } if ((znak/moc) > 0) { nula = 0; //jiz je jine cislo } if (nula != 1) { send_rs232_znak(((znak/moc)+'0'), line); } znak = znak % moc; countm--; } //while send_rs232_znak(((znak/1)+'0'), line); znak='H'; poslat=1; stav_aut = 0; /// } //end if a else break; } //end case 4 } //switch stav_aut } //konec velkeho else if (poslat) send_rs232_znak(znak,line); tp->tty_outtail++; //posune ptr na konec dat v bufferu if (tp->tty_outtail==tp->tty_outqueue+TTY_OUT_BYTES) // pokud je treba zacit zase od zacatku 'outqueue' tp->tty_outtail=tp->tty_outqueue; tp->tty_outcount--; } } void send_rs232_znak(char znak,int line) { int port; if (line==RS232LINE1) port=0x3f8; else port=0x2f8; asm cli port +=5; //port=stav linky=> 2fd or 3fd asm mov dx,port cekej: asm in al,dx asm mov cl,0x60 asm and al,0x60 asm sub al,cl asm jnz cekej port -=5; asm mov al,znak asm mov dx,port asm out dx,al asm sti }