////////////////////////////////////////////////////////////////////////////////
// read_app_register
//
void read_app_register( uint08_t reg )
{
	SendMsg.priority = VSCP_PRIORITY_MEDIUM;
	SendMsg.vscp_class = VSCP_CLASS1_PROTOCOL;
	SendMsg.vscp_type = VSCP_TYPE_PROTOCOL_RW_RESPONSE;
	SendMsg.length =  2;
	SendMsg.data[0] = reg;
	SendMsg.data[1] = 0x00; // default read

	switch ( reg ) {
		// Zone
		case 0x21:
			SendMsg.data[1] = readEEPROM( REG_APP_ZONE );
			break;
		// SubZone
		case 0x22:
			SendMsg.data[1] = readEEPROM( REG_DOOR_SUBZONE );
			break;		

		default:
			SendMsg.data[1] = 0;	
			break;	
	}
	// Send data
	VSCP_enqMsgTx( &SendMsg, FALSE);	
}
///////////////////////////////////////////////////////////////////////////////
// write_app_register
//
void write_app_register( uint08_t reg, uint08_t val )
{
	SendMsg.priority = VSCP_PRIORITY_MEDIUM;
	SendMsg.vscp_class = VSCP_CLASS1_PROTOCOL;
	SendMsg.vscp_type = VSCP_TYPE_PROTOCOL_RW_RESPONSE;
	SendMsg.length = 2;
	SendMsg.data[0] = reg;
	SendMsg.data[1] = ~val; // error return

	switch ( reg ) {
		// Zone
		case 0x23:
			writeEEPROM( REG_APP_ZONE, val);
			SendMsg.data[1] = readEEPROM( REG_APP_ZONE);
			break;
		// SubZone
		case 0x24:
			writeEEPROM( REG_DOOR_SUBZONE, val);
			SendMsg.data[1] = readEEPROM( REG_DOOR_SUBZONE);
			break;	

		default:
			SendMsg.data[1] = ~val; // error return	
			break;
	}
	// Send data
	VSCP_enqMsgTx( &SendMsg, FALSE);	
} 
Beispiel #3
0
bool Persistence::load()
{
    //free any previous loaded data
    flush();

    //load variable count
    readEEPROM(_mainPosition, (byte *)&_count, sizeof(_count));

    //validate variable count
    if ( _count > 0 && _count < MAX_VARIABLES )
    {
        //load data size
        readEEPROM(_mainPosition + sizeof(_count), (byte *)&_size, sizeof(_size));

        //copy data
        if (_size > 0)
        {
            _properties = (Property *) malloc(_size);
            readEEPROM(_mainPosition + sizeof(_count) + sizeof(_size), (byte *)_properties, _size);
            fixPointers();
        }

        return true;
    }
    else
    {
        _count = 0;
        return false;
    }
}
void doActionCtrlLed( unsigned char dmflags, unsigned char arg )
{
	unsigned char i;
	unsigned char val;
	uart_puts("action\n");	
	for ( i=0; i<8; i++ ) {
		
		// If the rely should not be handled just move on
		if ( !( arg & ( 1 << i ) ) ) continue;
		
		// Check if subzone should match and if so if it match
		if ( dmflags & VSCP_DM_FLAG_CHECK_SUBZONE ) {
			if ( vscp_imsg.data[ 2 ] != readEEPROM( VSCP_EEPROM_END + 
															REG_SWITCH0_SUBZONE + 
															i ) ) {
				continue;
			}
		}
			
		val = readEEPROM( VSCP_EEPROM_END + REG_SWITCH0_SUBZONE + i );
		
	
		PORTB ^= _BV(i);
									
//		// Should off event be sent?
//		if( val & RELAY_CONTROLBIT_ONEVENT ) {
//			SendInformationEvent( i, VSCP_CLASS1_INFORMATION, VSCP_TYPE_INFORMATION_ON );			
//		}
		
		// Should stop event be sent?
//		if( val & RELAY_CONTROLBIT_STARTEVENT ) {
//			SendInformationEvent( i, VSCP_CLASS1_INFORMATION, VSCP_TYPE_INFORMATION_START );
//		}
	}	
}
int main(void)
{
	tm gmt;
	WatchDogDisable();
	NutDelay(100);
	SysInitIO();
	SPIinit();
	LedInit();
	LcdLowLevelInit();
	Uart0DriverInit();
	Uart0DriverStart();
	LogInit();
	LogMsg_P(LOG_INFO, PSTR("-----------------------------------------------------------------------------------------------"));
	CardInit();
	X12Init();
	if (X12RtcGetClock(&gmt) == 0)
	{
		LogMsg_P(LOG_INFO, PSTR("RTC time [%02d:%02d:%02d]\n"), gmt.tm_hour, gmt.tm_min, gmt.tm_sec );
	}
	if (At45dbInit() == AT45DB041B)
	{
		
	}
	RcInit();
	KbInit();
	SysControlMainBeat(ON);             // enable 4.4 msecs hartbeat interrupt
	NutThreadSetPriority(1);
	NutTimerInit();
	sei();

	printf("\nreading EEPROM\n");
	NutSleep(1000);
	readEEPROM();
	printf("UTC: %d\n",IMCconfig.UTC);
	NutSleep(1000);

	IMCconfig.UTC++;	
	printf("na ophoging UTC: %d\n",IMCconfig.UTC);
	saveEEPROM();
	NutSleep(1000);
	readEEPROM();
	printf("na saving en reading UTC: %d\n",IMCconfig.UTC);

	printf("\nResetting EEPROM\n");
	NutSleep(1000);
	resetEEPROM();
	NutSleep(1000);
	readEEPROM();

	for (;;)
	{
		
	}

	return(0);      // never reached, but 'main()' returns a non-void, so.....
}
Beispiel #6
0
void writeEEPROM(uint8_t b, uint8_t updateProfile)
{
    FLASH_Status status;
    uint32_t i;
    uint8_t chk = 0;
    const uint8_t *p;
    int tries = 0;

    // prepare checksum/version constants
    mcfg.version = EEPROM_CONF_VERSION;
    mcfg.size = sizeof(master_t);
    mcfg.magic_be = 0xBE;
    mcfg.magic_ef = 0xEF;
    mcfg.chk = 0;

    // when updateProfile = true, we copy contents of cfg to global configuration. when false, only profile number is updated, and then that profile is loaded on readEEPROM()
    if (updateProfile) {
        // copy current in-memory profile to stored configuration
        memcpy(&mcfg.profile[mcfg.current_profile], &cfg, sizeof(config_t));
    }

    // recalculate checksum before writing
    for (p = (const uint8_t *)&mcfg; p < ((const uint8_t *)&mcfg + sizeof(master_t)); p++)
        chk ^= *p;
    mcfg.chk = chk;

//taskENTER_CRITICAL();

    // write it
retry:
    FLASH_Unlock();
    FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPRTERR);

    if (FLASH_ErasePage(FLASH_WRITE_ADDR) == FLASH_COMPLETE) {
        for (i = 0; i < sizeof(master_t); i += 4) {
            status = FLASH_ProgramWord(FLASH_WRITE_ADDR + i, *(uint32_t *) ((char *)&mcfg + i));
            if (status != FLASH_COMPLETE) {
                FLASH_Lock();
                tries++;
                if (tries < 3)
                    goto retry;
                else
                    break;
            }
        }
    }
    FLASH_Lock();

