Static Device_attr (val, S_irugo | S_IWUSR, Hello_val_show, Hello_val_store); The role

Source: Internet
Author: User

In Lao Luo's Android routines there are

Static Device_attr (val, S_irugo | S_IWUSR, Hello_val_show, Hello_val_store);

/* Read Device properties val*/

  • Static ssize_t hello_val_show (struct device* dev, struct device_attribute* attr, char* buf) {
  • struct hello_android_dev* Hdev = (struct hello_android_dev*) dev_get_drvdata (dev);
  • return __hello_get_val (Hdev, buf);
  • }
  • /* Write device Properties val*/
  • Static ssize_t Hello_val_store (struct device* dev, struct device_attribute* attr, const char* buf, si ze_t count) {
  • struct hello_android_dev* Hdev = (struct hello_android_dev*) dev_get_drvdata (dev);
  • return __hello_set_val (Hdev, buf, Count);
  • }

In this way, you can change/display the value of the Val variable in the serial terminal

# Cat Hello
0
# echo ' 5 ' > Hello
# # echo ' 5 ' > Hello # cat Hello
5

The original is static Device_attr (val, S_irugo | S_IWUSR, Hello_val_show, Hello_val_store);

The role

Prototypes are # define DEVICE_ATTR (_name, _mode, _show, _store) \

struct Device_attribute dev_attr_# #_name = __attr (_name, _mode, _show, _store)

The function macro device_attr is encapsulated in the __attr (_name,_mode,_show,_stroe) method, _show represents the Read method, and _stroe represents the Write method.

When we echo the data into the interface, we actually complete a write operation on the upper layer, which corresponds to kernel, and calls the "store" in the driver. Similarly, "show" is called when we have a cat interface. Here, simply built the android layer to the kernel bridge, the actual implementation of the hardware operation, or in the "show" and "store" completed

Static Device_attr (val, S_irugo | S_IWUSR, Hello_val_show, Hello_val_store); The role

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.