娇小w搡bbbb搡bbb,《第一次の人妻》,中国成熟妇女毛茸茸,边啃奶头边躁狠狠躁视频免费观看

字符設備驅動(1)代碼分析---之gpio_to_irq

發布者:真情相伴最新更新時間:2025-01-07 來源: cnblogs關鍵字:字符設備驅動  代碼分析 手機看文章 掃描二維碼
隨時隨地手機看文章


/**************************************************************

gpio_to_irq(S5PV210_GPH2(0))

**************************************************************/

 4 #define gpio_to_irq      __gpio_to_irq

 5 

 6 int __gpio_to_irq(unsigned gpio)

 7 {

 8     struct gpio_chip    *chip;

 9     chip = gpio_to_chip(S5PV210_GPH2(0));


static inline struct gpio_chip *gpio_to_chip(unsigned gpio)

{

    return gpio_desc[S5PV210_GPH2(0)].chip; 

    //參考gpio-s5pv210.c中

    //samsung_gpiolib_add_4bit_chips(s5pv210_gpio_4bit, nr_chips)函數

    //gpio_desc[id].chip = chip;

}


10     return chip->to_irq ? chip->to_irq(chip, gpio - chip->base) : -ENXIO;

11     //s5pv210_gpio_4bit

12 }


int samsung_gpiolib_to_irq(struct gpio_chip *chip, unsigned int offset)

{

//獲得gpio_chip結構體所在的父結構體s3c_gpio_chip的指針 

struct s3c_gpio_chip *s3c_chip = container_of(chip,struct s3c_gpio_chip, chip);

//獲取虛擬映射機制中定義的終端號

    return s3c_chip->irq_base + offset;


#define IRQ_EINT(x)        ((x) < 16 ? ((x) + S5P_EINT_BASE1)

                    : ((x) - 16 + S5P_EINT_BASE2))

#define S5P_EINT_BASE2        (IRQ_VIC_END + 1)

#define IRQ_VIC_END        S5P_IRQ_VIC3(31)

#define S5P_IRQ_VIC3(x)        (S5P_VIC3_BASE + (x))

#define S5P_VIC3_BASE        S5P_IRQ(96)

#define S5P_IRQ(x)        ((x) + S5P_IRQ_OFFSET)

#define S5P_IRQ_OFFSET        (32)


#define S5P_EINT_BASE1        (S5P_IRQ_VIC0(0))

#define S5P_IRQ_VIC0(x)        (S5P_VIC0_BASE + (x))

#define S5P_VIC0_BASE        S5P_IRQ(0)


}


static struct s3c_gpio_chip s5pv210_gpio_4bit[] = {

    

    {

        .chip    = {

            .base    = S5PV210_GPA0(0),

            .ngpio    = S5PV210_GPIO_A0_NR,

            .label    = 'GPA0',

        },

    }, 

    ...............

    ...............

    {

     .base    = (S5P_VA_GPIO + 0xC40),

     .config    = &gpio_cfg_noint,

     .irq_base = IRQ_EINT(16),

     .chip    = {

        .base    = S5PV210_GPH2(0),

        .ngpio    = S5PV210_GPIO_H2_NR,

        .label    = 'GPH2',

        .to_irq = samsung_gpiolib_to_irq,

        },

    }, 

    

