Пример #1
0
static void gettimeofday_init(void)
{
	int days, delta;
	struct tm tm;

	rtc_read_clock(&tm);
	private_clock.ticks = rdtsc64();

	/* Calculate the number of days in the year so far */
	days = day_of_year(tm.tm_mon, tm.tm_mday, tm.tm_year + 1900);

	delta = tm.tm_year - 70;

	days += (delta * 365);

	/* Figure leap years */

	if (delta > 2)
	  days += (delta - 2) / 4;

	private_clock.secs = (days * 86400) + (tm.tm_hour * 3600) +
		(tm.tm_min * 60) + tm.tm_sec;
}
Пример #2
0
static void parse_buffer( void ) {
     Channel_t ch_data[4];
     uint8_t  ch  = 0;
     uint8_t  res = 0;
     uint32_t val = 0;
     rtc_clock_t datetime;

     int year, month, date, hour, min, sec;


     switch( buffer[0] ) {
	  
     case '.':
	  printf_P( PSTR("%s\r\n"), buffer );
	  break;

     case '*':
	  uart1_puts( buffer+1 );
	  uart1_putc( 13 );
	  break;

     case 'V':
     case 'v':
	  printf_P( PSTR("%d.%d\r\n"), SWVERSIONMAJOR, SWVERSIONMINOR );
	  break;

     case 'L':
     case 'l':
	  printf_P( PSTR("%02X\r\n"), PINA );
	  break;

     case 'A':
     case 'a':

	  printf_P( PSTR("%i, %i, %i, %i\r\n"), 
		    adc_get_ch(0),
		    adc_get_ch(1),
		    adc_get_ch(2),
		    adc_get_ch(3)
	       );
	  
	  break;

     case 'c':


	  res = sscanf_P( &buffer[1], PSTR ("20%2x-%2x-%2x %2x:%2x:%2x"), &year, &month, &date, &hour, &min, &sec);

	  // set clock?
	  if (res==6) {
/*
	       printf_P( PSTR(" setting to: 20%02X-%02X-%02X %02X:%02X:%02X\r\n"), 
			 year,
			 month,
			 date,
			 hour,
			 min,
			 sec
		    );
*/

	       datetime.year  = year;
	       datetime.month = month;
	       datetime.date  = date;
	       datetime.hour  = hour;
	       datetime.min   = min;
	       datetime.sec   = sec;
	  
	       rtc_write_clock( &datetime );

	  }
	  
	  rtc_read_clock( &datetime );
	  
	  printf_P( PSTR("20%02X-%02X-%02X %02X:%02X:%02X\r\n"), 
		    datetime.year,
		    datetime.month,
		    datetime.date,
		    datetime.hour,
		    datetime.min,
		    datetime.sec
	       );


	  break;

     case 'C':

	  val = ms_now();
	  
	  printf_P( PSTR("%lu msec\r\n"), val );
	  
	  break;

	  
     case 'T':
     case 't':

	  s0_getChannelData( 0, &ch_data[0], 0 );
	  s0_getChannelData( 1, &ch_data[1], 0 );
	  s0_getChannelData( 2, &ch_data[2], 0 );
	  s0_getChannelData( 3, &ch_data[3], 0 );
	  
	  printf_P( PSTR("%lu, %lu, %lu, %lu\r\n"), 
		    ch_data[0].count, 
		    ch_data[1].count, 
		    ch_data[2].count, 
		    ch_data[3].count 
	       );
	  
	  break;

     case 'P':
     case 'p':

	  s0_getChannelData( 0, &ch_data[0], 0 );
	  s0_getChannelData( 1, &ch_data[1], 0 );
	  s0_getChannelData( 2, &ch_data[2], 0 );
	  s0_getChannelData( 3, &ch_data[3], 0 );

	  printf_P( PSTR("%lu, %lu, %lu, %lu\r\n"), 
		    ch_data[0].period,
		    ch_data[1].period, 
		    ch_data[2].period,
		    ch_data[3].period
	       );
	  
	  break;

     case 'r':
     case 'R':

	  switch( buffer[1] ) {
	       
	  case '1':
	  case 'B':
	  case 'b':
	       ch = 1;
	       break;
	       
	  case '2':
	  case 'C':
	  case 'c':
	       ch = 2;
	       break;
	       
	  case '3':
	  case 'D':
	  case 'd':
	       ch = 3;
	       break;
	       
	  default:
	       ch = 0;
	       
	  }

	  s0_getChannelData( ch, &ch_data[0], (buffer[0] == 'R') );
	  
	  printf_P( PSTR("%lu, %lu, %lu, %lu, %lu, %lu, %lu, %lu, %lu\r\n"), 
		     ms_now(),
		     ch_data[0].count,   // 1
		     ch_data[0].pcount,  // 2
		     ch_data[0].period,  // 3
		     ch_data[0].avg_cnt, // 4
		     ch_data[0].avg_sum, // 5
		     ch_data[0].min,     // 6
		     ch_data[0].max,     // 7
		     ch_data[0].last     // 8
	       );
	  
	  break;

     case 's':
     case 'S':

	  res = sscanf_P( &buffer[1], PSTR ("%i %lu"), &ch, &val);

	  if (ch<4) {

	       if (res == 2)
		    s0_setChannelTicks( ch, val );
	       
	  } else 
	       ch = 0;
	  

	  s0_getChannelData( ch, &ch_data[0], 0 );
	  printf_P( PSTR("%lu\r\n"), ch_data[0].count );
	  
	  break;

     case 'o':
     case 'O':

	  res = sscanf_P( &buffer[1], PSTR ("%i"), &ch);

	  if (res == 111) { // disabled ...
	       printf_P( PSTR("OK %d\r\n"), ch ? 1 : 0 );
	  } else {
	       printf_P( PSTR("?\r\n") );
	  }
	       
	  break;
	  
     case 'w':
     case 'W':

	  res = sscanf_P( &buffer[1], PSTR ("%i"), &ch);

	  if (res == 1) { // disabled ...
	       wd_set = ch;
	  }

	  printf_P( PSTR("OK %d\r\n"), wd_set );
	       
	  break;
	  

     case 'X':
     case 'x':

	  printf_P( PSTR("rebooting\r\n") );

	  while (1);
	  
	  break;
	  
	  
     default:
        printf_P( PSTR("?\r\n") );

     }
	  
}