顯示具有 WinCE Development 標籤的文章。 顯示所有文章
顯示具有 WinCE Development 標籤的文章。 顯示所有文章

星期三, 5月 18, 2011

Embedded System - LCD Device Driver Notes

LCD 驅動程式概念與實作

基本概念:

目前市面上見得到的 LCD, 在資料傳送上有兩種, 一種是 Sync(Synchronous) mode, 一種是 DE(Data Enable) mode, 有的 Panel 可用程式控制, 可以選擇使用其中一種.
在接腳上, DE Mode 通常只要 DE, Clock 與 RGB, 而 Sync Mode 則需要 VSync, HSync, Clock 與 RGB, 有些可程式控制的 Panel 則還會需要 SPI 來做控制, 僅管如此, 各面板廠做法都不同, 當然有例外, 像是有的面板 DE Mode 可能還要接 VSync, 此外 RGB 則可能有 16(565)bit, 18(666)bit 等等, 所有接法請依照該面板的 datasheet 為準.

DE Mode 比較簡單, 通常是 DE 腳 assert 時, 表示接受資料傳送, 這時 LCD Control 會從 RGB 資料線傳送資料給 LCD Panel, 現在大部份 Panel 大都採用此種模式.

Sync Mode 大致上來說, 則是在 VSync assert 然後 back porch n 個 clock 後, 接著 HSync assert 然後 back porch n 個 clock 後, 開始傳送這條水平線的資料, 到下一條水平線時再 front porch + HSync assert + back porch 一次, 一直到整張傳完, 準備傳下一張時, 再次 front porch + assert VSync + back porch, 當然這邊只是說個大概的工作原理, 一切基準都要看該面板 datasheet 為準.

所以由此可知, 垂直掃描頻率基本上就等於整張的掃描頻率, 也因此, 螢幕掃描頻率通常都是以垂直掃描為準就是這個道理.

Note: assert = 表示該接腳信號為有效, 一切以 datasheet 為準, 例如是 low active 時, 接腳為 low 電位就是 assert, 反之則是 high 為 assert.


LCD Panel Timing:

以 Data Image 的七吋面板 FG0700 為例, 這面板的解析度為 800x480, 但是加上無效區為 900x500, 我們知道 dot clock 的公式是:

dot clock = horizontal pixels * vertical pixels * frame rate

注意這邊所謂的 horizontal 與 vertical pixels 都包含 active pixels 與 blink pixels, 因此這張 panel 的 dot clock 為:

900 * 500 * 60 = 27 MHz

picoseconds of per pixel 的公式是 :

1e12 / dot clock

所以每個 pixel 的 ps (picoseconds, pico = e-12):

1 / 27e6 Hz = 37037e-12

水平掃描(horizontal scan-line)一條所需時間的公式是:

horizontal scan-line = horizontal pixels * picoseconds of per pixel

所以每條水平掃描的所需時間為:

900 * 37.037e-9 = 33.333e-6

所以我們知道水平掃描頻率(scan rate)為:

1 / 33.333e-6 = 30 KHz

而整個面板掃完一次需要的時間公式為:

vertical scan-line = vertical pixels * picoseconds of per pixel

500 * 33.333e-6 = 16.6665e-3

由此可以得知垂直掃描頻率為:

1 / 16.6665e-3 = 60 Hz

這意思就是這個面板一秒會更新 60 次.


實作:

參考 Datasheet 可以知道, 在 HSync 之前的叫做 HFP (Horizontal front porch), 在 HSync 之後的叫做 HBP (Horizontal back porch).
但是在 PXA3xx LCD Controller Register 裡叫做 BLW, ELW, 而在 Linux Frame Buffer Driver 裡的 struct 則叫做 left margin, right margin, 這要怎樣對應呢?
這也非常簡單, 參考 Documentatoin/fb/framebuffer.txt 與 PXA3xx Datasheet :

- left_margin: time from sync to picture
- right_margin: time from picture to sync
- upper_margin: time from sync to picture
- lower_margin: time from picture to sync

BLW + 1 = HBP
ELW + 1 = HFP
BFW = VBP
EFW = VFP

