CODE EXAMPLE 3-3 Read Action on User Flash Device (Continued)
printf("number of blocks = 0x%p", ufif0.info.blk_num); printf("block size = 0x%p" ufif0.info.blk_size);
}
static int
uflash_uninit() { if (ufd0)
close(ufd0);
cleanup: if (buf0)
free(buf0);
}
static int uflash_read() {
/* read block 0 of user flash */
if (pread(ufd0, buf0, ufif0.info.blk_size, 0) != ufif0.info.blk_size) perror("uflash0:read");
return(0);
}
main() { int ret;
module = argv[0]; ret = uflash_init(); if (!ret)
uflash_read(); uflash_uninit();
}
Write Example Program
CODE EXAMPLE
CODE EXAMPLE 3-4 Write Action on User Flash Device
/*
*uflash_write.c
*An example that shows how to write user flash
*/
#include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <errno.h> #include <uflash_if.h>
char *uflash0 = "/dev/uflash0";
Chapter 3 User Flash 49