国产探花免费观看_亚洲丰满少妇自慰呻吟_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和中斷線之間的映射關系


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 辽阳市| 呈贡县| 郁南县| 黎平县| 抚宁县| 贵南县| 泉州市| 封丘县| 海口市| 蕉岭县| 河源市| 兰西县| 梨树县| 霍林郭勒市| 建宁县| 平原县| 永登县| 濉溪县| 永吉县| 济源市| 同德县| 丰城市| 高碑店市| 凌源市| 象山县| 巴楚县| 衡东县| 武城县| 曲阜市| 东光县| 东乌| 定襄县| 汶上县| 石景山区| 中方县| 华蓥市| 桂阳县| 隆子县| 卫辉市| 连州市| 衢州市|