2009年12月24日 星期四

Linux USB指南

http://www.gentoo.org/doc/zh_cn/usb-guide.xml

EHCI

usb 2.0定義了低速(ls),全速(fs),高速(hs)傳輸。EHCI僅僅支持高速傳輸,所以它必須還要有一個companion HC,如(UHCI)來支持低速和全速設備,情況時這樣的:
1), fs/ls 設備插入到root hub port,會由companion HC(uhci/ohci)發現並管理設備;
2),fs/ls 設備插入到usb 2.0 hub(not root hub),那麼由ehci 通過split transaction和transanction translation(tt)支持fs/ls 設備。
比如,當一個usb設備插入root hub port時,先要做一件routing的事情。所有的root hub port默認是被EHCI佔有的,所以,EHCI和插入的usb設備通信,看是不是hs設備,如果是好說。如果不是,EHCI就放棄這個port的佔有 權,讓給companion HC(uhci/ohci)去管理。

UHCI,OHCI,EHCI差異

USB(Universal Serial Bus)通用串列匯流排:USB1.1規格支援兩種速率:低速(low speed)1.5Mbps和全速(full speed)12Mbps.
新的USB2.0規格除了支援原有的兩種速度外,還而外支援高速(high speed)480Mbps。

    USB host controller(USB主控器)必定是下列3種規格:
  1. UHCI : Intel公司提倡,UHCI線路比OHCI線路簡單多了,但是需要比較複雜的驅動程式,對CPU負擔也微重了些,UHCI採用I/O-mapped I/O方式(CPU使用I/O指令來存取USB controller),採用的廠商有Intel,VIA。
    在UHCI 中一個SOF 會出現一個Setup Token。
  2. OHCI:Compaq(康柏)公司主導,採用Memory-mapped I/O(CPU使用記憶體指令來存取USB controller),採用的廠商有Compaq,iMace,OPTi,SiS,Ali。
    在OHCI 中一個SOF 會可能出現三個Setup token。
  3. EHCI:USB規格,相容於UHCI,OHCI,只有USB2.0(EHCI)才提供高速480Mbps傳輸效率。

2009年12月21日 星期一

Vim color

  1. 下載 COLOR_SCHEME.vim
  2. mkdir ~/.vim/colors/
  3. mv COLOR_SCHEME.vim ~/.vim/colors/
  4. vim ~/.vimrc # 加入下述內容
    colorscheme COLOR_SCHEME

  5. 註1: .vimrc 要記得加 set t_Co=256 來支援 256 色的環境, 才不會覺得跟預覽圖不一樣.
  6. 註2: syntax on ...

Ubuntu samba 設定

【第一步】
叫出終端機,鍵入以下的指令:(以下數字後面的文字為說明)
1.安裝samba
sudo apt-get install samba

2.先停止服務,準備設定設定檔

sudo /etc/init.d/samba stop

3.設定 samba 設定檔

sudo gedit /etc/samba/smb.conf

4.設定分享資料夾,請在smb.conf的尾端加入以下的內容

[SHARE]
path = /home/你自己名稱/shared    ;分享路徑
browseable = yes            ;是否可瀏覽
read only = no              ;唯讀
create mask = 0644          ;檔案遮罩
directory mask = 0755       ;資料夾遮罩

5.啟動 samba 服務

sudo /etc/init.d/samba start

6.建立帳號密碼

sudo smbpasswd -a <帳號>

※若想直接分享,不需要設定每位使用者的帳號密碼,那麼在 smb.conf 中 security 設定更改成如下:

;security = share

【第二步】
  1. 在桌面上,滑鼠右鍵點選/home/你自己名稱/shared,選擇【共享選項】。
  2. 依照您的需求,自行決定。也可以都打勾!
  3. 再點選【新增分享】。

2009年12月1日 星期二

Timer tutorial include prescalers

timer tutorial (incl prescalers)

Delays@
Andrew Warren [fastfwd at ix.netcom.com] of Fast Forward Engineering San Diego, California says:
timer-0 has four components: The clock input (either from the TMR0 pin or from the internal instruction clock), the TMR0 prescaler, the TMR0 register, and the TMR0 interrupt flags (GIE, T0IE, and T0IF).

CLOCK INPUT:

You'll probably use the internal instruction clock as your TMR0 input; I'll assume that your PIC is running at 4 MHz. Since there's an internal divide-by-4 between the oscillator frequency and the instruction clock, this means that instruction clocks occur at a 1 MHz rate.

prescaler:

The TMR0 prescaler is set (via 4 bits in the OPTION register) to divide-by-1, -2, -4, -8, -16, -32, -64, -128, or -256. The TMR0 input clock (1 MHz in your case) is passed to the prescaler, whose divided-down output is then fed to the TMR0 register.
For example, if the TMR0 prescaler is set to divide-by-4 and the PIC is running at 4 MHz, the prescaler will send a 250 KHz clock to the TMR0 register.

TMR0 REGISTER:

