2013年2月6日 星期三

CSS vertical-align

垂直對齊。例如文字跟圖片擺在同一行時,預設是 baseline 對齊,像是這樣:

An W3Schools image with a default alignment.

如果想要中間對齊,可加「style="vertical-align: middle;"」,結果如下:

An W3Schools image with a default alignment.

其它垂直對齊方式可見參考 1。

參考:
  1. http://www.w3schools.com/cssref/pr_pos_vertical-align.asp
  2. http://www.w3schools.com/css/tryit.asp?filename=trycss_vertical-align

2013年1月14日 星期一

VAIO S13 安裝 Ubuntu 12.10

VAIO S13 筆電,型號 SVS13123CW,GPT 格式硬碟預裝 Windows 8 64-bit,UEFI 模式開機。要再安裝 Ubuntu 12.10 64-bit,讓它可以雙開機 (dual boot)。

註:Ubuntu 32-bit 不支援 UEFI,64-bit 的才支援。另外,需要 64-bit 作業系統才能用到已升級為 8GB 的記憶體。
註:已經將 BIOS 的 Secure Boot 關閉,這樣不影響 Windows 8 正常開機。

按照 Installing Ubuntu Quickly and Easily via Trial and Error 的步驟安裝 Ubuntu 12.10 64-bit,下面是安裝紀錄:(事實上可以再簡化,如後面說明)
  1. 8GB 隨身碟 (4G 應該也可以),用 UNetbootin 製作成 Live USB。
  2. Live USB 開機 (ASSIST 開電,或電源鍵開電 F2),選擇「Try Ubuntu without installing」。
  3. 執行桌面上的「Install Ubuntu 12.10」,按照一般方式安裝到硬碟,選擇「將 Ubuntu 與 Windows 8 安裝在一起」,會從 Windows 磁碟分割切出 ext4 跟 swap 分割,沿用原本的 EFI 分割。
  4. 重開機後是 Windows 8,此時看磁碟分割並沒有變化。再用 Live USB「Try Ubuntu」開機,安裝並執行 Boot Repair,使用「Recommended repair」。
  5. 重開機還是 Windows 8,但去看磁碟分割多了兩個。再用 Live USB  開機跑一次 Boot Repair 的「Recommended repair」,重開機還是一樣 Windows 8。
  6. 使用 http://askubuntu.com/a/150640 替換 Windows 開機管理程式的方式,解決了問題,看到 GRUB2 選單。(啟用 Secure Boot 這項替換會消失)
上述步驟 3.、4. 跟 6. 應該可以一併執行,而 5. 是多餘的。也就是安裝完 Ubuntu 後,執行 Boot Repair 並替換 Windows 開機管理程式,然後才重開機,如下:

a. Ctrl-Alt-T 開啟終端機視窗
b. 安裝並執行 Boot Repair (需要連上網際網路)
sudo add-apt-repository ppa:yannubuntu/boot-repair && sudo apt-get update
sudo apt-get install -y boot-repair && boot-repair
選「Recommended repair」

c. 替換 Windows 開機管理程式
mkdir mnt
sudo mount /dev/sda3 /mnt
cd mnt/EFI/Microsoft/Boot
sudo mv bootmgfw.efi bootmgfw.efi.old
sudo cp ../../ubuntu/grubx64.efi bootmgfw.efi

註:如果 Live USB 是安裝 Ubuntu-Secure-Remix 64-bit,則應該不需要連上網際網路安裝 Boot Repair,直接執行 boot-repair。
註:試過將 EFI/Boot/bootx64.efi 替換成 EFI/ubuntu/grubx64.efi 沒效。
註:試過《Dual-boot Windows 8 and Ubuntu 12.10 on UEFI hardware》用 EasyBCD 來製作 Windows 8 的開機選單,結果會出現 \NST\AutoNeoGrub0.mbr 找不到的問題。
註:發生過掛載 /dev/sda3 沒看到檔案,重新掛載就可以了
註:發生 Windows 8 開機後發現 C: 碟有問題,重新整理後重開機到一半螢幕沒顯示,使用「重新整理」還是怪怪的,最後「重設」將 Windows 8 重灌後恢復,不會動到 Ubuntu 的磁碟分割。
2013/01/17 補充:Windows 更新有可能覆蓋了 EFI/Microsoft/Boot/bootmgfw.efi,此時需要再替換 Windows 開機管理程式。

