Exemple #1
0
int main(void) {

	// init
	uart_init(UART_BAUD_SELECT(UART_BAUD_RATE, F_CPU));

	// enable interrupts after resetting the kicker
	sei();
	uart_puts_P("* Interrupts enabled. - ");
	
	ports_init();
	uart_puts_P("Ports initialized. - ");
	
	kicker_init();
	uart_puts_P("Kicker initialized. - ");

	//kicker_uext(500);

	uart_puts_P("Device initialized. Enter main loop\n");

	for (;;) {
		parser_process_uart();
	}

	return 0;
}
Exemple #2
0
static uint8_t I2C_DisplayWrite(void)
 {
  static uint16_t data = 0;
  uint8_t ret = 0;
  
  ret = i2c_start( I2C_DISPLAY | I2C_WRITE);  // set device address and write mode
  
  if ( ret ) {
    /* failed to issue start condition, possibly no device found */
    i2c_stop();
 #ifdef USE_UART
    uart_puts_P("Error - no DISP device!\r\n");
 #endif // USE_UART
    return ret;
  }
  
 #ifdef USE_UART
  uart_puts_P("Data: ");
  int2uart( data );
  uart_puts_P("\r\n");
 #endif // USE_UART
      
  if ( (data % 300) < 100 ) {
  
    i2c_write(0x00); // write remote buffer address (always)
    i2c_write(I2C_DISP_DATA);  // write command
      
    i2c_write(data & 0xff);  // write data bytes to remote buffer
    i2c_write((data & 0xff00) >> 8);

    i2c_write(data & 0xff);
    i2c_write((data & 0xff00) >> 8);

    i2c_stop();
  }
Exemple #3
0
// fill menu_dir file-list
// skipping "start" number of entries while scanning FAT
void menu_builtdir(uint16_t start)
{
	FRESULT res;
	
	res = f_opendir(&dir, ".");
	if (res) { uart_puts_P("f_opendir failed\r\n"); return; }

	for(;;) 
	{
		res = f_readdir(&dir, &Finfo);
		if ((res != FR_OK) || !Finfo.fname[0]) 
			break;
	
		fn = *Finfo.lfname ? Finfo.lfname : Finfo.fname;

		if (fn[0] == '.') continue;
		
		if(Finfo.fattrib & AM_DIR)
			uart_puts_P("/");
			
		if(strstr(strlwr(fn), ".mp3")) // FIXME: memory leak?
		{
		}		
	}
}
Exemple #4
0
static date_t parse_date(void) {

  char* date_pos;
  checked_r(char* token = parse_string(), 0);

  char* ds = strtok_r(token, ".", &date_pos);
  char* ms = strtok_r(NULL, ".", &date_pos);
  char* ys = strtok_r(NULL, ".", &date_pos);

#ifdef COMMANDLINE_DEBUG
  if ( !is_number(ds) || !is_number(ms) || !is_number(ys) ) {
	parse_fail = 1;
	uart_puts_P("ERR: parse_date: no date");
	return 0;
  }
#endif

  uint8_t d = atoi8(ds);
  uint8_t m = atoi8(ms);
  uint8_t y = atoi8(ys);

#ifdef COMMANDLINE_DEBUG
  if ( d > 31 || m > 12 || y > 99 ) {
	parse_fail = 1;
	uart_puts_P("ERR: parse_date: invalid date");
	return 0;
  }
#endif
  
  return date_from_dmy(d, m, y);
}
// TODO: double check datasheet, could be faster (smaller delays)
void humidity_sensor_read(Humidity_Sensor h, char *read_data, uint16_t max_bytes) {
  if (h.write) {} // stop complaining
  i2c_start(AM2315_TWI_ADDRESS_WRITE); // Sensor doesn't respond to start signal
  _delay_ms(2); // TODO: wait could be shorter?
  i2c_stop(); // should be woke now
  if(i2c_start(AM2315_TWI_ADDRESS_WRITE)) {// tell it to generate the temp and hum
    uart_puts_P(PSTR("Couldn't communicate with humidity sensor\r\n"));
    return;
  }
  i2c_write(READREGCODE);
  i2c_write(BEGINREG);
  i2c_write(NUMREGTOREAD);
  i2c_stop();
  _delay_ms(10); // TODO: wait could be shorter?
  uint8_t ret[NUMBYTESTOSTORE];
  i2c_start(AM2315_TWI_ADDRESS_READ); // now read the data
  for (int i = 0; i < NUMBYTESTOSTORE - 1; i++) ret[i] = i2c_read(1);
  ret[NUMBYTESTOSTORE - 1] = i2c_read(0); // this reads and sends a CRC signal
  i2c_stop();
  if (ret[0] != READREGCODE || ret[1] != NUMREGTOREAD) {
    uart_puts_P(PSTR("Error reading humidity sensor\r\n"));
    return;
  }
  // note that both these values are 10 times what they should be but
  // representing with floating point is a terrible idea so we manipulate the
  // print statement instead
  uint16_t hum = ((ret[2] << 8) | ret[3]);
  uint16_t temp = ((ret[4] << 8) | ret[5]); // NOTE that leading bit is sign
  uart_printf("Humidity is %d.%d %%RH and Temperature is %s%d.%d C\r\n",
      hum / 10, hum % 10, // hum / 10 first, then last digit goes after '.'
      ret[4] & 0x80 ? "-" : "", // handle the sign (if leading is set, then neg)
      (temp & 0x7f) / 10, temp % 10); // same as humidity except don't count b15
  snprintf(read_data, max_bytes, "%d.%d %%RH\r\n", hum / 10, hum % 10);
}
Exemple #6
0
static uint8_t search_sensors(void)
{
    uint8_t i;
    uint8_t id[OW_ROMCODE_SIZE];
    uint8_t diff, nSensors;

    uart_puts_P( NEWLINESTR "Scanning Bus for DS18X20" NEWLINESTR );

    ow_reset();

    nSensors = 0;

    diff = OW_SEARCH_FIRST;
    while ( diff != OW_LAST_DEVICE && nSensors < MAXSENSORS ) {
        DS18X20_find_sensor( &diff, &id[0] );

        if( diff == OW_PRESENCE_ERR ) {
            uart_puts_P( "No Sensor found" NEWLINESTR );
            break;
        }

        if( diff == OW_DATA_ERR ) {
            uart_puts_P( "Bus Error" NEWLINESTR );
            break;
        }

        for ( i=0; i < OW_ROMCODE_SIZE; i++ )
            gSensorIDs[nSensors][i] = id[i];

        nSensors++;
    }

    return nSensors;
}
Exemple #7
0
static time_t parse_time(void) {

  char* time_pos;
  checked_r(char* token = parse_string(), time_from_hms(0,0,0));

  char* hs = strtok_r(token, ":", &time_pos);
  char* ms = strtok_r(NULL, ":", &time_pos);
  char* ss = strtok_r(NULL, ":", &time_pos);

#ifdef COMMANDLINE_DEBUG
  if ( !is_number(hs) || !is_number(ms) || !is_number(ss) ) {
	parse_fail = 1;
	uart_puts_P("ERR: parse_time: no numbers");
	return time_from_hms(0, 0, 0);
  }
#endif


  uint8_t h = atoi8(hs);
  uint8_t m = atoi8(ms);
  uint8_t s = atoi8(ss);

#ifdef COMMANDLINE_DEBUG
  if ( h >= 24 || m >= 60 || s >= 60 ) {
	parse_fail = 1;
	uart_puts_P("ERR: parse_time: invalid format");
	return time_from_hms(0, 0, 0);
  }
#endif
  
  return time_from_hms(h, m, s);
}
Exemple #8
0
    /**
     * @brief Outputs the current state of the stack
     *
     * This outputs the current state of the stack using UART. It is used
     * within PRINT_STATE_STACK() and will only be compiled when LOG_USER_STATE
     * == 1.
     *
     * @see PRINT_STATE_STACK()
     */
    static void printStateStack()
    {

        uint8_t i=0;
        uart_puts_P("stack: [");

        for (; i < g_topOfStack; ++i) {

            uart_putc(g_stateStack[i] + '0');
            uart_putc(' ');

        }

        for (; i < USER_MAX_STATE_DEPTH; ++i) {

            uart_putc('_');
            uart_putc(' ');

        }

        uart_putc(']');
        uart_puts_P("top: ");
        uart_putc(g_topOfStack + '0');
        uart_putc('\n');

    }
int main(void){
	
	DDRC = 0x00;	
		
	uart_init( UART_BAUD_SELECT(UART_BAUD_RATE,F_CPU) );
	sei();
	unsigned int c;
	while(1){
		c = uart_getc();
		if(c & UART_NO_DATA){
				/*
			 	* NO UART DATA available
			 	*/
		}
		else{
				/*
				 *  New Data is avialable at the port.
				 *  check the frame for overrun errro
				 */
				if ( c & UART_FRAME_ERROR ){

	   					/* Framing Error detected, i.e no stop bit detected */
						uart_puts_P("UART Frame Error: ");
				}	
				if ( c & UART_OVERRUN_ERROR ){			
	
						/* 
						 *
						 * Overrun, a character already present in the UART UDR register was 
				 		 *
						 * not read by the interrupt handler before the next character arrived,
						 * one or more received characters have been dropped
				  		 *	
				 		 *                                                                  
						 */

						uart_puts_P("UART Overrun Error: ");
		
				}

				if ( c & UART_BUFFER_OVERFLOW ){

						/* 
						 *
					 	 * We are not reading the receive buffer fast enough,
						 *
						 * one or more received character have been dropped 
					 	 *
					 	 */

						uart_puts_P("Buffer overflow error: ");

				}

				processData(c);
			//	PORTC = c;
		}
	}
	return 0;
}
Exemple #10
0
void pcf8583_init(void) {
  uint8_t tmp[4];

  rtc_state = RTC_NOT_FOUND;
  uart_puts_P(PSTR("RTC "));
  if (i2c_write_register(PCF8583_ADDR, REG_CONTROL, CTL_START_CLOCK) ||
      i2c_read_registers(PCF8583_ADDR, REG_YEAR1, 4, tmp)) {
    uart_puts_P(PSTR("not found"));
  } else {
    if (tmp[0] == (tmp[2] ^ 0xff) &&
        tmp[1] == (tmp[3] ^ 0xff)) {
      rtc_state = RTC_OK;
      uart_puts_P(PSTR("ok"));

      /* Dummy RTC read to update the year if required */
      struct tm time;
      read_rtc(&time);
    } else {
      rtc_state = RTC_INVALID;
      uart_puts_P(PSTR("invalid"));
    }
  }

  uart_putcrlf();
}
Exemple #11
0
void cmd_write (uint64_t cluster, uint8_t adcport, uint64_t maxsize, uint8_t speed)
{
	uart_puts_P("Writing...\r\n");

	uint16_t maxblocks = maxsize / 512;
	uint16_t block = 0;
	char c = 0x00;
	while(c != 'q')
	{
		char values[512] = {0x00};
		for (uint16_t i = 0; i<=80; ++i)
		{
			adc_request(adcport);
			uint16_t adcvalue = adc_read();
			string_append(values, num2str(adcvalue, 10));
			string_append(values, "\r\n");
			for (uint8_t d = 0; d<=speed; ++d)
				_delay_ms(3);

			uart_puts(num2str(i, 10));
			uart_puts(": ");
			uart_puts(num2str(adcvalue, 10));
			uart_puts("\r\n");
			c = uart_getc();
			if (c == 'q') break;
		}
		fat_write_file(cluster, (unsigned char*)values, block);
		++block;
		if (block >= maxblocks) break;
	}

	uart_puts_P("...done\r\n");
}
Exemple #12
0
static void parse_get_humiditysetpoint(void) {
  char buf[4];
  uart_puts_P("+ ");
  uart_puts(itoa8(settings.humidity_setpoint[DAY], buf));
  uart_puts_P(" ");
  uart_puts(itoa8(settings.humidity_setpoint[NIGHT], buf));
  uart_puts_P(NEWLINE);
}
Exemple #13
0
static void parse_get_outputs(void) {
  for ( uint8_t i = OUTPUT_FIRST; i < OUTPUT_LAST; i ++ ) {
	uart_puts_P("+ ");
	portmap_print_output(i);
	if ( output_values & _BV(i) ) uart_puts_P(" 1");
	else uart_puts_P(" 0");
	uart_puts_P(NEWLINE);
  }
}
Exemple #14
0
static void th_tl_dump(uint8_t *sp)
{
    DS18X20_read_scratchpad( &gSensorIDs[0][0], sp, DS18X20_SP_SIZE );
    uart_puts_P( "TH/TL in scratchpad of sensor 1 now : " );
    uart_put_int( sp[DS18X20_TH_REG] );
    uart_puts_P( " / " );
    uart_put_int( sp[DS18X20_TL_REG] );
    uart_puts_P( NEWLINESTR );
}
Exemple #15
0
int main(void) {

  InitLEDPort();
  
  YellowLEDOn();
  delay_sec(1);
  YellowLEDOff();
  delay_sec(1);
  YellowLEDOn();

  delay_sec(1);
    
  i2c_init();                                // init I2C interface
#ifdef UART_DEBUG
  uart_init( UART_BAUD_SELECT(UART_BAUD_RATE,F_CPU) );
  
  sei();

  uart_puts_P("\r\n'lsm303test' ready!\r\n");
#endif // UART_DEBUG

#ifdef LSM303DLH_USE_ACC
  LSM303DLHInitACC( I2C_DEV_LSM303DLH_ACC1 );
#endif // LSM303DLH_USE_ACC

#ifdef LSM303DLH_USE_MAG
  LSM303DLHInitMAG( I2C_DEV_LSM303DLH_MAG );
#endif // LSM303DLH_USE_MAG

  while ( 1 ) {

#ifdef UART_DEBUG
    uart_puts_P("\r\nRunning test... ");
#endif // UART_DEBUG

#if (defined LSM303DLH_USE_ACC) || (defined LSM303DLH_USE_MAG)

# ifdef LSM303DLH_USE_ACC
    LSM303DLHTestACC();
# endif // LSM303DLH_USE_ACC
# ifdef LSM303DLH_USE_MAG
    LSM303DLHTestMAG();
# endif // LSM303DLH_USE_MAG

#else

# ifdef UART_DEBUG
    uart_puts_p( cCRLF );
# endif // UART_DEBUG

    delay_sec(2);
#endif // LSM303DLH_USE_ACC || LSM303DLH_USE_MAG
  }
      
  return 0;
}
Exemple #16
0
void show_sp_uart( uint8_t *sp, size_t n )
{
	size_t i;
	uart_puts_P( "SP:" );
	for( i = 0; i < n; i++ ) {
		if ( i == n-1 ) uart_puts_P( "CRC:" );
		uart_puthex_byte(sp[i]);
		uart_puts_P(" ");
	}
}
Exemple #17
0
static void parse_get_daytime(void) {
  char buf[18];
  ttoa(settings.daytime[DAYTIME_BEGIN], buf+0);
  ttoa(settings.daytime[DAYTIME_END], buf+9);
  buf[8] = ' ';

  uart_puts_P("+ ");
  uart_puts(buf);
  uart_puts_P(NEWLINE);
}
Exemple #18
0
void can_bus_destroy(Can_Bus cb) {
  if (cb.pin_count != 2) {
    uart_puts_P(
        PSTR("Error: Can Bus not initialized with 2 pins\r\n"));
    return;
  }
  *cb.port[0] &= ~_BV(cb.reg_bit[0]); // clear pin before making it an input
  *cb.ddr[0] &= ~_BV(cb.reg_bit[0]); // pins should be inputs by default
  uart_puts_P(PSTR("Can Bus successfully de-initialized\r\n"));
}
Exemple #19
0
static void uart_put_temp(int16_t decicelsius)
{
    char s[10];

    uart_put_int( decicelsius );
    uart_puts_P(" deci°C, ");
    DS18X20_format_from_decicelsius( decicelsius, s, 10 );
    uart_puts( s );
    uart_puts_P(" °C");
}
Exemple #20
0
static void uart_put_temp_maxres(int32_t tval)
{
    char s[10];

    uart_put_longint( tval );
    uart_puts_P(" °Ce-4, ");
    DS18X20_format_from_maxres( tval, s, 10 );
    uart_puts( s );
    uart_puts_P(" °C");
}
Exemple #21
0
// currently a hardcoded solution
void can_bus_init(Can_Bus cb) {
  if (cb.pin_count != 2) {
    uart_puts_P(
        PSTR("Can Bus needs to be initialized with 2 pins (TX, RX)\r\n"));
    return;
  }
  *cb.ddr[0] |= _BV(cb.reg_bit[0]); // TX is an output so set bit
  *cb.ddr[1] &= ~_BV(cb.reg_bit[1]); // RX is input so clear bit
  uart_puts_P(PSTR("Can Bus successfully initialized\r\n"));
}
Exemple #22
0
void cmd_ls (uint32_t cluster)
{
	uart_puts_P("\r\n|------------------------------------------------------|");
	uart_puts_P("\r\n|Filename         | Cluster  |  Attrib  |   Filesize   |");
	uart_puts_P("\r\n|------------------------------------------------------|\r\n");

	for (uint8_t element = 1; element < 240; ++element)
	{
		struct fs_entry entry;
		entry.cluster = fat_read_dir_ent(cluster, element,
				&entry.size, &entry.attrib, (unsigned char *)entry.name);
		if (entry.cluster == 0xffff) break;
		uart_puts_P("| ");
		uart_puts(setlen(entry.name, 15, 0x20));
		uart_puts_P(" | ");
		uart_puts(setlen(num2str(entry.cluster, 16), 8, 0x20));
		uart_puts_P(" | ");
		uart_puts(setlen(num2str(entry.attrib, 16), 8, 0x20));
		uart_puts_P(" | ");
		uart_puts(setlen(num2str(entry.size, 16), 12, 0x20));
		uart_puts_P(" | ");
		uart_puts("\r\n");
	}

	uart_puts_P("|------------------------------------------------------|\r\n");
}
Exemple #23
0
uint8_t menu_start(const char *path)
{
	Finfo.lfname = Lfname;
	Finfo.lfsize = sizeof(Lfname);

	res = f_mount(0, &fatfs);
	if (res) { uart_puts_P("f_mount failed\r\n"); return; }
	
	res = f_chdir("0:/music");
	if (res) { uart_puts_P("f_chdir failed\r\n"); return; }

}
Exemple #24
0
void DS18X20_uart_put_temp(const uint8_t subzero, 
	const uint8_t cel, 	const uint8_t cel_frac_bits)
{
	uint8_t buffer[sizeof(int)*8+1];
	int i;
	
	uart_putc((subzero)?'-':'+');
	uart_puti((int)cel);
	uart_puts_P(".");
	itoa(cel_frac_bits*DS18X20_FRACCONV,buffer,10);
	for (i=0;i<4-strlen(buffer);i++) uart_puts_P("0");
	uart_puts(buffer);
	uart_puts_P("°C");
}
Exemple #25
0
static uint8_t parse_int(void) {
  checked_r(char* token = parse_string(), 0);

#ifdef COMMANDLINE_DEBUG
  if ( !is_number(token) ) {
	parse_fail = 1;
	uart_puts_P("ERR: parse_int: no number: >");
	uart_puts(token);
	uart_puts_P("< " NEWLINE);
  }
#endif

  return atoi8(token);
}
void loopCommandLine(void) {
  // print status if we're not in the menu
  if (! menuEnabled) {
    if (TimerReached(&cmdline_looptime, 1000)) {
      printStatus();
    }
  } 
  // check for serial command
  unsigned int c = uart_getc();
  if (!(c & UART_NO_DATA)) {
    if (! menuEnabled) {
      menuEnabled=1;
      printHelp();
    }
    switch((char) c) {
      case 'x': case 'X':  // terminates menu
        uart_puts_P("Leaving menu." NEWLINESTR);
        menuEnabled=0; break;
      case 'b': case 'B':  // show PID values
        printPID(); break;
      case 'r': case 'R':  // reset PID values
        restorePIDDefault(); break;
      case 'o': case 'O':  // print out PID debug data
        togglePIDDebug(); break;
      case 'p':
        setPID_P(getPID_P() - delta); printPID(); break;
      case 'P':
        setPID_P(getPID_P() + delta); printPID();break;
      case 'i':
        setPID_I(getPID_I() - delta); printPID(); break;
      case 'I':
        setPID_I(getPID_I() + delta); printPID(); break;
      case 'd':
        setPID_D(getPID_D() - delta); printPID(); break;
      case 'D':
        setPID_D(getPID_D() + delta); printPID(); break;
      case 't':
        setPIDSetpoint(getPIDSetpoint() - delta); printPID(); break;
      case 'T':
        setPIDSetpoint(getPIDSetpoint() + delta); printPID(); break;
      case 's': case 'S':
        savePIDConfig(); break;
      case '+':  {// adjust delta
          delta *= 10.0; 
          if (delta > MAX_DELTA) delta = MAX_DELTA;
          uart_print_delta();
          break;
        }
      case '-':  {// adjust delta
          delta /= 10.0; 
          if (delta < MIN_DELTA) delta = MIN_DELTA;
          uart_print_delta();
          break;
        }

      case '?': // show menu
        printHelp(); break;
    }
  }
}
Exemple #27
0
int main (void)
{
	HW_Init();

	// enquanto a tensão de entrada estiver abaixo de 8V e acima de 16V, não faz nada
	do
	{
		ADCSRA |= (1<<ADSC);
		while (ADCSRA & (1<<ADSC));

	} while ((ADC < MIN_VI_COUNT) || (ADC > MAX_VI_COUNT));

	VoltInp = ADC;

	ADMUX = ((1<<REFS0) | (1<<REFS1)) + VOUT_CH; 	// feedback do conversor boost
	ADCSRA |= (1<<ADIF) | (1<<ADIE);		// limpa o flag e habilita interrupção do ADC

	tPIsat_params.w_kp_pu = eeprom_read_word(&ee_PI_kp);
	tPIsat_params.w_ki_pu = eeprom_read_word(&ee_PI_ki);
	tPIsat_params.sp = eeprom_read_word(&ee_PI_SP);

	ADCSRA |= (1<<ADSC);		// Inicia primeira leitura do ADC
	sei();


	uart_puts_P(PSTR("Inicio VFD\r"));
	vfd_setstring("Felipe Maimon");

	for(;;)
	{
		State_Machine();
	}
}
Exemple #28
0
void can_bus_write(Can_Bus cb, char *str, uint16_t max_bytes) {
  if (max_bytes) {} // stop complaining
  if (cb.pin_count != 2 ||
      ((*cb.ddr[0] & _BV(cb.reg_bit[0])) == 0) || // TX should be output
      ((*cb.ddr[1] & _BV(cb.reg_bit[1])) != 0)) { // RX should be input
    uart_puts_P(
        PSTR("Error: Can Bus not initialized with 2 pins\r\n"));
    return;
  }
  if (str[0] == 1) {
    *cb.port[0] |= _BV(cb.reg_bit[0]);
    _delay_us(50); // only allow it to turn on for a small amount of time (50us)
    *cb.port[0] &= ~_BV(cb.reg_bit[0]);
  }
  uart_puts_P(PSTR("Successfully actuated CAN BUS for 50 us\r\n"));
}
Exemple #29
0
static void eeprom_test(void)
{
    uint8_t sp[DS18X20_SP_SIZE], th, tl;

    uart_puts_P( NEWLINESTR "DS18x20 EEPROM support test for first sensor" NEWLINESTR );
    // DS18X20_eeprom_to_scratchpad(&gSensorIDs[0][0]); // already done at power-on
    th_tl_dump( sp );
    th = sp[DS18X20_TH_REG];
    tl = sp[DS18X20_TL_REG];
    tl++;
    th++;
    DS18X20_write_scratchpad( &gSensorIDs[0][0], th, tl, DS18B20_12_BIT );
    uart_puts_P( "TH+1 and TL+1 written to scratchpad" NEWLINESTR );
    th_tl_dump( sp );
    DS18X20_scratchpad_to_eeprom( DS18X20_POWER_PARASITE, &gSensorIDs[0][0] );
    uart_puts_P( "scratchpad copied to DS18x20 EEPROM" NEWLINESTR );
    DS18X20_write_scratchpad( &gSensorIDs[0][0], 0, 0, DS18B20_12_BIT );
    uart_puts_P( "TH and TL in scratchpad set to 0" NEWLINESTR );
    th_tl_dump( sp );
    DS18X20_eeprom_to_scratchpad(&gSensorIDs[0][0]);
    uart_puts_P( "DS18x20 EEPROM copied back to scratchpad" NEWLINESTR );
    DS18X20_read_scratchpad( &gSensorIDs[0][0], sp, DS18X20_SP_SIZE );
    if ( ( th == sp[DS18X20_TH_REG] ) && ( tl == sp[DS18X20_TL_REG] ) ) {
        uart_puts_P( "TH and TL verified" NEWLINESTR );
    } else {
        uart_puts_P( "verify failed" NEWLINESTR );
    }
    th_tl_dump( sp );
}
Exemple #30
0
/* DS1307 version, checks clock halt bit in seconds register */
void dsrtc_init(void) {
  int16_t tmp;

  rtc_state = RTC_NOT_FOUND;
  uart_puts_P(PSTR("DS1307 "));
  tmp = i2c_read_register(RTC_ADDR, REG_SECOND);
  if (tmp < 0) {
    uart_puts_P(PSTR("not found"));
  } else {
    if (tmp & STATUS_OSF) {
      rtc_state = RTC_INVALID;
      uart_puts_P(PSTR("invalid"));
    } else {
      rtc_state = RTC_OK;
      uart_puts_P(PSTR("ok"));
    }
  }
  uart_putcrlf();
}