//taskEXIT_CRITICAL();

    // Flash write failed - just die now
    if (tries == 3 || !validEEPROM()) {
        failureMode(10);
    }

    // re-read written data
    readEEPROM();
    if (b)
        blinkLED(15, 20, 1);
}
Beispiel #7
0
void writeParams(uint8_t b)
{
    FLASH_Status status;
    uint32_t i;
    uint8_t chk = 0;
    const uint8_t *p;

    cfg.version    = EEPROM_CONF_VERSION;
    cfg.size       = sizeof(config_t);
    cfg.magic_be   = 0xBE;
    cfg.magic_ef   = 0xEF;
    cfg.chk        = 0;
    for (p = (const uint8_t *)&cfg; p < ((const uint8_t *)&cfg + sizeof(config_t)); p++) chk ^= *p; // recalculate checksum before writing
    cfg.chk = chk;
    FLASH_Unlock();                                                                       // write it
    FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPRTERR);
  
    for (i = 0; i < FLASH_PAGES_FORCONFIG; i++)                                           // Erase the pages here
    {
        while (FLASH_ErasePage(FLASH_WRITE_ADDR + (i * FLASH_PAGE_SIZE)) != FLASH_COMPLETE);
    }

    for (i = 0; i < sizeof(config_t); i += 4)                                             // Write that config now.
    {
        status = FLASH_ProgramWord(FLASH_WRITE_ADDR + i, *(uint32_t *) ((char *) &cfg + i));
        if (status != FLASH_COMPLETE) break;                                              // TODO: fail
    }
    FLASH_Lock();
    readEEPROM();
    if (b) blinkLED(15, 20, 1);
}
Beispiel #8
0
void changeProfile(uint8_t profileIndex)
{
    masterConfig.current_profile_index = profileIndex;
    writeEEPROM();
    readEEPROM();
    blinkLedAndSoundBeeper(2, 40, profileIndex + 1);
}
Beispiel #9
0
void writeParams(void)
{
    FLASH_Status status;
    uint32_t i;
    uint8_t chk = 0;
    const uint8_t *p;
    
    cfg.version = EEPROM_CONF_VERSION;
    cfg.size = sizeof(config_t);
    cfg.magic_be = 0xBE;
    cfg.magic_ef = 0xEF;
    cfg.chk = 0;
    // recalculate checksum before writing
    for (p = (const uint8_t *)&cfg; p < ((const uint8_t *)&cfg + sizeof(config_t)); ++p)
        chk ^= *p;
    cfg.chk = chk;
    
    // write it
    FLASH_Unlock();
    FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPRTERR);

    if (FLASH_ErasePage(FLASH_WRITE_ADDR) == FLASH_COMPLETE) {
        for (i = 0; i < sizeof(config_t); i += 4) {
            status = FLASH_ProgramWord(FLASH_WRITE_ADDR + i, *(uint32_t *)((char *)&cfg + i));
            if (status != FLASH_COMPLETE)
                while(1);//break; // TODO: fail
        }
    }

    FLASH_Lock();

    readEEPROM();
}
Beispiel #10
0
void changeProfile(uint8_t profileIndex)
{
    masterConfig.current_profile_index = profileIndex;
    writeEEPROM();
    readEEPROM();
    beeperConfirmationBeeps(profileIndex + 1);
}
void main(void) {
    byte evalue;
    initSquareWear();
    setModeOutput(pinC7);
    latC7 = 0;
    delayMilliseconds(250); // short delay for EEPROM to stablize
    evalue = readEEPROM(0x0);   // read EEPROM address 0
    switch(evalue) {
        case 0:
            writeEEPROM(0x0, 1);    // write next index to EEPROM address 0
            busyEEPROM();           // wait till write completes
            while(1) {
                latC7 = !latC7;
                delayMilliseconds(100);
            }
            break;
        case 1:
            writeEEPROM(0x0, 2);
            busyEEPROM();
            while(1) {
                latC7 = !latC7;
                delayMilliseconds(500);
            }
            break;
        default:
            writeEEPROM(0x0, 0);
            busyEEPROM();
            while(1) {
                latC7 = !latC7;
                delayMilliseconds(1000);
            }
            break;

    }
}
Beispiel #12
0
void readStrEEPROM(char addr, unsigned char length, char *str)
{
	unsigned char i;
	
	for(i=0;i<length;i++)
		str[i] = readEEPROM(addr+i);
}
Beispiel #13
0
void writeParams(uint8_t b) {
  global_conf.currentSet=0;
  conf.checksum = calculate_sum((uint8_t*)&conf, sizeof(conf));
  eeprom_write_block((const void*)&conf, (void*)(global_conf.currentSet * sizeof(conf) + sizeof(global_conf)), sizeof(conf));
  readEEPROM();
  if (b == 1) blinkLED(15,20,1);
}
void MLX90621::initialise(int refrate) {
	refreshRate = refrate;
	Wire.begin(I2C_MASTER, 0, I2C_PINS_18_19, I2C_PULLUP_INT, I2C_RATE_100);
	delay(5);
	readEEPROM();
	writeTrimmingValue();
	setConfiguration();
}
//Initializers that should be called in the `setup()` function
//Initizalize the pin as output and the last value received 
void SensorFlare::DigitalOut::begin()
{
    pinMode(number, OUTPUT);
    Spark.function("digital",controlPin);
    //Initialize the output with the last receive value from SensorFlare    
    readEEPROM();
    digitalWrite(number,EEPROMData.outputData.digitalPin[number]);
  
}
Beispiel #16
0
unsigned char getFCell(void){
	for(int i=0;i<1024;i++){
		if((i%3)==0){
			unsigned char a=readEEPROM(i);
			if(a==0){
				unsigned char b=readEEPROM((i+1));
				if(b==0){
					unsigned char c=readEEPROM((i+2));
					if(c==0){
						return i;
					}
				}
			}
		}
		i+=3;
	}
	return 0;
}
/*
* Read the settings from EEPROM
*/
void Network::readSettings() {
  int j = 4;
  j+= readEEPROM(&mac[0], j, sizeof(mac) * sizeof(uint8_t));
  j+= readEEPROM(&use_dhcp, j, sizeof(bool));
  j+= readEEPROM(&ip, j);
  j+= readEEPROM(&subnet, j);
  j+= readEEPROM(&gateway, j);
  j+= readEEPROM(&dns, j);
  j+= readEEPROM(&httpPort, j, sizeof(httpPort));
  j+= readEEPROM(&websocketPort, j, sizeof(websocketPort));  
}
Beispiel #18
0
///////////////////////////////////////////////////////////////////////////////
//  getSegmentCRC
//
uint08_t vscp_getSegmentCRC( void )
{
	uint08_t aux;
	if (GetResource(RESOURCE_EE_ID) == E_OK)
	{
		aux = readEEPROM( VSCP_EEPROM_SEGMENT_CRC );
		ReleaseResource(RESOURCE_EE_ID);
		return aux;
	}
}
Beispiel #19
0
///////////////////////////////////////////////////////////////////////////////
//  getVSCPControlByte
//
uint08_t vscp_getControlByte( void )
{
	uint08_t aux;
	if (GetResource(RESOURCE_EE_ID) == E_OK)
	{
		aux = readEEPROM( VSCP_EEPROM_CONTROL );
		ReleaseResource(RESOURCE_EE_ID);
		return aux;
	}
}
Beispiel #20
0
///////////////////////////////////////////////////////////////////////////////
//  getNickname
//
uint08_t vscp_getNickname( void )
{
	uint08_t aux;
	if (GetResource(RESOURCE_EE_ID) == E_OK)
	{
		aux = readEEPROM( VSCP_EEPROM_NICKNAME );
		ReleaseResource(RESOURCE_EE_ID);
		return aux;
	}
}
Beispiel #21
0
///////////////////////////////////////////////////////////////////////////////
// getVSCPManufacturerId
// 
// Get Manufacturer id and subid from EEPROM
//
uint08_t vscp_getManufacturerId( uint08_t idx )
{
	uint08_t aux;
	if (GetResource(RESOURCE_EE_ID) == E_OK)
	{
		aux = readEEPROM( VSCP_EEPROM_REG_MANUFACTUR_ID0 + idx );	
		ReleaseResource(RESOURCE_EE_ID);
		return aux;
	}
}
Beispiel #22
0
///////////////////////////////////////////////////////////////////////////////
// getVSCP_GUID
// Get GUID from EEPROM
//
uint08_t vscp_getGUID( uint08_t idx )
{
	uint08_t aux;
	if (GetResource(RESOURCE_EE_ID) == E_OK)
	{
		aux = readEEPROM( VSCP_EEPROM_REG_GUID + idx );		
		ReleaseResource(RESOURCE_EE_ID);
		return aux;
	}
}
Beispiel #23
0
int main()
{
	uint8_t i;

	cli();

	wdt_enable(WDTO_60MS);

	for (i = 0; i < 8; i++) {
		PORTA = PORTA >> 1;
		PORTA |= ((readEEPROM(i) - '0') & 0x01) << 7;
	}

	for (i = 8; i < 16; i++) {
		PORTC = PORTC >> 1;
		PORTC |= ((readEEPROM(i) - '0') & 0x01) << 7;
	}

	DDRA = 0xff;
	DDRC = 0xff;

	for (stackTail = EEPROM_SIZE - 1; readEEPROM(stackTail) != 0xff; stackTail--);

	status = ((uint16_t) PORTC) << 8 | (uint16_t) PORTA;

	initUSART();

	setDuty();

	initTimer0();

	initTimer2();

	sei();

	printf("\nEntering the main loop\n");
	while (1) {
		wdt_reset();
	}

	return 0;
}
Beispiel #24
0
void setup()
{ 
  //Led output
  pinMode(7,OUTPUT);  // PD7
 
  checkEEPROM();
  readEEPROM();
  MAX7456_Setup();
  
  analogReference(DEFAULT);
}
Beispiel #25
0
static void RxMissionACKandResetML(uint8_t acktype)
{
    mavlink_message_t m;
    if (ScheduleEEPROMwriteMS && acktype != MAV_MISSION_ACCEPTED)       // Error and a faulty writeaction is scheduled
    {
        ScheduleEEPROMwriteMS = 0;                                      // Abort planned saving
        readEEPROM();                                                   // Reload already stored stuff
    }
    mavlink_msg_mission_ack_pack(MLSystemID, MLComponentID, &m, SysIDOfPartner, CompIDOfPartner, acktype);
    baseflight_mavlink_send_message(&m);  
    reset_mavlink();
}
void MLX90621::measure() {
	if (checkConfig()) {
		readEEPROM();
		writeTrimmingValue();
		setConfiguration();
	}
	readPTAT();
	readIR();
	calculateTA();
	readCPIX();
	calculateTO();
}
Beispiel #27
0
void systemInit(void)
{
	// Init cycle counter
    cycleCounterInit();

    // SysTick
    SysTick_Config(SystemCoreClock / 1000);

    ///////////////////////////////////

    checkFirstTime(false);
	readEEPROM();

	if (eepromConfig.receiverType == SPEKTRUM)
		checkSpektrumBind();

	checkResetType();

	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);  // 2 bits for pre-emption priority, 2 bits for subpriority

	initMixer();

    ledInit();
    cliInit();

    BLUE_LED_ON;

    delay(20000);  // 20 sec total delay for sensor stabilization - probably not long enough.....

    adcInit();
    batteryInit();
    gpsInit();
    i2cInit(I2C1);
    i2cInit(I2C2);
    pwmEscInit(eepromConfig.escPwmRate);
    pwmServoInit(eepromConfig.servoPwmRate);
    rxInit();
    spiInit(SPI2);
    spiInit(SPI3);
    telemetryInit();
    timingFunctionsInit();

    initFirstOrderFilter();
    initGPS();
    initMax7456();
    initPID();

    GREEN_LED_ON;

    initMPU6000();
    initMag(HMC5883L_I2C);
    initPressure(MS5611_I2C);
}
Beispiel #28
0
/******************************************************************************
 * Function:        void ReadMessageFromEEPROM(void)
 *
 * PreCondition:    None
 *
 * Input:           None
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        This function will save a store message from the EEPROM 
 *                  to memory. If no valid message is on EEPROM, save a 
 *                  default one.
 *
 * Note:            
 *
 *****************************************************************************/
