Commit e1aa93ffa72b92ec4eaf6ba40d85ac25c185daa8
1 parent
1ae11bd942
Exists in
master
and in
2 other branches
= Fram sample code
Showing
3 changed files
with
126 additions
and
0 deletions
Show diff stats
samplecode/fram/make.sh
... | ... | @@ -0,0 +1,14 @@ |
1 | +#!/bin/bash | |
2 | + | |
3 | +if [ -z "${FA_PRODUCT}" ] | |
4 | +then | |
5 | + echo "" | |
6 | + echo "Check environment variables..." | |
7 | + echo " $> source ../../env-4.9.4.env" | |
8 | + echo "" | |
9 | + exit 1 | |
10 | +fi | |
11 | + | |
12 | +${CROSS_COMPILE}gcc -o write write.c | |
13 | + | |
14 | +${CROSS_COMPILE}gcc -o read write.c | ... | ... |
samplecode/fram/read.c
... | ... | @@ -0,0 +1,57 @@ |
1 | +#include <stdio.h> | |
2 | +#include <stdlib.h> | |
3 | +#include <unistd.h> | |
4 | +#include <errno.h> | |
5 | +#include <signal.h> | |
6 | +#include <fcntl.h> | |
7 | +#include <ftw.h> | |
8 | +#include <string.h> | |
9 | + | |
10 | +#define READ_SIZE 512 | |
11 | +#define READ_BUF_LEN 2048 | |
12 | +#define DEV_NAME "/sys/bus/spi/devices/spi0.0/fram" | |
13 | + | |
14 | +int main(int argc, char ** argv) | |
15 | +{ | |
16 | + char read_buffer[READ_SIZE]={0,}; | |
17 | + char *device = NULL; | |
18 | + int i,j,k; | |
19 | + unsigned int fd; | |
20 | + unsigned int size; | |
21 | + | |
22 | + device = argv[1]; | |
23 | + | |
24 | + if(argc < 3) | |
25 | + device = DEV_NAME; | |
26 | + | |
27 | + | |
28 | + fd = open (device, O_RDWR); | |
29 | + if(fd < 0) | |
30 | + { | |
31 | + fputs("Error \n",stderr); | |
32 | + exit(1); | |
33 | + } | |
34 | + | |
35 | + printf(" 0 1 2 3 4 5 6 7 8 9 A B C D E F"); | |
36 | + | |
37 | + | |
38 | + for(i=0, k=0; i<4; i++) | |
39 | + { | |
40 | + size = read(fd, read_buffer, READ_SIZE); | |
41 | + | |
42 | + for(j=0; j<READ_SIZE; j++) | |
43 | + { | |
44 | + if( !(k%16) ) | |
45 | + printf("\n %03X: ",k&(~0x1)); | |
46 | + | |
47 | + k++; | |
48 | + printf("%02X ",read_buffer[j]); | |
49 | + } | |
50 | + printf("\n=====================================================\n"); | |
51 | + printf("ReadSize: %d\n",size); | |
52 | + } | |
53 | + | |
54 | + close(fd); | |
55 | + | |
56 | + return 0; | |
57 | +} | ... | ... |
samplecode/fram/write.c
... | ... | @@ -0,0 +1,55 @@ |
1 | +#include <stdio.h> | |
2 | +#include <stdlib.h> | |
3 | +#include <unistd.h> | |
4 | +#include <errno.h> | |
5 | +#include <signal.h> | |
6 | +#include <fcntl.h> | |
7 | +#include <ftw.h> | |
8 | +#include <string.h> | |
9 | + | |
10 | +#define READ_BUF_LEN 2048 | |
11 | +#define WRITE_BUF_LEN 2048 | |
12 | +#define DEV_NAME "/sys/bus/spi/devices/spi0.0/fram" | |
13 | + | |
14 | +int main(int argc, char ** argv) | |
15 | +{ | |
16 | + char *device = NULL; | |
17 | + unsigned char *write_buffer; | |
18 | + int i,j; | |
19 | + unsigned int fd; | |
20 | + unsigned int size; | |
21 | + | |
22 | + device = argv[1]; | |
23 | + | |
24 | + if(argc < 2) | |
25 | + device = DEV_NAME; | |
26 | + | |
27 | + | |
28 | + fd = open (device, O_RDWR); | |
29 | + if(fd < 0) | |
30 | + { | |
31 | + fputs("Error \n",stderr); | |
32 | + exit(1); | |
33 | + } | |
34 | + | |
35 | + write_buffer = (unsigned char *)malloc( sizeof(unsigned char)*WRITE_BUF_LEN ); | |
36 | + memset(write_buffer, 0x0, WRITE_BUF_LEN); | |
37 | + | |
38 | + j=0; | |
39 | + for(i=0;i<2048;i++) | |
40 | + { | |
41 | + write_buffer[i] = 0xff; | |
42 | + | |
43 | + if((i%0x10) == 0) | |
44 | + write_buffer[i] = j++; | |
45 | + } | |
46 | + | |
47 | + size = write(fd, write_buffer, WRITE_BUF_LEN); | |
48 | + printf("size(%d)\n",size); | |
49 | + | |
50 | + free(write_buffer); | |
51 | + close(fd); | |
52 | + | |
53 | + | |
54 | + return 0; | |
55 | +} | ... | ... |