示例#1
0
void configInit(void) {
    float ver;

    // start with what's in flash
    configFlashRead();

    // try to load any config params from uSD card
    if (configReadFile(0) < 0)
        // clear config if read error
        memset(p, 0, sizeof(p));
    else
        supervisorConfigRead();

    // get flash version
    ver = *(float *)(flashStartAddr()+16);
    if (isnan(ver))
        ver = 0.0f;

    // if compiled defaults are greater than flash version and loaded version
    if (DEFAULT_CONFIG_VERSION > ver && DEFAULT_CONFIG_VERSION > p[CONFIG_VERSION])
        configLoadDefault();
    // if flash version greater than or equal to currently loaded version
    else if (ver >= p[CONFIG_VERSION])
        configFlashRead();

    // if loaded version greater than flash version
    if (p[CONFIG_VERSION] > ver)
        configFlashWrite();
}
示例#2
0
void configFlashRead(void) {
    configRec_t *recs;
    int i, j;

    recs = (void *)flashStartAddr();

    for (i = 0; i < CONFIG_NUM_PARAMS; i++) {
        for (j = 0; j < CONFIG_NUM_PARAMS; j++)
            if (!strncasecmp(recs[i].name, configParameterStrings[j], 16))
                p[j] = recs[i].val;
    }

    AQ_NOTICE("config: Parameters restored from flash memory.\n");
}
示例#3
0
文件: config.c 项目: benzeng/AutoQuad
unsigned char configFlashWrite(void) {
    return flashAddress(flashStartAddr(), (uint32_t *)&p, sizeof(p));
}
示例#4
0
文件: config.c 项目: benzeng/AutoQuad
void configFlashRead(void) {
    memcpy(&p, (char *)flashStartAddr(), sizeof(p));
}
示例#5
0
uint8_t configFlashWrite(void) {
    configRec_t *recs;
    uint8_t ret = 0;
    int i;

    recs = (void *)aqCalloc(CONFIG_NUM_PARAMS, sizeof(configRec_t));

    if (recs) {
        configToken_t *tr = (configToken_t *)recs;
        configToken_t *tf = 0;

        // read all tokens
        do {
            tf = configTokenIterate(tf);

            // copy to RAM
            if (tf) {
                // only one instance per key
                do {
                    if (tr->key == 0 || tr->key == tf->key) {
                        memcpy(tr, tf, sizeof(configToken_t));
                        break;
                    }
                    tr++;
                } while (1);
            }
        } while (tf);

        ret = flashErase(flashStartAddr(), CONFIG_NUM_PARAMS*sizeof(configRec_t)/sizeof(uint32_t));

        // invalidate the flash data cache
        FLASH_DataCacheCmd(DISABLE);
        FLASH_DataCacheReset();
        FLASH_DataCacheCmd(ENABLE);

        if (ret) {
            tr = (configToken_t *)recs;

            // copy tokens back to flash
            while (tr->key)
                configTokenStore(tr++);

            // create param list in RAM
            for (i = 0; i < CONFIG_NUM_PARAMS; i++) {
                memcpy(recs[i].name, configParameterStrings[i], 16);
                recs[i].val = p[i];
            }

            ret = flashAddress(flashStartAddr(), (uint32_t *)recs, CONFIG_NUM_PARAMS*sizeof(configRec_t)/sizeof(uint32_t));
        }

        aqFree(recs, CONFIG_NUM_PARAMS, sizeof(configRec_t));

	AQ_NOTICE("config: Parameters saved to flash memory.\n");
    }
    else {
        AQ_NOTICE("config: Error writing params to flash, cannot allocate memory.\n");
    }

    return ret;
}