/********************************************//** * @brief Funkcja kalibrujaca offset DAC * @param speed : wartosc zmiany (-128 - 127) * @return uint8_t : aktualna wartosc (0 - 255) ***********************************************/ uint8_t DACOffsetCalib(int8_t val) { uint8_t offset = eeprom_read_byte(&e_offset); if((uint16_t)offset + val < 256 && offset + val >= 0) offset+= val; eeprom_write_byte(&e_offset, offset); DACB.OFFSETCAL=offset; return offset; }
/********************************************//** * @brief Funkcja kalibrujaca wzmocnienie DAC * @param speed : wartosc zmiany (-128 - 127) * @return uint8_t : aktualna wartosc (0 - 255) ***********************************************/ uint8_t DACGainCalib(int8_t val) { uint8_t gain = eeprom_read_byte(&e_gain); if((uint16_t)gain + val < 256 && gain + val >= 0) gain+= val; eeprom_write_byte(&e_gain, gain); DACB.GAINCAL=gain; return gain; }
void _EEPROM_writeData(int &pos, uint8_t* value, uint8_t size) { do { eeprom_write_byte((unsigned char*)pos, *value); pos++; value++; }while(--size); }
int EEPROM::Device::write(void* dest, const void* src, size_t size) { uint8_t* dp = (uint8_t*) dest; const uint8_t* sp = (const uint8_t*) src; size_t res = size; while (size--) eeprom_write_byte(dp++, *sp++); return (res); }
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; }
void writeColor(uint8_t color, uint8_t* base){ uint8_t i = RING_BUFFER_LEN; uint8_t* loc = base; while(i-->1){// Not going to bother to check if we can skip writing. if(0 != eeprom_read_byte(loc)){ eeprom_write_byte(loc++,0); if(color != 0) eeprom_write_byte(loc,color); return; } loc++; } // Otherwise, nuke the last byte with 0, and write the new value to the beginning if(0 != eeprom_read_byte(loc)) eeprom_write_byte(loc,0); if(color != 0) eeprom_write_byte(base,color); }
void initializeDelays() { detectorOnDelay = eeprom_read_byte((uint8_t*)(CHANNEL0_ON_DELAY)); if (0xFF == detectorOnDelay || 0x00 == detectorOnDelay) { eeprom_write_byte((uint8_t*)(CHANNEL0_ON_DELAY), 4); detectorOnDelay = eeprom_read_byte((uint8_t*)(CHANNEL0_ON_DELAY)); } detectorOffDelay = eeprom_read_byte((uint8_t*)(CHANNEL0_OFF_DELAY)); if (0xFF == detectorOffDelay || 0x00 == detectorOffDelay) { eeprom_write_byte((uint8_t*)(CHANNEL0_OFF_DELAY), 25); detectorOffDelay = eeprom_read_byte((uint8_t*)(CHANNEL0_OFF_DELAY)); } }
void try_reset_eeprom() { const char* symbol = "C_Quencer 0.4"; char id_str[13]; for (int i=0; i<13; ++i) { eeprom_busy_wait(); id_str[i] = eeprom_read_byte((uint8_t*)(i+1000)); } if (strncmp(id_str, symbol, sizeof(id_str)) != 0) { for (int i=0; i<1000; ++i) { eeprom_busy_wait(); eeprom_write_byte((uint8_t*)i, 0); } eeprom_write_block(symbol, (uint8_t*)1000, sizeof(symbol)); for (int i=0; i<13; ++i) { eeprom_busy_wait(); eeprom_write_byte((uint8_t*)(i+1000), symbol[i]); } } }
void lcd_material_store_material(uint8_t nr) { eeprom_write_word(EEPROM_MATERIAL_TEMPERATURE_OFFSET(nr), material[active_extruder].temperature); eeprom_write_word(EEPROM_MATERIAL_BED_TEMPERATURE_OFFSET(nr), material[active_extruder].bed_temperature); eeprom_write_word(EEPROM_MATERIAL_FLOW_OFFSET(nr), material[active_extruder].flow); eeprom_write_byte(EEPROM_MATERIAL_FAN_SPEED_OFFSET(nr), material[active_extruder].fan_speed); eeprom_write_float(EEPROM_MATERIAL_DIAMETER_OFFSET(nr), material[active_extruder].diameter); //eeprom_write_block(card.longFilename, EEPROM_MATERIAL_NAME_OFFSET(nr), 8); }
/** * @fn void main(void) * @brief eeprom emulation main function entry * */ void main (void) { U16 i; U8 tmp; SFRPAGE_SWITCH() ENABLE_VDDMON() DISABLE_WDT() SFRPAGE_RESTORE() eeprom_init(); for(i = 0;i< EE_SIZE ;i++) { if(eeprom_read_byte(i,&test_buf[i]) == ERROR) goto error; } for(i = 0;i < 2;i++) { test_buf[i] = i + 0x55; if(eeprom_write_byte(i, test_buf[i]) == ERROR) goto error; } tmp = 0; while(tmp < 50){ for(i = 2;i< EE_SIZE; i++) { test_buf[i] = i + 1; if(eeprom_write_byte(i, test_buf[i] + tmp) == ERROR) goto error; } tmp++; } for(i = 0; i< EE_SIZE; i++) { if(eeprom_read_byte(i,&test_buf[i]) == ERROR) goto error; if((i == 0) || (i == 1)){ if ((test_buf[0] != 0x55) || (test_buf[1] != 0x56)) goto error; }else{ if (test_buf[i] != (i + tmp)) goto error; } } while(1); error: i = 0xDEAD; while(1); }
void Preset::save(uint8_t index){ uint8_t buf[MIDI_ZONE_PRESET_SIZE]; uint8_t* offset = getAddress(index); eeprom_write_byte(offset++, size); for(uint8_t i=0; i<size; ++i){ uint8_t bts = writeZone(buf, i); eeprom_write_block(buf, offset, bts); offset += bts; } }
void pgm_set_program_state( u8 slot, u8 state ) { u8 newstate = state ? ( pgm_mask | ( 1 << slot ) ) : ( pgm_mask & ( u8 )~( 1 << slot ) ); if( newstate == pgm_mask ) return; pgm_mask = newstate; eeprom_write_byte( PGMADDR, pgm_mask ); eeprom_busy_wait(); }
int write_to_eeprom(struct eeprom *e, FILE *fp, int addr, char* pBuffer, int size) { int ret = -1; int i; if ( e != (struct eeprom *) NULL && pBuffer != NULL ) { if( strlen(pBuffer) >= size ) { for( i = 0, ret = 0; ret == 0 && i < size; i++ ) { if( (ret=eeprom_write_byte(e, addr++, pBuffer[i])) ) { fprintf(stderr, "write error at addr %0x\n", addr); } } } else { for( i = 0, ret = 0; ret == 0 && i < size; i++ ) { if( (ret=eeprom_write_byte(e, addr++, pBuffer[0])) ) { fprintf(stderr, "write error at addr %0x\n", addr); } } } } #ifdef _OLD_STYLE_MODE int c; while((c = fgetc(fp)) != EOF) { fflush(stdout); if(eeprom_write_byte(e, addr++, c)) { fprintf(stderr, "write error at addr %0x\n", addr); } } #endif // _OLD_STYLE_MODE return( ret ); }
bool lcd_material_verify_material_settings() { bool hasUPET = false; uint8_t cnt = eeprom_read_byte(EEPROM_MATERIAL_COUNT_OFFSET()); if (cnt < 2 || cnt > EEPROM_MATERIAL_SETTINGS_MAX_COUNT) return false; while(cnt > 0) { cnt --; if (eeprom_read_word(EEPROM_MATERIAL_TEMPERATURE_OFFSET(cnt)) > HEATER_0_MAXTEMP) return false; // if (eeprom_read_word(EEPROM_MATERIAL_BED_TEMPERATURE_OFFSET(cnt)) > BED_MAXTEMP) // return false; if (eeprom_read_byte(EEPROM_MATERIAL_FAN_SPEED_OFFSET(cnt)) > 100) return false; if (eeprom_read_word(EEPROM_MATERIAL_FLOW_OFFSET(cnt)) > 1000) return false; if (eeprom_read_float(EEPROM_MATERIAL_DIAMETER_OFFSET(cnt)) > 10.0) return false; if (eeprom_read_float(EEPROM_MATERIAL_DIAMETER_OFFSET(cnt)) < 0.1) return false; eeprom_read_block(card.longFilename, EEPROM_MATERIAL_NAME_OFFSET(cnt), 8); if (strcmp_P(card.longFilename, PSTR("UPET")) == 0) hasUPET = true; } cnt = eeprom_read_byte(EEPROM_MATERIAL_COUNT_OFFSET()); if (!hasUPET && cnt < EEPROM_MATERIAL_SETTINGS_MAX_COUNT) { strcpy_P(card.longFilename, PSTR("UPET")); eeprom_write_block(card.longFilename, EEPROM_MATERIAL_NAME_OFFSET(cnt), 5); eeprom_write_word(EEPROM_MATERIAL_TEMPERATURE_OFFSET(cnt), 250); // eeprom_write_word(EEPROM_MATERIAL_BED_TEMPERATURE_OFFSET(cnt), 60); eeprom_write_byte(EEPROM_MATERIAL_FAN_SPEED_OFFSET(cnt), 50); eeprom_write_word(EEPROM_MATERIAL_FLOW_OFFSET(cnt), 100); eeprom_write_float(EEPROM_MATERIAL_DIAMETER_OFFSET(cnt), 2.85); eeprom_write_byte(EEPROM_MATERIAL_COUNT_OFFSET(), cnt + 1); } return true; }
void PrintCounter::initStats() { #if ENABLED(DEBUG_PRINTCOUNTER) PrintCounter::debug(PSTR("initStats")); #endif this->loaded = true; this->data = { 0, 0, 0, 0, 0.0 }; this->saveStats(); eeprom_write_byte((uint8_t *) this->address, 0x16); }
unsigned char GetActiveParamSetNumber(void) { unsigned char set; set = eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET]); if(set > 5) { set = 2; eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], set); // diesen Parametersatz als aktuell merken } return(set); }
static uint8_t write_byte(uint8_t *p, uint8_t data) { if(0x00 <= p && p < 0x100) { error_state(); return 0; } else { eeprom_write_byte(p, data); } return 1; }
static void writeLEDMode(void) { // LED 모드 저장, 너무많은 eeprom접근을 막기위해 일정 간격으로 저장한다. const int countMAX = 1000; if(ledStateCount > 0 && ++ledStateCount == countMAX){ // DEBUG_PRINT(("writeLEDMode : mode %d, br %d \n", _fullLEDMode, _ledBrightnessMax)); ledStateCount = 0; if(_fullLEDMode != _fullLEDMode_saved){ _fullLEDMode_saved = _fullLEDMode; eeprom_write_byte((uint8_t *)EEPROM_LED_MODE, _fullLEDMode); // 1바이트 11번지 쓰기 // DEBUG_PRINT(("eeprom_write_byte : mode %d \n", _fullLEDMode)); } // brightness if(_ledBrightnessMax_saved != _ledBrightnessMax){ _ledBrightnessMax_saved = _ledBrightnessMax; eeprom_write_byte((uint8_t *)EEPROM_LED_BRIGHTNESS, _ledBrightnessMax); // 1바이트 9번지 쓰기 // DEBUG_PRINT(("eeprom_write_byte : _ledBrightnessMax %d \n", _ledBrightnessMax)); } } }
static void test_rollover_to_zero() { test("test_rollover_to_zero"); uint32_t *memory = (uint32_t *)112; eeprom_write_dword(memory, 0xFFFFFFFF); eeprom_write_byte((uint8_t *)memory + 4, 0xa5); uint32_t result = increment_eeprom_uint32(memory); assert(result == 0x00000000); assert(eeprom_read_dword(memory) == 0x00000000); assert(eeprom_read_byte((uint8_t *)memory + 4) == 0xa5); }
static void pgm_init() { // Check internal EEPROM data if( eeprom_read_byte( PGMADDR ) == 0xFF ) // initial EEPROM is blank { eeprom_write_byte( PGMADDR, 0x00 ); eeprom_busy_wait(); } pgm_mask = eeprom_read_byte( PGMADDR ); pgm_crt = pgm_get_first_index(); }
/* Modify module type. */ void update_module_type(uint8_t new_type) { module_type = new_type; init_modules(); // Keep module_type state in memory. TODO: Does this stay in EEPROM // even when I re-run micronucleus? We wouldn't want that though. // Unsure whether this is in interrupt context or standard context here cli(); eeprom_write_byte(MODULE_TYPE_EEPROM_ADDR, module_type); sei(); }
// Set station name to eeprom void OpenSprinkler::set_station_name(byte sid, char tmp[]) { int i=0; int start = ADDR_EEPROM_STN_NAMES + (int)sid * STATION_NAME_SIZE; tmp[STATION_NAME_SIZE]=0; while(1) { eeprom_write_byte((unsigned char *)(start+i), tmp[i]); if (tmp[i]==0 || i==(STATION_NAME_SIZE-1)) break; i++; } return; }
void MyEeprom::write_byte(uint8_t b, uint16_t relative_address) { cli(); while (!eeprom_is_ready()); uint16_t pCurrentOffset = currentOffset; if (firstAddress + (currentOffset + 1) * (dataLength + servisInfo) > maxAddress) { currentOffset = 0; } else { currentOffset++; } uint8_t tb = 0; for (uint16_t i = 0; i < dataLength; i++) { if (i == relative_address) { eeprom_write_byte((uint8_t*)(firstAddress + currentOffset * (dataLength + servisInfo) + servisInfo + i), b); } else { tb = eeprom_read_byte((uint8_t*)(firstAddress + pCurrentOffset * (dataLength + servisInfo) + servisInfo + i)); eeprom_write_byte((uint8_t*)(firstAddress + currentOffset * (dataLength + servisInfo) + servisInfo + i), tb); } } eeprom_write_byte((uint8_t*)(firstAddress + currentOffset * (dataLength + servisInfo)), P_VALID); eeprom_write_byte((uint8_t*)(firstAddress + pCurrentOffset * (dataLength + servisInfo)), P_INVALID); sei(); }
void togglePreset(){ if (CURRENT_PRESET >= (MAX_PRESETS - 1)) { CURRENT_PRESET = 0; } else { CURRENT_PRESET++; } eeprom_write_byte(&EEPROM_PRESET, CURRENT_PRESET); loadPreset(); }
uint_least8_t ADS7846_writeCalibration(uint16_t eeprom_addr) { if (tp_matrix.div != 0) { eeprom_write_byte((uint8_t *) eeprom_addr++, 0x55); eeprom_write_block((void *)&tp_matrix, (void *)eeprom_addr, sizeof(CAL_MATRIX)); return 1; } return 0; }
/* * hibernate(time2wake, offset, mode) - enter a hibernate state * * Waspmote enters hibernate. The device is off and no variable will be stored * in RAM memory * */ void WaspPWR::hibernate(const char* time2wake, uint8_t offset, uint8_t mode) { int retries = 3; // set EEPROM Hibernate flag eeprom_write_byte((unsigned char *) HIB_ADDR, HIB_VALUE); pinMode(XBEE_PW,OUTPUT); digitalWrite(XBEE_PW, LOW); //~ closeSerial(0); //~ while(digitalRead(GPS_PW)) //~ { //~ digitalWrite(GPS_PW,LOW); //~ } // switch multiplexers power supply Utils.muxOFF(); RTC.ON(); // Set RTC alarme to wake up from Sleep Power Down Mode RTC.setAlarm1(time2wake,offset,mode); // get backup of selected Alarm uint8_t day_aux = RTC.day_alarm1; uint8_t hour_aux = RTC.hour_alarm1; uint8_t minute_aux = RTC.minute_alarm1; uint8_t second_aux = RTC.second_alarm1; // get Alarm RTC.getAlarm1(); // check Alarm was correctly set if( ( day_aux != RTC.day_alarm1 ) || ( hour_aux != RTC.hour_alarm1 ) || ( minute_aux != RTC.minute_alarm1 ) || ( second_aux != RTC.second_alarm1 ) ) { return (void)0; } RTC.OFF(); pinMode(RTC_SLEEP,OUTPUT); digitalWrite(RTC_SLEEP,HIGH); delay(50); digitalWrite(RTC_SLEEP,LOW); // To avoid executing any other function after calling hibernate while( retries > 0 ) { retries--; pinMode(RTC_SLEEP,OUTPUT); digitalWrite(RTC_SLEEP,HIGH); delay(50); digitalWrite(RTC_SLEEP,LOW); delay(50); } }
void DataWarehouse::putData( int16_t data, uint8_t dataType, uint8_t hour ) { uint8_t todayIndex; uint8_t dataTypeIndex; uint8_t hourIndex; todayIndex = eeprom_read_byte((const uint8_t *)STORE_ADDR_TODAYINDEX); dataTypeIndex = getDataTypeIndex(dataType); hourIndex = hour2Index(hour); eeprom_write_byte( (uint8_t *)STORE_ADDR_VALIDFLAG, ~DATA_VALID ); writeData( data, todayIndex, dataTypeIndex, hourIndex ); eeprom_write_byte( (uint8_t *)STORE_ADDR_VALIDFLAG, DATA_VALID ); DBG_PRINT("putData:") DBG_PRINTLN_VAR(dataType, DEC); DBG_PRINTLN_VAR(data, DEC); }
void lcd_material_store_current_material() { for(uint8_t e=0; e<EXTRUDERS; e++) { eeprom_write_word(EEPROM_MATERIAL_TEMPERATURE_OFFSET(EEPROM_MATERIAL_SETTINGS_MAX_COUNT+e), material[e].temperature); eeprom_write_word(EEPROM_MATERIAL_BED_TEMPERATURE_OFFSET(EEPROM_MATERIAL_SETTINGS_MAX_COUNT+e), material[e].bed_temperature); eeprom_write_byte(EEPROM_MATERIAL_FAN_SPEED_OFFSET(EEPROM_MATERIAL_SETTINGS_MAX_COUNT+e), material[e].fan_speed); eeprom_write_word(EEPROM_MATERIAL_FLOW_OFFSET(EEPROM_MATERIAL_SETTINGS_MAX_COUNT+e), material[e].flow); eeprom_write_float(EEPROM_MATERIAL_DIAMETER_OFFSET(EEPROM_MATERIAL_SETTINGS_MAX_COUNT+e), material[e].diameter); } }
/** * \ingroup usartcmdline * \b WOL-Befehl Wake-On-Lan Paket versenden */ int16_t command_wol (char *outbuffer) { if (outbuffer) // nur bei USART return cmd_502(outbuffer); #if USE_WOL uint32_t var = 0; // EEPROM beschreiben, falls Parameter angegeben wurden if (getLong(&var)) { //schreiben der MAC for (unsigned char count = 0; count<6; count++) { eeprom_busy_wait (); eeprom_write_byte((unsigned char *)(WOL_MAC_EEPROM_STORE + count),(uint8_t)var); if (!getLong(&var)) break; } //zusätzlich schreiben der Broadcast-Adresse, falls vorhandenden if (getLong(&var)) { for (unsigned char count = 0; count<4;++count) { eeprom_busy_wait (); eeprom_write_byte((unsigned char*)(WOL_BCAST_EEPROM_STORE + count),(uint8_t)var); if (!getLong(&var)) break; } } //init wol_init(); }else{ //MagicPacket senden wol_request(); } #endif //USE_WOL return 0; }
void set_tune() { uint8_t i; // set up port B DDRB = _BV(OUTPIN); // set output pin PORTB = ~_BV(OUTPIN); // set pullups on inputs // set test mode --- play all "hit" sounds if TESTIN is 0 while (!(PINB & _BV(TESTIN))) { for (i=0; i<(sizeof(list)/sizeof(list[0])); i++) { PLAYTIME = (uint8_t*) (pgm_read_word(list+i)); hit(); _delay_loop_1(250); // delay 1000 cycles // select tune using PICKTUNE if (!(PINB & _BV(PICKTUNE))){ if (PINB & _BV(FOILEPEE)) eeprom_write_byte(&ee_epeesong, i); else eeprom_write_byte(&ee_foilsong, i); break; } } } i = eeprom_read_byte(&ee_foilsong); if (i < (sizeof(list)/sizeof(list[0]))) foil_song = (uint8_t*) (pgm_read_word(list+i)); else foil_song = (uint8_t*) (pgm_read_word(list)); i = eeprom_read_byte(&ee_epeesong); if (i < (sizeof(list)/sizeof(list[0]))) epee_song = (uint8_t*) (pgm_read_word(list+i)); else epee_song = (uint8_t*) (pgm_read_word(list+1)); return; }