Previous

Next

Bottom

Contents

Glossary

Index

 

Persistor CF1 User's Manual

Flash Memory Functions

February 1999

Revision 1.02

 Persistor Instruments Inc.
© 1998 All rights reserved.

Quick Reference Table

FlashAutoSelect

FlashErasureCounts

FlashSectorStarts

FlashBase

FlashErrorSignal

FlashSetWaits

FlashCheckErased

FlashGetWaits

FlashSize

FlashCheckInFlash

FlashInfoString

FlashSpeedNanoSecs

FlashDisallowErase

FlashInit

FlashTotalSectors

FlashDisallowWrite

FlashLastEraseTime

FlashVerify

FlashEnableErrTrap

FlashPostWrite

FlashWriteBlock

FlashEraseRange

FlashPreWrite

FlashWriteByte

FlashEraseSectors

FlashReservedSectors

FlashWriteWord

FlashEraseWrite

FlashSectorSize

Background

The CF1 has flash 1MB of flash memory. The first 64KB are taken by PBM, the BIOS, and the VEE (Virtual EEPROM). The next 192KB are generally taken by PicoDOS, but can be reclaimed for your own use if necessary. The remaining 768KB are available for your application program(s) or for logging data (with restrictions). The routines described here are generally used by the system, but may also be accessed by your applications. The MAX146 A-D examples demonstrates a low power logger that stores to system flash.

Warning!

The on-board flash has a rated endurance of 100,000 erase-write cycles. If you only use the flash for applications storage, you will never come close to reaching that limit. If you use the flash for data storage, you could easily exceed that limit. The on-board flash is not replacable, so make sure you know what you are doing.

FlashAutoSelect -- Return the flash manufacturers code word

This function returns a ulong that is used to identify the flash manufacturer. This is primarily used internally at the build and test phase by Persistor Instruments Inc..

Prototype:

ulong FlashAutoSelect(void);

Definition:

#include <cf1bios.h>

Returns:

Returns a ulong that is used to identify the flash manufacturer

Notes:

Used internally only.

Timing:

Timing-TBD

FlashBase -- Return the flash base address

This function returns the base address of all the flash memory in the CF1. This is normally 0x00E00000.

Prototype:

void *FlashBase(void);

Definition:

#include <cf1bios.h>

Returns:

Returns the base address of all the flash memory in the CF1

Notes:

Timing:

Timing-TBD

FlashCheckErased -- Return address of first non-erased word, zero if entire range is erased

This function verifies that all of the bytes in the range are currently erased(0xFF). If any of the bytes are not erased, the function will return a pointer to the first unerased byte.

Prototype:

void *FlashCheckErased(void *flash, ulong len);

Definition:

#include <cf1bios.h>

Returns:

Returns NULL if all bytes in the range are erased, or a pointer to the first non-erased byte if any are found.

Notes:

Timing:

Timing-TBD

FlashCheckInFlash -- Return true if address is in flash memory

This function returns TRUE if the given address is within the portion of the memory map occupied by flash memory.

Prototype:

bool FlashCheckInFlash(ulong testAddr);

Definition:

#include <cf1bios.h>

Inputs:

testAddr is the address you wish to test.

Returns:

Returns TRUE if testAddr is in flash or FALSE if it is not.

Notes:

Timing:

Timing-TBD

FlashDisallowErase -- Disable flash routines from erasing until next reset

This sets a flag in a BIOS register that prevents any flash sector erases until the next system reset. This can be useful in field deployment to keep the flash from being destroyed by a tight loop of erroneous erase cycles.

Prototype:

void FlashDisallowErase(void);

Definition:

#include <cf1bios.h>

Notes:

There is no way to clear the flag set by this function without resetting the machine.

Timing:

Timing-TBD

FlashDisallowWrite -- Disable flash routines from erasing until next reset

This sets a flag in a BIOS register that prevents any flash writes until the next system reset. This can be useful in field deployment to keep the flash from being modified by an error condition. This function also prevents erase operations on the flash until the next reset.

Prototype:

void FlashDisallowWrite(void);

Definition:

#include <cf1bios.h>

Notes:

There is no way to clear the flag set by this function without resetting the machine.

Timing:

Timing-TBD

FlashEnableErrTrap -- Enable/Disable flash error trapping

FlashEnableErrTrap is used to turn on and off error trapping in the flash subsystem. When an flash related function runs across an error, it may call the function FlashErrorSignal, which will by default simply return the short that was passed to it. However if this function has been used to turn on flash error trapping, the machine will cease execution and print debugging messages.

Prototype:

void FlashEnableErrTrap(bool dotrap);

Definition:

#include <cf1bios.h>

Inputs:

dotrap is a boolean which if passed TRUE indicates that RTCErrorSignal should cease execution and print debugging messages when called, as opposed to simply returning.

Notes:

Timing:

Timing-TBD

FlashEraseRange -- Erase blocks that fall in the specified range

This function, given a base address and a number of bytes, will erase all sectors covered by that range.

Prototype:

short FlashEraseRange(void *flash, ulong len);

Definition:

#include <cf1bios.h>

Inputs:

flash is a pointer to the base of the range to be erased.
len is the number of bytes in the range to be erased.

Returns:

Returns an error code if applicable.

Notes:

Because the flash part must erase whole sectors at a time, it is possible that data that is not in the specified range could be deleted.

Timing:

Timing-TBD

FlashEraseSectors -- Erase sectors specified in NULL terminated list

This function erases all the sectors listed in the given NULL terminated list. The numbers in the list are sector index numbers, not addresses.

Prototype:

short FlashEraseSectors(uchar *sectorList);

Definition:

#include <cf1bios.h>

Inputs:

sectorList is a NULL terminated list of sector numbers.

Returns:

Returns an error code if applicable.

Notes:

Timing:

Timing-TBD

FlashEraseWrite -- Block write to the flash, erase if necessary

This function writes an existing block of memory to the given location in flash. The entire area including any partial sectors where the block is to be written will be erased if necessary. Because flash erases by sector, it is possible that this operation could lose data that is not overlapped by the data you wish to copy.

Prototype:

short FlashEraseWrite(void *flash, const void *source, ulong *bytecount);

Definition:

#include <cf1bios.h>

Inputs:

flash is a pointer to the location in flash where the data should go
source is the pointer from whence the data should be copied
bytecount is the number of bytes to be copied.

Returns:

Returns an error code if applicable.

Notes:

Timing:

Timing-TBD

FlashErasureCounts -- Return long[] array of flash sectors erase counts

This function returns an array of shorts that tell how many times each sector of the flash has been erased. The index of the array is the sector number and the value is the number of erases.

Prototype:

short *FlashErasureCounts(void);

Definition:

#include <cf1bios.h>

Returns:

Returns an array of integers that contains the number of erases for each flash sector, and is indexed by the sector numbers.

Notes:

Timing:

Timing-TBD

FlashErrorSignal -- Return error or take FlashErrorTrap

This function is called internally on return from certain functions to deal with error conditions. It is listed here because it can be patched or can also be called by your functions to handle an error with respect to the setting of FlashEnableErrTrap. If the flash error trapping is enabled (by using FlashEnableErrTrap) when this is called, the machine will crash and print debugging messages, which will include whatever was in offense. Otherwise it will simply return the same short passed to it in code. When this function is called by the system, offense will contain the table entry address in the dispatch table (see cf1bios.h) of the function that called FlashErrorSignal.

Prototype:

short FlashErrorSignal(short code, long offense);

Definition:

#include <cf1bios.h>

Inputs:

code is the result code of the calling function.
offense is the address of the table entry that contains a pointer to the function which originally called FlashErrorSignal, but can be anything and is simply a value that is displayed as a debug message if error trapping is enable and a crash is triggered.

Returns:

Returns a copy of code.

Notes:

Timing:

Timing-TBD

FlashGetWaits -- Return the current number of wait states for the flash

This function allows a user application to ascertain the current number of wait states used by the processor when communicating with the flash.

Prototype:

short FlashGetWaits(void);

Definition:

#include <cf1bios.h>

Returns:

Returns the current number of wait states used by the processor when communicating with the flash.

Notes:

Timing:

Timing-TBD

