forked from contiki-os/contiki
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Newer and cleaner TARGET=econotag as well as robust mc13224v
configuration system. (also deprecate TARGET=redbee-econotag) - mc13224v now automatically probes hardware config for buck converter and 32kHz crystal as well as automatically monitors battery voltage and manages the buck accordingly. - new flashed based config system for mc13224v parameters such has radio modes (demod, autoack), nvmtype, mac address, channel and power. - considerably cleaned up econotag platform code (suffered from severe case of bit-rot)
- Loading branch information
Showing
15 changed files
with
950 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* MC1322x flash config system */ | ||
|
||
#include <mc1322x.h> | ||
#include "config.h" | ||
|
||
/* debug */ | ||
#define DEBUG DEBUG_FULL | ||
#include "net/uip-debug.h" | ||
|
||
mc1322xConfig mc1322x_config; | ||
|
||
void dump_bytes(uint32_t addr, uint16_t num); | ||
|
||
/* takes an mc1322xConf and initializes to default values */ | ||
void mc1322x_config_set_default(mc1322xConfig *c) { | ||
nvmType_t type; | ||
c->magic = MC1322X_CONFIG_MAGIC; | ||
c->version = MC1322X_CONFIG_VERSION; | ||
c->eui = 0; | ||
c->channel = RF_CHANNEL - 11; | ||
c->power = 0x11; | ||
c->flags.demod = DEMOD_DCD; | ||
c->flags.autoack = AUTOACK; | ||
nvm_detect(gNvmInternalInterface_c, &type); | ||
c->flags.nvmtype = type; | ||
} | ||
|
||
/* write out config to flash */ | ||
void mc1322x_config_save(mc1322xConfig *c) { | ||
nvmErr_t err; | ||
err = nvm_erase(gNvmInternalInterface_c, c->flags.nvmtype, 1 << MC1322X_CONFIG_PAGE/4096); | ||
err = nvm_write(gNvmInternalInterface_c, c->flags.nvmtype, (uint8_t *)c, MC1322X_CONFIG_PAGE, sizeof(mc1322xConfig)); | ||
} | ||
|
||
/* load the config from flash to the pass conf structure */ | ||
void mc1322x_config_restore(mc1322xConfig *c) { | ||
nvmErr_t err; | ||
nvmType_t type; | ||
if (c->flags.nvmtype == 0) { nvm_detect(gNvmInternalInterface_c, &type); } | ||
c->flags.nvmtype = type; | ||
err = nvm_read(gNvmInternalInterface_c, c->flags.nvmtype, c, MC1322X_CONFIG_PAGE, sizeof(mc1322xConfig)); | ||
} | ||
|
||
/* check the flash for magic number and proper version */ | ||
int mc1322x_config_valid(mc1322xConfig *c) { | ||
if (c->magic == MC1322X_CONFIG_MAGIC && | ||
c->version == MC1322X_CONFIG_VERSION) { | ||
return 1; | ||
} else { | ||
#if DEBUG | ||
if (c->magic != MC1322X_CONFIG_MAGIC) { PRINTF("config bad magic %04x\n\r", c->magic); } | ||
if (c->version != MC1322X_CONFIG_MAGIC) { PRINTF("config bad version %04x\n\r", c->version); } | ||
#endif | ||
return -1; | ||
} | ||
} | ||
|
||
void mc1322x_config_print(void) { | ||
uint64_t eui64; | ||
PRINTF("mc1322x config:\n\r"); | ||
PRINTF(" magic: %04x\n\r", mc1322x_config.magic); | ||
PRINTF(" version: %d\n\r", mc1322x_config.version); | ||
PRINTF(" eui: %08x%08x\n\r", (uint32_t)(mc1322x_config.eui>>32), (uint32_t)(mc1322x_config.eui & 0xffffffff)); | ||
PRINTF(" channel: %d\n\r", mc1322x_config.channel); | ||
PRINTF(" power: %d\n\r", mc1322x_config.power); | ||
PRINTF(" flags: %08x\n\r", mc1322x_config.flags); | ||
PRINTF(" demod: %d\n\r", mc1322x_config.flags.demod); | ||
PRINTF(" autoack: %d\n\r", mc1322x_config.flags.autoack); | ||
PRINTF(" nvm type: %d\n\r", mc1322x_config.flags.nvmtype); | ||
} | ||
|
||
void dump_bytes(uint32_t addr, uint16_t num) { | ||
uint32_t buf[num/4]; | ||
nvmErr_t err; | ||
uint16_t i; | ||
|
||
err = nvm_read(gNvmInternalInterface_c, mc1322x_config.flags.nvmtype, (uint8_t *)buf, addr, num); | ||
PRINTF("nvm_read returned: 0x%02x\r\n", err); | ||
|
||
for(i=0; i < num/4; i++) { | ||
printf("0x%08x\r\n", (unsigned int)buf[i]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* MC1322x flash config system */ | ||
|
||
#ifndef MC1322X_CONFIG_H | ||
#define MC1322X_CONFIG_H | ||
|
||
#define MC1322X_CONFIG_PAGE 0x1E000 /* nvm page where conf will be stored */ | ||
#define MC1322X_CONFIG_VERSION 1 | ||
#define MC1322X_CONFIG_MAGIC 0x1322 | ||
|
||
/* bitfield for various config flags */ | ||
struct FLAGS { | ||
uint32_t demod:1; /* radio demodulation mode */ | ||
uint32_t autoack:1; /* radio autoack vs. promiscuous mode */ | ||
uint32_t nvmtype:4; /* stores the result of nvm_detect */ | ||
uint32_t : 26; | ||
}; | ||
|
||
typedef struct { | ||
uint16_t magic; /* mc1322x magic number 0x1322 */ | ||
uint16_t version; /* mc1322x config version number */ | ||
uint64_t eui; | ||
uint8_t channel; /* value to pass to set_channel */ | ||
uint8_t power; /* value to pass to set_power */ | ||
struct FLAGS flags; | ||
} mc1322xConfig; | ||
|
||
extern mc1322xConfig mc1322x_config; | ||
|
||
void mc1322x_config_set_default(mc1322xConfig *c); | ||
void mc1322x_config_save(mc1322xConfig *c); | ||
void mc1322x_config_restore(mc1322xConfig *c); | ||
int mc1322x_config_valid(mc1322xConfig *c); | ||
void mc1322x_config_print(void); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.