CODE EXAMPLE 3-6 Sample User Flash Application Program (Continued)
case ’1’: /* write to user flash PROM */ fprintf(stderr,
"Enter PROM offset[0, 0xXX,XXXX]> "); scanf ("%x", &offset);
fprintf(stderr,
"Enter number of bytes[hex]> "); scanf ("%x", &size);
fprintf(stderr,
"Enter data pattern[0, 0xFF]> ");
scanf ("%x", &pat);
/*
*init write buffer.
*/
for (i = 0; i < size; i++) { w_buf[i] = pat;
}
n_byte = pwrite (fd, w_buf, size, offset); if (n_byte != size) {
/* the write failed */
printf ("Write process was failed at byte 0x%x \n", n_byte);
}
break;
case ’0’: /* read from user flash PROM */ fprintf(stderr,
"Enter PROM offset[0, 0xXX,XXXX]> "); scanf ("%x", &offset);
fprintf(stderr,
"Enter number of bytes[hex]> "); scanf ("%x", &size);
getchar(); /* clean up the char buf */
n_byte = pread (fd, r_buf, size, offset); if (n_byte != size) {
/* the read failed */
printf ("Read process was failed at \ byte 0x%x \n",
n_byte);
continue;
Chapter 3 User Flash 57