Blame view

samplecode/fram/read.c 950 Bytes
e1aa93ffa   larche   = Fram sample code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
  #include <stdio.h>
  #include <stdlib.h>
  #include <unistd.h>
  #include <errno.h>
  #include <signal.h>
  #include <fcntl.h>
  #include <ftw.h>
  #include <string.h>
  
  #define READ_SIZE		512
  #define READ_BUF_LEN	2048
  #define DEV_NAME	"/sys/bus/spi/devices/spi0.0/fram"
  
  int main(int argc, char ** argv)
  {
  	char read_buffer[READ_SIZE]={0,};
  	char *device = NULL;
  	int i,j,k;
  	unsigned int fd;
  	unsigned int size;
  
  	device = argv[1];
  
  	if(argc < 3)
  		device = DEV_NAME;
  
  
  	fd = open (device, O_RDWR);
  	if(fd < 0)
  	{
  		fputs("Error 
  ",stderr);
  		exit(1);
  	}
  
  	printf("       0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F");
  
  
  	for(i=0, k=0; i<4; i++)
  	{
  		size = read(fd, read_buffer, READ_SIZE);
  
  		for(j=0; j<READ_SIZE; j++)
  		{
  			if( !(k%16) )
  				printf("
   %03X: ",k&(~0x1));
  
  			k++;
  			printf("%02X ",read_buffer[j]);
  		}
  		printf("
  =====================================================
  ");
  		printf("ReadSize: %d
  ",size);
  	}
  
  	close(fd);
  
  	return 0;
  }