因此:

left_margin = HBP = BLW - 1
right_margin = HFP = ELW - 1
upper_margin = VBP = BFW
lower_margin = VFP = EFW

然後參考 datasheet 把正確的值填到 struct 裡, 開機 fb driver 正確啟動後, 應該可以在 LCD 看到一隻企鵝, 至於 WinCE 的改法也很簡單, 以 PXA3xx WinCE BSP 為例, 可以在 display driver 的 panel 目錄裡找到相對應硬體的結構, 改一改就好了, 比較麻煩的是一些可程式的 LCD, 這類 LCD 通常就要再送 SPI command 才會動.

星期五, 10月 22, 2010

WinCE 6 的 coredll 編譯錯誤解決方式

WinCE 6 的 coredll 編譯錯誤解決方式。

coredll.def : error LNK2001: unresolved external symbol RegistryBatchNotification
coredll.def : error LNK2001: unresolved external symbol RegistryCloseNotification
coredll.def : error LNK2001: unresolved external symbol RegistryDeleteValue
coredll.def : error LNK2001: unresolved external symbol RegistryGetDWORD
coredll.def : error LNK2001: unresolved external symbol RegistryGetString
coredll.def : error LNK2001: unresolved external symbol RegistryNotifyApp
coredll.def : error LNK2001: unresolved external symbol RegistryNotifyCallback
coredll.def : error LNK2001: unresolved external symbol RegistryNotifyMsgQueue
coredll.def : error LNK2001: unresolved external symbol RegistryNotifyWindow
coredll.def : error LNK2001: unresolved external symbol RegistrySetDWORD
coredll.def : error LNK2001: unresolved external symbol RegistrySetString
coredll.def : error LNK2001: unresolved external symbol RegistryStopNotification
coredll.def : error LNK2001: unresolved external symbol RegistryTestExchangeDWORD

這個錯誤是 coredll_ALL.lib 和 k.coredll_ALL.lib 的依賴性錯誤。

解決方法:
把這兩個檔案砍掉,通常會在專案的 reldir (release) 目錄裡, 或 clean & rebuild 也可以。

星期一, 6月 14, 2010

Windows CE 5, 6 Device Driver Concept

Windows CE 5, 6 Device Driver Concept

Windows CE Device Driver 依架構可分為 Layered driver 與 Monolithic driver:

Layered driver: divided driver to PDDs and MDDs (MDD 與 PDD 分開)

Monolithic driver: combines all PDDs and MDDs into one driver. (MDD 與 PDD 合在一起)

大部份的 Windows CE Driver 是由 PDD (Platform Dependent Driver) 與 MDD (Model Device Driver) 所組成的.

PDD: Platform Dependent Driver (平台相關驅動, 負責與 MDD 與 Hardware 溝通, 提供 DDSI 給 MDD 呼叫)

MDD: Model Device Driver (邏輯層, 介於 PDD 與 OS 中間, 提供 DDI 給 OS 呼叫)

DDSI (Device Driver Service Provide Interface): 一般由 PDD layer 所提供(expose)給 MDD layer 呼叫使用.

DDI (Device Driver Interface): 由 MDD 提供(expose)給 OS 呼叫的介面.

* Monolithic 理論上不會有 DDSI.

* MDD should not require any modify.
 MDD 提供了標準介面 DDI 給 OS 呼叫如 xxx_Open, xxx_Close, xxx_Init, 並透過 DDSI 來呼叫 PDD 提供的 function.

* PDD may need modify to fit your hardware platform.
 PDD 提供 DDSI functions 給 MDD 呼叫, 但如果是 monolithic driver 則不需要 DDSI, 因為可以直接呼叫函式.

physical devices: network adapters, timers, and universal asynchronous receiver-transmitters (UARTs).

virtual devices: file system.

sream interfaces driver (基本空架構, 不含 power management):

////////////////////////////////////////////////////////////////////////////////

#include
#include
#include
#include
#include

#define XXX_MSG_INFO    0
#define XXX_MSG_DEBUG   0
#define XXX_MSG_ERROR   1
#define XXX_OPEN_ALLOWED 5L

