Пример #1
0
void nv_read_parameter_int(uint32_t* val)
{
	nvObj_t *nv = nv_reset_nv_list();
	for (uint16_t i = 0; i < nv_index_max(); i++)
	{
		if (cfgArray[i].target == val)
		{
			nv->index = i;
			break;
		}
	}
	strncpy_P(nv->token, cfgArray[nv->index].token, TOKEN_LEN);
	read_persistent_value(nv);
	nv_set(nv);
}
Пример #2
0
stat_t write_persistent_value(nvObj_t *nv)
{
	if (cm.cycle_state != CYCLE_OFF)
        return(rpt_exception(STAT_FILE_NOT_OPEN));	// can't write when machine is moving

/* not needed
	if (nv->valuetype == TYPE_FLOAT) {
		if (isnan((double)nv->value)) return(rpt_exception(STAT_FLOAT_IS_NAN));		// bad floating point value
		if (isinf((double)nv->value)) return(rpt_exception(STAT_FLOAT_IS_INFINITE));// bad floating point value
	}
*/
	nvm.tmp_value = nv->value;
	ritorno(read_persistent_value(nv));
	if ((isnan((double)nv->value)) || (isinf((double)nv->value)) || (fp_NE(nv->value, nvm.tmp_value))) {
		memcpy(&nvm.byte_array, &nvm.tmp_value, NVM_VALUE_LEN);
		nvm.address = nvm.profile_base + (nv->index * NVM_VALUE_LEN);
		(void)EEPROM_WriteBytes(nvm.address, nvm.byte_array, NVM_VALUE_LEN);
	}
	nv->value =nvm.tmp_value;		// always restore value
	return (STAT_OK);
}
Пример #3
0
/************************************************************************************
 * config_init() - called once on hard reset
 *
 * Performs one of 2 actions:
 *	(1) if persistence is set up or out-of-rev load RAM and NVM with settings.h defaults
 *	(2) if persistence is set up and at current config version use NVM data for config
 *
 *	You can assume the cfg struct has been zeroed by a hard reset.
 *	Do not clear it as the version and build numbers have already been set by tg_init()
 *
 * NOTE: Config assertions are handled from the controller
 */
void config_init()
{
	nvObj_t *nv = nv_reset_nv_list();
	char *P_str_axis[3] = {"x","y", "z"};
	config_init_assertions();

#ifdef __ARM
// ++++ The following code is offered until persistence is implemented.
// ++++ Then you can use the AVR code (or something like it)
	cfg.comm_mode = JSON_MODE;					// initial value until EEPROM is read
	_set_defa(nv);
#endif
#ifdef __AVR
	cm_set_units_mode(MILLIMETERS);				// must do inits in millimeter mode
	nv->index = 0;								// this will read the first record in NVM

	read_persistent_value(nv);
	if (nv->value != cs.fw_build) {				// case (1) NVM is not setup or not in revision
//	if (fp_NE(nv->value, cs.fw_build)) {
		_set_defa(nv);
	} else {									// case (2) NVM is setup and in revision
		rpt_print_loading_configs_message();
		for (nv->index=0; nv_index_is_single(nv->index); nv->index++) {
			if (GET_TABLE_BYTE(flags) & F_INITIALIZE) {
				strncpy_P(nv->token, cfgArray[nv->index].token, TOKEN_LEN);	// read the token from the array
				read_persistent_value(nv);
				nv_set(nv);
			}
		}
		sr_init_status_report();
	}
#endif
#ifdef __RX
// ++++ The following code is offered until persistence is implemented.
// ++++ Then you can use the AVR code (or something like it)
	cm_set_units_mode(MILLIMETERS);				// must do inits in millimeter mode
	nv->index = 0;								// this will read the first record in NVM

	spiffs_DIR sf_dir;
	struct spiffs_dirent e;
	struct spiffs_dirent *pe = &e;

	spiffs_file *fd = &uspiffs[0].f;
	spiffs *fs = &uspiffs[0].gSPIFFS;

	R_FlashDataAreaAccess(0xFFFF,0xFFFF);
	checkifParFlashed = (char *)(0x00100000);
	if (SPIFFS_opendir(fs, "/", &sf_dir) == NULL)
	{

	}
	pe = SPIFFS_readdir(&sf_dir, pe);
	*fd = SPIFFS_open(fs, "config.met", SPIFFS_RDWR | SPIFFS_DIRECT, 0);
	SPIFFS_close(fs, *fd);
	if (*fd == SPIFFS_ERR_NOT_FOUND && strcmp(checkifParFlashed,checkParPhrase)) {				// case (1) NVM is not setup or not in revision
		*fd = SPIFFS_open(fs, "config.met", SPIFFS_CREAT | SPIFFS_RDWR | SPIFFS_DIRECT, 0);
		SPIFFS_close(fs, *fd);
		R_FlashEraseRange(0x00100000,0x20);
		R_FlashWrite(0x00100000,(uint32_t)checkParPhrase, 0x20);
		_set_defa(nv);
	} else {									// case (2) NVM is setup and in revision
		rpt_print_loading_configs_message();
		for (nv->index=0; nv_index_is_single(nv->index); nv->index++) {
			if (GET_TABLE_BYTE(flags) & F_INITIALIZE) {
				strncpy_P(nv->token, cfgArray[nv->index].token, TOKEN_LEN);	// read the token from the array
				read_persistent_value(nv);
				nv_set(nv);


			}
		}
		sr_init_status_report();
	}
	z_step_pulse = (M1_TRAVEL_PER_REV*M1_STEP_ANGLE)/(360*M1_MICROSTEPS);
#endif
}