write.c 897 Bytes
#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_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;
}