debug code example in Kernel

本文介绍了LED设备的调试方法,包括调试模式的设置与读取、LED模式及脉冲类型的配置。此外,还深入探讨了针对摄像头传感器的调试策略,如通过I2C接口进行寄存器的读写操作,并提供了具体的实现代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

 debug备忘

========================================= 1 ============================================

static ssize_t led_store_debug_mode(struct device *dev, struct device_attribute *attr,

         const char *buf, size_t count)

{

         sscanf(buf, "%d", &debug_mode);

         pr_info("leds-qpnp: %s debug mode\n",

                            debug_mode ? "enabling" : "disabling");

         return count;

}

static ssize_t led_show_debug_mode(struct device *dev,

                                         struct device_attribute *attr, char *buf)

{

         return snprintf(buf, PAGE_SIZE, "%d\n", debug_mode);

}

 

static DEVICE_ATTR(debug_mode, 0644, led_show_debug_mode, led_store_debug_mode);

 

static int __devinit qpnp_leds_probe(struct spmi_device *spmi)

{

                            rc = device_create_file(led->cdev.dev, &dev_attr_debug_mode);

                            if (rc)

                                     device_remove_file(led->cdev.dev, &dev_attr_debug_mode);

                            break;

}

 

 

========================================= 2 ============================================

static ssize_t led_mode_store(struct device *dev,

                            struct device_attribute *attr,

                            const char *buf, size_t count)

{

         struct qpnp_led_data *led;

         unsigned long state;

         struct led_classdev *led_cdev = dev_get_drvdata(dev);

         ssize_t ret = -EINVAL;

 

         ret = kstrtoul(buf, 10, &state);

         if (ret)

                   return ret;

 

         led = container_of(led_cdev, struct qpnp_led_data, cdev);

 

         return count;

}

 

static ssize_t led_strobe_type_store(struct device *dev,

                            struct device_attribute *attr,

                            const char *buf, size_t count)

{

         struct qpnp_led_data *led;

         unsigned long state;

         struct led_classdev *led_cdev = dev_get_drvdata(dev);

         ssize_t ret = -EINVAL;

 

         ret = kstrtoul(buf, 10, &state);

         if (ret)

                   return ret;

 

         led = container_of(led_cdev, struct qpnp_led_data, cdev);

 

         return count;

}

 

static DEVICE_ATTR(led_mode, 0664, NULL, led_mode_store);

static DEVICE_ATTR(strobe, 0664, NULL, led_strobe_type_store);

 

static struct attribute *led_attrs[] = {

         &dev_attr_led_mode.attr,

         &dev_attr_strobe.attr,

         NULL

};

 

static const struct attribute_group led_attr_group = {

         .attrs = led_attrs,

};

 

static int __devinit qpnp_leds_probe(struct spmi_device *spmi)

{

                            rc = sysfs_create_group(&led->cdev.dev->kobj,

                                                                 &led_attr_group);

}

 

static int __devexit qpnp_leds_remove(struct spmi_device *spmi)

{

                            sysfs_remove_group(&led_array[i].cdev.dev->kobj,

                                                                 &led_attr_group);

                            break;

}

 

 

 

========================================= 3 ============================================

 

#if DEBUG_FLASH_CN

static int foo = 0;

static struct kobject *flash_kobj;

struct qpnp_led_data *flash_debug_led;

 

static ssize_t flash_show(struct kobject *kobj, struct kobj_attribute *attr,

    char *buf)  //cat

{

         foo++;

         pr_err("+++++ flash %s(ID: %d) +++++ \n", __func__, foo);

         qpnp_dump_regs(flash_debug_led, flash_debug_regs, ARRAY_SIZE(flash_debug_regs));

         pr_err("- - - - - - - - - - - - - - \n");

         qpnp_dump_regs_2(flash_debug_led);

         pr_err("----- flash %s(ID: %d) ----- \n", __func__, foo);

         return sprintf(buf, "%d\n", foo);

}

 

static ssize_t flash_store(struct kobject *kobj, struct kobj_attribute *attr,

      const char *buf, size_t count) //echo >

{

          u8 val;

     sscanf(buf, "%d", &foo);

     pr_err("foo = %d.\n",foo);

 

          pr_err("flash %s()++++ \n", __func__);

          qpnp_dump_regs(flash_debug_led, flash_debug_regs, ARRAY_SIZE(flash_debug_regs));

          pr_err("%s(), rewrite some registers start \n", __func__);

 

          spmi_ext_register_readl(flash_debug_led->spmi_dev->ctrl, flash_debug_led->spmi_dev->sid, 0xd352, &val, sizeof(val));

          pr_err("%s(), rewrite reg0xd352=0x%x to 0x%x.\n", __func__, val, val&0x7F);

          val &= 0x7F;

          spmi_ext_register_writel(flash_debug_led->spmi_dev->ctrl, flash_debug_led->spmi_dev->sid, 0xd352, &val, sizeof(val));

          pr_err("%s(), rewrite some registers end \n", __func__);

         return count;

}

 

