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