国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 操作系統 > 正文

四、GPIO

2024-06-28 13:26:11
字體:
來源:轉載
供稿:網友
四、GPIO轉載請注明轉自:http://www.CUOXin.com/connectfuture/參考自linux-2.6.32.61/Documentation/一、簡介

GPIO全稱是General Purpose Input/Output,其關聯SOC上的一個管腳。平臺會分配相應的GPIO和外設關聯,諸如audio codec外設,GPIO和平臺強相關。

GPIO可由平臺配置輸入輸出,輸出即可寫,高電平為1,低電平為0。輸入即可讀,除了讀入數據外,輸入還能作為中斷信號。

二、GPIO標識

GPIO標識有效范圍在0..MAX_INT,負數代表該平臺不支持(可用作初始化)。

平臺定義了它們如何使用這些接口,并且通常為每個GPIO線使用#define宏定義符號,以便單板的啟動代碼與相關設計直接保持一致。與此相反,驅動應該只使用從setup代碼傳遞給他們的GPIO號碼,使用platform_data來保存單板特定的管腳配置數據(與其它所需的單板特定數據一起)。這避免了移植問題。

諸如一個平臺使用32-159,另一個平臺使用0-64。

int gpio_is_valid(int number);

可用此函數判斷此gpio線是否有效。

三、GPIO使用
  • 分配gpio

/* request GPIO, returning 0 or negative errno. * non-null labels may be useful for diagnostics. */ int gpio_request(unsigned gpio, const char *label); /* release PReviously-claimed GPIO */ void gpio_free(unsigned gpio);

此函數實現兩個目的:

  1. 標識使用gpio的信號。
  2. 防止沖突,多個驅動使用互斥的同一個信號,使用gpio_request可作為鎖。

Note that requesting a GPIO does NOT cause it to be configured in any way; it just marks that GPIO as in use. Separate code must handle any pin setup (e.g. controlling which pin the GPIO uses, pullup/pulldown).

Also note that it's your responsibility to have stopped using a GPIO before you free it.

  • 標記gpio的方向

/* set as input or output, returning 0 or negative errno */ int gpio_direction_input(unsigned gpio); int gpio_direction_output(unsigned gpio, int value);

  • Spinlock-Safe GPIO 訪問

/* GPIO INPUT: return zero or nonzero */ int gpio_get_value(unsigned gpio); /* GPIO OUTPUT */ void gpio_set_value(unsigned gpio, int value);

  • 可睡的GPIO訪問

int gpio_cansleep(unsigned gpio);

/* GPIO INPUT: return zero or nonzero, might sleep */ int gpio_get_value_cansleep(unsigned gpio); /* GPIO OUTPUT, might sleep */ void gpio_set_value_cansleep(unsigned gpio, int value);

Other than the fact that these calls might sleep, and will not be ignored for GPIOs that can't be accessed from IRQ handlers, these calls act the same as the spinlock-safe calls.

  • gpio輸入作為中斷信號

  /* map GPIO numbers to IRQ numbers */ int gpio_to_irq(unsigned gpio);

  /* map IRQ numbers to GPIO numbers (avoid using this) */ int irq_to_gpio(unsigned irq);

gpio和中斷線都是用整形標識的,其在兩個name space中,這兩個函數建立了gpio和中斷線之間的映射關系


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 丹江口市| 九龙坡区| 乌兰察布市| 保亭| 洛川县| 磐石市| 泰和县| 汨罗市| 綦江县| 嘉兴市| 朝阳县| 平乡县| 澄迈县| 龙游县| 威远县| 万安县| 达拉特旗| 麻阳| 华亭县| 望江县| 礼泉县| 灌云县| 六盘水市| 岱山县| 洛宁县| 迭部县| 涞源县| 诸暨市| 遂昌县| 湘潭县| 金沙县| 河津市| 泰州市| 金门县| 苏尼特右旗| 龙江县| 吉木乃县| 黔江区| 长阳| 黄梅县| 兴隆县|