2011年2月9日 星期三

fscanf usage ( Parse Command Line )

在寫有關於Printer 的AP的時候,要parse command line from file.
使用 fwscanf 遇到問題,在google並在WIN32下debug和實驗後,找到解法。

http://support.microsoft.com/kb/60336/en-us

第一個fwscanf 之後的 fwscanf都parse 不出來 ( return 0 )
因為 file pointer 停在 delimiter 前面,後續呼叫會失敗
所以要加 %*c

2010年12月24日 星期五

inline function

在想要optimize AAC encoder 的速度的時候
想要inline fabs()
卻無法成功

1. inline is for C++, __inline is for C & C++
2.要change compiler option /Ob0 to /Ob1 or /Ob2 ( In C++ --> Optimization --> Inline function expansion )
http://msdn.microsoft.com/en-us/library/47238hez.aspx
3. /Ob1 和 /ZI (Edit and Continue) 選項衝突,改用 /Zi
4. __forceinline 強迫inline 但compiler 不一定會照做,參考
http://msdn.microsoft.com/en-us/library/z8y1yy88.aspx

2010年12月5日 星期日

JSAMPARRAY & jpeg_read_scanlines

JSAMPROW data[1];
data[0] = new JSAMPLE[1920*1080];



while (cinfo.output_scanline < cinfo.output_height) {
num_scanlines = jpeg_read_scanlines(&cinfo, data, maxlines );
        }
      
        jpeg_read_scanlines 的第二個參數 JSAMPARRAY 是一個儲存 pointer to row 的陣列。
如果有一行 就得有一個元素,兩行就要有兩個元素。
也就是 & JSAMPROW 或 & data[n]


libjpeg.txt 的範例


        JSAMPROW row_pointer[1]; /* pointer to a single row */
int row_stride; /* physical row width in buffer */

row_stride = image_width * 3; /* JSAMPLEs per row in image_buffer */

while (cinfo.next_scanline < cinfo.image_height) {
   row_pointer[0] = & image_buffer[cinfo.next_scanline * row_stride];
   jpeg_write_scanlines(&cinfo, row_pointer, 1);
}


ycc_rgb_convert() in jdcolor.c

2010年12月1日 星期三

Long Lasted Problem Solved. After OEMInit hang

在db1200 的板子上,之前一開始做新的Image
NK.bin 都會Hang 在 -OEMInit 之後。
因為在 startup.s 中,呼叫完 OEMInit 之後 會reenable interrupt
而因為在公版中 有用到GPIO7 也就是 IC1 interrupt 7
如果這個GPIO7 pin 的狀態為 High 沒問題, 如果為 Low 的話 則會trigger interrupt 導致系統Hang住。 (使用MMPG module 就可以pass, 因為它把GPIO7 pull high

之前粗魯的解決方法就是 Disable 整個 IC1 (在startup.s 中 disable interrupt mask )或者在 intr.c (OEMInterruptInit()  )中 disable 整個 IC1 handler。

但是正確解法應該是,修改 db1200.h 或 pb1200.h
修改 PLATFORM_INTR_IC1_07


// Platform-specific interrupt defintions for kernel/hal/intr.c
#define PLATFORM_INTR_IC1_07 irqLL | INTR_MODE_UNMASK // 39 GPIO7 Board Interrupt Controller

不要定義 PLATFORM_INTR_IC1_07 的話 在intr.c
的  InterruptConfiguration[HWINTR_MAXIMUM ] array 就會定義 PLATFORM_INTR_IC1_07 為 irqNA


#ifndef PLATFORM_INTR_IC1_07
#define PLATFORM_INTR_IC1_07 irqNA
#endif
PLATFORM_INTR_IC1_07,

2010年11月17日 星期三

CreateDIBSection

在做印表機驅動程式的時候,要在圖片旁邊加字。
使用到CreateDIBSection

因為 Resolution 太大( 2392x3400) 所以 CreateDIBSection 只能一次
第二次會失敗。

所以每次都要釋放乾淨。
要用

SelectObject 把 DIBSection select 出來
然後 DeleteObject

2010年9月30日 星期四

USB Request Block & USB Protocol

5.1 Sync Field
Each USB packet starts with a SYNC field. This is basically used to synchronise the transmitter and the receiver so that the data can be transferred accurately.
In a USB slow / full speed system this SYNC field consists 3 KJ pairs followed by 2 K’s to make up 8 bits of data.
In a USB Hi-Speed system the synchronisation requires 15 KJ pairs followed by 2 K’s to make up 32 bits of data

Bus Hound 裏面有關 URB

USB Request Block 是定義在 Windows 或 Linux 中
跟實際的USB Protocol 沒有關係
URB 的定義在 usb.h 中
它是各種不同的定義的集合 ( union )
http://msdn.microsoft.com/en-us/library/ff538923(VS.85).aspx

2010年9月27日 星期一

sal.h

在做 USB Printer 的專案(x86)時,會用到 GUID_DEVINTERFACE_USB_DEVICE
及 IOCTL_PAR_QUERY_DEVICE_ID
所以要
#include
#include

而這兩個檔案是在 Windows DDK (WDK)裏有,所以要 add additional include directory
在 wdk 中的 \inc\api

現在問題來了,原來的project 為 vs2005
轉換成vs2008後 會出現一堆沒有定義 _In_opt 等等的錯誤
(為什麼要轉成 vs2008 的原因 是因為在vs2005中 下斷點有問題
有些部份無法設 breakpoint 會出現 the breakpoint will not currently be hit. invalid file line xxx
改成vs2008 之後就好了)

那是因為 vs2008 的 sal.h 和 ddk sdk 中的 sal.h 定義不同
必需要用到原來 vs2008中的 sal.h ( Visual Studio 9.0\vc\include ) 才行
但是因為我們加了 additional include directory
所以 wdk 中的 sal.h 會被先用到....
而造成錯誤

解決方法就是修改 Visual Studio 9.0\vc\include\crtdefs.h
在crtdefs.h 中會
#include
把它改成
#include "sal.h"
就可解決。(目前完美的方式)

...簡單的東西搞出麻煩的過程