////////////////////////////////////////////////////////////////////////////////

#define IOCTL_GET_SOMETHING 1
#define IOCTL_SET_SOMETHING 2

////////////////////////////////////////////////////////////////////////////////

static DWORD g_dwOpenCount = 0;

////////////////////////////////////////////////////////////////////////////////

DWORD XXX_Init(DWORD dwContext)
{
    /* reading values from registry */
    HKEY hKey;

    RETAILMSG(XXX_MSG_DEBUG, (TEXT("[XXX] DEBUG: XXX_Init:: dwContext (%s).\r\n"), dwContext));

    hKey = OpenDeviceKey((LPCTSTR)dwContext);
    if (!hKey) {
        RETAILMSG(XXX_MSG_ERROR, (TEXT("[XXX] ERROR: Failed to open device key (%s).\r\n"), dwContext));
    } else {
        // Read values from registry if needed
        RegCloseKey (hKey);
    }

    RETAILMSG(XXX_MSG_DEBUG, (TEXT("[XXX] INFO: XXX_Init Sucessfully. \r\n")));

    return 1;
}


BOOL XXX_Deinit(DWORD dwContext)
{
    RETAILMSG(XXX_MSG_DEBUG, (TEXT("[XXX] DEBUG: XXX_Deinit:: dwContext (%s).\r\n"), dwContext));
    return TRUE;
}   // XXX_Deinit


DWORD XXX_Open(DWORD dwData, DWORD dwAccess, DWORD dwShareMode)
{
    if (g_dwOpenCount >= XXX_OPEN_ALLOWED) {
        return 0;
    }
    g_dwOpenCount++;
    RETAILMSG(XXX_MSG_DEBUG, (TEXT("[XXX] DEBUG: XXX_Open:: dwContext(%d), dwOpenCount(%d).\r\n"), dwData, g_dwOpenCount));
    return dwData;
}   // XXX_Open


BOOL XXX_Close(DWORD Handle)
{
    if (!g_dwOpenCount) {
        return FALSE;
    }
    g_dwOpenCount--;
    RETAILMSG(XXX_MSG_DEBUG, (TEXT("[XXX] DEBUG: XXX_Close:: dwContext(%d), g_dwOpenCount(%).\r\n"), Handle, g_dwOpenCount));
    return TRUE;
}   // XXX_Close


BOOL XXX_IOControl(
    DWORD Handle,
    DWORD dwIoControlCode,
    PBYTE pInBuf,
    DWORD nInBufSize,
    PBYTE pOutBuf,
    DWORD nOutBufSize,
    PDWORD pBytesReturned
    )
{

    BOOL bErr = FALSE;
    UINT32 param1;
    UINT32 param2;

    RETAILMSG(XXX_MSG_DEBUG, (TEXT("[XXX] DEBUG: XXX_IOControl.\r\n")));

    switch (dwIoControlCode)
    {

        case IOCTL_GET_SOMETHING:
            RETAILMSG(XXX_MSG_DEBUG, (TEXT("[XXX] DEBUG: +IOCTL_GET_SOMETHING.\r\n")));
            if (nInBufSize >= 2)
            {
                param1 = *((UINT32 *)pInBuf);

                // add the code to get param2 here
                param2 = 1234;

                *((UINT32 *)(pInBuf+4)) = param2;
                bErr = TRUE;
            }
        break;

        case IOCTL_SET_SOMETHING:
            RETAILMSG(XXX_MSG_DEBUG, (TEXT("[XXX] DEBUG: +IOCTL_SET_SOMETHING.\r\n")));
            if (nInBufSize >= 2)
            {
                param1 = *((UINT32 *)pInBuf);
                param2 = *((UINT32 *)(pInBuf+4));
                bErr = TRUE;
            }
        break;


        default:
            RETAILMSG(XXX_MSG_ERROR, (TEXT("[XXX] ERROR: Undefined ID of Device IO Control (%d)!"), dwIoControlCode));
        break;
    }

    if (bErr == FALSE) {
        RETAILMSG(XXX_MSG_INFO, (TEXT("[XXX] ERROR: Device IO Control Error!")));
    }

    return bErr;
}   // XXX_IOControl

