wince的调试串口作为普通串口使用
生活随笔
收集整理的這篇文章主要介紹了
wince的调试串口作为普通串口使用
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
目前wince的串口0是作為調試串口用的,但是因為我的案子需要3個串口,所以要把它改為普通串口,但是開機時候還是需要打印debug信息,鑒于此,我修改如下:
debug.c中加入一行:
int DebugConsoleEnabled=1;
發送時候做判斷:
//------------------------------------------------------------------------------ // // ?Function: OEMWriteDebugByte // // ?Transmits a character out the debug serial port. // VOID OEMWriteDebugByte(UINT8 ch)? { ?? ?if(DebugConsoleEnabled == 0) return; ?? ?// Wait for transmit buffer to be empty ?? ?while ((INREG32(&g_pUARTReg->UTRSTAT) & 0x02) == 0);
?? ?// Send character ?? ?OUTREG32(&g_pUARTReg->UTXH, ch); }
//------------------------------------------------------------------------------ // // ?Function: OEMReadDebugByte // // ?Reads a byte from the debug serial port. Does not wait for a character.? // ?If a character is not available function returns "OEM_DEBUG_READ_NODATA". //
int OEMReadDebugByte()? { ?? ?UINT32 status, ch;
?? ?if(DebugConsoleEnabled == 0) return 0; ?? ?status = INREG32(&g_pUARTReg->UTRSTAT); ?? ?if ((status & 0x01) != 0) { ?? ? ? ch = INREG32(&g_pUARTReg->URXH); ?? ? ? // if ((status & UART_LINESTAT_RF) != 0) ch = OEM_DEBUG_COM_ERROR; ?? ?} else { ?? ? ? ch = OEM_DEBUG_READ_NODATA; ?? ?} ?? ?return (int)ch; }
然后在OemInit函數結束后把DebugConsoleEnabled = 0;就可以了。 不知道為何,我4.2的bsp生成的wince,用以前的串口測試程序來測試,就可以,但是我的5.0的wince,串口測試程序打開不了,無奈只能自己寫了一個簡單的c#的串口測試,串口0是ok的。后續就是串口1,串口2了。 ps:C#真是方便啊,一個從來沒有摸過c#的人就可以直接寫界面看起來并不簡單的程序。感覺和delphi的易用性差不多了。
?? ?// Send character ?? ?OUTREG32(&g_pUARTReg->UTXH, ch); }
//------------------------------------------------------------------------------ // // ?Function: OEMReadDebugByte // // ?Reads a byte from the debug serial port. Does not wait for a character.? // ?If a character is not available function returns "OEM_DEBUG_READ_NODATA". //
int OEMReadDebugByte()? { ?? ?UINT32 status, ch;
?? ?if(DebugConsoleEnabled == 0) return 0; ?? ?status = INREG32(&g_pUARTReg->UTRSTAT); ?? ?if ((status & 0x01) != 0) { ?? ? ? ch = INREG32(&g_pUARTReg->URXH); ?? ? ? // if ((status & UART_LINESTAT_RF) != 0) ch = OEM_DEBUG_COM_ERROR; ?? ?} else { ?? ? ? ch = OEM_DEBUG_READ_NODATA; ?? ?} ?? ?return (int)ch; }
然后在OemInit函數結束后把DebugConsoleEnabled = 0;就可以了。 不知道為何,我4.2的bsp生成的wince,用以前的串口測試程序來測試,就可以,但是我的5.0的wince,串口測試程序打開不了,無奈只能自己寫了一個簡單的c#的串口測試,串口0是ok的。后續就是串口1,串口2了。 ps:C#真是方便啊,一個從來沒有摸過c#的人就可以直接寫界面看起來并不簡單的程序。感覺和delphi的易用性差不多了。
總結
以上是生活随笔為你收集整理的wince的调试串口作为普通串口使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 云闪付利弊分析,0.38费率会不会封卡?
- 下一篇: 城投债和企业债的区别,了解二者的关系