FlashInfoString -- Return string describing flash "Am29LV800B-100"

This function returns a string that provides information stored internally that indicates which flash part is present on the CF1. Currently all CF1s have the string "Am29LV800B-100" but this could change at any time in the future.

Prototype:

char *FlashInfoString(void);

Definition:

#include <cf1bios.h>

Returns:

Returns a string describing the flash part installed on the CF1.

Notes:

Timing:

Timing-TBD

FlashInit -- Initialize the flash chip selects and variables

This function will never be called by a user's application, it is called by the BIOS initialization routines at startup. This routine maps the flash parts into memory, sets up the chip selects and designates the flash as a read only device. Any attempts to write to the flash as normal memory will result in a bus error. Please use the library functions documented here to modify the flash.

Prototype:

short FlashInit(void);

Definition:

#include <cf1bios.h>

Notes:

Timing:

Timing-TBD

FlashLastEraseTime -- Return last calendar time any part of flash was erased

This function returns the last calendar date/time that any part of the flash was erased. The time is returned in the form of a long specifying the date in seconds since midnight Jan 1, 1970.

Prototype:

ulong FlashLastEraseTime(void);

Definition:

#include <cf1bios.h>

Returns:

Returns calendar time of last erase.

Notes:

This time can be parsed by the RTClocaltime function, into a MM/DD/YY HH:MM:SS format.

Timing:

Timing-TBD

FlashPostWrite -- Conclude flash write operation

This function is used internally by flash writing routines. User applications will never use this function. This function provides services necessary to clean up and return to a normal operating state after a flash write. Specifically, this function restores the Status Register save by FlashPreWrite and re-enables interrupt processing.

Prototype:

void FlashPostWrite(vushort saveSR);

Definition:

#include <cf1bios.h>

Inputs:

saveSR is a vushort, filled by FlashPreWrite, that holds the contents of the Status Register.

Notes:

Timing:

Timing-TBD

FlashPreWrite - Prepare flash for write operation

This function is used internally by flash writing routines. User applications will never use this function. This function performs several services integral to the flash writing process. First, it verifies the validity of the range, making sure that all of the block lies within flash. Then it saves the status register in saveSR for later restoring with the FlashPostWrite function. Lastly it disables all interrupts to prevent failure during a flash write.

Prototype:

short FlashPreWrite(vushort *saveSR, void *firstAddr, void *lastAddr);

Definition:

#include <cf1bios.h>

Inputs:

saveSR is a pointer to a vushort that will hold the contents of the Status Register during the write.
firstAddr is the beginning address of the destination of the block to be written.
lastAddr is the last destination address of the block to be written.

Returns:

Returns error code if applicable.

Notes:

Timing:

Timing-TBD

FlashReservedSectors -- Return the number of reserved flash sectors

This function returns the number of flash sectors that are reserved by the Operating System for various purposes. This number is a count from the beginning of flash and is correct regardless of sector size. You are not allowed to modify any of the sectors that fall within the range of sector numbers formed by 0 and the number returned by this function.

Prototype:

short FlashReservedSectors(void);

Definition:

#include <cf1bios.h>

Returns:

Returns the number of flash sectors from the base of flash that are reserved for the OS.

Notes:

Timing:

Timing-TBD

FlashSectorSize -- Return the sectors size in bytes

This function allows the user to find the size in bytes of a particular sector of flash. This is important to check for each sector because flash sector sizes vary from sector to sector and part to part.

Prototype:

long FlashSectorSize(short sector);

Definition:

#include <cf1bios.h>

Inputs:

sector is the sector number whose size you wish to find.

Returns:

Returns the size in bytes of the indicated sector.

Notes:

Timing:

Timing-TBD

FlashSectorStarts -- Return long[] array of flash sector start addresses

This function returns an array of void pointers to the base of each sector of flash. The array is indexed by the sector numbers.

Prototype:

void **FlashSectorStarts(void);

Definition:

#include <cf1bios.h>

Returns:

Returns and array of void pointers that point to the base address of each sector of flash.

Notes:

A user application must use this function to determine base addresses of sectors because flash sectors are not uniform in size.

Timing:

Timing-TBD

FlashSetWaits -- Set the number of wait states for the flash

This function sets the number of wait states that the processor should use when communicating with the flash part. This function does nothing but call CSSetSysWaits with repeat values for the other parameters and the new given number of wait states for the flash.

Prototype:

void FlashSetWaits (short waits);

Definition:

#include <cf1bios.h>

Inputs:

waits is the number of wait states the processor should use when communicating with the flash part.

Notes:

This could have dangerous effects if used improperly.

Timing:

Timing-TBD

FlashSize -- Return the flash size in bytes

This function returns the total size of all flash memory in the CF1 (This does not include CompactFlash) in bytes.

Prototype:

long FlashSize(void);

Definition:

#include <cf1bios.h>

Returns:

Returns the total size of all flash memory in the CF1 in bytes.

Notes:

Please note that flash sector sizes vary within even a single part. Therefore the size in bytes returned by this function divided by the number of sectors is not the sector size and is actually a pretty meaningless number.

Timing:

Timing-TBD

FlashSpeedNanoSecs -- Return the flash access time in nanoseconds

This function returns the access time of the flash in nanoseconds. This is manufacturer data that is stored in the flash at build time.

Prototype:

short FlashSpeedNanoSecs(void);

Definition:

#include <cf1bios.h>

Returns:

Returns the flash access speed in nanoseconds.

Notes:

Timing:

Timing-TBD

FlashTotalSectors -- Return the total number of flash sectors

This function returns the total number of flash sectors in all of the flash memory on the CF1. This is useful for performing iterative operations on each flash sector. Use this function to establish a maximum index for the arrays returned by FlashSectorStarts and FlashErasureCounts.

Prototype:

short FlashTotalSectors(void);

Definition:

#include <cf1bios.h>

Returns:

Returns the total number of flash sectors in all of the flash memory on the CF1.

Notes:

Please note that flash sector sizes vary within even a single part. Therefore the size in bytes returned by this function divided by the number of sectors is not the sector size and is actually a pretty meaningless number.

Timing:

Timing-TBD

FlashVerify -- Block verify the flash

This function performs a comparison between the two blocks of memory pointed two by its two pointer parameters. It will return NULL if the two areas of memory were exactly the same. Otherwise it will return the address, in flash, of the first differing byte.

Prototype:

void *FlashVerify(const void *flash, const void *source, ulong bytecount);

Definition:

#include <cf1bios.h>

Inputs:

flash is a pointer to the beginning of the block to be compared, in flash
source
is a pointer to the beginning of the block to be compared, in memory
bytecount is the number of bytes to compare

Returns:

Returns NULL is the two areas are exactly the same, otherwise returns the address in flash of the first incorrect byte.

Notes:

Timing:

Timing-TBD

FlashWriteBlock -- Block write to the flash (must be erased)

This function writes an existing block of memory to the given location in flash. The entire area including any partial sectors where the block is to be written must have been pre-erased.

Prototype:

short FlashWriteBlock(void *flash, const void *source, ulong *bytecount);

Definition:

#include <cf1bios.h>

Inputs:

flash is a pointer to the location in flash where the data should go
source is the pointer from whence the data should be copied
bytecount is the number of bytes to be copied.

Returns:

Returns an error code if applicable.

Notes:

The data to be copied may span any number of flash sectors, but all addresses that will be written to must have been pre-erased.

Timing:

Timing-TBD

FlashWriteByte -- Write a single byte to flash (must be ones to zeros, see manual)

This function writes one byte (8 bits) to flash. The write must only change ones to zeros. Any change in the reverse direction requires that the byte be pre-erased.

Prototype:

short FlashWriteByte(uchar *flash, uchar byte);

Definition:

#include <cf1bios.h>

Inputs:

flash is a pointer to the location in flash where the byte is to be written.
byte is the byte to be written into the location flash.

Returns:

Returns an error code if applicable.

Notes:

Timing:

Timing-TBD

Previous

Next

Top

Contents

Glossary

Index

Tel: 508-759-6434

Fax: 508-759-6436

Copyright (C) 1998 Persistor Instruments Inc. - All Rights Reserved