其它使用問題
  • 無法掛載 Windows 8 磁碟分割,出現 hibernated,不能掛載。試過 http://askubuntu.com/a/228069 將「Turn on fast startup」關閉也是一樣。
  • 休眠:《我要如何讓我的電腦休眠? 》說到支援仍有問題,所以預設關閉。
  • Windows 網路
  • 有些 Fn 鍵不能使用,包括停用觸控板
  • 螢幕亮度及鍵盤燈自動控制
其它參考資料
  1. Managing EFI Boot Loaders for Linux
  2. Sony Vaio Control device drivers 包括 sony-laptop 及 sonypi
  3. Linux 安裝與使用

附錄:未安裝 Ubuntu 前的磁碟分割
註:sda1 是名為「SONYSYS」的 OEM 磁碟分割,sda2 是名為「Windows RE tools」的修復磁碟分割,sda6 是名為「Recovery」的修復磁碟分割。

附錄:安裝 Ubuntu 後的磁碟分割
ubuntu@ubuntu:~$ sudo parted /dev/sda print
Model: ATA Hitachi HTS54755 (scsi)
Disk /dev/sda: 500GB

Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start   End     Size    File system     Name                          Flags
 1      1049kB  274MB   273MB   fat32                                         hidden
 2      274MB   1819MB  1546MB  ntfs                                          hidden, diag
 3      1819MB  2092MB  273MB   fat32           EFI system partition          boot
 4      2092MB  2226MB  134MB                   Microsoft reserved partition  msftres
 5      2226MB  259GB   257GB   ntfs            Basic data partition
 7      259GB   468GB   208GB   ext4
 8      468GB   476GB   8463MB  linux-swap(v1)
 6      476GB   500GB   23.9GB  ntfs                                          hidden, diag

2012年11月21日 星期三

PCIe

PCI Express (PCIe, PCI-E)
  • 以序列點對點匯流排取代之前 PCI、PCI-X、AGP 的並列共享匯流排,但軟體跟 PCI 相容。PCI 取代 ISA、VESA,是 multi-master。
  • 一組序列點對點匯流排稱為 lane (通道),包含傳跟收的差動訊號共四條線。一個 PCIe 插槽可有 2n lanes,0 ≤ n ≤ 5。
  • PCIe Gen 3 每個通道大約會轉換為 1 GB/s。PCIe Gen 4 每個通道大約會轉換 2 GB/s,可向下相容。
  • M.2。https://www.kingston.com/tw/community/articledetail/articleid/48543
  • M.2 介面的 SSD 有 PCIe NVMe 和 SATA3 兩種規格,PCIe 又有 3.0 和 4.0 的差異。
PCI Express Mini Card (Mini PCIe)
  • 插槽除了電源外,可包含 PCIe lane、USB 2.0、SMBus、SIM Card、LED 等介面。
  • 接頭也用在 mSATA
Express Card
  • 跟 MiniPCIe 類似,一樣包含 PCIe lane、USB 2.0 介面。其前身 CardBus 是 32-bit @33MHz PCI 介面 (3.3V 電源),再前身 PCMCIA Card (PC Card) 是 16-bit ISA 介面。

miniPCI: PCI, 2W max. (Mini PCIe 取代)
cPCI (CompactPCI): PCI 背板含 PCI bus 及其他自訂的訊號,如電話、網路等。

M.2 是電腦內部擴充卡連接的規格。

  • M.2 取代 mSATA。
  • 搭配更先進的界面 features,比 mSATA 更適合 SSD。
  • 界面可以有 PCI Express 達 4 通道、SATA 3.0、和 USB 3.0 (a single logical port for each of the latter two),取決於主機和模組要支援什麼界面,不同 keying notches 來避免模組插到不相容的主機連接器。
  • SSD 邏輯界面支援傳統 SATA 的 Advanced Host Controller Interface (AHCI) 和 PCIe 的 NVM Express (NVMe)。NVMe 能進行平行 IO 來完整利用高速 PCIe 儲存裝置的能力。
YearSpec.Frequency/SpeedBandwidth
1992PCI33 MHz133 MB/s (32-bit simplex)
1993PCI 2.066 MHz533 MB/s (64-bit simplex)
1999PCI-X133 MHz1.06 GB/s (64-bit simplex)
2002PCI-X 2.0266 MHz2.13 GB/s (64-bit simplex)
2002PCIe 1.x2.5 GHz2 Gb/s (x16 duplex 8GB/s)
2006PCIe 2.x5 GHz 4 Gb/s (x16 duplex 16GB/s)
2010PCIe 3.x8.0 GHz 8 Gb/s (x16 duplex 32GB/s)
2017PCIe 4.x16.0 GT/s 128/130 編碼16 Gb/s (x16 duplex 64GB/s)
2019PCIe 5.x32.0 GT/s 128/130 編碼32 Gb/s (x16 duplex 128GB/s)

