芯片解密,芯片破解,IC解密,单片机解密,MCU解密,STM解密

飞芯科技提供芯片解密,芯片破解,IC解密,单片机解密,MCU解密,STM解密逆向服务

单片机解密AT91SAM9G25采用控制的 i2c 驱动

单片机解密单片机源程序如下:

  1. //i2c_test.c
  2. 单片机解密#include<stdio.h>  
  3. 单片机解密#include<linux/types.h>  
  4. 单片机解密#include<fcntl.h>  
  5. #include<unistd.h>  
  6. #include<stdlib.h>  
  7. #include<sys/types.h>  
  8. #include<sys/ioctl.h>  
  9. #include<errno.h>  
  10. #include<assert.h>  
  11. #include<string.h>  
  12. #include<linux/i2c.h>  
  13. #include<linux/i2c-dev.h>  

  14. #define CHIP_ADDR_START 0x40
  15. #define CHIP_NUM                1
  16. #define BUF_SIZE 32

  17. #define I2C_DEV "/dev/i2c-1"

  18. static int read_dth(int fd, unsigned char slave_address, unsigned char reg_addr, unsigned char buff[], int count)
  19. {
  20.         int ret;
  21.         struct i2c_rdwr_ioctl_data work_queue;
  22.        
  23.         work_queue.msgs = (struct i2c_msg *)malloc(work_queue.nmsgs *sizeof(struct i2c_msg));
  24.         if(!work_queue.msgs)  
  25.     {  
  26.         printf("read_dth, Memery alloc error\n");  
  27.          
  28.         return -1;  
  29.     }

  30.         work_queue.nmsgs = 2;   
  31.         work_queue.msgs[0].len = 1;   
  32.         work_queue.msgs[0].addr = slave_address;   
  33.         // work_queue.msgs[0].flags = 0;     /* write */   
  34.         work_queue.msgs[0].buf= ®_addr;   

  35.         work_queue.msgs[1].len= count;   
  36.         work_queue.msgs[1].addr= slave_address;   
  37.         work_queue.msgs[1].flags= 1;     /* read */   
  38.         work_queue.msgs[1].buf= buff;   

  39.         ret= ioctl(fd, I2C_RDWR, (unsigned long)&work_queue);   
  40.         if(ret < 0)
  41.         {   
  42.                 printf("readerror\n");     
  43.         }   
  44.         else
  45.         {
  46.                 printf("read  data: %02x%02x from address: %02x\n", buff[0], buff[1], reg_addr);
  47.         }
  48.          
  49.         return ret;
  50. }


  51. static int write_dth(int fd, unsigned char slave_address, unsigned char addr, char buff[], int count)
  52. {
  53.         int ret;
  54.         unsigned char buffer[2];
  55.         struct i2c_rdwr_ioctl_data work_queue;
  56.        
  57.     work_queue.msgs = (struct i2c_msg *)malloc(work_queue.nmsgs *sizeof(struct i2c_msg));
  58.         if(!work_queue.msgs)  
  59.     {  
  60.         printf("write_dth, Memery alloc error\n");  
  61.          
  62.         return -1;  
  63.     }
  64.        
  65.         work_queue.nmsgs = 1;   
  66.         work_queue.msgs[0].len = 2;   
  67.         work_queue.msgs[0].addr = slave_address;   
  68.         work_queue.msgs[0].flags = 0;     /* write */   

  69.           
  70.         work_queue.msgs[0].buf = buffer;   
  71.         work_queue.msgs[0].buf[0]= addr;    /* write address */   
  72.         work_queue.msgs[0].buf[1]= buff[0];  /* write data */   

  73.         ret= ioctl(fd, I2C_RDWR, (unsigned long)&work_queue);   
  74.         if(ret < 0)
  75.         {   
  76.                 printf("writedata error\n");     
  77.         }
  78.         else
  79.         {
  80.                 printf("writedata: %02x to address: %02x\n", buff[0], addr);  
  81.         }       

  82.         return  ret;

  83. }



联系方式

地址:石家庄市新华区民族路77号华强广场D座2009
电话:0311-88816616/87087811
手机:13315190088
传真:0311-67901001
联系人:张工
网址:www.taihedz.cn
邮箱:feixindz@163.com
微信:xinpianjiemi
QQ:527263666/568069805

在线客服
热线电话

企业微信