SlideShare a Scribd company logo
1 of 88
Hardware knowledge which the
software engineer must understand
Jethro Yeh
葉建良
2012/06/13
Outline
• 電子電路基礎概念
• 數位訊號基礎概念
 實際案例
• 系統單晶片處理器基礎概念
 SoC Processor Block Diagram
 Clock Block Diagram
 Power Management
 GPIO setting
 Transmit the data among I/O
 Interrupt
 ARM Interrupt Vector Table
 Linux API vs. Interrupt Process
 實際案例
電子電路基礎概念
• 電路:電子器材使用的是電能,而電能需藉由導體傳遞,故必須以導體連接電
源形成一封閉的迴路。此種以導線、電源、電子元件等聯結成迴路的裝
置,就稱為電路。
• 導線:通常以電阻較小的金屬銅為導線,在整個電路中導線的電阻可被忽略不
計。
• 電源:扮演供應電能的角色,提供電壓使電流能夠流通的裝置。
• 電壓:兩點之間的電位差 ( 單位電荷的能量差 ) 。當談到某處電壓為何時,通常指
對應某一參考點的電位差為何。單位為伏特(簡寫 V )。
• 電流:電子的流動稱為電流,電流流動的動力來自電源提供的電壓。
電流在電路中由高電位流向低電位,形成一個循環的通路。
可以將電流想像成水流,電流在電路中由高電位流向低電位流動,就像水
受到水壓而由高處向低處流動。單位為安培(簡寫 A )。
電阻器
• 在相同的電壓之下,電阻器的電阻值越大,能夠流過的電流就
越小。
• 電阻器的單位為 Ω( 歐姆 ) ,其主要用途包括:
- 限制流經某一段電路的電流 ( 限流 )
- 製造固定的電壓 ( 分壓 ) 。
    
           
電阻器 – 串聯
• 電阻器串聯: 1. 電路兩端的總電阻值為各電阻器阻值之相加總和
        2. 流經電阻器的電流大小是相等的
    
           
3V
10K
20K
電阻器 – 並聯
    
           
• 電阻器並聯: 1. 電阻器的電壓大小相同
    2. 等效電阻會變小
If R1=R2=10K, Req = 5K
電容器
• 由兩片平行的金屬板加以絕緣物質隔離,所構成的可儲存電能的元件稱為
電容器。其單位為法拉 ( 簡寫F ) 。
• 因電容由兩金屬片構成,中間有絕緣物,直流電無法流過電容,但通上交
流電時,由於電容能充放電所致,所以能讓交流電通過。
• 特性:阻直流、通交流
• 主要用途:濾波、穩壓
    
           
電容器
    
           
• 當電池接上電容器,電流會從電池流向電容器,使得電容器兩端累積相異
性電荷,這些正負電荷會互相吸引。
• 電容器的電量逐漸增加,電壓隨著增加,直到跟電池的電壓一樣時,才會
停止充電。
RC 充電
    
           
1
t = 1RC : 0.6321*V1
2RC : 0.8647*V1
3RC : 0.9502*V1
4RC : 0.9817*V1
5RC : 0.9933*V1
e:2.7183
RC 小
RC 大
-
RC 放電
    
           
1
RC 越小:充放電越快
RC 越大:充放電越慢
-
t = 1RC : 0.3679*V1
2RC : 0.1353*V1
3RC : 0.0498*V1
4RC : 0.0183*V1
5RC : 0.0067*V1
二極體
    
           
• 二極體具有陽極 (P 型 ) 和陰極 (N 型 ) 兩個端子。電流只能往單一方向流動
,電流可以從陽極流向陰極 ( 順向偏壓 ) ,不能從陰極流向陽極 ( 逆向偏壓
) 。因為這種特性常被應用在整流或開關。
• 矽半導體的臨界電壓約 0.6V ~ 0.7V ,鍺半導體約 0.3 ~ 0.4V 。
大多應用
在逆電壓
金屬氧化物半導體場效電晶體 (MOSFET)
    
           
• 在大部分的應用和符號,基板本體會和源極接在一起。
• 常見用途:開關、壓控電阻。
• N 通道:當 VGS<Vth( 臨界電壓 ) ,則 D 和 S 不導通;當 VGS>Vth ,則 D 和 S
導通。
P 通道:當 VSG<Vth ,則 D 和 S 不導通;當 VSG>Vth ,則 D 和 S 導通。
MOSFET 應用
    
           
• EN_SENSOR_1V8 = 0V , VDD_1V8_GEN 和 VDD_1V8_SENSOR 導通
EN_SENSOR_1V8 = 1.8V , VDD_1V8_GEN 和 VDD_1V8_SENSOR 不導通
數位訊號基礎概念
類比訊號 vs. 數位訊號
    
           
• 類比訊號:在任何一個時間點,均有連續的訊號存在。例如:聲波變化、
溫度變化、濕度變化等。
• 數位訊號:一般情況下,數位訊號只會在 0 或 1( 高和低電位 ) 這兩種狀態
之
間切換,是不連續的訊號,具有不易受干擾的優點。
雜訊干擾將電壓
提升或降低 0.1V
雜訊干擾將電壓
提升或降低 0.1V
1.8V
1
0
數位電路的優點
    
           
• 電子電路有數位 (digital) 電路與類比 (analog) 電路兩大類,而數位電路較類
比電路有以下的優點:
- 抗雜訊 (noise) 干擾能力較強。
- 可靠性高。
- 資料利用數位的形式比較容易儲存。
- 數位電路較易設計,可以達到精確的控制和較複雜的功能。
- 較容易使用現今的積體電路 (integrated circuit, IC) 來加以設計。
邏輯準位
    
           
• 一般數位電路中,邏輯「 0 」代表「低電位」,邏輯「 1 」代表「高電位」
。
• 輸入端:小於等於 VIL 的電壓被視為邏輯「 0 」,大於等於 VIH 的電壓被視
為邏
輯「 1 」。
• 輸出端:邏輯「 0 」會輸出小於等於 VOL 的電壓,邏輯「 1 」會輸出大於等
於
VOH 的電壓。
Floating ,會有邏輯誤判問題
脈波準位
    
           
• 脈波幅度的百分之 10 到百分之 90 所需時間稱為上升時間 t r ,脈波幅度的
百分之 90 到百分之 10 所需時間稱為下降時間 t f 。
• 若上升時間及下降時間越短,表示反應速度越快。
Rising time
Falling time
電氣特性 (Electrical Characteristics)
    
           
3V
0.9V
0.6V
0V
0V
2.1V 3V
3V2.4V
I2C-bus specification
    
           
在有些 bus 或電路會受等效 RC 影響
Power On Sequence
    
           
VCC
Reset
Interface 0x10=2 0x12=4
Data
>50ms >200ms >10ms>1ms >50ms
Power Off Sequence
    
           
VCC
Reset
Interface
Data
>10ms >100ms
Power On Sequence - SW
    
           
VCC
Reset
Interface 0x10=2 0x12=4
Data
>50ms >200ms >10ms>1ms >50ms
1
2
3
4
5
6
8
7
系統 resume 或 GPIO setting 改變 或 HW 改變 或 雜訊干擾
Power On Sequence - Proposed SW
    
           
VCC
Reset
Interface 0x10=2 0x12=4
Data
>50ms >200ms >10ms>1ms >50ms
1
2
3
4
5
6 8
7 9
10
問 Vendor
Power On Sequence – Case 1
問題描述:機器開機使用幾個小時後,發生 kernel panic. 而且問題只會發生在少數的機器 .
分析:從 log 看到, Sensor 使用 I2C bus 讀取資料,但 I2C driver 顯示 fail message(I2C timeout or
NAK).
更後面有 Sensor driver 造成 kernel panic 的 message.
大家開始怪 I2C driver大家開始怪 I2C driver
要求 Sensor driver 在 I2C fail 時,加入 retry 機制要求 Sensor driver 在 I2C fail 時,加入 retry 機制
要求 Sensor driver 注意 I2C fail 也不能造成 kernel
panic
要求 Sensor driver 注意 I2C fail 也不能造成 kernel
panic
問題發生的機率變低許多,但有時 Sensor driver 還是無法透過 I2C 要到資料問題發生的機率變低許多,但有時 Sensor driver 還是無法透過 I2C 要到資料
大家又開始怪 I2C driver大家又開始怪 I2C driver
I2C owner 花了幾天在複製問題且架環境來量測 HW 訊號,最後發覺是 Sensor Chip 沒有回
應
I2C owner 花了幾天在複製問題且架環境來量測 HW 訊號,最後發覺是 Sensor Chip 沒有回
應
Sensor owner 最後查到 Power on sequence 不符合 Sensor data sheet 的要求Sensor owner 最後查到 Power on sequence 不符合 Sensor data sheet 的要求
Sensor 的 Power on sequence 符合 data sheet 的要求後,問題再也沒出現Sensor 的 Power on sequence 符合 data sheet 的要求後,問題再也沒出現
不是每顆 chip 都會發生問題不是每顆 chip 都會發生問題偶爾會出問題偶爾會出問題
合理, Error handle 要做
好
合理, Error handle 要做
好
可以思考及討論可以思考及討論
Power On Sequence – Case 2
問題描述:有些機器,有時 Sensor 不能正常 work.
分析:從 log 看到, Sensor 使用 I2C bus 讀取資料,但 I2C driver 顯示 fail message(I2C timeout or
NAK).
大家又開始怪 I2C driver 了大家又開始怪 I2C driver 了
Sensor owner 確定 SW 控制的 Power on sequence 符合 Sensor data sheetSensor owner 確定 SW 控制的 Power on sequence 符合 Sensor data sheet
應主管要求,去量測發生問題時的 Sensor Power on 的 sequence ,
結果發現沒有符合 Sensor data sheet 的要求
應主管要求,去量測發生問題時的 Sensor Power on 的 sequence ,
結果發現沒有符合 Sensor data sheet 的要求Why?
Power On Sequence – Case 2
3V3
1V8
0~20ms
Data Sheet
3V3
1V8
1.3ms
Real HW
int Sensor_init()
{
SensorEnable_3V3();
SensorEnable_1V8();
…
}
int Sensor_init()
{
SensorEnable_3V3();
SensorEnable_1V8();
…
} SW
tegra_gpio_enable();
gpio_request();
gpio_direction_output()
;
tegra_gpio_enable();
gpio_request();
gpio_direction_output()
;
Why?
Power On Sequence – Case 2
1.8
0
0
3.3
0
3.3
放
電
放電
2.6
3.3
2.39ms 後 , 變成 2.6V
t = 2.39ms
-
3V3
3V3
Power On Sequence – Case 2
0
1.8
1.8
0
Power On Sequence – Case 2
3V3
1V8
Real HW
int Sensor_init()
{
SensorEnable_3V3();
SensorEnable_1V8();
…
}
int Sensor_init()
{
SensorEnable_3V3();
SensorEnable_1V8();
…
} SW
2.39ms
1.3ms1ms
tegra_gpio_enable();
gpio_request();
gpio_direction_output();
tegra_gpio_enable();
gpio_request();
gpio_direction_output();
tegra_gpio_enable();
gpio_request();
gpio_direction_output();
tegra_gpio_enable();
gpio_request();
gpio_direction_output();
Check Power On/Off Sequence of Component
1. Check power on sequence of component when device power on
2. Check power off sequence of component when device power off
3. Check power off sequence of component when system suspend
4. Check power on sequence of component when system resume
5. Check power on sequence of component when SW and HW reset
系統 suspend/resume 時, component 有 power on/off 才需要做 check
    
           
系統單晶片處理器基礎概念
系統單晶片處理器
    
           
• 一個典型的系統單晶片 (System-on-Chip ; SoC) 處理器會由以下各元件所組成
:
   - 一個或是多個微處理器、微控制器或是 DSP
   - 記憶體部份包含唯讀記憶體、隨機存取記憶體、 快閃記憶體等
   - 振盪器及 PLL 提供系統所需時脈來源
   - 其他週邊還有計數器 counter-timer , RTC 或是 Watchdog Timer
   - 額外工業標準的界面,像是 USB, I2C 等 .
   - 類比界面包含了類比 - 數位轉換器及數位 - 類比轉換器
   - 電壓調整電路及電源管理