PCI device 的定址包括 8-bit bus、5-bit device (32 個)、及 3-bit function (8 個)。每個 PCI 系統可以有 256 PCI buses,bus 間透過 PCI bridge 連接。
  • ID: domain (16-bit) + bus (8-bit) + device (5-bit) + function (3-bit)
  • per device configuration space
  • per bus memory-mapped space
    • cached or uncached
  • per bus IO-mapped space
    • 會有附帶動作, uncached
  • interrupt: 4 interrupt pins per PCI slot
    • interrupt lines are shareable and the routing to CPU is platform dependent.
每個 PCI function 的 configuration space 包含 256 bytes (PCI Express 有 4 KB), 須透過特別的 kernel 函數存取
  • standardized layout
  • First 64-byte is standardized
  • Little-endian
  • 4B unique function ID
  • Access: read and write registers of PCI controller (vendor dependent)
  • /proc/bus/pci/devices
  • /proc/bus/pci/*/* : binary
  • /sys/bus/pci/devices

參考

  1. https://en.wikipedia.org/wiki/M.2
  • Linux Device Drivers 3rd Edition, Chapter 12 PCI Driver

2012年11月20日 星期二

Raspberry Pi vs. MK802

一些 Raspberry Pi 跟 MK802 比較的文章
基本上,MK802 速度較快,記憶體較多,內建 Flash,有 802.11 b/g Wi-Fi (但無 Ethernet),有 USB OTG 當週邊。MK802 最大的問題是開放程度較低,相對支援跟社群也較少,要使用 GPIO 擴充較不容易。Ethernet 較容易解決,用 USB 轉就可以了,Raspberry Pi 也是用 SMSC LAN9512 將一個 USB 轉成 Ethernet 跟兩個 USB。

2012/11/27 補充: MK802 沒有 RCA Composite 端子,對沒有 HDMI 線及螢幕的我較不方便。另外,cubieboard  好像更好

2012年11月17日 星期六

shift register

Image from http://www.nxp.com/documents/data_sheet/74HC_HCT595.pdf
74HC595
74 系列的移位暫存器 IC 基本上都有序列輸入 (serial-input, SI) 及序列輸出 (serial-output, SO) 功能,有些有加上並列輸入 (parallel-input, PI) 或並列輸出 (parallel-output, PO),或者雙向移位功能,此外還有加上儲存暫存器或三態輸出。

例如 74164 是一個八位元的 SIPO 移位暫存器,而 74594 則再 PO 加上儲存暫存器,可讓移位過程中輸出不受影響。74595 則是 74594 再加上三態輸出,如圖。

74595 或 74594 可以作為 SPI 的 GPIO 擴充,把 SPI 的 SCK、MOSI、SS\ 分別接到 74595 的 SHCP、DS、STCP (MR\ 跟 OE\ 接地),SS\ 結束的 rising edge 剛好將資料載入儲存暫存器。

一些其它移位暫存器:
74165 8-bit PISO
74166 8-bit bidirectional PISO
74597 8-bit input register + PISO
74194 4-bit bidirectional + PI + PO
74299 8-bit bidirectional + 共用的 PI 及三態 PO
4014 PISO + 3-bit PO
4015 Dual 4-bit SIPO
4094 類似 74595,但沒有清除功能
7731 Quad 64-bit SISO

參考:
  1. http://www.nxp.com/documents/data_sheet/74HC_HCT595.pdf
  2. http://conductiveresistance.com/interactive-595-shift-register-simulator/

2012年11月11日 星期日

[Lua] Global Variable


全域變數不用宣告,存取尚未有的全域變數會得到 nil (存取未初始化的變數皆會得到 nil)。
一般不需要特地刪除全域變數,但指定為 nil 就是刪除。如果想要變數的生命有個範圍, 應該使用區域變數。

SIP header Via

所有 SIP 訊息 都要有 Via,縮寫 v。一開始的 UAC 和後續途經的每個 proxy 都會疊加一個 Via 放傳送的位址,依序作為回應的路徑。 格式 sent-protocol sent-by [ ;branch= branch ][ ; 參數 ...] s...