PDA

View Full Version : Help 2 Understand NV area


BitManip
02-28-2008, 03:28 PM
I see mentioned about the flash area that is Non Volitile (NV) and see in the script evalBase where things are stored into it. Like the line "saveNvParam(10, deviceType)" I understand what is being stored there (the string of the device type being a "Bridge,Photo or Buzz") . Can you give me a better lay of the land so to speak about that area; what I can and should not store there? What is read on power up etc?

Thanks

kbanks
02-28-2008, 04:33 PM
The NV Parameter storage area is only 512 bytes total, and some of that is used in defining the types and sizes of the parameters stored within it. So your first guideline is "don't go crazy storing LOTS of stuff here!" :)

Each NV parameter is tagged with an "ID" code. IDs 0 and 255 are reserved. IDs 1-127 are reserved for internal use by SNAP and SNAPpy. For example, ID 2 is the node's MAC Address.

IDs 128 through 254 are available for your own user defined parameters. In other words, you can define your own meanings for these IDs.

When you do a saveNvParam(id,obj), the second parameter is a Python/SNAPpy object, like an integer, boolean, or a string.

The system parameters are read at startup (Channel, Network ID, MAC Address, mesh routing timeouts, etc.). User parameters are only read when a script calls for it. Of course, this could be in the "startup hook" of a script.

When you do a "factory default" (under the options menu), it is the NV parameters that your are erasing (including any user defined parameters).

Kevin Banks

BitManip
03-07-2008, 11:03 AM
When you say the IDs 1-127 are reserved, I can respect that. But does that mean that we cant even just read them? I see you say "on startup, system parameters are only read (Channel, Network ID, MAC Address, mesh Routing timeouts, etc.)" Q: Is the UART enable/disable bits stored there also when you say "etc"? Q:If I promise not to change them can I just read them for my own program purposes? If yes, please provide me a full map.

Thanks:)

kbanks
03-07-2008, 03:32 PM
You can read any NV Param you want, by "reserved" we mean "don't save your own stuff here because we may overwrite it in a future release".

Here are the currently defined NV Params:

ACTIVE_BLOCK_ID = 1, // FF means this is the active block, 0 means it is not
MAC_ADDR_ID = 2,
NETWORK_ID = 3,
CHANNEL_ID = 4,
GROUP_INTEREST_MASK_ID = 5,
GROUP_FORWARDING_MASK_ID = 6,
SYSTEM_ERROR_ID = 9,
DEVICE_TYPE_ID = 10,
FEATURE_BITS_ID = 11,
DEFAULT_UART_ID = 12,
MESH_ROUTE_AGE_MAX_TIMEOUT_ID = 20,
MESH_ROUTE_AGE_MIN_TIMEOUT_ID = 21,
MESH_ROUTE_NEW_TIMEOUT_ID = 22,
MESH_ROUTE_USED_TIMEOUT_ID = 23,
MESH_ROUTE_DELETE_TIMEOUT_ID = 24,
MESH_RREQ_TRIES_ID = 25,
MESH_RREQ_WAIT_TIME_ID = 26,
MESH_INITIAL_HOPLIMIT_ID = 27,
MESH_MAX_HOPLIMIT_ID = 28,
MESH_SEQUENCE_NUMBER_ID = 29,
MESH_OVERRIDE_ID = 30,
SNAPPY_CRC_ID = 40,

You should recognize these from the documentation.

advantage-tim
05-20-2008, 05:12 PM
I was wondering if there's a way to read a GPIO pin on start up and set, either channel number, or network id. To have different "networks" at one location. Most likely I would read 2 ~ 4 pins to have a choice of different network id's to choose from - 2 pins should give four choices, etc (binary count).

kbanks
05-21-2008, 09:27 AM
Yes, what you want to do is very easy in SNAPpy. Here are some code snippets to get you started.

1) To do anything at startup, you will want to hook the startup event


snappyGen.setHook(SnapConstants.HOOK_STARTUP, startupEvent)


2) Since you have told SNAPpy to run a routine called startupEvent (and please realize that the name can be anything you want, just be sure you are consistent), add one to your script


def startupEvent():
"""This is hooked into the HOOK_STARTUP event"""
# do stuff here!


3) Since you want to make decisions based on input pins, you will need to (you guessed it) configure some pins as inputs.


setPinDir(17, False) # NOT an output, be an input
setPinDir(18, False) # NOT an output, be an input


4) Here I am assuming that the pins will either be unconnected (for a one bit), or grounded to be a zero bit. So we need to enable the internal pullup resistors.


setPinPullup(17, True) # DO enable pullup
setPinPullup(18, True) # DO enable pullup


4) Now that we have prepared them for use, we can read them


config = 0
if readPin(17):
config += 2
if readPin(18):
config += 1


5) This gives us a "config code" 0-3, which we can use to set our channel and network ID.


if config == 0:
setChannel(2)
setNetId(0x1234)
elif config == 1:
setChannel(8)
setNetId(0x5678)
elif config == 2:
setChannel(15)
setNetId(0xCAFE)
else:
setChannel(4)
setNetId(0x1C2C)


The entire script is attached. You should be able to modify it to meet your needs.