static struct kobj_attribute flash_attribute =

      __ATTR(fd_node, 0666, flash_show, flash_store);

 

/*

* Create a group of attributes so that we can create and destroy them all

* at once.

*/

static struct attribute *attrs[] = {

      &flash_attribute.attr,

      NULL,  /* need to NULL terminate the list of attributes */

};

 

/*

* An unnamed attribute group will put all of the attributes directly in

* the kobject directory.  If we specify a name, a subdirectory will be

* created for the attributes with the directory being the name of the

* attribute group.

*/

static struct attribute_group flash_attr_group = {

      .attrs = attrs,

};

 

static int __devinit qpnp_leds_probe(struct spmi_device *spmi)

{

#if DEBUG_FLASH_CN

     /*

      * Create a simple kobject with the name of "flash_debug",

      * located under /sys/kernel/

      *

      * As this is a simple directory, no uevent will be sent to

      * userspace.  That is why this function should not be used for

      * any type of dynamic kobjects, where the name and number are

      * not known ahead of time.

      */

          sprintf(flash_debug_dir, "flash_debug%d", led->id);

          pr_err("[CNYL]: create flash(%d) debug node start!\n", led->id);

     flash_kobj = kobject_create_and_add(flash_debug_dir, kernel_kobj);

     if (!flash_kobj)

          return -ENOMEM;

 

     /* Create the files associated with this kobject */

     retval = sysfs_create_group(flash_kobj, &flash_attr_group);

     if (retval) {

          kobject_put(flash_kobj);

                     pr_err("[CNYL]: create flash debug node failed.\n");

          }

          flash_debug_led = led;

          pr_err("[CNYL]: create flash(%d) debug node done!\n", led->id);

#endif

}

  

========================================= 4 ============================================

diff --git a/drivers/media/platform/msm/camera_v2/sensor/ar0543.c b/drivers/media/platform/msm/camera_v2/sensor/ar0543.c

index abaa4bd..e22d0f1 100755

--- a/drivers/media/platform/msm/camera_v2/sensor/ar0543.c

+++ b/drivers/media/platform/msm/camera_v2/sensor/ar0543.c

@@ -16,6 +16,8 @@

#define AR0543_SENSOR_NAME "ar0543"

DEFINE_MSM_MUTEX(ar0543_mut);

 

+#define SENSOR_KERNEL_DEBUG 1

+

static struct msm_sensor_ctrl_t ar0543_s_ctrl;

 

 static struct msm_sensor_power_setting ar0543_power_setting[] = {

@@ -145,6 +147,108 @@ static struct platform_driver ar0543_platform_driver = {

         },

};

 

+#if SENSOR_KERNEL_DEBUG

+static struct msm_camera_i2c_reg_array reg_w;

+static ssize_t sensor_status_show(struct device *dev,

+        struct device_attribute *attr, char *buf)

+{

+     ssize_t length = 0;

+       length = sprintf(buf, "sensor reg dump:\n"

+                                                               "    random read,addr-value:0x%04x - 0x%04x.%s\n",

+                                                                        reg_w.reg_addr, reg_w.reg_data,

+                                                                        (reg_w.reg_data != 0) ? " " : " (Have you read already?)"

+                                                               );

+/*

+    length = sprintf(buf, "debug Information(version: 20131030):\n"

+                                   "[R]    command:  reset the following parameters.\n"

+                                "[s]    msleep_time:\t%dms (effect in each AF/CAF).\n"

+                                "[i]    step_interval:\t%d (effect in opening camera).\n"

+                                "[l/h]  focuser range:\t%d--%d.\n"

+                                "[f]    flag_debug_foc:\t%d (%s).\n"

+                                "[p]    set_lens_pos:\t%d (enc_set:0x%x, enc_check:0x%x, diff: 0x%x).\n",

+                                tinfo.msleep_time,

+                                   tinfo.step_interval,

+                                   tinfo.pos_low, tinfo.pos_high,

+                                   tinfo.flag_debug_foc, tinfo.flag_debug_foc ? "Debug Mode" : "Normal Mode",

+                                   tinfo.set_lens_pos, tinfo.enc_set_lens_pos, tinfo.enc_actual_lens_pos, abs_closeloop(tinfo.enc_set_lens_pos-tinfo.enc_actual_lens_pos)

+                                );

+*/

+        return length;

+}

+

+

+static ssize_t sensor_attr_set(struct device *dev,

+        struct device_attribute *attr, const char *buf, size_t count)

