コード例 #1
0
void nodeconfig_listen(void)
{
  //
  // Listen for serial input, which is how we set the address
  //
  if (Serial.available())
  {
    // If the character on serial input is in a valid range...
    char c = Serial.read();
    if ( c >= '0' && c <= '5' )
    {
      *nextserialat++ = c;
      if ( nextserialat == maxserial )
      {
	*nextserialat = 0;
	printf_P(PSTR("\r\n*** Unknown serial command: %s\r\n"),serialdata);
	nextserialat = serialdata;
      }
    }
    else if ( tolower(c) == 'r' )
    {
      eeprom_info.relay = true;
      printf_P(PSTR("ROLE: %S\n\r"),eeprom_info.relay ? PSTR("Relay") : PSTR("Leaf") );
      if ( eeprom_info.flag == valid_eeprom_flag )
	eeprom_update_block(&eeprom_info,address_at_eeprom_location,sizeof(eeprom_info));
      else
	printf_P(PSTR("Please assign an address to commit this role to EEPROM\r\n"));
    }
    else if ( tolower(c) == 'l' )
    {
      eeprom_info.relay = false;
      printf_P(PSTR("ROLE: %S\n\r"),eeprom_info.relay ? PSTR("Relay") : PSTR("Leaf") );
      if ( eeprom_info.flag == valid_eeprom_flag )
	eeprom_update_block(&eeprom_info,address_at_eeprom_location,sizeof(eeprom_info));
      else
	printf_P(PSTR("Please assign an address to commit this role to EEPROM\r\n"));
    }
    else if ( c == 13 )
    {
      // Convert to octal
      char *pc = serialdata;
      uint16_t address = 0;
      while ( pc < nextserialat )
      {
	address <<= 3;
	address |= (*pc++ - '0');
      }

      // It is our address
      eeprom_info.flag = valid_eeprom_flag;
      eeprom_info.address = address;
      eeprom_update_block(&eeprom_info,address_at_eeprom_location,sizeof(eeprom_info));

      // And we are done right now (no easy way to soft reset)
      printf_P(PSTR("\n\rManually set to address 0%o\n\rPress RESET to continue!"),address);
      while(1);
    }
  }
}
コード例 #2
0
ファイル: eeprom.c プロジェクト: sowbug/weblight
void SetUpNewEEPROM() {
  eeprom_update_block(sig, (void*)(EEPROM_SIG_START), EEPROM_SIG_LENGTH);
  eeprom_update_byte((uint8_t*)EEPROM_VERSION_START, DEVICE_VERSION_MAJOR);
  eeprom_update_byte((uint8_t*)EEPROM_VERSION_START + 1,
                     DEVICE_VERSION_MINOR);
  eeprom_update_block((const void*)&webUsbDescriptorStringSerialNumber[1],
                      (void*)EEPROM_SERIAL_START, EEPROM_SERIAL_LENGTH);
}
コード例 #3
0
ファイル: wi07.c プロジェクト: kehribar/xmegaE5
/*-----------------------------------------------------------------------------
/ Tries to parse arguments like:
/  http://192.168.4.1/s,bu_bir_internet_agidir
/ and saves that string to proper EEPROM location
/------------------------------------------------------------------------------
/ tcpData[0 : 4]   => "GET /" => HTTP request header
/ tcpData[5 : 6]   => "s,"    => 's' is the ID for state machine and ',' is seperator
/ tcpData[7 : ...] => actual data we want to parse and store
/----------------------------------------------------------------------------*/
uint16_t parseTCP_setAndResponse(const char* name, uint8_t* eepromBaseAddr, uint8_t* ramBuffer, uint8_t maxLen,uint16_t tcpLen,uint8_t* respBuff)
{
  uint8_t ind = 0;

  while((tcpData[ind+7] != ' ') && (ind < (maxLen -1)))
  {
    ramBuffer[ind] = tcpData[ind+7];
    ind++;        
  }

  tcpLen = fill_tcp_data(respBuff,0,HTTP_RESPONSE_HEADER);

  if(ind < (maxLen -1))
  {
    ramBuffer[ind] = '\0';

    eeprom_update_block(ramBuffer,eepromBaseAddr,maxLen);

    tcpLen = fill_tcp_data(respBuff,tcpLen,name); 
    tcpLen = fill_tcp_data(respBuff,tcpLen," set to: ");
    tcpLen = fill_tcp_data(respBuff,tcpLen,ramBuffer);
    tcpLen = fill_tcp_data(respBuff,tcpLen,"\r\n");  
  }
  else
  {
    tcpLen = fill_tcp_data(respBuff,tcpLen,name);
    tcpLen = fill_tcp_data(respBuff,tcpLen," too long!\r\n");
  }

  return tcpLen;
}
コード例 #4
0
ファイル: logger.cpp プロジェクト: Flyingplanet/SkyDrop
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);
}
コード例 #5
0
ファイル: main.c プロジェクト: BennettRand/Dr-Wattson
static bool rfReceivePacket(NWK_DataInd_t *ind) {
	// First figure out what kind of packet this is, and then call the appropreate function.
	switch ((packetType_t) (ind->data[0])) {
	case bacon:
		processBaconPacket(ind);
		break;
	case connectionAck:
		if(processConnectionAck(ind)) {
			ui_baseStationConnected();
			eeprom_update_block(&(baseStationList[connectedBaseStation]), (void*)27, sizeof(struct baseStation));
			eeprom_update_byte((uint8_t*)29, 1); // Force the RSSI of the connected base station to 1 without modifying value in ram.
			eeprom_update_byte((uint8_t*)26, 0xFF);
		}
		break;
	case dataRequest:
		if (ind->size != sizeof(dataRequestPacket_t))
			break;
		memcpy(&datRequest, ind->data, sizeof(dataRequestPacket_t));
		receivedDataRequest = true;
		return false;
		break;
	case dataAck:
		handleDataAck(ind);
		break;
	case coldStart:
		receivedColdStart = true;
		break;
	default:
		break;
	}

	return true;
}
コード例 #6
0
ファイル: eeprom.c プロジェクト: calinalexandru/atmega328p-ip
void eeprom_write_light_cal_factor(uint8_t index, float value)
{
    if(index >= light_cal_size)
        return;

    eeprom_update_block((const void *)&value, (void *)offsetof(eeprom_t, light_cal[index].factor), sizeof(value));
}
コード例 #7
0
ファイル: eeprom.c プロジェクト: calinalexandru/atmega328p-ip
void eeprom_write_temp_cal_offset(uint8_t index, float value)
{
    if(index >= temp_cal_size)
        return;

    eeprom_update_block((const void *)&value, (void *)offsetof(eeprom_t, temp_cal[index].offset), sizeof(value));
}
コード例 #8
0
ファイル: bootloader.c プロジェクト: JohnOH/phatio
int main(void)
{
    MCUSR &= ~(1 << WDRF);
    wdt_disable();

     // led
    SETUPRED();
    SETUPGREEN();
    GREENON();
    REDON();

    uint8_t bootloader_version[5] = "b002";
    eeprom_update_block((void *)&bootloader_version, BOOTLOADER_VERSION_ADDR, 4);

    sd_disk sd;
    _delay_ms(250);

     uint16_t flash = 0;
     if (!sd_init(&sd) && disk_init(&sd)) {
         if (!find_and_load_bootfile(&sd)) {
             flash = 4*3;
         }
     }
     GREENOFF();
     REDOFF();

     for (int i=0; i<flash; i++) {
         REDTOGGLE();
        _delay_ms(250);
      }
    REDOFF();
     __asm__("jmp 0000");
     sd_write_block(0,0);
}
コード例 #9
0
ファイル: logger.cpp プロジェクト: Flyingplanet/SkyDrop
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);

}
コード例 #10
0
void update_highscores(uint8_t name[3], uint16_t score) {
  highscore new_score;
  for(uint8_t i = 0; i < 3; i++) {
    new_score.name[i] = *name;
    name++;
  }
  new_score.score = score;
  highscore new_scores[LIST_SIZE];
  highscore scores[LIST_SIZE];

  eeprom_read_block(scores, 0, sizeof(scores));

  //insert the new score into the scores array
  uint8_t i;
  for(i = 0; i < LIST_SIZE; i++) {
    // if the score is equal or higher, or the score is empty
    if(scores[i].score <= new_score.score || scores[i].score == -1) {
      new_scores[i] = new_score;
      break;
    } else {
      new_scores[i] = scores[i];
    }
  }

  // fill the last positions with stuff from the old leaderboard
  for(uint8_t j = i; j < LIST_SIZE-1; j++) {
    new_scores[j+1] = scores[j];
  }

  // update the eeprom
  eeprom_update_block(new_scores, 0, sizeof(new_scores));
}
コード例 #11
0
int main(void) {

  initUSART();
  char ramString[STRING_LEN];
  uint8_t counter;

  while (1) {
    printString("\r\n------------------\r\n");
    eeprom_read_block(ramString, eepromString, STRING_LEN);
    printString(ramString);

    printString("\r\nThe counter reads: ");
    counter = eeprom_read_byte(&eepromCounter);
    printByte(counter);

    printString("\r\nMy uint16_t value is: ");
    printWord(eeprom_read_word(&eepromWord));

    printString("\r\n   Enter a new introduction string below:\r\n");
    readString(ramString, STRING_LEN);
    eeprom_update_block(ramString, eepromString, STRING_LEN);
    counter++;
    eeprom_update_byte(&eepromCounter, counter);
  }
  return (0);
}
コード例 #12
0
ファイル: main.c プロジェクト: meeg/cee-firmware
void EVENT_USB_Device_ControlOUT(uint8_t* buf, uint8_t count){
	switch (usb_cmd){
		case 0xE1: // Write EEPROM
			eeprom_update_block(buf, (void*)(cmd_data*64), count);
			break;
	}
}
コード例 #13
0
int main(void) {

  char myString[STRING_MAXLEN];
  char *eepromAddress = (char *) STRING_ADDRESS;
  uint16_t counter;

  initUSART();

  while (1) {
    // Read from EEPROM and print out
    eeprom_read_block(myString, eepromAddress, STRING_MAXLEN);
    counter = eeprom_read_word((uint16_t *) COUNTER_ADDRESS);
    printString("\r\nYour old favorite color is: ");
    printString(myString);

    // Take input, store in EEPROM
    printString("\r\n\r\n Type your new favorite color.  ");
    readString(myString, sizeof(myString));
                   /* pass by address, function will change its values */
    eeprom_update_block(myString, eepromAddress, STRING_MAXLEN);
    counter++;
    printString("Thanks! \r\nYou've answered the same question ");
    printWord(counter);
    printString(" times.  \r\n");
    eeprom_update_word((uint16_t *) COUNTER_ADDRESS, counter);
  }

  return 0;
}
コード例 #14
0
ファイル: settings.c プロジェクト: bkbme/CALLogViewer
void settings_set_array(uint8_t key, uint8_t size, const uint8_t *value)
{
	if (key < ArraySettingsKeyCount && size <= ARRAY_SIZE)
	{
		eeprom_update_block((const void*) value, (void*) &eeArraySettings[key], size);
		change_flags |= SettingsArray;
	}
}
コード例 #15
0
ファイル: set_time.cpp プロジェクト: vshama/SkyDrop
void gui_set_time_timezone_cb(float val)
{
	int8_t tmp = val * 2;
	eeprom_busy_wait();
	eeprom_update_block((void *)&config_ee.system.time_zone, (void *)&config.system.time_zone, sizeof(int8_t));
	config.system.time_zone = tmp;
	gui_switch_task(GUI_SET_TIME);
}
コード例 #16
0
ファイル: main.cpp プロジェクト: bubgum/crw-cmu
/**
 * Sets the PID gains to zero-values.
 */
