int BspWriteIoTimingInfo(timint_info * info)
{
	uint16_t offset = BSP_IO_TIMING_OFFSET+1;
	if(info->time_max_count > SYS_TIMING_COUNT_MAX) {
		//还原
		NutNvMemSave(BSP_IO_TIMING_OFFSET,time_last_head,sizeof(time_last_head));
		return -1;
	}
	return NutNvMemSave(offset,info,sizeof(timint_info));
}
Exemple #2
0
void NtpWriteTimeToEeprom(tm time_struct){
    Eeprom_tm eeprom_tm_struct;

    eeprom_tm_struct.len = sizeof(eeprom_tm_struct);
    eeprom_tm_struct.tm_struct = time_struct;
    printf("uren: %d, minuten: %d, seconden: %d\n", time_struct.tm_hour, time_struct.tm_min, time_struct.tm_sec);
    int success = NutNvMemSave(100, &time_struct.tm_hour, sizeof(time_struct.tm_hour));
    if (success == 0){ puts("NtpWriteTimeToEeprom: hours succesfully written to eeprom \n"); }
    success = NutNvMemSave(105, &time_struct.tm_min, sizeof(time_struct.tm_min));
    if (success == 0){ puts("NtpWriteTimeToEeprom: mins succesfully written to eeprom \n"); }
    success = NutNvMemSave(110, &time_struct.tm_sec, sizeof(time_struct.tm_sec));
    if (success == 0){ puts("NtpWriteTimeToEeprom: secs succesfully written to eeprom \n"); }
    NutDelay(100);
}
int BspWriteControlMode(unsigned char index,CmdInputControl * pm)
{
	int ret = -1;
	uint16_t offset = BSP_MODE_CTL_OFFSET + index * sizeof(CmdInputControl);
	if(index >= INPUT_CHANNEL_NUM) {
		return ret;
	}
	ret = NutNvMemSave(offset,pm,sizeof(CmdInputControl));
	if(ret == 0) {
		unsigned int tmp;
		input_trig_mode[index] = pm->mode;

		tmp = pm->input_filter_time_hi;
		tmp <<= 8;
		tmp += pm->input_filter_time_lo;
		input_filter_hold_time_max[index] = tmp;

		tmp = pm->input_trig_front_time_hi;
		tmp <<= 8;
		tmp += pm->input_trig_front_time_lo;
		input_trig_before_delay_max[index] = tmp;

		tmp = pm->input_trig_after_time_hi;
		tmp <<= 8;
		tmp += pm->input_trig_after_time_lo;
		input_trig_after_delay_max[index] = tmp;

		input_trig_to_witch_io_out[index] = pm->input_trig_io_number;
	}
	return ret;
}
int BspWriteIoTiming(uint16_t index,timing_node_eeprom * time)
{
	uint16_t offset = BSP_IO_TIMING_OFFSET+1+sizeof(timint_info)+1;
	if(index >= SYS_TIMING_COUNT_MAX) {
		return -1;
	}
	offset += sizeof(timing_node_eeprom)*index;
	return NutNvMemSave(offset,time,sizeof(timing_node_eeprom));
}
int BspTimingStartWrite(void)
{
	uint16_t offset = BSP_IO_TIMING_OFFSET;
	uint8_t  buffer[sizeof(timint_info)+2];
	memset(buffer,0,sizeof(buffer));
	buffer[0] = 0x55;
	NutNvMemLoad(offset,time_last_head,sizeof(time_last_head));
	return NutNvMemSave(offset,buffer,sizeof(buffer));
}
Exemple #6
0
/*!
 * \brief Save network configuration in non-volatile memory.
 *
 * \return 0 if OK, -1 on failures.
 */
int NutNetSaveConfig(void)
{
#ifndef __NUT_EMULATION__	
    confnet.cd_size = sizeof(CONFNET);
    if (NutNvMemSave(CONFNET_EE_OFFSET, &confnet, sizeof(CONFNET))) {
        return -1;
    }
#endif
    return 0;
}
Exemple #7
0
void NtpWriteTimeToEeprom(tm time_struct){
    Eeprom_tm eeprom_tm_struct;

    eeprom_tm_struct.len = sizeof(eeprom_tm_struct);
    eeprom_tm_struct.tm_struct = time_struct;

    int success = NutNvMemSave(256, &eeprom_tm_struct, sizeof(eeprom_tm_struct));
    if (success == 0){ puts("NtpWriteTimeToEeprom: Time succesfully written to eeprom \n"); }

    NutDelay(100);
}
void BspWriteEepromSerialAddress(uint16_t address)
{
	uint16_t offset = BSP_IO_SERIAL_ADDR_OFFSET;
	if(IoGetConfig()&(1<<0)) {  //配置为1的时候,才能写数据
		uint16_t tmp;
		NutNvMemLoad(offset,&tmp,sizeof(tmp));
		if(tmp != address) {
			NutNvMemSave(offset,&address,sizeof(address));
		}
	}
}
int BspWriteManualCtlModeIndex(unsigned char index,unsigned char mode)
{
	int ret = 0;
	if(index >= INPUT_CHANNEL_NUM) {
		return -1;
	}
	ret = NutNvMemSave(BSP_MODE_INDEX_OFFSET+index,&mode,1);
	if(ret == 0) {
	    input_trig_mode[index] = mode;
	}
	return ret;
}
Exemple #10
0
/*!
 * \brief Save Nut/OS configuration in non-volatile memory.
 *
 * Since Nut/OS version 4.7.5, this routine is no longer called automatically 
 * during system initialization. Thus, if NutLoadConfig() fails, then the 
 * non-volatile memory remains invalid and NutLoadConfig() will again fail 
 * during the next system start.
 *
 * \return 0 if OK, -1 on failures.
 */
