/* * コンソールポートへの強制一文字出力 (割込みなし) */ void SerialRawPutc(INT chr) { SIOPCB * siopcb = &siopcb_table[CONSOLE_PORTID - 1]; assert(siopcb != NULL); if(!BITTEST(siopcb->Flag, SIO_STA_OPEN)) return; switch(SIO_TYP(siopcb->Flag)) { case SIO_TYP_CONSOLE: SerialConsole_PutChar(siopcb, chr, FALSE); break; case SIO_TYP_TTY: WinConsole_PutChar(siopcb, chr, FALSE); break; case SIO_TYP_SCRBUF: ScreenBuffer_PutChar(siopcb, chr, FALSE); break; case SIO_TYP_RAWSIO: RawSerial_PutChar(siopcb, chr, FALSE); break; } }
/* * シリアルI/Oポートのオープン */ SIOPCB * sio_opn_por(ID siopid, VP_INT exinf) { BOOL success; SIOPCB * siopcb = GET_SIOPCB(siopid); assert(siopcb != NULL); siopcb->exinf = exinf; success = TRUE; switch(SIO_TYP(siopcb->Flag)) { case SIO_TYP_CONSOLE: HALExecuteProcedure(CreateSerialConsole,siopcb); break; case SIO_TYP_TTY: WinConsole_CreatePort(siopcb); break; case SIO_TYP_SCRBUF: HALExecuteProcedure(ScreenBuffer_CreatePort,siopcb); break; case SIO_TYP_RAWSIO: HALExecuteProcedure(RawSerial_CreatePort,siopcb); break; default: success = FALSE; } if(success == TRUE) BITSET(siopcb->Flag, SIO_STA_OPEN); return siopcb; }
inline BOOL hw_port_getready(SIOPCB *p) { switch(SIO_TYP(p->flags)) { case SIO_TYP_M32RUART: return (sil_reb_mem((void *)(SIOSTS(p->port)+3)) & 0x4) != 0 ? TRUE : FALSE; } return FALSE; }
/* * シリアルI/Oポートからの文字受信 */ INT sio_rcv_chr(SIOPCB * siopcb) { switch(SIO_TYP(siopcb->flags)) { case SIO_TYP_M32RUART: return sil_reb_mem((void *)(SIORXB(siopcb->port)+3)); } return -1; }
/* * シリアルI/Oポートのクローズ */ void sio_cls_por(SIOPCB *siopcb) { switch(SIO_TYP(siopcb->flags)) { case SIO_TYP_M32RUART: /* 送受信動作を禁止する */ sil_wrb_mem((void *)(SIOCR(siopcb->port)+3), 0); break; } }
/* * シリアルI/Oポートのオープン */ SIOPCB * sio_opn_por(ID siopid, VP_INT exinf) { SIOPCB * siopcb = GET_SIOPCB(siopid); siopcb->exinf = exinf; switch(SIO_TYP(siopcb->flags)) { case SIO_TYP_M32RUART: /* UART初期化 */ sil_wrb_mem((void *)(SIOCR(siopcb->port)+3), 0); /* ポートを開く(UART0) */ sil_wrb_mem((void *)PDATA(5), 0); sil_wrb_mem((void *)PDIR(5), 0x80); /* UART, Non-parity, 1 stop-bit */ sil_wrb_mem((void *)(SIOMOD0(siopcb->port)+3), 0); /* 8bit, internal clock */ sil_wrh_mem((void *)(SIOMOD1(siopcb->port)+2), 0x0800); /* M32R(32102) - f(BLK)=16MHzで115200bps */ sil_wrh_mem((void *)(SIOBAUR(siopcb->port)+2), SERIAL_CLKDIV); sil_wrb_mem((void *)(SIORBAUR(siopcb->port)+3), SERIAL_CLKCMP); /* 送受信割込み発生許可 */ sil_wrh_mem((void *)(SIOTRCR(siopcb->port)+2), 0x0006); /* ステータスクリア, 送受信動作開始 */ sil_wrb_mem((void *)(SIOCR(siopcb->port)+2), 0x3); sil_wrb_mem((void *)(SIOCR(siopcb->port)+3), 0x3); /* 受信割込み受付許可 */ sil_wrh_mem((void *)(ICUCR(SIO,siopcb->port)+2), 0x1000); sil_wrh_mem((void *)(ICUCR(SIO,siopcb->port)+6), 0x1000); /* TxD,RxDピン有効(UART0) */ sil_wrh_mem((void *)PMOD(5), 0x5500); break; } return siopcb; }
/* * シリアルI/Oポートのクローズ */ void sio_cls_por(SIOPCB *siopcb) { assert(siopcb != NULL); switch(SIO_TYP(siopcb->Flag)) { case SIO_TYP_CONSOLE: HALExecuteProcedure(SerialConsole_FinalRelease,siopcb); break; case SIO_TYP_TTY: WinConsole_ClosePort(siopcb); break; case SIO_TYP_SCRBUF: HALExecuteProcedure(ScreenBuffer_ClosePort,siopcb); break; case SIO_TYP_RAWSIO: HALExecuteProcedure(RawSerial_ClosePort,siopcb); break; } }
/* * シリアルI/Oポートへの文字送信 */ BOOL sio_snd_chr(SIOPCB *siopcb, INT chr) { BOOL result; assert(siopcb != NULL); switch(SIO_TYP(siopcb->Flag)) { case SIO_TYP_CONSOLE: result = SerialConsole_PushChar(siopcb, chr); break; case SIO_TYP_TTY: result = WinConsole_PutChar(siopcb, chr, TRUE); break; case SIO_TYP_SCRBUF: result = ScreenBuffer_PutChar(siopcb, chr, TRUE); break; case SIO_TYP_RAWSIO: result = RawSerial_PutChar(siopcb, chr, TRUE); break; } return result; }