2011年5月31日 星期二

KITLOutputDebugString

WINCE 6 & 7 沒有 e_to_k.h

以下參考

Kitl 中output debug message的function : KITLOutputDebugString( ),
定义在
PUBLIC\COMMON\OAK\INC\e_to_k.h:
#define KITLOutputDebugString EdbgOutputDebugString
而 EdbgOutputDebugString, implement在
PLATFORM\COMMON\BOOT\BLCOMMON\format.c
就是一般的format printing,最终输出是呼叫 OEMWriteDebugByte( )。

这个function 就要每个platform 自己implement了,所以是在OAL中:
OAL\debug.c
这个对底层的string output function 就像一般的embedded system, putchar( )一样,
用最基本的polling 方式output string:
while(TX_NOT_EMPTY);
TX = outchar;
.但是为了怕有时候用来作output的serial port有其它用途 (通常不会友好结果 ),所以整个 OEMWriteDebugByte( ) 内部用#ifdef 包围起来。

OAL\debug.c 内含
• InitDebug
• ReadDebug
• WriteDebug
InitDebug 在对应的hardware (UART) 的 PowerOn, BSPPowerOn function 中呼叫。

所以要改变debug output channel,要修改 oal\debug 的这几个function,还要将InitDebug( )放到该channel hardware 启动的地方,和 BSP PowerOn 的地方。



2011年5月29日 星期日

Improve NDIS Driver speed

接到了一個任務 要加快網路的速度
目前的速度 2Mbps 太慢

找到了一篇
http://msdn.microsoft.com/en-us/library/aa447432.aspx

http://msdn.microsoft.com/en-us/library/ms892554.aspx

2011年5月25日 星期三

Windows 7 High CPU usage

http://answers.microsoft.com/en-us/windows/forum/windows_7-performance/system-interrupts-huge-cpu-usage/2197c025-b0b8-43f2-854b-72e576373607?page=2

http://www.msfn.org/board/topic/140263-how-to-get-the-cause-of-high-cpu-usage-by-dpc-interrupt/

http://msdn.microsoft.com/en-us/performance/default
http://msdn.microsoft.com/en-us/library/ff191077.aspx

後來找到有人用 Windows SDK 中的 Windows Performance Toolkit 來分析 deferred procedure calls and interrupt activity (DPCs and ISRs).


Windows SDK WDK 中有很多好東西及工具
如 WPT ( Windows Performance Toolkit)
App Verifier
Debugging Tools for Windows (dbghelp.dll dbgengine.dll )
PREfast


還有
Network Monitor 3.4
Process Explorer

2011年5月24日 星期二

USB Driver DLL load

在設定好registry 之後 還是沒有load到我寫的driver
感覺好像是沒有 USBDeviceAttach 這個函式。
但是我明明就有 implement , 而且也注意到了 .cpp 和 .c 的不同( function name decoration)

後來再做更詳細的確認,確定是 GetProcAddress( USBDeviceAttach ) 失敗( 但LoadLibrary 成功)

我想應該是此function 沒有 export 吧,果然。
加上 __declspec( dllexport )  (在此會跟 usbdi.h 的宣告衝突) 或
在 .def 裏加上 EXPORTS USBDeviceAttach 就解決了。

GetProcAddress 原來需要函式 為 exported 。否則找不到。


DllEntry
還有,PB很多driver 都是用 DllEntry 當入口,但是在 source 必須指定好 DLLENTRY
為 DllEntry 不然還是用 DllMain 較保險

補充:
DllEntry 和 DllMain 的差別
參考 http://msdn.microsoft.com/en-us/library/aa909718(v=winembedded.60).aspx

_DllMainCRTStartup (Preferred C runtime entry point for DLL) --> DllMain
_DllEntryCRTStartup( Basic C runtime entry point for DLL) --> DllEntry

預設 DLLENTRY MACRO 是 DllMain
_DllEntryCRTStartup 和 _DllMainCRTStartup 主要的差別是 _DllEntryCRTStartup 不會處理
Exception Handling 和 call _pRawDllMain (MFC 和ATL需要)

所以如果你用DllEntry 的話 DLLENTRY 也要設成 _DllEntryCRTStartup 或 DllEntry

USB Hub Problem

工作中有遇到一個問題,有些hub 無法正確工作在 high speed mode.
最後找到一個software resolution, 假如不是High Speed Mode 時,就一直reset 直到ok.
這段code 在 BSP的 USB20 的ehci 的 chw.cpp 中。
CHW::ResetAndEnablePort()
EHCI controller 以 owner 這個bit 來決定High Speed or Full Speed.
http://mkl-note.blogspot.com/2009/02/linux-ehci.html

當不是High Speed 的時候,EHCI set Owner bit 釋放所有權給UHCI或OHCI

Device detection& handover (ref EHCI r1.0 4.2.2 p.56)

  • EHCI is port owner initially
  • device connected, port detect the change, set the port connect change bit, (if enabled) issue interrupt
  • driver check LineStatus (PORTSC[11:10])
    • Not Low-speed device, perform EHCI reset (PORTSC[8])
      • if PortEnable (PORTSC[2]) == 1, the device is a High-speed device
      • if PortEnable (PORTSC[2]) == 0, the device is a Full-speed device, set PortOwner (PORTSC[13]) to 1 to release the port ownership
    • Low-speed device, set PortOwner(PORTSC[13]) to 1 to release the port ownership

Whenever the PortOwner(PORTSC[13]) is set to 1,
  • EHCI set the disconnect change bit, (if enabled) issue interrupt, and the port reported no device connected.
While EHCI doesn't own the port, the port stay in disconnected state.
When disconnect occur, both cHC and EHCI would detect the disconnect event, and the port ownership is returned to the EHCI.

2011年5月18日 星期三

WINCE Large Memory Allocation

在寫印表機的program 時,allocate 一整張的 buffer,大小約為24MB,然後因為需要再對Image 作resize, 就出現了 E_OUTOFMEMOMRY 。也就是記憶體不足。
使用 GlobalMemoryMemoryStatus 查看系統記憶體的狀況,大約有80幾MB 的Free Physical Memory。
但是到了APP 底下卻只剩下30MB左右。
原來,在WINCE底下, 記憶體是相當受限的,每個Process 分到一個 32MB slot,而這個32MB就要包含了 DLL, heaps, stacks, virtual memory space...等所有的使用。

http://msdn.microsoft.com/en-us/library/ms836325.aspx

解決之道 就是使用 VirtualAlloc 代替 new, malloc
在MEM_RESERVE 時,如果 size 超過 2MB 且為PAGE_NOACCESS時,系統會使用 LMA (address 4200 0000~ 8000 0000) 的空間。讓出更多space 給AP。
代碼如下:

ptrVirt = VirtualAlloc( NULL, 1024 * 1024 * 32, MEM_RESERVE, PAGE_NOACCESS);
RasterDataBuffer = (BYTE*)VirtualAlloc( ptrVirt, PrintingWidth * PrintingHeight * 3, MEM_COMMIT, PAGE_READWRITE);

2011年5月3日 星期二

wxWidgets

Qt & wxWidgets