void resetPID()
{
  memset(&pid, 0, sizeof(pid));

  pid.Kp[0] = 32000.0;
  pid.Kp[5] = -32000.0; // We invert the rudder so +-100% is positive RHS angle

  eeprom_update_block(&pid, &pidEeprom, sizeof(pidConstants_t));
}
コード例 #17
0
ファイル: app_config.c プロジェクト: DrMcCoy/contiki-inga
/**
 * Stores config data to EEPROM.
 */
static void
_app_config_save_internal()
{
#if APP_CONF_STORE_EEPROM
  log_i("Saving config to EEPROM...\n");
  system_config._check_sequence = CHECK_SEQUENCE;
  eeprom_update_block(&system_config, &ee_system_config, sizeof (system_config));
#endif
}
コード例 #18
0
ファイル: eeprom.c プロジェクト: sowbug/weblight
void WriteLightProgram(const uint8_t *opcode_buf, uint8_t opcode_buf_len) {
  eeprom_update_byte((uint8_t*)EEPROM_PROGRAM_SIZE, opcode_buf_len);
  if (opcode_buf_len == 0 || opcode_buf_len > EEPROM_PROGRAM_MAX_SIZE) {
    return;
  }
  eeprom_update_block((const void*)opcode_buf,
                      (void*)EEPROM_PROGRAM_START,
                      opcode_buf_len);
}
コード例 #19
0
ファイル: main.c プロジェクト: unwind/minimatrix
static void edit(void) {
	if(config.flags & IS_ANIMATION) {
		config.flags = IS_MARQUEE;
		config.mode.marquee.delay = 10;
		config.mode.marquee.spacing = 1;
		eeprom_update_block(&config, &stored_config.config, sizeof(config));
		eeprom_update_byte(&stored_config.data[0], '\0');
	}
	edit_marquee();
}
コード例 #20
0
ファイル: set_logger.cpp プロジェクト: ChrisDD11/SkyDrop
void gui_set_logger_glider_id_cb(uint8_t ret, char * buff)
{
	if (ret == GUI_TEXT_OK)
	{
		strcpy((char *)config.logger.glider_id, buff);
		eeprom_update_block((void *)config.logger.glider_id, (void *)config_ee.logger.glider_id, LOG_TEXT_LEN);
	}

	gui_switch_task(GUI_SET_LOGGER);
}
コード例 #21
0
void over_write_eeprom(){
	char c[15];
	//uint8_t count=0;
	vStringSend("new pw:");
	vRcvString(c);
	vStringSend("\r\n");
	eeprom_update_block((const void *)c, (void *)USERPW_ADDRESS, 10);
	eeprom_read_block((void*)readblock, (const void*)USERPW_ADDRESS, 10);
	
}
コード例 #22
0
ファイル: sensor_main.c プロジェクト: schugabe/FWS
/**
 * Load values from EEPROM. Apply default values, if data is not valid.
**/
void loadEepromValues(void) {
	// load values from eeprom
	eeprom_read_block(&config, &eeConfig, sizeof(config));

	// check if EEPROM has been erased and apply default values
	if (config.enable == 0xFFFF) {
		memcpy(&config, &defaultConfig, sizeof(config));
		eeprom_update_block(&config, &eeConfig, sizeof(eeConfig));
	}
}
コード例 #23
0
ファイル: conf.cpp プロジェクト: DD1984/skydrop_stm32
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);
}
コード例 #24
0
ファイル: Eeprom.cpp プロジェクト: ScribbleJ/sjfw
 bool beginWrite()
 {
   if(reading || writing)
     return false;
   eepromptr = 0;
   eeprom_busy_wait();
   eeprom_update_block(GUARDSTR, (void *)0, GUARDLEN);
   eepromptr = GUARDLEN;
   writing = true;
   return true;
 }
