Example #1
0
void
rfm12_ask_2272_send(uint8_t *command, uint8_t delay, uint8_t cnt)
{
  uint8_t code[49];

  for(uint8_t i=0;i<3;i++)
  {
    rfm12_ask_encode_tribit(code, i*16, command[i], 8);
  }
  code[48]=7; //sync
  rfm12_prologue ();
  rfm12_trans(0x8200|(1<<5)|(1<<4)|(1<<3));   // 2. PwrMngt TX on
  for(uint8_t ii=cnt;ii>0;ii--)               // Sequenz cnt send
  {
    wdt_kick();
    uint8_t rfm12_trigger_level=0;
    for(uint8_t i=0;i<49;i++)
    {
      rfm12_ask_trigger(rfm12_trigger_level^=1,code[i]*delay);
    }
    rfm12_ask_trigger(0,24*delay);
  }
  rfm12_trans(0x8208);                        // 2. PwrMngt TX off
  rfm12_epilogue ();
}
Example #2
0
void
usb_init(void)
{
#ifdef USB_NET_SUPPORT
  usb_net_init();
#endif

#define USB_DDR_CONFIG(pin)  DDR_CHAR( pin ## _PORT) &= ~(_BV((pin ## _PIN)) | _BV(USB_INT_PIN))
#define USB_PORT_CONFIG(pin)  PORT_CHAR( pin ## _PORT) &= ~(_BV((pin ## _PIN)) | _BV(USB_INT_PIN))
  USB_DDR_CONFIG(USB_DMINUS);
  USB_PORT_CONFIG(USB_DMINUS);
#undef USB_DDR_CONFIG
#undef USB_PORT_CONFIG

  uint8_t i;
  /* Reenummerate the device */
  usbDeviceDisconnect();
  for(i = 0; i < 20; i++){  /* 300 ms disconnect */
    _delay_ms(15);
    wdt_kick();
  }
  usbDeviceConnect();

  /* USB Initialize */
  usbInit();
}
Example #3
0
void
dcf77_init(void)
{
  DCFDEBUG("init dcf77\n");
#ifdef DCF1_USE_PON_SUPPORT
  DCFDEBUG("PON\n");
  /* if module needs a peak on PON to enable dcf77 receiver
   * configure pin as output, set low */
  PIN_SET(DCF1_PON);
#endif

#if defined(DCF77_PCINT_PIN)
  DCFDEBUG("configure_pcint\n");
  /* configure */
  dcf77_configure_pcint();
#elif defined(DCF77_INT_PIN)
  DCFDEBUG("HAVE_DCF77_INT\n");
  /* Initialize "real" Interrupt */
  _EIMSK |= _BV(DCF77_INT_PIN);
  _EICRA = (_EICRA & ~DCF77_INT_ISCMASK) | DCF77_INT_ISC;
#else
  DCFDEBUG("Analog Comparator\n");
  // Analog Comparator init
  ACSR |= _BV(ACIE);
#endif

#ifdef DCF1_USE_PON_SUPPORT
  for (uint8_t i = 0; i < 100; i++)
  {
    wdt_kick();
    _delay_ms(10);
  }
  PIN_CLEAR(DCF1_PON);
#endif
}
Example #4
0
void
rfm12_ask_tevion_send(uint8_t * housecode, uint8_t * command, uint8_t delay, uint8_t cnt)
{
  uint8_t code[41];

  for(uint8_t i=0;i<3;i++)
  {
    rfm12_ask_encode_byte(code, i*8, housecode[i], 8);
  }
  code[24]=((housecode[2] & (1<<0))>0 ?6:12);
  for(uint8_t i=0;i<2;i++)
  {
    rfm12_ask_encode_byte(code, (i*8)+25, command[i], 8);
  }
  rfm12_prologue ();
  rfm12_trans(0x8200|(1<<5)|(1<<4)|(1<<3));   // 2. PwrMngt TX on
  for(uint8_t ii=cnt;ii>0;ii--)               // Sequenz cnt send
  {
    wdt_kick();
    uint8_t rfm12_trigger_level=0;
    for(uint8_t i=0;i<41;i++)
    {
      rfm12_ask_trigger(rfm12_trigger_level^=1,code[i]*delay);
    }
    rfm12_ask_trigger(0,24*delay);
  }
  rfm12_trans(0x8208);                        // 2. PwrMngt TX off
  rfm12_epilogue ();
}
Example #5
0
int wdt_start(unsigned long msecs)
{
	int ret;
	ret = wdt_control(0);
	if (ret)
		return ret;
	ret = wdt_set_period(msecs);
	if (ret)
		return ret;
	ret = wdt_control(1);
	if (ret)
		return ret;
	ret = wdt_kick();
	last_wdt = msecs;
	return ret;
}
Example #6
0
void
dc3840_init (void)
{
  usart_init ();

  uint8_t sync_retries = 23;
  do
    {
      /* Send SYNC sequence.  dc3840_send_command internally repeats
	 three times, i.e. we send 23*5=115 sync requests  max. */
      if (dc3840_send_command (DC3840_CMD_SYNC, 0, 0, 0, 0))
	continue;

      /* Wait some more for next eight bytes to arrive. */
      wdt_kick ();
      _delay_ms (1);
      if (dc3840_reply_ptr >= 16) break;
    }
  while (-- sync_retries);

  if (! sync_retries)
    {
      DC3840_DEBUG ("Failed to sync to camera.\n");
      return;
    }

  /* We have received 16 bytes,
     -> ACK for our SYNC
     -> SYNC command from camera.

     We need to ACK the SYNC first. */
  dc3840_send_command (DC3840_CMD_ACK, DC3840_CMD_SYNC, 0, 0, 0);
  DC3840_DEBUG ("Successfully sync'ed to camera!\n");

#ifdef DC3840_UDP_DEBUG
  uip_ipaddr_t ip;
  uip_ipaddr_copy (&ip, all_ones_addr);

  uip_udp_conn_t *udp_dc3840_conn = uip_udp_new (&ip, 0, dc3840_net_main);

  if (!udp_dc3840_conn)
    return; /* dammit. */

  uip_udp_bind (udp_dc3840_conn, HTONS (DC3840_PORT));
#endif
}
Example #7
0
void
vfs_eeprom_init(void)
{
  unsigned char buf[SFS_PAGE_SIZE];
  vfs_eeprom_read_page(0, buf, sizeof(struct vfs_eeprom_page_superblock));
  vfs_eeprom_debug("Superblock %s\n", buf);

  /* Page 0  is the superblock */
  struct vfs_eeprom_page_superblock *sb = (struct vfs_eeprom_page_superblock *)buf;

  if (sb->magic != SFS_MAGIC_SUPERBLOCK || sb->identifier[0] != 0xdead 
      || sb->identifier[1] != 0xbeef || sb->version != SFS_VERSION) {
	  vfs_eeprom_debug("unformatted filesystem, format!\n");
	  vfs_eeprom_debug("magic: %x, ident %x%x, version: %x\n", sb->magic,
              sb->identifier[0], sb->identifier[1], sb->version);

    sb->magic = SFS_MAGIC_SUPERBLOCK;
    sb->identifier[0] = 0xdead;
    sb->identifier[1] = 0xbeef;
    sb->version = SFS_VERSION;
    sb->next_page = 0;
    sb->next_file = 0;
    vfs_eeprom_write_page(0, buf, sizeof(struct vfs_eeprom_page_superblock));
    memset(buf, 0, 2);
    vfs_eeprom_inode_t count = 1;
    while (count < SFS_PAGE_COUNT) {
      wdt_kick();
      vfs_eeprom_write_page(count, buf, 1);
      vfs_eeprom_debug("clear page %d\n", count);
      count++;
    }
  } else {
    vfs_eeprom_debug("detected, version %d\n", sb->version);
  }
//  struct vfs_file_handle_t *file = vfs_eeprom_open("index.html");
//  if (!file)
//    file = vfs_eeprom_create("index.html");
//    file = vfs_eeprom_open("index.html");
//  vfs_eeprom_fseek(handle, 2, SEEK_SET);
//  file->offset = vfs_eeprom_filesize(file);
//  memset(buf, 0, 20);
//  vfs_eeprom_read(file, buf, 10); 
//  vfs_eeprom_debug("%d %s\n", vfs_eeprom_filesize(file), buf);
}
Example #8
0
static void
rfm12_ask_2272_1527_send(uint8_t * command, uint8_t delay, uint8_t cnt,
                         const uint8_t * duty_factor)
{
  uint8_t code[49];
  uint8_t *p = code;

  for (uint8_t i = 0; i < 3; i++)
  {
    uint8_t byte = command[i];
    for (uint8_t mask = 0x80; mask; mask >>= 1)
    {
      if (byte & mask)
      {
        *p++ = pgm_read_byte(duty_factor);
        *p++ = pgm_read_byte(duty_factor + 1);
      }
      else
      {
        *p++ = pgm_read_byte(duty_factor + 2);
        *p++ = pgm_read_byte(duty_factor + 3);
      }
    }
  }
  *p = 7;                 // sync

  rfm12_prologue();
  rfm12_trans(RFM12_CMD_PWRMGT | RFM12_PWRMGT_ET | RFM12_PWRMGT_ES |
              RFM12_PWRMGT_EX);
  for (uint8_t ii = cnt; ii > 0; ii--)
  {
    wdt_kick();
    uint8_t rfm12_trigger_level = 0;
    for (uint8_t i = 0; i < 49; i++)
    {
      rfm12_ask_trigger(rfm12_trigger_level ^= 1, code[i] * delay);
    }
    rfm12_ask_trigger(0, 24 * delay);
  }
  rfm12_trans(RFM12_CMD_PWRMGT | RFM12_PWRMGT_EX);
  rfm12_epilogue();
}
Example #9
0
uint8_t
vfs_copy_file (const char *dest, const char *src)
{
  struct vfs_file_handle_t *d = vfs_creat (dest);
  if (d == NULL)
    {
      /* Failed to create destination file. */
      return 1;
    }

  struct vfs_file_handle_t *s = vfs_open (src);
  if (s == NULL)
    {
      /* Failed to open source file. */
      vfs_close (d);
      return 1;
    }

  uint16_t i;
  while ((i = vfs_read (s, uip_buf, sizeof (uip_buf))))
    {
      uint16_t j = vfs_write (d, uip_buf, i);

      if (i != j)		/* Short write */
	{
	  vfs_close (s);
	  vfs_close (d);
	  return 1;		/* TODO Shall we delete 'dest'? */
	}

      if (i < sizeof (uip_buf))	/* EOF */
	break;

      wdt_kick ();
    }

  vfs_close (s);
  vfs_close (d);

  return 0;
}
Example #10
0
void
rfm12_ask_tevion_send(uint8_t * housecode, uint8_t * command, uint8_t delay,
                      uint8_t cnt)
{
  uint8_t code[41];
  uint8_t *p = code;

  for (uint8_t i = 0; i < 3; i++)
  {
    uint8_t byte = housecode[i];
    for (uint8_t mask = 0x80; mask; mask >>= 1)
    {
      *p++ = byte & mask ? 12 : 6;
    }
  }
  *p++ = housecode[2] & 1 ? 6 : 12;
  for (uint8_t i = 0; i < 2; i++)
  {
    uint8_t byte = command[i];
    for (uint8_t mask = 0x80; mask; mask >>= 1)
    {
      *p++ = byte & mask ? 12 : 6;
    }
  }

  rfm12_prologue();
  rfm12_trans(RFM12_CMD_PWRMGT | RFM12_PWRMGT_ET | RFM12_PWRMGT_ES |
              RFM12_PWRMGT_EX);
  for (uint8_t ii = cnt; ii > 0; ii--)
  {
    wdt_kick();
    uint8_t rfm12_trigger_level = 0;
    for (uint8_t i = 0; i < 41; i++)
    {
      rfm12_ask_trigger(rfm12_trigger_level ^= 1, code[i] * delay);
    }
    rfm12_ask_trigger(0, 24 * delay);
  }
  rfm12_trans(RFM12_CMD_PWRMGT | RFM12_PWRMGT_EX);
  rfm12_epilogue();
}
Example #11
0
void
rfm12_ask_intertechno_send(uint8_t family, uint8_t group,
                           uint8_t device, uint8_t command)
{
  union
  {
    struct
    {
      uint16_t family:4;
      uint16_t device:2;
      uint16_t group:2;
      uint16_t command:4;
    } bits;
    uint16_t raw;
  } code;

  family -= 1;
  code.bits.family = family;
  device -= 1;
  code.bits.device = device;
  group -= 1;
  code.bits.group = group;
  code.bits.command = command ? 0x0E : 0x06;

  rfm12_prologue();
  rfm12_trans(RFM12_CMD_PWRMGT | RFM12_PWRMGT_ET | RFM12_PWRMGT_ES |
              RFM12_PWRMGT_EX);
  for (uint8_t j = 6; j > 0; j--)
  {
    wdt_kick();
    uint16_t c = code.raw;
    for (uint8_t i = 12; i; i--)
    {
      rfm12_ask_intertechno_send_bit(c & 1);
      c >>= 1;
    }
    rfm12_ask_intertechno_send_sync();
  }
  rfm12_trans(RFM12_CMD_PWRMGT | RFM12_PWRMGT_EX);
  rfm12_epilogue();
}
Example #12
0
/*******************************************************************************
  Function:
    void _SYS_Tasks ( void )

  Summary:
    Maintains state machines of system modules.
*/
static void _SYS_Tasks ( void)
{
    TIMEOUT_THREAD_0_START;
    while(1)
    {
        /* Maintain system services */
        SYS_DEVCON_Tasks(sysObj.sysDevcon);
        /* Maintain the file system state machine. */
        SYS_FS_Tasks();
        SYS_CONSOLE_Tasks(sysObj.sysConsole0);
        /* SYS_COMMAND layer tasks routine */ 
        SYS_CMD_Tasks();
        /* SYS_TMR Device layer tasks routine */ 
        SYS_TMR_Tasks(sysObj.sysTmr);

        /* Maintain Device Drivers */
        DRV_SST25VF064C_Tasks(sysObj.drvSst25vf064c0);
        DRV_SDCARD_Tasks(sysObj.drvSDCard);

        /* Maintain Middleware */
        NET_PRES_Tasks(sysObj.netPres);
        /* Maintain the TCP/IP Stack*/

        wdt_arm_thread_0();
        wdt_kick();
        if(TIMEOUT_THREAD_0(10))
        {
            TIMEOUT_THREAD_0_START;
            SYS_DEBUG(SYS_ERROR_INFO, "MON: SYS Stack size: %d\r\n",uxTaskGetStackHighWaterMark(NULL));
            size_t libc_heap_usage_total = TrackHeap_TotalUsage();
            size_t libc_heap_usage_max = TrackHeap_MaxUsage();
            SYS_DEBUG(SYS_ERROR_INFO, "MON: heap usage: %dKB (%dKB), free: %dKB\r\n", libc_heap_usage_total / 1024, libc_heap_usage_max / 1024,xPortGetFreeHeapSize() / 1024);
        }
        /* Task Delay */
        vTaskDelay(1 / portTICK_PERIOD_MS);
    }
}
Example #13
0
int
main (void)
{
#ifdef BOOTLOADER_SUPPORT
  _IVREG = _BV (IVCE);    /* prepare ivec change */
  _IVREG = _BV (IVSEL);   /* change ivec to bootloader */
#endif

  /* Default DDR Config */
#if IO_HARD_PORTS >= 4 && DDR_MASK_A != 0
  DDRA = DDR_MASK_A;
#endif
#if DDR_MASK_B != 0
  DDRB = DDR_MASK_B;
#endif
#if DDR_MASK_C != 0
  DDRC = DDR_MASK_C;
#endif
#if DDR_MASK_D != 0
  DDRD = DDR_MASK_D;
#endif
#if IO_HARD_PORTS >= 6
#if DDR_MASK_E != 0
  DDRE = DDR_MASK_E;
#endif
#if DDR_MASK_F != 0
  DDRF = DDR_MASK_F;
#endif
#endif
#if IO_HARD_PORTS >= 7
#if DDR_MASK_G != 0
  DDRG = DDR_MASK_G;
#endif
#endif


#ifdef STATUSLED_POWER_SUPPORT
  PIN_SET(STATUSLED_POWER);
#endif

  //FIXME: zum ethersex meta system hinzufügen, aber vor allem anderem initalisieren
  debug_init();
  debug_printf("%S (Debug mode)\n", pstr_E6_VERSION_STRING_LONG);

#ifdef DEBUG_RESET_REASON
  if (bit_is_set (mcusr_mirror, BORF))
    debug_printf("reset: Brown-out\n");
  else if (bit_is_set (mcusr_mirror, PORF))
    debug_printf("reset: Power on\n");
  else if (bit_is_set (mcusr_mirror, WDRF))
    debug_printf("reset: Watchdog\n");
  else if (bit_is_set (mcusr_mirror, EXTRF))
    debug_printf("reset: Extern\n");
  else
    debug_printf("reset: Unknown\n");
#endif

#ifdef BOOTLOADER_SUPPORT
  /* disable interrupts */
  cli ();
  wdt_disable();
#endif //BOOTLOADER_SUPPORT
  /* enable interrupts */
  sei ();

#ifdef USE_WATCHDOG
  debug_printf("enabling watchdog\n");
#ifdef DEBUG
  /* for debugging, test reset cause and jump to bootloader */
  if (MCU_STATUS_REGISTER & _BV (WDRF))
  {
    debug_printf("bootloader...\n");
    jump_to_bootloader();
  }
#endif
  /* set watchdog to 2 seconds */
  wdt_enable(WDTO_2S);
  wdt_kick();
#else //USE_WATCHDOG
  debug_printf("disabling watchdog\n");
  wdt_disable();
#endif //USE_WATCHDOG

#ifdef SPI_SUPPORT
  spi_init();
#endif

  ethersex_meta_init();

  /* must be called AFTER all other initialization */
#ifdef PORTIO_SUPPORT
  portio_init();
#elif defined(NAMED_PIN_SUPPORT)
  np_simple_init();
#endif

#ifdef ENC28J60_SUPPORT
  debug_printf ("enc28j60 revision 0x%x\n",
  read_control_register (REG_EREVID));
  debug_printf ("mac: %02x:%02x:%02x:%02x:%02x:%02x\n",
	  uip_ethaddr.addr[0], uip_ethaddr.addr[1], uip_ethaddr.addr[2],
	  uip_ethaddr.addr[3], uip_ethaddr.addr[4], uip_ethaddr.addr[5]);
#endif

#ifdef STATUSLED_BOOTED_SUPPORT
  PIN_SET(STATUSLED_BOOTED);
#endif

  ethersex_meta_startup();
  /* main loop */
  while (1)
  {
    wdt_kick();
    ethersex_meta_mainloop();

#ifdef SD_READER_SUPPORT
    if (sd_active_partition == NULL)
    {
      if (!sd_try_init())
      {
#ifdef VFS_SD_SUPPORT
        vfs_sd_try_open_rootnode();
#endif
      }
      wdt_kick();
    }
#endif

#ifdef BOOTLOADER_JUMP
    if (status.request_bootloader)
    {
#ifdef MBR_SUPPORT
      mbr_config.bootloader = 1;
      write_mbr();
#endif
#ifdef CLOCK_CRYSTAL_SUPPORT
      TIMER_8_AS_1_INT_OVERFLOW_OFF;
#endif
#ifdef DCF77_SUPPORT
      ACSR &= ~_BV (ACIE);
#endif
      cli();
      jump_to_bootloader();
    }
#endif

#ifndef TEENSY_SUPPORT
    if (status.request_wdreset)
    {
      cli();
      wdt_enable(WDTO_15MS);
      for (;;);
    }
#endif

    if (status.request_reset)
    {
      cli();
      void (*reset) (void) = NULL;
      reset();
    }
  }
}
Example #14
0
int16_t
cron_save()
{
#ifdef CRON_VFS_SUPPORT
  struct vfs_file_handle_t *file;
  vfs_size_t filesize;
  vfs_size_t tempsize;
#else
  uint16_t filesize;
  uint16_t tempsize;
#endif
  uint8_t count = 0;
  uint8_t saved_count = 0;

#ifdef DEBUG_CRON
  debug_printf("cron: saving jobs\n");
#endif

#ifdef CRON_VFS_SUPPORT
  file = vfs_create(CRON_FILENAME);

  if (file == NULL)
  {
#ifdef DEBUG_CRON
    debug_printf("cron: can't create file\n");
#endif
    return -1;
  }
#endif

  // placeholder
  filesize = sizeof(count);
  struct cron_event_linkedlist *job = head;
  while (job)
  {
    if (job->event.persistent)
    {
      count++;
      filesize += sizeof(struct cron_event) + job->event.extrasize;
    }
    job = job->next;
  }

#ifdef CRON_VFS_SUPPORT
  if (vfs_write(file, &count, sizeof(count)) != sizeof(count))
    return cron_write_error(file);
#else
  if (filesize >= CRON_EEPROM_SIZE)
    return -1;
  eeprom_save_offset(crontab, 0, &count, sizeof(uint8_t));
#endif

  filesize = sizeof(count);
  job = head;
  while (job)
  {
    if (job->event.persistent)
    {
#ifdef DEBUG_CRON
      debug_printf("cron: writing job %i\n", count);
#endif

      tempsize = sizeof(struct cron_event) + job->event.extrasize;
#ifdef DEBUG_CRON
      debug_printf
        ("cron: try to allocate size of %i consist of struct %i and extrasize %i!\n",
         tempsize, sizeof(struct cron_event), job->event.extrasize);
#endif

#ifdef CRON_VFS_SUPPORT
      if (vfs_write(file, &job->event, tempsize) != tempsize)
        return cron_write_error(file);
#else
      eeprom_save_offset(crontab, filesize, &job->event, tempsize);
#endif
      filesize += tempsize;
      saved_count++;
    }
    job = job->next;
    // reset watchdog only if it seems that everything is going right
    if (saved_count <= count)
    {
      wdt_kick();
    }
  }
#ifdef DEBUG_CRON
  debug_printf("cron: all jobs written with total size of %i\n", filesize);
#endif

#ifdef CRON_VFS_SUPPORT
  vfs_truncate(file, filesize);
  vfs_close(file);
#else
  eeprom_update_chksum();
#endif
  return saved_count;
}
Example #15
0
void reset_cpu(ulong addr)
{
	clk_enable(TNETV107X_LPSC_WDT_ARM);
	wdt_start(1);
	wdt_kick();
}
Example #16
0
File: sht.c Project: promovicz/rtos
static void wait(void)
{
    fflush(stdout);
    wdt_kick();
    usleep(1000);
}
Example #17
0
int main(void)
{
	#ifdef BOOTLOADER_SUPPORT
	_IVREG = _BV(IVCE);	            /* prepare ivec change */
	_IVREG = _BV(IVSEL);            /* change ivec to bootloader */
	#endif

	/* Clear the MCUSR Register to avoid endless wdreset loops */
	unsigned char reset_reason = 0;
	#ifdef MCUCSR
	reset_reason = MCUCSR;
	MCUCSR = 0;
	#else
		#ifdef MCUSR
		reset_reason = MCUSR;
		MCUSR = 0;
		#endif
	#endif

	/* Default DDR Config */
	#if IO_HARD_PORTS == 4 && DDR_MASK_A != 0
	DDRA = DDR_MASK_A;
	#endif
	#if DDR_MASK_B != 0
	DDRB = DDR_MASK_B;
	#endif
	#if DDR_MASK_C != 0
	DDRC = DDR_MASK_C;
	#endif
	#if DDR_MASK_D != 0
	DDRD = DDR_MASK_D;
	#endif
	#if IO_HARD_PORTS == 6
		#if DDR_MASK_E != 0
		DDRE = DDR_MASK_E;
		#endif
		#if DDR_MASK_F != 0
		DDRF = DDR_MASK_F;
		#endif
	#endif

	#ifdef STATUSLED_POWER_SUPPORT
	PIN_SET(STATUSLED_POWER);
	#endif

	//FIXME: zum ethersex meta system hinzufügen, aber vor allem anderem initalisieren
	debug_init();
	debug_printf("Ethersex " VERSION_STRING " (Debug mode)\n");

	#ifdef DEBUG_RESET_REASON
	     if (bit_is_set(reset_reason, BORF)) debug_printf("reset: Brown-out\n");
	else if (bit_is_set(reset_reason, PORF)) debug_printf("reset: Power on\n");
	else if (bit_is_set(reset_reason, WDRF)) debug_printf("reset: Watchdog\n");
	else if (bit_is_set(reset_reason, EXTRF)) debug_printf("reset: Extern\n");
	else debug_printf("reset: Unknown\n");
	#endif

	#ifdef BOOTLOADER_SUPPORT
	/* disable interrupts */
	cli();
	#else
	/* enable interrupts */
	sei();
	#endif //BOOTLOADER_SUPPORT

	#ifdef USE_WATCHDOG
		debug_printf("enabling watchdog\n");
		#ifdef DEBUG
		/* for debugging, test reset cause and jump to bootloader */
		if (MCUSR & _BV(WDRF)) {
			debug_printf("bootloader...\n");
			jump_to_bootloader();
		}
		#endif
		/* set watchdog to 2 seconds */
		wdt_enable(WDTO_2S);
		wdt_kick();
	#else //USE_WATCHDOG
		debug_printf("disabling watchdog\n");
		wdt_disable();
	#endif //USE_WATCHDOG

	#ifdef ADC_SUPPORT
	/* ADC Prescaler to 64 */
	ADCSRA = _BV(ADEN) | _BV(ADPS2) | _BV(ADPS1);
	/* ADC set Voltage Reference to extern*/
	/* FIXME: move config to the right place */
	ADMUX = ADC_REF; //_BV(REFS0) | _BV(REFS1);
	#endif

	#if defined(RFM12_SUPPORT) || defined(ENC28J60_SUPPORT) \
	|| defined(DATAFLASH_SUPPORT)
	spi_init();
	#endif

	ethersex_meta_init();

	#ifdef RFM12_SUPPORT
		rfm12_init();

		#ifdef TEENSY_SUPPORT
		cli ();
		rfm12_trans (0xa620);	/* rfm12_setfreq(RFM12FREQ(433.92)); */
		rfm12_trans (0x94ac);	/* rfm12_setbandwidth(5, 1, 4); */
			#ifdef RFM12_IP_SUPPORT
			rfm12_trans (0xc610);	/* rfm12_setbaud(192); */
			rfm12_trans (0x9820);	/* rfm12_setpower(0, 2); */
			rfm12_rxstart();
			#endif  /* RFM12_IP_SUPPORT */
		sei ();
		#else  /* TEENSY_SUPPORT */
		rfm12_setfreq(RFM12FREQ(433.92));
		rfm12_setbandwidth(5, 1, 4);
			#ifdef RFM12_IP_SUPPORT
			rfm12_setbaud(CONF_RFM12_BAUD / 100);
			rfm12_setpower(0, 2);
			rfm12_rxstart();
			#endif  /* RFM12_IP_SUPPORT */
		#endif  /* not TEENSY_SUPPORT */
	#endif  /* RFM12_SUPPORT */

	/* must be called AFTER all other initialization */
	#ifdef PORTIO_SUPPORT
	portio_init();
	#elif defined(NAMED_PIN_SUPPORT)
	np_simple_init();
	#endif

	#ifdef ENC28J60_SUPPORT
	debug_printf("enc28j60 revision 0x%x\n", read_control_register(REG_EREVID));
	debug_printf("mac: %02x:%02x:%02x:%02x:%02x:%02x\n",
			uip_ethaddr.addr[0],
			uip_ethaddr.addr[1],
			uip_ethaddr.addr[2],
			uip_ethaddr.addr[3],
			uip_ethaddr.addr[4],
			uip_ethaddr.addr[5]
			);
	#endif

	#ifdef STATUSLED_BOOTED_SUPPORT
	PIN_SET(STATUSLED_BOOTED);
	#endif

	ethersex_meta_startup();

	/* main loop */
	while(1) {

	wdt_kick();
	ethersex_meta_mainloop();

	#ifdef SD_READER_SUPPORT
	if (sd_active_partition == NULL) {
	    if (! sd_try_init ())
		vfs_sd_try_open_rootnode ();

	    wdt_kick();
	}
	#endif

	#ifndef BOOTLOAD_SUPPORT
		if(status.request_bootloader) {
			#ifdef CLOCK_CRYSTAL_SUPPORT
			_TIMSK_TIMER2 &= ~_BV(TOIE2);
			#endif
			#ifdef DCF77_SUPPORT
			ACSR &= ~_BV(ACIE);
			#endif
			cli();
			jump_to_bootloader();
		}

		#ifndef TEENSY_SUPPORT
		if(status.request_wdreset) {
			cli();
			wdt_enable(WDTO_15MS);
			for(;;);
		}
		#endif

		if(status.request_reset) {
			cli();

			void (* reset)(void) = NULL;
			reset();
		}
	#endif
	}

}
Example #18
0
static void period_cb(uev_t *UNUSED(w), void *UNUSED(arg), int UNUSED(event))
{
	wdt_kick("Kicking watchdog.");
}