+{

+        int err;

+        const char *ptr = buf + 1;

+        //u8 ch;

+        //size_t idx = 0;

+        //u32 val = 0;

+                char reg_buf[7], data_buf[7];

+

+                *(reg_buf + 6) = '\0';

+                *(data_buf + 6) = '\0';

+

+        if (count <= 1)

+                return count;

+

+        if (ptr) {

+                          switch (buf[0]) {

+                          case 'R':

+                                            break;

+                          case 'w'://format: w0xABCD,0xEFGH

+                                   //if (count <= 1)

+                                   //return count;

+                          memcpy(reg_buf, (buf + 1), 6);

+                          memcpy(data_buf, (buf + 8), 6);

+                          reg_w.reg_addr  = (unsigned short)simple_strtoul(reg_buf,   NULL, 16);

+                          reg_w.reg_data   = (unsigned short)simple_strtoul(data_buf, NULL, 16);

+                                                      pr_info("SENSOR write{0x%04X, 0x%04X}.\n", reg_w.reg_addr, reg_w.reg_data);

+                          err = ar0543_s_ctrl.sensor_i2c_client->i2c_func_tbl->i2c_write(ar0543_s_ctrl.sensor_i2c_client, reg_w.reg_addr, reg_w.reg_data, MSM_CAMERA_I2C_WORD_DATA);

+                          reg_w.reg_data = 0;

+                          if (err)

+                                   return err;

+                          break;

+                          case 'r'://format: r0xABCD

+                                            //if (count <= 1)

+                                                      //return count;

+                          memcpy(reg_buf, (buf + 1), 6);

+                          reg_w.reg_addr  = (unsigned short)simple_strtoul(reg_buf,   NULL, 16);

+                                                      pr_info("SENSOR read{0x%04X}.\n", reg_w.reg_addr);

+                          err = ar0543_s_ctrl.sensor_i2c_client->i2c_func_tbl->i2c_read(ar0543_s_ctrl.sensor_i2c_client, reg_w.reg_addr, &(reg_w.reg_data), MSM_CAMERA_I2C_WORD_DATA);

+                          if (err)

+                                   return err;

+                          break;

+                }

+                }

+

+        return count;

+}

+

+static DEVICE_ATTR(d, 0775, sensor_status_show, sensor_attr_set);

+struct kobject *keobj;

+

+static int drv_sensor_sysfs_init(void /*struct test_info_t *info*/)

+{

+        keobj = kobject_create_and_add("sensor", NULL);

+        if (!keobj) {

+                pr_err("%s subsystem register failed!\n", __func__);

+                return -ENOMEM;

+        }

+

+        if (sysfs_create_file(keobj, &dev_attr_d.attr)) {

+                pr_err("%s sysfs create file failed!\n", __func__);

+                kobject_del(keobj);

+                keobj = NULL;

+                return -ENOMEM;

+        }

+        //ker_info = info;

+

+        return 0;

+}

+#endif

+

static int32_t ar0543_platform_probe(struct platform_device *pdev)

{

         int32_t rc = 0;

@@ -152,6 +256,11 @@ static int32_t ar0543_platform_probe(struct platform_device *pdev)

 

        match = of_match_device(ar0543_dt_match, &pdev->dev);

         rc = msm_sensor_platform_probe(pdev, match->data);

+

+#if SENSOR_KERNEL_DEBUG

+       drv_sensor_sysfs_init();

+#endif

+

         return rc;

}


 

### APP_MSG_SYS_EVENT in Android Development In the context of Android development, `APP_MSG_SYS_EVENT` typically refers to a message type used within certain frameworks or libraries for inter-component communication. However, specific documentation directly addressing this exact term might be sparse. For profiling and debugging applications on Android devices, especially those running on OMAP4 processors with Ice Cream Sandwich (ICS), challenges can arise from using newer versions of tools like OProfile due to compatibility issues[^1]. To address these concerns effectively: - **Using Older Versions**: It may prove beneficial to revert to earlier versions of binary packages such as OProfile along with customized scripts designed specifically for ICS on OMAP4 platforms. When dealing with system events at lower levels, accessing detailed information about kernel activities becomes crucial. Kernel-level symbols necessary for deeper analysis reside either within dedicated debug info packages or through compiling kernels configured with support for all symbol tables (`CONFIG_KALLSYMS`) option enabled[^2]. To troubleshoot problems related to `APP_MSG_SYS_EVENT`, consider implementing comprehensive logging mechanisms around where messages are sent and received. This approach helps trace back any anomalies observed during runtime operations without relying solely on external profilers which could introduce additional complexities. Additionally, leveraging built-in diagnostic features provided by Android SDKs alongside third-party monitoring solutions tailored towards mobile environments would enhance visibility into application behavior under various conditions including handling system-wide notifications represented possibly via constructs similar to what `APP_MSG_SYS_EVENT` signifies. ```java // Example code snippet demonstrating how one might implement enhanced logging around message passing public void handleMessage(Message msg) { switch(msg.what){ case MSG_TYPE_APP_MSG_SYS_EVENT: Log.d(TAG, "Handling APP_MSG_SYS_EVENT"); // Your logic here... break; default: super.handleMessage(msg); } } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值