2011年8月7日 星期日

linux nfc kernel driver pn544

讀 linux kernel "Documentation/nfc/nfc-pn544.txt"

感謝作者: Jari Vanhala
聯絡方式: Matti Aaltonen (matti.j.aaltonen at nokia.com)

兩個可參考的驅動程式: "drivers/nfc/pn533.c", "drivers/nfc/pn544.c" 感謝 Nokia 的愛心。

使用 linux kernel 的 misc device, device name /dev/pn544
其中 pn544 有 I2C, SPI, HSU 三種介面但驅動程式只提供 I2C 介面實作

對 user space 介面有 sysfs 的硬體測試與 IOCTL 切換 HCI, firmware update 兩種工作模式,傳輸訊息的方式有三種:read, write, poll

由 user space 傳訊息到 PN544  晶片進行控制,驅動程式目前只傳遞訊息不瞭解訊息內容

溝通協定

正常的 HCI 模式與 firmware update 模式的 read/write 行為不太一樣,因為兩種模式的訊息格式與溝通協定都不同。

HCI模式的溝通協定採用 ETSI 的 HCI spec,firmware update 則另有特殊協定。

HCI 訊息有 8 bit header 跟訊息內容。header 包括訊息長度,最大 33 bytes。傳送出去的訊息需要經過 checksum 驗證。

Firmware update 訊息長度存在第二(MSB)跟第三(LSB)位元組,最大值 1024 bytes.

sysfs 的硬體測試指的是讀取 sysfs 檔案後能將 pn544 轉為 firmware update mode,如果未提供測試則不需要建立此 sysfs 檔案。

使用範例:

 60 Example:
 61 > cat /sys/module/pn544/drivers/i2c\:pn544/3-002b/nfc_test
 62 1

正常運作流程:
device 檔案 open 後 pn544 就給電,未開啟前斷電,一次只能有單一使用者。user space 應用程式使用 HCI 訊息控制。 當有資料可讀時就發出一次中斷,當 user space 下 read 時才從 pn544 實際讀取資料,poll() 檢查 read interrupt state。設定與單元測試都由 user space 的 read/write 完成。

範例 platform data:


78 static int rx71_pn544_nfc_request_resources(struct i2c_client *client)
79 {
80 /* Get and setup the HW resources for the device */
81 }
82
83 static void rx71_pn544_nfc_free_resources(void)
84 {
85 /* Release the HW resources */
86 }
87
88 static void rx71_pn544_nfc_enable(int fw)
89 {
90 /* Turn the device on */
91 }
92
93 static int rx71_pn544_nfc_test(void)
94 {
95 /*
96 * Put the device into the FW update mode
97 * and then back to the normal mode.
98 * Check the behavior and return one on success,
99 * zero on failure.
100 */
101 }
102
103 static void rx71_pn544_nfc_disable(void)
104 {
105 /* turn the power off */
106 }
107
108 static struct pn544_nfc_platform_data rx71_nfc_data = {
109 .request_resources = rx71_pn544_nfc_request_resources,
110 .free_resources = rx71_pn544_nfc_free_resources,
111 .enable = rx71_pn544_nfc_enable,
112 .test = rx71_pn544_nfc_test,
113 .disable = rx71_pn544_nfc_disable,
114 };


NXP pn544 introduction pdf
including: contact less procotols, host interfaces, power cosumption

NXP NFC 的 peer to peer, card emulation, Reader三種模式與使用的溝同協定說明

值得注意的是,就專利版圖來看,目前 NFC 市場並沒有真正的大廠,前六強分別是 Sony, Broadcom, IBM, Nokia, Panasonic, NXP

沒有留言:

張貼留言