예제 #1
0
u08 ve_read_write (char cmd, u08 display)
{
   int d;

   EIndex = EE_VAREDITOR;          // starting address

 
   if(cmd=='W') {  // Write to EEPROM

      // write marker first so that erased EEPROM can be detected
      // this will make an assumption that EE_VAREDITOR has not been changed as would
      // be possible if flashing new program code, but leaving EERPOM untouched

          // checksum might be nicer here, but this is simple

      d = 0xFACE;
  
      while(!eeprom_is_ready());               
      eeprom_write_block(&d,(void *) EIndex,2);  // write marker
      EIndex += 2;
   }

   // if Reading, look for marker

   if (cmd=='R') {
      while (!eeprom_is_ready());               
      eeprom_read_block(&d,(void*) EIndex,2);
      if (d != 0xFACE) return (0);    // EEPROM does not contain saved var editor data
      EIndex+=2;
   }      


   if(vePort==-1) {
     if(display) {
        lcd_clear();
        if (cmd=='R') lcd_textPS(0,0,"Reading EEPROM");
                else           lcd_textPS(0,0,"Writing EEPROM");
     }
   }
   else  
   {   if (cmd=='R') printf(PS("\nReading EEPROM..."));
       else           printf(PS("\nWriting EEPROM..."));
 
   }

   if (cmd=='R') veFlags = _BV(veREAD);
   else          veFlags = _BV(veWRITE);

   ve_process();            // iterate through all vars
   veFlags = 0;

   if (vePort==-1)
   { if(display) delay_ms(1000); } 
   else
   printf (PS("Finished\n\n"));

   return (1); // success

}
예제 #2
0
long ve_bit1(char *s, long v, u08 BitNum, u08 OnOffLabel)
{
   if(ve_flag(veREAD)) {  // Reading  From EEPROM   
      if(ve_flag(veEEPROM_NO_RW)) return(v); // this var is disabled from EEPROM RW 

      while (!eeprom_is_ready());               

      if(eeprom_read_byte((void*) EIndex++)) v |= (1<<BitNum);
   }
   else if(ve_flag(veWRITE)) {  // Writing To EEPROM
      if(ve_flag(veEEPROM_NO_RW)) return(v); // this var is disabled from EEPROM RW 

      while (!eeprom_is_ready());               

      if(bit_is_set(v,BitNum)) eeprom_write_byte((void*) EIndex++,1);
      else                     eeprom_write_byte((void*) EIndex++,0);
   }
   else if((veGroupI == veCurGroup) && (++veVarI == veCurVar)) {   // if current variable

      if(ve_flag(veCOUNT_VARS)) return(v);  // iterating just to get counts

      veCurVal = MAXLONG;   // flag to not draw slider
          
      if(veDelta < 0) v &= ~_BV(BitNum);  // - turn off
      if(veDelta > 0) v |= _BV(BitNum);   // + turn on

      veDelta = 0;

#ifdef RES_128x64
      lcd_setxy(0,CHAR_HEIGHT*3);                 
      printf("%s ", s);
#else
      lcd_setxy(0,CHAR_HEIGHT*4);                 
      printf("%s ", s);
#endif

      if(bit_is_set(v,BitNum)) {
        if(OnOffLabel) printf("ON");
        else           printf("1");
      } 
      else {
        if(OnOffLabel) printf("OFF");
        else           printf("0");
      } 
   

      if (vePort != -1) printf (PS("\n"));
   }

   return(v);
   // options for load/save
}
예제 #3
0
/*
 * int ifs_init(void): Initialize IFS files
 */