SoC Processor Block Diagram
    
           
時脈 (Clock)
    
           
• 時脈是一種固定週期的脈波,用來控制電路做動作或做訊號同步,一般一
個脈波週期是電路運作最基本的時間單位。
• 時脈頻率 (Clock rate) 是指同步電路中時脈的基礎頻率,它以「每秒多少週
期脈波」來度量,單位是赫茲 (Hz) 。
• 時脈是最基本的要素。任何時脈錯誤,均可能造成傳輸或接收不正確的資
料。
• SoC Processor 的時脈頻率通常是由晶體振蕩器的頻率提供的。
Rising edge
Falling edge
石英晶體 & 石英晶體振盪器
    
           
• 石英晶體振盪器是利用石英晶體的壓電效應,用來產生高精度振盪頻率的
一種電子元件。
• 石英晶體( crystal 或 Xtal )是石英晶片加上電極與外殼封裝。 這是單純
石英晶體被動元件,不含主動元件,需搭配外加電路才會產生振盪。石英
晶體通常是兩支接腳的電子元件。
• 石英晶體振盪器( crystal oscillator ,簡寫 OSC 或 XO )是指內含石英晶
體與振盪電路的模組,需要電源,可直接產生振盪訊號輸出。 石英振盪器
通常是四支接腳的電子元件,其中兩支為電源,一支為振盪訊號輸出,另
一支為空腳或控制用。
鎖相迴路 (PLL ; Phase Locked Loop)
    
           
• 鎖相迴路是一種利用反饋 (Feedback) 控制原理來實現的頻率及相位同步技
術,其作用是將電路輸出的 Clock 與其外部的參考 Clock 保持同步。當參考
Clock 的頻率或相位發生改變時,鎖相迴路會檢測到這種變化,並且通過其
內部的反饋系統來調節輸出頻率,直到兩者重新同步,這種同步又稱為「
鎖相」 (Phase-locked) 。
• PLL 大部分用來產生精確的 Clock 。
PD : 相位偵測
LPF :低通濾波器
VCO :壓控振蕩器
DIV : 除頻器
Clock Block Diagram
    
           
Internal Power Domain
    
           
SoC Processor Power Mode
    
           
Component Power Mode
    
           
• Normal Mode
• Standby Mode
• Sleep Mode
• Deep Sleep Mode
• Auto Sleep Mode
• Power off Mode
OS Power State
    
           
OS
SoC
Processor
Most
Controller
Most
Component
Normal / Run
Mode
Normal Mode
Power on/off
Enable/Disable
PLL
Normal Mode
Auto Sleep Mode
Power off Mode
Idle Mode
Idle Mode
Standby Mode
Power on/off
Enable/Disable
PLL
Normal Mode
Auto Sleep Mode
Power off Mode
Suspend Mode
Sleep Mode
Deep Sleep
Mode
Power on/off
Enable/Disable
PLL
Auto Sleep Mode
Standby Mode
Sleep Mode
Deep Sleep Mode
Power off Mode
Power off Mode Power off Mode Power off Mode Power off Mode
Power Management
    
           
SoC Processor
LCD
Controller
VCC_LCD
PLL
LCD
VCC_3V3
VCC_1V8
Reset
Oscillator
MDDI
PMIC
I2C
Controller
I2C Bus
1. Power
2. Clock
3. Bus
4. GPIO
Power Management – OS Suspend Mode
  Component Processor Controller
