Sun Microsystems CP2500 manual Code Example 3-4Write Action on User Flash Device

Page 64

CODE EXAMPLE 3-4Write Action on User Flash Device (Continued)

int ufd0;

uflash_if_t ufif0; char *buf0;

char *module; static int uflash_init() {

char *buf0 = malloc(ufif0.info.blk_size); if (!buf0) {

printf("%s: cannot allocate memory\n", module); return(-1);

}

/* open device */

if ((ufd0 = open(uflash0, O_RDWR)) == -1 ) { perror("uflash0: ");

exit(1);

}

/* get uflash sizes */

if (ioctl(ufd0, UIOCIBLK, &ufif0) == -1 ) { perror("ioctl(ufd0, UIOCIBLK): "); exit(1);

}

if (ufd0) {

printf("%s: \n", uflash0);

printf("manfacturer id = 0x%p\n", ufif0.info.mfr_id); printf("device id = 0x%p\n", ufif0.info.dev_id); 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_write() {

int i;

/* write some pattern to the buffers */

for (i = 0; i < ufif0.info.blk_size; i += sizeof(int)) *((int *) (buf0 + i)) = 0xDEADBEEF;

/* write block 0 of user flash */

if (pwrite(ufd0, buf0, ufif0.info.blk_size, 0) != ufif0.info.blk_size) perror("uflash0:write");

return(0);

50 Netra CP2500 Board Programming Guide • March 2007

Image 64
Contents Netra CP2500 Board Programming Guide Page Contents User Flash Figures Vi Netra CP2500 Board Programming Guide March Tables Viii Netra CP2500 Board Programming Guide March Code Samples Netra CP2500 Board Programming Guide March Preface How This Book Is OrganizedUsing Unix Commands Typographic ConventionsShell Prompts Related DocumentationThird-Party Web Sites Documentation, Support, and TrainingSun Welcomes Your Comments Watchdog Timer OverviewPicl Plug-In Module 1Watchdog Plug-In Interfaces for Netra CP2500 Board Software 2Properties Under watchdog-controllerNode3Properties Under watchdog-timerNode HEALTHY#Watchdog Node Management Code Code Example 1-1System Watchdog Node Management Code ExampleCode Example 1-1System Watchdog Node Management Code Example Usagestr Code Example 1-1System Watchdog Node Management Code Example Code Example 1-1System Watchdog Node Management Code Example Code Example 1-1System Watchdog Node Management Code Example Code Example 1-1System Watchdog Node Management Code Example Code Example 1-1System Watchdog Node Management Code Example Null Code Example 1-1System Watchdog Node Management Code Example Code Example 1-1System Watchdog Node Management Code Example Code Example 1-1System Watchdog Node Management Code Example Code Example 1-1System Watchdog Node Management Code Example Code Example 1-1System Watchdog Node Management Code Example Notreached Code Example 1-1System Watchdog Node Management Code Example OpenBoot Prom Interface Netra CP2500 Board Programming Guide March Environmental Monitoring Typical Environmental Monitoring System Application Environmental Monitoring Component Compatibility1Compatible Environmental Monitoring Components I2C Typical Cycle From Power Up to Shutdown Environmental Monitoring Protection at the OpenBoot PromPost Shutdown Recovery Hardware Environmental Monitoring Functions 3I2C ComponentsEnvironmental Monitoring CPU Switching Power On and Off Inlet, Exhaust, and CPU Temperature MonitoringNetra CP2500 Board Programming Guide March OpenBoot Prom Environmental Monitoring Critical Temperature Response at OpenBoot PromUsing the show-sensorsCommand at OpenBoot Prom Environmental Monitoring Application ProgrammingReading Temperature Sensor States Using 4PICL Temperature Sensor Class Node PropertiesUsing a Configuration File for Sensor Information Solaris Driver InterfaceSample Application Program Code Example 2-1Sample envmond Application ProgramCode Example 2-1Sample envmond Application Program Code Example 2-1Sample envmond Application Program Code Example 2-1Sample envmond Application Program Reading the CPU Temperature Environmental Limits Prtdiag command example5Description of Values Displayed by Solaris Commands User Flash User Flash Usage and ImplementationUser Flash Driver OpenBoot Prom Device Tree and Properties1User Flash Node Properties Application Programming Interface User Flash Device FilesInterface Header File 2System CallsStructures to Use in Ioctl Arguments Code Example 3-1PROM Information StructureExample Programs ErrorsCode Example 3-2User Flash Interface Structure Read Example Program Code Example 3-3Read Action on User Flash DeviceWrite Example Program Code Example 3-4Write Action on User Flash DeviceCode Example 3-4Write Action on User Flash Device Block Erase Example Program Code Example 3-5Block Erase Action on User Flash DeviceCode Example 3-5Block Erase Action on User Flash Device Sample User Flash Application Program Code Example 3-6Sample User Flash Application ProgramCode Example 3-6Sample User Flash Application Program Code Example 3-6Sample User Flash Application Program Code Example 3-6Sample User Flash Application Program Code Example 3-6Sample User Flash Application Program Code Example 3-6Sample User Flash Application Program Index PiclWatchdog-controller, 3 Watchdog-timer, 3