int ifs_init(void)
{
	uint8_t *src, *dest;
#if FLASHEND >0xffff
	uint32_t flash_src;
#define flash_read_byte(addr) pgm_read_byte_far(addr)
#else
	uint16_t flash_src;
#define flash_read_byte(addr) pgm_read_byte_near(addr)
#endif /* FLASHEND */

	// initialize .ifs_int_0
	for(dest = __ifs_int_0_start; dest < __ifs_int_0_end; dest++) {
		*dest = 0x00;
	}
	// poll until eeprom is ready
	while(!eeprom_is_ready()) ;
	src =__ifs_int_eep_loadstart;
	for(dest = __ifs_int_eep_start; dest < __ifs_int_eep_end; dest++) {
		*dest = eeprom_read_byte(src++);
	}
#if FLASHEND >0xffff
	flash_src = ptr_to_ui32(__ifs_int_flash_loadstart);
#else
	flash_src = __ifs_int_flash_loadstart;
#endif /* FLASHEND */
	for(dest = __ifs_int_flash_start; dest < __ifs_int_flash_end; dest++) {
		*dest = flash_read_byte(flash_src++);
	}
#if defined (USE_EXT_RAM)
	// initialize .ifs_ext_0
	for(dest = __ifs_ext_0_start; dest < __ifs_ext_0_end; dest++) {
		*dest = 0x00;
	}
	// poll until eeprom is ready
	while(!eeprom_is_ready()) ;
	src =__ifs_ext_eep_loadstart;
	for(dest = __ifs_ext_eep_start; dest < __ifs_ext_eep_end; dest++) {
		*dest = eeprom_read_byte(src++);
	}
#if FLASHEND >0xffff
	flash_src = ptr_to_ui32(__ifs_ext_flash_loadstart);
#else
	flash_src = __ifs_ext_flash_loadstart;
#endif /* FLASHEND */
	for(dest = __ifs_ext_flash_start; dest < __ifs_ext_flash_end; dest++) {
		*dest = flash_read_byte(flash_src++);
	}
#endif /* USE_EXT_RAM */
	return 0;
}
예제 #4
0
void MyEeprom::write_ulong(uint32_t l, uint16_t relative_address) {
  cli();
  while (!eeprom_is_ready());
    uint16_t pCurrentOffset = currentOffset;
    if (firstAddress + (currentOffset + 2) * (dataLength + servisInfo) > maxAddress) {
        currentOffset = 0;
    } else { currentOffset++; }
    uint8_t tb = 0;
    int32_t currentNAddress = firstAddress + currentOffset * (dataLength + servisInfo) + servisInfo;
    int32_t currentOAddress = firstAddress + pCurrentOffset * (dataLength + servisInfo) + servisInfo;   
    for (uint16_t i = 0; i < dataLength; i++) {
        if (i == relative_address) {
            eeprom_write_byte((uint8_t*)(currentNAddress + i + 0), *((uint8_t*)&l + 0));
            eeprom_write_byte((uint8_t*)(currentNAddress + i + 1), *((uint8_t*)&l + 1));
            eeprom_write_byte((uint8_t*)(currentNAddress + i + 2), *((uint8_t*)&l + 2));
            eeprom_write_byte((uint8_t*)(currentNAddress + i + 3), *((uint8_t*)&l + 3));
            i+=3;
        } else {
          tb = eeprom_read_byte((uint8_t*)(currentOAddress + i));
          eeprom_write_byte((uint8_t*)(currentNAddress + 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();
}
예제 #5
0
uint8_t MyEeprom::readByte(uint16_t relative_address) {
  while (!eeprom_is_ready());
  if (rotateEeprom == true) {
    return(eeprom_read_byte((uint8_t*)(firstAddress + currentOffset * (dataLength + servisInfo) + servisInfo + relative_address)));
  } else { 
    return(eeprom_read_byte((uint8_t*)(firstAddress + servisInfo + relative_address)));
  }
}
예제 #6
0
/**
 @brief	Replace HTML's variables to system configuration value
*/
static uint16_t replace_sys_env_value(
	uint8_t* base, 	/**< pointer to html buffer */
	uint16_t len
	)
{
	uint8_t sys_string[16]; // if there are more characters to substituted in response file, then make this bigger
	uint8_t *tptr, *ptr;
	time_t time_stamp;
	tm local_time;

	tptr = ptr = base;

	while((ptr = (uint8_t*)strchr((char*)tptr, '$')))
	{
		if((tptr = (uint8_t*)strstr((char*)ptr, EVB_PAGES_SERVED)))
		{
			memset(tptr,0x20,14); // erase system variable trigger string
			if( eeprom_is_ready() )
				sprintf_P((char *)sys_string, PSTR("%08u"), eeprom_read_dword(&pagesServed) ); // number of pages served by the http server.
			memcpy(tptr,sys_string,8); // copy the characters, but don't copy the /0
			tptr+=8;
		}

#if defined (portRTC_DEFINED)
		else if((tptr = (uint8_t*)strstr((char*)ptr, EVB_RTC)))
		{
			memset(tptr,0x20,11); // erase system variable trigger string
			if ( getDateTimeDS1307( (tm*)&local_time ) == pdTRUE)
				sprintf_P((char *)sys_string, PSTR("%02u:%02u:%02u"), local_time.tm_hour, local_time.tm_min, local_time.tm_sec);
			memcpy(tptr,sys_string,8);  // copy the characters, but don't copy the /0
			tptr+=8;
		}
#else
		else if((tptr = (uint8_t*)strstr((char*)ptr, EVB_RTC)))
		{
			memset(tptr,0x20,11); // erase system variable trigger string
	    	time(&time_stamp);
	    	localtime_r( &time_stamp, &local_time);
			sprintf_P((char *)sys_string, PSTR("%02d:%02d:%02d"), local_time.tm_hour, local_time.tm_min, local_time.tm_sec);
			memcpy(tptr,sys_string,8);  // copy the characters, but don't copy the /0
			tptr+=8;
		}
#endif
		else	// tptr == 0 && ptr!=0;
		{
			if(ptr==base)
			{
//				xSerialPrint_P(PSTR("$ Character"));
				return len;
			}
//			xSerialPrint_P(PSTR("REPLACE CONTINUE"));
			tptr = ptr;
			break;
		}
	}
	if(!ptr) return len;
	return (uint16_t)(tptr-base);
}
예제 #7
0
void MyEeprom::simple_write_byte(uint8_t b, uint16_t relative_address) {
    cli();
    while (!eeprom_is_ready());
    if (eeprom_read_byte((uint8_t*)firstAddress) == P_INVALID) {
      eeprom_write_byte((uint8_t*)firstAddress, P_VALID);
    }
    eeprom_write_byte((uint8_t*)firstAddress + servisInfo + relative_address, b);
    sei();
}
예제 #8
0
extern void read_signals(void) {

    uchar_t buffer[20];

    uchar_t size, pos = 0, pos1;
    uchar_t signal_type;
    uchar_t controller_size;

    uchar_t i;


    // mark unused configurations
    for ( i=0; i<8; i++ )
        configuration[0][i].si = 0;


    while ( !eeprom_is_ready() );
    eeprom_read_block(buffer, conf_buffer, 20);

    // is eeprom flashed?
    if ( buffer[pos++] != EEPROM_MAGIC )
        return;

    size = buffer[pos ++];

    while ( pos < size ) {

        current_controller = buffer[pos++];
        controller_size = buffer[pos++];

        pos1 = pos+controller_size;

        while ( pos < pos1 ) {
            current_signal = buffer[pos++];
            signal_type = buffer[pos++];

            CONF.si = signal_type;

            switch ( signal_type ) {
            case 1: // ST_CONTROL_DIGITAL
            case 2: // ST_CONTROL_ANALOG
                pos = configure_as_control(buffer, pos, signal_type);
                break;
            case 3: // ST_STATUS
                pos = configure_as_status(buffer, pos);
                break;
            default:
                // panic!!!
                break;
            }
        }

    }


}
예제 #9
0
void MyEeprom::simple_write_ulong(uint32_t l, uint16_t relative_address) {
  cli();
  while (!eeprom_is_ready());  
    if (eeprom_read_byte((uint8_t*)firstAddress) == P_INVALID) {
      eeprom_write_byte((uint8_t*)firstAddress, P_VALID);
    }
    eeprom_write_byte((uint8_t*)firstAddress + servisInfo + relative_address + 0, *((uint8_t*)&l + 0));
    eeprom_write_byte((uint8_t*)firstAddress + servisInfo + relative_address + 1, *((uint8_t*)&l + 1));
    eeprom_write_byte((uint8_t*)firstAddress + servisInfo + relative_address + 2, *((uint8_t*)&l + 2));
    eeprom_write_byte((uint8_t*)firstAddress + servisInfo + relative_address + 3, *((uint8_t*)&l + 3));
    sei();
}
예제 #10
0
bool EasyVRBridge::checkEEPROM()
{
  uint8_t b0 = eeprom_read_byte(BRIDGE_ID0);
  uint8_t b1 = eeprom_read_byte(BRIDGE_ID1);
  if (b0 != 'B')
  {
    while (!eeprom_is_ready());
    eeprom_write_byte(BRIDGE_ID0, 'B');
  }
  else if (b1 == 'b')
  {
    while (!eeprom_is_ready());
    eeprom_write_byte(BRIDGE_ID1, 'B');
    return true;
  }
  if (b1 != 'B')
  {
    while (!eeprom_is_ready());
    eeprom_write_byte(BRIDGE_ID1, 'B');
  }    
  return false;
}
예제 #11
0
uint32_t MyEeprom::readULong (uint16_t relative_address) {
  uint32_t l = 0;
  uint32_t cAddress = 0;
  if (rotateEeprom == true) {
    cAddress = firstAddress + currentOffset * (dataLength + servisInfo) + servisInfo + relative_address;
  } else {
    cAddress = firstAddress + servisInfo + relative_address;
  }
  while (!eeprom_is_ready());
  *((uint8_t*)&l + 0) = eeprom_read_byte((uint8_t*)(cAddress + 0));
  *((uint8_t*)&l + 1) = eeprom_read_byte((uint8_t*)(cAddress + 1));
  *((uint8_t*)&l + 2) = eeprom_read_byte((uint8_t*)(cAddress + 2));
  *((uint8_t*)&l + 3) = eeprom_read_byte((uint8_t*)(cAddress + 3));
  return l;
}
예제 #12
0
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();
}
예제 #13
0
uint8_t EepromReadConfig(void * baseadr, void * buf, uint8_t len)
{
  struct netCheckSum_t checksum;

  // wait for eeprom
  while (eeprom_is_ready() == 0);

  // read config and checksum
  eeprom_read_block(buf,baseadr,len);
  eeprom_read_block(&checksum,baseadr+len,sizeof(checksum));

  // before calculating the checksum, we check if they are interlocked
  if (checksum.positive != ~checksum.negative)
    return 0; // read config failed (bad checksum)

  // as they are interlocked, it's time to proove the checksum
  if (calculateCheckSum(buf,len) != checksum.positive)
    return 0; // read config failed (bad checksum)

  return 1; // data is valid
}
예제 #14
0
void initUSB()
{
	uint8_t uCalVal;

	do {} while (!eeprom_is_ready());
    uCalVal = eeprom_read_byte(OSCCAL_EEPROM_ADDR); // calibration value from last time
	/* Check that returned calibration value is valid before setting OSCCAL. */
    if (uCalVal != 0xff) OSCCAL = uCalVal;

  /* Note about eeprom_read: As these functions modify IO registers, they are
   * known to be non-reentrant. If any of these functions are used from both,
   * standard and interrupt context, the applications must ensure proper
   * protection (e.g. by disabling interrupts before accessing them).
   * Note: It's unclear whether hadUsbReset is in an interrupt context. */

    // read module type from last time
    uint8_t stored_module_type = eeprom_read_byte(MODULE_TYPE_EEPROM_ADDR);
	/* Check that returned calibration value is valid before setting module_type. */
    if (stored_module_type != 0xff && stored_module_type != 0) {
      module_type = stored_module_type;
    }

	/* Enable watchdog timer */
    wdt_enable(WDTO_2S);

    usbInit();
    usbDeviceDisconnect();  // enforce re-enumeration, do this while interrupts are disabled!

	// fake USB disconnect for > 250 ms
	// If delay is longer than watchdog timeout, split this into smaller delays
	// with wdt_reset called in between.
	wdt_reset();
	_delay_ms(USB_DISCONNECT_DELAY_MS);
	wdt_reset();

    usbDeviceConnect();
}
예제 #15
0
MyEeprom::MyEeprom (uint32_t first_address, uint32_t max_address, uint16_t data_length, bool reload_pages) {
  /*if (first_address + data_length + 1 > max_address) {
      return null;
  }*/
  firstAddress = first_address;
  maxAddress = max_address;
  dataLength = data_length;
  rotateEeprom = true;

  if (reload_pages == false) { currentOffset = 0; }
  else {
      bool found = false;
      currentOffset = 0;
      while (!eeprom_is_ready());
      while ((first_address + currentOffset * (data_length + servisInfo) < max_address) && (!found)) {
          if (eeprom_read_byte((uint8_t*)(first_address + currentOffset * (data_length + servisInfo))) == P_VALID) {
              found = true;
          } else {
              currentOffset++;
          }
      }
      if (!found) { currentOffset = 0; }
  }
}
예제 #16
0
int16_t cmd_decode (uint8_t *buffer_ptr)
{

 uint8_t  cmd_no =0;
 uint8_t  *cmd_argument;
 uint8_t   i,j ;
 
// Should repeat until end of buffer
 
// Loop until end of text

   cmd_argument = buffer_ptr;
     
   while ( cmd_no !=  CMD_LINE_END)     // Until end of line which mean g_motor will change
   {
 		cmd_no =  text_decode (buffer_ptr,cmd_argument);
#ifdef DEBUG		
		uart_puts("Command :");
 		uart_putc(0x30+cmd_no);
 		uart_putc('*');
 		uart_puts(cmd_argument);
#endif        
 		switch (cmd_no)
		{
			case MOTOR_CMD: 
				g_motor = (uint8_t)atoi(cmd_argument);
				if (g_motor > 0)
				   g_motor--;                //  > 0 Start from 0 need -1
				else
				   g_motor = 0;
 				break;
			case  SPEED_CMD:	
				i = (uint8_t)atoi(cmd_argument);
				if ( i >=  MOTOR_MAX_SPEED)
						i = MOTOR_MAX_SPEED;    // Start from 0
				if (i)   // i > 0; 		
					i--;   //Start from 0;		
				g_speed[g_motor] =  g_speed_table[i];
				if (g_speed[g_motor] == 0)
				        g_mode[g_motor] = MOTOR_STOP;
  				break;
			case  ANGLE_CMD:   // Can be - 	             			 
     			g_angle[g_motor] = atoi(cmd_argument);
				if (g_angle[g_motor] < 0)
				{   
						g_mode[g_motor] = MOTOR_BACKWARD;
 
// Set g_angle to positive value by invert all bit and +1                
                        g_angle[g_motor] = (~(g_angle[g_motor])+1);
                        if  (g_angle[g_motor] > 1)
						{
 						   g_angle[g_motor] *= MOTOR_ANGLE_COEF;
						   g_status[g_motor] = 1;
 						   g_speed[g_motor] = g_speed_table[MOTOR_ANGLE_SPEED] ;
						}		
				}	
				else  if (g_angle[g_motor] == 0)
				       {  	
							g_mode[g_motor] = MOTOR_STOP;
 					   }
				else	  
				{
					if ((g_angle[g_motor] > 0))   //  +
					{
						g_mode[g_motor] = MOTOR_FORWARD;
 					}
					if  (g_angle[g_motor] > 1)
					{
 						g_angle[g_motor] *=  MOTOR_ANGLE_COEF;	
						g_status[g_motor] = 1;
  						g_speed[g_motor]  = g_speed_table[MOTOR_ANGLE_SPEED] ;
					}
 				}
                g_pos[g_motor] = 0;
				break;	
			case PROGRAM_CMD:
				g_program_flag = (uint8_t)atoi(cmd_argument);
				if (g_program_flag)   // Start  program save in buffer
				{
					uart_puts ("Program Start to save : ");
				     g_program_index = 0;
				}
				else
				{  
					uart_puts ("Program End : ");
				}
				break;
 			case SAVE_CMD:
				j = (uint8_t)atoi(cmd_argument);
				if ( j > 0)    // Save commmand to eeprom
                {
					g_program_buff[g_program_index] = 0x00 ;  // Put null at the end
                    g_program_index++;   
                    for ( i =0; i < g_program_index; i++)
                    {
						while (!eeprom_is_ready());
							eeprom_write_byte(&g_program_eeprom[i],g_program_buff[i]);
					}
					debug_value( g_program_index,10);
					uart_puts ("Save complete ");
					g_program_index = 0;	
				}
				break;
		    case RUN_CMD:
			    program_run();
			    break;
 			default:
			    uart_putc(0x0D);
				uart_putc(0x0A);
 		        break;	  
		}		
    }
 
 return 0; 
}
예제 #17
0
bool EEPROMClassEx::isReady() {
	return eeprom_is_ready();
}
예제 #18
0
	void StorageManager::writeByte(uint8_t * address, uint8_t data)
	{
		while ( !eeprom_is_ready() ) {}
		eeprom_write_byte(address, data);
	}
예제 #19
0
	uint8_t StorageManager::readByte(uint8_t * address)
	{
		while ( !eeprom_is_ready() ) {}
		return eeprom_read_byte(address);
	}
예제 #20
0
파일: EEPROM.cpp 프로젝트: JJK801/Cosa
bool 
EEPROM::Device::is_ready()
{
  return (eeprom_is_ready());
}
예제 #21
0
파일: lcd.c 프로젝트: Ponderosa/tri_phase
/**********************************************************
* UserService
*
* Arguments:
* Returns:
*
* 
**********************************************************/
void UserService(uint8_t user_button)
{
	/****Static Variables****/
	static uint8_t  top_state = BLANK;
	static uint8_t  previous_user_button;
	static uint16_t temp_address;
	static uint8_t blink_temp;
	
	/****Variables****/
	uint16_t scratch_address;
	
	if (!user_button)
	{
		//countdown to blank
	}
	
	if (previous_user_button == user_button)
	{
		previous_user_button = user_button;
		user_button = 0;
	}
	else
	{
		previous_user_button = user_button;
	}

	switch (top_state)
	{
		case BLANK:		//LCD is OFF
			digit1 = LCD_BLANK;
			digit2 = LCD_BLANK;
			digit3 = LCD_BLANK;
			digit4 = LCD_BLANK;
		
			if (user_button)
			{
				top_state = ADDRESS;
			}
			break;
		case ADDRESS:	//Fixture DMX Address
			digit1 = LCD_A;
			digit2 = LCD_d;
			digit3 = LCD_d;
			digit4 = LCD_r;
			
			switch (user_button)
			{
				case MENU:
					top_state = BLANK;
					break;
				case ENTER:
					temp_address = triphase_address;
					top_state = ADDRESS_EDIT;
					break;
				case UP:
					top_state = FIRMWARE;
					break;
				case DOWN:
					top_state = MOTOR;
					break;
				default:
					break;	
			}
			break; 
		case ADDRESS_EDIT:
			digit4 = AddressDigitLookup(temp_address % 10);
			scratch_address = temp_address / 10;
			digit3 = AddressDigitLookup(scratch_address % 10);
			scratch_address = scratch_address / 10;
			digit2 = AddressDigitLookup(scratch_address % 10);
			digit1 = LCD_BLANK;
			
			switch (user_button)
			{
				case MENU:
					top_state = ADDRESS;
					break;
				case ENTER:
					triphase_address = temp_address;
					if (eeprom_is_ready())
					{
						eeprom_write_word(EEPROM_DMX_ADDRESS, triphase_address);
					}
					top_state = BLANK_ADDRESS;
					break;
				case UP:
					if (MAX_ADDRESS > temp_address)
					{
						temp_address++;
					}					
					else 
					{
						temp_address = MIN_ADDRESS;
					}
					break;
				case DOWN:
					if (MIN_ADDRESS < temp_address)
					{
						temp_address--;
					}
					else
					{
						temp_address = MAX_ADDRESS;
					}
					break;
				default:
					break;
			}			
			break;
		case BLANK_ADDRESS:
			blink_temp++;
			if (blink_temp == 5)
			{
				blink_temp = 0;
				top_state = ADDRESS_EDIT;
			}
			break;
		//case BLINK:
			//break; 
		case MOTOR:
			digit1 = LCD_M;
			digit2 = LCD_P;
			digit3 = LCD_BLANK;
			digit4 = LCD_BLANK;
			
			switch (user_button)
			{
				case MENU:
					top_state = BLANK;
					break;
				case ENTER:
					//top_state = MOTOR_EDIT;
					break;
				case UP:
					top_state = ADDRESS;
					break;
				case DOWN:
					top_state = AUTO;
					break;
				default:
					break;	
			}
			break;
		case AUTO:
			digit1 = LCD_P;
			digit2 = LCD_E;
			digit3 = LCD_r;
			digit4 = LCD_F;
		
			switch (user_button)
			{
				case MENU:
					top_state = BLANK;
					break;
				case ENTER:
					//top_state = AUTO_EDIT;
					break;
				case UP:
					top_state = MOTOR;
					break;
				case DOWN:
					top_state = BLIND;
					break;
				default:
					break;	
			}
			break;
		case BLIND:
			digit1 = LCD_6;
			digit2 = LCD_L;
			digit3 = LCD_n;
			digit4 = LCD_d;
		
			switch (user_button)
			{
				case MENU:
					top_state = BLANK;
					break;
				case ENTER:
					//top_state = BLIND_EDIT;
					break;
				case UP:
					top_state = AUTO;
					break;
				case DOWN:
					top_state = DISPLAY;
					break;
				default:
					break;	
			} 
			break;
		case DISPLAY:
			digit1 = LCD_d;
			digit2 = LCD_1;
			digit3 = LCD_5;
			digit4 = LCD_P;
		
			switch (user_button)
			{
				case MENU:
					top_state = BLANK;
					break;
				case ENTER:
					//top_state = DISPLAY_EDIT;
					break;
				case UP:
					top_state = BLIND;
					break;
				case DOWN:
					top_state = HOURS;
					break;
				default:
					break;	
			}
			break;
		case HOURS:
			digit1 = LCD_F;
			digit2 = LCD_H;
			digit3 = LCD_r;
			digit4 = LCD_5;
		
			switch (user_button)
			{
				case MENU:
					top_state = BLANK;
					break;
				case ENTER:
					//top_state = HOURS_SHOW;
					break;
				case UP:
					top_state = DISPLAY;
					break;
				case DOWN:
					top_state = FIRMWARE;
					break;
				default:
					break;	
			}
			break;
		case FIRMWARE:
			digit1 = LCD_U;
			digit2 = LCD_E;
			digit3 = LCD_r;
			digit4 = LCD_BLANK;
		
			switch (user_button)
			{
				case MENU:
					top_state = BLANK;
					break;
				case ENTER:
					//top_state = FIRMWARE_SHOW;
					break;
				case UP:
					top_state = HOURS;
					break;
				case DOWN:
					top_state = ADDRESS;
					break;
				default:
					break;	
			}
			break;
		default:
			top_state = BLANK;
			break;
	}
}
예제 #22
0
/**
 * Check if EEPROM memory is ready to be accessed
 */
bool Eeprom::isReady()
{
    return eeprom_is_ready();
}
예제 #23
0
파일: eeprom.c 프로젝트: 13416795/contiki
/*---------------------------------------------------------------------------*/
void
eeprom_read(eeprom_addr_t addr, unsigned char *buf, int size)
{
  while(!eeprom_is_ready());
  eeprom_read_block(buf, (unsigned short *)addr, size);
}
예제 #24
0
int main ()
{
    void *p;

    /* Fill all EEPROM.	*/
    for (p = 0; p <= (void *)E2END; p++)
	eeprom_write_byte (p, (int)(p + 1));
    
    /* Update a byte.	*/
    {
	unsigned char *p = (unsigned char *)1;
	
	eeprom_update_byte (p, 2);	/* the same value	*/
	if (!eeprom_is_ready ()) exit (__LINE__);
	if (eeprom_read_byte (p) != 2) exit (__LINE__);

	eeprom_update_byte (p, 0x12);	/* different value	*/
	if (eeprom_is_ready ()) exit (__LINE__);
	if (eeprom_read_byte (p) != 0x12) exit (__LINE__);
    }

    /* Update a word.	*/
    {
	unsigned int *p = (unsigned int *)2;

	eeprom_update_word (p, 0x0403);		/* the same value	*/
	if (!eeprom_is_ready ()) exit (__LINE__);
	if (eeprom_read_word (p) != 0x0403) exit (__LINE__);

	eeprom_update_word (p, 0x0413);
	if (eeprom_is_ready ()) exit (__LINE__);
	if (eeprom_read_word (p) != 0x0413) exit (__LINE__);

	eeprom_update_word (p, 0x1413);
	if (!eeprom_is_ready ()) exit (__LINE__);
	if (eeprom_read_word (p) != 0x1413) exit (__LINE__);
    }

    /* Update a double word.	*/
    {
	unsigned long *p = (unsigned long *)4;

	eeprom_update_dword (p, 0x08070605);	/* the same value	*/
	if (!eeprom_is_ready ()) exit (__LINE__);
	if (eeprom_read_dword (p) != 0x08070605) exit (__LINE__);

	eeprom_update_dword (p, 0x08070615);
	if (eeprom_is_ready ()) exit (__LINE__);
	if (eeprom_read_dword (p) != 0x08070615) exit (__LINE__);

	eeprom_update_dword (p, 0x08071615);
	if (!eeprom_is_ready ()) exit (__LINE__);
	if (eeprom_read_dword (p) != 0x08071615) exit (__LINE__);

	eeprom_update_dword (p, 0x08171615);
	if (!eeprom_is_ready ()) exit (__LINE__);
	if (eeprom_read_dword (p) != 0x08171615) exit (__LINE__);

	eeprom_update_dword (p, 0x18171615);
	if (!eeprom_is_ready ()) exit (__LINE__);
	if (eeprom_read_dword (p) != 0x18171615) exit (__LINE__);
    }

    /* Update a block.	*/
    {
	unsigned char *p = (unsigned char *)8;
	unsigned char s[5];
	
	memcpy_P (s, PSTR ("\x09\x0A\x0B\x0C\x0D"), 5);
	eeprom_update_block (s, p, 5);
	if (!eeprom_is_ready ()) exit (__LINE__);
	memset (s, 0, sizeof (s));
	eeprom_read_block (s, p, 5);
	if (memcmp_P (s, PSTR ("\x09\x0A\x0B\x0C\x0D"), 5)) exit (__LINE__);

	memcpy_P (s, PSTR ("\x19\x0A\x0B\x0C\x0D"), 5);
	eeprom_update_block (s, p, 5);
	if (eeprom_is_ready ()) exit (__LINE__);
	memset (s, 0, sizeof (s));
	eeprom_read_block (s, p, 5);
	if (memcmp_P (s, PSTR ("\x19\x0A\x0B\x0C\x0D"), 5)) exit (__LINE__);

	memcpy_P (s, PSTR ("\x19\x0A\x0B\x0C\x1D"), 5);
	eeprom_update_block (s, p, 5);
	if (!eeprom_is_ready ()) exit (__LINE__);
	memset (s, 0, sizeof (s));
	eeprom_read_block (s, p, 5);
	if (memcmp_P (s, PSTR ("\x19\x0A\x0B\x0C\x1D"), 5)) exit (__LINE__);
	
	memcpy_P (s, PSTR ("\x1A\x1B\x1C"), 3);
	eeprom_update_block (s, p + 1, 1);
	eeprom_update_block (s + 1, p + 2, 2);
    }

    /* Check all EEPROM.	*/
    for (p = 0; p <= (void *)E2END; p++) {
	unsigned char c;
	c = (int)p + ((p && (p < (void *)13)) ? 0x11 : 1);
	if (eeprom_read_byte (p) != c)
	    exit (__LINE__);
    }

    return 0;
}
예제 #25
0
void chb_eeprom_read(U16 addr, U8 *buf, U16 size)
{
  while(!eeprom_is_ready());
  eeprom_read_block(buf, (U16 *)addr, size);
}
예제 #26
0
long ve_int1(char *s, long v, u08 vsize, long min, long max) 
{
char ns[COLS/CHAR_WIDTH+1];
long p;

   p = 0; 

   if(ve_flag(veREAD)) {  // Read From EEPROM
      if(ve_flag(veEEPROM_NO_RW)) return(v); // this var is disabled from EEPROM RW 
      
      while (!eeprom_is_ready());               
      eeprom_read_block(&p,(void*) EIndex,vsize);
      EIndex += vsize;

//    veVarCount++;   

      // sign extension issues??
      // maybe code datatype in list
      // 8 16 32  signed unsigned      

      switch(vsize) {
         case 1: v = (u08)  p;   break;
         case 2: v = (int)  p;   break;
         case 4: v = (long) p;   break;
      }

      return(v);
   }

   
   if(ve_flag(veWRITE)) {  // Write to EEPROM
      if(ve_flag(veEEPROM_NO_RW)) return(v); // this var is disabled from EEPROM RW 

      while(!eeprom_is_ready());               
      eeprom_write_block(&v,(void *) EIndex, vsize);  // a
      EIndex += vsize;
//    veVarCount++;
      return (v);
   }


   if((veGroupI == veCurGroup) && (++veVarI == veCurVar)) {   // if current variable

     if(ve_flag(veCOUNT_VARS)) return(v);

     if (veStoreSerialBuffer)
         {
       veStoreSerialBuffer = 0;                

       // 0x could do hex scan ?

       veBuf[veBufIndex]   = 0;            // add null terminator
       sscanf(veBuf, "%ld", &v);

     }
     

     if(ve_flag(veUPDATE_FROM_SLIDER)) {
        v = veCurVal;
        ve_clrflag(veUPDATE_FROM_SLIDER);
     }


     if (vePort == -1) {

        if(ve_flag(veCALL_INPUT_DIALOG)) {

#ifdef RES_128x64
           sprintf(ns, "%-13s", s);
           v = menu_calc(ns, NO_MATH|FIX_MODE|NO_DP_CHANGE) / calc_scale;     // invoke calculator for number input/edit with no math
#else
           sprintf(ns, "%-16s", s);
           v = menu_calc(ns, NO_MATH|FIX_MODE|NO_DP_CHANGE) / calc_scale;     // invoke calculator for number input/edit with no math
#endif
//     sprintf(ns, "%ld", v);
//     v = menu_calc(ns, EVAL_TITLE|FIX_MODE|NO_DP_CHANGE) / calc_scale;     // invoke calculator for number input/edit with no math

          ve_clrflag(veCALL_INPUT_DIALOG);
          veDelta = 0;

        }      
      }  
       

        v += veDelta;   // add delta to variable 
        veDelta = 0;    // reset delta

        if(v < min) v = min;
        if(v > max) v = max;


      if (vePort == -1) {


      // Note: on printf statements below -- do not use PS on format strings
          // to save RAM. Buffer allocated by PS macro is being used by parameter s
          // s will be overwritten and you will see the format string appear in output 

#ifdef RES_128x64
         lcd_setxy(0,CHAR_HEIGHT*3);                 
         printf("%s %ld", s, v); // show var label and value
#else
         lcd_setxy(0,CHAR_HEIGHT*4);                 
         printf("%s %ld", s, v); // show var label and value
#endif
      } 


      veCurMin = min;
      veCurMax = max;
      veCurVal = v;

      //if (vePort != -1) printf ("%s : %s %ld \n",veCurGroupStr,s,v);

      if (vePort != -1) printf ("%s %ld \n",s,v);
   }

   if(v < min) v = min;   // clip to min max range regardless of match 
   if(v > max) v = max;   // this applied to every var needed ???
  

   return(v);

   // options for load/save
}