コード例 #25
0
ファイル: printcounter.cpp プロジェクト: ClumsyApe/Marlin
void PrintCounter::saveStats() {
  #if ENABLED(DEBUG_PRINTCOUNTER)
    PrintCounter::debug(PSTR("saveStats"));
  #endif

  // Refuses to save data if object is not loaded
  if (!this->isLoaded()) return;

  // Saves the struct to EEPROM
  eeprom_update_block(&this->data,
    (void *)(this->address + sizeof(uint8_t)), sizeof(printStatistics));
}
コード例 #26
0
ファイル: menu.c プロジェクト: 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();
	}
}
コード例 #27
0
ファイル: net_conf.c プロジェクト: atalax/avr-uip-2
void net_conf_save(void)
{
	// update functions write if data is different
#if defined(eeprom_update_block)
	// added to avr-lib @ version 1.6.7
	eeprom_update_block((const void *)net_conf_ip_addr,
	                    (void *)NET_CONF_EEMEM_IP_ADDR, 4);
	eeprom_update_block((const void *)net_conf_net_mask,
	                    (void *)NET_CONF_EEMEM_NET_MASK, 4);
	eeprom_update_block((const void *)net_conf_gateway,
	                    (void *)NET_CONF_EEMEM_GATEWAY, 4);
	eeprom_update_byte((uint8_t *)NET_CONF_EEMEM_ENABLE_DHCP, net_conf_enable_dhcp);
#else
	eeprom_write_block((const void *)net_conf_ip_addr,
	                   (void *)NET_CONF_EEMEM_IP_ADDR, 4);
	eeprom_write_block((const void *)net_conf_net_mask,
	                   (void *)NET_CONF_EEMEM_NET_MASK, 4);
	eeprom_write_block((const void *)net_conf_gateway,
	                   (void *)NET_CONF_EEMEM_GATEWAY, 4);
	eeprom_write_byte((uint8_t *)NET_CONF_EEMEM_ENABLE_DHCP, net_conf_enable_dhcp);
#endif
	// note we don't write the mac here.
}
コード例 #28
0
inline static 
void gravar_ler_sensor_eeprom(sensor * s,valores * eeprom_s)
{
  /* Caso o valor de umas das variaveis for 0 (o que significativa que não houve calibragem)
     nós guardamos nela o valor da ultima calibragem feita(que está salva na eeprom). Do contrário
     nós salvamos os valores da calibragem na eeprom.
   */

  if (s->valor.linha != 0 || s->valor.fundo != 0)
    eeprom_update_block((void *)&s->valor,(void *)eeprom_s,sizeof *eeprom_s);

  else eeprom_read_block((void *)&s->valor,(void *)eeprom_s,sizeof *eeprom_s);

  s->media = (s->valor.fundo + s->valor.linha) / 2;
}
コード例 #29
0
bool sm_write_chunk(uint8_t chunk_id, char* data) {
	// check where the chunk goes: the first chunk goes to the EE_DOMAIN_NAME area of the eeprom
	if(chunk_id == 0) {
		if(data[0] == '\0') // if the first byte of the new name is zero, don't write anything (leave the old name in the eeprom)
			return true;
		cli();
		eeprom_update_block(data, (void*)(EE_DOMAIN_NAME), EE_DOMAIN_NAME_SIZE);
		eeprom_busy_wait();
		sei();
		// The write fails if no function call follows an EEPROM write. This is strangeness.
		_delay_ms(2);
		return true;
	} else { // the other chunks go to the EE_STATEMACHINE_... area
		chunk_id -= 1; // subtract 1 from chunk id, because the first chunk went to the DOMAIN_NAME, so we have to restart counting from 0
		// check if chunk offset is valid
		if(((chunk_id+1) * (EE_STATEMACHINE_CHUNK_SIZE))
				> EE_STATEMACHINE_ID_SIZE +
				EE_STATEMACHINE_N_CONDITIONS_SIZE + EE_STATEMACHINE_CONDITIONS_SIZE
				+ EE_STATEMACHINE_N_DT_TRANSITIONS_SIZE + EE_STATEMACHINE_DATETIME_TRANSITIONS_SIZE
				+ EE_STATEMACHINE_N_TRANSITIONS_SIZE + EE_STATEMACHINE_TRANSITIONS_SIZE) 
		{
			return false;
		} else { // write chunk to eeprom
			cli();
			eeprom_update_block(data,
					(void *)(EE_STATEMACHINE_ID + (chunk_id * EE_STATEMACHINE_CHUNK_SIZE)), 
					EE_STATEMACHINE_CHUNK_SIZE
					);
			eeprom_busy_wait();
			sei();
			// The write fails if no function call follows an EEPROM write. This is strangeness.
			_delay_ms(2);
			return true;
		}
	}
}
コード例 #30
0
ファイル: common.cpp プロジェクト: leachim1/SkyDrop
bool LoadEEPROM()
{
	FILINFO fno;

	if (f_stat("UPDATE.EE", &fno) == FR_OK)
	{
		DEBUG("EE update found.\n");

		FIL * ee_file;
		ee_file = new FIL;

		f_open(ee_file, "UPDATE.EE", FA_READ);
		uint16_t rd = 0;

		byte4 tmp;

		f_read(ee_file, tmp.uint8, sizeof(tmp), &rd);
		if (tmp.uint32 != BUILD_NUMBER)
		{
			gui_showmessage_P(PSTR("UPDATE.EE is not\ncompatibile!"));
			DEBUG("Rejecting update file %lu != %lu\n", tmp.uint32, BUILD_NUMBER);
			delete ee_file;
			return false;
		}

		//rewind the file
		f_lseek(ee_file, 0);
		DEBUG("tell = %d\n", f_tell(ee_file));

		for (uint16_t i = 0; i < fno.fsize; i += rd)
		{
			uint8_t buf[256];

			f_read(ee_file, buf, sizeof(buf), &rd);

			DEBUG("tell = %d\n", f_tell(ee_file));
			DEBUG(" %d / %d\n", i + rd, fno.fsize);

			eeprom_busy_wait();
			eeprom_update_block(buf, (uint8_t *)(APP_INFO_EE_offset + i), rd);
		}

		gui_showmessage_P(PSTR("UPDATE.EE\napplied."));
		delete ee_file;
		return true;
	}
	return false;
}