The TMR0 register can be preloaded with any 8-bit value that you like.
Each clock pulse from the prescaler increments the contents of the TMR0 register. When the value in the TMR0 register rolls over from 0xFF to 0x00, the T0IF flag is set (the TMR0 register continues to be incremented on every pulse from the prescaler, though).

INTERRUPT FLAGS:

If the GIE and T0IE flags are set when the T0IF flag is set, an interrupt is generated (the GIE bit is automatically cleared (to temporarily prevent further interrupts while your interrupt routine is executing), and the PIC jumps to the "interrupt vector" at location 0x04. Your interrupt-service routine at that location should check the T0IF flag to determine the source of the interrupt, then must clear the T0IF flag to prevent the PIC from immediately jumping back to the interrupt routine when interrupts are re-enabled.
At this point in the interrupt routine, you can re-load the RTCC with any appropriate value.
When you're finished handling the interrupt, your code should execute a RETFIE instruction, which will automatically set the GIE bit to re-enable interrupts and return to your main program.
Luis F says:
If you want the delay in seconds:
Delay = (256 - InitTMR0 * prescaler)
            -----------------------------------------
                    Frequency / 4
Or if you want the value to put in TMR0 to get a determinate DELAY
InitTMR0 = 256 - ( DELAY * Frequency ) / ( 4* prescaler)

2009年11月28日 星期六

c language standard library function


Reference website: http://www.cplusplus.com/reference/clibrary/ 
Reference: "Embedded Linux, C-language programming practice" 
In fact, in reference to web pages, you can already find all the C language standard library functions. Here I only list what I learned: 
  C-set of the standard library functions are: 
     : the standard set of input and output functions. 
     : a set of function determining character type (whether upper case, numbers, spaces)

     : a set of function Operating string. 
     : a set of mathematical applications related functions. 
     : tool set, including the type conversion and some system functions. 
     : a set of additional assertion functions. 
     : variable parameters, tool kit. such as the printf function will use this package. 
     : a set of function supporting jump feature

     : a set of processing interrupts. 
     :a set of function dealing with the date and time
     : integer type maximum and minimum set.

     : maximum and minimum set of floating-point type.

1. Standard formal input and output class function 
    Header files are involved in stdio.h and stdarg.h 
   * scanf function: Format input string 
   * printf functions: formatting output strings 
   * putchar function: the output characters to the standard output 
   * getchar function: get character from standard input 
   * putc function: output characters to the file 
   * getc function: get characters from a file 
           while ((c = getchar ()! = EOF)) putchar (c) 
           c = getc (pFile) 
           getchar () is equivalent to getc (stdin) 
   * gets function: get the string 
   * puts the function: output the specified string 
   * ungetc function: the return of characters to write


2. Character processing and conversion functions 
   * sprintf function: formatted output string to a buffer 
           sprintf (s, "% d", 123) 
           sprintf (s, "% 08X", 456); turn 16 hex 
           sprintf (s, "% 10.3f", 3.1434) 
   * strcat and strncat functions: string concatenation 
          char * strncat (char * dest, const char * src, size_t n) 
   * strcpy and strncpy functions: string copying 
          char strncpy (char * dest, const char * src, size_t maxlen) 
   * strcmp and strncmp functions: String Comparison 
           int strcmp (const char * s1, const char * s2) 
           s1> s2 return 1 
           s1 = s2 return 0 
           s1
   * strlen function: Get the string length of the 
   * strchr and strrchr function: Character / String location 
           strchar: search a character position of first occurrence 
           strrchr: search a character position of last occurrence 
   * strstr function: string search 
   * strupr and strlwr function: to convert the letters 
   * strdup and strndup function: string copying 
           char * strdup (const char * s) 
           The string s to copy to the specified memory cell


3. Math class functions counting 
    div acos atan cos tan cosh exp frexp ldexp log modf pow sqrt ceil abs floor


4. Data structures and algorithms class functions 
     * bsearch function: binary search 
     * lfind function: linear search 
     * lsearch function: linear search 
     * qsort function: the use of ordered array of quick sort method 
     * rand function: generate random number


5. File I / O operation class correlation function 
     * fopen function: open file 
     * fclose function: close file 
     * fgetc function: read a character from a file 
            fp = fopen ( "exit", "r") 
            while ((c = fgetc (fp))! = EOF) 
     * fputc function: to a specified character is written to the file stream 
     * fgets function: read a string from a file 
     * fputs function: to a specified string into the document
     * rewind function: Reset the file position of the file stream to read and write at the beginning of 
     * ftell function: get the file stream to read position 
     * fseek function: get the file stream to read position 
     * fwrite function: to build the file to write to the file stream 
     * fread function: read data from the file stream 
     * fgetpos function: get the file location 
                The stream's current location is recorded in the * position for the subsequent fsetpos () call using the 
     * fsetpos function: Set File Location


6. Utility functions 
     * assert function: diagnostic procedures 
     * setjmp function: to save call