In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Today, the editor will share with you the relevant knowledge about how Android reads and writes eeprom. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.
Android 9 read and write eeprom
It is relatively easy for linux to read eeprom because most of the eeprom drivers are integrated in the kernel and the file directory is in kernel/drivers/misc/eeprom/at24.c.
And we don't have to distinguish between the different ways of reading and writing caused by the different capacity of at24cxx, just compile at24.c to the kernel, and then register the corresponding i2C channel in dts. The module a0a1a2 in hand is grounded, so the device address is 0xa0, while the device address is registered as seven-bit address in dts, namely 0x50.
& i2c1 {status = "okay"; clock-frequency =; pinctrl-names= "default"; pinctrl-0=; at24c256@50 {compatible = "at24,24c256"; reg =; status = "okay";};}
In theory, after upgrading the compiled kernel, you should find the eeprom node under the corresponding i2C node, but you can't find this node. Look at the code and find out that there is such a thing.
At24- > nvmem_config.name = dev_name (& client- > dev); at24- > nvmem_config.dev = & client- > dev; at24- > nvmem_config.read_only =! writable; at24- > nvmem_config.root_only = true; at24- > nvmem_config.owner = THIS_MODULE; at24- > nvmem_config.compat = true; at24- > nvmem_config.base_dev = & client- > dev At24- > nvmem_config.reg_read = at24_read; at24- > nvmem_config.reg_write = at24_write; at24- > nvmem_config.priv = at24; at24- > nvmem_config.stride = 1; at24- > nvmem_config.word_size = 1; at24- > nvmem_config.size = chip.byte_len; at24- > nvmem = nvmem_register (& at24- > nvmem_config) If (IS_ERR (at24- > nvmem)) {err = PTR_ERR (at24- > nvmem); goto err_clients;}
The original new kernel introduced the nvmem architecture to operate on eeprom. Reconfigure the kernel, turn on the compile option for nvmem, and find the node of nvmem after the upgrade.
The operation of the application layer to the eeprom is through this node.
Write an application layer code:
# include # include "android/log.h" # include # define FILE_PATH "/ sys/bus/nvmem/devices/1-00500/nvmem" int main () {int fd;int size;char data [512] = {0}; char r_data [64] = {0}; char * w_data = "Hello worded good Day!\ n"; fd = open (FILE_PATH, O_RDWR) If (fd < 0) {printf ("Can't open file% s\ r\ n", FILE_PATH); return-1;} lseek (fd,0,SEEK_SET); write (fd,data,sizeof (data)); / / erase eepromlseek (fd,0,SEEK_SET); write (fd,w_data,strlen (w_data)); lseek (fd,0,SEEK_SET); size = read (fd,r_data,sizeof (r_data)) Printf ("read data==%s\ n", r_data); close (fd); return 0;}
Android.mk
LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) LOCAL_SRC_FILES:= max.cLOCAL_MODULE: = maxLOCAL_MODULE_TAGS: = optionalLOCAL_SHARED_LIBRARIES + =\ libcutils\ liblog LOCAL_MODULE_PATH: = $(PRODUCT_OUT) / vendor/bininclude $(BUILD_EXECUTABLE)
These are all the contents of the article "how to read and write eeprom by Android". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.