<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-6198249661133467553</id><updated>2024-10-25T20:11:22.420+08:00</updated><category term="driver"/><category term="kernel"/><category term="source code"/><category term="application"/><category term="communication"/><category term="kernel boot init linux"/><category term="kernel driver"/><category term="linux"/><category term="porting"/><category term="2.6.x"/><category term="DMA"/><category term="GNU"/><category term="GNU configuration"/><category term="GPIO"/><category term="HAL"/><category term="Linux原始碼存放架構"/><category term="MMC/SD"/><category term="MMU"/><category term="RTC"/><category term="compiler"/><category term="cross"/><category term="debug"/><category term="device driver"/><category term="embedded linux"/><category term="ethernet"/><category term="installation"/><category term="kconfig"/><category term="kernel NFS root-file-system boot mount"/><category term="kernel configuration"/><category term="kernel driver pci host client"/><category term="kernel driver sound USB speaker"/><category term="kernel driver sysfs"/><category term="linker"/><category term="linux kernel driver device"/><category term="real time"/><category term="rs232"/><category term="serial"/><category term="serial port"/><category term="timer"/><category term="tool-chain"/><category term="什麼是Embedded Linux"/><category term="好用的除錯編碼"/><category term="崁入式系統的基本硬體需求"/><category term="我的主旨"/><title type='text'>大家一起來玩 Linux</title><subtitle type='html'>Linux 是一個開放原始碼的軟體, 也是大家群體群力的軟體, 所以有心要從事軟體工作的人没有不研究它, 我本身也是一個軟體愛好者, 因此在這邊分享我的經驗, 能夠做自己喜歡的事, 是一件非常快樂的事。</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://victoryuembeddedlinux.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6198249661133467553/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://victoryuembeddedlinux.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/6198249661133467553/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/06577529210679988448</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>32</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-6198249661133467553.post-4243154845293613909</id><published>2017-02-25T11:44:00.003+08:00</published><updated>2017-02-25T11:44:50.637+08:00</updated><title type='text'>I2C master (adapter) device driver</title><content type='html'>在 Linux kernel I2C device driver 中稱呼 master 為 adapter, 每一個 I2C bus 中只能有一個 master, 而在 embedded 系統中通常是 SoC 內建, 一樣受 I2C core 中所管理, 另外在 i2c_dev.c 中會為每一個 master 建立一個 device node 為 /dev/i2c-xxx 其中 xxx 為 bus number, 應用程式可以使用這個 device node 控制 master 收送資料, 進而可以取代 client device driver。&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: blue; font-size: large;&quot;&gt;&lt;b&gt;資料結構&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
struct i2c_adapter {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; struct module *owner;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; unsigned int class;               /* classes to allow probing for */&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; const struct i2c_algorithm *algo; /* the algorithm to access the bus */&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; void *algo_data;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* data fields that are valid for all devices   */&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; struct rt_mutex bus_lock;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int timeout;                    /* in jiffies */&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int retries;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; struct device dev;              /* the adapter device */&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int nr;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; char name[48];&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; struct completion dev_released;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; struct mutex userspace_clients_lock;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; struct list_head userspace_clients;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; struct i2c_bus_recovery_info *bus_recovery_info;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; const struct i2c_adapter_quirks *quirks;&lt;br /&gt;
};&lt;br /&gt;
#define to_i2c_adapter(d) container_of(d, struct i2c_adapter, dev) // d is device&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
以上是在驅動一開始要註冊時所需資料結構, 其內容需給予準備好以備註冊一個 master (adapter) device driver, 其中有一個 algo member 為收送資料的 call back function, 通常是讓 client 驅動所呼叫&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: blue; font-size: large;&quot;&gt;algo 資料結構&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;div&gt;
struct i2c_algorithm {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* If an adapter algorithm can&#39;t do I2C-level access, set master_xfer&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; to NULL. If an adapter algorithm can do SMBus access,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; smbus_xfer. If set to NULL, the SMBus protocol is&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; using common I2C messages */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* master_xfer should return the number of messages&lt;br /&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; processed, or a negative value on error */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int (*master_xfer)(struct i2c_adapter *adap, struct i2c_msg *msgs,&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int num);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int (*smbus_xfer) (struct i2c_adapter *adap, u16 addr&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; unsigned short flags, char read_write&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; u8 command, int size, union i2c_smbus_data *data);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* To determine what the adapter supports */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; u32 (*functionality) (struct i2c_adapter&amp;nbsp;*);&lt;br /&gt; #if IS_ENABLED(CONFIG_I2C_SLAVE)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int (*reg_slave)(struct i2c_client *client);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int (*unreg_slave)(struct i2c_client *client);&lt;br /&gt;#endif&lt;br /&gt;};&lt;/div&gt;
&lt;div&gt;
其中的 master_xfer &amp;amp; smbus_xfer 就是給 client 驅動所呼叫的 call back function 來收送資料&lt;/div&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;color: blue; font-size: large;&quot;&gt;I2C core 所提供 Kernel API&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;#include &amp;lt;linux/i2c.h&amp;gt; // 驅動需要的 include file&lt;/li&gt;
&lt;li&gt;static inline void *i2c_get_adapdata(const struct i2c_adapter *dev) // 使用 i2c_adapter 的資料結構來取得你自行設定的私有資料結構&lt;/li&gt;
&lt;li&gt;static inline void i2c_set_adapdata(struct i2c_adapter *dev, void *data)// 使用 i2c_adapter 的資料結構來設定你自行設定的私有資料結構&lt;/li&gt;
&lt;li&gt;void i2c_lock_adapter(struct i2c_adapter *); // 鎖定這個 adapter bus, 以確保只有一個人在收送資料, 這是一個很重要的動作, 因為 I2C &lt;/li&gt;
&lt;li&gt;void i2c_unlock_adapter(struct i2c_adapter *); // 解鎖 adapter bus, 這必需和上面的鎖定成對使用&lt;/li&gt;
&lt;li&gt;static inline struct i2c_adapter *i2c_parent_is_i2c_adapter(const struct i2c_adapter *adapter) // 取得上一層的 adapter data, 這在如果有多工器時會更需要用到&lt;/li&gt;
&lt;li&gt;extern int i2c_add_adapter(struct i2c_adapter *); // 增加一個 adapter or master, 這不指定 bus number, 由系統自動 assign &lt;/li&gt;
&lt;li&gt;extern void i2c_del_adapter(struct i2c_adapter *); // 移除一個 adapter&lt;/li&gt;
&lt;li&gt;extern int i2c_add_numbered_adapter(struct i2c_adapter *); // 增加一個指定 bus number 的 adapter&lt;/li&gt;
&lt;li&gt;int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num);
// 這是給 client 驅動所呼叫的的程式來要求 adapter 收送資料給 client, 而 master 則是轉成呼叫上面所提的 master_xfer &amp;amp; smbus_xfer call back function&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;color: blue; font-size: large;&quot;&gt;範例 - id table&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
static const struct of_device_id mv64xxx_i2c_of_match_table[] = {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; { .compatible = &quot;allwinner,sun4i-a10-i2c&quot;, .data = &amp;amp;mv64xxx_i2c_regs_sun4i},&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; { .compatible = &quot;allwinner,sun6i-a31-i2c&quot;, .data = &amp;amp;mv64xxx_i2c_regs_sun4i},&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; { .compatible = &quot;marvell,mv64xxx-i2c&quot;, .data = &amp;amp;mv64xxx_i2c_regs_mv64xxx},&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; { .compatible = &quot;marvell,mv78230-i2c&quot;, .data = &amp;amp;mv64xxx_i2c_regs_mv64xxx},&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; { .compatible = &quot;marvell,mv78230-a0-i2c&quot;, .data = &amp;amp;mv64xxx_i2c_regs_mv64xxx},&lt;br /&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {} // 一定要有這個做為結束&lt;br /&gt;};&lt;br /&gt;MODULE_DEVICE_TABLE(of, mv64xxx_i2c_of_match_table);&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;color: blue; font-size: large;&quot;&gt;adapter algo example&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
static int &lt;br /&gt;mv64xxx_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num) &lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; struct mv64xxx_i2c_data *drv_data = i2c_get_adapdata(adap);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // just do it&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // return how many messages are sent &lt;br /&gt;} &lt;br /&gt;&lt;br /&gt;static u32 &lt;br /&gt;mv64xxx_i2c_functionality(struct i2c_adapter *adap) &lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return I2C_FUNC_I2C | I2C_FUNC_10BIT_ADDR | I2C_FUNC_SMBUS_EMUL; &lt;br /&gt;} &lt;br /&gt;&lt;br /&gt;static const struct i2c_algorithm mv64xxx_i2c_algo = {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .master_xfer = mv64xxx_i2c_xfer,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .functionality = mv64xxx_i2c_functionality, &lt;br /&gt;};&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: blue; font-size: large;&quot;&gt;&lt;b&gt;example – probe call back function&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
static int mv64xxx_i2c_probe(struct platform_device *pd) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // prepare i2c_adapter data structure&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; adapter.name= “myname”;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; adapter.timeout = msecs_to_jiffies(timeout);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; adapter.dev.parent = &amp;amp;pd-&amp;gt;dev;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; adapter.algo = &amp;amp;mv64xxx_i2c_algo;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; adapter.owner = THIS_MODULE;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; adapter.class = I2C_CLASS_DEPRECATED;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; adapter.nr = pd-&amp;gt;id; // bus number&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; adapter.dev.of_node = pd-&amp;gt;dev.of_node;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // call i2c_add_numbered_adapter(&amp;amp;adapter) &lt;/div&gt;
&lt;div&gt;
}&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: blue; font-size: large;&quot;&gt;&lt;b&gt;example – remove call back function &amp;amp; driver register&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
static int mv64xxx_i2c_remove(struct platform_device *dev) {}; &lt;br /&gt;static struct platform_driver mv64xxx_i2c_driver = {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .probe  = mv64xxx_i2c_probe,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .remove = mv64xxx_i2c_remove,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .driver = {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .name   = MV64XXX_I2C_CTLR_NAME,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .of_match_table = mv64xxx_i2c_of_match_table,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }, &lt;br /&gt;}; &lt;br /&gt;module_platform_driver(mv64xxx_i2c_driver);&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: blue; font-size: large;&quot;&gt;&lt;b&gt;如何加入一個 slave device&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;可以在 device tree 中描述，並準備好驅動程式即可，以下為範例： &lt;br /&gt;i2c0: i2c@11000 {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pinctrl-names = &quot;default&quot;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pinctrl-0 = &amp;lt;&amp;amp;i2c0_pins&amp;gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // timeout-ms = &amp;lt;3000&amp;gt;;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; eeprom@50 {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; compatible = &quot;atmel,24c64&quot;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pagesize = &amp;lt;32&amp;gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; reg = &amp;lt;0x50&amp;gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; marvell,board_id_reg = &amp;lt;0x7&amp;gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; };&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rtc@6f {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; compatible = &quot;isl,isl1208&quot;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; reg = &amp;lt;0x6f&amp;gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; };&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; moxaeds-i2c-mux@08 {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; compatible = &quot;moxa,moxaeds-i2c-mux&quot;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; reg = &amp;lt;0x08&amp;gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }; &lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; };&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;可以在 adapter (master) 驅動中加入，以下為範例： &lt;br /&gt;static int      moxaeds_create_client(struct moxaeds_priv_struct *priv, u32 addr, const char *type, int index) &lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; struct i2c_board_info   info;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; struct dev_archdata     dev_ad;&lt;br /&gt; 　&amp;nbsp;&amp;nbsp; memset(&amp;amp;info, 0, sizeof(info));&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; memset(&amp;amp;dev_ad, 0, sizeof(dev_ad));&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; info.addr = addr;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ( addr &amp;gt; 0x7f )&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; info.flags |= I2C_CLIENT_TEN; // for 10 bits address slave device&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; strncpy(info.type, type, I2C_NAME_SIZE);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; info.archdata = &amp;amp;dev_ad;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; priv-&amp;gt;client[index] = i2c_new_device(priv-&amp;gt;madap, &amp;amp;info);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ( priv-&amp;gt;client[index] == NULL )&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return -ENODEV;&lt;br /&gt;&amp;nbsp;&amp;nbsp; 　return 0;&lt;br /&gt;} &lt;br /&gt;ret = moxaeds_create_client(fpga9_son_priv[busnum], 0x50, &quot;24c64&quot;, EEPROM_CLIENT);&lt;/li&gt;
&lt;/ul&gt;
</content><link rel='replies' type='application/atom+xml' href='http://victoryuembeddedlinux.blogspot.com/feeds/4243154845293613909/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://victoryuembeddedlinux.blogspot.com/2017/02/i2c-master-adapter-device-driver.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6198249661133467553/posts/default/4243154845293613909'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6198249661133467553/posts/default/4243154845293613909'/><link rel='alternate' type='text/html' href='http://victoryuembeddedlinux.blogspot.com/2017/02/i2c-master-adapter-device-driver.html' title='I2C master (adapter) device driver'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/06577529210679988448</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6198249661133467553.post-4398704120861223200</id><published>2017-02-05T23:33:00.001+08:00</published><updated>2017-02-05T23:33:06.757+08:00</updated><title type='text'>I2C client 端驅動程式</title><content type='html'>&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;img border=&quot;0&quot; height=&quot;225&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVJYUoOr_AZwsehxik8V2xxSOu-X9NXrRuO26CSv4eD-b4OK1sf-BNiVWeKRsEZK3lLXpfJxWkNrfrOEx8kCBUYn-tuuAXb4EcT3UrLwEl8Vjn3Y-Hkk7hgHRoWsAKwgV_Fk0I954S1pI/s400/i2c-software-1.png&quot; width=&quot;400&quot; /&gt;&lt;br /&gt;
以上為在 Linux Kernel 中的軟體架構, 其主要分為幾部分:&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;I2C core 為核心程式, 也是管理程式, 做為和 kernel 之間其它驅動要收送 I2C 資炓的介面&lt;/li&gt;
&lt;li&gt;I2C client 為各個 I2C client 端元件的驅動式, 必須透過 I2C core 來通知 I2C master 收送資料給自己&lt;/li&gt;
&lt;li&gt;I2C master 為 I2C master 的驅動, 提供給 I2C core 讓 I2C client 來收送資料&lt;/li&gt;
&lt;li&gt;I2C multiplexer 在同一個 I2C master 之下的 bus, 不能有重覆的 I2C client address, 但有時需要使用多個相同 I2C client 時就需要 I2C multiplexer 來做切換的動作, 而在 multiplexer 中會建立多個 virtual master (adapter)&lt;/li&gt;
&lt;li&gt;I2C slave 其實和 I2C client 一樣, 都是 client 端驅動程式, 只是這類的驅動會使用 event 的方式來做收送資料, 這類驅動較少使用&lt;/li&gt;
&lt;/ul&gt;
I2C bus 是一個 master/slave 的網路架構, 一切的收送均需由 master 來做控制, 而其通訊方式其實是一種 broadcast 的方式, 所以每一個 client (slave) 都會有一個位址來辨認, 所以 client 端的驅動必需要透過 I2C core 來通知 master 的驅動收送資料, 而 client 端的驅動程式則知道自已本身要如何控制, 所以才會有 client 端的驅動程式。&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: blue; font-size: large;&quot;&gt;source code directory in kernel source code root&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;kernel-source/drivers/i2c&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;busses 目錄放 master device driver&lt;/li&gt;
&lt;li&gt;muexs 目錄放 multiplexer device driver&lt;/li&gt;
&lt;li&gt;algos 目錄放演算法或協議 device driver&lt;/li&gt;
&lt;li&gt;i2c-core.c i2c 核心程式&lt;/li&gt;
&lt;li&gt;i2c-dev.c 建立 bus master device node 以及介面程式&lt;/li&gt;
&lt;li&gt;i2c-mux.c 處理 multiplexer 的核心程式&lt;/li&gt;
&lt;li&gt;i2c-boardinfo.c 提供建立 i2c board information 的程式 (這是較舊的做法, 現在通常使用 device tree)&lt;span style=&quot;color: black; font-family: Constantia; font-size: 24.0pt; language: en-US; mso-ascii-font-family: Constantia; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: +mn-cs; mso-bidi-theme-font: minor-bidi; mso-color-index: 1; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-font-kerning: 12.0pt; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: black; mso-style-textfill-fill-themecolor: text1; mso-style-textfill-type: solid;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/ul&gt;
&lt;br /&gt;&lt;span style=&quot;color: blue; font-size: large;&quot;&gt;&lt;b&gt;使用時機&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;原則上 slave 端的元件才是我們要使用的元件, 如 EEPROM&lt;/li&gt;
&lt;li&gt;client 資料結構中含 adapter data&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;span style=&quot;color: blue; font-size: large;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: blue; font-size: large;&quot;&gt;&lt;b&gt;i2c_client 資料結構說明&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
/**&lt;br /&gt;* struct i2c_client - represent an I2C slave device&lt;br /&gt;* @flags: I2C_CLIENT_TEN indicates the device uses a ten bit chip address;&lt;br /&gt;*      I2C_CLIENT_PEC indicates it uses SMBus Packet Error Checking&lt;br /&gt;* @addr: Address used on the I2C bus connected to the parent adapter.&lt;br /&gt;* @name: Indicates the type of the device, usually a chip name that&#39;s&lt;br /&gt;*      generic enough to hide second-sourcing and compatible revisions.&lt;br /&gt;* @adapter: manages the bus segment hosting this I2C device&lt;br /&gt;* @dev: Driver model device node for the slave.&lt;br /&gt;* @irq: indicates the IRQ generated by this device (if any)&lt;br /&gt;* @detected: member of an i2c_driver.clients list or i2c-core&#39;s&lt;br /&gt;*      userspace_devices list&lt;br /&gt;* @slave_cb: Callback when I2C slave mode of an adapter is used. The adapter&lt;br /&gt;*      calls it to pass on slave events to the slave driver.&lt;br /&gt;*&lt;br /&gt;* An i2c_client identifies a single device (i.e. chip) connected to an&lt;br /&gt;* i2c bus. The behaviour exposed to Linux is defined by the driver&lt;br /&gt;* managing the device.&lt;br /&gt;*/&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;PS: 這個資料結構在 client 端註冊的 probe call back function 中會傳給它&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;direction: ltr; language: zh-TW; margin-bottom: 0pt; margin-left: .3in; margin-top: 3.84pt; mso-line-break-override: none; punctuation-wrap: hanging; text-align: left; text-indent: -.3in; unicode-bidi: embed; word-break: normal;&quot;&gt;
struct i2c_client {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; unsigned short flags;           /* div., see below              */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; unsigned short addr;            /* chip address - NOTE: 7bit    */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* addresses are stored in the  */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* _LOWER_ 7 bits               */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; char name[I2C_NAME_SIZE];&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; struct i2c_adapter *adapter;    /* the adapter we sit on        */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; struct device dev;              /* the device structure         */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int irq;                        /* irq issued by device         */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; struct list_head detected;&lt;br /&gt;#if IS_ENABLED(CONFIG_I2C_SLAVE)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i2c_slave_cb_t slave_cb;        /* callback for slave mode      */&lt;br /&gt;#endif&lt;/div&gt;
&lt;div style=&quot;direction: ltr; language: zh-TW; margin-bottom: 0pt; margin-left: .3in; margin-top: 3.84pt; mso-line-break-override: none; punctuation-wrap: hanging; text-align: left; text-indent: -.3in; unicode-bidi: embed; word-break: normal;&quot;&gt;
};&lt;/div&gt;
&lt;div style=&quot;direction: ltr; language: zh-TW; margin-bottom: 0pt; margin-left: .3in; margin-top: 3.84pt; mso-line-break-override: none; punctuation-wrap: hanging; text-align: left; text-indent: -.3in; unicode-bidi: embed; word-break: normal;&quot;&gt;
#define to_i2c_client(d) container_of(d, struct i2c_client, dev)&lt;/div&gt;
&lt;div style=&quot;direction: ltr; language: zh-TW; margin-bottom: 0pt; margin-left: .3in; margin-top: 3.84pt; mso-line-break-override: none; punctuation-wrap: hanging; text-align: left; text-indent: -.3in; unicode-bidi: embed; word-break: normal;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;PS: 其中 I2C_NAME_SIZE 目前定義為 20&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;/span&gt;&lt;b&gt;&lt;/b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: blue; font-size: large;&quot;&gt;&lt;b&gt;i2c_driver 資料結構說明&lt;/b&gt;&lt;/span&gt;&lt;b&gt;&lt;/b&gt;&lt;br /&gt;* struct i2c_driver - represent an I2C device driver&lt;br /&gt;* @class: What kind of i2c device we instantiate (for detect)&lt;br /&gt;* @attach_adapter: Callback for bus addition (deprecated)&lt;br /&gt;* @probe: Callback for device binding&lt;br /&gt;* @remove: Callback for device unbinding&lt;br /&gt;* @shutdown: Callback for device shutdown&lt;br /&gt;* @alert: Alert callback, for example for the SMBus alert protocol&lt;br /&gt;* @command: Callback for bus-wide signaling (optional)&lt;br /&gt;* @driver: Device driver model driver&lt;br /&gt;* @id_table: List of I2C devices supported by this driver&lt;br /&gt;* @detect: Callback for device detection&lt;br /&gt;* @address_list: The I2C addresses to probe (for detect)&lt;br /&gt;* @clients: List of detected clients we created (for i2c-core use only)&lt;br /&gt;* The driver.owner field should be set to the module owner of this driver.&lt;br /&gt;* The driver.name field should be set to the name of this driver.&lt;br /&gt;* For automatic device detection, both @detect and @address_list must be defined.&lt;br /&gt; * @class should also be set, otherwise only devices forced with module parameters&lt;br /&gt; * will be created. The detect function must fill at least the name field of&lt;br /&gt; * the i2c_board_info structure it is handed upon successful detection, and possibly&lt;br /&gt; * also the flags field. If @detect is missing, the driver will still work fine for enumerated&lt;br /&gt;* devices. Detected devices simply won&#39;t be supported. This is expected&lt;br /&gt;* for the many I2C/SMBus devices which can&#39;t be detected reliably, and&lt;br /&gt;* the ones which can always be enumerated in practice.&lt;br /&gt;* The i2c_client structure which is handed to the @detect callback is&lt;br /&gt;* not a real i2c_client. It is initialized just enough so that you can&lt;br /&gt;* call i2c_smbus_read_byte_data and friends on it. Don&#39;t do anything&lt;br /&gt; * else with it. In particular, calling dev_dbg and friends on it is not allowed.&lt;/div&gt;
&lt;div&gt;
struct i2c_driver {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; unsigned int class;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Notifies the driver that a new bus has appeared. You should avoid&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * using this, it will be removed in a near future. */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int (*attach_adapter)(struct i2c_adapter *) __deprecated;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Standard driver model interfaces */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int (*probe)(struct i2c_client *, const struct i2c_device_id *);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int (*remove)(struct i2c_client *);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* driver model interfaces that don&#39;t relate to enumeration  */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; void (*shutdown)(struct i2c_client *);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Alert callback, for example for the SMBus alert protocol.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * The format and meaning of the data value depends on the protocol.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * For the SMBus alert protocol, there is a single bit of data passed&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * as the alert response‘s low bit (“event flag”). */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; void (*alert)(struct i2c_client *, unsigned int data);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* a ioctl like command that can be used to perform specific functions&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * with the device. */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int (*command)(struct i2c_client *client, unsigned int cmd, void *arg);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; struct device_driver driver;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; const struct i2c_device_id *id_table;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Device detection callback for automatic device creation */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int (*detect)(struct i2c_client *, struct i2c_board_info *);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; const unsigned short *address_list;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; struct list_head clients; &lt;br /&gt;};&lt;/div&gt;
&lt;div&gt;
#define to_i2c_driver(d) container_of(d, struct i2c_driver, driver)&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;PS: 在 I2C client 端的驅動程式, 必需宣告這個資料, 其中 probe &amp;amp; remove 兩個 call back function 為必需實做的兩個 call back function, 另外 id_table 也是需要宣告的, 以下會有範例說明&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;color: blue; font-size: large;&quot;&gt;I2C core 所提供的 API for client driver&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
#include &amp;lt;Linux/i2c.h&amp;gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;color: red;&quot;&gt;int i2c_register_driver(struct module *, struct i2c_driver *);&lt;/span&gt; // 註冊一個 client 端驅動, 通常在module_init 中呼叫&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;color: red;&quot;&gt;void i2c_del_driver(struct i2c_driver *);&lt;/span&gt; // 移除一個 client 諯驅動, 通常在 module_exit 中呼叫&lt;/li&gt;
&lt;li&gt;
#define&lt;span style=&quot;color: red;&quot;&gt; i2c_add_driver(driver)&lt;/span&gt; \&amp;nbsp;// 簡化上面的 API&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i2c_register_driver(THIS_MODULE, driver) &lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;color: red;&quot;&gt;module_i2c_driver&lt;/span&gt;(moxaeds_driver); // 簡化 module_init &amp;amp; module_exit&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;color: blue; font-size: large;&quot;&gt;probe call back function example&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
static int      moxaeds_probe(struct i2c_client *client, const struct i2c_device_id *id) &lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; struct i2c_adapter      *adap=to_i2c_adapter(client-&amp;gt;dev.parent); // my parent master&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; enum si5351_variant variant = (enum si5351_variant)id-&amp;gt;driver_data; // get private data which from id table defined&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // allocate private data and initialize it&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // initialize hardware&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // keep got client data, 就是將傳進來的 client 資料存在 local, 因為後面整個驅動都會用到&lt;/div&gt;
&lt;div&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0; &lt;br /&gt;}&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;color: blue; font-size: large;&quot;&gt;remove call back function example&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
static int      moxaeds_remove(struct i2c_client *client) &lt;br /&gt;{&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // release all resource&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0; &lt;br /&gt;}&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;/b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;color: blue; font-size: large;&quot;&gt;id table example in driver&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
static const struct i2c_device_id       moxaeds_id[] = {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&quot;moxaeds-i2c-mux&quot;, 0 /* private data */},&amp;nbsp;// 若有很多個, 可以再加&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {} // 一定要加這個為結束&lt;br /&gt;}; &lt;br /&gt;MODULE_DEVICE_TABLE(i2c, moxaeds_id);&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: blue; font-size: large;&quot;&gt;&lt;b&gt;device tree example in driver&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
static const struct of_device_id si5351_dt_ids[] = {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; { .compatible = &quot;silabs,si5351a&quot;, .data = (void *)SI5351_VARIANT_A /* private data */, },&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; { .compatible = &quot;silabs,si5351a-msop&quot;,&amp;nbsp;.data = (void *)SI5351_VARIANT_A3 /* private data */, },&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; { .compatible = &quot;silabs,si5351b&quot;, .data = (void *)SI5351_VARIANT_B /* private data */, },&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; { .compatible = &quot;silabs,si5351c&quot;, .data = (void *)SI5351_VARIANT_C /* private data */, },&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; { }&amp;nbsp; // 一定要加這個為結束&lt;br /&gt;}; &lt;/div&gt;
&lt;div&gt;
MODULE_DEVICE_TABLE(of, si5351_dt_ids);&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: blue; font-size: large;&quot;&gt;&lt;b&gt;device tree example in device tree file&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;i2c0: i2c@11000 {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pinctrl-names = &quot;default&quot;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pinctrl-0 = &amp;lt;&amp;amp;i2c0_pins&amp;gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // timeout-ms = &amp;lt;3000&amp;gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* hardware change to connect after FPAG#9 bus 15&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; eeprom@50 {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; compatible = &quot;atmel,24c64&quot;;&amp;nbsp;// 這是上面 driver 中宣告的 device tree, &#39;,&#39; 之後名字最多20字母&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pagesize = &amp;lt;32&amp;gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; reg = &amp;lt;0x50&amp;gt;;&amp;nbsp;// 這是 i2c client&amp;nbsp;address&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; marvell,board_id_reg = &amp;lt;0x7&amp;gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; };&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rtc@6f {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; compatible = &quot;isl,isl1208&quot;;&amp;nbsp;// 這是上面 driver 中宣告的 device tree&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; reg = &amp;lt;0x6f&amp;gt;;&amp;nbsp;// 這是 i2c client&amp;nbsp;address&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; };&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; moxaeds-i2c-mux@08 {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; compatible = &quot;moxa,moxaeds-i2c-mux&quot;;&amp;nbsp;// 這是上面 driver 中宣告的 device tree&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; reg = &amp;lt;0x08&amp;gt;;&amp;nbsp;// 這是 i2c client&amp;nbsp;address&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; };&lt;br /&gt; };&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;color: blue; font-size: large;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;color: blue; font-size: large;&quot;&gt;另一個 device tree example in device tree file&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&amp;amp;i2c0 {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; status = &quot;okay&quot;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; clock-frequency = &amp;lt;100000&amp;gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; si5351: clock-generator {&lt;br /&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; compatible = &quot;silabs,si5351a-msop&quot;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; reg = &amp;lt;0x60&amp;gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #address-cells = &amp;lt;1&amp;gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #size-cells = &amp;lt;0&amp;gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #clock-cells = &amp;lt;1&amp;gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* connect xtal input to 25MHz reference */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; clocks = &amp;lt;&amp;amp;ref25&amp;gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; clock-names = &quot;xtal&quot;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* connect xtal input as source of pll0 and pll1 */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; silabs,pll-source = &amp;lt;0 0&amp;gt;, &amp;lt;1 0&amp;gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; clkout0 {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; reg = &amp;lt;0&amp;gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; silabs,drive-strength = &amp;lt;8&amp;gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; silabs,multisynth-source = &amp;lt;0&amp;gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; silabs,clock-source = &amp;lt;0&amp;gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; silabs,pll-master;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; };&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; clkout2 {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; reg = &amp;lt;2&amp;gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; silabs,drive-strength = &amp;lt;8&amp;gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; silabs,multisynth-source = &amp;lt;1&amp;gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; silabs,clock-source = &amp;lt;0&amp;gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; silabs,pll-master;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; };&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }; &lt;br /&gt;};&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;color: blue; font-size: large;&quot;&gt;上面所提 i2c_driver 資料結構範例&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
static struct i2c_driver        moxaeds_driver = {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .driver         = {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .name   = &quot;moxaeds-i2c-mux&quot;,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .owner  = THIS_MODULE,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .of_match_table = of_match_ptr(si5351_dt_ids), // my device tree&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; },&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .probe          = moxaeds_probe,&amp;nbsp;// 參考前面的範&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .remove         = moxaeds_remove,&amp;nbsp;// 參考前面的範&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .id_table       = moxaeds_id, // my id table &lt;br /&gt;};&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;/span&gt;&lt;b&gt;&lt;/b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: blue; font-size: large;&quot;&gt;&lt;b&gt;module_init &amp;amp; module_exit example&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
#if 0   // if you want to debug module initialize function enable here &lt;br /&gt;static int __init       moxaeds_init(void) &lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dgprintk(HIGH_DEBUG_LEVEL, &quot;\n&quot;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return i2c_add_driver(&amp;amp;moxaeds_driver); &lt;br /&gt;} &lt;br /&gt;module_init(moxaeds_init);&lt;br /&gt; &lt;br /&gt;static void __exit      moxaeds_exit(void) &lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dgprintk(HIGH_DEBUG_LEVEL, &quot;\n&quot;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i2c_del_driver(&amp;amp;moxaeds_driver); &lt;br /&gt;} &lt;br /&gt;module_exit(moxaeds_exit); &lt;br /&gt;#else &lt;br /&gt;module_i2c_driver(moxaeds_driver); // to use i2c module initialize macro &lt;br /&gt;#endif&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: blue; font-size: large;&quot;&gt;&lt;b&gt;如何傳送資料在 client 端驅動&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;call i2c_transfer() or __i2c_transfer(), 前面一個會幫忙做 lock bus 的動作, 可避免同時有在存取相同的 bus master, 而後面的則不會, 必需使用者自己做 lock 的動作&lt;/li&gt;
&lt;li&gt;範例如下： &lt;br /&gt;struct i2c_msg           msg[2]; &lt;br /&gt;u8                         tbuf[4], rbuf[4]; &lt;br /&gt;int                                ret;&lt;br /&gt;msg[0].addr = moxaeds_client_fpga-&amp;gt;addr; &lt;br /&gt;msg[0].flags = 0; &lt;br /&gt;msg[0].len = 1; &lt;br /&gt;msg[0].buf = tbuf; &lt;br /&gt;tbuf[0] = FPGA_SET_BIT_MAP_REG_NO; &lt;br /&gt;msg[1].addr = moxaeds_client_fpga-&amp;gt;addr; &lt;br /&gt;msg[1].flags = I2C_M_RD; &lt;br /&gt;msg[1].len = 2; &lt;br /&gt;msg[1].buf = rbuf; &lt;br /&gt;ret = i2c_transfer(moxaeds_master_adap, msg, 2); // called i2c_transfer(), not __i2c_transfer(),&lt;br /&gt;if ( ret != 2 ) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; myprintk(&quot;Read bit map register fail [%d] !\n&quot;, ret);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0; &lt;br /&gt;} &lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
return sprintf(buf, &quot;0x%02x%02x&quot;, rbuf[0], rbuf[1]);&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;// 其中在 i2c_transfer 中第一個參數 moxaeds_master_adap, 在前面所提 probe call back function 所傳進來的 client 中其中的 member&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;/ul&gt;
</content><link rel='replies' type='application/atom+xml' href='http://victoryuembeddedlinux.blogspot.com/feeds/4398704120861223200/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://victoryuembeddedlinux.blogspot.com/2017/02/i2c-client.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6198249661133467553/posts/default/4398704120861223200'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6198249661133467553/posts/default/4398704120861223200'/><link rel='alternate' type='text/html' href='http://victoryuembeddedlinux.blogspot.com/2017/02/i2c-client.html' title='I2C client 端驅動程式'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/06577529210679988448</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVJYUoOr_AZwsehxik8V2xxSOu-X9NXrRuO26CSv4eD-b4OK1sf-BNiVWeKRsEZK3lLXpfJxWkNrfrOEx8kCBUYn-tuuAXb4EcT3UrLwEl8Vjn3Y-Hkk7hgHRoWsAKwgV_Fk0I954S1pI/s72-c/i2c-software-1.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6198249661133467553.post-5674897187222943956</id><published>2017-02-02T22:54:00.002+08:00</published><updated>2017-02-02T22:54:27.989+08:00</updated><title type='text'>I2C 硬體了解</title><content type='html'>&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;What is I2C (Inter-IC) ?&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;它是一種半雙工的串列式 bus&lt;/li&gt;
&lt;li&gt;它是一種廣播式的 bus&lt;/li&gt;
&lt;li&gt;三種通訊速度&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;Standard is 100 Kbps&lt;/li&gt;
&lt;li&gt;Fast-mode is 400 Kbps&lt;/li&gt;
&lt;li&gt;High-speed mode supports speeds up to 3.4 Mbps&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;supports 7-bits and 10-bits address&lt;/li&gt;
&lt;li&gt;Master-slave communication&lt;/li&gt;
&lt;li&gt;每一個 slave 都會給一個特定位址, 對於 7-bits address 只能 0x08 ~ 0x77, 10-bits address 可以設定 0x77 以後&lt;/li&gt;
&lt;li&gt;假如 slave address 有相同, 硬體上則可能會使用多工器來切換&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;硬體實際接法&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5PH9Cpw0jQDfuT-yeQlPdnitAZ1-xEXnhUWHtXCM1p69xG-6Tx5Uk-Jp1q8bZC0xizai25N-IGoWGK5PFcEgLJIHhMUgeMBX3OjqyklNU9av4QnT3Hc7NYrpiHPVKl0q9yMorivRabwA/s1600/i2c-hardware-1.png&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5PH9Cpw0jQDfuT-yeQlPdnitAZ1-xEXnhUWHtXCM1p69xG-6Tx5Uk-Jp1q8bZC0xizai25N-IGoWGK5PFcEgLJIHhMUgeMBX3OjqyklNU9av4QnT3Hc7NYrpiHPVKl0q9yMorivRabwA/s320/i2c-hardware-1.png&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgp3VH43JN9OeAhA_srNKhrS33gMlblQTMxbpfyiACgbqZQNjSJN5PDUFSLvRlz7_dJZ6Pg4maEWv1Xr-eI3HJnyQz2sSaOmch9_1RvnnRy3gOsU3aY-ywx7XpmOzqV3mkgSC48jrhPcU8/s320/i2c-hardware-2.png&quot; /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;硬體訊號&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;•When the bus is free, both lines are HIGH.&lt;br /&gt;• The data on the SDA line must be stable during the HIGH period of the clock.&lt;br /&gt;• The HIGH or LOW state of the data line can only change when the clock signal on the SCL line is LOW.&lt;br /&gt;&lt;br /&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRRXU0A7A-eOOQ8xMyrBFPegUsHoxSJF5lZSTixPNEWH4A0XDs5M3ILCQ09rAb1TQPofJ5czq6216QlEGEi-PJJ3QgFn4OuVrjtlUEwPVlJhr6wnA4sTwKlPLnefPaYFbLsRoLwoo4qYU/s1600/i2c-hardware-3.png&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRRXU0A7A-eOOQ8xMyrBFPegUsHoxSJF5lZSTixPNEWH4A0XDs5M3ILCQ09rAb1TQPofJ5czq6216QlEGEi-PJJ3QgFn4OuVrjtlUEwPVlJhr6wnA4sTwKlPLnefPaYFbLsRoLwoo4qYU/s200/i2c-hardware-3.png&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBvC8ubVzIn-lKeGdqc93v6djl-nswCXoFUHH77Fm6HeAkDduoy6bYhUaA94_di_rtb48ZQeUd5a4yXHPXXlCJc6aNMVdxxIrqT9V28oO4i1XbLnjqLCpfTYBOfU_vMHIoXA5fXlFW2z8/s1600/i2c-hardware-4.png&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBvC8ubVzIn-lKeGdqc93v6djl-nswCXoFUHH77Fm6HeAkDduoy6bYhUaA94_di_rtb48ZQeUd5a4yXHPXXlCJc6aNMVdxxIrqT9V28oO4i1XbLnjqLCpfTYBOfU_vMHIoXA5fXlFW2z8/s320/i2c-hardware-4.png&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWYo8mIgMg1nFg22DyILG7HhlMAI0MYr_saq83fSYNC7Kr3waCTgisSvMdm170opaXWyvvHhUF8mmuZEqR_X7WK98RqaRAOxd22-2lmoEQbobxdCdHrMG8be8Jp3vEZgfeFQD32hC4NRk/s1600/i2c-hardware-5.png&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;66&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWYo8mIgMg1nFg22DyILG7HhlMAI0MYr_saq83fSYNC7Kr3waCTgisSvMdm170opaXWyvvHhUF8mmuZEqR_X7WK98RqaRAOxd22-2lmoEQbobxdCdHrMG8be8Jp3vEZgfeFQD32hC4NRk/s400/i2c-hardware-5.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Start and Stop conditions&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;•A HIGH to LOW transition on the SDA line while SCL is HIGH is one such unique case. This situation indicates a START condition.&lt;br /&gt;• A LOW to HIGH transition on the SDA line while SCL is HIGH defines a STOP condition.&lt;br /&gt;• START and STOP conditions are always generated by the master.&lt;br /&gt;• The bus is considered to be busy after the START condition. &lt;br /&gt;• The bus is considered to be free again a certain time after the STOP condition.&lt;br /&gt;&lt;br /&gt; &lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5peEfvzAWSnMs8t7QGXDmuWTE5J28nIiXPce8zbNIMZe2DrSlqHcVX-ebMIrU1p_k1UbWZ_nYXYOEoZhF8gYNCLmJk-BpZG74bHdbCnDAkx9nQ7octJ2n8GbehEbQbeRb78zNXcefeaM/s320/i2c-hardware-6.png&quot; /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Data Format&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;•Every byte put on the SDA line must be 8-bits long.&lt;br /&gt; • Each byte has to be followed by an acknowledge bit.&lt;br /&gt; &lt;br /&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi85qya-HaiyoWhdbJbP-uV1xyXCEcjl4CbpWX_U9LC1v0LLkEqkO7OdBWEMKkYOBJmWGAwcW3V_qfegXwu57jIQdC6RN_zH8lyakO5Ue65Ud-hE-Uu-7IToDnA9dCp6hX5fNykFyJY974/s320/i2c-hardware-7.png&quot; /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Link level protocol&lt;/b&gt;&lt;/span&gt; &lt;br /&gt;&lt;br /&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjDUfoqqMa_Dutj-YSMgSb6M4kW8O1PY0lHENUqP3-XiOBlHbZcSz4NjQZCtSptp_N5NDmhZKk3rnzSfnWThoZreUARorFGdx9YM1DcW30OYBeqdhxUTQhXeM1p1C9NV-Wd48EceREz1ls/s1600/i2c-hardware-8.png&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjDUfoqqMa_Dutj-YSMgSb6M4kW8O1PY0lHENUqP3-XiOBlHbZcSz4NjQZCtSptp_N5NDmhZKk3rnzSfnWThoZreUARorFGdx9YM1DcW30OYBeqdhxUTQhXeM1p1C9NV-Wd48EceREz1ls/s320/i2c-hardware-8.png&quot; /&gt;&lt;/a&gt; &lt;br /&gt; &lt;br /&gt;&lt;br /&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjr6p1kJL5dNVBxSiMATiiKxr60avx02J_LskPTwev7c1gxUZ3r1xhT7smRPOLx32VP74aFiCBk7yx6p4klk5Fq0krWCgN-vy-sfnkKthDJB3WRS5ZlP1KB8HpOpFyywcPue1AkUmj72H8/s1600/i2c-hardware-9.png&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjr6p1kJL5dNVBxSiMATiiKxr60avx02J_LskPTwev7c1gxUZ3r1xhT7smRPOLx32VP74aFiCBk7yx6p4klk5Fq0krWCgN-vy-sfnkKthDJB3WRS5ZlP1KB8HpOpFyywcPue1AkUmj72H8/s320/i2c-hardware-9.png&quot; /&gt;&lt;/a&gt; &lt;br /&gt; &lt;br /&gt;&lt;br /&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhitj_8hl_kR6LTYa8LkBYKQi1WzXE1UFd95H0amFKgErpsjsdBZK4VBziLTc7AtbEdI9-05bLty-2sa691dunCpSyxvlroSaLCYZBvzfGdpuw6SQUNlZ69SeklVGSzlGzTFDSXsYcRFR0/s1600/i2c-hardware-10.png&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhitj_8hl_kR6LTYa8LkBYKQi1WzXE1UFd95H0amFKgErpsjsdBZK4VBziLTc7AtbEdI9-05bLty-2sa691dunCpSyxvlroSaLCYZBvzfGdpuw6SQUNlZ69SeklVGSzlGzTFDSXsYcRFR0/s320/i2c-hardware-10.png&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Address table&lt;/b&gt;&lt;/span&gt; &lt;br /&gt;&lt;br /&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSBhpOFwY7Nr_16trRe20a8etxQsz7arCD2D8uGJ6jYYDLshN88QyhdzlN2GKz_gri-Ul7LcrQ2C2a1DUMPeIFPSmUlpQXGygNlvJMIumBM-bK_lLziM8G8vPmNRdL_YSC0a1QSrJCzE8/s1600/i2c-hardware-11.png&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSBhpOFwY7Nr_16trRe20a8etxQsz7arCD2D8uGJ6jYYDLshN88QyhdzlN2GKz_gri-Ul7LcrQ2C2a1DUMPeIFPSmUlpQXGygNlvJMIumBM-bK_lLziM8G8vPmNRdL_YSC0a1QSrJCzE8/s320/i2c-hardware-11.png&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&amp;nbsp;Two groups of eight addresses (0000XXX and 1111XXX) are reserved for the purposes&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;span style=&quot;color: black; font-family: 新細明體;&quot;&gt;&lt;span style=&quot;color: #04617b; font-size: 50.0pt; font-weight: normal;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;div style=&quot;direction: ltr; language: zh-TW; margin-bottom: 0pt; margin-left: .3in; margin-top: 5.76pt; mso-line-break-override: none; punctuation-wrap: hanging; text-align: left; text-indent: -.3in; unicode-bidi: embed; word-break: normal;&quot;&gt;
&lt;div style=&quot;direction: ltr; language: zh-TW; margin-bottom: 0pt; margin-left: 0in; margin-top: 0pt; mso-line-break-override: none; punctuation-wrap: hanging; text-align: left; unicode-bidi: embed; word-break: normal;&quot;&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;constantia&amp;quot;;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;h3 style=&quot;direction: ltr; language: zh-TW; margin-bottom: 0pt; margin-left: .3in; margin-top: 5.76pt; mso-line-break-override: none; punctuation-wrap: hanging; text-align: left; text-indent: -.3in; unicode-bidi: embed; word-break: normal;&quot;&gt;
&lt;/h3&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://victoryuembeddedlinux.blogspot.com/feeds/5674897187222943956/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://victoryuembeddedlinux.blogspot.com/2017/02/i2c.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6198249661133467553/posts/default/5674897187222943956'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6198249661133467553/posts/default/5674897187222943956'/><link rel='alternate' type='text/html' href='http://victoryuembeddedlinux.blogspot.com/2017/02/i2c.html' title='I2C 硬體了解'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/06577529210679988448</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5PH9Cpw0jQDfuT-yeQlPdnitAZ1-xEXnhUWHtXCM1p69xG-6Tx5Uk-Jp1q8bZC0xizai25N-IGoWGK5PFcEgLJIHhMUgeMBX3OjqyklNU9av4QnT3Hc7NYrpiHPVKl0q9yMorivRabwA/s72-c/i2c-hardware-1.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6198249661133467553.post-8934263719057302333</id><published>2014-12-12T16:31:00.001+08:00</published><updated>2014-12-12T16:31:50.177+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="device driver"/><category scheme="http://www.blogger.com/atom/ns#" term="embedded linux"/><category scheme="http://www.blogger.com/atom/ns#" term="kernel driver"/><category scheme="http://www.blogger.com/atom/ns#" term="linux"/><title type='text'>寫驅動程式所需的技能</title><content type='html'>&lt;div style=&quot;-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Baskerville; font-size: 14px; text-indent: 27px;&quot;&gt;
我個人寫過很多種作業系統的驅動程式，但是寫驅動程式對一般寫程式的人員而言是一個非常神秘的事，不知道如何著手，也不知道需要那些技能，這邊就來談談這方面的事，好讓有心要寫驅動程式的人員才知道如何準備。&lt;/div&gt;
&lt;div style=&quot;-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Baskerville; font-size: 14px; text-indent: 27px;&quot;&gt;
首先當然 C 要很熟，以前的人在寫 Linux 驅動程式時總是喜歡用較艱深的語法來寫，造成其他的人很難理解，現在則是𣎴會這樣了，大家都會用較簡易的方式來寫，所以如何來檢視自己的 C 是否熟悉，找出 Linux 驅動程式一個約有 100 行的程式碼，在10～20 分鐘之內將其看完，即可了解其程式羅輯，甚至其中若有錯誤也可將其指出，以及該程式的優缺點，那你的 C 就夠熟了。再者驅動程式中用很多的 function pointer 以及資料結構，另外對 pointer 也用的很多，所以這方面的 C 都要很熟悉，將會對於寫驅動程式有很大的幫助。&lt;/div&gt;
&lt;div style=&quot;-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Baskerville; font-size: 14px; text-indent: 27px;&quot;&gt;
再來需要的技能就比較有點麻煩，因為是寫驅動程式，所以對硬體要有一點認識，舉例來說如果你要寫的是硬碟驅動程式，你當然得對硬碟的一些硬體動作或者行為必須有所了解，因為驅動程式就是在控制硬體行為，如此你才能知道如何去控制硬體才是正確的，又如你寫的是 Ethernet 驅動程式，你必須對於 Ethernet 的硬體行為以及基本的操作要有所了解，如此當你在寫它的驅動程式時，才能了解為何其硬體行為如何，出來的結果才知道正確或不正確，再者對於通訊協議的驅動程式，你可能對其協議內容也要有所了解，這樣對正確性以及除錯都有所幫助， 另外在做自我測試時才能知道如何架設測試環境，所有的軟體一定都要經過嚴謹的測試，才能確定其一定的正確性，尤其是在硬體的驅動程式，因為硬體有相容性的問題，而這些問題可能都需要經過軟體，以及硬體環境的架設才能得到正確的測試，而對硬體的了解都有助於你開發驅動程式的優質化。&lt;/div&gt;
&lt;div style=&quot;-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Baskerville; font-size: 14px; text-indent: 27px;&quot;&gt;
另外的一個知識則是對作業系統的了解，驅動程序它要利用 kernel 所提供的 API 來和系統合作，所以它也可以說是作業系統的一部分，而且它是運行在系統中，因此如果驅動寫的不好，是會造成系統當掉，或者不穩定等等，所以對於該系統的一些內部行為要有所了解，如此也才能和系統好好地合作。另外一個的知識是系統了解，是在開完機之後的系統了解，如何設定系統，如果你的驅動程式是給系統管理用的，那你就要了解如何使用它，如此測試才能確保你的驅動是正確的，你也必須很清楚地了解，你的驅動程式到底是在何時載入系統的，這樣才能確保它可以正常地運行你的驅動程式。&lt;/div&gt;
&lt;div style=&quot;-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Baskerville; font-size: 14px; text-indent: 27px;&quot;&gt;
這時則是我們最常説的，需要了解作業業系統的驅動程式要如何撰寫，每個作業系統的驅動程式架構都不太一樣，所以我們必須去了解它，但是在Linux中有一個好處，就是你可以取得所有的驅動程式原始碼，因此你可以參考其他人的程式，方便你快速了解，再者驅動程式所呼叫的API，和應用程式完全不同，因此你需要全部重新了解以及知道。&lt;/div&gt;
&lt;div style=&quot;-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Baskerville; font-size: 14px; text-indent: 27px;&quot;&gt;
最後則是應用程式的了解，也就是要會寫應用程式來測試你的驅動程式，前面有提過驅動程式通常是給應用程式用的，為了要確保你的驅動程式是没有問題，你必須自己先寫一些應用測試程式來測你的驅動程式，當然如果你所在的單位有專門的測試單位，你可以讓測試單位來協助你測試，不過我還是建議自己還是先測試有没有問題，再交給測試單位測試，我想這是對自己的程式負責的態度。&lt;/div&gt;
&lt;div style=&quot;-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Baskerville; font-size: 14px; text-indent: 27px;&quot;&gt;
結論我再一次條例式列出寫驅程式所需的技巧：&lt;/div&gt;
&lt;ul&gt;
&lt;li style=&quot;-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Baskerville; font-size: 14px; margin: 0px;&quot;&gt;&lt;span style=&quot;font-family: Helvetica; font-size: 12px;&quot;&gt;&lt;/span&gt;C 語言的熟悉&lt;/li&gt;
&lt;li style=&quot;-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Baskerville; font-size: 14px; margin: 0px;&quot;&gt;&lt;span style=&quot;font-family: Helvetica; font-size: 12px;&quot;&gt;&lt;/span&gt;作業系統的了解&lt;/li&gt;
&lt;li style=&quot;-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Baskerville; font-size: 14px; margin: 0px;&quot;&gt;&lt;span style=&quot;font-family: Helvetica; font-size: 12px;&quot;&gt;&lt;/span&gt;硬體的了解&lt;/li&gt;
&lt;li style=&quot;-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Baskerville; font-size: 14px; margin: 0px;&quot;&gt;&lt;span style=&quot;font-family: Helvetica; font-size: 12px;&quot;&gt;&lt;/span&gt;了解如何撰寫驅動程式&lt;/li&gt;
&lt;li style=&quot;-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Baskerville; font-size: 14px; margin: 0px;&quot;&gt;&lt;span style=&quot;font-family: Helvetica; font-size: 12px;&quot;&gt;&lt;/span&gt;作業系統的操作的了解&lt;/li&gt;
&lt;li style=&quot;-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Baskerville; font-size: 14px; margin: 0px;&quot;&gt;&lt;span style=&quot;font-family: Helvetica; font-size: 12px;&quot;&gt;&lt;/span&gt;應用程式的撰寫&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;div style=&quot;-webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; font-family: Baskerville; font-size: 14px; text-indent: 27px;&quot;&gt;
以上是我個人認為要寫好一個驅動程式所必要的條件，通常我們要會寫一個驅動程式不太難，但是要寫好一個驅動程式就不太容易，所謂一個好的驅動程式，有幾個必要條件，第一要穩定，就是在任何情況下都不會當掉，第二就是要好維護，不要讓後面接手的人看不懂你的程式，也不知道要如何修改，第三就是要容易除錯，最後希望大家都能夠寫好一個驅動程式。&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://victoryuembeddedlinux.blogspot.com/feeds/8934263719057302333/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://victoryuembeddedlinux.blogspot.com/2014/12/blog-post.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6198249661133467553/posts/default/8934263719057302333'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6198249661133467553/posts/default/8934263719057302333'/><link rel='alternate' type='text/html' href='http://victoryuembeddedlinux.blogspot.com/2014/12/blog-post.html' title='寫驅動程式所需的技能'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/06577529210679988448</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6198249661133467553.post-3752205414444906257</id><published>2012-09-02T16:06:00.004+08:00</published><updated>2012-09-02T16:06:40.455+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="2.6.x"/><category scheme="http://www.blogger.com/atom/ns#" term="driver"/><category scheme="http://www.blogger.com/atom/ns#" term="GPIO"/><category scheme="http://www.blogger.com/atom/ns#" term="kernel"/><category scheme="http://www.blogger.com/atom/ns#" term="RTC"/><title type='text'>如何撰寫在Linux Kernel 2.6.x的GPIO驅動程式</title><content type='html'>&lt;br /&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 18px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;b&gt;前言&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;GPIO是目前SoC常常會使用到的一個元件，以往的GPIO使用上並不普遍，所以在Linux Kernel並未加以統一寫法，因此以往的寫法則各家自行撰寫，比較多的是架構在misc的驅動之下，但今日新的Linux Kernel則有給予新的統一做法，它讓kernel中有要用GPIO的其它驅動程式可以透過其定義的library API來使用，而GPIO本身則實現其實體層的控制就好，如此一來其它使用GPIO的驅動則在porting更容易了。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; min-height: 15px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 18px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;b&gt;什麼是GPIO&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;對於GPIO我們要先有一些了解，GPIO – Generic Program Input Output，中文說法是可程式輸出輸入的控制訊號，意思是該點可以設定為input或者output訊號，而其輸出的訊號則是單純的數位訊號，不是high就是low，而輸入訊號的偵測也是一樣，而其電位則是TTL訊號，而這樣的東西，通常可以例如模擬I2C HOST，或者拿來讀取RTC的介面，又或接一個LED當做某些事件的指示使用。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; min-height: 15px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 18px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;b&gt;Kernel中的GPIO Library&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;還没有寫驅動程式之前，我們先來了解這個library，它是最近的Linux kernel版本所定義的，是給其它需要用到GPIO的驅動程式所使用，意思就是在Kernel內部定義了義標準的GPIO Library API，如此一來對需要使用到GPIO的驅動程式便可以不用理會其底層的GPIO，也不會因平台不同而各家自行所定義的GPIO API而造成上層的驅動程式而跟著修改，我們可以用以下的軟體加構圖來了解其中的做法：&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhHOLQzNk7Vi9GvhZZCeMrhxATw-D3r7QFEN4INmB8DPN_ve0tx1LWZWUQ-uh_LcOBTupBhW56-G9sAjA25fQkTEWfhhMnjQp5JKLsxLWrABiSWkjMQ2X_xFgDB5dLdkDM6sUNvyZB-YeQ/s1600/gpio-driver.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;131&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhHOLQzNk7Vi9GvhZZCeMrhxATw-D3r7QFEN4INmB8DPN_ve0tx1LWZWUQ-uh_LcOBTupBhW56-G9sAjA25fQkTEWfhhMnjQp5JKLsxLWrABiSWkjMQ2X_xFgDB5dLdkDM6sUNvyZB-YeQ/s320/gpio-driver.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; min-height: 15px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; min-height: 15px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; min-height: 15px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; min-height: 15px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; min-height: 15px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; min-height: 15px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; min-height: 15px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; min-height: 15px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; min-height: 15px;&quot;&gt;
&lt;br /&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; min-height: 15px;&quot;&gt;
&lt;br /&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; min-height: 15px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;目前定義較常用的Kernel API有如下：&lt;/span&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; margin: 0px;&quot;&gt;&lt;span style=&quot;font-family: Wingdings; letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;b&gt;int gpio_direction_output(unsigned gpio, int value);&lt;/b&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; margin-left: 24px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;這是設定該GPIO為output，第一個參數為GPIO number，第二個參數則是設定其為輸出時的初始值。&lt;/span&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; margin: 0px;&quot;&gt;&lt;span style=&quot;font-family: Wingdings; letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;b&gt;int gpio_set_value(unsigned gpio, int value);&lt;/b&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; margin-left: 24px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;這是針對己經設為output的GPIO設定其值為high或者為low。&lt;/span&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; margin: 0px;&quot;&gt;&lt;span style=&quot;font-family: Wingdings; letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;b&gt;int gpio_direction_input(unsigned gpio);&lt;/b&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; margin-left: 24px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;這是設定該GPIO為input。&lt;/span&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; margin: 0px;&quot;&gt;&lt;span style=&quot;font-family: Wingdings; letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;b&gt;int gpio_get_value(unsigned gpio);&lt;/b&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; margin-left: 24px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;這是針對己設為input的GPIO讀回其現在的輸入值為何。&lt;/span&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; margin: 0px;&quot;&gt;&lt;span style=&quot;font-family: Wingdings; letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;b&gt;int gpio_request_array(struct gpio *array, size_t num);&lt;/b&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; margin-left: 24px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;這是若要使用任何GPIO時，必須先呼叫該API，這個動作有點類似open的動作，以免其它人會佔用到相同的GPIO pin，這個API可以讓你要求不連續任意個存在的GPIO，之後你就可以使用以上的所有API。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; margin-left: 24px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;struct gpio {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; margin-left: 24px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; unsigned&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; gpio;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; margin-left: 24px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; unsigned long &amp;nbsp; flags;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; margin-left: 24px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; const char&amp;nbsp; &amp;nbsp; &amp;nbsp; *label;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; margin-left: 24px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;};&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; margin-left: 24px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;flags可以設定的值如下：&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; margin-left: 24px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;#define GPIOF_DIR_OUT &amp;nbsp; (0 &amp;lt;&amp;lt; 0)&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; margin-left: 24px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;#define GPIOF_DIR_IN&amp;nbsp; &amp;nbsp; (1 &amp;lt;&amp;lt; 0)&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; margin-left: 24px; min-height: 15px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; margin-left: 24px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;#define GPIOF_INIT_LOW&amp;nbsp; (0 &amp;lt;&amp;lt; 1)&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; margin-left: 24px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;#define GPIOF_INIT_HIGH (1 &amp;lt;&amp;lt; 1)&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; margin-left: 24px; min-height: 15px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; margin-left: 24px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;#define GPIOF_IN &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (GPIOF_DIR_IN)&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; margin-left: 24px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;#define GPIOF_OUT_INIT_LOW (GPIOF_DIR_OUT | GPIOF_INIT_LOW)&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; margin-left: 24px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;#define GPIOF_OUT_INIT_HIGH (GPIOF_DIR_OUT | GPIOF_INIT_HIGH)&lt;/span&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; margin: 0px;&quot;&gt;&lt;span style=&quot;font-family: Wingdings; letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;b&gt;int gpio_free_array(struct gpio *array, size_t num);&lt;/b&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; margin-left: 24px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;上一個若類似open的動作，這一個API就是close的動作。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;以上這些kernel API都是給kernel內部其它driver使用的，使用它之前必需確定GPIO驅動已經被載入，否則將會無法使用，所以這時驅動載入的順序是非常重要的。另外由於有這一層的介面，使得其它會使用到GPIO的驅動程式，會統一的介面，不會因為底層的GPIO控制驅動程式不同因而有不同的介面，而產生需要修改程式，這對軟體的維護會是一大負擔。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; min-height: 15px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 18px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;b&gt;實體層的GPIO chip controller的驅動程式&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;這是一個底層的驅動程式，直接控制GPIO的晶片，並接受上層的管理層的指令動作，並以此提供其它需要使用GPIO的驅動程式，可以有統一的介面。該驅動程式會用到一個資料結構，它是宣告在include/asm-generic/gpio.h，並且在kernel中必需將CONFIG_GENERIC_GPIO啓動，其宣告如下：&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;/**&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp;* struct gpio_chip - abstract a GPIO controller&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp;* @label: for diagnostics&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp;* @dev: optional device providing the GPIOs&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp;* @owner: helps prevent removal of modules exporting active GPIOs&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp;* @request: optional hook for chip-specific activation, such as&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp;*&amp;nbsp; &amp;nbsp; &amp;nbsp; enabling module power and clock; may sleep&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp;* @free: optional hook for chip-specific deactivation, such as&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp;*&amp;nbsp; &amp;nbsp; &amp;nbsp; disabling module power and clock; may sleep&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp;* @direction_input: configures signal &quot;offset&quot; as input, or returns error&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp;* @get: returns value for signal &quot;offset&quot;; for output signals this&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp;*&amp;nbsp; &amp;nbsp; &amp;nbsp; returns either the value actually sensed, or zero&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp;* @direction_output: configures signal &quot;offset&quot; as output, or returns error&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp;* @set: assigns output value for signal &quot;offset&quot;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp;* @to_irq: optional hook supporting non-static gpio_to_irq() mappings;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp;*&amp;nbsp; &amp;nbsp; &amp;nbsp; implementation may not sleep&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp;* @dbg_show: optional routine to show contents in debugfs; default code&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp;*&amp;nbsp; &amp;nbsp; &amp;nbsp; will be used when this is omitted, but custom code can show extra&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp;*&amp;nbsp; &amp;nbsp; &amp;nbsp; state (such as pullup/pulldown configuration).&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp;* @base: identifies the first GPIO number handled by this chip; or, if&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp;*&amp;nbsp; &amp;nbsp; &amp;nbsp; negative during registration, requests dynamic ID allocation.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp;* @ngpio: the number of GPIOs handled by this controller; the last GPIO&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;*&amp;nbsp; &amp;nbsp; &amp;nbsp; handled is (base + ngpio - 1).&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp;* @can_sleep: flag must be set iff get()/set() methods sleep, as they&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp;*&amp;nbsp; &amp;nbsp; &amp;nbsp; must while accessing GPIO expander chips over I2C or SPI&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp;* @names: if set, must be an array of strings to use as alternative&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp;*&amp;nbsp; &amp;nbsp; &amp;nbsp; names for the GPIOs in this chip. Any entry in the array&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp;*&amp;nbsp; &amp;nbsp; &amp;nbsp; may be NULL if there is no alias for the GPIO, however the&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp;*&amp;nbsp; &amp;nbsp; &amp;nbsp; array must be @ngpio entries long.&amp;nbsp; A name can include a single printk&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp;*&amp;nbsp; &amp;nbsp; &amp;nbsp; format specifier for an unsigned int.&amp;nbsp; It is substituted by the actual&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp;*&amp;nbsp; &amp;nbsp; &amp;nbsp; number of the gpio.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp;*&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp;* A gpio_chip can help platforms abstract various sources of GPIOs so&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp;* they can all be accessed through a common programing interface.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp;* Example sources would be SOC controllers, FPGAs, multifunction&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp;* chips, dedicated GPIO expanders, and so on.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp;*&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp;* Each chip controls a number of signals, identified in method calls&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp;* by &quot;offset&quot; values in the range 0..(@ngpio - 1).&amp;nbsp; When those signals&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp;* are referenced through calls like gpio_get_value(gpio), the offset&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp;* is calculated by subtracting @base from the gpio number.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp;*/&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;struct gpio_chip {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; const char&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; *label;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; struct device &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; *dev;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; struct module &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; *owner;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; min-height: 15px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (*request)(struct gpio_chip *chip,&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; unsigned offset);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; void&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (*free)(struct gpio_chip *chip,&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; unsigned offset);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; min-height: 15px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (*direction_input)(struct gpio_chip *chip,&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; unsigned offset);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (*get)(struct gpio_chip *chip,&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; unsigned offset);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (*direction_output)(struct gpio_chip *chip,&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; unsigned offset, int value);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (*set_debounce)(struct gpio_chip *chip,&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; unsigned offset, unsigned debounce);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; min-height: 15px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; void&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (*set)(struct gpio_chip *chip,&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; unsigned offset, int value);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (*to_irq)(struct gpio_chip *chip,&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; unsigned offset);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; min-height: 15px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; void&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (*dbg_show)(struct seq_file *s,&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; struct gpio_chip *chip);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; base;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; u16 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ngpio;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; const char&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; *const *names;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; unsigned&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; can_sleep:1;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; unsigned&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; exported:1;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; min-height: 15px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;#if defined(CONFIG_OF_GPIO)&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; /*&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; * If CONFIG_OF is enabled, then all GPIO controllers described in the&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; * device tree automatically may have an OF translation&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; */&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; struct device_node *of_node;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int of_gpio_n_cells;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int (*of_xlate)(struct gpio_chip *gc, struct device_node *np,&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; const void *gpio_spec, u32 *flags);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;#endif&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;};&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;另外向上註冊及移除的API如下：&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;/* add/remove chips */&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;extern int gpiochip_add(struct gpio_chip *chip);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;extern int __must_check gpiochip_remove(struct gpio_chip *chip);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;extern struct gpio_chip *gpiochip_find(void *data, int (*match)(struct gpio_chip *chip, void *data));&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; min-height: 15px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 18px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;b&gt;程式範例&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 14px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px; text-decoration: underline;&quot;&gt;&lt;b&gt;GPIO控制晶片驅動程式：&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;struct myart_gpio_module {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;struct gpio_chip gpio;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;……………………………….&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;};&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; min-height: 15px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;int myart_gpio_to_irq(struct gpio_chip *chip, unsigned offset)&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;struct myart_gpio_module *module;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; min-height: 15px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;module = container_of(chip, struct myart_gpio_module, gpio);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;return module-&amp;gt;intr_start + offset;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; min-height: 15px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; min-height: 15px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;int myart_gpio_direction_input(struct gpio_chip *chip,unsigned offset)&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;myart_gpio_inout_pin(offset , MCPU_GPIO_INPUT);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;return 0;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; min-height: 15px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;int myart_gpio_get_value(struct gpio_chip *chip, unsigned offset)&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;return myart_gpio_get_pin(offset);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; min-height: 15px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;int myart_gpio_direction_output(struct gpio_chip *chip,unsigned offset, int value)&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;myart_gpio_inout_pin(offset , MCPU_GPIO_OUTPUT);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;return 0;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; min-height: 15px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;void&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;myart_gpio_set_value(struct gpio_chip *chip,&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;unsigned offset, int value)&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;myart_gpio_set_pin(offset , value);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; min-height: 15px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;static int __devinit myart_gpio_probe(struct platform_device *pdev)&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;……………………………….&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;/* Initialize the GPIO data structures */&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;module-&amp;gt;gpio.dev = &amp;amp;pdev-&amp;gt;dev;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;module-&amp;gt;gpio.label = pdev-&amp;gt;name;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;module-&amp;gt;gpio.owner = THIS_MODULE;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;module-&amp;gt;gpio.direction_input = myart_gpio_direction_input;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;module-&amp;gt;gpio.get = myart_gpio_get_value;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;module-&amp;gt;gpio.direction_output = myart_gpio_direction_output;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;module-&amp;gt;gpio.set = myart_gpio_set_value;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;module-&amp;gt;gpio.to_irq = myart_gpio_to_irq;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;module-&amp;gt;gpio.can_sleep = 0;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;module-&amp;gt;gpio.base = 0;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;module-&amp;gt;gpio.ngpio = MCPU_GPIO_NUM;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; min-height: 15px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #ff2500; font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;color: black; letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;ret = &lt;/span&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;b&gt;gpiochip_add(&amp;amp;(module-&amp;gt;gpio));&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;……………………………………..&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; min-height: 15px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;static int __devexit my_gpio_remove(struct platform_device *pdev)&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;……………………………..&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #ff2500; font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;color: black; letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;ret = &lt;/span&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;b&gt;gpiochip_remove(&amp;amp;module-&amp;gt;gpio);&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;if (ret) {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;dev_err(dev, &quot;unable to remove GPIO chip\n&quot;);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;return ret;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;………………………..&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;return 0;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; min-height: 15px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;static struct platform_driver my_gpio_driver = {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;.driver = {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;.name&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;= &quot;GPIO Driver&quot;,&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;.owner&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;= THIS_MODULE,&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;},&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;.probe&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;= my_gpio_probe,&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;.remove&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;= __devexit_p(my_gpio_remove),&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;};&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; min-height: 15px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;static int __init my_gpio_module_init(void)&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;return platform_driver_register(&amp;amp;my_gpio_driver);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; min-height: 15px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;static void __exit my_gpio_module_exit(void)&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;platform_driver_unregister(&amp;amp;my_gpio_driver);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; min-height: 15px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;module_init(my_gpio_module_init);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;module_exit(my_gpio_module_exit);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; min-height: 15px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 18px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;b&gt;上層GPIO應用驅動程式&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;上層的GPIO應用驅程式則是使用GPIO Kernel Library所提供的介面來撰寫驅動程式，如RTC, I2C等等都是常看到的使用GPIO來應用的驅動程式，它必須使用gpio_request_array()來向kernel取得所要用的GPIO，並確定它是没被其它驅動程式所使用，使用後並將其佔住不被其它驅動程式所佔用，在該應用驅動程式下載時需要呼叫gpio_free_array()將所佔用的GPIO free給其它的驅動程式使用，在整個驅動程式中則可以使用gpio_direction_input(), gpio_direction_output(), gpio_set_value(), gpio_get_value()來個別控制相對的GPIO為input or output，並且讀回或者設定相對GPIO為high or low。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; min-height: 15px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 18px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;b&gt;程式範例&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 14px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px; text-decoration: underline;&quot;&gt;&lt;b&gt;GPIO RTC驅動程式：&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;static void rtc_write(u8 cmd, u8 Data)&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;………………………&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;gpio_direction_output(GPIO_RTC_DATA, MCPU_GPIO_LOW);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; gpio_set_value(GPIO_RTC_RESET, MCPU_GPIO_HIGH);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;………………………&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; min-height: 15px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;static u8 rtc_read(u8 cmd)&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;…………………&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;gpio_direction_input(GPIO_RTC_DATA);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;………………..&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;v = gpio_get_value(GPIO_RTC_DATA);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;…………………….&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; min-height: 15px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;static int myart_rtc_read_time(struct device *dev, struct rtc_time *tm)&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;……………………..&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;v = rtc_read(RTC_MONTH_R);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;………………………………&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; min-height: 15px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;static int myart_rtc_set_time(struct device *dev, struct rtc_time *tm)&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;……………………&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;rtc_write(RTC_YEAR_W, v);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;……………………..&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; min-height: 15px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;static const struct rtc_class_ops myart_rtc_ops = {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;.read_time = myart_rtc_read_time,&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;.set_time = myart_rtc_set_time,&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;};&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; min-height: 15px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;static struct gpio rtc_gpios[] = {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; { GPIO_RTC_RESET, GPIOF_DIR_OUT, &quot;rtc_reset&quot;},&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; { GPIO_RTC_SCLK, GPIOF_DIR_OUT, &quot;rtc_sclk&quot;},&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; { GPIO_RTC_DATA, GPIOF_DIR_OUT, &quot;rtc_data&quot;},&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;};&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; min-height: 15px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;static int __init myart_rtc_probe(struct platform_device *pdev)&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;…………………………..&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;err = &lt;/span&gt;&lt;span style=&quot;color: #ff2500; letter-spacing: 0.0px;&quot;&gt;&lt;b&gt;gpio_request_array&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;(rtc_gpios, ARRAY_SIZE(rtc_gpios));&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;…………………………..&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;rtc = &lt;/span&gt;&lt;span style=&quot;color: #ff2500; letter-spacing: 0.0px;&quot;&gt;&lt;b&gt;rtc_device_register&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;(&quot;rtc-myart&quot;, &amp;amp;pdev-&amp;gt;dev, &amp;amp;myart_rtc_ops,&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;&amp;nbsp; THIS_MODULE);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;…………………………..&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; min-height: 15px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;static int __exit myart_rtc_remove(struct platform_device *pdev)&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;…………………………..&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #ff2500; font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;color: black; letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;b&gt;rtc_device_unregister&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: black; letter-spacing: 0.0px;&quot;&gt;(rtc);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #ff2500; letter-spacing: 0.0px;&quot;&gt;&lt;b&gt;gpio_free_array&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;(rtc_gpios, ARRAY_SIZE(rtc_gpios));&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;return 0;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; min-height: 15px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;static struct platform_driver myart_rtc_driver = {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;.driver = {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;.name = &quot;RTC&quot;,&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;.owner = THIS_MODULE,&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;},&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;.remove = __exit_p(myart_rtc_remove),&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;};&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; min-height: 15px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;static int __init myart_rtc_init(void)&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;return platform_driver_probe(&amp;amp;myart_rtc_driver, myart_rtc_probe);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; min-height: 15px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;static void __exit myart_rtc_exit(void)&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; platform_driver_unregister(&amp;amp;myart_rtc_driver);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px; min-height: 15px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;module_init(myart_rtc_init);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 12px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;module_exit(myart_rtc_exit);&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://victoryuembeddedlinux.blogspot.com/feeds/3752205414444906257/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://victoryuembeddedlinux.blogspot.com/2012/09/linux-kernel-26xgpio.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6198249661133467553/posts/default/3752205414444906257'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6198249661133467553/posts/default/3752205414444906257'/><link rel='alternate' type='text/html' href='http://victoryuembeddedlinux.blogspot.com/2012/09/linux-kernel-26xgpio.html' title='如何撰寫在Linux Kernel 2.6.x的GPIO驅動程式'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/06577529210679988448</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhHOLQzNk7Vi9GvhZZCeMrhxATw-D3r7QFEN4INmB8DPN_ve0tx1LWZWUQ-uh_LcOBTupBhW56-G9sAjA25fQkTEWfhhMnjQp5JKLsxLWrABiSWkjMQ2X_xFgDB5dLdkDM6sUNvyZB-YeQ/s72-c/gpio-driver.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6198249661133467553.post-3907096896528792286</id><published>2012-03-19T22:08:00.000+08:00</published><updated>2012-03-19T22:08:51.819+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="driver"/><category scheme="http://www.blogger.com/atom/ns#" term="HAL"/><category scheme="http://www.blogger.com/atom/ns#" term="real time"/><category scheme="http://www.blogger.com/atom/ns#" term="timer"/><title type='text'>Linux Kernel New HAL Timer Device Driver</title><content type='html'>&lt;br /&gt;
&lt;div style=&quot;color: #032060; font: 20.0px BiauKai; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;前言&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px BiauKai; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;由於現在的作業系統對於Real Time的需求越來越多，而對於Real Time的需求則是需要一個較精確的時間計時，以往的Linux在時間的設計上已經不符這個需求，所以在2.6.38之後的版本中已經針對它來修改，這份文件將會說明對於這個新架構的HAL Timer Device Driver的寫法為何。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #032060; font: 20.0px BiauKai; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;以往的問題&lt;/span&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li style=&quot;font: 12.0px BiauKai; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;font: 12.0px Wingdings; letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;時間不夠精細，需要能夠取得nanosecond&lt;/span&gt;&lt;/li&gt;
&lt;li style=&quot;font: 12.0px BiauKai; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;font: 12.0px Wingdings; letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;在計算時間時必需能夠考慮到timer counter overflow的問題&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #032060; font: 20.0px BiauKai; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;現在的做法&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px BiauKai; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;你可以註冊多個clocksource, 所謂的clocksource就是可以產生一個固定的clock, 並且可以讀回其計數值, 系統中將會比較各個clocksource的精確度, 以找出最佳的clocksource做為系統的clocksource, 而這個clocksource將會做為系統的計算時間用, 另外必須註冊一個做為clock event使用, 這就是取代以往的timer interrupt, 而clocksource和clockevent可以為同一個, 也可以為分別不同的timer, 若系統的timer夠多, 建議可以設定不同的timer&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;How to&lt;/span&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li style=&quot;font: 12.0px BiauKai; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;font: 12.0px Wingdings; letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;在arch/arm/mach-xxx的目錄中必須包以下的程式碼&lt;/span&gt;&lt;/li&gt;
&lt;ul&gt;
&lt;li style=&quot;font: 12.0px BiauKai; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;font: 12.0px Wingdings; letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;在MACHINE_START宣告中須有timer的資料結構指定&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/ul&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;MACHINE_START(MOXAART, &quot;Moxa ART CPU platform&quot;)&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .boot_params = 0x100,&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .fixup = moxaart_fixup,&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .map_io = moxaart_map_io, /* map physical to virtual address */&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .init_irq = irq_init_irq,&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #fd1e13; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;color: black; letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;b&gt;.timer = &amp;amp;moxaart_timer,&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .init_machine = moxaart_init,&amp;nbsp; /* register&amp;nbsp; platform_device */&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;MACHINE_END&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px BiauKai; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;其中timer的資料結構如下&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;extern void &amp;nbsp; &amp;nbsp; moxaart_timer_init(void);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;static struct sys_timer moxaart_timer = {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .init &amp;nbsp; = moxaart_timer_init,&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;};&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px BiauKai; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;其中init的成員為一個call back function，其寫法如下&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;void __init moxaart_timer_init(void)&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; *timer_ctrl_reg = timer_ctrl_reg_value;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; setup_irq(IRQ_TIMER1, &amp;amp;moxaart_timer_irq);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #fd1e13; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;color: black; letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;b&gt;moxaart_clocksource_init();&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #fd1e13; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; moxaart_clockevent_init();&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px BiauKai; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;請注意其中將會註冊一個clock source以及一個clock event。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li style=&quot;font: 12.0px BiauKai; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;font: 12.0px Wingdings; letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;如何初始化以及設定一個clock source&lt;/span&gt;&lt;/li&gt;
&lt;ul&gt;
&lt;li style=&quot;font: 12.0px BiauKai; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;font: 12.0px Wingdings; letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;啓動該計時器，準備一個call back function讓系統可以隨時讀取讓計時器的值，最後呼叫一個kernel API clocksource_mmio_init()來設定一個clock source, 以下為範例程式&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/ul&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;static cycle_t&amp;nbsp; moxaart_clocksource_read(struct clocksource *c)&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #fd1e13; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;color: black; letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;b&gt;return ~moxaart_timer_get_counter(CLOCK_TIMER);&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;static void __init&amp;nbsp; &amp;nbsp; &amp;nbsp; moxaart_clocksource_init(void)&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; moxaart_timer_set_reload(CLOCK_TIMER, MAX_COUNTER);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; moxaart_timer_set_counter(CLOCK_TIMER, MAX_COUNTER);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; moxaart_timer_enable(CLOCK_TIMER);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; clocksource_mmio_init(NULL, &quot;timer2&quot;, APB_CLK, CLOCK_RATING, 32, moxaart_clocksource_read);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px BiauKai; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;請注意在讀取計時器的值call back function中的return值，若讓計時器是遞減的值則必須反相加一個 ”~”, 若是遞加則不用。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li style=&quot;font: 12.0px BiauKai; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;font: 12.0px Wingdings; letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;如何初始化以及設定一個clock event&lt;/span&gt;&lt;/li&gt;
&lt;ul&gt;
&lt;li style=&quot;font: 12.0px BiauKai; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;font: 12.0px Wingdings; letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;這個初始化較為繁複，首先你要準備一個資料結構struct clock_evelt_device, 以下為其範例&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/ul&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;static struct clock_event_device&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; clockevent_moxaart = {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .name &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; = &quot;timer1&quot;,&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .features &amp;nbsp; &amp;nbsp; &amp;nbsp; = CLOCK_EVT_FEAT_PERIODIC|CLOCK_EVT_FEAT_ONESHOT,&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .irq&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; = IRQ_TIMER1,&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .rating &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; = CLOCK_RATING,&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .shift&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; = CLOCK_SHIFT,&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .set_mode &amp;nbsp; &amp;nbsp; &amp;nbsp; = moxaart_set_mode,&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .set_next_event = moxaart_set_next_event,&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;};&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px BiauKai; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;其中的features設定CLOCK_EVT_FEAT_PERIODIC, 是較為傳統的timer功能，就是會一直產生的固定時間，也就是以前所謂的tick功能，而CLOCK_EVT_FEAT_ONESHOT的功能較為新的設計，若要有high resolution (至nanosecond等級)，則必須有這個功能，意思就是timer可以只產生一次到的interrupt，而不是前面所提的periodic一直產生的timer interrupt。另外對shift成員的設定為一個為2的幾次方值，如32則表示所有的timer counter值將會先乘於2的32次方。&lt;/span&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;ul&gt;
&lt;li style=&quot;font: 12.0px BiauKai; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;font: 12.0px Wingdings; letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;接下需要準備ISR, 其設定如下&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/ul&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;static struct irqaction moxaart_timer_irq = {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .name &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; = &quot;timer1&quot;,&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .flags&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; = IRQF_DISABLED|IRQF_TIMER|IRQF_TRIGGER_FALLING|IRQF_IRQPOLL,&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .handler&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; = moxaart_timer_interrupt,&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .dev_id &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; = &amp;amp;clockevent_moxaart&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;};&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px BiauKai; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;請注意其成員dev_id為上面所宣告的clockevent_moxaart。&lt;/span&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;ul&gt;
&lt;li style=&quot;font: 12.0px BiauKai; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;font: 12.0px Wingdings; letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;在clock_event_device中的成員set_mode call back function則是在設定該timer是要使用何種方，以下為其寫法&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/ul&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;static void &amp;nbsp; &amp;nbsp; moxaart_set_mode(enum clock_event_mode mode, struct clock_event_device *evt)&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; switch ( mode ) {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; case CLOCK_EVT_MODE_PERIODIC:&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; moxaart_timer_set_reload(USED_TIMER, LATCH);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; moxaart_timer_set_counter(USED_TIMER, LATCH);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; moxaart_timer_enable(USED_TIMER);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; break;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; case CLOCK_EVT_MODE_ONESHOT:&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; moxaart_timer_set_reload(USED_TIMER, 0);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; moxaart_timer_set_match1(USED_TIMER, 0);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; timer_ctrl_reg_value &amp;amp;= ~(TIMER1_INT_ENABLE);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; timer_ctrl_reg_value |= (TIMER1_ENABLE|TIMER1_USED_PCLK);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; *timer_ctrl_reg = timer_ctrl_reg_value;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; break;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; case CLOCK_EVT_MODE_RESUME:&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; moxaart_timer_enable(USED_TIMER);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; break;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; case CLOCK_EVT_MODE_SHUTDOWN:&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; case CLOCK_EVT_MODE_UNUSED:&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; default:&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; moxaart_timer_disable(USED_TIMER);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;break;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px BiauKai; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;請注意其模式中的periodic和oneshot定義的不同，在oneshot的模式中會將reload的值設為零。&lt;/span&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;ul&gt;
&lt;li style=&quot;font: 12.0px BiauKai; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;font: 12.0px Wingdings; letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;而對於set_next_event的call back function，則是只是設定讓計時器的reload值&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/ul&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;static int&amp;nbsp; &amp;nbsp; &amp;nbsp; moxaart_set_next_event(unsigned long evt, struct clock_event_device *unused)&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; moxaart_timer_set_reload(USED_TIMER, evt);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return 0;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;ul&gt;
&lt;li style=&quot;font: 12.0px BiauKai; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;font: 12.0px Wingdings; letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;對於ISR的寫法如下&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/ul&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;static irqreturn_t moxaart_timer_interrupt(int irq, void *dev_id)&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; struct clock_event_device &amp;nbsp; &amp;nbsp; &amp;nbsp; *evt=dev_id;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; *(volatile unsigned int *)(MOXAART_TIMER_VA_BASE+TIMER_INTR_STATE) = 0;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; evt-&amp;gt;event_handler(evt);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return IRQ_HANDLED;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px BiauKai; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;對於timer interrupt的寫法其實很制式，大家都一樣。&lt;/span&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;ul&gt;
&lt;li style=&quot;font: 12.0px BiauKai; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;font: 12.0px Wingdings; letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;最後則是clock event的初始化，其寫法如下&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/ul&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;static void __init&amp;nbsp; &amp;nbsp; &amp;nbsp; moxaart_clockevent_init(void)&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; clockevent_moxaart.mult = div_sc(APB_CLK, NSEC_PER_SEC, clockevent_moxaart.shift);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; clockevent_moxaart.max_delta_ns = clockevent_delta2ns(0xffffffff, &amp;amp;clockevent_moxaart);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; clockevent_moxaart.min_delta_ns = clockevent_delta2ns(0xf, &amp;amp;clockevent_moxaart);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; clockevent_moxaart.cpumask = cpumask_of(0);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #fd1e13; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;color: black; letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;b&gt;clockevents_register_device(&amp;amp;clockevent_moxaart);&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li style=&quot;font: 12.0px BiauKai; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;font: 12.0px Wingdings; letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;在arch/arm/Kconfig的有關自己CPU的選項中必須有以下的設定&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div style=&quot;color: #0f70c0; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;color: black; letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;select GENERIC_CLOCKEVENTS&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #0f70c0; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;select CLKSRC_MMIO&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px BiauKai; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;以下是一個範例：&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #0f70c0; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;config ARCH_MOXAART&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #0f70c0; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; bool &quot;MOXA ART CPU&quot;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #0f70c0; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; select CPU_FA526&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #0f70c0; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; select USB_ARCH_HAS_EHCI&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #0f70c0; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; select MIGHT_HAVE_PCI&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #0f70c0; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; select ARCH_REQUIRE_GPIOLIB&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #0f70c0; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; select GENERIC_GPIO&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #0f70c0; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; select GENERIC_CLOCKEVENTS&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #0f70c0; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; select CLKSRC_MMIO&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #0f70c0; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; help&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #0f70c0; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Support for MOXA ART CPU&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #032060; font: 20.0px BiauKai; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;附錄&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #17355d; font: 16.0px Arial; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;b&gt;Kernel APIs&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;/**&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp;* clocksource_mmio_init - Initialize a simple mmio based clocksource&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp;* @base: &amp;nbsp; &amp;nbsp; &amp;nbsp; Virtual address of the clock readout register&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp;* @name: &amp;nbsp; &amp;nbsp; &amp;nbsp; Name of the clocksource&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp;* @hz: &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Frequency of the clocksource in Hz&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp;* @rating: &amp;nbsp; &amp;nbsp; Rating of the clocksource&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp;* @bits: &amp;nbsp; &amp;nbsp; &amp;nbsp; Number of valid bits&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp;* @read: &amp;nbsp; &amp;nbsp; &amp;nbsp; One of clocksource_mmio_read*() above&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp;*/&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;int __init clocksource_mmio_init(void __iomem *base, const char *name,&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; unsigned long hz, int rating, unsigned bits,&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; cycle_t (*read)(struct clocksource *))&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://victoryuembeddedlinux.blogspot.com/feeds/3907096896528792286/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://victoryuembeddedlinux.blogspot.com/2012/03/linux-kernel-new-hal-timer-device.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6198249661133467553/posts/default/3907096896528792286'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6198249661133467553/posts/default/3907096896528792286'/><link rel='alternate' type='text/html' href='http://victoryuembeddedlinux.blogspot.com/2012/03/linux-kernel-new-hal-timer-device.html' title='Linux Kernel New HAL Timer Device Driver'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/06577529210679988448</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6198249661133467553.post-3131004188464108063</id><published>2012-02-28T17:57:00.002+08:00</published><updated>2012-02-28T17:58:35.172+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="application"/><category scheme="http://www.blogger.com/atom/ns#" term="communication"/><title type='text'>API Select怎麼用</title><content type='html'>&lt;br /&gt;
&lt;div style=&quot;font: 18.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;b&gt;前言&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;常在寫網路程式的人對select()這個API應該不莫生才對，或常寫伺服器端程式也應該很熟悉才對，它可以同時監看多個檔案的讀寫允許，而且檔案包含各種週邊元件以及網路的socket，這裏我將會介紹它經常被用的應用，以及我個人經驗中覺有點特別的用法分享給其他人參考參考。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 18.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;b&gt;Select函式原型&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px Arial; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;font: normal normal normal 12px/normal &#39;Lucida Grande&#39;; letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;int select(int &lt;i&gt;nfds&lt;/i&gt;, fd_set *restrict &lt;i&gt;readfds&lt;/i&gt;,&lt;/span&gt;&lt;span style=&quot;font: normal normal normal 12px/normal &#39;Lucida Grande&#39;; letter-spacing: 0px;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;fd_set *restrict &lt;i&gt;writefds&lt;/i&gt;, fd_set *restrict &lt;i&gt;errorfds&lt;/i&gt;,&lt;/span&gt;&lt;span style=&quot;font: normal normal normal 12px/normal &#39;Lucida Grande&#39;; letter-spacing: 0px;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;struct timeval *restrict &lt;i&gt;timeout&lt;/i&gt;);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;font: normal normal normal 12px/normal Arial; letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;這個函數主要是用來同時監看數個檔案(包含socket)，其中的事件在一定時間內是否有發生，而其中的事件有是否有資料可取得，是否可以寫入，以及其它錯誤事件，若在一段時間內沒有任何事件產生，則會回覆一個timeout的訊息，這個函數好用在它可以同時監看很多個檔案，以及時間，如此一來可以讓電腦更有效率以及可以同時處理多個檔案。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #0f70c0; font: 14.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;color: black; font: normal normal normal 12px/normal &#39;Lucida Grande&#39;; letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;b&gt;其中輸入的參數說明如下：&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px Arial; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;int nfds&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;font: normal normal normal 12px/normal Arial; letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;對所要監看的所有file handle中最大的file handle號碼加1&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px Arial; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;fd_set *restrict readfds&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;font: normal normal normal 12px/normal Arial; letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;相對監看該檔案是否有資料已收到或者已有資料可讀，只是確認有資可讀，但不知有多少資料可讀。可以使用FD_SET來設定相對需要確認的檔案，以及使用FD_ISSET來檢查確認的結果。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px Arial; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;fd_set *restrict writefds&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;font: normal normal normal 12px/normal Arial; letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;相對確認該檔案是否可以寫入或者有空間可寫入，只是確認可寫入，但是有多少空間可寫入，並不知道。可以使用FD_SET來設定相對需要確認的檔案，以及使用FD_ISSET來檢查確認的結果。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px Arial; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;fd_set *restrict errorfds&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;font: normal normal normal 12px/normal Arial; letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;相對確認該檔案是否有任何錯誤產生，可以使用FD_SET來設定相對需要確認的檔案，以及使用FD_ISSET來檢查確認的結果。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px Arial; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;struct timeval *restrict timeout&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;這是設定timeout時間，若為NULL則是無限制時間監看及確認，其宣告如下：&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;struct timeval {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;time_t&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;tv_sec;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;suseconds_t&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;tv_usec;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;以上最小時間單位為usec，但是在Linux中系統tick設定通常為10ms之下，通常最小時間可細分也只能到10ms，比這個小的時間其實是無法達到的。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;其回傳值如下：&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&amp;gt; 0&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;表示所以監看的檔案中有幾個檔案已符合條件。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;= 0&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;表示未任何事件發生並且已經timeout。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&amp;lt; 0&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;表示有錯誤產生。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 18.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;b&gt;其它會用到的巨集指令&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;void FD_CLR(int fd, fd_set *set);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;清除掉該檔案相對檔案的設定，也就是取消對該檔案的監看。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;int&amp;nbsp; FD_ISSET(int fd, fd_set *set);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;檢查相對該檔案是否為真，就是對該檔案所監看的結果，確認是否為真，若是為真即表示該事件有發生，若為否則表示該事件未發生。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;void FD_SET(int fd, fd_set *set);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;設定監看該檔案行為。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;void FD_ZERO(fd_set *set);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;清除所有檔案的監看及設定。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 18.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;b&gt;正常使用&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;在Linux中任何週邊都是使用檔案來使用，所以在select中的所使用file handle可以是網路socket open來的，也可以是open device node所得來的，也可以是真正的檔案，所以以下為一個正常使用的範例：&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;int&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;fd1=soekcet(…)&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;int&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;fd2=open(“device-node-name”, …);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;int&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;maxfd;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;fd_set&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;readfds, writerfds;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;struct timeval&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;timev;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;FD_ZERO(&amp;amp;readfds);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;FD_ZERO(&amp;amp;writefds);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;if ( fd1 &amp;gt; fd2 )&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;maxfd = fd1;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;else&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;maxfd = fd2;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;FD_SET(fd1, &amp;amp;readfds);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;FD_SET(fd2, &amp;amp;readfds);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;FD_SET(fd1, &amp;amp;writefds);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;FD_SET(fd2, &amp;amp;writefds);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;timev.tv_sec = 3;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;timev.tv_usec = 0;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;if ( select(maxfd, &amp;amp;readfds, &amp;amp;writefds, NULL, &amp;amp;timev) ) {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;if ( FD_ISSET(fd1, &amp;amp;readfds) ) {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;// fd1有資料可讀&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;if ( FD_ISSET(fd2, &amp;amp;readfds) ) {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;// fd2 有資料可讀&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;if ( FD_ISSET(fd1, &amp;amp;writefds) ) {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;// fd1 可寫入&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;if (FD_ISSET(fd2, &amp;amp;writefds) ) {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;// fd2 可寫入&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;} else {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;// timeout or error&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;以上的寫法在應用有許多好處，一是可以同時處理許多檔案，並且可以隨時加入或退出，二是使用事作觸發讓系統的負載不會過重，並且也可兼顧時效性。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 18.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;b&gt;短時間休眠用&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;前面所提是一般正常的使用方式，有一種另外的使用場合，那是因為在Linux的sleep function中只有秒級的單位，若我們想要實現msec的sleep則無法做到(注:現在在real time中可以有usleep)，則可以利用select的timeout機制來作sleep的msec等級，其寫法如下：&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;struct timeval&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;timev;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;timev.tv_sec = 0;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;timev.tv_usec = 10000;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;// 10msec&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;select(1, NULL, NULL, NULL, &amp;amp;timev);&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://victoryuembeddedlinux.blogspot.com/feeds/3131004188464108063/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://victoryuembeddedlinux.blogspot.com/2012/02/api-select.html#comment-form' title='1 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6198249661133467553/posts/default/3131004188464108063'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6198249661133467553/posts/default/3131004188464108063'/><link rel='alternate' type='text/html' href='http://victoryuembeddedlinux.blogspot.com/2012/02/api-select.html' title='API Select怎麼用'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6198249661133467553.post-6814833439893311778</id><published>2012-01-02T23:15:00.000+08:00</published><updated>2012-01-02T23:15:36.517+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="application"/><category scheme="http://www.blogger.com/atom/ns#" term="GNU"/><category scheme="http://www.blogger.com/atom/ns#" term="GNU configuration"/><title type='text'>GNU編繹設定</title><content type='html'>我們現在大多會在網路下載各種GNU的軟件原始碼，並給予做編繹的動作，而在每個原始碼的根目錄中通常會有一個shell script，檔名會是configure，而我們在編繹原始碼之前，都需要先執行這一個執行檔，而在這執行檔中，會有三個設定，分別為--host, --build, --target其代表的意義如下：&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; --build &amp;nbsp; - 表示要在那一個機器執行編繹的動作，通常為 i686-pc-linux，原則這個可以讓configure自動幫你判別&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; --host &amp;nbsp; &amp;nbsp;- 表示最後的執行要在那個平台執行，例如arm-linux&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; --target &amp;nbsp;- 表示其執行檔為何種格式，例如arm-linux，所以這會和--host相同&lt;br /&gt;
另外我們在執行編繹有幾個環境會做設定如下：&lt;br /&gt;
CC=arm-linux-gcc&lt;br /&gt;
CPP=&quot;arm-linux-gcc -E&quot;&lt;br /&gt;
LD=arm-linux-ld&lt;br /&gt;
AS=arm-linux-as&lt;br /&gt;
NM=arm-linux-nm&lt;br /&gt;
RANLIB=arm-linux-ranlib&lt;br /&gt;
CXX=arm-linux-g++</content><link rel='replies' type='application/atom+xml' href='http://victoryuembeddedlinux.blogspot.com/feeds/6814833439893311778/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://victoryuembeddedlinux.blogspot.com/2012/01/gnu.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6198249661133467553/posts/default/6814833439893311778'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6198249661133467553/posts/default/6814833439893311778'/><link rel='alternate' type='text/html' href='http://victoryuembeddedlinux.blogspot.com/2012/01/gnu.html' title='GNU編繹設定'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6198249661133467553.post-2424312957789050550</id><published>2011-12-09T13:02:00.001+08:00</published><updated>2011-12-09T13:03:35.857+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="kernel boot init linux"/><title type='text'>Linux Kernel 開機大追蹤</title><content type='html'>&lt;br /&gt;
&lt;div style=&quot;font: 18.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;b&gt;前言&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;多年之前大家都在談論所謂後PC時代，在當時大家無法很確定什麼是後PC時代，在今天因為智慧型手機及平板電腦的興起，己使大家可以很清楚地了解什麼是後PC時代，就是嵌入式系統，而在這些嵌入式系統中，會需要一個作業系統，而Linux的免費，以及它的穩定、open source code、Linux 已成為現在嵌入式首選的作業系統，也因此現在已有越來越多人投入開發。通常若要了解一個作業作統，可以從其開機流程來了解，若清楚地了解其開機流程程，將有助於你了解整個作業系統。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 18.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;b&gt;Kernel原始碼&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Linux將其所有的程式碼全部公開，用以讓所有世界高手來修改，其實你可以將其視做一個framework的原始碼，所以你若了解其原始碼目錄的擺放將會有助於你開發的速度。以下是kernel source code根目錄的內容：&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1ggpgawOBIk8WWAGzbxym6t4oG_8M0Ft3IEz_6L6QdcGH0FKTf_gqgjqA6QypQWDJopHwndIBP8z116uuXHyJGAdAPA_TA_81heEldun0Cq_kb9GHDJixDDNtVw41JLQFX6ijIYgtWDxP/s1600/kernel-booting.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;46&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1ggpgawOBIk8WWAGzbxym6t4oG_8M0Ft3IEz_6L6QdcGH0FKTf_gqgjqA6QypQWDJopHwndIBP8z116uuXHyJGAdAPA_TA_81heEldun0Cq_kb9GHDJixDDNtVw41JLQFX6ijIYgtWDxP/s320/kernel-booting.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;font: 10.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;b&gt;圖一Linux Kernel source code根目錄&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 10.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 12.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;b&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;其中幾個比較重要的目錄說明如下：&lt;/span&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;font: 12.0px Wingdings; letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;arch&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;這是一個HAL層的原始碼，和CPU以及各個板子有關，通常這部分會由CPU廠商所提供，另外程式起始包含在這裏面，後面將會給予說明。&lt;/span&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;font: 12.0px Wingdings; letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;drivers&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;這是各個元件的驅動元件，而各個元件的驅動程式，將會依照各分門別類給予不同的目錄而放置。&lt;/span&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li style=&quot;font: 12.0px Wingdings; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;font: 12.0px &#39;Lucida Grande&#39;; letter-spacing: 0.0px;&quot;&gt;mm&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;這是有關記憶體管理的部分程式碼，這部分是和硬件無關的程式，其底層則是呼叫HAL層的程式碼，而這部分則是前面所提的arch目錄。&lt;/span&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li style=&quot;font: 12.0px Wingdings; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;font: 12.0px &#39;Lucida Grande&#39;; letter-spacing: 0.0px;&quot;&gt;fs&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;在這個目錄所放置的則是各種檔案系統的程式，通常檔案系統和硬體沒有關係，而其底層的IDE或者SCSI等等則是放在前面所提的driver目錄之中。對於各種的虛擬檔案系統也是在這裏。&lt;/span&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;font: 12.0px Wingdings; letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;kernel&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;這是系統微核心的地方，而這部分通常和硬體無關，排程的管理也是在這裏。&lt;/span&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;font: 12.0px Wingdings; letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;net&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;有關各種網路協定的實做，都在這裏，從網路的link層至應用層都在這裏，以及和應用程式之間的socket層介面也是在此目錄中。&lt;/span&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;font: 12.0px Wingdings; letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;include&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;kernel中用到C和組合語言的include file放在這個目錄。&lt;/span&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;font: 12.0px Wingdings; letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;init&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 24.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;這是系統開機時的初始化動作，這會呼叫arch之下以及各個driver的初始化動作。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 18.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;b&gt;Kernel編譯模式&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;我們在編譯kernel有兩種模式可以產生，一種是有壓縮的形式，這種形式檔案會較小很多，但是在啓動時會先做自我解壓縮，這樣會造成開機時會較慢一點，另外一種是直接產生一個binary (位元)檔，這是一個kernel的執行檔，這個檔案會大很多，但其實就是前一種解壓縮完之後的內容。如何編譯這兩種kernel呢? 其實很簡單，若要產生壓縮的程式碼，在根目錄執行 &lt;/span&gt;&lt;span style=&quot;color: #fd1e13; letter-spacing: 0.0px;&quot;&gt;&lt;b&gt;’make zImage’&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;就可以了，它會產生一個檔案 zImage ，放在目錄arch/arm/boot之內，另外要產生沒有壓縮的kernel執行 &lt;/span&gt;&lt;span style=&quot;color: #fd1e13; letter-spacing: 0.0px;&quot;&gt;&lt;b&gt;’make linux’&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;就可以了，而其產生的檔名為 vmlinux 在原始檔的根目錄之下，最後要說明的是要產生壓縮的 zImage 一定會先產生沒有壓縮的 vmlinux，再由其做壓縮成 zImage。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 18.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;b&gt;自我解壓縮&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;壓縮的zImage檔其前面有一個自我解壓縮的程式碼，這段程式碼在arch/arm/boot/compressed目錄之內，第一個執行的程式為該目錄之下的head.S，原則上bootloader可以傳遞參數給kernel，它將透過暫存器r1及r2來傳送，其中r1是CPU的ID，這個值其實是由CP15的指令所讀來的，而r2則是存於一些tag的指標位置，通常在embedded系統中我們都會省略而不使用。這是一小段解壓縮的程式碼，它可以放在記憶中任何位置來執行，也就是為independent code，其實它是將kernel壓縮後利用linker及objdump公用程式，將其結合成為一個可執行檔或者是firmware，其實是將壓縮過的核心程式當做是資料和head.S的程式結合在一起，另外值得一提的是，這個解壓縮程式可放在記憶體中任何位置執行，所以它會自動判別解壓縮後的程式是否會覆蓋自己而給予避開。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 18.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;b&gt;第一個指令&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;如果是有壓縮的第一個指令如前所提的，放在arch/arm/boot/compressed/head.S，若不是壓縮檔則是放在arch/arm/kernel/head.S之內，應該說這才是真正kernel的第一個指令，一樣的在解壓縮之後會將bootloader所傳送過來的r1 &amp;amp; r2暫存器原封不動的再傳給kernel，而 r1 則是傳遞 CPU 的代碼，而kernel則會使用cp15的指令讀回做檢查，並且查核那一個ARM core，則會使用相對的cache指令將cache打開，通常打開cache時需要啓動MMU才能打開cache，而這時通常會設定虛擬位址和真實位址是一樣的，而打開cache是為了要加快解壓縮的速度，而在解壓縮之前會將r1 &amp;amp; r2分別拷貝至r7 &amp;amp; r8暫存器，而在解壓縮完之後，會將這兩個暫存器存回原先的r1 &amp;amp; r2，而r2則是存放參數位置，而這些參數是有關開機時的選項，而這些說明目前已經寫在程式的開頭地方，當你看其原始碼時即可看到，而第一個指令則是在標示在.setion “.text.head”的地方。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;接著它會檢查從bootloader傳來的CPU ID是否正確，在kernel中可以撰寫支援多顆CPU的程式碼，因此可以透過這個代碼來取得相對應的程式碼，主要是cache以及CP15指令的不同，另外還有關MMU方面的操作也有所不同，當確認讓CPU ID是有被支援的，就會繼續執行下去。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;再來的動作則取回該CPU的訊息，以及該CPU在kernel己經準備好的一些初始化程式碼，我們在porting kernel時會建立一個錄在arch/arm之下，然後以mach-當開頭的目錄，像是mach-ixp4xx，在這目錄之內將會建立一個C程式碼，在這之內會有一個巨集指令MACHINE_START，在這之內會有一些call back function的設定，在初始化的過程中會被呼叫，其主要是設定那些硬體需要被mapping至那些virtual address，以及timer &amp;amp; interrupt controller的初始化程式碼，當這些初始化的程式碼都可以正確無誤地被執行，它最後則會執會init/main.c中的start_kernel，而在它執行的當中它會檢查從bootloader傳來的command line，若沒有會有一個警告訊息，說這個tag有問題，若你確定没有傳，那你可以忽略掉它。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;當它初始都没有問題，則會開始載入各個驅動程式，以及kernel本身的初始化動作，如記憶體管理，當這些都正常執行完之後，就會開始執行第一支AP，它會先執行由bootloader或者在kernel中設定的command line所指定的第一支程式，若没有則會尋找/sbin/init這支程式，若無法執行，則行bash，還是無法執行則會panic系統，並會說明找不到程式可執行，若第一支程式可以正常執行，則其它的程式則會由這第一支程式去執行其它程式，若它沒有執行其它程式，則將不會執行其它程式，另外第一支程式可以是一支shell script，以上則是kernel開機的順序。&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://victoryuembeddedlinux.blogspot.com/feeds/2424312957789050550/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://victoryuembeddedlinux.blogspot.com/2011/12/linux-kernel.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6198249661133467553/posts/default/2424312957789050550'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6198249661133467553/posts/default/2424312957789050550'/><link rel='alternate' type='text/html' href='http://victoryuembeddedlinux.blogspot.com/2011/12/linux-kernel.html' title='Linux Kernel 開機大追蹤'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1ggpgawOBIk8WWAGzbxym6t4oG_8M0Ft3IEz_6L6QdcGH0FKTf_gqgjqA6QypQWDJopHwndIBP8z116uuXHyJGAdAPA_TA_81heEldun0Cq_kb9GHDJixDDNtVw41JLQFX6ijIYgtWDxP/s72-c/kernel-booting.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6198249661133467553.post-2225810826862624281</id><published>2011-11-08T23:58:00.000+08:00</published><updated>2011-11-08T23:58:49.402+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="installation"/><category scheme="http://www.blogger.com/atom/ns#" term="linux"/><title type='text'>如何製作一個Debian安裝磁碟在USB storage上</title><content type='html'>Debian是在linux中常被使用的發行版本，它可以從多種的儲存謀體來做安裝的動作，這裹要介紹從USB stroage (俗稱大姆哥)做安裝的動作，以下則是裝作USB安裝碟的流程：&lt;br /&gt;
1．將USB format成FAT or FAT32檔案系統，因為只有這兩種系統才能做為開機系統，而且這兩種檔案系統有可能會讓USB可使用的大小比實際硬體還要小。&lt;br /&gt;
2．從網路下載一個公共程式 syslinux&lt;br /&gt;
3．執行指令 &#39;syslinux /dev/sdb1&#39; (其中/dev/sdb1則是USB磁碟機代碼)，完成之後將其掛載起來&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;mount /dev/sdb1 /mnt/usbdisk&lt;br /&gt;
4．下載網路安裝檔 netboot.sio 至PC並將其掛載起來如下&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;mount -o loop /home/netboot.iso /mnt/isodisk&lt;br /&gt;
5．拷貝上一個動作所掛載的網路安裝檔的所有內容至USB disk&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;cp -a /mnt/isodisk/* /mnt/usbdisk&lt;br /&gt;
6．將在USB disk中根目錄之下的isolinux目錄名稱改為syslinux&lt;br /&gt;
7．將在USB disk中的syslinux/isolinux.bin檔名改為syslinux/syslinux.bin&lt;br /&gt;
8．將在USB disk中的syslinux/isolinux.cfg檔名改為syslinux/syslinux.cfg&lt;br /&gt;
到此就大功告成，最後重新開機進入BIOS設定從USB disk開機即可</content><link rel='replies' type='application/atom+xml' href='http://victoryuembeddedlinux.blogspot.com/feeds/2225810826862624281/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://victoryuembeddedlinux.blogspot.com/2011/11/debianusb-storage.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6198249661133467553/posts/default/2225810826862624281'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6198249661133467553/posts/default/2225810826862624281'/><link rel='alternate' type='text/html' href='http://victoryuembeddedlinux.blogspot.com/2011/11/debianusb-storage.html' title='如何製作一個Debian安裝磁碟在USB storage上'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6198249661133467553.post-46509704266666407</id><published>2011-09-27T17:20:00.000+08:00</published><updated>2011-09-28T19:12:29.315+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="driver"/><category scheme="http://www.blogger.com/atom/ns#" term="kernel"/><category scheme="http://www.blogger.com/atom/ns#" term="serial"/><title type='text'>Serial驅動程式中的Flow Control問題</title><content type='html'>&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 19px;&quot;&gt;&lt;b&gt;什麼是Flow Control&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;Flow Control簡單講就是流量控制，其主要目的就是避免通訊的雙方資料被掉包，那為何資料會掉包呢？我們想像一個情境，通訊一定是至少兩人以上互相傳送資料，互相傳送資料雙方硬體不一定會一樣，所以在效能上也會不一樣，若當接收端來不及處理已接收到資料時，若沒有通知對方暫停傳送資料，因而造成對方持續送資料，這樣就會產一種現象，就是接收端會將收進來的資料丟棄，或者不接收對方送過來的資料，因而造成資料的留失，所以我們就使用流量控制的部分來確保資料不要留失。其實其中的做法也不是太難，就是利用一個機制來通知對方不要送資料就好了，而問題在於以前這種的控制都由軟體來做，但是最後還是控制使用硬體來通知對方，在控制硬體送出訊號給對方會需要一些時間處理，而這段時間長短是無法預測的，並且對方還是在繼續傳送資料，假如這段時間過長，就會造成和没有流量控制一樣的情形，也因此為了解決這個問題，現在就有人改用硬體來處理這個問題，就可以大大降低這個問題的產生，但是若要真正有效發揮硬體的功能是需要修改軟體的，所以以下我們會來說明如何修改軟體。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 18.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;b&gt;Serial Port的流量控制方式&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;RS232的流量控制方式有兩種，一種稱為軟體流量控制方式，另外一種就是所謂的硬體流量方式，什麼是軟體流量控制方式，其控制方式就是將控制訊息加到資料之中，用另外一個方式說明，就是當接收端無法收資料時就送一個字元Xoff (0x13)給對方，可以收的時候就送一個字元Xon (0x11)給對方，所以軟體控制的方式有幾種限制，首先是在傳送的資料不可以包含這兩個字完，否則將會嚴重破壞流量控制的正常運行，另外一個限制就這兩個字元必須是要即時被送出，若和要送給對方的資料一起排隊的話，有可能會延誤流量控制的時間點，因而造成流量控制的失敗。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;另外一種的流量控制方式為硬體方式，其作法是必需另外再接兩條線，一條為RTS至對方的CTS，因為是雙向的所以另外一條就是我的CTS接至對方的RTS，另外的說法雙方都會增加兩隻腳為RTS及CTS，其做法很簡單就是當接收端資料快滿的時候，將RTS設為low，一直到可以接收資料時再將RTS拉為high，相對的傳送端會隨時檢查CTS，當它為low時就停止送資料，當它為high時就開始送資料。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;RS232的上層控制驅動程式為tty_io，而這層則會負責流量控制，當需要做相對流量控制的行為時，它會呼叫你的RS232驅動程式作動作，所以只要做相對的動作即可，而這個動作則是前一篇文章-serial port device driver中所提的throttle &amp;amp; unthrottle這兩個call back function。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 18.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;b&gt;有什麼問題嗎？&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;若按照前面所提的，在寫串列式驅動程式的時候有什麼問題？看是沒有問題，但問題就在後面，因為現在的UART越做越好，所以就將流量控制的動作直接由IC本身實現，就不需要軟體來處理，IC實現有它的好處，因為它是由硬體來處理，所以反應的時間會非常快，能夠避免軟體處理時需要冗長的時間，可能會造成反應不及而讓流量控制無效。在找出問題之前我們先看以下的圖：&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgDsz-ZpUcSotdeGNuony5quxq_byOhk1nQ3pyqIcbilPZizNO4lly1saFVmUQyFBi9IPUNSKKWPXzMM3LTEv05N8AAXU4B3jfYG4m0oxgHuqYODKtJzsau6r4uvjsLBGSHK1L3FttXowuD/s1600/serial-flow-control.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;232&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgDsz-ZpUcSotdeGNuony5quxq_byOhk1nQ3pyqIcbilPZizNO4lly1saFVmUQyFBi9IPUNSKKWPXzMM3LTEv05N8AAXU4B3jfYG4m0oxgHuqYODKtJzsau6r4uvjsLBGSHK1L3FttXowuD/s320/serial-flow-control.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px Helvetica; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;以上為驅動程式的架構圖，通常每一層驅程式都會有自已的buffer來存放收送的資料，而前面有說過在tty_io層會做流量控制，而它是如何判斷何時需要做流量控制呢？當然是依照它自已的buffer來做判斷，快滿的時候就叫對方不要送資料，buffer已被讀完則通知對方可以送資料，問題在於當上層的buffer滿並不代表低層IC上的buffer已滿，如此一來有一種情境將會發生，底層的IC buffer已滿，因為有支援流量控制，所以IC已經主動通知對方不要送資料，可是這時候因為上層的資料未滿，或者剛到低水位，所以通知低層送出通知對方可以送資料，如此一來將會弄亂底層的流量控制，簡單的說明就是上層的buffer水位和底層是不會同步的，用另外一種方式來看待這個問題，其實這麼多層的驅動程式，只要其中有一層做流量控制即可，這時候當然讓最低層的IC來處理即可，因為可以反應最快，並且因為由IC自行處理，所以可以減輕CPU的負擔，所以在有IC支援流量控制時RS232的驅動程式，應該如以下的寫法將會是比較好的：&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;static void uart_throttle(struct tty_struct *tty)&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;…………&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;disable_IC_receiving_and_receiving_interrupt();&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;………………..&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;static void uart_unthrottle(struct tty_struct *tty)&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;………………&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;enable_IC_receiving_and_receiving_interrupt();&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;…………………&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;没錯一個簡單的動作，就是在throttle的callback function中停止收資料就好了，因為如此一來將會造成IC buffer到達高水位而讓IC自動作成流量控制的行為即可，另外unthrottle的callback function中再一次啓動收資料即可，因為將IC中的buffer讀走而達低水位時，IC將會再次自動做出流量控制，如此一來上層可以不用知道低層IC的buffer使用情形，也不會弄亂IC的流量控制，這是在IC支援流量控制時所要做的修正。&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://victoryuembeddedlinux.blogspot.com/feeds/46509704266666407/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://victoryuembeddedlinux.blogspot.com/2011/09/serialflow-control.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6198249661133467553/posts/default/46509704266666407'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6198249661133467553/posts/default/46509704266666407'/><link rel='alternate' type='text/html' href='http://victoryuembeddedlinux.blogspot.com/2011/09/serialflow-control.html' title='Serial驅動程式中的Flow Control問題'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgDsz-ZpUcSotdeGNuony5quxq_byOhk1nQ3pyqIcbilPZizNO4lly1saFVmUQyFBi9IPUNSKKWPXzMM3LTEv05N8AAXU4B3jfYG4m0oxgHuqYODKtJzsau6r4uvjsLBGSHK1L3FttXowuD/s72-c/serial-flow-control.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6198249661133467553.post-4016081074186944070</id><published>2011-09-12T17:14:00.000+08:00</published><updated>2011-09-14T20:48:45.421+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="DMA"/><category scheme="http://www.blogger.com/atom/ns#" term="driver"/><category scheme="http://www.blogger.com/atom/ns#" term="kernel"/><category scheme="http://www.blogger.com/atom/ns#" term="MMU"/><title type='text'>驅動程式中的DMA問題</title><content type='html'>&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Grande&#39;; font-size: 19px;&quot;&gt;&lt;b&gt;前言&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;什麼是DMA(directly memory access)? 簡單的講就直接記憶體存取，或許你還是無法明白，這樣說好了，在一個電腦系統中，通常都是由CPU (中央控制單元) 來對記憶體做存取的動作，也就是在各個電腦週邊元件中，若要對記憶體做存取動作，則必須經由 CPU 來做仲介的角色，而DMA則可以取代CPU這個工作，但僅至於資料而已無法對指令做這個動作，因為記憶體在系統中是唯一的，若要讓CPU及DMA可以很順暢的工作而不會互相干擾，則必需在軟體上做一些協調的動作，另外因為CPU有MMU及Cache的元件，也使得為了要讓DMA取得正確的資料，所以在寫這方面的驅動程式時需要特別注意，以下就來說明這方面的作法及問題。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 18.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;b&gt;硬體架構&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNyjEUIxngN6JhNUGHuynPC-ASMMfN91iGcI6bRs5As13XTxHr6Y2GOJlSlb1_5M5FKkw-yQW6iyA9VURVyhuv-qFuTILEPS2hybwJsQIYPQTOItwY1VbaQpR-labhCi1yW69z8aCDjxLT/s1600/dma.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;174&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNyjEUIxngN6JhNUGHuynPC-ASMMfN91iGcI6bRs5As13XTxHr6Y2GOJlSlb1_5M5FKkw-yQW6iyA9VURVyhuv-qFuTILEPS2hybwJsQIYPQTOItwY1VbaQpR-labhCi1yW69z8aCDjxLT/s320/dma.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;圖一&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 18.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;b&gt;問題點&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;從上圖中我們可以清楚地了解以下幾件事：&lt;/span&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;font: normal normal normal 12px/normal Wingdings; letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;當CPU要向DRAM或者是週邊元件存取時，所以放出來的位置將會經過cache及MMU的處理。&lt;/span&gt;&lt;/li&gt;
&lt;ul&gt;
&lt;li style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;font: normal normal normal 12px/normal Wingdings; letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;在cache中的處理主要是提高對記憶體的存取速度。&lt;/span&gt;&lt;/li&gt;
&lt;li style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;font: normal normal normal 12px/normal Wingdings; letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;當作業啓動時所有程式均使用虛擬記憶體，所以一定會經過MMU的位址轉換，因為當實際要對週邊元件或者記憶體存取時一定會使用實體位址。&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;li style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;font: normal normal normal 12px/normal Wingdings; letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;當DMA要存取記憶體時並不會經過MMU模組的轉換，換句話說就是DMA會直接使用實體位址來存取記憶體。&lt;/span&gt;&lt;/li&gt;
&lt;ul&gt;
&lt;li style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;font: normal normal normal 12px/normal Wingdings; letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;另外一個問題是DMA也沒有經過cache模組，所以存取的資直接從記憶體存取。&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/ul&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 18.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;b&gt;解決方案&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;由以上的問題描述，我們可以看一個很基本的問題，就是CPU和DMA之間對記憶體的存取可能會有不相符的現象產生。首先我們先來看週邊元件要送資料，也就是從CPU寫入資料至記憶體，然後DMA從記憶體取得資料給週邊元件，進而週邊元件送出資料，這裡問題在於CPU寫入資料時，可能不會一定寫入記憶體，有可能保留至cache中，若這時DMA來取資料將會是不對的資料，因此在DMA存取之前，一定要讓CPU的cache單元做一次sync的動作，將若有還有cache中的資料，真的寫入記憶體中，如此一來DMA將可以取得正確資料。換一個簡單的說法，就是週邊元件要送資料時必須對cache做sync的動作，確認最後的資料是有寫入記憶體。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;另一個資料方向就是當週邊元件收到資料時，將會由DMA直接寫入記憶體，完作接收後，週邊元件會產生一個中斷通知CPU來讀取資料，這時的問題是在於存放收到資料，有可能是已被cache住，若CPU不做任何動作而直接來讀取資料，一樣會產生資料不正確的情形，這時在CPU讀取時必須對該區塊作一個cache invalid的動作，讓CPU在讀取該區塊資料，會實際至記憶體做讀取的動作，因此重新讓cache元件，針對該區域重新做cache的動作，如此一來就不會有資料不正確的情形產生。所以說週邊元件在收資料時，必需對cache做invalid的動作。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;另外有一個簡單的作法，就是在準備這些記憶體時，就取得讓記憶體是不會做cache的動作，如此一來就不需要做資料同步動作。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 18.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;b&gt;Kernel API&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;我們從以上知道問題，也知道該如何解決，現在的問題是有多少的kernel API可供使用，以下我們就來看：&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 18.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;linux dma-mapping.h=&quot;&quot;&gt;&lt;/linux&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 18.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;dma_addr_t dma_map_single(struct device *, void *, size_t, enum dma_data_direction);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 18.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;void dma_unmap_single(struct device *, dma_addr_t, size_t, enum dma_data_direction);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 18.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;dma_addr_t dma_map_page(struct device *, struct page *,unsigned long, size_t, enum dma_data_direction);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 18.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;void dma_unmap_page(struct device *, dma_addr_t, size_t,enum dma_data_direction);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 18.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;void dma_cache_maint(const void *kaddr, size_t size, int rw);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 18.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;void dma_cache_maint_page(struct page *page, unsigned long offset,size_t size, int rw);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 18.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;enum dma_data_direction {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DMA_BIDIRECTIONAL = 0,&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DMA_TO_DEVICE = 1,&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DMA_FROM_DEVICE = 2,&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DMA_NONE = 3,&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;};&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;以上的kernel API主要是針對將一般取得的記憶體(例如由kmalloc所取得)，是會被cache的記憶體，將cache中的資料和實體記憶體資料做同步的動作，其DMA_TO_DEVICE就是做invalidate的動作，而DMA_FROM_DEVICE就是synchronize的動作，這些API必需要在呼叫DMA之前完成。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 18.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;void *dmam_alloc_coherent(struct device *dev, size_t size,dma_addr_t *dma_handle, gfp_t gfp);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 18.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;void dmam_free_coherent(struct device *dev, size_t size, void *vaddr,dma_addr_t dma_handle);&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;以上的kernel API是在要allocate記憶體時就取得不會被cache的記憶體，如此一來對這塊記憶體的存取時就不需要前面所提的動作 – invalidate or synchronize，另外也可取得該記憶體的實體記憶體，這個實體記憶體將會給DMA controller所使用。&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://victoryuembeddedlinux.blogspot.com/feeds/4016081074186944070/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://victoryuembeddedlinux.blogspot.com/2011/09/dma.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6198249661133467553/posts/default/4016081074186944070'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6198249661133467553/posts/default/4016081074186944070'/><link rel='alternate' type='text/html' href='http://victoryuembeddedlinux.blogspot.com/2011/09/dma.html' title='驅動程式中的DMA問題'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNyjEUIxngN6JhNUGHuynPC-ASMMfN91iGcI6bRs5As13XTxHr6Y2GOJlSlb1_5M5FKkw-yQW6iyA9VURVyhuv-qFuTILEPS2hybwJsQIYPQTOItwY1VbaQpR-labhCi1yW69z8aCDjxLT/s72-c/dma.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6198249661133467553.post-8176943810567600130</id><published>2011-07-28T23:23:00.001+08:00</published><updated>2011-09-14T20:49:12.478+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="driver"/><category scheme="http://www.blogger.com/atom/ns#" term="kernel"/><category scheme="http://www.blogger.com/atom/ns#" term="MMC/SD"/><title type='text'>SD/MMC驅動程式面面談</title><content type='html'>&lt;div style=&quot;font: 18.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;b&gt;前言&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;MMC/SD在現在崁入式系統常被使用，因為它的體積小而且目前最新的版本可以支援到2TB，所以現在的崁入式的系統中自然而然會選用它來做儲存媒介。而SD/MMC其標準定義了實體層的硬體介面訊號，以及第二層為指令及資料讀寫的定義。它可分為SD/MMC為第一版只支援至2G，而SDHC則是第二版，可以支援至32G，它和第一版的差異，除了實體層的工作頻率增加，可以較快速的讀取之，在第二層也有擴充其功能，使其可以存取更大的檔案系統，而目前最新的為SDXC它可以支援至2TB，它又將工件往上提升，可是可以向下相容，也就是舊規格的SD卡也可以用，現在我們來介紹如何在driver中撰這些程式碼。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 18.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;b&gt;MMC/SD程式目錄&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;MMC/SD在Linux Kernel原始程式碼中的擺放位置為drivers/mmc，在其中又分為三個子目錄，分別為host、core及card，而這三個目錄其所包含內容如下：&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #fd1e13; font: 14.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;b&gt;host&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;則是各家SD controller晶片廠所實現的部分，其主要是控制硬體，並將上層的所下的指令給轉換至硬體層，我們所要撰寫的驅動程式也是在這個目錄之下。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #fd1e13; font: 14.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;b&gt;core&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;這是SD/MMC的管理及核心程式的地方，其中包含了第二層大家共通的部分，也是提供實體註冊及管理的部分，這個部分是大家一起共用，所以不用修改。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #fd1e13; font: 14.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;b&gt;card&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;這是kernel中的檔案系統和管理中心溝通部分，也就是將檔案系統的需求轉換至核心管理程式，而核心管理再將其轉換至實體層，這個部分也是大家一起共用，所以也不需要修改。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;在2.6.18之後有支援SDHC其主要是第二層的指令增加，所以舊的SD硬體 (SD host) 可以經軟體的改變而可以支援SDHC，只是因為硬體沒有改變，因此無法支援較高速的SD card。而在載入驅動程式需如下：&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #1f497d; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;color: black; letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;b&gt;insmod mmc_core.ko&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #1f497d; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;insmod mmc_block.ko&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #1f497d; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;insmod your_hardware_SD_driver.ko&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;color: #1f497d; letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;因為這是一個底層的驅動程式，所以你可以在上層載入任何的檔案系統，因為檔案系統是一個純軟體的驅動程式，所以和硬體無關，只是FAT32最大所能支援的檔案系統就只有32G，所以若要使用較大的檔案系統則必需使用其它的檔案系統。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 18.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;b&gt;系統驅動程式結構&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;我們先來了解一下linux kernel其中驅動程式的結構，在linux kernel的驅動程式中會將各種元件給予分門別類，並且在各種類別中會給予建構一個管理層的驅動程式，其主要目的是要建立和應用程式之間的標準介面，並且管理相同類別中的各家不同的硬體廠商，如此一來即可規範硬體廠商如何撰寫廠商，避免因不同的廠商而產生不同的驅動程式的撰寫格式不同，或者造成應用程式的介面，進而造成使用者因不同的廠商而要修改軟體。其架構圖如下：&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Times; font-size: small;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhyhTufFi0OFXszEnFKxWa_v-rjx_M6tlNhfU-p6uCEM3x0d8QCeu0hpVfrgy5pGtz8-zmFWO2e-yx9c4g2KcTVRN_nrq-dd7Sx5-T31EhZUTHYMYmvGS-xC4Gjcx8wMEuvIpOso7HxGE1/s1600/sddriver.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;186&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhyhTufFi0OFXszEnFKxWa_v-rjx_M6tlNhfU-p6uCEM3x0d8QCeu0hpVfrgy5pGtz8-zmFWO2e-yx9c4g2KcTVRN_nrq-dd7Sx5-T31EhZUTHYMYmvGS-xC4Gjcx8wMEuvIpOso7HxGE1/s320/sddriver.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Times; font-size: small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;圖一：驅動程式系統架構&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;圖一清楚地表示前面所說明的各個目錄所負責的事情，而我們今天所要實現就是在host的目錄之下，向core註冊一個硬體，如此一來就可很輕易地連接到整個檔案系統，而檔案系統維護的部分，則是由上層的檔案所維護，對硬體層而言則是執行上層的指令，並且是完全是被動的，不會主動自行執行任何指令。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 18.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;b&gt;MMC core所提供的API&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;在介紹如何撰寫前，先來了解有那些MMC core API可供使用，其所用的include file是&lt;linux host.h=&quot;&quot; mmc=&quot;&quot;&gt;及&lt;linux mmc=&quot;&quot; sd.h=&quot;&quot;&gt;，而API如下：&lt;/linux&gt;&lt;/linux&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #548dd4; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 18.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;b&gt;struct mmc_host *mmc_alloc_host(int extra, struct device *)&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;這是allocate MMC註冊時所需的資料結構記憶體，另外可以多要一些記憶體來存放驅動程式的私有資料，其input/output說明如下：&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #fd1e13; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;color: black; letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;b&gt;Input :&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;int extra – 需要額外記憶體的大小，其存放位置的指標將會放在return回來的mmc資料結構中的private指標，它將會是緊接在mmc資料結構的最後面，或者經由呼叫mmc_priv(struct mmc_host *)來取得其指標。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;struct device * – 為驅動程式進入時系統會傳過來的一個參數，只要將其再轉傳過去即可。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #fd1e13; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;color: black; letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;b&gt;Output :&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;其返回值為一個mmc_host資料結構的位址point，這個資料結構會在後面介紹，這個point位址將會給予保留，因為我們需要在其中幾個call back欄位填入我們要實現的功能，也就是提供給上層驅動程式如何溝通的介面。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #548dd4; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;void *mmc_priv(struct mmc_host *host)&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;這是取回私有資料的指標，通常會再給予強迫轉型給local變數。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #fd1e13; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;color: black; letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;b&gt;Input :&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;struct mmc_host *host – 是mmc_alloc_host API所return回來的class pointer。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #fd1e13; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;color: black; letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;b&gt;Output :&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;其返回值為一個指標位址。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #548dd4; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;int mmc_add_host(struct mmc_host *)&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp;這是增加一個SD host controller，而其所需要的資料結構則是由上一個API所取得回來的，而登錄加入時上層的管理者會掃瞄一次是否有SD卡已經插上來，若有則增加一個SD disk，若没有也會設定該SD host所支援的電壓及頻率。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #fd1e13; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;color: black; letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;b&gt;Iuput:&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;struct mmc_host * - 是由mmc_alloc_host API所return回來的class pointer。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #fd1e13; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;color: black; letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;b&gt;Output:&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;0代表成功，非0值代表錯誤。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #548dd4; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;color: black; letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;b&gt;void mmc_remove_host(struct mmc_host *)&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;這是移除一個SD host controller，其做的事情和mmc_add_host()是相反的事。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #fd1e13; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Input:&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;struct mmc_host * - 是由mmc_alloc_host API所return回來的class pointer。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #fd1e13; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;color: black; letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;b&gt;Output:&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;無&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #548dd4; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;void mmc_free_host(struct mmc_host *)&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;這是將mmc_alloc_host()所取得的資料結構記憶體空間歸還給系統，另外也會將多取得的私有空間也歸還給系統，所以在這之後將不可再使用該資料結構的記憶體空間。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #fd1e13; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;color: black; letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;b&gt;Input:&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;struct mmc_host * - 是由mmc_alloc_host API所return回來的class pointer。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #fd1e13; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;color: black; letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;b&gt;Output:&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;無&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #548dd4; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;color: black; letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;b&gt;void mmc_detect_change(struct mmc_host *, unsigned long delay)&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;在控制器偵測到有SD卡的插入或拔出都會呼叫這個API通知上層管理層加入一張SD卡或者移除一張SD卡，請不要搞亂並沒有移除或增加一個控制器，只是SD卡而己，但在移除時未完成的SD動作，都需要給予放棄。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #fd1e13; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;color: black; letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;b&gt;Input:&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;struct mmc_host * - 是由mmc_alloc_host API所return回來的class pointer。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;unsigned long delay – 當是插入時通常會設定一個值，以等待插入的SD卡電氣訊號穩定，而移除時通常其值會是0。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #fd1e13; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;color: black; letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;b&gt;Output:&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;無&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #548dd4; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;color: black; letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;b&gt;void mmc_request_done(struct mmc_host *, struct mmc_request *)&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;這是一個非常也常用到的API，原則上層管理層下達指令給控制器時都是透過mmc_request，而當控制器完成該指令時則需要呼叫這個API來通知上層已完成該指令，而在SD的控制指令則是半雙工的，一個指令完成之後才會有下一個，不會有連續好幾個指令產生。另外指令是包含讀寫資料。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #fd1e13; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;color: black; letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;b&gt;Input:&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;struct mmc_host * - 是由mmc_alloc_host API所return回來的class pointer。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;struct mmc_request * - 是由上層所下的指令資料結構。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #fd1e13; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;color: black; letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;b&gt;Output:&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;無&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 18.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;b&gt;資料結構&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;如前面所提，其中最重要的資料結構宣告如下：&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;struct mmc_ios {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; unsigned int&amp;nbsp; &amp;nbsp; clock;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; /* clock rate */&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; unsigned short&amp;nbsp; vdd;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; unsigned char &amp;nbsp; bus_mode;&amp;nbsp; &amp;nbsp; /* command output mode */&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; unsigned char &amp;nbsp; chip_select;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; /* SPI chip select */&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; unsigned char &amp;nbsp; power_mode; &amp;nbsp; /* power supply mode */&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; unsigned char &amp;nbsp; bus_width;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; /* data bus width */&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; unsigned char &amp;nbsp; timing;&amp;nbsp; &amp;nbsp; &amp;nbsp; /* timing specification used */&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;};&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;這是一個SD卡的基本設定值，其中要支援的電壓值、使用的頻率等等，其使用時機當有SD卡插上會要求設定這些以啓動插入的SD卡。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;struct mmc_host_ops {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; void (*request)(struct mmc_host *host, struct mmc_request *req);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; void&amp;nbsp; &amp;nbsp; (*set_ios)(struct mmc_host *host, struct mmc_ios *ios);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int &amp;nbsp; &amp;nbsp; (*get_ro)(struct mmc_host *host);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int &amp;nbsp; &amp;nbsp; (*get_cd)(struct mmc_host *host);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; void&amp;nbsp; &amp;nbsp; (*enable_sdio_irq)(struct mmc_host *host, int enable);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;};&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;這是設定讓SD host所能提供功能，而其中的request最為重要，它是SD要對SD卡任何的動作需求，包含讀寫資料，以其它SD控制指令下達，set_ios則是設定以上資料結構的call back function，get_ro則是回覆這個SD卡是否可以寫入。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;struct mmc_host {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; struct device &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; *parent;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; struct device &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; class_dev;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; index;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; const struct mmc_host_ops *ops;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; unsigned int&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; f_min;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; unsigned int&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; f_max;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; u32 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ocr_avail;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; unsigned long &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; caps; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; /* Host capabilities */&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; /* host specific block data */&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;unsigned int max_seg_size; &amp;nbsp; /* see blk_queue_max_segment_size */&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;unsigned short max_hw_segs;/* see blk_queue_max_hw_segments */&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;unsigned short max_phys_segs; /* see blk_queue_max_phys_segments */&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; unsigned short&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; unused;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp; unsigned int max_req_size; /* maximum number of bytes in one req */&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; unsigned int max_blk_size; /* maximum size of one mmc block */&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp;unsigned int max_blk_count; /* maximum number of blocks in one req */&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; /* private data */&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; spinlock_t&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; lock;&amp;nbsp; &amp;nbsp; /* lock for claim and bus ops */&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; struct mmc_ios&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ios; &amp;nbsp; &amp;nbsp; /* current io bus settings */&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; u32 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ocr; &amp;nbsp; &amp;nbsp; /* the current OCR setting */&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; /* group bitfields together to minimize padding */&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; unsigned int&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; use_spi_crc:1;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; unsigned int&amp;nbsp; &amp;nbsp; claimed:1;&amp;nbsp; &amp;nbsp; &amp;nbsp; /* host exclusively claimed */&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; unsigned int &amp;nbsp; bus_dead:1; &amp;nbsp; &amp;nbsp; /* bus has been released */&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;#ifdef CONFIG_MMC_DEBUG&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; unsigned int &amp;nbsp; &amp;nbsp; removed:1; &amp;nbsp; /* host is being removed */&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;#endif&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; struct mmc_card&amp;nbsp; &amp;nbsp; *card; /* device attached to this host */&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; wait_queue_head_t &amp;nbsp; &amp;nbsp; &amp;nbsp; wq;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; struct delayed_work &amp;nbsp; &amp;nbsp; detect;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; const struct mmc_bus_ops *bus_ops; &amp;nbsp; /* current bus driver */&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; unsigned int&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; bus_refs; &amp;nbsp; &amp;nbsp; &amp;nbsp; /* reference counter */&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; unsigned int&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; sdio_irqs;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; struct task_struct&amp;nbsp; &amp;nbsp; &amp;nbsp; *sdio_irq_thread;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; atomic_t&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; sdio_irq_thread_abort;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;#ifdef CONFIG_LEDS_TRIGGERS&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; struct led_trigger&amp;nbsp; &amp;nbsp; &amp;nbsp; *led; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; /* activity led */&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;#endif&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; struct dentry &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; *debugfs_root;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;#ifdef CONFIG_MMC_EMBEDDED_SDIO&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; struct {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; struct sdio_cis &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; *cis;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; struct sdio_cccr&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; *cccr;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; struct sdio_embedded_func&amp;nbsp; &amp;nbsp; *funcs;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; num_funcs;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; } embedded_sdio_data;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;#endif&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; unsigned long &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; private[0] ____cacheline_aligned;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;};&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;這是記錄SD host的一些資訊，SD中所有驅動程式將會隨時使用這個資訊。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;struct mmc_command {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; u32 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; opcode;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; u32 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; arg;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; u32 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; resp[4];&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; unsigned int&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; flags;&amp;nbsp; &amp;nbsp; /* expected response type */&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; unsigned int&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; retries; &amp;nbsp; &amp;nbsp; /* max number of retries */&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; unsigned int&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; error;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; /* command error */&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;/*&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp;* Standard errno values are used for errors, but some have specific&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp;* meaning in the MMC layer:&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp;*&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp;* ETIMEDOUT&amp;nbsp; &amp;nbsp; Card took too long to respond&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp;* EILSEQ &amp;nbsp; &amp;nbsp; &amp;nbsp; Basic format problem with the received or sent data&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp;*&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (e.g. CRC check failed, incorrect opcode in response&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp;*&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; or bad end bit)&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp;* EINVAL &amp;nbsp; &amp;nbsp; &amp;nbsp; Request cannot be performed because of restrictions&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp;*&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; in hardware and/or the driver&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp;* ENOMEDIUM&amp;nbsp; &amp;nbsp; Host can determine that the slot is empty and is&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp;*&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; actively failing requests&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp;*/&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; struct mmc_data&amp;nbsp; *data; /* data segment associated with cmd */&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; struct mmc_request &amp;nbsp; *mrq; &amp;nbsp; &amp;nbsp; &amp;nbsp; /* associated request */&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;};&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;這個資料結構只有在下指令時會用到，但是有一個很重要的概念是，讀寫資料也是指令的一種，所以意思就是SD的管理層軟體全部使用command和實體的驅動程式做溝通。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;struct mmc_data {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; unsigned int&amp;nbsp; timeout_ns;&amp;nbsp; /* data timeout (in ns, max 80ms) */&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; unsigned int &amp;nbsp; &amp;nbsp; timeout_clks; &amp;nbsp; /* data timeout (in clocks) */&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; unsigned int&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; blksz;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; /* data block size */&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; unsigned int&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; blocks; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; /* number of blocks */&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; unsigned int&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; error;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; /* data error */&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; unsigned int&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; flags;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; unsigned int&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; bytes_xfered;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; struct mmc_command&amp;nbsp; &amp;nbsp; &amp;nbsp; *stop; &amp;nbsp; &amp;nbsp; /* stop command */&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; struct mmc_request&amp;nbsp; &amp;nbsp; &amp;nbsp; *mrq; &amp;nbsp; &amp;nbsp; &amp;nbsp; /* associated request */&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; unsigned int&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; sg_len; &amp;nbsp; &amp;nbsp; &amp;nbsp; /* size of scatter list */&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; struct scatterlist&amp;nbsp; &amp;nbsp; &amp;nbsp; *sg;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; /* I/O scatter list */&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;};&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;這是當指令為讀寫資料時會用到的資料結構，其中有包含要存放的buffer，但有點很重要，就是這個buffer是使用page的管理，而不是raw buffer的方式。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;struct mmc_request {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; struct mmc_command&amp;nbsp; &amp;nbsp; &amp;nbsp; *cmd;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; struct mmc_data &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; *data;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; struct mmc_command&amp;nbsp; &amp;nbsp; &amp;nbsp; *stop;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; void&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; *done_data; &amp;nbsp; &amp;nbsp; /* completion data */&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; void&amp;nbsp; (*done)(struct mmc_request *);/* completion function */&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;};&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;這是來存放指令的資料結構。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 18.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;b&gt;範例程式&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;static void vicsd_request(struct mmc_host *mmc, struct mmc_request *mrq)&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;struct vicsd_host&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;*host=mmc_priv(mmc);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;struct mmc_command&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;*cmd;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;spin_lock(&amp;amp;host-&amp;gt;lock);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;host-&amp;gt;mrq = mrq;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;cmd = mrq-&amp;gt;cmd;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;// if no card inserted, return timeout error&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;if ( readl(&amp;amp;host-&amp;gt;reg-&amp;gt;status) &amp;amp; MSD_CARD_DETECT ) {&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;// card is removed&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;cmd-&amp;gt;error = MMC_ERR_TIMEOUT;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;goto request_done;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;// request include data or not&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;if ( cmd-&amp;gt;data ) {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;vicsd_prepare_data(host, cmd-&amp;gt;data);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;// do request command&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;vicsd_send_command(host, cmd);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;if ( cmd-&amp;gt;data &amp;amp;&amp;amp; cmd-&amp;gt;error == MMC_ERR_NONE ) {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;spin_unlock(&amp;amp;host-&amp;gt;lock);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;return;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;request_done:&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;vicsd_request_done(host);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;spin_unlock(&amp;amp;host-&amp;gt;lock);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;static void vicsd_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;struct vicsd_host&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;*host=mmc_priv(mmc);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;spin_lock(&amp;amp;host-&amp;gt;lock);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;if (ios-&amp;gt;clock) {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;// set SD host controller frequency&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;} else if ( !(readl(&amp;amp;host-&amp;gt;reg-&amp;gt;clock_control) &amp;amp; MSD_CLK_DIS) ) {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;/*&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt; * Ensure that the clock is off.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt; */&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;if ( ios-&amp;gt;power_mode == MMC_POWER_OFF ) {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;// power off host controller&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;} else {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;// power on host controller&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;#if 1&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;// set bus width&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;if ( ios-&amp;gt;bus_width == MMC_BUS_WIDTH_1 ) {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;………………………….&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;} else {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;…………………………..&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;#endif&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;spin_unlock(&amp;amp;host-&amp;gt;lock);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;static int&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;vicsd_get_ro(struct mmc_host *mmc)&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;struct vicsd_host&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;*host=mmc_priv(mmc);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;if ( readl(&amp;amp;host-&amp;gt;reg-&amp;gt;status) &amp;amp; MSD_WRITE_PROT )&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;return 1;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;else&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;return 0;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;static struct mmc_host_ops vicsd_ops = {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;.request&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;= vicsd_request,&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;.set_ios&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;= vicsd_set_ios,&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;.get_ro&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;= vicsd_get_ro,&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;};&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;static int vicsd_probe(struct platform_device *pdev)&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;struct device *dev = &amp;amp;pdev-&amp;gt;dev;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;struct mmc_host&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;*mmc;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;int&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;ret;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;// allocate a MMC host data structure&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;mmc = mmc_alloc_host(sizeof(struct vicsd_host), dev);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;if (!mmc) {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;ret = -ENOMEM;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;goto out;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;// initialize the MMC host data structure&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;mmc-&amp;gt;ops = &amp;amp;vicsd_ops;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;mmc-&amp;gt;f_min = 400000;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;mmc-&amp;gt;f_max = 25000000;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;mmc-&amp;gt;mode = MMC_MODE_SD;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;#if 1&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;mmc-&amp;gt;ocr_avail = 0xffff00;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;// support 2.0v - 3.6v power&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;#else&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;mmc-&amp;gt;ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;mmc-&amp;gt;caps = MMC_CAP_4_BIT_DATA;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;mmc-&amp;gt;max_hw_segs = 128;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;mmc-&amp;gt;max_phys_segs = 128;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;mmc-&amp;gt;max_sectors = 128;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;mmc-&amp;gt;max_seg_size = mmc-&amp;gt;max_sectors * 512;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;#endif&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;host = mmc_priv(mmc);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;host-&amp;gt;mmc = mmc;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;…………………………………………………..&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;/*&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; * Ensure that the host controller is shut down, and setup&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; * with our defaults.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; */&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;// reset the SD card controller&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;………………………………………………&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;// to check any card inserted or not&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;……………………………………………&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;// initialize the SD card host register&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;…………………………………………..&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;dev_set_drvdata(dev, mmc);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;mmc_add_host(mmc);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;return 0;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp;out:&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;if (mmc)&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;mmc_free_host(mmc);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;return ret;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;static struct platform_driver vicsd_driver = {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;.probe&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; = vicsd_probe,&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;.remove &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; = vicsd_remove,&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;.suspend&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;= vicsd_suspend,&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;.resume&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;= vicsd_resume,&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;.driver&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;= {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;.name&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;= &quot;victor-sd&quot;,&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;},&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;};&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;static int __init vicsd_init(void)&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;int&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;ret;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;ret=platform_driver_register(&amp;amp;vicsd_driver);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;if ( ret ) {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;printk(&quot;fail !\n&quot;);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;platform_driver_unregister(&amp;amp;vicsd_driver);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;} else {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;vicsd_device = platform_device_alloc(&quot;moxart-sd&quot;, -1);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;if (!vicsd_device) {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;platform_driver_unregister(&amp;amp;vicsd_driver);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;return -ENOMEM;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;ret = platform_device_add(vicsd_device);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;if (ret) {&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;platform_device_put(vicsd_device);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;platform_driver_unregister(&amp;amp;vicsd_driver);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;return ret;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;printk(&quot;OK.\n&quot;);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;return ret;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;static void __exit vicsd_exit(void)&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;platform_driver_unregister(&amp;amp;vicsd_driver);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;module_init(vicsd_init);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;
&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;module_exit(vicsd_exit);&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://victoryuembeddedlinux.blogspot.com/feeds/8176943810567600130/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://victoryuembeddedlinux.blogspot.com/2011/07/sdmmc.html#comment-form' title='1 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6198249661133467553/posts/default/8176943810567600130'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6198249661133467553/posts/default/8176943810567600130'/><link rel='alternate' type='text/html' href='http://victoryuembeddedlinux.blogspot.com/2011/07/sdmmc.html' title='SD/MMC驅動程式面面談'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhyhTufFi0OFXszEnFKxWa_v-rjx_M6tlNhfU-p6uCEM3x0d8QCeu0hpVfrgy5pGtz8-zmFWO2e-yx9c4g2KcTVRN_nrq-dd7Sx5-T31EhZUTHYMYmvGS-xC4Gjcx8wMEuvIpOso7HxGE1/s72-c/sddriver.jpg" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6198249661133467553.post-7064789115577163471</id><published>2011-04-26T23:20:00.000+08:00</published><updated>2011-04-26T23:33:40.602+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="kernel driver sysfs"/><title type='text'>如何撰寫Driver支援sysfs檔案系統</title><content type='html'>&lt;div style=&quot;font: 18.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;b&gt;前言&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;在現在Linux的系統中，有一個新的虛擬檔案系統，叫做sysfs，它只要是來管理Linux系統中的週邊元件，及配合使用公用程式來自動產生device node。其實它是一個虛擬的記憶體檔案系統，它是由proc所變化而來的，它是由各個driver所產生，換另一句話就是要Driver有撰寫才會有這樣的功能，它是繼承kobject的資料結構，另外其檔名及內容都是driver自行解決，目前主要都是來設定driver自己本身的一些功能，這樣可以讓驅動程式更多元化，或者可以讀取驅動程式現在的情形為何，這可以來維護系統的運作，現在有很多驅動程式已經支援這個功能，所以有許多的系統管理程式，也是透過這個介面來管理系統核心。現在我們來介紹如何在driver中撰這些程式碼。&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 18.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;b&gt;如何啓動這個目錄&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;因為它是一個虛擬的記憶體檔案系統，所以將使用Linux系統中管理檔案系統一樣的方法，就是使用mount的指令將其掛載在作業系統的檔案系統中，以下為單獨載入的指令：&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;color: #1f497d; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;b&gt;&amp;gt; mount&amp;nbsp; –t&amp;nbsp; sysfs&amp;nbsp; sysfs&amp;nbsp; /sys&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 10.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 12.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;另外在kernel的選項中必須要啓動以下選項：&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;color: #1f497d; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;b&gt;CONFIG_SYSFS=y&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 18.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;b&gt;系統驅動程式結構&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;我們先來了解一下linux kernel其中驅動程式的結構，在linux kernel的驅動程式中會將各種元件給予分門別類，並且在各種類別中會給予建構一個管理層的驅動程式，其主要目的是要建立和應用程式之間的標準介面，並且管理相同類別中的各家不同的硬體廠商，如此一來即可規範硬體廠商如何撰寫廠商，避免因不同的廠商而產生不同的驅動程式的撰寫格式不同，或者造成應用程式的介面，進而造成使用者因不同的廠商而要修改軟體。其架構圖如下：&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2to7t1Rqxj5m2H3XSMnNbehQ_YIrGliPn3PCfVTjqceZe5kQY_wj4nP5dPLvmqJ1O4uxU5KHouTM4xvzTXQaP4ZXFiGhaS18g5YPP3ZvSEHV_6e-S6deV96N8eLi8lOfbo-C8UdwfxpRC/s1600/sysfsdriver.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;167&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2to7t1Rqxj5m2H3XSMnNbehQ_YIrGliPn3PCfVTjqceZe5kQY_wj4nP5dPLvmqJ1O4uxU5KHouTM4xvzTXQaP4ZXFiGhaS18g5YPP3ZvSEHV_6e-S6deV96N8eLi8lOfbo-C8UdwfxpRC/s320/sysfsdriver.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; text-align: center;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;圖一：驅動程式系統架構&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;以圖一中來看將會有一個RTC class產生，它將會統籌管理系統中所有的RTC元件，而系統中所有的RTC將會和它來做一個註冊，如此會產生一個RTC的class及其底下的RTC0, RTC1 ….. RTCn，其會在/sys/class之下會建立一個RTC的目錄，而每一個註冊的RTC元件將會在RTC class目錄之下產生RTC0至RTCn的子目錄，而每一個子目錄將會各別產生或者說是繼承RTC class的各個檔案。&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 18.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;b&gt;Kernel API&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;在介紹如何撰寫前，先來了解有那些kernel API可供使用，其所用的include file是&lt;linux/device.h&gt;，而API如下：&lt;/linux/device.h&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;color: #548dd4; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 18.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;b&gt;struct class *class_create(struct module *owner, const char *name)&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;這是建立一個模組的類別，其input/output說明如下：&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;color: #fd1e13; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;b&gt;Input :&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;struct module *owner – 模組的擁有者，通常是設定為&lt;/span&gt;&lt;b&gt;THIS_MODULE&lt;/b&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;。&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;const char *name –要建立之類別名稱，之後可以建立在這個類別之下的檔案。&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;color: #fd1e13; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;b&gt;Output :&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;其返回值為一個class資料結構的位址point，這個資料結構會在後面介紹，這個point位址將會給予保留，因為我們需要在其中幾個call back欄位填入我們要實現的功能，也就是提供給AP如何溝通的介面。&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;color: #548dd4; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;b&gt;extern struct device *device_create(struct class *cls, struct device *parent, dev_t devt, void *drvdata, const char *fmt, ...) __attribute__((format(printf, 5, 6)));&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;color: #548dd4; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;b&gt;#define device_create_drvdata &amp;nbsp; device_create&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp;這是在該類別之下建立一個週邊元件，也就是建立一個device。&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;color: #fd1e13; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;b&gt;Input :&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;struct class *cls – 是前一個API所return回來的class pointer。&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;struct devuce *parent – 為該元件的上一層driver為何若没有可以設定為NULL。&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;dev_t devt – 這是該元件的major number &amp;amp; minor number的結合，可以使用巨集指令MKDEV()來產生。&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;const char *fmt – 為該元件的device node名稱。&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;color: #fd1e13; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;b&gt;Output :&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;其返回值為一個device的資料結構，可讓driver其它地方使用。&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 18.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;b&gt;資料結構&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;如前面所提，其中最重要的資料結構宣告如下：&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;struct class {&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; const char&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; *name;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; struct module &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; *owner;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; struct class_attribute&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; *class_attrs;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;color: #fd1e13; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;letter-spacing: 0px;&quot;&gt;struct device_attribute &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; *dev_attrs;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; struct kobject&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; *dev_kobj;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int (*dev_uevent)(struct device *dev, struct kobj_uevent_env *env);&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; void (*class_release)(struct class *class);&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; void (*dev_release)(struct device *dev);&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int (*suspend)(struct device *dev, pm_message_t state);&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int (*resume)(struct device *dev);&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; struct pm_ops *pm;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; struct class_private *p;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;};&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;其中的成員struct device_attribute *dev_attrs; 是比較重要，這是設定在這類別之下所建立的元件都會繼承這些基設定，而每一個設都可以設定為唯讀或可讀寫，可以參考以下範例得到較清楚的解答。&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 18.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;b&gt;範例程式&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;#include &amp;lt;linux/kernel.h&amp;gt;&lt;linux/kernel.h&gt;&lt;/linux/kernel.h&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;#include &amp;lt;linux/module.h&amp;gt;&lt;linux/module.h&gt;&lt;/linux/module.h&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;#include &amp;lt;linux/spinlock.h&amp;gt;&lt;linux/spinlock.h&gt;&lt;/linux/spinlock.h&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;#include &amp;lt;linux/mutex.h&amp;gt;&lt;linux/mutex.h&gt;&lt;/linux/mutex.h&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;#include &amp;lt;linux/tty.h&amp;gt;&lt;linux/tty.h&gt;&lt;/linux/tty.h&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;#include &amp;lt;linux/proc_fs.h&amp;gt;&lt;linux/proc_fs.h&gt;&lt;/linux/proc_fs.h&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;#include &amp;lt;linux/timer.h&amp;gt;&lt;linux/timer.h&gt;&lt;/linux/timer.h&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;#include &amp;lt;linux/sysfs.h&amp;gt;&lt;linux/sysfs.h&gt;&lt;/linux/sysfs.h&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;#include &amp;lt;linux/device.h&amp;gt;&lt;linux/device.h&gt;&lt;/linux/device.h&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;#include &amp;lt;linux/platform_device.h&amp;gt;&lt;linux/platform_device.h&gt;&lt;/linux/platform_device.h&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;#include &amp;lt;asm/uaccess.h&amp;gt;&lt;asm/uaccess.h&gt;&lt;/asm/uaccess.h&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;#define VICTOR_DEBUG&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;#include &quot;../include/mydebug.h&quot;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;#define MY_MAJOR&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 40&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;struct class&amp;nbsp; &amp;nbsp; *sysfs_class;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;static ssize_t&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;sysfs_show_name(struct device *dev, struct device_attribute *attr, char *buf)&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return sprintf(buf, &quot;show name\n&quot;);&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;static ssize_t&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;sysfs_show_date(struct device *dev, struct device_attribute *attr, char *buf)&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ssize_t retval;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; retval = sprintf(buf, &quot;show date\n&quot;);&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return retval;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;color: #fd1e13; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;/*&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;color: #fd1e13; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;這是一個讀取的call back function，必需返回共有多少的bytes放在buffer中。&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;color: #fd1e13; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;*/&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;static ssize_t&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;sysfs_show_time(struct device *dev, struct device_attribute *attr, char *buf)&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ssize_t retval;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; retval = sprintf(buf, &quot;show time\n&quot;);&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return retval;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;static ssize_t&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;sysfs_show_max_user_freq(struct device *dev, struct device_attribute *attr, char *buf)&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return sprintf(buf, &quot;show max user freq\n&quot;);&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;color: #fd1e13; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;/*&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;color: #fd1e13; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;這是一個寫入的call back functio，一樣必需返回共有多少bytes被處理。&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;color: #fd1e13; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;*/&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;static ssize_t&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;sysfs_set_max_user_freq(struct device *dev, struct device_attribute *attr, const char *buf, size_t n)&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; printk(&quot;get string = %s\n&quot;, buf);&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return n;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;color: #fd1e13; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;/*&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;color: #fd1e13; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;以下設定中，S_IRUGO表示唯讀而己，S_IWUR表示可以寫入，而相對應的call back function必需要實現，其定義在linux/stat.h之。&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;color: #fd1e13; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;*/&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;static struct device_attribute sysfs_attrs[] = {&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; __ATTR(name, S_IRUGO, sysfs_show_name, NULL),&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; __ATTR(date, S_IRUGO, sysfs_show_date, NULL),&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; __ATTR(time, S_IRUGO, sysfs_show_time, NULL),&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; __ATTR(max_user_freq, S_IRUGO | S_IWUSR, sysfs_show_max_user_freq, sysfs_set_max_user_freq),&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; { },&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;};&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;static int sysfs_suspend(struct device *dev, pm_message_t mesg)&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; dbg_printk(&quot;\n&quot;);&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return 0;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;static int sysfs_resume(struct device *dev)&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; dbg_printk(&quot;\n&quot;);&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return 0;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;static int&amp;nbsp; &amp;nbsp; &amp;nbsp; __init mysysfs_init(void)&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; dbg_printk(&quot;\n&quot;);&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; sysfs_class = class_create(THIS_MODULE, &quot;mysysfs&quot;);&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (IS_ERR(sysfs_class)) {&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; printk(KERN_ERR &quot;%s: couldn&#39;t create class\n&quot;, __FILE__);&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return PTR_ERR(sysfs_class);&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; dbg_printk(&quot;class create OK.\n&quot;);&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; sysfs_class-&amp;gt;suspend = sysfs_suspend;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; sysfs_class-&amp;gt;resume = sysfs_resume;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; sysfs_class-&amp;gt;dev_attrs = sysfs_attrs;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; device_create_drvdata(sysfs_class, NULL, MKDEV(200, 0), NULL, &quot;mysysfs0&quot;);&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return 0;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;static void &amp;nbsp; &amp;nbsp; __exit mysysfs_exit(void)&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; dbg_printk(&quot;\n&quot;);&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; device_destroy(sysfs_class, MKDEV(200, 0));&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; class_destroy(sysfs_class);&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;module_init(mysysfs_init);&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0px;&quot;&gt;module_exit(mysysfs_exit);&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://victoryuembeddedlinux.blogspot.com/feeds/7064789115577163471/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://victoryuembeddedlinux.blogspot.com/2011/04/driversysfs.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6198249661133467553/posts/default/7064789115577163471'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6198249661133467553/posts/default/7064789115577163471'/><link rel='alternate' type='text/html' href='http://victoryuembeddedlinux.blogspot.com/2011/04/driversysfs.html' title='如何撰寫Driver支援sysfs檔案系統'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2to7t1Rqxj5m2H3XSMnNbehQ_YIrGliPn3PCfVTjqceZe5kQY_wj4nP5dPLvmqJ1O4uxU5KHouTM4xvzTXQaP4ZXFiGhaS18g5YPP3ZvSEHV_6e-S6deV96N8eLi8lOfbo-C8UdwfxpRC/s72-c/sysfsdriver.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6198249661133467553.post-5781594868357346547</id><published>2011-04-06T22:32:00.000+08:00</published><updated>2011-04-06T22:32:21.452+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="kernel driver"/><title type='text'>如何撰寫Driver支援proc檔案系統</title><content type='html'>&lt;div style=&quot;font: 18.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;b&gt;前言&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;在Linux的系統中，通常我們都會有一個目錄 – proc，其實它是一個虛擬的記憶體檔案系統，它通常是一個應用程式和kernel直接溝通的一個介面，它是由各個driver所產生，換另一句話就是要Driver有撰寫才會有這樣的功能，另外其檔名及內容都是driver自行解決，目前主要都是來設定driver自己本身的一些功能，這樣可以讓驅動程式更多元化，或者可以讀取驅動程式現在的情形為何，這可以來維護系統的運作，現在有很多驅動程式已經支援這個功能，所以有許多的系統管理程式，也是透過這個介面來管理系統核心。現在我們來介紹如何在driver中撰這些程式碼。&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 18.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;b&gt;如何啓動這個目錄&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;因為它是一個虛擬的記憶體檔案系統，所以將使用Linux系統中管理檔案系統一樣的方法，就是使用mount的指令將其掛載在作業系統的檔案系統中，以下為單獨載入的指令：&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;color: #1f497d; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px color: #000000;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;b&gt;&amp;gt; mount –t proc proc /porc&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 10.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 12.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;另外在kernel的選項中必須要啓動以下選項：&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;color: #1f497d; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px color: #000000;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;b&gt;CONFIG_PROC_FS=y&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;color: #1f497d; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;CONFIG_PROC_SYSCTL=y&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 18.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;b&gt;Kernel API&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;在介紹如何撰寫前，先來了解有那些kernel API可供使用，其所用的include file是&lt;linux/proc_fs.h&gt;，而API如下：&lt;/linux/proc_fs.h&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;color: #548dd4; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;b&gt;struct proc_dir_entry *create_proc_entry(const char *name, mode_t mode, struct proc_dir_entry *parent)&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;這是建立一個在相對目錄之下的一個檔名或目錄，其input/output說明如下：&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;color: #fd1e13; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px color: #000000;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;b&gt;Input :&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;const char *name – 想要建立的檔名，相對於後面的parent的目錄之下，若後面的parent為NULL，則其相對目錄為/proc之下，另外這個檔名也可以包含目錄。&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;mode_t mode – 前面所要建立之名稱為檔案或者是目錄，0為檔案，S_IFDIR為目錄。&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;struct proc_dir_entry *parent – 這次要建立的檔名或者目錄，其上層的目錄為何，若這個參數為NULL則表示為/proc目錄。&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;color: #fd1e13; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px color: #000000;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;b&gt;Output :&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;其返回值為一個資料結構的位址point，這個資料結構會在後面介紹，這個point位址將會給予保留，因為我們需要在其中幾個call back欄位填入我們要實現的功能，也就是提供給AP如何溝通的介面。&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;color: #548dd4; font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;b&gt;void remove_proc_entry(const char *name, struct proc_dir_entry *parent);&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;這是移除已建立的檔案或目錄，其中輸入的參數皆和建立時相同。&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;以下為一個簡單的範例：&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;struct proc_dir_entry&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;*MyProcEntry;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;MyProcEntry = create_proc_entry(“driver/myproc”, 0, NULL);&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;MyProcEntry-&amp;gt;read = MyProcRead;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;MyProcEntry-&amp;gt;write = MyProcWrite;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;……………………………….&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;remove_proc_entry(“driver/myproc”, NULL);&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 18.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;b&gt;資料結構&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;如前面所提，其中最重要的資料結構宣告如下：&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;struct proc_dir_entry {&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; unsigned int low_ino;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; unsigned short namelen;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; const char *name;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mode_t mode;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; nlink_t nlink;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; uid_t uid;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; gid_t gid;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; loff_t size;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; const struct inode_operations *proc_iops;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; /*&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; * NULL -&amp;gt;proc_fops means &quot;PDE is going away RSN&quot; or&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; * &quot;PDE is just created&quot;. In either case, e.g. -&amp;gt;read_proc won&#39;t be&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; * called because it&#39;s too late or too early, respectively.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; *&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; * If you&#39;re allocating -&amp;gt;proc_fops dynamically, save a pointer&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; * somewhere.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; */&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; const struct file_operations *proc_fops;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; struct proc_dir_entry *next, *parent, *subdir;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; void *data;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; read_proc_t *read_proc;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; write_proc_t *write_proc;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; atomic_t count; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; /* use count */&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int pde_users;&amp;nbsp; /* number of callers into module in progress */&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; struct completion *pde_unload_completion;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; struct list_head pde_openers; &amp;nbsp; /* who did -&amp;gt;open, but not -&amp;gt;release */&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;};&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;在這個資料結構中有兩個重要的call back function，一個是read_proc，另一個是write_proc，其實就是寫入及讀出。以下為其簡單的範例：&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;static int&amp;nbsp; &amp;nbsp; &amp;nbsp; my_read_proc(char *page, char **start, off_t off, int count, int *eof, void *data)&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; char&amp;nbsp; &amp;nbsp; *out = page;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int &amp;nbsp; &amp;nbsp; len;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; dbg_printk(&quot;page=0x%p,off=0x%x,count=%d\n&quot;, page, off, count);&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; out += sprintf(out, &quot;This is a read proc testing.\n&quot;);&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; dbg_printk(&quot;out=0x%p\n&quot;, out);&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; len = out - page - off;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; dbg_printk(&quot;len=%d,out=0x%p\n&quot;, len, out);&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (len &amp;lt; count)&amp;nbsp; {&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; *eof = 1;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (len &amp;lt;= 0)&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return 0;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&amp;nbsp; else&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; len = count;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; *start = page + off;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; dbg_printk(&quot;start=0x%p\n&quot;, start);&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return len;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;static int&amp;nbsp; &amp;nbsp; &amp;nbsp; my_write_proc(struct file *file, const char __user *buffer, unsigned long count, void *data)&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; char&amp;nbsp; &amp;nbsp; *buf;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; dbg_printk(&quot;count=%d\n&quot;, count);&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; buf = kmalloc(count+1, GFP_KERNEL);&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if ( copy_from_user(buf, (char*)buffer , count) ) {&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; kfree(buf);&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return -EFAULT;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; buf[count] = 0;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; dbg_printk(&quot;string=%s\n&quot;, buf);&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; kfree(buf);&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return count;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px; min-height: 15.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font: 12.0px &#39;Lucida Grande&#39;; margin: 0.0px 0.0px 0.0px 0.0px;&quot;&gt;&lt;span style=&quot;letter-spacing: 0.0px;&quot;&gt;在read call back function中所傳入的page為要存放輸出內容的buffer所在page address，其off為相對於page的offset位置，通常為0，不管read or write其所return的值為實際處理的大小，因為其處理方式為page的方式，所以一次可處理的資料不會大於一個page的大小，現在default值為4096bytes，以上的範例若是成功將可以產生一個虛擬檔案/proc/driver/myproc，你將可以使用簡單的echo &amp;amp; cat來對其做讀寫的動作。&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://victoryuembeddedlinux.blogspot.com/feeds/5781594868357346547/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://victoryuembeddedlinux.blogspot.com/2011/04/driverproc.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6198249661133467553/posts/default/5781594868357346547'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6198249661133467553/posts/default/5781594868357346547'/><link rel='alternate' type='text/html' href='http://victoryuembeddedlinux.blogspot.com/2011/04/driverproc.html' title='如何撰寫Driver支援proc檔案系統'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6198249661133467553.post-5452518440586346695</id><published>2011-03-03T23:27:00.000+08:00</published><updated>2011-03-07T00:00:06.633+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="kernel driver pci host client"/><title type='text'>如何撰寫ARM CPU的Linux PCI Host 驅動程式</title><content type='html'>&lt;p style=&quot;MARGIN: 0px; FONT: 18px &#39;Heiti TC Light&#39;color:#000219;&quot; &gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;   style=&quot;font-family:arial;font-size:180%;&quot;&gt;簡介&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;是一種&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;BUS&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;，它可以讓你擴充週邊元件的一種&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;BUS&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;，在&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PC&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;上使用非常普遍，因為它是一個共同的標準介面，所以它可以讓很多的週邊元件附加在這個電腦上，而且可以很容易地附加進來，雖然現在的嵌入式系統已經把很多的週邊已&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;SoC&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;在&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;CPU&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;裏面，可是有時候在成本的考量，由&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;來擴充週邊，就不會有必須要的現象產生，因為他可以選擇，這樣就不會造成&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;SoC&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;的&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;CPU&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;成本過高，另外把過多的週邊元件&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;SoC&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;會造成&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;CPU&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;用電過高，更進而造成過熱現象產生，造成必需使用其它的煽熱元件，如鋁片或者風扇等，這會造成產品體積變大，成本增加，等問題產生。&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;的另一個好處是它是一個&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PNP&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;的&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;BUS&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;，對資源的分配及取得是較有彈性，如此一來對軟體撰寫者也是一大好處，因為這樣一來軟體較容易移植至各個不同的&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;CPU&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;平台，而不需要因為不同的&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;CPU&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;而撰寫不同的程式。&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span style=&quot;font-size:180%;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;b&gt;ARM&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 18px &#39;Heiti TC Light&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:x-large;&quot;&gt;和&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:x-large;&quot;&gt;x86&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 18px &#39;Heiti TC Light&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:x-large;&quot;&gt;的&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:x-large;&quot;&gt;PCI&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 18px &#39;Heiti TC Light&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:x-large;&quot;&gt;有何不同&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;以硬體來說是没有不同，因為它本來就是一種標準，那在軟體上有何不同？因為在&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;x86&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;上只有一種&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;CPU&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;，而且它的&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI Host&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;的&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;IC&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;都一樣，並不會因為不同的生產廠商而有所不同，也因此在&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI Host&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;的驅動程式都是&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;OS&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;廠商所撰寫好了，但是每家的&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;ARM CPU&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;廠商所生產的&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI Host&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;的控制器都不同，所以軟體人員必須各別撰寫，以應付不同的&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;CPU&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;廠商，也是為什麼我們必須要知道如何撰寫&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI Host&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;驅動程式。&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;另外&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;它是一種主從式架構，&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;host&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;端是由主機板廠商所負責，&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;x86&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;平台它通常會留下幾個標準的&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;slot&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;讓使用者可以購買其它的&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;client&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;的擴充卡來增加週邊元件，在&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;ARM base&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;的嵌入系統中，通常&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI Host&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;會是&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;SoC&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;在&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;CPU&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;內，對於&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;client&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;的元件，原則上不會是做成&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;slot&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;再插卡，通常是直接拉&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI Bus&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;的訊號線從&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI Host&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;至&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI client&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;，如此一來就可節省空間及成本。&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span style=&quot;font-size:180%;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;PCI Bus&lt;/span&gt;&lt;span style=&quot;FONT: 18px &#39;Heiti TC Light&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:x-large;&quot;&gt;開機順序&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI Bus&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;在開機程序中，開機時&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI Host&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;會先自我控制器做初始化程序，之後會將可分配及使用的資源和系統登錄，之後將掃描是否有&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI client&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;的週邊元件接上，若有則依照它們所要求的資源分配給它們，分配完之後則檢查是否有相對應的&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;client&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;端登錄驅動程式，若有則呼叫其所登錄的&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;call back function&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;，而這個&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;call back function&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;則是&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI client&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;的驅動程式所登錄，在這個&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;call back function&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;中通常所完成的事是初始化其元件，&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI host&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;將會逐一已插上的&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI client&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;重覆前面的動作，一直到所有已插上的週邊元件都完成分配資源。&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span style=&quot;font-size:180%;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;PCI Configuration Table&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;FONT: 12px &#39;Heiti TC Light&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;在&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI host&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Heiti TC Light&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;和&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI client&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Heiti TC Light&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;之間有一個表叫做&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;configuration table&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Heiti TC Light&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;，該表有&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;256&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Heiti TC Light&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;字元，它是做為&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;host&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Heiti TC Light&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;和&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;client&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Heiti TC Light&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;之間溝通資源分配及其資訊交換的表格，其內容如下：&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUcmudRCskyeThkWmBmNxcErrK6eEJDxD52UjHKSo3Yjm7duuAI2Vf1CXw2pq513269B_naJac_uz6BI-dk0pEQai2TdaWnVABIFeGZBoL5n0Ce2p88lLNsbnsEZBib7Kqt2NRTq3jHfka/s1600/p1.jpg&quot;&gt;&lt;img style=&quot;MARGIN: 0px 10px 10px 0px; WIDTH: 320px; FLOAT: left; HEIGHT: 275px; CURSOR: hand&quot; id=&quot;BLOGGER_PHOTO_ID_5580985421830207842&quot; border=&quot;0&quot; alt=&quot;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUcmudRCskyeThkWmBmNxcErrK6eEJDxD52UjHKSo3Yjm7duuAI2Vf1CXw2pq513269B_naJac_uz6BI-dk0pEQai2TdaWnVABIFeGZBoL5n0Ce2p88lLNsbnsEZBib7Kqt2NRTq3jHfka/s320/p1.jpg&quot; /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;FONT: 12px &#39;Heiti TC Light&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px Helvetica&quot;&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px Helvetica&quot;&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;以上所看到是我們較會用到的部分，這份表是存放在&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI client&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;上的，其中的幾個重要欄位說明如下：&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;ul&gt;&lt;li style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;Vendor ID &amp;amp; Device ID&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Heiti TC Light&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;是唯讀的，&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI host&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Heiti TC Light&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;將會把它存起來，&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI client&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Heiti TC Light&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;也是用這兩個&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;ID&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Heiti TC Light&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;來向&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;host&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Heiti TC Light&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;做註冊，&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;host&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Heiti TC Light&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;也會拿它來做比對，當前面所提要呼叫&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;client&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Heiti TC Light&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;端時才知道要呼叫那一個驅動程式。&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;command&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;則是&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;host&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;有些動作需要&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;client&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;端來做時所下的指令，而這些指令在&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;的標準有定義。&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;status&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;是目前&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;client&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;現狀的表示，也是&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;標準中有所定義。&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;Base Address Registers&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;是非常重要的項目，它是&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;client&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;和&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;host&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;端資源描述的地方，而且它是一個雙向溝通的資料，對&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;32&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;位元的設備來說則總共最多有&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;6&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;個資源可以取得，若是&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;64&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;位元的設備，則最多只有&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;3&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;個資源可以取得，其實做法很簡單，就是將兩個&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;32&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;位元合成一個&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;64&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;位元。在此我們只說明&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;32&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;位元的設備，因為目前&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;64&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;位元的嵌入式並不多見，在說明之前我們先了解一件事，就是當&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;CPU&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;和週邊做溝通有兩個路徑，一個是&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;I/O&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;存取，一個記憶體存取，這在硬體上有所差異，所以在這欄位使用最低的兩個位元來表示需求何種資源，以二進位來看，&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;00&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;代表是需要記憶，&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;01&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;代表是需要 &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;I&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;／&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;O&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;，所耍的大小從位元&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;2&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;開始，若不需要則填零，不然則填其所需的大小，當&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI Host&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;掃描之後會將該&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;client&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;週邊所分配到的起始位置填回，如此完成資源的分配。&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;COLOR: rgb(1,6,50);font-family:&#39;Lucida Grande&#39;;&quot; class=&quot;Apple-style-span&quot; &gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:x-large;&quot;&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:x-large;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;COLOR: rgb(1,6,50);font-family:&#39;Lucida Grande&#39;;&quot; class=&quot;Apple-style-span&quot; &gt;&lt;span style=&quot;font-size:180%;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;PCI Host&lt;/span&gt;&lt;span style=&quot;FONT: 18px &#39;Heiti TC Light&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:x-large;&quot;&gt;實做&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;在了解了&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI Bus&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;的基本定義之後我們開始要來談實做的部分，在&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI Host&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;部分，因為像前面所提的部分標準和硬硬體無關，或者另外的說法是硬體工作內容是一樣，因為這部分已由&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;GNU&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;所撰寫好，我們並不需要做任何更動，這部分的原始碼在&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;kernel source&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;的&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;drivers/pci&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;目錄之下，我們所要寫的是&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;HAL&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;部分，你必須在&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;arch/arm/mach-xxxx&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;的目錄之下（這個目錄是你在&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;porting&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;一個&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;SoC&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;時會建立的目錄，其中的&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;xxxx&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;是你自行定義的名稱），撰寫一個&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI Host&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;的一個&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;C&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;程式，而在這程式有幾個部分需要撰寫，首先需要宣告一個資料結構如下：&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;struct hw_pci ixdp425_pci __initdata = {&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;.nr_controllers&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;= 1,&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;.preinit&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;= ixdp425_pci_preinit,&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;.swizzle&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;= pci_std_swizzle,&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;.setup&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;= ixp4xx_setup,&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;.scan&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;= ixp4xx_scan_bus,&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;.map_irq&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;= ixdp425_map_irq,&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;};&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;先在此說明一下這個資料結構的定義，其資料結構原型為&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;struct hw_pci&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;，其定義在&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;arch/arm/mach/pci.h (&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;這是&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;kernel&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;版本&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;2.6.31&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;之後，&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;ixdp425_pci &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;是使用者自行取的名字，&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;__initdata&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;定義為這個資料在&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;kernel&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;初始化之後會給予&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;free&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;收回使用），其各個成員說明如下：&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;.nr_controllers&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;是指示有多少個&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI host&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;控制器，通常都是只有一個。&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;.preinit&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;FONT: 12px &#39;Heiti TC Light&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;這是在初始化該&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI host chipset&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Heiti TC Light&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;的&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;call back function&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Heiti TC Light&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;，這也是和各個&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;SoC&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Heiti TC Light&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;有所不&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;同，所要做的初始化內容也不盡相同， 當註冊一個&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI Host&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;時第一個被呼叫的副程式，&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;若有需要中斷的設定，必需要在此完成和系統註冊。&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;font-size:100%;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;.setup&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;FONT: 12px &#39;Heiti TC Light&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;它是一個&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;call back function pointer&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Heiti TC Light&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;，在這個副程式原型為&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;int ixp4xx_setup(int nr, &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;struct pci_sys_data *sys)&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Heiti TC Light&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;，所以系統會將第幾個&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI host controller - nr&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Heiti TC Light&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;以及一個指&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Heiti TC Light&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;標&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;struct pci_sys_data *sys&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Heiti TC Light&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;，在呼它時傳送給它，這個指標將會是需要填入這&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;Host controller&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Heiti TC Light&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;可以使用的資源，以下是一個範例：&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;struct resource *res;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;res = kzalloc(sizeof(*res) * 2, GFP_KERNEL);&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;res[0].name = &quot;PCI I/O Space&quot;;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;res[0].start = 0x00000000;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;res[0].end = 0x0000ffff;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;res[0].flags = IORESOURCE_IO;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;res[1].name = &quot;PCI Memory Space&quot;;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;res[1].start = 0x4b000000;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;res[1].end = 0x4bffffff;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;res[1].flags = IORESOURCE_MEM&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;request_resource(&amp;amp;ioport_resource, &amp;amp;res[0]);&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;request_resource(&amp;amp;iomem_resource, &amp;amp;res[1]);&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;sys-&gt;resource[0] = &amp;amp;res[0];&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;sys-&gt;resource[1] = &amp;amp;res[1];&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;sys-&gt;resource[2] = NULL;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;從以上的註冊系統將會保留所要的資源，而在之前所提的標準的&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI driver&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;會協助分配資&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;源給&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI client&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;，所以之後如何分配及管理這些資源，你就不用費心了。&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;.scan&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;這是系統要開始掃描在&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI Bus&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;有插上那些&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI client&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;時會呼叫的副程式，通常都會直&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;接再展轉呼叫系統的掃描程式，以下是其範例程式：&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;return pci_scan_bus(sys-&gt;busnr, &amp;amp;ixp4xx_ops, sys);&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;在以上的&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;sys&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;變數為系統傳過來的，&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;ixp4xx_ops&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;則是我們所要準備的一些有關&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI Bus&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Heiti TC Light&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;設定的一些&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;HAL call back function&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Heiti TC Light&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;，其內容為如下：&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;struct pci_ops ixp4xx_ops = {&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;.read = ixp4xx_pci_read_config,&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;.write = ixp4xx_pci_write_config,&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;};&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;FONT: 12px &#39;Heiti TC Light&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;上面其的&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;read/write&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Heiti TC Light&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;為在讀寫前面所談的&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;configuration table&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Heiti TC Light&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;的方式，這和每一個晶片&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;不同，其控制的位置也不同，所以根據每一顆&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;SoC&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;來寫，而這兩個的函數原型如下：&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;int ixp4xx_pci_read_config(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *value)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;int ixp4xx_pci_write_config(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 value)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;在系統呼叫進來的&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;bus&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;的資料結構中成員&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;bus-&gt;number&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;是這個系統中第幾個&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;bus&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;，在&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Heiti TC Light&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;控制晶片時可能會用到，&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;devfn&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Heiti TC Light&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;則是&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;slot number&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Heiti TC Light&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;和&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;function number&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Heiti TC Light&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;的結合，你可以&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Heiti TC Light&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;使用巨集指令&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI_SLOT()&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Heiti TC Light&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;或&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI_FUNC()&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Heiti TC Light&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;分別取得其資訊，&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;size&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Heiti TC Light&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;則是表示&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;1 or 2 or 4 &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;bytes&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Heiti TC Light&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;的存取，&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;where&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Heiti TC Light&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;則是需要特別注意，它是在存取&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;1 or 2 bytes&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Heiti TC Light&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;會用到，在&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;256 &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;bytes&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Heiti TC Light&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;的&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;configuration table&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Heiti TC Light&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;的相對位置，大部分&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI host &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Heiti TC Light&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;控制器會有&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;boundary&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;存取的問題，這邊需要特別注意做轉換，&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;value&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;則是較簡單，是讀取或寫入所&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;放的值。&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;.map_irq&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;則是當&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI Host&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;在掃描時在要指定&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;IRQ&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;時會呼叫這個副程式，而這個副程式則會回傳要&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;指定的中斷號碼。&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;當以上的資料準備好之後，你需要撰寫一個初始化的進入點，讓系統開機會呼叫這個初始&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;化副程式，以下為其範例：&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;int __init ixdp425_pci_init(void)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;{&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;return pci_common_init(&amp;amp;ixdp425_pci);&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;subsys_initcall(ixdp425_pci_init);&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;font-size:100%;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;由以上的程式碼可以看到，該程式會直接呼叫系統的&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;pci_common_init()&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;而且給它前面所&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;提的資料結構，當你呼叫該系統程式時，系統會馬上呼叫你所給的資料結構中的&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;preinit &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;call back function&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Heiti TC Light&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;，之後會呼叫&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;setup call back function&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Heiti TC Light&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;，再接著就是呼叫&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;scan call &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;back function&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;，如此而完成一個&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI host&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;的載入動作，以下用流程圖來表示如下：&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;font-size:100%;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjqOMhzR02H13kSdNi_kIzX1cyO60-7Nw5LVo3zsreDoWKE2zEOT9jKm7ElBLtfqdnj6XDtUW87WNSRKyop4EsaPDlT_btYRwmpdeeB2OgAqiW7Jt41Cs8KVNvZGhqFozqlvtQ24bmn3UL/s1600/p2.jpg&quot;&gt;&lt;img style=&quot;MARGIN: 0px 10px 10px 0px; WIDTH: 320px; FLOAT: left; HEIGHT: 222px; CURSOR: hand&quot; id=&quot;BLOGGER_PHOTO_ID_5580985424632909506&quot; border=&quot;0&quot; alt=&quot;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjqOMhzR02H13kSdNi_kIzX1cyO60-7Nw5LVo3zsreDoWKE2zEOT9jKm7ElBLtfqdnj6XDtUW87WNSRKyop4EsaPDlT_btYRwmpdeeB2OgAqiW7Jt41Cs8KVNvZGhqFozqlvtQ24bmn3UL/s320/p2.jpg&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px Helvetica&quot;&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt; &lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt; &lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt; &lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt; &lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt; &lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt; &lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt; &lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt; &lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt; &lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt; &lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;最後記得用巨集指令&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;subsys_initcall()&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;將你所完成的副程式註冊為一個開機會被呼叫的副程式。&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span style=&quot;font-size:180%;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;PCI Host&lt;/span&gt;&lt;span style=&quot;FONT: 18px &#39;Heiti TC Light&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:x-large;&quot;&gt;需要注意的地方&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;原則上在以上所說明的應該就完成了&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI Host&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;的移植，因為我們在移植時只要完成這部分會和硬體有關的 &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;HAL &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;層即可，但是還是有一些地方必需要注意，第一個就是在&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;x86&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;的平台上是有所謂的&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;I/O&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;存取，我是指&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;CPU&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;本身就有這個支援，&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;CPU&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;對週邊的元件的存取方式，本來就有兩種，一種是記憶體存取，一種是&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;I/O&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;存取，而在&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI bus&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;也有這兩種的存取方式，所以這兩種不同的存取方法，被視為兩種不同的資源，但是在&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;ARM CPU&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;中是没有&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;I/O &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;存取的，它只有記憶體存取，而我們在寫驅動程式時若是&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;I/O&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;存取則會使用&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;inb(), oub(), inw(), outw(), inl(), outl()&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;等副程式，若是記憶體存取則會使用&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;readb(), writeb(), readw(), writew(), readl(), writel()&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;等副程式，因為&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;ARM CPU&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;沒有&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;I/O &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;存取所以在&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;HAL&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;層會將&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;inx(), outx()&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;等副程式內容改寫，改成使用記憶體存取，如此一來應是沒有任何問題才對，問題在於對於&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;I/O&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;存取的驅動程式，對於所使的資源&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;也就所分配到的&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;I/O &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;位置&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;不會將其轉換為虛擬位址，可是如此一來將會產生非法存取記憶體位置，因為&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;kernel&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;一啓動所有的程式碼都需要使用虛擬位址，對於這個問題有幾個解決方法，第一個是修改&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI client&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;的驅動程式碼，可是這會有一個缺點，那就是這個原始碼必需只能使用在你的&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;ARM&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;平台，其它如&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;x86&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;的平台將無法使用，另外你也必需修改你的驅動程式，所以個人比較不喜歡這個方式，另一個方式則是修改我的&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI host&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;的資源分配，很簡單的做法，就是前面有提到在初始化時需要將可分配的資源向系統註冊，註冊前先將其轉換為虛擬位址，再向系統註冊就可以了，如此的修改不多，又沒有前一個方法的問題，並且前面已說明我們本來就是需要修改&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI host&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;的程式碼。&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;同樣是存取方式的問題，我們先看以下的表示圖，再來討論這個問題：&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEil96ulPeR2_XbfOCINUB5vWQEu1jdpvxlZFeHGduizuZ8fz4HtRTgsuZTdXH2y8FYv8qquI23nAFsH7nunv3aDYHHKh7K6tfpqomQ_UL-n3BWme8og9JWs1zo5JHYIje68kP1A9P00XEwM/s1600/p3.jpg&quot;&gt;&lt;img style=&quot;MARGIN: 0px 10px 10px 0px; WIDTH: 320px; FLOAT: left; HEIGHT: 137px; CURSOR: hand&quot; id=&quot;BLOGGER_PHOTO_ID_5580985429248132178&quot; border=&quot;0&quot; alt=&quot;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEil96ulPeR2_XbfOCINUB5vWQEu1jdpvxlZFeHGduizuZ8fz4HtRTgsuZTdXH2y8FYv8qquI23nAFsH7nunv3aDYHHKh7K6tfpqomQ_UL-n3BWme8og9JWs1zo5JHYIje68kP1A9P00XEwM/s320/p3.jpg&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px Helvetica&quot;&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;因為&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;ARM CPU&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;只有記憶體存取的方式，而&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI bus&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;卻有兩種（記憶體和&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;I/O&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;的存取方式），另外&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI host&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;的晶片有兩種，一種是它本身對&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI bus&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;的兩種不同存取方式會做自動的轉換，意思對於&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI client&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;是使用&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;I/O&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;存取方式的週邊，它會自動將&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;ARM CPU&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;過來的記憶體存取方式，自動轉換為&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;I/O&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;存取方式，所以對於前面所提的第二種&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;I/O&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;存取方式的修改將可以達成，而對於&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;ARM CPU&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;的記憶體存取方式，則可以直接轉換至&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI bus&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;即可，對於這種&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI Host&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;的晶片可以省卻我們很多工夫。但是有另外一種&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI host&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;晶片是不會如此做的，對於這種晶片則是較麻煩的，對於這種晶片你必須控其中的一些暫存器在&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI bus&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;上做出&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;I/O &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;存取的訊號，以下則是其寫法說明（這是在&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;2.6.31&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;之後的寫法）：&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;首先你必須在&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;arch/arm/mach-xxxx&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;的目錄之下，建立一個檔案&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;include/mach/io.h&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;，請注意其路徑及檔名不可更改，因為在整個&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;kernel &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;原始碼中的&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;Makefile&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;及編譯時要尋找&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;C&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;語言的&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;include file&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;路徑都已寫好，你若更改將會造成編譯錯誤，在這個檔案之中將可以改寫&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;ARM CPU&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;已內定改好的&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;inx()&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;及&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;outx()&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;的副程式，若你在這個檔案之中宣告如下：&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;#define&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;__io(v)&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;__typesafe_io(v)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;font-size:100%;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;表示使用&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;ARM CPU&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;中己改好的&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;inx()&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;及&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;outx()&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;副程式，這是使用&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI host&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;會自動轉換&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;I/O &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;存取至&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI bus&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;的晶片，若不是你所需要的修改如下：&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;font-size:100%;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt; &lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;#define&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;outb(p, v)&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;__ixp4xx_outb(p, v)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;#define&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;outw(p, v)&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;__ixp4xx_outw(p, v)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;#define&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;outl(p, v)&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;__ixp4xx_outl(p, v)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;#define&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;outsb(p, v, l)&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;__ixp4xx_outsb(p, v, l)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;#define&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;outsw(p, v, l)&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;__ixp4xx_outsw(p, v, l)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;#define&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;outsl(p, v, l)&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;__ixp4xx_outsl(p, v, l)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;#define&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;inb(p)&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;__ixp4xx_inb(p)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;#define&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;inw(p)&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;__ixp4xx_inw(p)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;#define&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;inl(p)&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;__ixp4xx_inl(p)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;#define&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;insb(p, v, l)&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;__ixp4xx_insb(p, v, l)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;#define&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;insw(p, v, l)&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;__ixp4xx_insw(p, v, l)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;#define&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;insl(p, v, l)&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;__ixp4xx_insl(p, v, l)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;font-size:100%;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;你必需針對每一個副給予重新定義至另一個你改寫的內容，而這些改寫的內容則是針對你所使用的&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI host&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;晶片做控制，以下為其範例：&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;font-size:100%;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;div&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;static inline void &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;__ixp4xx_outb(u8 value, u32 addr)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;{&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;u32 n, byte_enables, data;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;n = addr % 4;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;byte_enables = (0xf &amp;amp; ~BIT(n)) &amp;lt;&amp;lt; IXP4XX_PCI_NP_CBE_BESL;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;..........................&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;return data &amp;gt;&amp;gt; (8*n);&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;.................................&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;另外幾個和&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;I/O&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;有關的副程式你也必需重新改寫如下：&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;font-size:100%;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;#define&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;ioread8(p)&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;__ixp4xx_ioread8(p)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;#define&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;ioread16(p)&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;__ixp4xx_ioread16(p)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;#define&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;ioread32(p)&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;__ixp4xx_ioread32(p)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;#define&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;ioread8_rep(p, v, c)&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;__ixp4xx_ioread8_rep(p, v, c)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;#define&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;ioread16_rep(p, v, c)&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;__ixp4xx_ioread16_rep(p, v, c)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;#define&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;ioread32_rep(p, v, c)&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;__ixp4xx_ioread32_rep(p, v, c)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;#define&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;iowrite8(v,p)&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;__ixp4xx_iowrite8(v,p)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;#define&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;iowrite16(v,p)&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;__ixp4xx_iowrite16(v,p)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;#define&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;iowrite32(v,p)&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;__ixp4xx_iowrite32(v,p)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;#define&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;iowrite8_rep(p, v, c)&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;__ixp4xx_iowrite8_rep(p, v, c)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;#define&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;iowrite16_rep(p, v, c)&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;__ixp4xx_iowrite16_rep(p, v, c)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;#define&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;iowrite32_rep(p, v, c)&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;__ixp4xx_iowrite32_rep(p, v, c)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;#define&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;ioport_map(port, nr)&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;((void __iomem*)(port + PIO_OFFSET))&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;#define&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;ioport_unmap(addr)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;#define PIO_OFFSET 0x10000UL&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;#define PIO_MASK 0x0ffffUL&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;#define&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;__is_io_address(p)&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;(((unsigned long)p &gt;= PIO_OFFSET) &amp;amp;&amp;amp; \&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;((unsigned long)p &lt;= (PIO_MASK + PIO_OFFSET)))&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;font-size:100%;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;static inline unsigned int&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;__ixp4xx_ioread8(const void __iomem *addr)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;{&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;unsigned long port = (unsigned long __force)addr;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;if (__is_io_address(port))&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;(unsigned int)__ixp4xx_inb(port &amp;amp; PIO_MASK);&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;else&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;return (unsigned int)__ixp4xx_readb(addr);&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;..........................................&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;static inline void&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;__ixp4xx_iowrite8(u8 value, void __iomem *addr)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;{&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;unsigned long port = (unsigned long __force)addr;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;if (__is_io_address(port))&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;__ixp4xx_outb(value, port &amp;amp; PIO_MASK);&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;else&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;__ixp4xx_writeb(value, addr);&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;....................................&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;除此之外有些&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI host&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;的晶片對於&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;ARM CPU&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;的記憶體存取方式也不會直接自動轉換至&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI bus&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;，和&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;I/O&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;存取一樣必須控制&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI host&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;晶片來產生一個&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI bus&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;上的記憶體存取，其改寫內容和&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;I/O&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;改寫很像，一樣的你若不需要改寫，使用&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;ARM CPU&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;內定的程式碼則必需有一個以下的宣告：&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;#define __mem_pci(a)&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;(a)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;font-size:100%;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;若要改寫以下為其範例：&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;#define&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;writeb(v, p)&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;__ixp4xx_writeb(v, p)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;#define&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;writew(v, p)&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;__ixp4xx_writew(v, p)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;#define&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;writel(v, p)&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;__ixp4xx_writel(v, p)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;#define&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;writesb(p, v, l)&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;__ixp4xx_writesb(p, v, l)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;#define&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;writesw(p, v, l)&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;__ixp4xx_writesw(p, v, l)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;#define&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;writesl(p, v, l)&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;__ixp4xx_writesl(p, v, l)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;#define&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;readb(p)&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;__ixp4xx_readb(p)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;#define&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;readw(p)&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;__ixp4xx_readw(p)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;#define&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;readl(p)&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;__ixp4xx_readl(p)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;#define&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;readsb(p, v, l)&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;__ixp4xx_readsb(p, v, l)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;#define&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;readsw(p, v, l)&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;__ixp4xx_readsw(p, v, l)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;#define&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;readsl(p, v, l)&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;__ixp4xx_readsl(p, v, l)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;static inline void &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;__ixp4xx_writeb(u8 value, volatile void __iomem *p)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;{&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;....................................&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;if (addr &gt;= VMALLOC_START) {&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;__raw_writeb(value, addr);&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;return;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;.............................&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;....................................&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;/*&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;* We can use the built-in functions b/c they end up calling writeb/readb&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;*/&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;#define memset_io(c,v,l)&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;_memset_io((c),(v),(l))&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;#define memcpy_fromio(a,c,l)&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;_memcpy_fromio((a),(c),(l))&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;#define memcpy_toio(c,a,l)&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;_memcpy_toio((c),(a),(l))&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;最後有一個問題需要注意的是，通常對於使用記憶體存取的使用之前，做一個實體記憶體轉換為虛擬位址，若你的&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI host&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;是前面的方式需要使用&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI host&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;來產生一個存取動作，那麼你可以也需要改寫&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;ioremap() &amp;amp; iounmap()&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;的副程式，其範例程式如下：&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;static inline void __iomem *&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;__ixp4xx_ioremap(unsigned long addr, size_t size, unsigned int mtype)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;{&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;if((addr &lt;&gt; 0x4fffffff))&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;return __arm_ioremap(addr, size, mtype);&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;return (void __iomem *)addr;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;static inline void&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;__ixp4xx_iounmap(void __iomem *addr)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;{&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;if ((__force u32)addr &gt;= VMALLOC_START)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;__iounmap(addr);&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;#define __arch_ioremap(a, s, f)&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;__ixp4xx_ioremap(a, s, f)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;#define&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;__arch_iounmap(a)&lt;/span&gt;&lt;span style=&quot;WHITE-SPACE: pre&quot; class=&quot;Apple-tab-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;__ixp4xx_iounmap(a)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Lucida Grande&#39;&quot;&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Heiti TC Light&#39;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;至此你應可以完成你的&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI Host&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;的程式，而且可以讓你的&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI client&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;的程式更有相容性，而可以使用在多種&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;CPU&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;之下，你也許會有疑問為何要如此的相容性？因為你的&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;PCI client&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;的驅動程式，可能由晶片廠商所提供，但是他們只有在&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;FONT: 12px &#39;Lucida Grande&#39;; LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;x86&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;的平台有測試過，為了可以無痛的使用這些原始碼，所以你必需了解以上所提的事。&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://victoryuembeddedlinux.blogspot.com/feeds/5452518440586346695/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://victoryuembeddedlinux.blogspot.com/2011/03/arm-cpulinux-pci-host.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6198249661133467553/posts/default/5452518440586346695'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6198249661133467553/posts/default/5452518440586346695'/><link rel='alternate' type='text/html' href='http://victoryuembeddedlinux.blogspot.com/2011/03/arm-cpulinux-pci-host.html' title='如何撰寫ARM CPU的Linux PCI Host 驅動程式'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUcmudRCskyeThkWmBmNxcErrK6eEJDxD52UjHKSo3Yjm7duuAI2Vf1CXw2pq513269B_naJac_uz6BI-dk0pEQai2TdaWnVABIFeGZBoL5n0Ce2p88lLNsbnsEZBib7Kqt2NRTq3jHfka/s72-c/p1.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6198249661133467553.post-6268897105035210912</id><published>2011-01-10T21:15:00.000+08:00</published><updated>2011-01-17T22:54:33.782+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="kernel driver sound USB speaker"/><title type='text'>如何啓動USB sound</title><content type='html'>&lt;span style=&quot;font-family:arial;&quot;&gt;&lt;span style=&quot;font-size:180%;&quot;&gt;&lt;strong&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;color:#ff0000;&quot;&gt;簡介&lt;/span&gt;&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/span&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;USB喇叭是一個標準的USB class，它是一個USB接頭直接接到一對喇叭，而在喇叭中直接有音訊解碼器及擴大機，可以讓你播放各音樂檔檔式，如mp3 or wav格式，在kernel中有其標準的驅動程式可供使用，在此說明如何在kernel source code做設定，以及要如何安裝才可以使用。&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-size:180%;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;color:#ff0000;&quot;&gt;Kernel驅動程式的選項&lt;/span&gt;&lt;/b&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;在原始中已有現成的驅動程式，我們只要設定使用它就可以了，要設定原始碼，當然是執行&#39;&lt;i&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;color:#000099;&quot;&gt; make menuconfig&#39;&lt;/span&gt;&lt;/b&gt;&lt;/i&gt; 其選項如下 :&lt;br /&gt;首先要進入&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;color:#000099;&quot;&gt;‘Device Driver&#39;&lt;/span&gt;&lt;/b&gt;的選項如下：&lt;/div&gt;&lt;div&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjN28jviBQYLJmKlEYB36AS1ndOmsKI5m954hT-m9h_myp9o68wbgI_g0BK8X5uo1bD0qCkJUr4eoHZrJzbBwSYCW8uakEtxQ-iqOE5nXSW0rt6HQTqBbjCAVDkw4EsZBizMZQp_Txua2r5/s1600/dd.jpg&quot;&gt;&lt;img style=&quot;MARGIN: 0px 10px 10px 0px; WIDTH: 320px; FLOAT: left; HEIGHT: 182px; CURSOR: hand&quot; id=&quot;BLOGGER_PHOTO_ID_5563157779246420402&quot; border=&quot;0&quot; alt=&quot;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjN28jviBQYLJmKlEYB36AS1ndOmsKI5m954hT-m9h_myp9o68wbgI_g0BK8X5uo1bD0qCkJUr4eoHZrJzbBwSYCW8uakEtxQ-iqOE5nXSW0rt6HQTqBbjCAVDkw4EsZBizMZQp_Txua2r5/s320/dd.jpg&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px Helvetica&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt; &lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px Helvetica&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt; &lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px Helvetica&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;進入之後選擇&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;color:#000099;&quot;&gt;&#39;Sound&#39;&lt;/span&gt;&lt;/b&gt;的選項如下：&lt;/span&gt;&lt;/p&gt;&lt;div&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgPtvkL2fGRlAHnZINKYnif8q4DpDRelm5EPzGvt9UQm4M_1vJg_VsKfGOKIb16dgLqX-_GKSgRAC8mAd_D4qR2KEJzFxtnQ1ef1ogfByt_CTQK0_sWTWTILFaTW32ug97ePf9OGJ9vbq1t/s1600/sound.jpg&quot;&gt;&lt;img style=&quot;MARGIN: 0px 10px 10px 0px; WIDTH: 320px; FLOAT: left; HEIGHT: 182px; CURSOR: hand&quot; id=&quot;BLOGGER_PHOTO_ID_5563158278447002306&quot; border=&quot;0&quot; alt=&quot;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgPtvkL2fGRlAHnZINKYnif8q4DpDRelm5EPzGvt9UQm4M_1vJg_VsKfGOKIb16dgLqX-_GKSgRAC8mAd_D4qR2KEJzFxtnQ1ef1ogfByt_CTQK0_sWTWTILFaTW32ug97ePf9OGJ9vbq1t/s320/sound.jpg&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px Helvetica&quot;&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px Helvetica&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt; &lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px Helvetica&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt; &lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px Helvetica&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;啓動&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;color:#000099;&quot;&gt;‘Sound card support&#39;&lt;/span&gt;&lt;/b&gt;，之後再進入&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;color:#000099;&quot;&gt;’Advanced Linux Sound Architecture&#39;&lt;/span&gt;&lt;/b&gt;如下：&lt;/span&gt;&lt;br /&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWb2l4-hMLWZkYqT6Qgo8Knn7iTLnIxy1hsEtFhAYPWuZIgp8riL6KzLr8-vDryittmqHhQxbLqY6ZVRSP_nWbGq3Y-tSdrUNtLO_6-U29IE6MsjM-KzxPnbYXWTNHMOHJtq16LfG9nQzk/s1600/and.jpg&quot;&gt;&lt;img style=&quot;MARGIN: 0px 10px 10px 0px; WIDTH: 320px; FLOAT: left; HEIGHT: 182px; CURSOR: hand&quot; id=&quot;BLOGGER_PHOTO_ID_5563158802464456754&quot; border=&quot;0&quot; alt=&quot;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWb2l4-hMLWZkYqT6Qgo8Knn7iTLnIxy1hsEtFhAYPWuZIgp8riL6KzLr8-vDryittmqHhQxbLqY6ZVRSP_nWbGq3Y-tSdrUNtLO_6-U29IE6MsjM-KzxPnbYXWTNHMOHJtq16LfG9nQzk/s320/and.jpg&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/p&gt;&lt;div&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px Helvetica&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px Helvetica&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt; &lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px Helvetica&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;請將以上所有項目給予啓動，之後請按往下𨧞進入&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;color:#000099;&quot;&gt;‘Generic devices&#39;&lt;/span&gt;&lt;/b&gt;選項如下：&lt;/span&gt;&lt;br /&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkCbLylJqzSM-mk0pxj38zXF_HqBOO5aH70eX2PHMmABKlptwWJ3Aqjx9RwciwPFybuUO2pTlXGcWx1rFzUQx11lzBdoqMm3gyhyJaLlr42oVLSNpbKUvA4QOiAs8G2oNoWeT39jLA7-zo/s1600/generic.jpg&quot;&gt;&lt;img style=&quot;MARGIN: 0px 10px 10px 0px; WIDTH: 320px; FLOAT: left; HEIGHT: 182px; CURSOR: hand&quot; id=&quot;BLOGGER_PHOTO_ID_5563160121345878226&quot; border=&quot;0&quot; alt=&quot;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkCbLylJqzSM-mk0pxj38zXF_HqBOO5aH70eX2PHMmABKlptwWJ3Aqjx9RwciwPFybuUO2pTlXGcWx1rFzUQx11lzBdoqMm3gyhyJaLlr42oVLSNpbKUvA4QOiAs8G2oNoWeT39jLA7-zo/s320/generic.jpg&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt; &lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;將以下所有選項啓動 :&lt;/span&gt;&lt;br /&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjzLPGwoG6UJP_cufKe0LXz22R7ECvzGJvK6U4rVKOerkIR83VmI9I2FcQ_ypIvZ9rftxZGmOqZhc9twRR97uO6SiroHpFoiee8dWwf5bh8e9B1xXDMNxp6iq9yhLccnzgCnGY7lFrBZRQR/s1600/device.jpg&quot;&gt;&lt;img style=&quot;MARGIN: 0px 10px 10px 0px; WIDTH: 320px; FLOAT: left; HEIGHT: 182px; CURSOR: hand&quot; id=&quot;BLOGGER_PHOTO_ID_5563160695235231890&quot; border=&quot;0&quot; alt=&quot;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjzLPGwoG6UJP_cufKe0LXz22R7ECvzGJvK6U4rVKOerkIR83VmI9I2FcQ_ypIvZ9rftxZGmOqZhc9twRR97uO6SiroHpFoiee8dWwf5bh8e9B1xXDMNxp6iq9yhLccnzgCnGY7lFrBZRQR/s320/device.jpg&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;回到上一個主單，進入&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;color:#000099;&quot;&gt;‘USB devices&#39;&lt;/span&gt;&lt;/b&gt;選項如下：&lt;/span&gt; &lt;/div&gt;&lt;div&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi2GuSiXtiWOQoiMFke_4syv3YRJOsteuzfdMuUoFe2h1q2v_6HDbcFOKZUgItm6rgS560PXQ8spQVUV0-DgyrkkWZFlpvz31opwI8MsnSrZWH8Hi-50pM9k78rKzmajM6IhrlDj_aDVmGA/s1600/usbdevice.jpg&quot;&gt;&lt;img style=&quot;MARGIN: 0px 10px 10px 0px; WIDTH: 283px; FLOAT: left; HEIGHT: 320px; CURSOR: hand&quot; id=&quot;BLOGGER_PHOTO_ID_5563163433843413890&quot; border=&quot;0&quot; alt=&quot;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi2GuSiXtiWOQoiMFke_4syv3YRJOsteuzfdMuUoFe2h1q2v_6HDbcFOKZUgItm6rgS560PXQ8spQVUV0-DgyrkkWZFlpvz31opwI8MsnSrZWH8Hi-50pM9k78rKzmajM6IhrlDj_aDVmGA/s320/usbdevice.jpg&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px Helvetica&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px Helvetica&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px Helvetica&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px Helvetica&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px Helvetica&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px Helvetica&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px Helvetica&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px Helvetica&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px Helvetica&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;以上完成kernel的選項設定，重新編繹kernel即可 :&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px Helvetica&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:x-large;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;color:#ff0000;&quot;&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px Helvetica&quot;&gt;&lt;span style=&quot;font-size:180%;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;color:#ff0000;&quot;&gt;播放程式&lt;/span&gt;&lt;/b&gt; &lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px Helvetica&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;有兩個簡單的播放程式可用：&lt;/span&gt; &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;mp3play - 這是一個可以播放MP3音樂檔格式的一個簡單應用程式。&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;play - 這是一個可以播放wav音樂檔格式的一個簡單應用程式。&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;以上兩個程式都可以在網路找到，並且將其重新編繹即可。&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px Helvetica&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;   style=&quot;font-size:180%;color:#ff0000;&quot;&gt;需要建立的Device Node&lt;/span&gt;&lt;/b&gt; &lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px Helvetica&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;有幾個device node必需建立給應用程式使用如下：&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px Helvetica&quot;&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px Helvetica&quot;&gt;&lt;strong&gt;&lt;em&gt;&lt;span style=&quot;font-size:100%;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&gt; mknod dsp c 14 3&lt;/span&gt; &lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Times New Roman&#39;color:#fd1e13;&quot; &gt;&lt;strong&gt;&lt;em&gt;&lt;span style=&quot;font-size:100%;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&gt; mknod audio c 14 4&lt;/span&gt; &lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Times New Roman&#39;color:#fd1e13;&quot; &gt;&lt;strong&gt;&lt;em&gt;&lt;span style=&quot;font-size:100%;&quot;&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&gt; mknod mixer c 14 0&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Times New Roman&#39;color:#fd1e13;&quot; &gt;&lt;span style=&quot;LETTER-SPACING: 0px;font-size:180%;color:#ff0000;&quot;  &gt;&lt;b&gt;需要載入的驅動程式&lt;/b&gt;&lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;/p&gt;&lt;div&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;b&gt;&lt;i&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;b&gt;&lt;i&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&gt; modprobe snd_usb_audio&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;/span&gt; &lt;/div&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Times New Roman&#39;color:#fd1e13;&quot; &gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;b&gt;&lt;i&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&gt; modprobe snd_pcm_oss&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px &#39;Times New Roman&#39;color:#fd1e13;&quot; &gt;&lt;strong&gt;&lt;em&gt;&lt;span style=&quot;font-size:100%;&quot;&gt;&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;&lt;span style=&quot;LETTER-SPACING: 0px&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;color:#000000;&quot;&gt;若載入正常可以看到以下的驅動程式被載入：&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;br /&gt;&lt;/p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgC0avZvQwOsUhURL5etdJ4V1GdOB_hp52_XsuZOn51VyJHTOAyLuaIm6Zn2EuHSAaifUeV1ZxVkvC9MNdDW0SE3E6FavGBppB1J2_1kv17eboexJyB25SrseNA7-Xo-THNrvgqCsJzABF2/s1600/load.jpg&quot;&gt;&lt;img style=&quot;MARGIN: 0px 10px 10px 0px; WIDTH: 320px; FLOAT: left; HEIGHT: 181px; CURSOR: hand&quot; id=&quot;BLOGGER_PHOTO_ID_5563164869056266802&quot; border=&quot;0&quot; alt=&quot;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgC0avZvQwOsUhURL5etdJ4V1GdOB_hp52_XsuZOn51VyJHTOAyLuaIm6Zn2EuHSAaifUeV1ZxVkvC9MNdDW0SE3E6FavGBppB1J2_1kv17eboexJyB25SrseNA7-Xo-THNrvgqCsJzABF2/s320/load.jpg&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px Helvetica&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;color:#000000;&quot;&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px Helvetica&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;color:#000000;&quot;&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px Helvetica&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;color:#000000;&quot;&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px Helvetica&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;color:#000000;&quot;&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px Helvetica&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;color:#000000;&quot;&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px Helvetica&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;color:#000000;&quot;&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px Helvetica&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;color:#000000;&quot;&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt; &lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px Helvetica&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;color:#000000;&quot;&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt; &lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px Helvetica&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;color:#000000;&quot;&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt; &lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px Helvetica&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;color:#000000;&quot;&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt; &lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px Helvetica&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;color:#000000;&quot;&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt; &lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px Helvetica&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;color:#000000;&quot;&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt; &lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px Helvetica&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;color:#000000;&quot;&gt;若USB Speaker插入有被正常找到，你可以在目&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQKBDNALXDQ0NcKrX1feik0tG30g4Eg1X-sOVCD15xWuyAlWigfA35qHZLEj0yJ87e02N3CoAp67h0prTX91yr56EUti2Gji9oJrm0gezShVhIjk9xH8hrzEL18-ueOXk8aGOGjEK_4k-n/s1600/found.jpg&quot;&gt;&lt;img style=&quot;MARGIN: 0px 10px 10px 0px; WIDTH: 320px; FLOAT: left; HEIGHT: 181px; CURSOR: hand&quot; id=&quot;BLOGGER_PHOTO_ID_5563164935279833474&quot; border=&quot;0&quot; alt=&quot;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQKBDNALXDQ0NcKrX1feik0tG30g4Eg1X-sOVCD15xWuyAlWigfA35qHZLEj0yJ87e02N3CoAp67h0prTX91yr56EUti2Gji9oJrm0gezShVhIjk9xH8hrzEL18-ueOXk8aGOGjEK_4k-n/s320/found.jpg&quot; /&gt;&lt;/a&gt;錄/proc/asound之下看到以下檔案：&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px Helvetica&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;color:#000000;&quot;&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px Helvetica&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;color:#000000;&quot;&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px Helvetica&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;color:#000000;&quot;&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px Helvetica&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;color:#000000;&quot;&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px Helvetica&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;color:#000000;&quot;&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px Helvetica&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;color:#000000;&quot;&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt; &lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px Helvetica&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;color:#000000;&quot;&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt; &lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px Helvetica&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;color:#000000;&quot;&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt; &lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px Helvetica&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;color:#000000;&quot;&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt; &lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px Helvetica&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;color:#000000;&quot;&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt; &lt;/p&gt;&lt;p style=&quot;MARGIN: 0px; FONT: 12px Helvetica&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;color:#000000;&quot;&gt;這時你可以執行一下程式測試，若一切正常你可以聽到聲音，如此你也大功告成。&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;/i&gt;&lt;/b&gt;&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://victoryuembeddedlinux.blogspot.com/feeds/6268897105035210912/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://victoryuembeddedlinux.blogspot.com/2011/01/usb-sound.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6198249661133467553/posts/default/6268897105035210912'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6198249661133467553/posts/default/6268897105035210912'/><link rel='alternate' type='text/html' href='http://victoryuembeddedlinux.blogspot.com/2011/01/usb-sound.html' title='如何啓動USB sound'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjN28jviBQYLJmKlEYB36AS1ndOmsKI5m954hT-m9h_myp9o68wbgI_g0BK8X5uo1bD0qCkJUr4eoHZrJzbBwSYCW8uakEtxQ-iqOE5nXSW0rt6HQTqBbjCAVDkw4EsZBizMZQp_Txua2r5/s72-c/dd.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6198249661133467553.post-2572090786907266229</id><published>2010-12-25T21:30:00.000+08:00</published><updated>2011-02-17T22:59:00.854+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="kernel boot init linux"/><title type='text'>kernel的開機執行順序</title><content type='html'>Linux是一個目前非常普遍的作業系統，因為它為免費且公開原始碼的作業系統，所以在嵌入系統中大家都很喜歡使用它，而且它的執行可以很小，且又有效率。我們現在就來大概地了解一下它的開機順序。&lt;div&gt;首先我們要了解的是，Linux kernel可以被編譯成兩種形式，一種是有壓縮的，另一種是沒有壓縮的，兩種形式其第一個執行指令不同，我們先來了解有壓縮的，它是將另一種沒有壓縮的kernel將其做壓縮，並在其前面加一段解壓縮的程式碼，而這段程式碼則是可以執行在記憶中任何位置，並且會將kernel作解壓縮之後放在記憶上，之後將其控制權交給kernel，之後的執行順序，有壓縮和没壓縮的順序是一樣的。&lt;/div&gt;&lt;div&gt;那麼我們先來看看有壓縮的第一個指令在那裹，以ARM CPU來說，它是在arch/arm/boot/compressed/head.S的程式裹，這一段是使用組合語言寫的，其中有兩個重要的暫存器，一個是r1存放的是CPU的代碼，這個代碼是由使用自行定義，由bootloader傳過來，這個值定義在arch/arm/tools/mach-types中，在編譯時會產生一個include/asm/mach-types.h，這時會使用CP15來讀回CPU的ID做比對，確認是否正確，並且使用相對應的cache操作副程式，因此在正確的CPU ID比對之後會啓動cache，以加快對kernel的解壓縮動作。&lt;/div&gt;&lt;div&gt;在解壓縮kernel之前，解壓縮程式會先檢查現在的位置是否和解壓縮之後的位址是否有衝突，若沒有則直接開始解壓縮，若有將會解壓縮至其它地方，之後再搬至最後kernel所要擺放的位置，並且跳至kernel的第一個指令，開始執行，而kernel的第一個指令放在arch/arm/kernel/head.S，開始執行時kernel會比對CPU ID是否正確，再初始化系統的cache HAL call back function，以及各種初始化動作，這些定在MACHINE_START的巨集宣告中，而這是使用者所宣告的，這時也會初始化整記憶體管理，最後會呼叫kernel_start，這是在init/main.c之中，接下來會載入各個driver，以及會mount root file system，當一切都好了之後則會呼叫第一支應用程式，default為/sbin/init，你可以在make menuconfig中將其更換你所要執行的程式，而這支程式可以是binary file也可以是shell script，到此就結束所有的開機動作。&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://victoryuembeddedlinux.blogspot.com/feeds/2572090786907266229/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://victoryuembeddedlinux.blogspot.com/2010/12/kernel.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6198249661133467553/posts/default/2572090786907266229'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6198249661133467553/posts/default/2572090786907266229'/><link rel='alternate' type='text/html' href='http://victoryuembeddedlinux.blogspot.com/2010/12/kernel.html' title='kernel的開機執行順序'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6198249661133467553.post-3612725389327488384</id><published>2010-12-14T22:22:00.000+08:00</published><updated>2011-02-18T22:40:32.787+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="kernel configuration"/><title type='text'>如何製作kernel的default setting</title><content type='html'>當我們取得kernel的source code之後，將其解壓縮，原則上我們第一動作當然會修改根目錄中的Makefile，將其ARCH &amp;amp; CROSS_COMPILE的環境變數修改，例如如下： &lt;div&gt;ARCH = arm&lt;/div&gt;&lt;div&gt;CROSS_COMPILE = arm-linux-&lt;/div&gt;&lt;div&gt;接著我們將會執行make menuconfig的動作，在結束這個動作之後會產生兩個一個是 .config 它是存在原紿檔的根目錄中，這個檔是給Makefile讀取用的，另一個檔為include/linux/autoconfig.h這是給kernel中的C程式用的，當你完成所有的開發之後，可以將 .config 檔拷貝至 arch/arm/default目錄之下，並且取名為 xxxx_defconfig，其中的 xxxx 為你個人自行取名，如此一來當其它人拿到你的source code之後不知該如何設定時，他可以先執行 make xxxx_defconfig 如此一來將會用你之前的設定設置至 .config &amp;amp; include/linux/autoconfig.h 之中，如此一來這將會是你的default setting。&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://victoryuembeddedlinux.blogspot.com/feeds/3612725389327488384/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://victoryuembeddedlinux.blogspot.com/2010/12/%E5%A6%82%E4%BD%95%E8%A3%BD%E4%BD%9Ckernel%E7%9A%84default-setting.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6198249661133467553/posts/default/3612725389327488384'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6198249661133467553/posts/default/3612725389327488384'/><link rel='alternate' type='text/html' href='http://victoryuembeddedlinux.blogspot.com/2010/12/%E5%A6%82%E4%BD%95%E8%A3%BD%E4%BD%9Ckernel%E7%9A%84default-setting.html' title='如何製作kernel的default setting'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6198249661133467553.post-6797844720540240441</id><published>2010-10-26T22:12:00.000+08:00</published><updated>2010-11-14T11:25:39.311+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="linux kernel driver device"/><title type='text'>Linux Device Driver的基本架構</title><content type='html'>每一種OS都會有驅動程式, 而驅動程式主要是做為應用程式要使用各種系統的週邊元件的一中間橋樑, kernel接收及管理應用程式的需求, 並將其需求轉送給驅動程式, 而kernel將會處理多工的問題, 為了讓各種驅動程式好撰寫, 所以每一種OS將會規定驅動程式的寫法, 就好像C語言也有規定應用程式的寫法, 而在linux的OS中規定驅動程式的寫法如下：&lt;div&gt;&lt;ul&gt;&lt;li&gt;目前都是使用C語言來撰寫驅動程式&lt;/li&gt;&lt;li&gt;程式務必include &lt;linux/kernel.h&gt; &lt;linux h=&quot;&quot;&gt; &amp;amp; include &lt;linux/module.h&gt;&lt;linux h=&quot;&quot;&gt;&lt;/linux&gt;&lt;/linux&gt;&lt;/li&gt;&lt;li&gt;每一個程式都會有一個進入點, 或者第一個指令的地方, linux device driver的進入點如下:&lt;/li&gt;&lt;/ul&gt;static int&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;__init your_driver_name_init(void)&lt;/div&gt;&lt;div&gt;{&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;return 0;&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;div&gt;module_init(your_driver_name_init);&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;其進入點的名字你可以隨意取一個名字, 但是其原型的宣告方式必須是固定的, 請參考上面的範例程式, 最後必須使用一個巨集指令module_init()來宣告其為程式進入點。&lt;/div&gt;&lt;div&gt;&lt;ul&gt;&lt;li&gt;Linux的驅動程式可以是static link至kernel, 也可以是動態的方式, linux稱做module, 若是static的方式則必須要有完整的kernel source code, 並且在編譯時會將整個kernel source code編譯過, 而module的方式則不用, 只需要kernel的include檔即, 但是不管是static或者module其進入點宣告方式都一樣&lt;/li&gt;&lt;li&gt;離開或者是下載驅動程式時的進入點宣告如下 :&lt;/li&gt;&lt;/ul&gt;static void&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;__exit your_driver_name_exit(void)&lt;/div&gt;&lt;div&gt;{&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;div&gt;module_exit(your_driver_name_exit);&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;這和進入點一樣, 名字可以隨意取, 但是原型宣告則必須固定, 並且使用module_exit()巨集指令來確定離開驅動式的進入點。&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;以上是Linux的驅動程式的基本概念。&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://victoryuembeddedlinux.blogspot.com/feeds/6797844720540240441/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://victoryuembeddedlinux.blogspot.com/2010/10/linux-device-driver.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6198249661133467553/posts/default/6797844720540240441'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6198249661133467553/posts/default/6797844720540240441'/><link rel='alternate' type='text/html' href='http://victoryuembeddedlinux.blogspot.com/2010/10/linux-device-driver.html' title='Linux Device Driver的基本架構'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6198249661133467553.post-3053008873633665946</id><published>2010-10-21T10:56:00.000+08:00</published><updated>2010-11-14T11:37:17.469+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="kernel NFS root-file-system boot mount"/><title type='text'>如何使用NFS做為開機時的root file system</title><content type='html'>&lt;div&gt;我們都知道Linux在開機時必須要mount一個檔案系統做為根目錄系統, 而這個根目錄通常會指定定在kernel bootup command line的root及rootfstype選項中指定, 但是初期我們在開發embedded系統時通常會有問題, 或者embedded flash的空間不大, 所以若可以使用NFS做為root file system, 將會對開發embedded系統來說會是一項非常方便的事情, 以下即是說明如何設定來使用NFS做為開機時的root file system。&lt;/div&gt;&lt;div&gt;若要使用NFS做為開機時的根目錄, 在kernel的選項中有幾個是必須被打開, 如NFS client (CONFIG_ROOT_NFS), 以及可以自動設定IP的選項, 如DHCP或者BOOTP或RARP, 這是讓kernel開機時即可取得IP address (CONFIG_IP_PNP), 因為NFS是架構在網路上。&lt;/div&gt;&lt;div&gt;而其中的boot command line的設定如下 :&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;root=/dev/nfs&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;而其中的/dev/nfs為一個虛擬的device node, 並不是真實存在, 所以也並不需要真的在檔案系統中建立這個device node&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;nfsroot=[{server-ip}:]{root-dir}[,{nfs-options}]&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;nfsroot是指定NFS server的資料，　若沒有指定nfsroot則會default使用/tftpboot/%s, 做為mount的點，其各個選項說明如下:&lt;/div&gt;&lt;div&gt;{server-ip}&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;是指定NFS server的IP address&lt;/div&gt;&lt;div&gt;{root-dir}&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;是指定NFS server export出來的目錄, 也是會被mount為根目錄的目錄&lt;/div&gt;&lt;div&gt;{nfs-options}&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;為選項如下：&lt;/div&gt;&lt;div&gt;&lt;ul&gt;&lt;li&gt;port = portmap所使用的port number&lt;/li&gt;&lt;li&gt;rsize = 4096&lt;/li&gt;&lt;li&gt;wsize = 4096&lt;/li&gt;&lt;li&gt;timeo = 7&lt;/li&gt;&lt;li&gt;retrans = 3&lt;/li&gt;&lt;li&gt;acregmin = 3&lt;/li&gt;&lt;li&gt;acregmax = 60&lt;/li&gt;&lt;li&gt;acdirmin = 30&lt;/li&gt;&lt;li&gt;acdirmax = 60&lt;/li&gt;&lt;li&gt;flags = hard, nointr, noposix, cto, ac&lt;/li&gt;&lt;/ul&gt;ip={client-ip}:{server-ip}:{gw-ip}:{netmask}:{hostname}:{device}:{autoconf}&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;這是在設定embedded自已的IP address, 若沒有這個設定, 將會依照kernel中所設定的autoconf方法取得IP address, 這個設定可以如下各個情形：&lt;/div&gt;&lt;div&gt;&lt;ul&gt;&lt;li&gt;ip=&quot;off&quot;&lt;/li&gt;&lt;li&gt;ip=&quot;none&quot;&lt;/li&gt;&lt;li&gt;ip=dhcp&quot;&lt;/li&gt;&lt;li&gt;ip=&quot;autoconf&quot;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div&gt;其各選項說明如下 :&lt;/div&gt;&lt;div&gt;{client-ip}&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;embedded自已本身的IP address&lt;/div&gt;&lt;div&gt;{server-ip}&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;NFS server的IP address&lt;/div&gt;&lt;div&gt;{gw-ip}&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;gateway IP address&lt;/div&gt;&lt;div&gt;{netmask} &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;netmask&lt;/div&gt;&lt;div&gt;{hostname}&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;embedded自已本身的名字&lt;/div&gt;&lt;div&gt;{device}&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;embedded自已本身所使用的網路介面名字&lt;/div&gt;&lt;div&gt;{autoconf}&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;其可用的選項如下 :&lt;/div&gt;&lt;div&gt;&lt;ul&gt;&lt;li&gt;off or none&lt;/li&gt;&lt;li&gt;on or any&lt;/li&gt;&lt;li&gt;dhcp&lt;/li&gt;&lt;li&gt;bootp&lt;/li&gt;&lt;li&gt;rarp&lt;/li&gt;&lt;li&gt;both  (使用bootp &amp;amp; rarp)&lt;/li&gt;&lt;li&gt;default is any&lt;/li&gt;&lt;/ul&gt;以上若是使用正確將可以使用NFS來做為開機時的root file system，以下是一個範例：&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt; root=/dev/nfs console=ttySAC0,115200 nfsroot=192.168.2.144:/home/work/embedded/filesystem/rootfs ip=dhcp&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;以上範例測試板是dhcp取得IP address，以下是另一個範例!為設定固定IP address ：&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt; root=/dev/nfs console=ttySAC0,115200 nfsroot=192.168.2.144:/home/work/embedded/filesystem/rootfs ip=192.168.2.90&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://victoryuembeddedlinux.blogspot.com/feeds/3053008873633665946/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://victoryuembeddedlinux.blogspot.com/2010/10/nfsroot-file-system.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6198249661133467553/posts/default/3053008873633665946'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6198249661133467553/posts/default/3053008873633665946'/><link rel='alternate' type='text/html' href='http://victoryuembeddedlinux.blogspot.com/2010/10/nfsroot-file-system.html' title='如何使用NFS做為開機時的root file system'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6198249661133467553.post-2113649724521582925</id><published>2010-10-04T22:31:00.000+08:00</published><updated>2011-03-11T22:45:44.774+08:00</updated><title type='text'>在Linux一些好用的設定</title><content type='html'>&lt;ul&gt;&lt;li&gt;如何讓在Linux系統下ls指令時所顯示的檔名，會根據檔案屬性不同，顯示不同的顏色，其做法是在使用者的home directory之下編譯.bashrc檔案，加入一些設定如下&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;　　　　export LS_OPTIONS=&#39;--color=auto&#39;&lt;/div&gt;&lt;div&gt;　　　　eval &quot;`dircolors`&quot;&lt;/div&gt;&lt;div&gt;　　　　alias ls=&#39;ls $LS_OPTIONS&#39;&lt;/div&gt;&lt;div&gt;　　　　alias ll=&#39;ls $LS_OPTIONS -l&#39;&lt;/div&gt;&lt;div&gt;　　　　alias l=&#39;ls $LS_OPTIONS -lA&#39;&lt;/div&gt;&lt;div&gt;&lt;ul&gt;&lt;li&gt;在debain系統按裝套件的指令&lt;/li&gt;&lt;/ul&gt;                apt-get install package-name&lt;/div&gt;&lt;div&gt;                apt-cache search package-name&lt;/div&gt;&lt;div&gt;&lt;ul&gt;&lt;li&gt;檢查有多少軟件已按裝&lt;/li&gt;&lt;/ul&gt;dpkg -l&lt;/div&gt;&lt;div&gt;&lt;ul&gt;&lt;li&gt;&lt;span style=&quot; ;font-family:新細明體;&quot;&gt;&lt;span style=&quot; ;font-family:新細明體;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;免設&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot; ;font-family:Arial;&quot;&gt;&lt;span style=&quot; ;font-family:Arial;&quot; lang=&quot;EN-US&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;IP/  &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot; ;font-family:新細明體;&quot;&gt;&lt;span style=&quot; ;font-family:新細明體;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;免使用&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot; ;font-family:Arial;&quot;&gt;&lt;span style=&quot; ;font-family:Arial;&quot; lang=&quot;EN-US&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;public IP  / &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot; ;font-family:新細明體;&quot;&gt;&lt;span style=&quot; ;font-family:新細明體;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;使用&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot; ;font-family:Arial;&quot;&gt;&lt;span style=&quot; ;font-family:Arial;&quot; lang=&quot;EN-US&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;P2P /  Window, Ubuntu, iphone&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot; ;font-family:新細明體;&quot;&gt;&lt;span style=&quot; ;font-family:新細明體;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;支援，可以穿透任何&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot; ;font-family:Arial;&quot;&gt;&lt;span style=&quot; ;font-family:Arial;&quot; lang=&quot;EN-US&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;firewall&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot; ;font-family:Arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;http://&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:Arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;a title=&quot;http://www.teamviewer.com/&quot; href=&quot;http://www.teamviewer.com/&quot;&gt;www.teamviewer.com&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:Arial;&quot;&gt;用過心得：還是VNC的效能較好，比較不會有延遲晝面及解析度較好。但是VNC無法透過internet使用。&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;ul&gt;&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:Arial;&quot;&gt;如何設定讓debain 6.0的Window可以用root權限登入：&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:Arial;&quot;&gt;default的debain 6.0是不讓人使用root來登錄，當然這是為了安全著想，但是有時debain我們是將它安裝在virtual machine中，只是自已使用，所以常常需使用su或者做權限的認證才能做事，其實是很麻煩的，所以可以直接用root來登錄是一件很方便的事。其實要讓root可以直接登入是一件很簡單的事，只要修改 /etc/pam.d/gdm3 的檔案，將以下的這行mark掉就好了：&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:Arial;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:Arial;&quot;&gt;auth   required        pam_succeed_if.so user != root quiet_success&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:Arial;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;font-family:Arial;font-size:78%;&quot;&gt;&lt;span lang=&quot;EN-US&quot;   style=&quot; ;font-family:Arial;font-size:9pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://victoryuembeddedlinux.blogspot.com/feeds/2113649724521582925/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://victoryuembeddedlinux.blogspot.com/2010/10/linux.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6198249661133467553/posts/default/2113649724521582925'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6198249661133467553/posts/default/2113649724521582925'/><link rel='alternate' type='text/html' href='http://victoryuembeddedlinux.blogspot.com/2010/10/linux.html' title='在Linux一些好用的設定'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6198249661133467553.post-2668368117017070166</id><published>2010-08-20T21:00:00.000+08:00</published><updated>2011-06-08T21:51:15.521+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="compiler"/><category scheme="http://www.blogger.com/atom/ns#" term="cross"/><category scheme="http://www.blogger.com/atom/ns#" term="linker"/><category scheme="http://www.blogger.com/atom/ns#" term="tool-chain"/><title type='text'>如何編譯ARM Cross Compiler ToolChain</title><content type='html'>在Embedded系統中, 通常我們會需要做cross development, 而這時則需要cross compiler, 而有時等待網路上其他編譯好的cross compiler會太慢, 或者他們編譯時所選的選項不是你想要的, 這時則必需自行編譯, 我個人的經驗則是完全自行編譯使用, 而不用其他人所編譯好的toolchain, 所以我將我個人的經驗提供給大家做參考。在編譯之前你必需準備好以下的環境及source code:&lt;br /&gt;
&lt;br /&gt;
&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;下載原始碼&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
1. 安裝好一個PC Linux, 你可以用virtual machine來建立, 個人不太建議使用cygwin這類的環境來做開發環境。&lt;br /&gt;
2. 必需在PC Linux上按裝軟體如下:&lt;/div&gt;&lt;div&gt;&lt;ul&gt;&lt;li&gt;x86版本的gcc compiler (必須包含g++)&lt;/li&gt;
&lt;li&gt;公共程式texi2html&lt;/li&gt;
&lt;li&gt;公共程式gawk&lt;/li&gt;
&lt;li&gt;函式庫zlib&lt;/li&gt;
&lt;/ul&gt;3. 下載kernel source code (這裏我使用2.6.35當範例) 。&lt;br /&gt;
4. 下載gcc source code (這裏我使用4.5.0當範例) 。&lt;br /&gt;
5. 下載glibc source code (這裏我使用2.11.2當範例) 。&lt;br /&gt;
6. 下載binutil source code (這裏我使用2.20.0當範例) 。&lt;br /&gt;
7. 下載glibc ARM patched file (glibc-ports-2.11.tar.bz2)。&lt;br /&gt;
8. 下載gmp source code (這裏我使用5.0.1當範例) 。&lt;br /&gt;
9. 下載mpfr source code (這裏我使用3.0.0當範例) 。&lt;br /&gt;
10. 下載mpc source code (這裏我使用0.8.2當範例, 在GCC 4.5.0之後必需使用mpc)。&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;編譯流程&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
以下則是整個編譯過程的主要步驟, 你必須依照以下的順序, 否則你將無法順利編譯成功：&lt;br /&gt;
1. 將下載下來的source code全部解壓縮至各別的目錄。&lt;br /&gt;
2. 先編譯binutils, 並將其按裝在你的PC Linux上 (這裏假設按裝的目錄為/usr/local/arm-linux-gnueabi), 這個原始碼是ld, as, ranlib等的程式碼。&lt;br /&gt;
3. 編譯gmp並將其按裝至以上binutil按裝目錄之下的tools目錄。&lt;br /&gt;
4. 宣告一個系統變數 export LD_LIBRARY_PATH=/usr/local/arm-linux-gnueabi/tools/lib。&lt;br /&gt;
5. 編譯mpfr並將其按裝至以上binutil按裝目錄之下的tools目錄。&lt;br /&gt;
6. 編譯mpc並將其按裝至以上binutil按裝目錄之下的tools目錄。&lt;br /&gt;
7. 增加系統search變數 export PATH=$PATH:/usr/local/arm-linux-gnueabi/bin。&lt;br /&gt;
8. 編譯gcc為static以及只有 c 語言的支援, 並將其按裝至PC Linux。&lt;br /&gt;
9. 編譯glibc為shared library並將其按裝至PC Linux, 若是要編譯多種版本library (little endian, big endian version), 則必須要在這個步驟重覆執行, 使用不同的參數來產生不同版本的library。&lt;br /&gt;
10. 再編譯一次gcc, 但是將其編譯為shared library, 並有c++的支援, 至此就大功告成。&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000099;&quot;&gt;編譯gmp步驟如下:&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;1. 建立一個子目錄為 /usr/local/arm-linux-gnueabi/tools&lt;br /&gt;
&lt;div&gt;2. 進入gmp的source code directory&lt;/div&gt;&lt;div&gt;3. 建立一個目錄為build-arm, 並進入該目錄&lt;/div&gt;&lt;div&gt;4. 執行命令如下:&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; CPPFLAGS=-fexceptions ../configure --prefix=/usr/local/arm-linux-gnueabi/tools --enable-cxx --with-gnu-ld&lt;/span&gt;&lt;br /&gt;
5. 執行make &amp;amp; make install&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000099;&quot;&gt;編譯mpfr步驟如下:&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;&lt;div&gt;1. 進入mpfr的source code directory&lt;/div&gt;&lt;div&gt;2. 建立一個目錄為build-arm, 並進入該目錄&lt;/div&gt;&lt;div&gt;3. 執行命令如下:&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; ../configure --prefix=/usr/local/arm-linux-gnueabi/tools --with-gmp=/usr/local/arm-linux-gnueabi/tools --with-gnu-ld&lt;/span&gt;&lt;br /&gt;
4. 執行make &amp;amp; make install&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000099;&quot;&gt;編譯mpc步驟如下:&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;&lt;div&gt;1. 進入mpc的source code directory&lt;/div&gt;&lt;div&gt;2. 建立一個目錄為build-arm, 並進入該目錄&lt;/div&gt;&lt;div&gt;3. 執行命令如下:&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; ../configure --prefix=/usr/local/arm-linux-gnueabi/tools --with-gnu-ld --with-gmp=/usr/local/arm-linux-gnueabi/tools --with-mpfr=/usr/local/arm-linux-gnueabi/tools&lt;/span&gt;&lt;br /&gt;
4. 執行make &amp;amp; make install&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000099;&quot;&gt;編譯binutil的步驟如下:&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
1. 進入binutils的source code directory&lt;br /&gt;
2. 建立一個月錄build-arm, 並且進入該目錄&lt;br /&gt;
3. 執行命令如下:&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;../configure --prefix=/usr/local/arm-linux-gnueabi --host=i686-pc-linux --build=i686-pc-linux --target=arm-linux-gnueabi --enable-shared --disable-multilib --with-gmp=/usr/local/arm-linux-gnueabi/tools --with-mpfr=/usr/local/arm-linux-gnueabi/tools --with-mpc=/usr/local/arm-linux-gnueabi/tools&lt;/div&gt;&lt;div&gt;3-1. 假如你要支援多種版本的library (little-endian &amp;amp; big-endian), 則所下的參數會是如下 :&lt;/div&gt;&lt;div&gt;../configure --prefix=/usr/local/arm-linux-gnueabi --build=i686-pc-linux --host=i686-pc-linux --target=arm-linux-gnueabi --enable-shared --enable-multilib --with-lib-path=/usr/local/arm-linux-gnueabi/lib:/usr/local/arm-linux-gnueabi/lib/be:/usr/local/arm-linux-gnueabi/lib/soft-float:/usr/local/arm-linux-gnueabi/lib/be/soft-float --with-gmp=/usr/local/arm-linux-gnueabi/tools --with-mpfr=/usr/local/arm-linux-gnueabi/tools --with-mpc=/usr/local/arm-linux-gnueabi/tools&lt;/div&gt;&lt;div&gt;主要是多一個--with-lib-path的選項。&lt;/div&gt;&lt;div&gt;4. 之後執行make &amp;amp; make install&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000099;&quot;&gt;設定環境變數&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;這時需要先編譯一版使用static library的gcc版本, 再使用這版compiler去編譯glibc為shared library, 之後再回頭再編譯一次gcc為使用shared library, 在編譯之前需設定幾個環境變數如下 :&lt;/div&gt;&lt;/div&gt;&lt;div&gt;1. export LD_LIBRARY_PATH=/usr/local/arm-linux-gnueabi/tools/lib&lt;/div&gt;&lt;div&gt;2. export PATH=$PATH:/usr/local/arm-linux-gnueabi/bin&lt;/div&gt;&lt;div&gt;3. 若要支援多版本的編繹器則需要修改設定檔gcc/config/arm/t-linux-eabi，增加內容如下：&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;MULTILIB_OPTIONS = mlittle-endian/mbig-endian&lt;/div&gt;&lt;div&gt;MULTILIB_DIRNAMES = le be&lt;/div&gt;&lt;div&gt;LIBGCC = stmp-multilib&lt;/div&gt;&lt;div&gt;INSTALL_LIBGCC = install-multilib&lt;/div&gt;&lt;p:colorscheme colors=&quot;#ffffe1,#000000,#330033,#330033,#cccc99,#ff0000,#990033,#b2b2b2&quot;&gt;&lt;/p:colorscheme&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;&lt;b&gt;以下是編譯的流程 :&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;1. 進入GCC source code目錄並建立一個子目錄build-arm-static&lt;/div&gt;&lt;div&gt;2. 進入build-arm-static目錄, 執行以下指令&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; ../configure --host=i686-pc-linux --build=i686-pc-linux --target=arm-linux-gnueabi --prefix=/usr/local/arm-linux-gnueabi --with-gmp=/usr/local/arm-linux-gnueabi/tools --with-mpfr=/usr/local/arm-linux-gnueabi/tools --with-gnu-ld --without-newlib --enable-long-long --disable-libada --without-cvs --disable-libgomp --disable-libmudflap --disable-libssp --disable-threads --enable-__cxa_atexit --disable-shared --enable-languages=c --with-system-zlib --with-mpc=/usr/local/arm-linux-gnueabi/tools --disable-multilib&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;2-1.若是要支援多版library則設定如下:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;./configure --host=i686-pc-linux --build=i686-pc-linux --target=arm-linux-gnueabi --prefix=/usr/local/arm-linux-gnueabi --with-gmp=/usr/local/arm-linux-gnueabi/tools --with-mpfr=/usr/local/arm-linux-gnueabi/tools --with-gnu-ld --without-newlib --enable-long-long --disable-libada --without-cvs --disable-libgomp --disable-libmudflap --disable-libssp --disable-threads --enable-__cxa_atexit --disable-shared --enable-languages=c --with-system-zlib --with-mpc=/usr/local/arm-linux-gnueabi/tools --enable-multilib&lt;/span&gt;&lt;/div&gt;&lt;div&gt;3. 執行make &amp;amp; make install&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;編譯glibc&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;接下來是要編譯glibc是較麻煩的一件事, 在編譯glibc之前, 你必須使用kernel來產生一些header files因為在編譯glibc時需要用到, 以下是產生kernel header file的步驟：&lt;/div&gt;&lt;div&gt;1. 進入kernel source code目錄, 修改Makefile中的ARCH及CROSS_COMPILE變數如下 :&lt;/div&gt;&lt;div&gt;ARCH := arm&lt;/div&gt;&lt;div&gt;CROSS_COMPILE := arm-linux-gnueabi&lt;/div&gt;&lt;div&gt;INSTALL_MOD_PATH := `pwd`/installed_modules&lt;/div&gt;&lt;div&gt;1-1. 你若要產生多種版本的library (little endian &amp;amp; big endian), 那你必須更改兩個檔案 (glibc-source-code/Makeconfig &amp;amp; glibc-source-code/config.make.in), 以便在編譯完要按裝時可以得到適當的按裝, 其修改內容如下:&lt;/div&gt;&lt;div&gt;&lt;ul&gt;&lt;li&gt;glibc-source-code/Makefconfig 第193行加入以下內容:&lt;/li&gt;
&lt;/ul&gt;slibdir = $(libdir)&lt;/div&gt;&lt;div&gt;&lt;ul&gt;&lt;li&gt;glibc-source-code/config.make.in mark掉第13行 #slibdir = @libc_cv_slibdir@, 加入一行如下:&lt;/li&gt;
&lt;/ul&gt;slibdir = @libdir@&lt;/div&gt;&lt;div&gt;1-2.  在新版的glibc中gcc_eh並未準備好，所以無法使用，必須修Makeconfig檔以防止在編譯glibc時會連結gcc_eh, 你必須將該檔中的-lgcc_eh移除即。&lt;/div&gt;&lt;div&gt;2. 執行make menuconfig並選擇一種ARM平台, 之後將設定存下&lt;/div&gt;&lt;div&gt;3. 執行make headers_install以取得編譯glibc時要使用的kernel header files, 這時這些的include files將會被產生在kernel source code的目錄之下的usr/include目錄&lt;/div&gt;&lt;div&gt;4. 進入glibc的source code根目錄, 並建立一個目錄為build-arm-le, 並將glibc-ports-2.11.tar.bz2解壓縮的內容拷貝至glibc的目錄並設為ports的目錄&lt;/div&gt;&lt;div&gt;5. 進入build-arm-le的目錄, 並執行以下指令 :&lt;/div&gt;&lt;div&gt;CC=arm-linux-gnueabi-gcc CXX=arm-linux-gnueabi-g++ CPP=&quot;arm-linux-gnueabi-gcc -E&quot; LD=arm-linux-gnueabi-ld STRIP=arm-linx-gnueabi-strip AR=arm-linux-gnueabi-ar NM=arm-linux-gnueabi-nm AS=arm-linux-gnueabi-as RANLIB=arm-linux-gnueabi-ranlib ARCH=arm ../configure --prefix=/usr/local/arm-linux-gnueabi --target=arm-linux-gnueabi --host=arm-linux-gnueabi --build=i686-pc-linux --disable-profile --enable-add-ons --with-__thread --enable-threads=posix --enable-multilib --without-cvs --enable-shared --without-gd --with-headers=/home/work/kernel/linux-2.6.35/usr/include --libdir=/usr/local/arm-linux-gnueabi/lib libc_cv_forced_unwind=yes libc_cv_c_cleanup=yes&lt;/div&gt;&lt;div&gt;5-1.進入build-arm-be的目錄, 並執行以下指令:&lt;/div&gt;&lt;div&gt;CC=&quot;arm-linux-gnueabi-gcc -mbig-endian&quot; CXX=&quot;arm-linux-gnueabi-g++ -mbig-endian&quot; CPP=&quot;arm-linux-gnueabi-gcc -E -mbig-endian&quot; LD=&quot;arm-linux-gnueabi-ld -EB&quot; STRIP=arm-linx-gnueabi-strip AR=arm-linux-gnueabi-ar NM=arm-linux-gnueabi-nm AS=&quot;arm-linux-gnueabi-as -EB&quot; RANLIB=arm-linux-gnueabi-ranlib ARCH=arm ../configure --prefix=/usr/local/arm-linux-gnueabi --target=arm-linux-gnueabi --host=arm-linux-gnueabi --build=i686-pc-linux --disable-profile --enable-add-ons --with-__thread --enable-threads=posix --enable-multilib --without-cvs --enable-shared --without-gd --with-headers=/home/work/kernel/linux-2.6.35/usr/include --libdir=/usr/local/arm-linux-gnueabi/lib/be libc_cv_forced_unwind=yes libc_cv_c_cleanup=yes&lt;/div&gt;&lt;div&gt;6. 執行make &amp;amp; make install, 至此即可完成glibc的建立, 你將可以在/usr/local/arm-linux-gnueabi目錄下, 可以發現include &amp;amp; lib的目錄內容已包含glibc的內容&lt;br /&gt;
7. &amp;nbsp;將kernel/usr/include目錄之下的所有檔案拷貝至/usr/local/arm-linux-gnueabi/include目錄之下&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;編譯gcc for shared library&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;最後的動作則是要再重新編譯一次gcc使它支援shared library, 在重新編譯之前, 有幾個動作必須要完成, 以下是這些動作的內容：&lt;/div&gt;&lt;div&gt;1.  進入/usr/local/arm-linux-gnueabi/arm-linux-gnueabi的目錄, 特別注意是有兩層的arm-linux-gnueabi, 不可弄錯&lt;/div&gt;&lt;div&gt;2. 執行指令如下：&lt;/div&gt;&lt;div&gt;&amp;gt; mv lib lib.bak&lt;/div&gt;&lt;div&gt;&amp;gt; ln -s ../lib lib&lt;/div&gt;&lt;div&gt;&amp;gt; ln -s ../include include&lt;/div&gt;&lt;div&gt;&amp;gt; cp -a lib.bak/* ../lib&lt;/div&gt;&lt;div&gt;這時可以正式開始來重新編譯gcc, 其步驟如下：&lt;/div&gt;&lt;div&gt;1. 進入gcc source code目錄, 並建立一個目錄為build-arm-shared, 之後進入build-arm-shared目錄&lt;/div&gt;&lt;div&gt;2. 執行以下指令 :&lt;/div&gt;&lt;div&gt;../configure --host=i686-pc-linux --build=i686-pc-linux --target=arm-linux-gnueabi --prefix=/usr/local/arm-linux-gnueabi --with-arch=armv6 --with-gmp=/usr/local/arm-linux-gnueabi/tools --with-mpfr=/usr/local/arm-linux-gnueabi/tools --with-gnu-ld --without-newlib --enable-long-long --disable-libada --without-cvs --disable-libgomp --disable-libmudflap --disable-libssp --enable-threads --enable-__cxa_atexit --enable-shared --enable-languages=c,c++ --with-system-zlib --with-mpc=/usr/local/arm-linux-gnueabi/tools --disable-multilib&lt;/div&gt;&lt;div&gt;2-1.若要支援多版library執行指令如下:&lt;/div&gt;&lt;div&gt;../configure --host=i686-pc-linux --build=i686-pc-linux --target=arm-linux-gnueabi --prefix=/usr/local/arm-linux-gnueabi --with-arch=armv6 --with-gmp=/usr/local/arm-linux-gnueabi/tools --with-mpfr=/usr/local/arm-linux-gnueabi/tools --with-gnu-ld --without-newlib --enable-long-long --disable-libada --without-cvs --disable-libgomp --disable-libmudflap --disable-libssp --enable-threads --enable-__cxa_atexit --enable-shared --enable-languages=c,c++ --with-system-zlib --with-mpc=/usr/local/arm-linux-gnueabi/tools --enable-multilib&lt;/div&gt;&lt;div&gt;3. 執行make ; make install &lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;至此就大功告成, 你可以寫一個簡單的hello程式來試試, 記得這是default share library的cross compiler, 所以你執行ap時也要記得將shared library也拷貝至embedded computer&lt;br /&gt;
&lt;br /&gt;
最後有一個公共程式很好用，那就是 ldd 它可將應用程式及 library 所用到的 library 例出來，default 的 ldd 有點問題無法執行，這邊可以自行寫一個 shell script 檔名就是 arm-linux-gnueabi-ldd 其內容如下：&lt;br /&gt;
&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
arm-linux-gnueabi-objdump -x $@ | grep NEEDED&lt;br /&gt;
&lt;br /&gt;
並將這執行放至 /usr/local/arm-linux-gnueabi/bin 目錄之下即可。&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://victoryuembeddedlinux.blogspot.com/feeds/2668368117017070166/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://victoryuembeddedlinux.blogspot.com/2010/08/arm-cross-compiler-toolchain.html#comment-form' title='2 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6198249661133467553/posts/default/2668368117017070166'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6198249661133467553/posts/default/2668368117017070166'/><link rel='alternate' type='text/html' href='http://victoryuembeddedlinux.blogspot.com/2010/08/arm-cross-compiler-toolchain.html' title='如何編譯ARM Cross Compiler ToolChain'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6198249661133467553.post-4134118933362879103</id><published>2009-11-09T23:03:00.000+08:00</published><updated>2010-11-14T11:39:31.664+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="kernel"/><category scheme="http://www.blogger.com/atom/ns#" term="porting"/><category scheme="http://www.blogger.com/atom/ns#" term="source code"/><title type='text'>如何porting linux kernel給一顆新的ARM CPU</title><content type='html'>ARM CPU是目前使用最多的embedded CPU, 所以這邊會就我個人經驗來分享如何porting一顆新的ARM CPU Linux platform, 在porting之前有幾項硬體規格必須事先弄清楚：&lt;div&gt;&lt;ul&gt;&lt;li&gt;CPU是何種ARM core, 例如arm926, 是V5, V6還是V7等等&lt;/li&gt;&lt;li&gt;SoC多少週邊元件在這顆Embedded ARM CPU之內&lt;/li&gt;&lt;li&gt;interrupt如何設定及使用, 這裏所指的是interrupt controller&lt;/li&gt;&lt;li&gt;timer如何設定及使用&lt;/li&gt;&lt;li&gt;DRAM &amp;amp; Flash mapping至CPU那個位置&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;收集這些資訊之後, 開始要做Linux kernel porting的工作, 以下是它的工作步驟&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;ul&gt;&lt;li&gt;修改源始碼根目錄的Makefile, 將其中幾個變數做修改如下&lt;/li&gt;&lt;/ul&gt;           ARCH := ARM&lt;/div&gt;&lt;div&gt;           CROSS_COMPILE := arm-linux-gnueabi&lt;/div&gt;&lt;div&gt;           INSTALL_MOD_PATH := `pwd`/installed_modules&lt;/div&gt;&lt;div&gt;&lt;ul&gt;&lt;li&gt;在arch/arm目錄之下建立一個子目錄其名字為mach-開頭, 之後你可以取一個名字, 例如mach-victorcpu, 而在這目錄下的程式皆為HAL層的程式碼&lt;/li&gt;&lt;li&gt;在arch/arm/tools目錄之下有一個文字檔 &quot;mach-types&quot; , 仿照其它CPU的寫法, 你必須定一個ID號碼, 必須是唯一的。&lt;/li&gt;&lt;li&gt;在你建立的mach-victorcpu目錄建立Makefile &amp;amp; Kconfig, 並將你建立的Kconfig檔加入至arch/arm/Kconfig的include之中&lt;/li&gt;&lt;li&gt; 在新建mach-victorcpu的新目錄中, 必須幾個檔案而其內容如下:&lt;/li&gt;&lt;li&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;MACHINE_DESCRIPTION&lt;/li&gt;&lt;li&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;interrupt controller initialization&lt;/li&gt;&lt;li&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;timer controller initialization&lt;/li&gt;&lt;li&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;mapping fixed some SoC address to be virtual address, 有些SoC的元件在開機就必須使用到的, 就需要使用事先定對好的方式來設定, 例如timer&lt;/li&gt;&lt;li&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; 若有PCI host, 則必須撰寫其HAL層在此, 而PCI BUS Driver則會在driver/pci的目錄中, 不用撰寫。&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre;&quot;&gt;若在cahce操作部若有和ARM的標準不同, 則必需撰寫其差異部分的程式在arch/arm/mm的目錄之下。&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre;&quot;&gt;接下來必需要開始撰寫各個SoC進來元件的device driver, 你要依照硬體的設計來撰寫個別device driver。&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre;&quot;&gt;以上為porting Linux kernel時非常非常大項分法所需要撰寫的程式說明。&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://victoryuembeddedlinux.blogspot.com/feeds/4134118933362879103/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://victoryuembeddedlinux.blogspot.com/2009/11/portingcpu.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6198249661133467553/posts/default/4134118933362879103'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6198249661133467553/posts/default/4134118933362879103'/><link rel='alternate' type='text/html' href='http://victoryuembeddedlinux.blogspot.com/2009/11/portingcpu.html' title='如何porting linux kernel給一顆新的ARM CPU'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6198249661133467553.post-6104482380402212273</id><published>2009-10-29T23:05:00.001+08:00</published><updated>2010-11-25T15:45:17.089+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="driver"/><category scheme="http://www.blogger.com/atom/ns#" term="rs232"/><category scheme="http://www.blogger.com/atom/ns#" term="serial port"/><title type='text'>如何撰寫一個serial port的驅動程式</title><content type='html'>&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;font-size:180%;&quot;&gt;簡介&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;RS232是kernel中常用到的一種週邊元件，在以前主要是拿來連接終端設備的通訊介面，而今日則是常被拿來做控制或者和其它設備通訊的介面，因為其硬體簡單及成本低所以會被很多設備做為最基本的通訊介面，因為其發展有很長一段時間，所以在Linux中有為它特別規劃一組軟體堆疊，主要分為實體控制層以及上層的終端控制層，其架構如下:&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiNNPQ4OR9qGjDBR5weOHFEhCMSAb5HSP1LSgx3qeF5VO8llX0Qoocth7pkA659_2Y94h2jbKsNueA1hh13uhmOdT7nsD6uhnoXk3m_5s-m3hOswe5bPC-Sh_NFNaENwusq5ubc_kJNrqNT/s1600-h/SerialDriverStructure.jpg&quot;&gt;&lt;img style=&quot;MARGIN: 0px 10px 10px 0px; WIDTH: 206px; FLOAT: left; HEIGHT: 320px; CURSOR: hand&quot; id=&quot;BLOGGER_PHOTO_ID_5399875092663389922&quot; border=&quot;0&quot; alt=&quot;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiNNPQ4OR9qGjDBR5weOHFEhCMSAb5HSP1LSgx3qeF5VO8llX0Qoocth7pkA659_2Y94h2jbKsNueA1hh13uhmOdT7nsD6uhnoXk3m_5s-m3hOswe5bPC-Sh_NFNaENwusq5ubc_kJNrqNT/s320/SerialDriverStructure.jpg&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;font-size:180%;&quot;&gt;初始化&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;所以通常我們要寫的是實體層的驅動程式，在driver的進入點，若是PCI介面，則先註冊一個PCI的call back function，若是local bus則是可以註冊一個platform device call back function，當系統進入你所註冊的call back function，必須對你所使用的硬體介面位址做一個remapping的動作，就是將實體位址轉換成虛擬位址，接著後面的所有程式碼都要使用這個虛擬位址，這時要開始初始化你的硬體及driver，首先建立一個struct tty_driver的資料結構，其宣告如下：&lt;br /&gt;&lt;br /&gt;&lt;span lang=&quot;EN-US&quot;  style=&quot;font-family:細明體;&quot;&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;struct tty_driver {&lt;br /&gt;&lt;span style=&quot;mso-tab-count: 1&quot;&gt;&lt;/span&gt;int&lt;span style=&quot;mso-tab-count: 1&quot;&gt; &lt;/span&gt;magic;&lt;span style=&quot;mso-tab-count: 2&quot;&gt; &lt;/span&gt;/* magic number for this structure */&lt;br /&gt;&lt;span style=&quot;mso-tab-count: 1&quot;&gt;&lt;/span&gt;struct cdev cdev;&lt;br /&gt;&lt;span style=&quot;mso-tab-count: 1&quot;&gt;&lt;/span&gt;struct module&lt;span style=&quot;mso-tab-count: 1&quot;&gt; &lt;/span&gt;*owner;&lt;br /&gt;&lt;span style=&quot;mso-tab-count: 1&quot;&gt;&lt;/span&gt;const char&lt;span style=&quot;mso-tab-count: 1&quot;&gt; &lt;/span&gt;*driver_name;&lt;br /&gt;&lt;span style=&quot;mso-tab-count: 1&quot;&gt;&lt;/span&gt;const char&lt;span style=&quot;mso-tab-count: 1&quot;&gt; &lt;/span&gt;*name;&lt;br /&gt;&lt;span style=&quot;mso-tab-count: 1&quot;&gt;&lt;/span&gt;int&lt;span style=&quot;mso-tab-count: 1&quot;&gt; &lt;/span&gt;name_base;&lt;span style=&quot;mso-tab-count: 1&quot;&gt; &lt;/span&gt;/* offset of printed name */&lt;br /&gt;&lt;span style=&quot;mso-tab-count: 1&quot;&gt;&lt;/span&gt;int&lt;span style=&quot;mso-tab-count: 1&quot;&gt; &lt;/span&gt;major;&lt;span style=&quot;mso-tab-count: 2&quot;&gt; &lt;/span&gt;/* major device number */&lt;br /&gt;&lt;span style=&quot;mso-tab-count: 1&quot;&gt;&lt;/span&gt;int&lt;span style=&quot;mso-tab-count: 1&quot;&gt; &lt;/span&gt;minor_start;&lt;span style=&quot;mso-tab-count: 1&quot;&gt; &lt;/span&gt;/* start of minor device number */&lt;br /&gt;&lt;span style=&quot;mso-tab-count: 1&quot;&gt;&lt;/span&gt;int&lt;span style=&quot;mso-tab-count: 1&quot;&gt; &lt;/span&gt;minor_num;&lt;span style=&quot;mso-tab-count: 1&quot;&gt; &lt;/span&gt;/* number of *possible* devices */&lt;br /&gt;&lt;span style=&quot;mso-tab-count: 1&quot;&gt;&lt;/span&gt;int&lt;span style=&quot;mso-tab-count: 1&quot;&gt; &lt;/span&gt;num;&lt;span style=&quot;mso-tab-count: 2&quot;&gt; &lt;/span&gt;/* number of devices allocated */&lt;br /&gt;&lt;span style=&quot;mso-tab-count: 1&quot;&gt;&lt;/span&gt;short&lt;span style=&quot;mso-tab-count: 1&quot;&gt; &lt;/span&gt;type;&lt;span style=&quot;mso-tab-count: 2&quot;&gt; &lt;/span&gt;/* type of tty driver */&lt;br /&gt;&lt;span style=&quot;mso-tab-count: 1&quot;&gt;&lt;/span&gt;short&lt;span style=&quot;mso-tab-count: 1&quot;&gt; &lt;/span&gt;subtype;&lt;span style=&quot;mso-tab-count: 1&quot;&gt; &lt;/span&gt;/* subtype of tty driver */&lt;br /&gt;&lt;span style=&quot;mso-tab-count: 1&quot;&gt;&lt;/span&gt;struct ktermios init_termios; /* Initial termios */&lt;br /&gt;&lt;span style=&quot;mso-tab-count: 1&quot;&gt;&lt;/span&gt;int&lt;span style=&quot;mso-tab-count: 1&quot;&gt; &lt;/span&gt;flags;&lt;span style=&quot;mso-tab-count: 2&quot;&gt; &lt;/span&gt;/* tty driver flags */&lt;br /&gt;&lt;span style=&quot;mso-tab-count: 1&quot;&gt;&lt;/span&gt;int&lt;span style=&quot;mso-tab-count: 1&quot;&gt; &lt;/span&gt;refcount;&lt;span style=&quot;mso-tab-count: 1&quot;&gt; &lt;/span&gt;/* for loadable tty drivers */&lt;br /&gt;&lt;span style=&quot;mso-tab-count: 1&quot;&gt;&lt;/span&gt;struct proc_dir_entry *proc_entry; /* /proc fs entry */&lt;br /&gt;&lt;span style=&quot;mso-tab-count: 1&quot;&gt;&lt;/span&gt;struct tty_driver *other; /* only used for the PTY driver */&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;mso-tab-count: 1&quot;&gt;&lt;/span&gt;/*&lt;br /&gt;&lt;span style=&quot;mso-tab-count: 1&quot;&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;/span&gt;* Pointer to the tty data structures&lt;br /&gt;&lt;span style=&quot;mso-tab-count: 1&quot;&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;/span&gt;*/&lt;br /&gt;&lt;span style=&quot;mso-tab-count: 1&quot;&gt;&lt;/span&gt;struct tty_struct **ttys;&lt;br /&gt;&lt;span style=&quot;mso-tab-count: 1&quot;&gt;&lt;/span&gt;struct ktermios **termios;&lt;br /&gt;&lt;span style=&quot;mso-tab-count: 1&quot;&gt;&lt;/span&gt;struct ktermios **termios_locked;&lt;br /&gt;&lt;span style=&quot;mso-tab-count: 1&quot;&gt;&lt;/span&gt;void *driver_state;&lt;span style=&quot;mso-tab-count: 1&quot;&gt; &lt;/span&gt;/* only used for the PTY driver */&lt;br /&gt;&lt;span style=&quot;mso-tab-count: 1&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;mso-tab-count: 1&quot;&gt;&lt;/span&gt;/*&lt;br /&gt;&lt;span style=&quot;mso-tab-count: 1&quot;&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;/span&gt;* Interface routines from the upper tty layer to the tty&lt;br /&gt;&lt;span style=&quot;mso-tab-count: 1&quot;&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;/span&gt;* driver.&lt;span style=&quot;mso-tab-count: 1&quot;&gt; &lt;/span&gt;Will be replaced with struct tty_operations.&lt;br /&gt;&lt;span style=&quot;mso-tab-count: 1&quot;&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;/span&gt;*/&lt;br /&gt;&lt;span style=&quot;mso-tab-count: 1&quot;&gt;&lt;/span&gt;int&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;(*open)(struct tty_struct * tty, struct file * filp);&lt;br /&gt;&lt;span style=&quot;mso-tab-count: 1&quot;&gt;&lt;/span&gt;void (*close)(struct tty_struct * tty, struct file * filp);&lt;br /&gt;&lt;span style=&quot;mso-tab-count: 1&quot;&gt;&lt;/span&gt;int&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;(*write)(struct tty_struct * tty,&lt;br /&gt;&lt;span style=&quot;mso-tab-count: 2&quot;&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;/span&gt;const unsigned char *buf, int count);&lt;br /&gt;&lt;span style=&quot;mso-tab-count: 1&quot;&gt;&lt;/span&gt;void (*put_char)(struct tty_struct *tty, unsigned char ch);&lt;br /&gt;&lt;span style=&quot;mso-tab-count: 1&quot;&gt;&lt;/span&gt;void (*flush_chars)(struct tty_struct *tty);&lt;br /&gt;&lt;span style=&quot;mso-tab-count: 1&quot;&gt;&lt;/span&gt;int&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;(*write_room)(struct tty_struct *tty);&lt;br /&gt;&lt;span style=&quot;mso-tab-count: 1&quot;&gt;&lt;/span&gt;int&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;(*chars_in_buffer)(struct tty_struct *tty);&lt;br /&gt;&lt;span style=&quot;mso-tab-count: 1&quot;&gt;&lt;/span&gt;int&lt;span style=&quot;mso-spacerun: yes&quot;&gt; &lt;/span&gt;(*ioctl)(struct tty_struct *tty, struct file * file,&lt;br /&gt;&lt;span style=&quot;mso-tab-count: 2&quot;&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;/span&gt;unsigned int cmd, unsigned long arg);&lt;br /&gt;&lt;span style=&quot;mso-tab-count: 1&quot;&gt;&lt;/span&gt;long (*compat_ioctl)(struct tty_struct *tty, struct file * file,&lt;br /&gt;&lt;span style=&quot;mso-tab-count: 3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;/span&gt;unsigned int cmd, unsigned long arg);&lt;br /&gt;&lt;span style=&quot;mso-tab-count: 1&quot;&gt;&lt;/span&gt;void (*set_termios)(struct tty_struct *tty, struct ktermios * old);&lt;br /&gt;&lt;span style=&quot;mso-tab-count: 1&quot;&gt;&lt;/span&gt;void (*throttle)(struct tty_struct * tty);&lt;br /&gt;&lt;span style=&quot;mso-tab-count: 1&quot;&gt;&lt;/span&gt;void (*unthrottle)(struct tty_struct * tty);&lt;br /&gt;&lt;span style=&quot;mso-tab-count: 1&quot;&gt;&lt;/span&gt;void (*stop)(struct tty_struct *tty);&lt;br /&gt;&lt;span style=&quot;mso-tab-count: 1&quot;&gt;&lt;/span&gt;void (*start)(struct tty_struct *tty);&lt;br /&gt;&lt;span style=&quot;mso-tab-count: 1&quot;&gt;&lt;/span&gt;void (*hangup)(struct tty_struct *tty);&lt;br /&gt;&lt;span style=&quot;mso-tab-count: 1&quot;&gt;&lt;/span&gt;void (*break_ctl)(struct tty_struct *tty, int state);&lt;br /&gt;&lt;span style=&quot;mso-tab-count: 1&quot;&gt;&lt;/span&gt;void (*flush_buffer)(struct tty_struct *tty);&lt;br /&gt;&lt;span style=&quot;mso-tab-count: 1&quot;&gt;&lt;/span&gt;void (*set_ldisc)(struct tty_struct *tty);&lt;br /&gt;&lt;span style=&quot;mso-tab-count: 1&quot;&gt;&lt;/span&gt;void (*wait_until_sent)(struct tty_struct *tty, int timeout);&lt;br /&gt;&lt;span style=&quot;mso-tab-count: 1&quot;&gt;&lt;/span&gt;void (*send_xchar)(struct tty_struct *tty, char ch);&lt;br /&gt;&lt;span style=&quot;mso-tab-count: 1&quot;&gt;&lt;/span&gt;int (*read_proc)(char *page, char **start, off_t off,&lt;br /&gt;&lt;span style=&quot;mso-tab-count: 3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;/span&gt;int count, int *eof, void *data);&lt;br /&gt;&lt;span style=&quot;mso-tab-count: 1&quot;&gt;&lt;/span&gt;int (*write_proc)(struct file *file, const char __user *buffer,&lt;br /&gt;&lt;span style=&quot;mso-tab-count: 3&quot;&gt;&lt;/span&gt;&lt;span style=&quot;mso-spacerun: yes&quot;&gt;&lt;/span&gt;unsigned long count, void *data);&lt;br /&gt;&lt;span style=&quot;mso-tab-count: 1&quot;&gt;&lt;/span&gt;int (*tiocmget)(struct tty_struct *tty, struct file *file);&lt;br /&gt;&lt;span style=&quot;mso-tab-count: 1&quot;&gt;&lt;/span&gt;int (*tiocmset)(struct tty_struct *tty, struct file *file,&lt;br /&gt;&lt;span style=&quot;mso-tab-count: 3&quot;&gt;&lt;/span&gt;unsigned int set, unsigned int clear);&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;mso-tab-count: 1&quot;&gt;&lt;/span&gt;struct list_head tty_drivers;&lt;br /&gt;};&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0cm 0cm 0pt&quot; class=&quot;MsoPlainText&quot;&gt;&lt;span lang=&quot;EN-US&quot;  style=&quot;font-family:細明體;&quot;&gt;在這個資料結構中其中分為幾個部分，第一個部分是所以謂的callback function的註冊，在這些個callback function中你必須金對你有實現的部分給予註冊，若沒有就可以給予不註冊，但相對的你的驅動程式所支援的功能會較少。另一個部分則是驅動程式本身資訊的資料，如major number、starting minor number、tty device name等等，以下是一個例子：&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0cm 0cm 0pt&quot; class=&quot;MsoPlainText&quot;&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0cm 0cm 0pt&quot; class=&quot;MsoPlainText&quot;&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0cm 0cm 0pt&quot; class=&quot;MsoPlainText&quot;&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;struct tty_driver MySerialDriver;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0cm 0cm 0pt&quot; class=&quot;MsoPlainText&quot;&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;#define MAX_PORTS 4&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0cm 0cm 0pt&quot; class=&quot;MsoPlainText&quot;&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;struct ktermios *my_termios[MAX_PORTS];&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0cm 0cm 0pt&quot; class=&quot;MsoPlainText&quot;&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;struct ktermios *my_termios_locked[MAX_PORTS];&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0cm 0cm 0pt&quot; class=&quot;MsoPlainText&quot;&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0cm 0cm 0pt&quot; class=&quot;MsoPlainText&quot;&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0cm 0cm 0pt&quot; class=&quot;MsoPlainText&quot;&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;memset(&amp;amp;MySerialDriver, 0 sizeof(MySerialDriver));&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0cm 0cm 0pt&quot; class=&quot;MsoPlainText&quot;&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;MySerialDriver.name = &quot;ttyN&quot;;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0cm 0cm 0pt&quot; class=&quot;MsoPlainText&quot;&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;MySerialDriver.major = 40;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0cm 0cm 0pt&quot; class=&quot;MsoPlainText&quot;&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;MySerialDriver.minor_start = 0;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0cm 0cm 0pt&quot; class=&quot;MsoPlainText&quot;&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;MySerialDriver.minor_num = MAX_PORTS;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0cm 0cm 0pt&quot; class=&quot;MsoPlainText&quot;&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;MySerialDriver.num = MAX_PORTS;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0cm 0cm 0pt&quot; class=&quot;MsoPlainText&quot;&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;MySerialDriver.magic = TTY_DRIVER_MAGIC;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0cm 0cm 0pt&quot; class=&quot;MsoPlainText&quot;&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;MySerialDriver.type = TTY_DRIVER_TYPE_SERIAL;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0cm 0cm 0pt&quot; class=&quot;MsoPlainText&quot;&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;MySerialDriver.subtype = SERAL_TYPE_NORMAL;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0cm 0cm 0pt&quot; class=&quot;MsoPlainText&quot;&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;MySerialDriver.init_termios = tty_std_termios;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0cm 0cm 0pt&quot; class=&quot;MsoPlainText&quot;&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;MySerialDriver.init_termios.c_cflag = B9600 CS8 CREAD CLOCAL;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0cm 0cm 0pt&quot; class=&quot;MsoPlainText&quot;&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;MySerialDriver.flags = TTY_DRIVER_REAL_RAW;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0cm 0cm 0pt&quot; class=&quot;MsoPlainText&quot;&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;MySerialDriver.termios = my_termios;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0cm 0cm 0pt&quot; class=&quot;MsoPlainText&quot;&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;MySerialDriver.termios_locked = my_termios_locked;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0cm 0cm 0pt&quot; class=&quot;MsoPlainText&quot;&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0cm 0cm 0pt&quot; class=&quot;MsoPlainText&quot;&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0cm 0cm 0pt&quot; class=&quot;MsoPlainText&quot;&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;MySerialDriver.open = my_open;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0cm 0cm 0pt&quot; class=&quot;MsoPlainText&quot;&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0cm 0cm 0pt&quot; class=&quot;MsoPlainText&quot;&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:x-large;&quot;&gt;以下為driver initialize的工作內容&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0cm 0cm 0pt&quot; class=&quot;MsoPlainText&quot;&gt;&lt;span style=&quot;font-family:細明體;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot; ;font-family:細明體;&quot;&gt;1. allocate tty driver資料結構使用&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0cm 0cm 0pt&quot; class=&quot;MsoPlainText&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;ul&gt;&lt;li&gt;struct tty_driver *mxvar_sdriver=alloc_tty_driver(MXSER_PORTS + 1);&lt;/li&gt;&lt;/ul&gt;2. 在allocate的tty driver資料結構中填入必要的資訊&lt;/span&gt;&lt;p&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0cm 0cm 0pt&quot; class=&quot;MsoPlainText&quot;&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;mxvar_sdriver-&gt;owner = THIS_MODULE;&lt;/li&gt;&lt;li&gt;mxvar_sdriver-&gt;magic = TTY_DRIVER_MAGIC;&lt;/li&gt;&lt;li&gt;mxvar_sdriver-&gt;name = &quot;ttyMI&quot;;&lt;/li&gt;&lt;li&gt;mxvar_sdriver-&gt;major = ttymajor;&lt;/li&gt;&lt;li&gt;mxvar_sdriver-&gt;minor_start = 0;&lt;/li&gt;&lt;li&gt;mxvar_sdriver-&gt;num = MXSER_PORTS + 1;&lt;/li&gt;&lt;li&gt;mxvar_sdriver-&gt;type = TTY_DRIVER_TYPE_SERIAL;&lt;/li&gt;&lt;li&gt;mxvar_sdriver-&gt;subtype = SERIAL_TYPE_NORMAL;&lt;/li&gt;&lt;li&gt;mxvar_sdriver-&gt;init_termios = tty_std_termios;&lt;/li&gt;&lt;li&gt;mxvar_sdriver-&gt;init_termios.c_cflag = B9600|CS8|CREAD|HUPCL|CLOCAL;&lt;/li&gt;&lt;li&gt;mxvar_sdriver-&gt;flags = TTY_DRIVER_REAL_RAW|TTY_DRIVER_DYNAMIC_DEV;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0cm 0cm 0pt&quot; class=&quot;MsoPlainText&quot;&gt;3. 設定tty會使用的各個call back function&lt;/p&gt;&lt;p style=&quot;MARGIN: 0cm 0cm 0pt&quot; class=&quot;MsoPlainText&quot;&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;tty_set_operations(mxvar_sdriver, &amp;amp;mxser_ops);&lt;/li&gt;&lt;/ul&gt;而其中的mxser_ops設定如下:&lt;div&gt;&lt;div&gt;static const struct tty_operations mxser_ops = {&lt;/div&gt;&lt;div&gt;        .open = mxser_open,&lt;/div&gt;&lt;div&gt;        .close = mxser_close,&lt;/div&gt;&lt;div&gt;        .write = mxser_write,&lt;/div&gt;&lt;div&gt;        .put_char = mxser_put_char,&lt;/div&gt;&lt;div&gt;        .flush_chars = mxser_flush_chars,&lt;/div&gt;&lt;div&gt;        .write_room = mxser_write_room,&lt;/div&gt;&lt;div&gt;        .chars_in_buffer = mxser_chars_in_buffer,&lt;/div&gt;&lt;div&gt;        .flush_buffer = mxser_flush_buffer,&lt;/div&gt;&lt;div&gt;        .ioctl = mxser_ioctl,&lt;/div&gt;&lt;div&gt;        .throttle = mxser_throttle,&lt;/div&gt;&lt;div&gt;        .unthrottle = mxser_unthrottle,&lt;/div&gt;&lt;div&gt;        .set_termios = mxser_set_termios,&lt;/div&gt;&lt;div&gt;        .stop = mxser_stop,&lt;/div&gt;&lt;div&gt;        .start = mxser_start,&lt;/div&gt;&lt;div&gt;        .hangup = mxser_hangup,&lt;/div&gt;&lt;div&gt;        .break_ctl = mxser_rs_break,&lt;/div&gt;&lt;div&gt;        .wait_until_sent = mxser_wait_until_sent,&lt;/div&gt;&lt;div&gt;        .tiocmget = mxser_tiocmget,&lt;/div&gt;&lt;div&gt;        .tiocmset = mxser_tiocmset,&lt;/div&gt;&lt;div&gt;};&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0cm 0cm 0pt&quot; class=&quot;MsoPlainText&quot;&gt;4. 向tty_io註冊driver&lt;/p&gt;&lt;p style=&quot;MARGIN: 0cm 0cm 0pt&quot; class=&quot;MsoPlainText&quot;&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;    retval = tty_register_driver(mxvar_sdriver);&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0cm 0cm 0pt&quot; class=&quot;MsoPlainText&quot;&gt;5. 註冊 PCI client或者platform的driver, 等待其call back所設定probe程序&lt;/p&gt;&lt;p style=&quot;MARGIN: 0cm 0cm 0pt&quot; class=&quot;MsoPlainText&quot;&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;     retval = pci_register_driver(&amp;amp;mxser_driver);&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;div&gt;PCI client driver的資料結構如下：&lt;/div&gt;&lt;div&gt;&lt;div&gt;static struct pci_driver mxser_driver = {&lt;/div&gt;&lt;div&gt;        .name = &quot;mxser&quot;,&lt;/div&gt;&lt;div&gt;        .id_table = mxser_pcibrds,&lt;/div&gt;&lt;div&gt;        .probe = mxser_probe,&lt;/div&gt;&lt;div&gt;        .remove = __devexit_p(mxser_remove)&lt;/div&gt;&lt;div&gt;};&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;或者&lt;/div&gt;&lt;div&gt;&lt;ul&gt;&lt;li&gt;retval = platform_register_driver(&amp;amp;mxser_driver);&lt;/li&gt;&lt;/ul&gt;platform client driver的資料結構如下：&lt;/div&gt;&lt;div&gt;&lt;div&gt;static struct platform_driver moxaarm11_gmac_driver = {&lt;/div&gt;&lt;div&gt;        .driver.name    = DRV_NAME,&lt;/div&gt;&lt;div&gt;        .probe          = moxaarm11_gmac_probe,&lt;/div&gt;&lt;div&gt;        .remove         = moxaarm11_gmac_remove,&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;};&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;6. 這時HAL層(PCI or platform)若有找到該元件, 將會呼叫設定的probe call back function&lt;/div&gt;&lt;p style=&quot;MARGIN: 0cm 0cm 0pt&quot; class=&quot;MsoPlainText&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0cm 0cm 0pt&quot; class=&quot;MsoPlainText&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:x-large;&quot;&gt;&lt;b&gt;probe call back function內做的事情&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0cm 0cm 0pt&quot; class=&quot;MsoPlainText&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;1. 取得所分配到的resource, 包含I/O及IRQ&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0cm 0cm 0pt&quot; class=&quot;MsoPlainText&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;2. 向kernel註冊所需的resource, 若是使用memory的方式來存取, 記得需要將取得的physical address用ioremap將其轉換為virtual address&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0cm 0cm 0pt&quot; class=&quot;MsoPlainText&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;3. 註冊IRQ service routine (ISR)&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0cm 0cm 0pt&quot; class=&quot;MsoPlainText&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;4. 針對每一個實體的port向上層tty做註冊&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0cm 0cm 0pt&quot; class=&quot;MsoPlainText&quot;&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;tty_register_device(mxvar_sdriver, brd-&gt;idx + i, &amp;amp;pdev-&gt;dev);&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0cm 0cm 0pt&quot; class=&quot;MsoPlainText&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0cm 0cm 0pt&quot; class=&quot;MsoPlainText&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot; ;font-size:x-large;&quot;&gt;&lt;b&gt;remove call back function內做的事情&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0cm 0cm 0pt&quot; class=&quot;MsoPlainText&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;1. 將取得resource釋放出來&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0cm 0cm 0pt&quot; class=&quot;MsoPlainText&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;2. 將已remap過的virtual address做unremap的動作&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0cm 0cm 0pt&quot; class=&quot;MsoPlainText&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;3. 取消已註冊的ISR&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0cm 0cm 0pt&quot; class=&quot;MsoPlainText&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;4. 針對每一個已註冊的實體port向上層tty做取消的動作&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;MARGIN: 0cm 0cm 0pt&quot; class=&quot;MsoPlainText&quot;&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt; tty_unregister_device(mxvar_sdriver, brd-&gt;idx + i);&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;原則上remove的動作剛好都和probe做相反的動作&lt;/span&gt;&lt;/span&gt;&lt;p&gt;&lt;/p&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot; ;font-size:x-large;&quot;&gt;&lt;b&gt;各個operation call back function內做的事情&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:large;&quot;&gt;這些的call back function都會先經過tty_io的處理之後，才會再呼叫這些call back function。&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:large;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:large;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;open&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;這是當AP呼叫open()時會被呼叫的進入點，但是在呼叫你的open call back function之前，會先經過tty_io處理過，在你的open call back function中如何取得的minor number? 可以從tty_io傳給你的tty_struct structure 中的成員index取得(tty-&gt;index)，你若有控制多port的serial port這時你就可以知道AP要open那一個port，另外linux是一個多工的作業系統，所以有可能多個AP會呼叫下來，也許會open同一個port，這時driver本身自已要記住該port已被open多少次，當是第一個open時需初始化該port，以及buffer的allocate，另外serial port的硬體設定是保留前一個設定，在open時不會做更動。&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:large;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;close&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot; ;font-size:medium;&quot;&gt;從call back的名字就可以知道，這是從AP的close()時的進入點，這個call back function應該檢查是否為最後一個close，也就之前已有多個open()之中的最後一個close(), 記得前面的open會記住被open幾次，在close則相對地減掉被open的數，在最後一次的close時，應將open中所取得的resource應全數release給kernel。&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:large;&quot;&gt;write&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;這是送資料的進入點, 通常我們都會先將資料放在自已的buffer, 之後再慢慢送, 而且通常會使用interrupt的方式來送, 而這個return值會是有多少bytes已存在你的buffer中&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:large;&quot;&gt;put_char&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;serial communication中有所謂software flow control, 它是用資料中兩個bytes XON(0x11), XOFF (0x13)來做這流量控制, 而當要送這個bytes時就會呼叫這一個call back function, 而且這兩個必須要馬上被送出, 不可放在buffer之中, 所以原則上會在這個call back function做一個flag記錄, 而在interrupt service routine中即時送出&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:large;&quot;&gt;flush_chars&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;這是清除本來在put_char中的資料, 若尚未送出將給予丟棄&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:large;&quot;&gt;write_room&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;檢查送的buffer還剩多少空間可以存放資料&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:large;&quot;&gt;char_in_buffer&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;已收進多少資料在driver buffer之中&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:large;&quot;&gt;ioctl&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;這是相對應AP的ioctl() API, 在linux的tty中已定義一些ioctl() command, 應給予支援, 你也可以自行定義一些ioctl()&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:large;&quot;&gt;set_termios&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;設定RS232如baud rate, data bits, stop bits等等, 將會使用struct termios來做設定資料結構&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:large;&quot;&gt;throttle&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;這是在做flow control用的, 在以往hardware不夠好的時候, flow control是軟體來實現, 而且由tty_io來控制, 現在硬體已比以前強了, 所以flow control部分將會由硬體來實現, 而這個將是停止送資料, 不用管是由software flow control or hardware flow control來的, 這個call back function被呼叫時, 就是停止送資料&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:large;&quot;&gt;unthrottle&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;這個動作也是在做flow control, 和上面的throttle相反, 則是開始送資料&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:large;&quot;&gt;stop&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;shutdown該UART port&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:large;&quot;&gt;start&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;啓動該port&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:large;&quot;&gt;hangup&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;這是在接modem時用的, 用在掛電話&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:large;&quot;&gt;&lt;b&gt;break_ctrl&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;這是在送break訊號的控制&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:large;&quot;&gt;&lt;b&gt;flush_buffer&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:large;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-weight: normal;  font-size:medium;&quot;&gt;這是清除在driver buffer中的資料, 將存放在buffer中尚未處理的資料全部給予丟棄&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:large;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-weight: normal;  font-size:medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:large;&quot;&gt;&lt;b&gt;wait_until_sent&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;等待在buffer中尚未送出的資料全部送出, 而且需要block在這裏面&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:large;&quot;&gt;&lt;b&gt;tiocmget&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;最得modem的訊號 CTS, DSR, DCD, RI&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:large;&quot;&gt;&lt;b&gt;tiocmset&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;控制modem訊號 RTS, DTR&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:large;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;在了解各個call back function的定義及作業內容，這時寫driver的人就必須依照這樣的定義來撰寫serial port device driver. 最後最重要的是interrupt service routine, 原則上收送資料都是使用interrupt的方式來收送, 但是在送資料時, 應該是一次就將FIFO填滿, 而收的部分通常設定一個FIFO的high water就產生interrupt, 因為不可在FIFO滿的時候才產生interrupt, 這樣沒有緩衝時間來處理後面持續進來的資料, 容易造成FIFO overflow, 以上是RS232 device driver的大概說明, 其它還有許多細節的部分留待以後再說明&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://victoryuembeddedlinux.blogspot.com/feeds/6104482380402212273/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://victoryuembeddedlinux.blogspot.com/2009/10/serial-port.html#comment-form' title='2 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6198249661133467553/posts/default/6104482380402212273'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6198249661133467553/posts/default/6104482380402212273'/><link rel='alternate' type='text/html' href='http://victoryuembeddedlinux.blogspot.com/2009/10/serial-port.html' title='如何撰寫一個serial port的驅動程式'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiNNPQ4OR9qGjDBR5weOHFEhCMSAb5HSP1LSgx3qeF5VO8llX0Qoocth7pkA659_2Y94h2jbKsNueA1hh13uhmOdT7nsD6uhnoXk3m_5s-m3hOswe5bPC-Sh_NFNaENwusq5ubc_kJNrqNT/s72-c/SerialDriverStructure.jpg" height="72" width="72"/><thr:total>2</thr:total></entry></feed>