|
|
|
|
|
|
|
||
|
||
|
|
||
April 2000 |
Revision 1.02 |
|
Persistor Instruments Inc. |
© 1998 All rights reserved. |
|
VEE stands for Virtual EEPROM. It's 7.5KB of persistant storage that can be used to hold small amounts of any kind of binary or text data (usually configuration data) that wants to stay with the CF1 (as opposed to on removable CompactFlash files) and uses named tags to store and fetch this data. The virtual part of the name is in the context of the familiar small serial EEPROM chips that are often associated with little embedded controllers and the EEPROM part actually is electrically erasable read-only memory, albeit two reserved 8KB sectors of the big flash array.
The VEE can store three types of standard data (longs, floats, and C strings) as well as arbitrary binary data for custom types and structures. Each entry is stored along with a 16 bit CRC, and the entire VEE is verified when PicoDOS initializes. Each fetch of a VEE entry also re-verifies the CRC. VEE lookup is considerable slower than convential memory accesses, so a wise strategy for frequently accessed data is to fetch it once at the start of your program and keep a local copy in RAM for repeat access.
PicoDOS efficiently manages the 7.5KB VEE data by minimizing the writes and erases performed on a pair of 8KB flash memory sectors. The missing 512 bytes (x2) is reserved by PBM for controlling the boot process. From your programs, you use API calls like VEEFetch(), VEEStore(), and VEEDelete() to get data into and out of the virtual EEPROM, and from the PicoDOS command shell you can access the string-type VEE data with the DOS-like SET command.
A quick example helps shed light on how and why VEE is useful. By default, the CF1 performs all of its communications at 9600 BAUD, though it's easily capable of talking at any rate from 50 to 230,000 BAUD. It acts this way so that you can hook it to any 9600 BAUD terminal and be assured that if the CF1 speaks, you'll be able to hear it. Very nice, unless your application embeds the CF1 in a system where everything else communicates at 38,400 BAUD. You can of course write your CF1 program to change the baud rate as one of its first tasks, but it's sometime tedious and error prone to have to switch baud rates for any kind of maintanence. With PicoDOS 2.0, you can tell the CF1 to use a custom baud rate using the agreed upon VEE variable called "SYS.BAUD" (though PBM still uses 9600 baud for emergencies) at startup, or any time it would normally reset to the default baud rate. To enable this, from PicoDOS you would simply type "SET SYS.BAUD=38400", or from within your program with the call VEEStore("SYS.BAUD", "38400"). To see the current setting, from PicoDOS you could type "SET" (viewing all of the VEE variables), or from within your program with the call VEEFetch("SYS.BAUD").
Though PicoDOS does its best to minimize writes and erases, using VEE does place additional wear and tear on the flash memory. In typical use (less than 1KB data in less than 50 variables), your probably good for about a million changes before the flash fatigues (just the VEE sectors). For its intended purpose, this is indeed overkill, nevertheless, it is possible to code nasty loops into your applications that could burn through this in less than a day. For that reason, the VEE limits sector erasures to 4 per reset (about a thousand VEE changes) and there is an API call named VEELock() that prohibits any future VEE writes until the next full reset cycle.
![]()
enum
{
veeErrorStart = VEE_ERRORS
, veeNotInited // Hasn't been initialized
, veeLocked // Locked, can't write or erase
, veeSpareNotErased // Flash invalid, must be cleared to use
, veeBadEntry // Invalid entry in VEE table
, veeBadCRC // Entry has bad CRC
, veeBadNameSize // Entry has bad name size
, veeBadDataSize // Entry has bad data size
, veeTooManyErases // Too many erases (limited to 4)
, veeTableFull // No more room in VEE
};
#define VEE_MAX_NAME_LEN 13 // 14 incl. zero terminator
#define VEE_MAX_DATA_LEN 1024 // 2^10 max data (not incl. hdr.)
typedef enum { vbin, vstr, vlong, vfloat } VEEType;
typedef union { void *bin; char *str; long lng; float flt; } VEEData;
typedef struct
{
ushort crc; // of all fields
ushort type : 2; // string, long, float, binary
ushort nlen : 4; // name length (15+'\0' max)
ushort dlen : 10; // data length (1024 max)
uchar data[]; // name, 1 or 2 zeros, data, 0 or 1 zeros
} VEEVar;
This is called by PicoDOS on startup.
|
Prototype: |
void* VEEInit(void); |
|
Definition: |
#include <cf1pico.h> |
|
Inputs: |
None. |
|
Returns: |
Returns nothing. |
|
Notes: |
Notes. |
|
Timing: |
TBD |
Store a zero terminated C string into the virtual eeprom.
|
Prototype: |
bool VEEStoreStr(char *name, char *str); |
|
Definition: |
#include <cf1pico.h> |
|
Inputs: |
name is a pointer to a zero terminated C string of
up to 15 characters that identifies the entry. |
|
Returns: |
Returns true if successful. |
|
Notes: |
If a VEE variable with the same name already exists, it will be deleted to make room for the new one. |
|
Timing: |
TBD |
Return either a signed long value found in the virtual eeprom or a default value.
|
Prototype: |
char *VEEFetchStr(char *name, char *fallback); |
|
Definition: |
#include <cf1pico.h> |
|
Inputs: |
name is a pointer to a zero terminated C string of
up to 15 characters that identifies the entry. |
|
Returns: |
Returns a C string. |
|
Notes: |
|
|
Timing: |
TBD |
Store a 32 bit long binary value (C long or ulong) into the virtual eeprom.
|
Prototype: |
bool VEEStoreLong(char *name, long lvalue); |
|
Definition: |
#include <cf1pico.h> |
|
Inputs: |
name is a pointer to a zero terminated C string of
up to 15 characters that identifies the entry. |
|
Returns: |
Returns true if successful. |
|
Notes: |
If a VEE variable with the same name already exists, it will be deleted to make room for the new one. |
|
Timing: |
TBD |
Return either a signed long value found in the virtual eeprom or a default value.
|
Prototype: |
long VEEFetchLong(char *name, long fallback); |
|
Definition: |
#include <cf1pico.h> |
|
Inputs: |
name is a pointer to a zero terminated C string of
up to 15 characters that identifies the entry. |
|
Returns: |
Returns a signed long value. |
|
Notes: |
The eeprom entry may be either a long value or a string that evaluates to a long value (uses atol()) |
|
Timing: |
TBD |
Store a 32 bit IEEE floating point binary value (C float) into the virtual eeprom.
|
Prototype: |
bool VEEStoreFloat(char *name, float fvalue); |
|
Definition: |
#include <cf1pico.h> |
|
Inputs: |
name is a pointer to a zero terminated C string of
up to 15 characters that identifies the entry. |
|
Returns: |
Returns true if successful. |
|
Notes: |
If a VEE variable with the same name already exists, it will be deleted to make room for the new one. |
|
Timing: |
TBD |
Return either a float value found in the virtual eeprom or a default value.
|
Prototype: |
float VEEFetchFloat(char *name, float fallback); |
|
Definition: |
#include <cf1pico.h> |
|
Inputs: |
name is a pointer to a zero terminated C string of
up to 15 characters that identifies the entry. |
|
Returns: |
Returns a four byte float value. |
|
Notes: |
The eeprom entry may be either a float value or a string that evaluates to a float value (uses atof()) |
|
Timing: |
TBD |
Store a block of binary data into the virtual eeprom.
|
Prototype: |
bool VEEStoreBin(char *name, ushort size, void *data); |
|
Definition: |
#include <cf1pico.h> |
|
Inputs: |
name is a pointer to a zero terminated C string of
up to 15 characters that identifies the entry. |
|
Returns: |
Returns true if successful. |
|
Notes: |
If a VEE variable with the same name already exists, it will be deleted to make room for the new one. |
|
Timing: |
TBD |
Return data from a named VEE entry.
|
Prototype: |
VEEData VEEFetchData(char *name); |
|
Definition: |
#include <cf1pico.h> |
|
Inputs: |
name is a pointer to a zero terminated C string of up to 15 characters that locates the entry. |
|
Returns: |
Returns a 32 bit VEEData union value which is either a long, float, string pointer, or binary data pointer. |
|
Notes: |
This function assumes you know that the requested named variable exists and that you also know the type of data that's stored with the name. If that's not the case, use the VEEFetchVar function and decode the addition fields for type information. |
|
Timing: |
TBD |
Return a pointer to a VEEVar structure.
|
Prototype: |
VEEVar VEEFetchVar(char *name); |
|
Definition: |
#include <cf1pico.h> |
|
Inputs: |
name iis a pointer to a zero terminated C string of up to 15 characters that locates the entry. |
|
Returns: |
Returns a pointer to a VEEVar structure or zero if the requested name can't be found. |
|
Notes: |
You can determine the type of data from the type field, and access the name and stored data using the companion VEEGetName and VEEGetData functions. |
|
Timing: |
TBD |
Given a VEEVar structure pointer, return a pointer to its zero terminated C string.
|
Prototype: |
char* VEEGetName(VEEVar *vvp); |
|
Definition: |
#include <cf1pico.h> |
|
Inputs: |
vvp is a pointer to a VEEVar structure from VEEFetchVar, VEELookup, or VEEFetchNext. |
|
Returns: |
Returns a pointer to a zero terminated C string or zero if there is a problem. |
|
Notes: |
Notes. |
|
Timing: |
TBD |
Given a VEEVar structure pointer, return a pointer to its data field, which is guaranteed to begin on an even boundary.
|
Prototype: |
void* VEEGetData(VEEVar *vvp, short *size); |
|
Definition: |
#include <cf1pico.h> |
|
Inputs: |
vvp is a pointer to a VEEVar structure from
VEEFetchVar, VEELookup, or VEEFetchNext. |
|
Returns: |
Returns a non-zero pointer or zero if there is a problem. |
|
Notes: |
Notes. |
|
Timing: |
TBD |
Store data into the virtual EEPROM
|
Prototype: |
VEEVar VEEStore(char *name, VEEType vtype, ushort size, void *data); |
|
Definition: |
#include <cf1pico.h> |
|
Inputs: |
name is a pointer to a zero terminated C string of
up to 15 characters that identifies the entry. |
|
Returns: |
Returns a pointer to the new VEEVar structure if successful, zero if not. |
|
Notes: |
You will generally want to use VEEStoreStr, VEEStoreLong, VEEStoreFloat, VEEStoreBin instead of this lower level function. If a VEE variable with the same name already exists, it will be deleted to make room for the new one. |
|
Timing: |
TBD |
Delete a virtual eeprom variable.
|
Prototype: |
bool VEEDelete(char *name); |
|
Definition: |
#include <cf1pico.h> |
|
Inputs: |
name is a pointer to a zero terminated C string of up to 15 characters that locates the entry. |
|
Returns: |
Returns true if found and successful, false if not found or the VEE is locked. |
|
Notes: |
Notes. |
|
Timing: |
TBD |
Delete the entire virtual eeprom.
|
Prototype: |
bool VEEClear(void); |
|
Definition: |
#include <cf1pico.h> |
|
Inputs: |
None. |
|
Returns: |
Returns true if successful. |
|
Notes: |
This erases the entire VEE except for a single byte that is copied and retained for the PBM startup vector. Use this only to fix unrecoverable problems that could happen if an applicaition program corrupts the VEE flash. |
|
Timing: |
TBD |
Lock the VEE until the next reset.
|
Prototype: |
void VEELock(void); |
|
Definition: |
#include <cf1pico.h> |
|
Inputs: |
None. |
|
Returns: |
Returns nothing. |
|
Notes: |
This will inhibit all further VEE writing until the next full reset. |
|
Timing: |
TBD |
Confirms VEE internal data structures and returns the free space in bytes or -1 if there is an error
|
Prototype: |
short VEECheck(void); |
|
Definition: |
#include <cf1pico.h> |
|
Inputs: |
None. |
|
Returns: |
Returns zero or one of the enumerated VEE error codes. |
|
Notes: |
Notes. |
|
Timing: |
TBD |
Clean up and condense the VEE tables.
|
Prototype: |
bool VEECleanUp(void); |
|
Definition: |
#include <cf1pico.h> |
|
Inputs: |
None. |
|
Returns: |
Returns true if successful, false if the VEE is corrupted or locked. |
|
Notes: |
This function is called automatically when VEE space is running short and space can be made free from previously deleted entries. You can call this if you anticipate that this is immenent, but don't want to incur the time penalty when the CPU is busy. Calling this repeatedly is a very bad idea as it defeats the flash wear minimization the VEE based on. |
|
Timing: |
TBD |
Lookup a named variable in the VEE with no further verification.
|
Prototype: |
VEEVar VEELookup(char *name); |
|
Definition: |
#include <cf1pico.h> |
|
Inputs: |
name is a pointer to a zero terminated C string of up to 15 characters that identifies the entry. |
|
Returns: |
Returns a pointer to a VEEVar structure or zero if the requested name can't be found. |
|
Notes: |
Use VEEFetchVar or VEEFetchData for you application. |
|
Timing: |
TBD |
Returns the complete size of a VEE variable including name, data, crc, and any padding.
|
Prototype: |
short VEEVarSize(VEEVar *entry); |
|
Definition: |
#include <cf1pico.h> |
|
Inputs: |
entry is a pointer to a VEEVar structure |
|
Returns: |
Returns the total size in bytes or zero. |
|
Notes: |
Used internally |
|
Timing: |
TBD |
Return the offset from the VEEVar structure start to the actual data.
|
Prototype: |
short VEEDataOffset(VEEVar *entry); |
|
Definition: |
#include <cf1pico.h> |
|
Inputs: |
entry is a pointer to a VEEVar structure |
|
Returns: |
Returns the offset in bytes or zero. |
|
Notes: |
Used internally |
|
Timing: |
TBD |
Return the next sequential VEEVar entry.
|
Prototype: |
VEEVar VEEFetchNext(VEEVar *prev); |
|
Definition: |
#include <cf1pico.h> |
|
Inputs: |
prev is a pointer to a VEEVar structure, or zero to find the first. |
|
Returns: |
Returns a pointer to the next VEEVar structure or zero if there are no more. |
|
Notes: |
Used to iterate through the VEE for a list of directory of VEE entries. |
|
Timing: |
TBD |
|
|
|
|
|
|
Tel: 508-759-6434 |
|
Fax: 508-759-6436 |
|
|
||