Example #1
0
Waypoints::WP
Waypoints::get_waypoint_with_index(uint8_t i)
{
	Waypoints::WP wp;

	i = constrain(i, 0, _total);
	uint32_t mem = _start_byte + (i * _wp_size);
	
	eeprom_busy_wait();
	wp.id = eeprom_read_byte((uint8_t *)mem);

	mem++;
	eeprom_busy_wait();
	wp.p1 = eeprom_read_byte((uint8_t *)mem);

	mem++;
	eeprom_busy_wait();
	wp.alt = (long)eeprom_read_dword((uint32_t *)mem);

	mem += 4;
	eeprom_busy_wait();
	wp.lat = (long)eeprom_read_dword((uint32_t *)mem);

	mem += 4;
	eeprom_busy_wait();
	wp.lng = (long)eeprom_read_dword((uint32_t *)mem);
}
Example #2
0
void gui_set_autostart_action(uint8_t index)
{
	switch(index)
	{
		case(1):
			gui_value_conf_P(PSTR("Start threshold"), GUI_VAL_NUMBER_DISABLE, PSTR("+/-%0.0fm"), config.autostart.start_sensititvity, 0, 100, 1, gui_set_autostart_start_threshold_cb);
			gui_switch_task(GUI_SET_VAL);
		break;

		case(2):
			gui_value_conf_P(PSTR("Land threshold"), GUI_VAL_NUMBER_DISABLE, PSTR("+/-%0.0fm"), config.autostart.land_sensititvity, 0, 100, 1, gui_set_autostart_land_threshold_cb);
			gui_switch_task(GUI_SET_VAL);
		break;

		case(3):
			gui_value_conf_P(PSTR("Timeout"), GUI_VAL_NUMBER, PSTR("%0.0f sec"), config.autostart.timeout, 5, 240, 1, gui_set_autostart_timeout_cb);
			gui_switch_task(GUI_SET_VAL);
		break;

		case(4):
			config.autostart.flags ^= AUTOSTART_SUPRESS_AUDIO;
			eeprom_busy_wait();
			eeprom_update_byte(&config_ee.autostart.flags, config.autostart.flags);
		break;

		case(5):
			config.autostart.flags ^= AUTOSTART_ALWAYS_ENABLED;
			eeprom_busy_wait();
			eeprom_update_byte(&config_ee.autostart.flags, config.autostart.flags);
		break;
	}
}
Example #3
0
//------------------------------------------------------------------------------
//
void command_wol (void)
{
#if USE_WOL
    // EEPROM beschreiben, falls Parameter angegeben wurden
    if ((*((unsigned int*)&variable[0]) != 0x00000000) || (*((unsigned int*)&variable[1]) != 0x00000000) || (*((unsigned int*)&variable[2]) != 0x00000000))
    {
        //schreiben der MAC
        for (unsigned char count = 0; count<6; count++)
        {
            eeprom_busy_wait ();
            eeprom_write_byte((unsigned char *)(WOL_MAC_EEPROM_STORE + count),variable[count]);
        }
        //zusätzlich schreiben der Broadcast-Adresse, falls vorhandenden
        for (unsigned char count = 0; count<4 && (*((unsigned int*)&variable[6]) != 0x00000000); count++)
        {
            eeprom_busy_wait ();
            eeprom_write_byte((unsigned char*)(WOL_BCAST_EEPROM_STORE + count),variable[count+6]);
        }
        //init
        wol_init();
    } else {
        //MagicPacket senden
        wol_request();
    }
#endif //USE_WOL	
}
Example #4
0
void gui_set_logger_action(uint8_t index)
{
	switch(index)
	{
		case(0):
			config.logger.enabled = !config.logger.enabled;
			eeprom_busy_wait();
			eeprom_update_byte(&config_ee.logger.enabled, config.logger.enabled);
		break;

		case(1):
			if (fc.logger_state == FLIGHT_LAND)
			{
				gui_showmessage_P(PSTR("Cannot change\nin flight!"));
				return;
			}
			config.logger.format = (config.logger.format + 1) % NUMBER_OF_FORMATS;
			eeprom_busy_wait();
			eeprom_update_byte(&config_ee.logger.format, config.logger.format);
		break;

		case(2):
			gui_switch_task(GUI_SET_AUTOSTART);
		break;
	}
}
Example #5
0
void calibrate(void)
{
  uint16_t min, max;
  // Timer/Counter0,1 Overflow Interrupt Enable - LED1 blinking
  TIMSK |= _BV(TOIE1);

  // Calibrate minimum value
  PORTA &= ~_BV(LED2);
  wait_for_prog();
  min = pressure();
  PORTA |= _BV(LED2);

  // Calibrate maximum value
  PORTA &= ~_BV(LED3);
  wait_for_prog();
  max = pressure();
  PORTA |= _BV(LED3) | _BV(LED1);

  // Save values in EEPROM
  eeprom_busy_wait();
  eeprom_write_word(PMINIMUM, min);

  eeprom_busy_wait();
  eeprom_write_word(PMAXIMUM, max);

  // Timer/Counter0,1 Overflow Interrupt Disable
  TIMSK &= ~_BV(TOIE1);
}
Example #6
0
void logger_next_flight()
{
	uint8_t sec, min, hour, day, wday, month;
	uint16_t year;
	uint32_t today;


	datetime_from_epoch(time_get_local(), &sec, &min, &hour, &day, &wday, &month, &year);
	today = datetime_to_epoch(0, 0, 0, day, month, year);
	
	if (today == logger_flight_day)
	{
		logger_flight_number++;

		eeprom_busy_wait();
		eeprom_update_byte(&config_ro.flight_number, logger_flight_number);
	}
	else
	{
		logger_flight_number = 0;
		logger_flight_day = today;

		eeprom_busy_wait();
		eeprom_update_block((void *)&logger_flight_day, &config_ro.flight_date, sizeof(logger_flight_day));
		eeprom_update_byte(&config_ro.flight_number, logger_flight_number);
	}

	DEBUG("date is: ");
	print_datetime(today);
	DEBUG("flight number is: %d\n", logger_flight_number);
}
Example #7
0
void logger_init()
{
	log_fil = new FIL;
	fc.logger_state = LOGGER_IDLE;

	uint8_t sec, min, hour, day, wday, month;
	uint16_t year;
	uint32_t today;


	datetime_from_epoch(time_get_local(), &sec, &min, &hour, &day, &wday, &month, &year);
	today = datetime_to_epoch(0, 0, 0, day, month, year);

	eeprom_busy_wait();
	eeprom_read_block((void *)&logger_flight_day, &config_ro.flight_date, sizeof(logger_flight_day));
	logger_flight_number = eeprom_read_byte(&config_ro.flight_number);

	if (logger_flight_day != today)
	{
		logger_flight_number = 0;
		logger_flight_day = today;

		eeprom_busy_wait();
		eeprom_update_block((void *)&logger_flight_day, &config_ro.flight_date, sizeof(logger_flight_day));
		eeprom_update_byte(&config_ro.flight_number, logger_flight_number);
	}

	DEBUG("date is: ");
	print_datetime(today);
	DEBUG("flight number is: %d\n", logger_flight_number);

}
Example #8
0
void PLEN2::JointController::resetSettings()
{
    #if DEBUG
        PROFILING("JointController::resetSettings()");
    #endif


    EEPROM[INIT_FLAG_ADDRESS] = INIT_FLAG_VALUE;
    eeprom_busy_wait();

    for (uint8_t index = 0; index < sizeof(Shared::m_SETTINGS_INITIAL); index++)
    {
        EEPROM[SETTINGS_HEAD_ADDRESS + index] = pgm_read_byte(
            reinterpret_cast<const uint8_t*>(Shared::m_SETTINGS_INITIAL) + index
        );
        eeprom_busy_wait();
    }

    for (uint8_t joint_id = 0; joint_id < JOINTS_SUM; joint_id++)
    {
        m_SETTINGS[joint_id].MIN  = pgm_read_word(Shared::m_SETTINGS_INITIAL + joint_id * 3 + 0);
        m_SETTINGS[joint_id].MAX  = pgm_read_word(Shared::m_SETTINGS_INITIAL + joint_id * 3 + 1);
        m_SETTINGS[joint_id].HOME = pgm_read_word(Shared::m_SETTINGS_INITIAL + joint_id * 3 + 2);

        setAngle(joint_id, m_SETTINGS[joint_id].HOME);
    }
}
Example #9
0
void cfg_load()
{
  eeprom_busy_wait();

  /* check for magic number */
  uint8_t magic = eeprom_read_byte((const uint8_t *)EEPROM_MAGIC_ADDR);
  if (magic != EEPROM_MAGIC)
  {
    /* no data previously stored; set defaults and save */
    cfg_set_defaults();
    cfg_save();
  }
  else
  {
    /* data previously stored; read it */
    eeprom_busy_wait();
    eeprom_read_block(profile1,(const void *)EEPROM_PROF1_ADDR,TC_NUM_PARAMS);
    eeprom_busy_wait();
    eeprom_read_block(profile2,(const void *)EEPROM_PROF2_ADDR,TC_NUM_PARAMS);

    /* sanity check */
    uint8_t i;
    for (i = 0; i < TC_NUM_PARAMS; i++)
    {
      /* if the value is corrupt, restore the default */
      uint8_t maxval = pgm_read_byte(&(params[i]->numvals));
      if (profile1[i] >= maxval)
        profile1[i] = pgm_read_byte(&(params[i]->defaultval));
      if (profile2[i] >= maxval)
        profile2[i] = pgm_read_byte(&(params[i]->defaultval));
    }
  }
}
Example #10
0
void gui_set_advanced_action(uint8_t index)
{
	switch(index)
	{
	case(0):
		config.connectivity.usb_mode = !config.connectivity.usb_mode;
		eeprom_busy_wait();
		eeprom_update_byte(&config_ee.connectivity.usb_mode, config.connectivity.usb_mode);
	break;

	case(1):
		config.connectivity.uart_function = (config.connectivity.uart_function + 1) % NUMBER_OF_UART_FORWARD;
		eeprom_busy_wait();
		eeprom_update_byte(&config_ee.connectivity.uart_function, config.connectivity.uart_function);
		uart_stop();
		uart_init();
	break;

	case(2):
		if (!storage_card_in())
		{
			gui_showmessage_P(PSTR("No SD card!"));

			return;
		}
		gui_dialog_set_P(PSTR("Warning"), PSTR("This will erase\nall data from SD\ncard! Continue?"), GUI_STYLE_YESNO, gui_set_advanced_format_cb);
		gui_switch_task(GUI_DIALOG);
	break;

	case(3):
		gui_switch_task(GUI_SET_CALIB);
	break;
	}
}
Example #11
0
void gui_layouts_action(uint8_t index)
{
	switch(index)
	{
	case(0):
		gui_switch_task(GUI_SET_WIDGETS);
	break;

	case(1):
		gui_switch_task(GUI_SET_LAYOUT);
	break;

	case(2):
		gui_value_conf_P(PSTR("Pages count"), GUI_VAL_NUMBER, PSTR("%1.0f"), config.gui.number_of_pages, 1, MAX_NUMBER_OF_PAGES, 1, gui_set_layouts_pages_cb);
		gui_switch_task(GUI_SET_VAL);
	break;

	case(3):
		config.gui.silent ^= (1 << active_page);
		eeprom_busy_wait();
		eeprom_update_byte(&config_ee.gui.silent, config.gui.silent);
	break;

	case(4):
		config.gui.hide_label ^= (1 << active_page);
		eeprom_busy_wait();
		eeprom_update_byte(&config_ee.gui.hide_label, config.gui.hide_label);
	break;

    case(5):
        gui_switch_task(GUI_SET_AUTOSET);
    break;
	}
}
Example #12
0
void gui_set_bluetooth_action(uint8_t index)
{
	switch (index)
	{
		case(1):
			config.system.use_bt = !config.system.use_bt;
			eeprom_busy_wait();
			eeprom_update_byte(&config_ee.system.use_bt, config.system.use_bt);

			if (config.system.use_bt)
				bt_module_init();
			else
				bt_module_deinit();
		break;

		case(2):
			config.system.protocol = (config.system.protocol + 1) % NUMBER_OF_PROTOCOLS;
			eeprom_busy_wait();
			eeprom_update_byte(&config_ee.system.protocol, config.system.protocol);
		break;

		case(3):
			config.system.forward_gps = !config.system.forward_gps;
			eeprom_busy_wait();
			eeprom_update_byte(&config_ee.system.forward_gps, config.system.forward_gps);
		break;
	}
}
Example #13
0
void 
Waypoints::set_waypoint_with_index(Waypoints::WP wp, uint8_t i)
{
	i = constrain(i, 0, _total);
	uint32_t mem = _start_byte + (i * _wp_size);

	eeprom_busy_wait();
	eeprom_write_byte((uint8_t *) mem, wp.id);

	mem++;
	eeprom_busy_wait();
	eeprom_write_byte((uint8_t *) mem, wp.p1);

	mem++;
	eeprom_busy_wait();
	eeprom_write_dword((uint32_t *) mem, wp.alt);

	mem += 4;
	eeprom_busy_wait();
	eeprom_write_dword((uint32_t *) mem, wp.lat);

	mem += 4;
	eeprom_busy_wait();
	eeprom_write_dword((uint32_t *) mem, wp.lng);
}
void PLEN2::JointController::resetSettings()
{
	#if DEBUG
		volatile Utility::Profiler p(F("JointController::resetSettings()"));
	#endif

	EEPROM[INIT_FLAG_ADDRESS()] = INIT_FLAG_VALUE();
	eeprom_busy_wait();

	for (int index = 0; index < sizeof(Shared::m_SETTINGS_INITIAL); index++)
	{
		EEPROM[SETTINGS_HEAD_ADDRESS() + index] = pgm_read_byte(
			reinterpret_cast<const char*>(Shared::m_SETTINGS_INITIAL) + index
		);
		eeprom_busy_wait();
	}

	for (char joint_id = 0; joint_id < SUM; joint_id++)
	{
		m_SETTINGS[joint_id].MIN  = pgm_read_word(Shared::m_SETTINGS_INITIAL + joint_id * 3 + 0);
		m_SETTINGS[joint_id].MAX  = pgm_read_word(Shared::m_SETTINGS_INITIAL + joint_id * 3 + 1);
		m_SETTINGS[joint_id].HOME = pgm_read_word(Shared::m_SETTINGS_INITIAL + joint_id * 3 + 2);

		setAngle(joint_id, m_SETTINGS[joint_id].HOME);
	}
}
Example #15
0
void clear_events()
{
	events_count = 0;
	
	// clear all data
	for (int i = 0; i < EVENTS_SIZE; i++)
	{
		events[i].pin = -1;
		events[i].time = 0;
		events[i].pin_state = 0;
		events[i].inc = 0;
		events[i].duration = 0;
		events[i].type = 0;
		
	}
	
	// save event to eeprom
	eeprom_busy_wait();
	eeprom_write_block(&events, &events_ee, sizeof(struct Event) * EVENTS_SIZE);
	
	// save count
	eeprom_busy_wait();
	eeprom_write_byte(&events_count_ee, events_count);
	
	event_mode = MANUAL_MODE;
}
Example #16
0
void add_event(int pin, int32_t time, int pin_state)
{
	// don't add if no space
	if (events_count >= EVENTS_SIZE - 1)
	return;
	
	events[events_count].pin = pin;
	events[events_count].time = time;
	events[events_count].pin_state = pin_state;
	
	if (pin_state > 1)
	events[events_count].type = PWM;
	else
	events[events_count].type = EXP;
	
	events_count++;
	
	// save event to eeprom
	eeprom_busy_wait();
	eeprom_write_block(&events, &events_ee, sizeof(struct Event) * EVENTS_SIZE);
	
	// save count
	eeprom_busy_wait();
	eeprom_write_byte(&events_count_ee, events_count);
}
Example #17
0
void  write32int (int inode, int offset, int32_t value)
{
    
    uint16_t addr;
  	
  	uint16_t value1;
  	
  	uint32_t value2;
  	
  	value1 = (uint16_t)((*(uint32_t *)&value) >> 16);
  	
  	value2 = (uint16_t)((*(uint32_t *)&value) & 0x0000ffff);
  	
  	addr = inode*INODESIZE + offset;
  	
  	eeprom_busy_wait();
  	
  	//value2 = *(uint16_t *)&value;
  	
  	eeprom_write_word((uint16_t *)addr, value2);
  	
  	
  	addr = inode*INODESIZE + offset +2 ;
  	
  	eeprom_busy_wait();
  	
  	//value2 = *(uint16_t *)&value;
  	
  	eeprom_write_word((uint16_t *)addr, value1);
   	
  	return;    		

}
void PLEN2::JointController::loadSettings()
{
    #if DEBUG
        PROFILING("JointController::loadSettings()");
    #endif


    uint8_t* filler = reinterpret_cast<uint8_t*>(m_SETTINGS);
    
    if (EEPROM[INIT_FLAG_ADDRESS] != INIT_FLAG_VALUE)
    {
        EEPROM[INIT_FLAG_ADDRESS] = INIT_FLAG_VALUE;
        eeprom_busy_wait();

        for (uint8_t index = 0; index < sizeof(m_SETTINGS); index++)
        {
            EEPROM[SETTINGS_HEAD_ADDRESS + index] = filler[index];
            eeprom_busy_wait();
        }
    }
    else
    {
        for (uint8_t index = 0; index < sizeof(m_SETTINGS); index++)
        {
            filler[index] = EEPROM[SETTINGS_HEAD_ADDRESS + index];
        }
    }

    for (uint8_t joint_id = 0; joint_id < JOINTS_SUM; joint_id++)
    {
        setAngle(joint_id, m_SETTINGS[joint_id].HOME);
    }

    /*
        @brief Configure timer 1

        @attention
        It might be easy to understand compare-matched output is LOW,
        but in that case, PWM is outputting at switching multiplexer's output,
        so the signal gets an impulse noise.
    */
    cli();

    TCCR1A =
        _BV(WGM11)  | _BV(WGM10)  | // Set mode to "10bit fast PWM".
        _BV(COM1A1) | _BV(COM1A0) | // Set OC1A to HIGH when compare matched.
        _BV(COM1B1) | _BV(COM1B0) | // Set OC1B to HIGH when compare matched.
        _BV(COM1C1) | _BV(COM1C0);  // Set OC1C to HIGH when compare matched.

    TCCR1B = 
        _BV(WGM12) |                // Set mode to "10bit fast PWM".
        _BV(CS11)  | _BV(CS10);     // Set prescaler to 64.

    TIFR1 = _BV(OCF1A) | _BV(OCF1B) | _BV(OCF1C) | _BV(TOV1); // Clearing interruption flag.

    sei();

    TIMSK1 = _BV(TOIE1); // Begin timer 1.
}
//----------------------------------------------------------------------------
//Empfang der IP
void udp_cmd_get (unsigned char index)
{
	//UDP_CMD_DEBUG("** CMD DATA GET Bytes: %i **\r\n",((UDP_DATA_END_VAR)-(UDP_DATA_START)));

	struct IP_Header *ip;
	ip = (struct IP_Header *)&eth_buffer[IP_OFFSET];
	udp_cmd_pollReplyTarget = ip->IP_Srcaddr;
	
	if(strcasestr_P((char*)&eth_buffer[UDP_DATA_START],PSTR("CMD IP ")) != 0){	
		if ((eth_buffer[UDP_DATA_START+11] == myip[0] &&
			eth_buffer[UDP_DATA_START+12] == myip[1] &&
			eth_buffer[UDP_DATA_START+13] == myip[2] &&
			eth_buffer[UDP_DATA_START+14] == myip[3])||
			(eth_buffer[UDP_DATA_START+11] == 255 &&
			eth_buffer[UDP_DATA_START+12] == 255 &&
			eth_buffer[UDP_DATA_START+13] == 255 &&
			eth_buffer[UDP_DATA_START+14] == 255))
		{
			//write default port
			unsigned short tmp = 0x1936;
			eeprom_write_block(&tmp,(void *)64, 2);

			//write_eeprom_ip(IP_EEPROM_STORE);
			if (*((unsigned int*)&eth_buffer[UDP_DATA_START+7]) != 0x00000000)
			{	
				//value ins EEPROM schreiben
				for (unsigned char count = 0; count<4;count++)
				{
					eeprom_busy_wait ();
					eeprom_write_byte((unsigned char *)(IP_EEPROM_STORE + count),eth_buffer[UDP_DATA_START+7+count]);
				}
			}

			//write_eeprom_netmask(NETMASK_EEPROM_STORE);
			if (*((unsigned int*)&eth_buffer[UDP_DATA_START+15]) != 0x00000000)
			{	
				//value ins EEPROM schreiben
				for (unsigned char count = 0; count<4;count++)
				{
					eeprom_busy_wait ();
					eeprom_write_byte((unsigned char *)(NETMASK_EEPROM_STORE + count),eth_buffer[UDP_DATA_START+15+count]);
				}
			}
			
			(*((unsigned long*)&myip[0])) = MYIP;
			(*((unsigned long*)&netmask[0])) = NETMASK;

			//UDP_CMD_DEBUG("My IP: %1i.%1i.%1i.%1i\r\n",myip[0],myip[1],myip[2],myip[3]);
			//UDP_CMD_DEBUG("MASK %1i.%1i.%1i.%1i\r\n", netmask[0]  , netmask[1]  , netmask[2]  , netmask[3]);
			
			//send OK
			eth_buffer[UDP_DATA_START] = 'O';
			eth_buffer[UDP_DATA_START+1] = 'K';
			//create_new_udp_packet(2,UDP_CMD_PORT_TX+1392,UDP_CMD_PORT_TX,udp_cmd_pollReplyTarget);
			create_new_udp_packet(2,UDP_CMD_PORT_TX+3456,UDP_CMD_PORT_TX,(unsigned long)0xffffffff);
		}
	}
}
Example #20
0
uint8_t eeprom_del_rule (uint8_t pos)
{
/*  del_rule
*   
*/  
  uint8_t count,i;
  uint16_t target_adress;
  RULES_STRUCTUR hilf;
  
  RULE_DEBUG("Del Rule:%i\r\n",pos);
  
  
  //aktuelle Anzahl auslesen
	count = get_rule_count();
  

  if(pos>=0 && pos<=count)
  {
    //folgende Regeln nachr�ckenen lassen
    for(i=pos;i<count;i++)
    {
      
      if(eeprom_get_rule(i+1,&hilf))
      {
          
        // Zieladresse berechnen
        target_adress=RULES_EEPROM_STORE+1+(i*sizeof(RULES_STRUCTUR));
        RULE_DEBUG("EEPROM write adress:%i\r\n",target_adress);
    
  
        // Regel in den EEPROM schreiben
        eeprom_busy_wait ();
        eeprom_write_block((unsigned char *)&hilf,(unsigned char *)target_adress,sizeof(RULES_STRUCTUR));
      }
      else
      {
        return 0;
      }
      
  
    }
  
    //bisher alles OK -> neuen Wert ins EEPROM schreiben
		eeprom_busy_wait ();
		eeprom_write_byte((unsigned char *)(RULES_EEPROM_STORE),--count);
  
    return 1;
  }
  else
  {
    RULE_DEBUG("Failure: Out of Range\r\n");
    return 0;
  }
  
return 0;
  
}
Example #21
0
void cfg_save()
{
  eeprom_busy_wait();
  eeprom_write_byte((uint8_t *)EEPROM_MAGIC_ADDR, EEPROM_MAGIC);
  eeprom_busy_wait();
  eeprom_write_block(profile1, (void *)EEPROM_PROF1_ADDR, TC_NUM_PARAMS);
  eeprom_busy_wait();
  eeprom_write_block(profile2, (void *)EEPROM_PROF2_ADDR, TC_NUM_PARAMS);
}
Example #22
0
void eeprom_write_buffer(struct sample_buffer* buffer, uint16_t pos) {
  eeprom_busy_wait();
  eeprom_update_word((uint16_t*) pos, buffer->count);
  pos += 2;
  
  for (uint16_t i = 0; i < buffer->count; i++) {
    eeprom_busy_wait();  
    eeprom_update_byte((uint8_t*) pos + i, sample_at(buffer, i));
  }
}
Example #23
0
void eeprom_read_buffer(struct sample_buffer* buffer, uint16_t pos) {
  eeprom_busy_wait();
  uint16_t length = eeprom_read_word((uint16_t*) pos);
  pos += 2;
  
  for (uint16_t i = 0; i < length; i++) {
    eeprom_busy_wait();  
    push_sample(buffer, eeprom_read_byte((uint8_t*) pos + i));
  }
}
Example #24
0
void lcdSaveCustomChar(uint8_t romCharNum)
{
    // EEPROM にデータを書き出す。
    eeprom_busy_wait();
    eeprom_write_block(&rCustom, (void *)(sizeof(custom_char_t)*romCharNum), sizeof(custom_char_t));
    eeprom_busy_wait();

    // 書き込みに時間が必要なのかも、ウェイト入れる
//	_delay_ms(10000);
}
Example #25
0
void cfg_reset_factory_test()
{
	uint8_t ff_buffer[sizeof(cfg_ro_t)];
	for (uint16_t i = 0; i < sizeof(cfg_ro_t); i++)
		ff_buffer[i] = 0xFF;

	eeprom_busy_wait();
	eeprom_update_block(ff_buffer, &config_ro, sizeof(cfg_ro_t));
	eeprom_busy_wait();
	task_set(TASK_POWERDOWN);
}
Example #26
0
File: menu.c Project: stewdk/pwct
static void eepromUpdateStringSafe(char *src, char *eepromDst)
{
	char readString[LCD_NUM_CHARACTERS+1];
	eeprom_busy_wait();
	eeprom_update_block(src, eepromDst, LCD_NUM_CHARACTERS+1);
	printf("EEPROM written\n");
	eeprom_busy_wait();
	eeprom_read_block(readString, eepromDst, LCD_NUM_CHARACTERS+1);
	if (strcmp(readString, src)) {
		eepromCorrupt();
	}
}
Example #27
0
bool StoreEEPROM()
{
	wdt_reset();
	DEBUG("Storing settings\n");

	if (!storage_selftest())
	{
		DEBUG("Error: Storage not available\n");
		return false;
	}

	FIL * ee_file;
	ee_file = new FIL;

	if (f_open(ee_file, "CFG.EE", FA_WRITE | FA_CREATE_ALWAYS) != FR_OK)
	{
		DEBUG("Unable to create file\n");
		delete ee_file;

		return false;
	}
	uint16_t wd = 0;

	eeprom_busy_wait();
	eeprom_update_dword(&config_ee.build_number, BUILD_NUMBER);

	uint16_t i = 0;
	do
	{
		uint8_t buf[256];
		uint16_t rwd;

		if (i + sizeof(buf) < sizeof(cfg_t))
			wd = sizeof(buf);
		else
			wd = sizeof(cfg_t) - i;


		eeprom_busy_wait();
		eeprom_read_block(buf, (uint8_t *)(APP_INFO_EE_offset + i), wd);


		assert(f_write(ee_file, buf, wd, &rwd) == FR_OK);

		i += wd;
	} while (i < sizeof(cfg_t));

	f_close(ee_file);
	DEBUG("File closed\n");

	delete ee_file;
	return true;
}
Example #28
0
bool StoreEEPROM()
{
	wdt_reset();
	DEBUG("Storing settings\n");

	FIL * ee_file;
	ee_file = new FIL;

	if (f_open(ee_file, "CFG.EE", FA_WRITE | FA_CREATE_ALWAYS) != FR_OK)
	{
		DEBUG("Unable to create file\n");
		return false;
		delete ee_file;
	}
	uint16_t wd = 0;

	eeprom_busy_wait();
	eeprom_update_dword(&config.build_number, BUILD_NUMBER);

	uint16_t res;

	uint16_t i = 0;
	do
	{
		uint8_t buf[256];
		uint16_t rwd;

		if (i + sizeof(buf) < sizeof(config))
			wd = sizeof(buf);
		else
			wd = sizeof(config) - i;

		DEBUG(" >> i %d s %d rwd %d\n", i, wd, rwd);

		eeprom_busy_wait();
		eeprom_read_block(buf, (uint8_t *)(APP_INFO_EE_offset + i), wd);

		DEBUG(" << \n");

		res = f_write(ee_file, buf, wd, &rwd);

		i += wd;
		DEBUG("i %d s %d rwd %d\n", i, wd, rwd);
	} while (i < sizeof(config));

	f_close(ee_file);
	DEBUG("File closed\n");

	delete ee_file;
	return true;
}
Example #29
0
File: menu.c Project: stewdk/pwct
static void eepromUpdateByteSafe(uint8_t *eepromVariable, uint8_t *shadowVariable, uint8_t newValue)
{
	uint8_t readValue;
	eeprom_busy_wait();
	eeprom_update_byte(eepromVariable, newValue);
	printf("EEPROM written\n");
	eeprom_busy_wait();
	readValue = eeprom_read_byte(eepromVariable);
	if (readValue != newValue) {
		eepromCorrupt();
	} else {
		*shadowVariable = newValue;
	}
}
Example #30
0
File: menu.c Project: stewdk/pwct
static void eepromUpdateFloatSafe(float *eepromVariable, float *shadowVariable, float newValue)
{
	float readValue;
	eeprom_busy_wait();
	eeprom_update_float(eepromVariable, newValue);
	printf("EEPROM written\n");
	eeprom_busy_wait();
	readValue = eeprom_read_float(eepromVariable);
	if (readValue != newValue) {
		eepromCorrupt();
	} else {
		*shadowVariable = newValue;
	}
}