From e1aa93ffa72b92ec4eaf6ba40d85ac25c185daa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EA=B7=9C=ED=98=95?= Date: Fri, 31 Mar 2017 11:51:59 +0900 Subject: [PATCH] = Fram sample code --- samplecode/fram/make.sh | 14 ++++++++++++ samplecode/fram/read.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ samplecode/fram/write.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 126 insertions(+) create mode 100755 samplecode/fram/make.sh create mode 100644 samplecode/fram/read.c create mode 100644 samplecode/fram/write.c diff --git a/samplecode/fram/make.sh b/samplecode/fram/make.sh new file mode 100755 index 0000000..4eb3d1b --- /dev/null +++ b/samplecode/fram/make.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +if [ -z "${FA_PRODUCT}" ] +then + echo "" + echo "Check environment variables..." + echo " $> source ../../env-4.9.4.env" + echo "" + exit 1 +fi + +${CROSS_COMPILE}gcc -o write write.c + +${CROSS_COMPILE}gcc -o read write.c diff --git a/samplecode/fram/read.c b/samplecode/fram/read.c new file mode 100644 index 0000000..4da3ba3 --- /dev/null +++ b/samplecode/fram/read.c @@ -0,0 +1,57 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#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 \n",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 +#include +#include +#include +#include +#include +#include +#include + +#define READ_BUF_LEN 2048 +#define WRITE_BUF_LEN 2048 +#define DEV_NAME "/sys/bus/spi/devices/spi0.0/fram" + +int main(int argc, char ** argv) +{ + char *device = NULL; + unsigned char *write_buffer; + int i,j; + unsigned int fd; + unsigned int size; + + device = argv[1]; + + if(argc < 2) + device = DEV_NAME; + + + fd = open (device, O_RDWR); + if(fd < 0) + { + fputs("Error \n",stderr); + exit(1); + } + + write_buffer = (unsigned char *)malloc( sizeof(unsigned char)*WRITE_BUF_LEN ); + memset(write_buffer, 0x0, WRITE_BUF_LEN); + + j=0; + for(i=0;i<2048;i++) + { + write_buffer[i] = 0xff; + + if((i%0x10) == 0) + write_buffer[i] = j++; + } + + size = write(fd, write_buffer, WRITE_BUF_LEN); + printf("size(%d)\n",size); + + free(write_buffer); + close(fd); + + + return 0; +} -- 2.1.4