2011-12-16

U-BOOT CODE (flash & memory) (flashtest)

參考 cp, cmp 與 erase command之source code
int do_fhtest(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
    ulong addr = 0x100e0000, dest = 0x4000000, len = 0x8, size = 2;
    ulong count = len;
 
    //erase
    flash_sect_erase(0x100e0000, 0x100fffff);
    // write to flash
    int rc = flash_write(0x3000000, 0x100e0000, count*size);
   
    //flash to mem
    //ulong addr = 0x100e0000, dest = 0x4000000, count = 0x10, size = 2;
    count = len;          
    while (count-- > 0)
    {
        if (size == 4)
        {
           *((ulong  *)dest) = *((ulong  *)addr);
        }  
        else if (size == 2)
        {
           *((ushort *)dest) = *((ushort *)addr);
        }
        else
        {
           *((u_char *)dest) = *((u_char *)addr);
        }
       
        addr += size;
        dest += size;
    }

    //compare
    ulong addr1=0x3000000, addr2=0x4000000;
    //ulong addr1=0x100e0000, addr2=0x4000000;
    count = len;
    while (count-- > 0)
    {
        if (size == 4)
        {
            ulong word1 = *(ulong *)addr1;
            ulong word2 = *(ulong *)addr2;
            if (word1 != word2)
            {
               printf("word at 0x%08lx (0x%08lx) "
               "!= word at 0x%08lx (0x%08lx)\n",
               addr1, word1, addr2, word2);
               return 0;
            }
         }
        else if (size == 2)
        {
            ushort hword1 = *(ushort *)addr1;
            ushort hword2 = *(ushort *)addr2;
             if (hword1 != hword2)
            {
                printf("halfword at 0x%08lx (0x%04x) "
     "!= halfword at 0x%08lx (0x%04x)\n",
     addr1, hword1, addr2, hword2);
    //printf("FAIL\N");
                return 0;
                //break;
             }
       }

  addr1 += size;
  addr2 += size;
 }
    printf("PASS\n");

   return 0;
}


U_BOOT_CMD
(
        untest,      4,     1,   do_fhtest,
        "flashtest \n",
        ""
        "flashtest \n"
);

2011-12-07

I²C (Inter Integrated Circuit)

I²C 常見應用:

I2C是由兩條訊號組成,主要應用在晶片的I/O,A/D或D/A轉換器,溫度感測,主要製造廠商有Atmel,Intel,Cypress,Philips,Microchips,ST半導體,德州儀器等等……


I²C 匯流排定義:

是一種雙線式介面,可由一個主控制端去傳輸給多個副控制端,當然也可以去設定多個主控制端。訊號主要傳送資料的腳位為SDA,會搭配另一條CLOCK訊號(SCK)以及一條接地線。



相關知識:

所有的 device 都接在一起,使用相同的訊號線連接(SCL、SDA),在 I2C 發起交易的 device 為 『Master』,他會跟所定址到的 『slave』 進行通訊。I2c support multi-master,但是一般實做上只會有一個。

每個 I²C 元件都擁有一個獨一無二的 7-bit I²C 位址,讓主控端知道通訊傳輸的對象是誰,通常 7-bit 中四個較重要的位元 (MSB) 為固定的,並依元件本身性質的分類區分,如 1010 即代表串列 EEPROM,而其他三個較不重要的位元 (LSB),即 A2、A1 與 A0 則可以透過硬體電子接腳設定,並取得高達 8 個不同的 I²C 位址組合,因此在同一個 I²C 匯流排上可以有 8 個相同形式的元件運作,這些接腳固定在 VCC 高電壓代表邏輯 1,固定在接地低電壓則代表邏輯 0,7-bit 的定址方式可以帶來匯流排上 128 個元件的組合,但由於部份位址設定保留給特殊指令應用,因此實際上最高元件數大約為 120 個。


  1. SCL (serial clock):傳送時脈訊號。
  2. SDA (seral data):傳送實際的資料。

I²C 匯流排說明:

  Start:  SDA訊號由高準位轉低準位並且SCL為高準位時。
  Address:  一般都由7或10位元組成,其狀態之後還會標示其位址是寫入或是讀取。
  Read/Write Bit (R/W):  由一個位元組成,用來表示此筆資料是讀取或是寫入。
  Acknowledge Bit (ACK):  由一個位元組成,用來表示這筆資料是否已經獲得傳送的回應。
  Data:  表示這筆訊號中的資料表示,可知道是寫入或是讀取的狀態。
  Stop:  SDA由低轉高且SCL為高準位時。


I²C 匯流排術語:
  1. Transmitter: The device which sends data to the bus
  2. Receiver: The device which receives data from the bus
  3. Master: The device which initiates a transfer, generates clock signals and terminates a transfer
  4. Slave: The device addressed by a master
  5. Multi-master: More than one master can attempt to control the bus at the same time without corrupting the message
  6. Arbitration: Procedure to ensure that, if more than one master simultaneously tries to control the bus, only one is allowed to do so and the winning message is not corrupted
  7. Synchronization: Procedure to synchronize the clock signals of two or more devices

2011-12-02

ERROR: The content of the adapter has changed but listview did not receive a notification

Error:The content of the adapter has changed but listview did not receive a notification

原因: adapter 的內容更新速度過快, 導致View的速度跟不上
辦法: 加入sleep()

(此為新發現之原因, 尚有多種可能)