    {

        .base    = (S5P_VA_GPIO + 0xC60),

        .config    = &gpio_cfg_noint,

        .irq_base = IRQ_EINT(24),

        .chip    = {

            .base    = S5PV210_GPH3(0),

            .ngpio    = S5PV210_GPIO_H3_NR,

            .label    = 'GPH3',

            .to_irq = samsung_gpiolib_to_irq,

        },

    },

};


 1 static __init int s5pv210_gpiolib_init(void)

 2 {

 3     struct s3c_gpio_chip *chip = s5pv210_gpio_4bit;

 4     int nr_chips = ARRAY_SIZE(s5pv210_gpio_4bit);


for (i = 0; i < nr_chips; i++, chip++) {

        if (chip->config == NULL) {

            chip->config = &gpio_cfg;

            chip->group = gpioint_group++;

        }

        if (chip->base == NULL)

            chip->base = S5PV210_BANK_BASE(i);

    }


 6     samsung_gpiolib_add_4bit_chips(s5pv210_gpio_4bit, nr_chips);


void  __init samsung_gpiolib_add_4bit_chips(struct s3c_gpio_chip *chip,

                       int nr_chips)

{

        for (; nr_chips > 0; nr_chips--, chip++)

        {

            samsung_gpiolib_add_4bit(chip);


void __init samsung_gpiolib_add_4bit(struct s3c_gpio_chip *chip)

            {

                    chip->chip.direction_input = samsung_gpiolib_4bit_input;

                    chip->chip.direction_output = samsung_gpiolib_4bit_output;

                    chip->pm = __gpio_pm(&s3c_gpio_pm_4bit);

            }


            s3c_gpiolib_add(chip); 


    __init void s3c_gpiolib_add(struct s3c_gpio_chip *chip)

            {

          //將s3c_gpio_chip 結構體變量s5pv210_gpio_4bit數組中的每一個數組變量 '.chip'傳遞給gpio_chip結構體指針gc

          struct gpio_chip *gc = &chip->chip; 

         //gc    = {

                //    .base    = S5PV210_GPH2(0),

                //    .ngpio    = S5PV210_GPIO_H2_NR,

                //    .label    = 'GPH2',

                //    .to_irq = samsung_gpiolib_to_irq,

                //    },

                int ret;

                spin_lock_init(&chip->lock);

          //給gc結構體指針其他結構體成員賦值

                if (!gc->direction_input)

                    gc->direction_input = s3c_gpiolib_input;

                if (!gc->direction_output)

                    gc->direction_output = s3c_gpiolib_output;

                if (!gc->set)

                    gc->set = s3c_gpiolib_set;

                if (!gc->get)

                    gc->get = s3c_gpiolib_get;


            #ifdef CONFIG_PM

                if (chip->pm != NULL) {

                    if (!chip->pm->save || !chip->pm->resume)

                        printk(KERN_ERR 'gpio: %s has missing PM functionsn',

                               gc->label);

                } else

                    printk(KERN_ERR 'gpio: %s has no PM functionn', gc->label);

            #endif


                // gpiochip_add() prints own failure message on error.

                ret = gpiochip_add(gc);


int gpiochip_add(struct gpio_chip *chip){   

 unsigned long    flags;    int        status = 0;    unsigned    id;

int        base = chip->base; //base = S5PV210_GPH2(0)

  //查看獲得的gpio_chip結構體指針基址和范圍是否在有效范圍之內

    if ((!gpio_is_valid(base) || !gpio_is_valid(base + chip->ngpio - 1))

            && base >= 0) {

        status = -EINVAL;

        goto fail;

    }


    spin_lock_irqsave(&gpio_lock, flags);


    if (base < 0) {

        base = gpiochip_find_base(chip->ngpio);

        if (base < 0) {

            status = base;

            goto unlock;

        }

        chip->base = base;

    }


    //these GPIO numbers must not be managed by another gpio_chip 

    //遍歷某個GPIO端口組的所有IO,如:S5PV210_GPH2端口組的8個IO口S5PV210_GPH2(0)~(7)

 

  for (id = base; id < base + chip->ngpio; id++) 

  {

   //正常狀態gpio_desc[base].chip未被初始化,所以各個成員為NULL

    if (gpio_desc[id].chip != NULL) {

            status = -EBUSY;

            break;

        }

    }

  if (status == 0) {

     for (id = base; id < base + chip->ngpio; id++) {

            gpio_desc[id].chip = chip;

//至此完成gpio_desc[S5PV210_GPH2(0)].chip的賦值,作為返回值在gpio_to_chip()中返回


            // REVISIT:  most hardware initializes GPIOs as

             * inputs (often with pullups enabled) so power

             * usage is minimized.  Linux code should set the

             * gpio direction first thing; but until it does,

             * we may expose the wrong direction in sysfs.

             

[1] [2]
關鍵字:字符設備驅動  代碼分析 引用地址:字符設備驅動(1)代碼分析---之gpio_to_irq

上一篇:Linux嵌入式學習-ds18b20驅動
下一篇:make: Warning: File `led.c' has modification time 15 s in the future

推薦閱讀最新更新時間:2025-04-23 20:10

充分應用功能安全性開發環境中集成的代碼分析工具
目前,越來越多的汽車、工業和其他應用都在強調功能安全性(functional safety),其開發過程也需要先進和完善的工具鏈支持,以及一些重要的開發工具使用經驗。作為功能安全性產品的研發工程師,一定聽說過類似MISRA C的靜態代碼檢查,以及其他一些代碼標準和自動化檢查工具。但是,在日常的開發流程中,僅僅知道這些標準并不代表著能夠高效地讓代碼符合代碼標準。 本文將從代碼標準本身、以及配套的檢查工具如何使用及流程兩方面,通過以業界常見的IAR開發工具鏈為例來提供一些思路,解釋為什么在開發需要安全認證的產品時,推薦使用其自帶的代碼分析工具。在實際應用中,針對Renesas RX和Arm系列內核,C-STAT 靜態代碼分析和 C
[嵌入式]
充分應用功能安全性開發環境中集成的<font color='red'>代碼</font><font color='red'>分析</font>工具
小廣播
設計資源 培訓 開發板 精華推薦

最新單片機文章
何立民專欄 單片機及嵌入式寶典

北京航空航天大學教授,20余年來致力于單片機與嵌入式系統推廣工作。

 
EEWorld訂閱號

 
EEWorld服務號

 
汽車開發圈

 
機器人開發圈

電子工程世界版權所有 京ICP證060456號 京ICP備10001474號-1 電信業務審批[2006]字第258號函 京公網安備 11010802033920號 Copyright ? 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
主站蜘蛛池模板: 娄烦县| 白朗县| 和林格尔县| 江源县| 芒康县| 屯门区| 农安县| 澄城县| 邹城市| 元江| 澎湖县| 金坛市| 凌海市| 新乡县| 清丰县| 诸城市| 桐乡市| 海安县| 神木县| 澄迈县| 河南省| 凤台县| 襄汾县| 福海县| 姚安县| 荆门市| 密山市| 平安县| 隆化县| 中西区| 莱阳市| 鹤山市| 潼南县| 无极县| 金秀| 南涧| 鲜城| 秦安县| 北辰区| 安平县| 江达县|