Blame view

samplecode/fram/fram_test.c 1.68 KB
543e61c65   larche   = JIG Test 관련 스크립...
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
  #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 RW_SIZE		32
  
  #define DEV_NAME    "/sys/bus/spi/devices/spi0.0/fram"
  
  unsigned char *cWriteBuffer = NULL;
  unsigned char *cReadBuffer = NULL;
  
  
  int RWDateCompare(void)
  {
  	int i;
  
  	for(i=0; i<RW_SIZE; i++)
  	{
  		if( cWriteBuffer[i] != cReadBuffer[i] )
  			return -1;
  	}
  
  	return 0;
  }
  
  int Fram_Write(int fd)
  {
  	int ret;
  
  	lseek(fd, 0, SEEK_SET);
  	ret = write(fd, cWriteBuffer, RW_SIZE);
  
  	if(ret != RW_SIZE) 
  	{
  		fputs("Error Write()
  ",stderr);
  		free(cWriteBuffer);
  		free(cReadBuffer);
  		exit(-EIO);
  	}
  
  	return 0;
  }
  
  int Fram_Read(int fd)
  {
  	int ret;
  
  	lseek(fd, 0, SEEK_SET);
  	ret = read(fd, cReadBuffer, RW_SIZE);
  
  	if(ret != RW_SIZE)
  	{
  		fputs("Error Read()
  ",stderr);
  		free(cWriteBuffer);
  		free(cReadBuffer);
  		exit(-EIO);
  	}
  
  	return 0;
  }
  
  
  int main(int argc, char **argv)
  {
  
  	int ret, i;
  	unsigned int fd;
  
  	printf("### Fram Read/Write Test App Start!! ###
  ");
  	cWriteBuffer = (unsigned char *)malloc( sizeof(unsigned char)*RW_SIZE);
  	if( cWriteBuffer == NULL)
  		return -ENOMEM;
  
  	cReadBuffer = (unsigned char *)malloc( sizeof(unsigned char)*RW_SIZE);
  	if( cReadBuffer == NULL)
  		return -ENOMEM;
  
  	memset(cWriteBuffer, 0, RW_SIZE);
  	memset(cReadBuffer, 0, RW_SIZE);
  
  	fd = open (DEV_NAME, O_RDWR);
  	if(fd < 0) {
  		fputs("Error open()
  ",stderr);
  		free(cWriteBuffer);
  		free(cReadBuffer);
  		return -ENODEV;
  	}
  
  	// Init 0 (32Byte)
  	Fram_Write(fd);
  
  	// Set Value
  	for(i=0; i<RW_SIZE; i++)
  		cWriteBuffer[i] = i;
  
  
  	Fram_Write(fd);
  
  	Fram_Read(fd);
  
  	ret = RWDateCompare();
  
  	printf("### Fram Read/Write Test App End!! ###
  ");
  	return ret;
  }