DWORD XXX_Read(DWORD Handle, LPVOID pBuffer, DWORD dwNumBytes)
{
    return 0;
}

DWORD XXX_Write(DWORD Handle, LPCVOID pBuffer, DWORD dwNumBytes)
{
    return 0;
}

DWORD XXX_Seek(DWORD Handle, long lDistance, DWORD dwMoveMethod)
{
    return 0;
}

void XXX_PowerUp(void)
{
    return;
}

void XXX_PowerDown(void)
{
    return;
}

BOOL WINAPI DllEntry(HANDLE hInstDll, DWORD dwReason, LPVOID lpvReserved)
{
    switch ( dwReason )
    {
        case DLL_PROCESS_ATTACH:
            RETAILMSG(XXX_MSG_INFO, (TEXT("XXX: DLL_PROCESS_ATTACH\r\n")));
            DisableThreadLibraryCalls((HMODULE) hInstDll);
            break;

        case DLL_PROCESS_DETACH:
            RETAILMSG(XXX_MSG_INFO, (TEXT("XXX: DLL_PROCESS_DETACH\r\n")));
            break;
    }

    return (TRUE);
}

星期四, 1月 14, 2010

WinCE 6 出現 VMProcessPageFault Error 的對策

WinCE 6 出現: VMProcessPageFault Error: Page fault occurred while in power handler! Address = xxxxxxxx 的對策:

  • 1. 確定 platform.bib 有 power handle 的 driver 都禁止 paging, 可以透過設定 SHK 或 SHM 的方式達成.
  • 2. 用 dumpbin /exports *.dll > C:\commondll.txt 後搜尋所有 driver 有 PowerUp 的 driver 如果在 common.bib 中載入的 flag 是 SH (user mode) 加上 M 成為 SHM.


更動的 driver 如下:
btagsvc.dll btmodem.dll btsvc.dll softkb.dll uiproxy.dll

問題產生原因在於 WinCE 的 Virtual Memory Paging 策略:
  • 1. WinCE 沒有像 WinXP 的 Page File, 因此在 paging 時會將 user mode driver "page out".
  • 2. power handle function 應禁止 paging.
  • 3. common.bib 某些 driver 有 power handle function 卻是在 user mode 下執行.

WinCE Virtual Memory Basic Terms:
  • 1. committed = have PM assigned to them.
  • 2. reserved = assigned to an allocation, but don't have PM assigned to them.
  • 3. free = not assigned, not allocated.

WinCE Virtual Memory Notes:
  • The page next to each other in VM(Virtual Memory) may not next to each other in PM(Physical Memory).
  • It's not one to one mapping, two VM address could mapping to same PM address.
  • WinCE has no page file, so they will "delay committing" as long as possible.
其他參考資料:

What is Virtual Memory
http://blogs.msdn.com/ce_base/archive/2006/10/30/What-is-Virtual-Memory.aspx

Paging and the Windows CE Paging Pool
http://blogs.msdn.com/ce_base/archive/2008/01/19/Paging-and-the-Windows-CE-Paging-Pool.aspx

其他 MSDN 上的資料
Paging Pool
http://msdn.microsoft.com/en-us/library/aa915364.aspx

Paging Pool: Windows CE 5.0 vs. Windows Embedded CE 6.0

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

Slaying the virtual memory monster
http://blogs.msdn.com/hegenderfer/archive/2007/08/31/slaying-the-virtual-memory-monster.aspx

星期三, 9月 16, 2009

The differences between L"Text", _T("Text") and TEXT("Text")

The differences between L"Text", _T("Text") and TEXT("Text"):
  • _T("Text") and TEXT("Text") is a narrow-character (ASCII) literal in an ANSI build but a wide character (UNICODE) literal in a Unicode build.
  • L"Text" is always a wide-character literal, regardless of pre-processor definitions.
  • _T() and TEXT() are macros, the L prefix is part of the core C and C++ language lexical structure.
  • There is no difference between _T() and TEXT(), both macro do same thing, only difference is _T() defines in tchar.h and TEXT() defines in windows.h.