void ReadMessageFromEEPROM()
{
    char length, eeprom_crc, eeprom_message[MESSAGE_LENGTH+1];
        
    eeprom_crc = readEEPROM(0x00);
    length = readEEPROM(0x01);

     // Se o CRC do comprimento da mensagem for incorrecto, n‹o se faz load da mensagem
    if (crc(0,length) != eeprom_crc)
        strcpypgm2ram(message, MESSAGE_DEFAULT);
    else
    {
        eeprom_crc = readEEPROM(0x02);
        readStrEEPROM(0x03, length, eeprom_message);
        eeprom_message[length] = '\0';
        if (strcrc(eeprom_message) != eeprom_crc)
            strcpypgm2ram(message, MESSAGE_DEFAULT);
        else
            strcpy(message, eeprom_message);
    }    
}
Beispiel #29
0
unsigned char validatePassword(long f){
	if(f>0){
		processNumber(f);
		for(int i=0;i<1024;i++){
			if(i%3==0){
				unsigned char a=readEEPROM(i);
				if(a==num1){
					unsigned char b=readEEPROM((i+1));
					if(b==num2){
						unsigned char c=readEEPROM((i+2));
						if(c==num3){
							return 1;
						}
					}
				}
			}
			i+=3;
		}
	}
	return 0;
}
void writeParams(uint8_t b) {
  #ifdef MULTIPLE_CONFIGURATION_PROFILES
    if(global_conf.currentSet>2) global_conf.currentSet=0;
  #else
    global_conf.currentSet=0;
  #endif
  conf.checksum = calculate_sum((uint8_t*)&conf, sizeof(conf));
  eeprom_write_block((const void*)&conf, (void*)(global_conf.currentSet * sizeof(conf) + sizeof(global_conf)), sizeof(conf));
  readEEPROM();
  if (b == 1) blinkLED(15,20,1);
  #if defined(BUZZER)
    alarmArray[7] = 1; //beep if loaded from gui or android
  #endif
}