int NutSaveConfig(void)
{
    /* Sanity checks. */
    NUTASSERT(sizeof(CONFOS) <= 255);
    NUTASSERT(strlen(confos.hostname) <= MAX_HOSTNAME_LEN);

    /* Update the magic part. */
    confos.size = sizeof(CONFOS);
    memcpy(confos.magic, CONFOS_EE_MAGIC, sizeof(CONFOS_EE_MAGIC) - 1);

    return NutNvMemSave(CONFOS_EE_OFFSET, &confos, sizeof(CONFOS));
}
int BspWriteIpConfig(CmdIpConfigData * cid)
{
	int ret = 0;
#if 0
	if(IoGetConfig()&(1<<0)) {
		return NutNvMemSave(BSP_IP_ADDR_OFFSET,cid,sizeof(CmdIpConfigData));
	} else {
		return -1;
	}
#endif
	ret = NutNvMemSave(BSP_IP_ADDR_OFFSET,cid,sizeof(CmdIpConfigData));
	if(!ret) {
		//如果不是SET模式,则启动系统
#ifdef CHANGE_IP_REBOOT_SYSTEM
		if(!(IoGetConfig()&(1<<0))) {
		    RequestSystemReboot();
		}
#endif
	}
	return ret;
}
int BspWriteManualCtlModeIndex(unsigned char index,unsigned char mode)
{
	int ret = -1;
	CmdInputControl ctl;
	uint16_t offset = BSP_MODE_CTL_OFFSET + index * sizeof(CmdInputControl);
	if(index >= INPUT_CHANNEL_NUM) {
		return ret;
	}
	ret = NutNvMemLoad(offset,&ctl,sizeof(CmdInputControl));
	ctl.mode = mode;
	ret = NutNvMemSave(offset,&ctl,sizeof(CmdInputControl));
	if(ret == 0) {
		input_trig_mode[index] = mode;
	}
	return ret;
}
int BspWriteIoName(uint8_t addr[2],CmdIoName * io)
{
	uint16_t offset = BSP_IO_NAME_OFFSET;
	if(addr[1] == 0) {
		offset += addr[0]*sizeof(CmdIoName);
	} else if(addr[1] == 1) {
		offset += OUTPUT_NUM*sizeof(CmdIoName) + addr[0]*sizeof(CmdIoName);
	} else {
		memset(io->io_name,0,sizeof(io->io_name));
		return -1;
	}
	if(1) {
		return NutNvMemSave(offset,io,sizeof(CmdIoName));
	}
	return -1;
}
int BspTimingDoneWrite(void)
{
	uint16_t offset = BSP_IO_TIMING_OFFSET+1+sizeof(timint_info);
	uint8_t ox = 0xAA;
	return NutNvMemSave(offset,&ox,sizeof(ox));
}
int save_relay_info(ethernet_relay_info * info)
{
	uint16_t offset = BSP_HTTP_CLIENT_INFO_OFFSET;
	NutNvMemSave(offset,info,sizeof(ethernet_relay_info));
}
void BspWriteFactoryOut(char ch)
{
	uint16_t offset = BSP_FACTORY_OUT_OFFSET;
	NutNvMemSave(offset,&ch,sizeof(char));
}
void BspSavemultimgr_info(device_info_st * info)
{
	uint16_t offset = BSP_MULTI_MANGER_DATA_OFFSET;
	NutNvMemSave(offset,info,sizeof(device_info_st));
}
int BspWriteBoardInfo(CmdBoardInfo * info)
{
	return NutNvMemSave(BSP_BOARD_INFO_OFFSET,info,sizeof(CmdBoardInfo));
}
int BspWriteWebPassword(char *password)
{
	return NutNvMemSave(BSP_KEY_OFFSET,password,sizeof(gpassword));
}
int BspWriteHostAddress(host_address * info)
{
	return NutNvMemSave(HOST_ADDRESS_CONFIG,info,sizeof(host_address));
}