Power Off /
Clock Off
(Power Off
Mode)
1. Check power consumption
2. Check the time of power on/off
sequence
3. Affect other components/function
- Share the power with other
parts/component
4. Need initialize registers again when
power on
(follow "Power On/Off Sequence")
5. The pin keep low level
1. Check power consumption
2. Check the time of power on/off
sequence
3. Affect other function/pin
- Share the power with other
parts/controller
- Check power domain (may be pin
floating)
4. Need initialize registers again when
power on (follow "Power On/Off
Sequence")
5. The pin keep low level
Power On / Clock
Off
(Standby/Sleep
Mode)
1. Check power consumption
2. Check the time of turn on/off sequence
3. Check wake up source
4. Don't affect the function when modify
the bus/GPIO configuration of the
1. Check power consumption
2. Check the time of turn on/off sequence
3. Don't affect the function when modify
the bus/GPIO configuration of the
提昇 / 下拉 電阻 (Pull-Up/ Pull-Down
Resistor)
SoC
Processor
Component
VCC
Pull up
Resistor
Pull down
Resistor
提昇 / 下拉 電阻 (Pull-Up/ Pull-Down
Resistor)
• 防止輸入端懸空。當輸入端懸空易受靜電等干擾,這些靜電可能會燒毀晶
片或電路。
• 改變輸出的電壓準位。
• 在輸入端懸空時有確定的 High/Low 狀態 。
• 增加輸出的電流驅動能力。 (Pull-Up)
• 提昇電阻的阻值會影響高低電位轉換的速度 。阻值越小,速度越快,消耗
功率越大。反之亦然。
• 當電流流經提昇電阻時會消耗額外的消耗功率,並且可能會引起輸出電位
的延遲。
下拉 電阻 (Pull-Down Resistor)
SoC
Processor
Charger
ICReset pin
High active
High Impedance
提昇電阻 (Pull-Up Resistor)
SoC
Processor
SD Detect
100K0.033mA
SDLow
3V3
SDLow
0.033mA * 30 = 0.99mA
通用輸入輸出 (General Purpose I/O)
    
           
• PIN 腳可以由程式控制自由使用。 PIN 腳依現實考量可作為通用輸入 (GPI)
或通用輸出 (GPO) 。
• 不是每根 PIN 腳都能設成 GPIO 。
Pin
Function
Function 1  
Function 2  
…  
GPIO
Output
High
Low
Input
Pull Up
Pull Down
No Pull
Hi-Z or
High Impedance
Pull Up
Pull Down
No Pull
By Processor
GPIO - Output
    
           
SoC Processor
LCD
Controller
VCC_LCD
Output
Pin 12:
0: Disable
1: Enable
Pin 10
Vibrator
Input
Pin 12
GPIO
Controller
VCC_IO
Power?
Function Control
GPIO - Output
    
           
xxx
Controller
Output
GPIO
Controller
SoC Processor
By Processor
Pull up
Pull down
GPIO - Output
    
           
xxx
Controller
Output
GPIO
Controller
SoC Processor
15K
3V3 3V3
0V
Default
0.22mA
建議改用 No pull
GPIO - Input
    
           
xxx
Controller
Input
GPIO
Controller
SoC Processor
Pull up
Pull down
By Processor
Pull up
Pull down
GPIO - Input
    
           
xxx
Controller
SD Detect
GPIO
Controller
SoC Processor
Pull up?
Pull down?
No pull?
1. Function work
2. Power consumption
SDLow
Low active
GPIO - Input
    
           
xxx
Controller
SD Detect
GPIO
Controller
SoC Processor
Pull up?
Pull down?
No pull?
1. Function work
2. Power consumption
SDHigh
High active
GPIO - Input
    
           
xxx
Controller
Gyro interrupt
GPIO
Controller
SoC Processor
Pull up?
Pull down?
No pull?
1. Function work
2. Power consumption
Gyro
Sensor
High active
GPIO - Input
    
           
xxx
Controller
GPIO
Controller
SoC Processor
Pull up?
Pull down?
No pull?
1. Function work
2. Power consumption
Thermal
Sensor
Low active
TEMP_ALERT#
Case 1 - Component Power off mode
    
           
xxx
Controller
GPIO
Controller
SoC Processor
Component
I2C
VCC
?
Functio
n
Function
1
I2C
Function
2
 
…  
GPIO
Output
High
Low
Input
Pull Up
Pull
Case 2 - Component Sleep mode
    
           
xxx
Controller
GPIO
Controller
SoC Processor
Component
I2C
VCC
?
Functio
n
Function
1
I2C
Function
2
 
…  
GPIO
Output
High
Low
Pull Up
Enter/Exit sleep mode through I2C command
Case 3 – I2C discussion
    
           
I2C
Controller
GPIO
Controller
SoC Processor
L-Sensor VCC
P-Sensor VCC
Gyro
Sensor
VCC
I2C
Case 3 – I2C discussion
    
           
I2C
Controller
GPIO
Controller
SoC Processor
Camera VCC
I2C
Output Low
Case 4 – Power Domain Off
    
           
SD
Controller
GPIO
Controller
SoC Processor
LCD
Reset
VCC
VCC_SD
SD VCC
LED
High active VCC
High activeHi-Z
Hi-Z
VCC_SD
Recommend
Case 5 – GPIO of Tegra 3
    
           
Tegra3_TRM_DP05644001v01_sec.pdf
P.414 SFIO/GPIO Pin Multiplexing Architecture
P.285 Structure of Pinmux Controller
Tegra3_Datasheet_DS05160001_v3.0_sec.pdf
P.84 POR (Power On Reset)
P.85 After Wake, pin State
Case 5 – GPIO API of Tegra 3
    
           
gpio_request();
gpio_direction_output();
tegra_gpio_enable();
…
gpio_free();
tegra_gpio_disable();
gpio_request();
gpio_direction_output();
tegra_gpio_enable();
…
gpio_free();
tegra_gpio_disable();
gpio_request();
tegra_gpio_enable();
gpio_direction_output();
…
tegra_gpio_disable();
gpio_request();
tegra_gpio_enable();
gpio_direction_output();
…
tegra_gpio_disable();
tegra_gpio_enable();
gpio_request();
gpio_direction_output();
…
gpio_free();
tegra_gpio_disable();
tegra_gpio_enable();
gpio_request();
gpio_direction_output();
…
gpio_free();
tegra_gpio_disable();
gpio_request();
gpio_direction_output();
…
gpio_free();
gpio_request();
gpio_direction_output();
…
gpio_free();
1 32
4
tegra_gpio_disable();
…
tegra_gpio_disable();
…
5
gpio_request();
tegra_gpio_enable();
gpio_direction_output();
…
tegra_gpio_disable();
gpio_free();
gpio_request();
tegra_gpio_enable();
gpio_direction_output();
…
tegra_gpio_disable();
gpio_free(); 6
Case 5 – GPIO API of Tegra 3
           
gpio_request();
tegra_gpio_enable();
gpio_direction_output();
gpio_direction_input();
gpio_request();
tegra_gpio_enable();
gpio_direction_output();
gpio_direction_input();
tegra_gpio_disable();
gpio_free();
tegra_gpio_disable();
gpio_free();
The pin change to GPIO modeThe pin change to GPIO mode
if ( gpio_desc[gpio]->flags == FLAG_REQUESTED )
return -EBUSY;
set_bit ( FLAG_REQUESTED, &gpio_desc[gpio]->flags );
if ( gpio_desc[gpio]->flags == FLAG_REQUESTED )
return -EBUSY;
set_bit ( FLAG_REQUESTED, &gpio_desc[gpio]->flags );
if ( gpio_desc[gpio]->flags == FLAG_REQUESTED )
return -EIO;
tegra_gpio_set(chip, offset, value);
tegra_gpio_mask_write(GPIO_MSK_OE(offset), offset, 1);
if ( gpio_desc[gpio]->flags == FLAG_REQUESTED )
return -EIO;
tegra_gpio_set(chip, offset, value);
tegra_gpio_mask_write(GPIO_MSK_OE(offset), offset, 1);
if ( gpio_desc[gpio]->flags == FLAG_REQUESTED )
return -EIO;
tegra_gpio_mask_write(GPIO_MSK_OE(offset), offset, 0);
if ( gpio_desc[gpio]->flags == FLAG_REQUESTED )
return -EIO;
tegra_gpio_mask_write(GPIO_MSK_OE(offset), offset, 0);
The pin change to SFIO modeThe pin change to SFIO mode
if ( gpio_desc[gpio]->flags == FLAG_REQUESTED )
clear_bit(FLAG_REQUESTED, &desc->flags);
if ( gpio_desc[gpio]->flags == FLAG_REQUESTED )
clear_bit(FLAG_REQUESTED, &desc->flags);
1
2
2
2
Option
3
4
Case 5 – GPIO API of Tegra 3
    
           
gpio_request();
gpio_direction_output();
tegra_gpio_enable();
…
gpio_free();
tegra_gpio_disable();
gpio_request();
gpio_direction_output();
tegra_gpio_enable();
…
gpio_free();
tegra_gpio_disable();
gpio_request();
tegra_gpio_enable();
gpio_direction_output();
…
tegra_gpio_disable();
gpio_request();
tegra_gpio_enable();
gpio_direction_output();
…
tegra_gpio_disable();
tegra_gpio_enable();
gpio_request();
gpio_direction_output();
…
gpio_free();
tegra_gpio_disable();
tegra_gpio_enable();
gpio_request();
gpio_direction_output();
…
gpio_free();
tegra_gpio_disable();
gpio_request();
gpio_direction_output();
…
gpio_free();
gpio_request();
gpio_direction_output();
…
gpio_free();
1 32
4
tegra_gpio_disable();
…
tegra_gpio_disable();
…
5
gpio_request();
tegra_gpio_enable();
gpio_direction_output();
…
tegra_gpio_disable();
gpio_free();
gpio_request();
tegra_gpio_enable();
gpio_direction_output();
…
tegra_gpio_disable();
gpio_free(); 6
Context switch
gpio_free();
tegra_gpio_enable();
gpio_request();
gpio_free();
Context switch
Transmit the data among I/O
• Polling
• Interrupt-driven I/O
• DMA(Direct Memory Access)
Polling
• I/O device 只要將資訊放進
Status Register , CPU 透過
周期性的檢查來得知需要服
務的 device 。
GPIO
Controller
SD
Controller
LCD
Controller
I2C
Controller
CPU Core
…
1
2
3
4…
Interrupt-driven I/O
GPIO
Controller
SD
Controller
LCD
Controller
I2C
Controller
CPU Core
…
Interrupt
Controller
• 利用 interrupt 的機制,當一
個 I/O device 需要服務時,
會發出 interrupt 來通知
CPU 。 CPU 收到 interrupt
後,再做相對應的處理。
DMA
• DMA 是一個特殊的硬體結構,
需要有一個 DMA controller ,
它允許 I/O device 與記憶體之
間直接轉移資料,而不需經由
CPU 的參與。
Polling vs. Interrupt vs. DMA
  Polling Interrupt-driven I/O DMA
優點
1. 軟體實作最簡單
2. 可利用軟體來更改 CPU
polling 的順序
1. 不用浪費許多時間在
polling 上面
1. 不用浪費許多時間在
polling 上面
2. 適用於高速裝置
3. 傳送大筆資料,最不
佔 CPU 時間,對系統效
能影響最小
缺點
1. 因為 CPU 速度遠快於 I/O
device ,會浪費許多時間在
polling 上
2. Power consumption 變高會最
明顯
3. 系統效能下降會最明顯
4. 不適合高速裝置
1. 需要有 interrupt signal
和 ISR(Interrupt Service
Routine) 存在
2. 不適合高速裝置
1. 需要有 DMA
Controller
2. 控制方式較複雜
SoC
Processor Input
Interrupt - GPIO
    
           
Rising Edge Falling Edge
High Level Low Level
Interrupt - GPIO
    
           
xxx
Controller
Input
GPIO
Controller
SoC Processor
Pull up
Pull down
Edge
Detect
Level
Detect
Interrupt Controller
    
           
GPIO
Controller
SD
Controller
LCD
Controller
I2C
Controller
CPU Core
…
Interrupt
Controller
ARM Interrupt Vector Table
    
           
Exception Type Mode Priority
Normal
Vector Address
High
Vector Address
  Reset  Supervisor 1  0x00000000  0xFFFF0000
  Undefined Instructions  Undefined 6  0x00000004  0xFFFF0004
  S/W Interrupt  Supervisor 6  0x00000008  0xFFFF0008
  Prefetch Abort  Abort 5  0x0000000C  0xFFFF000C
  Data Abort  Abort 2  0x00000010  0xFFFF0010
 Interrupt Request  IRQ 4  0x00000018  0xFFFF0018
 Fast Interrupt Request  FIQ 3  0x0000001C  0xFFFF001C
ARM Interrupt Vector Table
    
           
.globl __vectors_start
__vectors_start:
ARM( swi SYS_ERROR0 )
W(b) vector_und + stubs_offset
W(ldr) pc, .LCvswi + stubs_offset
W(b) vector_pabt + stubs_offset
W(b) vector_dabt + stubs_offset
W(b) vector_addrexcptn + stubs_offset
W(b) vector_irq + stubs_offset
W(b) vector_fiq + stubs_offset
.globl __vectors_end
__vectors_end:
kernel/arch/arm/kernel/entry-armv.Skernel/arch/arm/kernel/entry-armv.S
ARM Interrupt Vector Table
    
           
void __init early_trap_init(void)
{
unsigned long vectors = CONFIG_VECTORS_BASE;
/*
* Copy the vectors, stubs and kuser helpers (in entry-armv.S)
* into the vector page, mapped at 0xffff0000, and ensure these
* are visible to the instruction stream.
*/
memcpy((void *)vectors, __vectors_start, __vectors_end - __vectors_start);
memcpy((void *)vectors + 0x200, __stubs_start, __stubs_end - __stubs_start);
memcpy((void *)vectors + 0x1000 - kuser_sz, __kuser_helper_start, kuser_sz);
}
kernel/arch/arm/kernel/Traps.ckernel/arch/arm/kernel/Traps.c
kernel/arch/arm/configs/picasso_m_defconfigkernel/arch/arm/configs/picasso_m_defconfig
CONFIG_VECTORS_BASE=0xffff0000
以 Nvidia T30 BSP 為例,下面 API 對 Interrupt 和 OS Schedule 的
處理有什麼影響 ?
enable_irq() / disable_irq()
enable_fiq() / disable_fiq()
spin_lock() / spin_unlock()
spin_lock_irq() / spin_unlock_irq()
spin_lock_irqsave() / spin_unlock_irqrestore()
問題
    
           
以 Nvidia T30 BSP 為例,下面 API 對 Interrupt 和 OS Schedule 的
處理有什麼影響 ?
enable_irq() / disable_irq()
enable_fiq() / disable_fiq()
spin_lock() / spin_unlock()
spin_lock_irq() / spin_unlock_irq()
spin_lock_irqsave() / spin_unlock_irqrestore()
問題
    
           
Register of Interrupt ControllerRegister of Interrupt Controller
以 Nvidia T30 BSP 為例,下面 API 對 Interrupt 和 OS Schedule 的
處理有什麼影響 ?
enable_irq() / disable_irq()
enable_fiq() / disable_fiq()
spin_lock() / spin_unlock()
spin_lock_irq() / spin_unlock_irq()
spin_lock_irqsave() / spin_unlock_irqrestore()
問題
    
           
#define FIQ_START 0
void disable_fiq(int fiq)
{
disable_irq(fiq + FIQ_START);
}
#define FIQ_START 0
void disable_fiq(int fiq)
{
disable_irq(fiq + FIQ_START);
}
#define FIQ_START 0
void enable_fiq(int fiq)
{
enable_irq(fiq + FIQ_START);
}
#define FIQ_START 0
void enable_fiq(int fiq)
{
enable_irq(fiq + FIQ_START);
}
以 Nvidia T30 BSP 為例,下面 API 對 Interrupt 和 OS Schedule 的
處理有什麼影響 ?
enable_irq() / disable_irq()
enable_fiq() / disable_fiq()
spin_lock() / spin_unlock()
spin_lock_irq() / spin_unlock_irq()
spin_lock_irqsave() / spin_unlock_irqrestore()
問題
    
           
Not affect the interruptNot affect the interrupt
以 Nvidia T30 BSP 為例,下面 API 對 Interrupt 和 OS Schedule 的
處理有什麼影響 ?
enable_irq() / disable_irq()
enable_fiq() / disable_fiq()
spin_lock() / spin_unlock()
spin_lock_irq() / spin_unlock_irq()
spin_lock_irqsave() / spin_unlock_irqrestore()
問題
    
           
static inline void arch_local_irq_disable(void)
{
asm volatile(
" cpsid i @ arch_local_irq_disable"
: :
: "memory", "cc");
}
static inline void arch_local_irq_disable(void)
{
asm volatile(
" cpsid i @ arch_local_irq_disable"
: :
: "memory", "cc");
}
static inline void arch_local_irq_enable(void)
{
asm volatile(
" cpsie i @ arch_local_irq_enable"
: :
: "memory", "cc");
}
static inline void arch_local_irq_enable(void)
{
asm volatile(
" cpsie i @ arch_local_irq_enable"
: :
: "memory", "cc");
}
以 Nvidia T30 BSP 為例,下面 API 對 Interrupt 和 OS Schedule 的
處理有什麼影響 ?
enable_irq() / disable_irq()
enable_fiq() / disable_fiq()
spin_lock() / spin_unlock()
spin_lock_irq() / spin_unlock_irq()
spin_lock_irqsave() / spin_unlock_irqrestore()
static inline unsigned long arch_local_irq_save(void)
{
unsigned long flags;
asm volatile(
" mrs %0, cpsr @ arch_local_irq_save"
" cpsid i"
: "=r" (flags) : : "memory", "cc");
return flags;
}
static inline unsigned long arch_local_irq_save(void)
{
unsigned long flags;
asm volatile(
" mrs %0, cpsr @ arch_local_irq_save"
" cpsid i"
: "=r" (flags) : : "memory", "cc");
return flags;
}
問題
    
           
static inline void
arch_local_irq_restore(unsigned long flags)
{
asm volatile(
" msr cpsr_c, %0 @ local_irq_restore"
:
: "r" (flags)
: "memory", "cc");
}
static inline void
arch_local_irq_restore(unsigned long flags)
{
asm volatile(
" msr cpsr_c, %0 @ local_irq_restore"
:
: "r" (flags)
: "memory", "cc");
}
spinlock_t dsp_lock; /* global dsp lock */
int dsp_mode;
void dsp_main()
{
spin_lock_irqsave(&dsp_lock, flags);
dsp_cmx_hardware();
...
dsp_mode = 2;
dsp_proc(dsp_mode);
...
spin_unlock_irqrestore(&dsp_lock, flags);
}
spinlock_t dsp_lock; /* global dsp lock */
int dsp_mode;
void dsp_main()
{
spin_lock_irqsave(&dsp_lock, flags);
dsp_cmx_hardware();
...
dsp_mode = 2;
dsp_proc(dsp_mode);
...
spin_unlock_irqrestore(&dsp_lock, flags);
}
    
           
void dsp_isr()
{
spin_lock_irqsave(&dsp_lock, flags);
dsp_mode = 0;
dsp_proc(dsp_mode);
spin_unlock_irqrestore(&dsp_lock, flags);
}
void dsp_isr()
{
spin_lock_irqsave(&dsp_lock, flags);
dsp_mode = 0;
dsp_proc(dsp_mode);
spin_unlock_irqrestore(&dsp_lock, flags);
}
Potential Bug
void dsp_cmx_hardware()
{
...
}
void dsp_cmx_hardware()
{
...
}
spin_lock_irq(xxx_lock);
...
spin_unlock_irq(xxx_lock);
Enable IRQ
Mode
DeadlockDeadlock
Interrupt
    
           
Linux API
Interrupt
Process
Affect OS
Schedule
enable_irq() disable_irq() Interrupt Controller No
enable_fiq() disable_fiq() Interrupt Controller No
spin_lock() spin_unlock() X No
spin_lock_irq() spin_unlock_irq()
IRQ mode of ARM
core
Yes
spin_lock_irqsav
e()
spin_unlock_irqresto
re()
IRQ mode of ARM
core
Yes
Thank you
E-mail: jethro1123@gmail.com.tw

More Related Content

What's hot

簡易的面試心得分享
簡易的面試心得分享簡易的面試心得分享
簡易的面試心得分享Jack Wang
 
晴峯閣-介紹簡報
晴峯閣-介紹簡報晴峯閣-介紹簡報
晴峯閣-介紹簡報ssuser216512
 
(公開版)Reconf研2017GUINNESS
(公開版)Reconf研2017GUINNESS(公開版)Reconf研2017GUINNESS
(公開版)Reconf研2017GUINNESSHiroki Nakahara
 
AMD_Xilinx_AI_VCK5000_20220602R1.pdf
AMD_Xilinx_AI_VCK5000_20220602R1.pdfAMD_Xilinx_AI_VCK5000_20220602R1.pdf
AMD_Xilinx_AI_VCK5000_20220602R1.pdf直久 住川
 
2015年度GPGPU実践プログラミング 第10回 行列計算(行列-行列積の高度な最適化)
2015年度GPGPU実践プログラミング 第10回 行列計算(行列-行列積の高度な最適化)2015年度GPGPU実践プログラミング 第10回 行列計算(行列-行列積の高度な最適化)
2015年度GPGPU実践プログラミング 第10回 行列計算(行列-行列積の高度な最適化)智啓 出川
 
プリント基板設計 RaspberryPi HAT基板設計実習
プリント基板設計 RaspberryPi HAT基板設計実習プリント基板設計 RaspberryPi HAT基板設計実習
プリント基板設計 RaspberryPi HAT基板設計実習MarbleStream
 
社會網絡分析法軟體-NodeXL教學-郭迺鋒與林崑峯-三星課程網2013
社會網絡分析法軟體-NodeXL教學-郭迺鋒與林崑峯-三星課程網2013社會網絡分析法軟體-NodeXL教學-郭迺鋒與林崑峯-三星課程網2013
社會網絡分析法軟體-NodeXL教學-郭迺鋒與林崑峯-三星課程網2013Beckett Hsieh
 
Zynq MPSoC勉強会 Codec編
Zynq MPSoC勉強会 Codec編Zynq MPSoC勉強会 Codec編
Zynq MPSoC勉強会 Codec編Tetsuya Morizumi
 
금융회사 대표가 된 평범한 개발자 이야기.pptx
금융회사 대표가 된  평범한 개발자 이야기.pptx금융회사 대표가 된  평범한 개발자 이야기.pptx
금융회사 대표가 된 평범한 개발자 이야기.pptxGeneral Programmer
 
Xj CHEROKEE manual do proprietario
Xj CHEROKEE manual do proprietarioXj CHEROKEE manual do proprietario
Xj CHEROKEE manual do proprietarioPaulo Zurro Fraysse
 
CTF for ビギナーズ ネットワーク講習資料
CTF for ビギナーズ ネットワーク講習資料CTF for ビギナーズ ネットワーク講習資料
CTF for ビギナーズ ネットワーク講習資料SECCON Beginners
 
Fibre Bathroom Door Designs In Kerala | Fiber Door For Bathroom
Fibre Bathroom Door Designs In Kerala | Fiber Door For BathroomFibre Bathroom Door Designs In Kerala | Fiber Door For Bathroom
Fibre Bathroom Door Designs In Kerala | Fiber Door For Bathroombpshafeeque
 
半導體製程設備裝機工程管理之研究
半導體製程設備裝機工程管理之研究半導體製程設備裝機工程管理之研究
半導體製程設備裝機工程管理之研究5045033
 
GPUをJavaで使う話(Java Casual Talks #1)
GPUをJavaで使う話(Java Casual Talks #1)GPUをJavaで使う話(Java Casual Talks #1)
GPUをJavaで使う話(Java Casual Talks #1)なおき きしだ
 
オープンソースコンパイラNNgenでつくるエッジ・ディープラーニングシステム
オープンソースコンパイラNNgenでつくるエッジ・ディープラーニングシステムオープンソースコンパイラNNgenでつくるエッジ・ディープラーニングシステム
オープンソースコンパイラNNgenでつくるエッジ・ディープラーニングシステムShinya Takamaeda-Y
 

What's hot (20)

簡易的面試心得分享
簡易的面試心得分享簡易的面試心得分享
簡易的面試心得分享
 
晴峯閣-介紹簡報
晴峯閣-介紹簡報晴峯閣-介紹簡報
晴峯閣-介紹簡報
 
(公開版)Reconf研2017GUINNESS
(公開版)Reconf研2017GUINNESS(公開版)Reconf研2017GUINNESS
(公開版)Reconf研2017GUINNESS
 
Plan 9のお話
Plan 9のお話Plan 9のお話
Plan 9のお話
 
應徵軟體工程師
應徵軟體工程師應徵軟體工程師
應徵軟體工程師
 
AMD_Xilinx_AI_VCK5000_20220602R1.pdf
AMD_Xilinx_AI_VCK5000_20220602R1.pdfAMD_Xilinx_AI_VCK5000_20220602R1.pdf
AMD_Xilinx_AI_VCK5000_20220602R1.pdf
 
Abnt nbr iec 62271 200
Abnt nbr iec 62271 200Abnt nbr iec 62271 200
Abnt nbr iec 62271 200
 
2015年度GPGPU実践プログラミング 第10回 行列計算(行列-行列積の高度な最適化)
2015年度GPGPU実践プログラミング 第10回 行列計算(行列-行列積の高度な最適化)2015年度GPGPU実践プログラミング 第10回 行列計算(行列-行列積の高度な最適化)
2015年度GPGPU実践プログラミング 第10回 行列計算(行列-行列積の高度な最適化)
 
プリント基板設計 RaspberryPi HAT基板設計実習
プリント基板設計 RaspberryPi HAT基板設計実習プリント基板設計 RaspberryPi HAT基板設計実習
プリント基板設計 RaspberryPi HAT基板設計実習
 
社會網絡分析法軟體-NodeXL教學-郭迺鋒與林崑峯-三星課程網2013
社會網絡分析法軟體-NodeXL教學-郭迺鋒與林崑峯-三星課程網2013社會網絡分析法軟體-NodeXL教學-郭迺鋒與林崑峯-三星課程網2013
社會網絡分析法軟體-NodeXL教學-郭迺鋒與林崑峯-三星課程網2013
 
新呈工業12 s介紹
新呈工業12 s介紹新呈工業12 s介紹
新呈工業12 s介紹
 
Zynq MPSoC勉強会 Codec編
Zynq MPSoC勉強会 Codec編Zynq MPSoC勉強会 Codec編
Zynq MPSoC勉強会 Codec編
 
금융회사 대표가 된 평범한 개발자 이야기.pptx
금융회사 대표가 된  평범한 개발자 이야기.pptx금융회사 대표가 된  평범한 개발자 이야기.pptx
금융회사 대표가 된 평범한 개발자 이야기.pptx
 
Xj CHEROKEE manual do proprietario
Xj CHEROKEE manual do proprietarioXj CHEROKEE manual do proprietario
Xj CHEROKEE manual do proprietario
 
CTF for ビギナーズ ネットワーク講習資料
CTF for ビギナーズ ネットワーク講習資料CTF for ビギナーズ ネットワーク講習資料
CTF for ビギナーズ ネットワーク講習資料
 
Fibre Bathroom Door Designs In Kerala | Fiber Door For Bathroom
Fibre Bathroom Door Designs In Kerala | Fiber Door For BathroomFibre Bathroom Door Designs In Kerala | Fiber Door For Bathroom
Fibre Bathroom Door Designs In Kerala | Fiber Door For Bathroom
 
半導體製程設備裝機工程管理之研究
半導體製程設備裝機工程管理之研究半導體製程設備裝機工程管理之研究
半導體製程設備裝機工程管理之研究
 
GPUをJavaで使う話(Java Casual Talks #1)
GPUをJavaで使う話(Java Casual Talks #1)GPUをJavaで使う話(Java Casual Talks #1)
GPUをJavaで使う話(Java Casual Talks #1)
 
オープンソースコンパイラNNgenでつくるエッジ・ディープラーニングシステム
オープンソースコンパイラNNgenでつくるエッジ・ディープラーニングシステムオープンソースコンパイラNNgenでつくるエッジ・ディープラーニングシステム
オープンソースコンパイラNNgenでつくるエッジ・ディープラーニングシステム
 
RISC-Vの可能性
RISC-Vの可能性RISC-Vの可能性
RISC-Vの可能性
 

Similar to 20120613 - Hardware knowledge which the software engineer must understand

Electrical parameter measurement
Electrical parameter measurementElectrical parameter measurement
Electrical parameter measurementchuancao
 
第6章 输入输出技术
第6章 输入输出技术第6章 输入输出技术
第6章 输入输出技术jugn
 
數位邏輯實習 實習手冊Ch2教用
數位邏輯實習 實習手冊Ch2教用數位邏輯實習 實習手冊Ch2教用
數位邏輯實習 實習手冊Ch2教用lungtengtech
 
电气英文单词
电气英文单词电气英文单词
电气英文单词micholl2005
 
Cogent Ate D100 Presentation
Cogent Ate D100 PresentationCogent Ate D100 Presentation
Cogent Ate D100 PresentationWilliam Huo
 
Original NPN Transistor 3DD304X D304X 304 12A 400V TO-220 New SINO-MICROELECT...
Original NPN Transistor 3DD304X D304X 304 12A 400V TO-220 New SINO-MICROELECT...Original NPN Transistor 3DD304X D304X 304 12A 400V TO-220 New SINO-MICROELECT...
Original NPN Transistor 3DD304X D304X 304 12A 400V TO-220 New SINO-MICROELECT...AUTHELECTRONIC
 
PIC单片机的A/D和D/A技术
PIC单片机的A/D和D/A技术PIC单片机的A/D和D/A技术
PIC单片机的A/D和D/A技术krfantasy
 
Deployment instruction tg4100 f-ig_cn
Deployment instruction tg4100 f-ig_cnDeployment instruction tg4100 f-ig_cn
Deployment instruction tg4100 f-ig_cnahnlabchina
 
穩壓元件及其相關迴路之研究 --以可調式輸出電源供應器為例
穩壓元件及其相關迴路之研究 --以可調式輸出電源供應器為例穩壓元件及其相關迴路之研究 --以可調式輸出電源供應器為例
穩壓元件及其相關迴路之研究 --以可調式輸出電源供應器為例Chen-Hung Hu
 
数字电路复习
数字电路复习数字电路复习
数字电路复习zhaowmm
 
Arduino 習作工坊 - Lesson 2 動力之夜
Arduino 習作工坊 - Lesson 2 動力之夜Arduino 習作工坊 - Lesson 2 動力之夜
Arduino 習作工坊 - Lesson 2 動力之夜CAVEDU Education
 
Motion cs 1
Motion cs 1Motion cs 1
Motion cs 1kairry
 
03 计算机的逻辑部件02
03 计算机的逻辑部件0203 计算机的逻辑部件02
03 计算机的逻辑部件02Huaijin Chen
 

Similar to 20120613 - Hardware knowledge which the software engineer must understand (20)

Electrical parameter measurement
Electrical parameter measurementElectrical parameter measurement
Electrical parameter measurement
 
第6章 输入输出技术
第6章 输入输出技术第6章 输入输出技术
第6章 输入输出技术
 
89S51電路板
89S51電路板89S51電路板
89S51電路板
 
數位邏輯實習 實習手冊Ch2教用
數位邏輯實習 實習手冊Ch2教用數位邏輯實習 實習手冊Ch2教用
數位邏輯實習 實習手冊Ch2教用
 
第6章
第6章第6章
第6章
 
电气英文单词
电气英文单词电气英文单词
电气英文单词
 
Gkdq5
Gkdq5Gkdq5
Gkdq5
 
20 cpu04
20 cpu0420 cpu04
20 cpu04
 
Cogent Ate D100 Presentation
Cogent Ate D100 PresentationCogent Ate D100 Presentation
Cogent Ate D100 Presentation
 
Original NPN Transistor 3DD304X D304X 304 12A 400V TO-220 New SINO-MICROELECT...
Original NPN Transistor 3DD304X D304X 304 12A 400V TO-220 New SINO-MICROELECT...Original NPN Transistor 3DD304X D304X 304 12A 400V TO-220 New SINO-MICROELECT...
Original NPN Transistor 3DD304X D304X 304 12A 400V TO-220 New SINO-MICROELECT...
 
PIC单片机的A/D和D/A技术
PIC单片机的A/D和D/A技术PIC单片机的A/D和D/A技术
PIC单片机的A/D和D/A技术
 
Deployment instruction tg4100 f-ig_cn
Deployment instruction tg4100 f-ig_cnDeployment instruction tg4100 f-ig_cn
Deployment instruction tg4100 f-ig_cn
 
穩壓元件及其相關迴路之研究 --以可調式輸出電源供應器為例
穩壓元件及其相關迴路之研究 --以可調式輸出電源供應器為例穩壓元件及其相關迴路之研究 --以可調式輸出電源供應器為例
穩壓元件及其相關迴路之研究 --以可調式輸出電源供應器為例
 
数字电路复习
数字电路复习数字电路复习
数字电路复习
 
Arduino 習作工坊 - Lesson 2 動力之夜
Arduino 習作工坊 - Lesson 2 動力之夜Arduino 習作工坊 - Lesson 2 動力之夜
Arduino 習作工坊 - Lesson 2 動力之夜
 
18 cpu02
18 cpu0218 cpu02
18 cpu02
 
Sr868a cn-20100110
Sr868a cn-20100110Sr868a cn-20100110
Sr868a cn-20100110
 
Motion cs 1
Motion cs 1Motion cs 1
Motion cs 1
 
03 计算机的逻辑部件02
03 计算机的逻辑部件0203 计算机的逻辑部件02
03 计算机的逻辑部件02
 
19 cpu03
19 cpu0319 cpu03
19 cpu03
 

20120613 - Hardware knowledge which the software engineer must understand

  • 1. Hardware knowledge which the software engineer must understand Jethro Yeh 葉建良 2012/06/13
  • 2. Outline • 電子電路基礎概念 • 數位訊號基礎概念  實際案例 • 系統單晶片處理器基礎概念  SoC Processor Block Diagram  Clock Block Diagram  Power Management  GPIO setting  Transmit the data among I/O  Interrupt  ARM Interrupt Vector Table  Linux API vs. Interrupt Process  實際案例
  • 5. • 電壓:兩點之間的電位差 ( 單位電荷的能量差 ) 。當談到某處電壓為何時,通常指 對應某一參考點的電位差為何。單位為伏特(簡寫 V )。 • 電流:電子的流動稱為電流,電流流動的動力來自電源提供的電壓。 電流在電路中由高電位流向低電位,形成一個循環的通路。 可以將電流想像成水流,電流在電路中由高電位流向低電位流動,就像水 受到水壓而由高處向低處流動。單位為安培(簡寫 A )。
  • 6. 電阻器 • 在相同的電壓之下,電阻器的電阻值越大,能夠流過的電流就 越小。 • 電阻器的單位為 Ω( 歐姆 ) ,其主要用途包括: - 限制流經某一段電路的電流 ( 限流 ) - 製造固定的電壓 ( 分壓 ) 。                 
  • 7. 電阻器 – 串聯 • 電阻器串聯: 1. 電路兩端的總電阻值為各電阻器阻值之相加總和         2. 流經電阻器的電流大小是相等的                  3V 10K 20K
  • 8. 電阻器 – 並聯                  • 電阻器並聯: 1. 電阻器的電壓大小相同     2. 等效電阻會變小 If R1=R2=10K, Req = 5K
  • 9. 電容器 • 由兩片平行的金屬板加以絕緣物質隔離,所構成的可儲存電能的元件稱為 電容器。其單位為法拉 ( 簡寫F ) 。 • 因電容由兩金屬片構成,中間有絕緣物,直流電無法流過電容,但通上交 流電時,由於電容能充放電所致,所以能讓交流電通過。 • 特性:阻直流、通交流 • 主要用途:濾波、穩壓                 
  • 11. RC 充電                  1 t = 1RC : 0.6321*V1 2RC : 0.8647*V1 3RC : 0.9502*V1 4RC : 0.9817*V1 5RC : 0.9933*V1 e:2.7183 RC 小 RC 大 -
  • 12. RC 放電                  1 RC 越小:充放電越快 RC 越大:充放電越慢 - t = 1RC : 0.3679*V1 2RC : 0.1353*V1 3RC : 0.0498*V1 4RC : 0.0183*V1 5RC : 0.0067*V1
  • 13. 二極體                  • 二極體具有陽極 (P 型 ) 和陰極 (N 型 ) 兩個端子。電流只能往單一方向流動 ,電流可以從陽極流向陰極 ( 順向偏壓 ) ,不能從陰極流向陽極 ( 逆向偏壓 ) 。因為這種特性常被應用在整流或開關。 • 矽半導體的臨界電壓約 0.6V ~ 0.7V ,鍺半導體約 0.3 ~ 0.4V 。 大多應用 在逆電壓
  • 14. 金屬氧化物半導體場效電晶體 (MOSFET)                  • 在大部分的應用和符號,基板本體會和源極接在一起。 • 常見用途:開關、壓控電阻。 • N 通道:當 VGS<Vth( 臨界電壓 ) ,則 D 和 S 不導通;當 VGS>Vth ,則 D 和 S 導通。 P 通道:當 VSG<Vth ,則 D 和 S 不導通;當 VSG>Vth ,則 D 和 S 導通。
  • 15. MOSFET 應用                  • EN_SENSOR_1V8 = 0V , VDD_1V8_GEN 和 VDD_1V8_SENSOR 導通 EN_SENSOR_1V8 = 1.8V , VDD_1V8_GEN 和 VDD_1V8_SENSOR 不導通
  • 17. 類比訊號 vs. 數位訊號                  • 類比訊號:在任何一個時間點,均有連續的訊號存在。例如:聲波變化、 溫度變化、濕度變化等。 • 數位訊號:一般情況下,數位訊號只會在 0 或 1( 高和低電位 ) 這兩種狀態 之 間切換,是不連續的訊號,具有不易受干擾的優點。 雜訊干擾將電壓 提升或降低 0.1V 雜訊干擾將電壓 提升或降低 0.1V 1.8V 1 0
  • 18. 數位電路的優點                  • 電子電路有數位 (digital) 電路與類比 (analog) 電路兩大類,而數位電路較類 比電路有以下的優點: - 抗雜訊 (noise) 干擾能力較強。 - 可靠性高。 - 資料利用數位的形式比較容易儲存。 - 數位電路較易設計,可以達到精確的控制和較複雜的功能。 - 較容易使用現今的積體電路 (integrated circuit, IC) 來加以設計。
  • 19. 邏輯準位                  • 一般數位電路中,邏輯「 0 」代表「低電位」,邏輯「 1 」代表「高電位」 。 • 輸入端:小於等於 VIL 的電壓被視為邏輯「 0 」,大於等於 VIH 的電壓被視 為邏 輯「 1 」。 • 輸出端:邏輯「 0 」會輸出小於等於 VOL 的電壓,邏輯「 1 」會輸出大於等 於 VOH 的電壓。 Floating ,會有邏輯誤判問題
  • 20. 脈波準位                  • 脈波幅度的百分之 10 到百分之 90 所需時間稱為上升時間 t r ,脈波幅度的 百分之 90 到百分之 10 所需時間稱為下降時間 t f 。 • 若上升時間及下降時間越短,表示反應速度越快。 Rising time Falling time
  • 23. Power On Sequence                  VCC Reset Interface 0x10=2 0x12=4 Data >50ms >200ms >10ms>1ms >50ms
  • 25. Power On Sequence - SW                  VCC Reset Interface 0x10=2 0x12=4 Data >50ms >200ms >10ms>1ms >50ms 1 2 3 4 5 6 8 7 系統 resume 或 GPIO setting 改變 或 HW 改變 或 雜訊干擾
  • 26. Power On Sequence - Proposed SW                  VCC Reset Interface 0x10=2 0x12=4 Data >50ms >200ms >10ms>1ms >50ms 1 2 3 4 5 6 8 7 9 10 問 Vendor
  • 27. Power On Sequence – Case 1 問題描述:機器開機使用幾個小時後,發生 kernel panic. 而且問題只會發生在少數的機器 . 分析:從 log 看到, Sensor 使用 I2C bus 讀取資料,但 I2C driver 顯示 fail message(I2C timeout or NAK). 更後面有 Sensor driver 造成 kernel panic 的 message. 大家開始怪 I2C driver大家開始怪 I2C driver 要求 Sensor driver 在 I2C fail 時,加入 retry 機制要求 Sensor driver 在 I2C fail 時,加入 retry 機制 要求 Sensor driver 注意 I2C fail 也不能造成 kernel panic 要求 Sensor driver 注意 I2C fail 也不能造成 kernel panic 問題發生的機率變低許多,但有時 Sensor driver 還是無法透過 I2C 要到資料問題發生的機率變低許多,但有時 Sensor driver 還是無法透過 I2C 要到資料 大家又開始怪 I2C driver大家又開始怪 I2C driver I2C owner 花了幾天在複製問題且架環境來量測 HW 訊號,最後發覺是 Sensor Chip 沒有回 應 I2C owner 花了幾天在複製問題且架環境來量測 HW 訊號,最後發覺是 Sensor Chip 沒有回 應 Sensor owner 最後查到 Power on sequence 不符合 Sensor data sheet 的要求Sensor owner 最後查到 Power on sequence 不符合 Sensor data sheet 的要求 Sensor 的 Power on sequence 符合 data sheet 的要求後,問題再也沒出現Sensor 的 Power on sequence 符合 data sheet 的要求後,問題再也沒出現 不是每顆 chip 都會發生問題不是每顆 chip 都會發生問題偶爾會出問題偶爾會出問題 合理, Error handle 要做 好 合理, Error handle 要做 好 可以思考及討論可以思考及討論
  • 28. Power On Sequence – Case 2 問題描述:有些機器,有時 Sensor 不能正常 work. 分析:從 log 看到, Sensor 使用 I2C bus 讀取資料,但 I2C driver 顯示 fail message(I2C timeout or NAK). 大家又開始怪 I2C driver 了大家又開始怪 I2C driver 了 Sensor owner 確定 SW 控制的 Power on sequence 符合 Sensor data sheetSensor owner 確定 SW 控制的 Power on sequence 符合 Sensor data sheet 應主管要求,去量測發生問題時的 Sensor Power on 的 sequence , 結果發現沒有符合 Sensor data sheet 的要求 應主管要求,去量測發生問題時的 Sensor Power on 的 sequence , 結果發現沒有符合 Sensor data sheet 的要求Why?
  • 29. Power On Sequence – Case 2 3V3 1V8 0~20ms Data Sheet 3V3 1V8 1.3ms Real HW int Sensor_init() { SensorEnable_3V3(); SensorEnable_1V8(); … } int Sensor_init() { SensorEnable_3V3(); SensorEnable_1V8(); … } SW tegra_gpio_enable(); gpio_request(); gpio_direction_output() ; tegra_gpio_enable(); gpio_request(); gpio_direction_output() ; Why?
  • 30. Power On Sequence – Case 2 1.8 0 0 3.3 0 3.3 放 電 放電 2.6 3.3 2.39ms 後 , 變成 2.6V t = 2.39ms - 3V3 3V3
  • 31. Power On Sequence – Case 2 0 1.8 1.8 0
  • 32. Power On Sequence – Case 2 3V3 1V8 Real HW int Sensor_init() { SensorEnable_3V3(); SensorEnable_1V8(); … } int Sensor_init() { SensorEnable_3V3(); SensorEnable_1V8(); … } SW 2.39ms 1.3ms1ms tegra_gpio_enable(); gpio_request(); gpio_direction_output(); tegra_gpio_enable(); gpio_request(); gpio_direction_output(); tegra_gpio_enable(); gpio_request(); gpio_direction_output(); tegra_gpio_enable(); gpio_request(); gpio_direction_output();
  • 33. Check Power On/Off Sequence of Component 1. Check power on sequence of component when device power on 2. Check power off sequence of component when device power off 3. Check power off sequence of component when system suspend 4. Check power on sequence of component when system resume 5. Check power on sequence of component when SW and HW reset 系統 suspend/resume 時, component 有 power on/off 才需要做 check
  • 35. 系統單晶片處理器                  • 一個典型的系統單晶片 (System-on-Chip ; SoC) 處理器會由以下各元件所組成 :    - 一個或是多個微處理器、微控制器或是 DSP    - 記憶體部份包含唯讀記憶體、隨機存取記憶體、 快閃記憶體等    - 振盪器及 PLL 提供系統所需時脈來源    - 其他週邊還有計數器 counter-timer , RTC 或是 Watchdog Timer    - 額外工業標準的界面,像是 USB, I2C 等 .    - 類比界面包含了類比 - 數位轉換器及數位 - 類比轉換器    - 電壓調整電路及電源管理
  • 36. SoC Processor Block Diagram                 
  • 37. 時脈 (Clock)                  • 時脈是一種固定週期的脈波,用來控制電路做動作或做訊號同步,一般一 個脈波週期是電路運作最基本的時間單位。 • 時脈頻率 (Clock rate) 是指同步電路中時脈的基礎頻率,它以「每秒多少週 期脈波」來度量,單位是赫茲 (Hz) 。 • 時脈是最基本的要素。任何時脈錯誤,均可能造成傳輸或接收不正確的資 料。 • SoC Processor 的時脈頻率通常是由晶體振蕩器的頻率提供的。 Rising edge Falling edge
  • 38. 石英晶體 & 石英晶體振盪器                  • 石英晶體振盪器是利用石英晶體的壓電效應,用來產生高精度振盪頻率的 一種電子元件。 • 石英晶體( crystal 或 Xtal )是石英晶片加上電極與外殼封裝。 這是單純 石英晶體被動元件,不含主動元件,需搭配外加電路才會產生振盪。石英 晶體通常是兩支接腳的電子元件。 • 石英晶體振盪器( crystal oscillator ,簡寫 OSC 或 XO )是指內含石英晶 體與振盪電路的模組,需要電源,可直接產生振盪訊號輸出。 石英振盪器 通常是四支接腳的電子元件,其中兩支為電源,一支為振盪訊號輸出,另 一支為空腳或控制用。
  • 39. 鎖相迴路 (PLL ; Phase Locked Loop)                  • 鎖相迴路是一種利用反饋 (Feedback) 控制原理來實現的頻率及相位同步技 術,其作用是將電路輸出的 Clock 與其外部的參考 Clock 保持同步。當參考 Clock 的頻率或相位發生改變時,鎖相迴路會檢測到這種變化,並且通過其 內部的反饋系統來調節輸出頻率,直到兩者重新同步,這種同步又稱為「 鎖相」 (Phase-locked) 。 • PLL 大部分用來產生精確的 Clock 。 PD : 相位偵測 LPF :低通濾波器 VCO :壓控振蕩器 DIV : 除頻器
  • 42. SoC Processor Power Mode                 
  • 43. Component Power Mode                  • Normal Mode • Standby Mode • Sleep Mode • Deep Sleep Mode • Auto Sleep Mode • Power off Mode
  • 44. OS Power State                  OS SoC Processor Most Controller Most Component Normal / Run Mode Normal Mode Power on/off Enable/Disable PLL Normal Mode Auto Sleep Mode Power off Mode Idle Mode Idle Mode Standby Mode Power on/off Enable/Disable PLL Normal Mode Auto Sleep Mode Power off Mode Suspend Mode Sleep Mode Deep Sleep Mode Power on/off Enable/Disable PLL Auto Sleep Mode Standby Mode Sleep Mode Deep Sleep Mode Power off Mode Power off Mode Power off Mode Power off Mode Power off Mode
  • 46. Power Management – OS Suspend Mode   Component Processor Controller Power Off / Clock Off (Power Off Mode) 1. Check power consumption 2. Check the time of power on/off sequence 3. Affect other components/function - Share the power with other parts/component 4. Need initialize registers again when power on (follow "Power On/Off Sequence") 5. The pin keep low level 1. Check power consumption 2. Check the time of power on/off sequence 3. Affect other function/pin - Share the power with other parts/controller - Check power domain (may be pin floating) 4. Need initialize registers again when power on (follow "Power On/Off Sequence") 5. The pin keep low level Power On / Clock Off (Standby/Sleep Mode) 1. Check power consumption 2. Check the time of turn on/off sequence 3. Check wake up source 4. Don't affect the function when modify the bus/GPIO configuration of the 1. Check power consumption 2. Check the time of turn on/off sequence 3. Don't affect the function when modify the bus/GPIO configuration of the
  • 47. 提昇 / 下拉 電阻 (Pull-Up/ Pull-Down Resistor) SoC Processor Component VCC Pull up Resistor Pull down Resistor
  • 48. 提昇 / 下拉 電阻 (Pull-Up/ Pull-Down Resistor) • 防止輸入端懸空。當輸入端懸空易受靜電等干擾,這些靜電可能會燒毀晶 片或電路。 • 改變輸出的電壓準位。 • 在輸入端懸空時有確定的 High/Low 狀態 。 • 增加輸出的電流驅動能力。 (Pull-Up) • 提昇電阻的阻值會影響高低電位轉換的速度 。阻值越小,速度越快,消耗 功率越大。反之亦然。 • 當電流流經提昇電阻時會消耗額外的消耗功率,並且可能會引起輸出電位 的延遲。
  • 49. 下拉 電阻 (Pull-Down Resistor) SoC Processor Charger ICReset pin High active High Impedance
  • 50. 提昇電阻 (Pull-Up Resistor) SoC Processor SD Detect 100K0.033mA SDLow 3V3 SDLow 0.033mA * 30 = 0.99mA
  • 51. 通用輸入輸出 (General Purpose I/O)                  • PIN 腳可以由程式控制自由使用。 PIN 腳依現實考量可作為通用輸入 (GPI) 或通用輸出 (GPO) 。 • 不是每根 PIN 腳都能設成 GPIO 。 Pin Function Function 1   Function 2   …   GPIO Output High Low Input Pull Up Pull Down No Pull Hi-Z or High Impedance Pull Up Pull Down No Pull By Processor
  • 52. GPIO - Output                  SoC Processor LCD Controller VCC_LCD Output Pin 12: 0: Disable 1: Enable Pin 10 Vibrator Input Pin 12 GPIO Controller VCC_IO Power? Function Control
  • 54. GPIO - Output                  xxx Controller Output GPIO Controller SoC Processor 15K 3V3 3V3 0V Default 0.22mA 建議改用 No pull
  • 55. GPIO - Input                  xxx Controller Input GPIO Controller SoC Processor Pull up Pull down By Processor Pull up Pull down
  • 56. GPIO - Input                  xxx Controller SD Detect GPIO Controller SoC Processor Pull up? Pull down? No pull? 1. Function work 2. Power consumption SDLow Low active
  • 57. GPIO - Input                  xxx Controller SD Detect GPIO Controller SoC Processor Pull up? Pull down? No pull? 1. Function work 2. Power consumption SDHigh High active
  • 58. GPIO - Input                  xxx Controller Gyro interrupt GPIO Controller SoC Processor Pull up? Pull down? No pull? 1. Function work 2. Power consumption Gyro Sensor High active
  • 59. GPIO - Input                  xxx Controller GPIO Controller SoC Processor Pull up? Pull down? No pull? 1. Function work 2. Power consumption Thermal Sensor Low active TEMP_ALERT#
  • 60. Case 1 - Component Power off mode                  xxx Controller GPIO Controller SoC Processor Component I2C VCC ? Functio n Function 1 I2C Function 2   …   GPIO Output High Low Input Pull Up Pull
  • 61. Case 2 - Component Sleep mode                  xxx Controller GPIO Controller SoC Processor Component I2C VCC ? Functio n Function 1 I2C Function 2   …   GPIO Output High Low Pull Up Enter/Exit sleep mode through I2C command
  • 62. Case 3 – I2C discussion                  I2C Controller GPIO Controller SoC Processor L-Sensor VCC P-Sensor VCC Gyro Sensor VCC I2C
  • 63. Case 3 – I2C discussion                  I2C Controller GPIO Controller SoC Processor Camera VCC I2C Output Low
  • 64. Case 4 – Power Domain Off                  SD Controller GPIO Controller SoC Processor LCD Reset VCC VCC_SD SD VCC LED High active VCC High activeHi-Z Hi-Z VCC_SD Recommend
  • 65. Case 5 – GPIO of Tegra 3                  Tegra3_TRM_DP05644001v01_sec.pdf P.414 SFIO/GPIO Pin Multiplexing Architecture P.285 Structure of Pinmux Controller Tegra3_Datasheet_DS05160001_v3.0_sec.pdf P.84 POR (Power On Reset) P.85 After Wake, pin State
  • 66. Case 5 – GPIO API of Tegra 3                  gpio_request(); gpio_direction_output(); tegra_gpio_enable(); … gpio_free(); tegra_gpio_disable(); gpio_request(); gpio_direction_output(); tegra_gpio_enable(); … gpio_free(); tegra_gpio_disable(); gpio_request(); tegra_gpio_enable(); gpio_direction_output(); … tegra_gpio_disable(); gpio_request(); tegra_gpio_enable(); gpio_direction_output(); … tegra_gpio_disable(); tegra_gpio_enable(); gpio_request(); gpio_direction_output(); … gpio_free(); tegra_gpio_disable(); tegra_gpio_enable(); gpio_request(); gpio_direction_output(); … gpio_free(); tegra_gpio_disable(); gpio_request(); gpio_direction_output(); … gpio_free(); gpio_request(); gpio_direction_output(); … gpio_free(); 1 32 4 tegra_gpio_disable(); … tegra_gpio_disable(); … 5 gpio_request(); tegra_gpio_enable(); gpio_direction_output(); … tegra_gpio_disable(); gpio_free(); gpio_request(); tegra_gpio_enable(); gpio_direction_output(); … tegra_gpio_disable(); gpio_free(); 6
  • 67. Case 5 – GPIO API of Tegra 3             gpio_request(); tegra_gpio_enable(); gpio_direction_output(); gpio_direction_input(); gpio_request(); tegra_gpio_enable(); gpio_direction_output(); gpio_direction_input(); tegra_gpio_disable(); gpio_free(); tegra_gpio_disable(); gpio_free(); The pin change to GPIO modeThe pin change to GPIO mode if ( gpio_desc[gpio]->flags == FLAG_REQUESTED ) return -EBUSY; set_bit ( FLAG_REQUESTED, &gpio_desc[gpio]->flags ); if ( gpio_desc[gpio]->flags == FLAG_REQUESTED ) return -EBUSY; set_bit ( FLAG_REQUESTED, &gpio_desc[gpio]->flags ); if ( gpio_desc[gpio]->flags == FLAG_REQUESTED ) return -EIO; tegra_gpio_set(chip, offset, value); tegra_gpio_mask_write(GPIO_MSK_OE(offset), offset, 1); if ( gpio_desc[gpio]->flags == FLAG_REQUESTED ) return -EIO; tegra_gpio_set(chip, offset, value); tegra_gpio_mask_write(GPIO_MSK_OE(offset), offset, 1); if ( gpio_desc[gpio]->flags == FLAG_REQUESTED ) return -EIO; tegra_gpio_mask_write(GPIO_MSK_OE(offset), offset, 0); if ( gpio_desc[gpio]->flags == FLAG_REQUESTED ) return -EIO; tegra_gpio_mask_write(GPIO_MSK_OE(offset), offset, 0); The pin change to SFIO modeThe pin change to SFIO mode if ( gpio_desc[gpio]->flags == FLAG_REQUESTED ) clear_bit(FLAG_REQUESTED, &desc->flags); if ( gpio_desc[gpio]->flags == FLAG_REQUESTED ) clear_bit(FLAG_REQUESTED, &desc->flags); 1 2 2 2 Option 3 4
  • 68. Case 5 – GPIO API of Tegra 3                  gpio_request(); gpio_direction_output(); tegra_gpio_enable(); … gpio_free(); tegra_gpio_disable(); gpio_request(); gpio_direction_output(); tegra_gpio_enable(); … gpio_free(); tegra_gpio_disable(); gpio_request(); tegra_gpio_enable(); gpio_direction_output(); … tegra_gpio_disable(); gpio_request(); tegra_gpio_enable(); gpio_direction_output(); … tegra_gpio_disable(); tegra_gpio_enable(); gpio_request(); gpio_direction_output(); … gpio_free(); tegra_gpio_disable(); tegra_gpio_enable(); gpio_request(); gpio_direction_output(); … gpio_free(); tegra_gpio_disable(); gpio_request(); gpio_direction_output(); … gpio_free(); gpio_request(); gpio_direction_output(); … gpio_free(); 1 32 4 tegra_gpio_disable(); … tegra_gpio_disable(); … 5 gpio_request(); tegra_gpio_enable(); gpio_direction_output(); … tegra_gpio_disable(); gpio_free(); gpio_request(); tegra_gpio_enable(); gpio_direction_output(); … tegra_gpio_disable(); gpio_free(); 6 Context switch gpio_free(); tegra_gpio_enable(); gpio_request(); gpio_free(); Context switch
  • 69. Transmit the data among I/O • Polling • Interrupt-driven I/O • DMA(Direct Memory Access)
  • 70. Polling • I/O device 只要將資訊放進 Status Register , CPU 透過 周期性的檢查來得知需要服 務的 device 。 GPIO Controller SD Controller LCD Controller I2C Controller CPU Core … 1 2 3 4…
  • 71. Interrupt-driven I/O GPIO Controller SD Controller LCD Controller I2C Controller CPU Core … Interrupt Controller • 利用 interrupt 的機制,當一 個 I/O device 需要服務時, 會發出 interrupt 來通知 CPU 。 CPU 收到 interrupt 後,再做相對應的處理。
  • 72. DMA • DMA 是一個特殊的硬體結構, 需要有一個 DMA controller , 它允許 I/O device 與記憶體之 間直接轉移資料,而不需經由 CPU 的參與。
  • 73. Polling vs. Interrupt vs. DMA   Polling Interrupt-driven I/O DMA 優點 1. 軟體實作最簡單 2. 可利用軟體來更改 CPU polling 的順序 1. 不用浪費許多時間在 polling 上面 1. 不用浪費許多時間在 polling 上面 2. 適用於高速裝置 3. 傳送大筆資料,最不 佔 CPU 時間,對系統效 能影響最小 缺點 1. 因為 CPU 速度遠快於 I/O device ,會浪費許多時間在 polling 上 2. Power consumption 變高會最 明顯 3. 系統效能下降會最明顯 4. 不適合高速裝置 1. 需要有 interrupt signal 和 ISR(Interrupt Service Routine) 存在 2. 不適合高速裝置 1. 需要有 DMA Controller 2. 控制方式較複雜
  • 74. SoC Processor Input Interrupt - GPIO                  Rising Edge Falling Edge High Level Low Level
  • 77. ARM Interrupt Vector Table                  Exception Type Mode Priority Normal Vector Address High Vector Address   Reset  Supervisor 1  0x00000000  0xFFFF0000   Undefined Instructions  Undefined 6  0x00000004  0xFFFF0004   S/W Interrupt  Supervisor 6  0x00000008  0xFFFF0008   Prefetch Abort  Abort 5  0x0000000C  0xFFFF000C   Data Abort  Abort 2  0x00000010  0xFFFF0010  Interrupt Request  IRQ 4  0x00000018  0xFFFF0018  Fast Interrupt Request  FIQ 3  0x0000001C  0xFFFF001C
  • 78. ARM Interrupt Vector Table                  .globl __vectors_start __vectors_start: ARM( swi SYS_ERROR0 ) W(b) vector_und + stubs_offset W(ldr) pc, .LCvswi + stubs_offset W(b) vector_pabt + stubs_offset W(b) vector_dabt + stubs_offset W(b) vector_addrexcptn + stubs_offset W(b) vector_irq + stubs_offset W(b) vector_fiq + stubs_offset .globl __vectors_end __vectors_end: kernel/arch/arm/kernel/entry-armv.Skernel/arch/arm/kernel/entry-armv.S
  • 79. ARM Interrupt Vector Table                  void __init early_trap_init(void) { unsigned long vectors = CONFIG_VECTORS_BASE; /* * Copy the vectors, stubs and kuser helpers (in entry-armv.S) * into the vector page, mapped at 0xffff0000, and ensure these * are visible to the instruction stream. */ memcpy((void *)vectors, __vectors_start, __vectors_end - __vectors_start); memcpy((void *)vectors + 0x200, __stubs_start, __stubs_end - __stubs_start); memcpy((void *)vectors + 0x1000 - kuser_sz, __kuser_helper_start, kuser_sz); } kernel/arch/arm/kernel/Traps.ckernel/arch/arm/kernel/Traps.c kernel/arch/arm/configs/picasso_m_defconfigkernel/arch/arm/configs/picasso_m_defconfig CONFIG_VECTORS_BASE=0xffff0000
  • 80. 以 Nvidia T30 BSP 為例,下面 API 對 Interrupt 和 OS Schedule 的 處理有什麼影響 ? enable_irq() / disable_irq() enable_fiq() / disable_fiq() spin_lock() / spin_unlock() spin_lock_irq() / spin_unlock_irq() spin_lock_irqsave() / spin_unlock_irqrestore() 問題                 
  • 81. 以 Nvidia T30 BSP 為例,下面 API 對 Interrupt 和 OS Schedule 的 處理有什麼影響 ? enable_irq() / disable_irq() enable_fiq() / disable_fiq() spin_lock() / spin_unlock() spin_lock_irq() / spin_unlock_irq() spin_lock_irqsave() / spin_unlock_irqrestore() 問題                  Register of Interrupt ControllerRegister of Interrupt Controller
  • 82. 以 Nvidia T30 BSP 為例,下面 API 對 Interrupt 和 OS Schedule 的 處理有什麼影響 ? enable_irq() / disable_irq() enable_fiq() / disable_fiq() spin_lock() / spin_unlock() spin_lock_irq() / spin_unlock_irq() spin_lock_irqsave() / spin_unlock_irqrestore() 問題                  #define FIQ_START 0 void disable_fiq(int fiq) { disable_irq(fiq + FIQ_START); } #define FIQ_START 0 void disable_fiq(int fiq) { disable_irq(fiq + FIQ_START); } #define FIQ_START 0 void enable_fiq(int fiq) { enable_irq(fiq + FIQ_START); } #define FIQ_START 0 void enable_fiq(int fiq) { enable_irq(fiq + FIQ_START); }
  • 83. 以 Nvidia T30 BSP 為例,下面 API 對 Interrupt 和 OS Schedule 的 處理有什麼影響 ? enable_irq() / disable_irq() enable_fiq() / disable_fiq() spin_lock() / spin_unlock() spin_lock_irq() / spin_unlock_irq() spin_lock_irqsave() / spin_unlock_irqrestore() 問題                  Not affect the interruptNot affect the interrupt
  • 84. 以 Nvidia T30 BSP 為例,下面 API 對 Interrupt 和 OS Schedule 的 處理有什麼影響 ? enable_irq() / disable_irq() enable_fiq() / disable_fiq() spin_lock() / spin_unlock() spin_lock_irq() / spin_unlock_irq() spin_lock_irqsave() / spin_unlock_irqrestore() 問題                  static inline void arch_local_irq_disable(void) { asm volatile( " cpsid i @ arch_local_irq_disable" : : : "memory", "cc"); } static inline void arch_local_irq_disable(void) { asm volatile( " cpsid i @ arch_local_irq_disable" : : : "memory", "cc"); } static inline void arch_local_irq_enable(void) { asm volatile( " cpsie i @ arch_local_irq_enable" : : : "memory", "cc"); } static inline void arch_local_irq_enable(void) { asm volatile( " cpsie i @ arch_local_irq_enable" : : : "memory", "cc"); }
  • 85. 以 Nvidia T30 BSP 為例,下面 API 對 Interrupt 和 OS Schedule 的 處理有什麼影響 ? enable_irq() / disable_irq() enable_fiq() / disable_fiq() spin_lock() / spin_unlock() spin_lock_irq() / spin_unlock_irq() spin_lock_irqsave() / spin_unlock_irqrestore() static inline unsigned long arch_local_irq_save(void) { unsigned long flags; asm volatile( " mrs %0, cpsr @ arch_local_irq_save" " cpsid i" : "=r" (flags) : : "memory", "cc"); return flags; } static inline unsigned long arch_local_irq_save(void) { unsigned long flags; asm volatile( " mrs %0, cpsr @ arch_local_irq_save" " cpsid i" : "=r" (flags) : : "memory", "cc"); return flags; } 問題                  static inline void arch_local_irq_restore(unsigned long flags) { asm volatile( " msr cpsr_c, %0 @ local_irq_restore" : : "r" (flags) : "memory", "cc"); } static inline void arch_local_irq_restore(unsigned long flags) { asm volatile( " msr cpsr_c, %0 @ local_irq_restore" : : "r" (flags) : "memory", "cc"); }
  • 86. spinlock_t dsp_lock; /* global dsp lock */ int dsp_mode; void dsp_main() { spin_lock_irqsave(&dsp_lock, flags); dsp_cmx_hardware(); ... dsp_mode = 2; dsp_proc(dsp_mode); ... spin_unlock_irqrestore(&dsp_lock, flags); } spinlock_t dsp_lock; /* global dsp lock */ int dsp_mode; void dsp_main() { spin_lock_irqsave(&dsp_lock, flags); dsp_cmx_hardware(); ... dsp_mode = 2; dsp_proc(dsp_mode); ... spin_unlock_irqrestore(&dsp_lock, flags); }                  void dsp_isr() { spin_lock_irqsave(&dsp_lock, flags); dsp_mode = 0; dsp_proc(dsp_mode); spin_unlock_irqrestore(&dsp_lock, flags); } void dsp_isr() { spin_lock_irqsave(&dsp_lock, flags); dsp_mode = 0; dsp_proc(dsp_mode); spin_unlock_irqrestore(&dsp_lock, flags); } Potential Bug void dsp_cmx_hardware() { ... } void dsp_cmx_hardware() { ... } spin_lock_irq(xxx_lock); ... spin_unlock_irq(xxx_lock); Enable IRQ Mode DeadlockDeadlock Interrupt
  • 87.                  Linux API Interrupt Process Affect OS Schedule enable_irq() disable_irq() Interrupt Controller No enable_fiq() disable_fiq() Interrupt Controller No spin_lock() spin_unlock() X No spin_lock_irq() spin_unlock_irq() IRQ mode of ARM core Yes spin_lock_irqsav e() spin_unlock_irqresto re() IRQ mode of ARM core Yes

Editor's Notes

  1. 可靠性高。數位電路中只需分辨出訊號的有與無,故電路的元件參數,可 以允許有較大的變化(漂移)範圍。所以當零件老化或採用不同廠牌的零件時,數位電路較不會出現功能不正常的現象。
  2. Device Power on seq. Suspend後Reset會被拉成low, power on sequence會不對 這case在Device power on/off不一定有問題. 在suspend/resume就會有問題. SW reset或電路的改變都可能影響Reset的預設準位, 有潛在的風險
  3. Ex.1. 改HW或換BSP, 有很低很低的機率會造成BSP的timer或delay不準,造成delay time有誤差. 建議開發初期和出貨前至少要量測一次.
  4. DSP (數位訊號處理器) 是一種功能強大且非常快速的微處理器,其特性在於能夠即時處理數位訊號, 以便為連續的類比訊號進行測量或濾波。用作處理通用資料時,叫作中央處理器(Central Processing Unit, CPU)這也是最為人所知的應用(如:Intel Pentium CPU);專用於作圖像資料處理的,叫作Graphics Processing Unit圖形處理器(如Nvidia GeForce 6150 GPU);
  5. I2C recovery
  6. SPI2_CS0_N接WiFi chip的reset, 如果WiFi chip的reset pin是High active. SDMMC3_CLK output low
  7. I2C recovery
  8. 重置向量 (Reset Interrupt Vector) :重置向量是處理器給電開機後,執行第一道指令的位址,這條指令將使處理器跳躍到初始化程式碼處。 未定義指令向量(Undefined Interrupt Vector):未定義指令向量是在處理器不能對第一道指令解碼時使用。通常當我們在開發新的DSP指令時,可以使用這個部份來進行模擬測試 ============================================================== 1. FIQ的優先順序比IRQ高 2. FIQ模式比IRQ模式多幾個的寄存器(R8~R12)。這樣在執行FIQ中斷處理函數時,就不需要保存通用寄存器(R8~R12),也就是說FIQ處理常式在保存和恢復現場時可以少處理幾個寄存器(R8~R12),從而提高了中斷處理的速度。 3. FIQ的中斷向量位址在0x0000_001c,而IRQ的在0x0000_0018。我們知道0x0000_0018處只能放置一條指令,而且是跳轉指令。而FIQ後面沒有其它的中斷向量表,我們可以直接在0x0000_001c處放置FIQ的中斷處理常式。這樣就至少少了一條跳轉指令。 軟體中斷向量(Software Interrupt Vector:Trap):軟體中斷向量是執行 SWI 指令時被呼叫的。 SWI 指令經常用於呼叫一個作業系統常式的機制(System Call)。 預先存取中止向量(Prefetch Abort Interrupt Vector):發生在試圖從一個未獲得正確存取許可權的位址去存取時,而實際上中止發生在解碼階段。 資料中止向量(Data Abort Interrupt Vector):和預先存取中止向量類似,發生在一道指令試圖存取未獲得正確存取許可權的資料記憶體時。 中斷請求向量(Interrupt Request Vector):用於外部硬體中斷處理器的正常執行流,只有當 CPSR 中的 IRQ 位元未被遮罩時才發生。 快速中斷請求向量(Fast Interrupt RequestVector):和中斷請求向量累類似,是為了要求更快速的中斷反應時間,有當 CPSR 中的 FIQ 位元未被遮罩時才發生。
  9. linux的進程調度時機有:1、進程狀態轉換的時刻:進程終止、進程睡眠 2、設備驅動程式主動調用schedule 3、當前的進程的時間片用完(current-&amp;gt;counter=0)4、進程從中斷、異常返回