PROCESS_THREAD(interferer_example, ev, data)
{
 PROCESS_EXITHANDLER()  
 PROCESS_BEGIN();
 
 static struct etimer et;
 //powertrace_start(CLOCK_SECOND * 2);

 // Initial configurations on CC2420: channel and tx power
 watchdog_stop();
 cc2420_set_txpower(power);
 cc2420_set_channel(26);
 //printf("interfering with periodic interference\n"); 
 // Continuous Interference
 
 CC2420_SPI_ENABLE();
 
 //SPI_SET_UNMODULATED(0x1800,0x0100,0x0508,0x0004);
 SPI_SET_MODULATED(0x050C);
 
 //powertrace_start(CLOCK_SECOND*2);

 while(1){	
 
 for(power=3; power<32; power+=4){
 SPI_SET_TXPOWER((0xa0ff & 0xffe0) | (power & 0x1f));
 etimer_set(&et, CLOCK_SECOND/1000);
 PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
 //printf ("transmit power = %d\n",power);
 }
 
 for(power=27; power>3; power-=4){
 SPI_SET_TXPOWER((0xa0ff & 0xffe0) | (power & 0x1f));
 etimer_set(&et, CLOCK_SECOND/1000);
 PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
 //printf ("transmit power = %d\n",power);
 }
 
 for(power=3; power<32; power+=2){
 SPI_SET_TXPOWER((0xa0ff & 0xffe0) | (0 & 0x1f));
 etimer_set(&et, CLOCK_SECOND/1000);
 PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
 //printf ("transmit power = %d\n",power);
 }
 
} 
 CC2420_SPI_DISABLE();
 void powertrace_stop(void); 
 PROCESS_WAIT_EVENT();  
 PROCESS_END();
}
Beispiel #2
0
int
main() {
    const struct CMUnitTest tests[] = {
            cmocka_unit_test_setup_teardown(cm_session_test, cm_setup, cm_teardown),
            cmocka_unit_test_setup_teardown(cm_session_neg_test, cm_setup, NULL),
            cmocka_unit_test_setup_teardown(cm_buffers_test, cm_setup, cm_teardown),
            cmocka_unit_test_setup_teardown(cm_signals_test, cm_setup, cm_teardown),
    };

    watchdog_start(300);
    int ret = cmocka_run_group_tests(tests, NULL, NULL);
    watchdog_stop();
    return ret;
}
/*--------------------------------------------------------------------------*/
ISR(TIMER0_A1, rtimer_a01_isr)
{
  /* store the IV register as any read/write resets interrupt flags */
  uint16_t ivreg = TA0IV;

  if(ivreg & TA0IV_TACCR1) {
    /* rtimer interrupt */
    TA0CCTL1 &= ~CCIFG;
    watchdog_start();

    /* check for and run any pending rtimers */
    rtimer_run_next();

    /* also check for any pending events and wake up if needed */
    if(process_nevents() > 0) {
      LPM4_EXIT;
    }
    watchdog_stop();




  } else if(ivreg & TA0IV_TACCR2) {
    /* simple pwm interrupt */
    TA0CCTL2 &= ~CCIFG;

    if(spwm.on_time > 0) {
      if(spwm.on_time == period) {
        TA0CCTL2 &= ~CCIE;  /* no need for interrupt, is at 100% DC */
/*        SIMPLE_PWM_PORT(OUT) |= (1 << spwm.pin);*/
        pwm_on_cb();

      } else {
        /* normal on-case */
        if(period_end) {
          period_end = 0;
          TA0CCR2 = TAR + spwm.on_time;
/*          SIMPLE_PWM_PORT(OUT) |= (1 << spwm.pin);*/
          pwm_off_cb();

        } else {
          period_end = 1;
          TA0CCR2 = TAR + (period - spwm.on_time);
/*          SIMPLE_PWM_PORT(OUT) &= ~(1 << spwm.pin);*/
          pwm_on_cb();
        }
      }
    }
  }
}
Beispiel #4
0
void    watchdog_destroy(WATCHDOG *wp)
{
    char   *myname = "watchdog_destroy";

    watchdog_stop(wp);
    watchdog_curr = wp->saved_watchdog;
    if (sigaction(SIGALRM, &wp->saved_action, (struct sigaction *) 0) < 0)
	msg_fatal("%s: sigaction(SIGALRM): %m", myname);
    if (wp->saved_time)
	alarm(wp->saved_time);
    myfree((char *) wp);
    if (msg_verbose)
	msg_info("%s: %p", myname, (void *) wp);
}
Beispiel #5
0
static int watchdog_release(struct inode *inode, struct file *file)
{
	struct watchdog_core_data *wd_data = file->private_data;
	struct watchdog_device *wdd;
	int err = -EBUSY;
	bool running;

	mutex_lock(&wd_data->lock);

	wdd = wd_data->wdd;
	if (!wdd)
		goto done;

	/*
	 * We only stop the watchdog if we received the magic character
	 * or if WDIOF_MAGICCLOSE is not set. If nowayout was set then
	 * watchdog_stop will fail.
	 */
	if (!test_bit(WDOG_ACTIVE, &wdd->status))
		err = 0;
	else if (test_and_clear_bit(_WDOG_ALLOW_RELEASE, &wd_data->status) ||
		 !(wdd->info->options & WDIOF_MAGICCLOSE))
		err = watchdog_stop(wdd);

	/* If the watchdog was not stopped, send a keepalive ping */
	if (err < 0) {
		pr_crit("watchdog%d: watchdog did not stop!\n", wdd->id);
		watchdog_ping(wdd);
	}

	watchdog_update_worker(wdd);

	/* make sure that /dev/watchdog can be re-opened */
	clear_bit(_WDOG_DEV_OPEN, &wd_data->status);

done:
	running = wdd && watchdog_hw_running(wdd);
	mutex_unlock(&wd_data->lock);
	/*
	 * Allow the owner module to be unloaded again unless the watchdog
	 * is still running. If the watchdog is still running, it can not
	 * be stopped, and its driver must not be unloaded.
	 */
	if (!running) {
		module_put(wd_data->cdev.owner);
		kref_put(&wd_data->kref, watchdog_core_data_release);
	}
	return 0;
}
Beispiel #6
0
 timera0 (void) {
  ENERGEST_ON(ENERGEST_TYPE_IRQ);

  watchdog_start();

  rtimer_run_next();

  if(process_nevents() > 0) {
    LPM4_EXIT;
  }

  watchdog_stop();

  ENERGEST_OFF(ENERGEST_TYPE_IRQ);
}
static void watchdog_workfunc(struct work_struct *work)
{
	struct watchdog_data *wd;

	wd = container_of(work, struct watchdog_data, work.work);

	pr_debug("%s: pet watchdog\n", __func__);

	/* stop watchdog and restart it */
	watchdog_stop(wd);
	watchdog_start(wd);

	/* reschedule to clear it again in the future */
	queue_delayed_work(wd->wq, &wd->work, wd->pet_interval);
}
Beispiel #8
0
int main(void)
{
    watchdog_stop();

    set_mcu_speed_dco_mclk_8MHz_smclk_1MHz();
    leds_init();

    led_red_on();
    for(;;)
    {
        delay_ms(1000);
        led_red_switch();
        led_green_switch();
    }
}
Beispiel #9
0
/*---------------------------------------------------------------------------*/
void
watchdog_init(void)
{
  /* The MSP430 watchdog is enabled at boot-up, so we stop it during
     initialization. */
  counter = 0;
  watchdog_stop();
#if CONTIKI_TARGET_WISMOTE
  SFRIFG1 &= ~WDTIFG;
  SFRIE1 |= WDTIE;
#else
  IFG1 &= ~WDTIFG;
  IE1 |= WDTIE;
#endif
}
Beispiel #10
0
/*---------------------------------------------------------------------------*/
ISR(TIMERA1, timera1)
{
  ENERGEST_ON(ENERGEST_TYPE_IRQ);

  watchdog_start();

  if(TAIV == 2) {

    /* HW timer bug fix: Interrupt handler called before TR==CCR.
     * Occurs when timer state is toggled between STOP and CONT. */
    while(TACTL & MC1 && TACCR1 - TAR == 1);

    /* Make sure interrupt time is future */
    do {
      TACCR1 += INTERVAL;
      ++count;

      /* Make sure the CLOCK_CONF_SECOND is a power of two, to ensure
	 that the modulo operation below becomes a logical and and not
	 an expensive divide. Algorithm from Wikipedia:
	 http://en.wikipedia.org/wiki/Power_of_two */
#if (CLOCK_CONF_SECOND & (CLOCK_CONF_SECOND - 1)) != 0
#error CLOCK_CONF_SECOND must be a power of two (i.e., 1, 2, 4, 8, 16, 32, 64, ...).
#error Change CLOCK_CONF_SECOND in contiki-conf.h.
#endif
      if(count % CLOCK_CONF_SECOND == 0) {
	++seconds;
        energest_flush();
      }
    } while((TACCR1 - TAR) > INTERVAL);

    last_tar = TAR;

    if(etimer_pending() &&
       (etimer_next_expiration_time() - count - 1) > MAX_TICKS) {
      etimer_request_poll();
      LPM4_EXIT;
    }

  }
  /*  if(process_nevents() >= 0) {
    LPM4_EXIT;
    }*/

  watchdog_stop();

  ENERGEST_OFF(ENERGEST_TYPE_IRQ);
}
Beispiel #11
0
/*---------------------------------------------------------------------------*/
static void
collect_garbage(int mode)
{
  uint16_t sector;
  struct sector_status stats;
  coffee_page_t first_page, isolation_count;

  watchdog_stop();

  PRINTF("Coffee: Running the file system garbage collector in %s mode\n",
	 mode == GC_RELUCTANT ? "reluctant" : "greedy");
  /*
   * The garbage collector erases as many sectors as possible. A sector is
   * erasable if there are only free or obsolete pages in it.
   */
  for(sector = 0; sector < COFFEE_SECTOR_COUNT; sector++) {
    isolation_count = get_sector_status(sector, &stats);
    PRINTF("Coffee: Sector %u has %u active, %u obsolete, and %u free pages.\n",
        sector, (unsigned)stats.active,
	(unsigned)stats.obsolete, (unsigned)stats.free);

    if(stats.active > 0) {
      continue;
    }

    if((mode == GC_RELUCTANT && stats.free == 0) ||
       (mode == GC_GREEDY && stats.obsolete > 0)) {
      first_page = sector * COFFEE_PAGES_PER_SECTOR;
      if(first_page < *next_free) {
        *next_free = first_page;
      }

      if(isolation_count > 0) {
        isolate_pages(first_page + COFFEE_PAGES_PER_SECTOR, isolation_count);
      }

      COFFEE_ERASE(sector);
      PRINTF("Coffee: Erased sector %d!\n", sector);

      if(mode == GC_RELUCTANT && isolation_count > 0) {
        break;
      }
    }
  }

  watchdog_start();
}
Beispiel #12
0
/*---------------------------------------------------------------------------*/
static struct file *
reserve(const char *name, coffee_page_t pages,
	int allow_duplicates, unsigned flags)
{
  struct file_header hdr;
  coffee_page_t page;
  struct file *file;

  watchdog_stop();

  if(!allow_duplicates && find_file(name) != NULL) {
    watchdog_start();
    return NULL;
  }

  page = find_contiguous_pages(pages);
  if(page == INVALID_PAGE) {
    if(*gc_wait) {
      return NULL;
    }
    collect_garbage(GC_GREEDY);
    page = find_contiguous_pages(pages);
    if(page == INVALID_PAGE) {
      watchdog_start();
      *gc_wait = 1;
      return NULL;
    }
  }

  memset(&hdr, 0, sizeof(hdr));
  memcpy(hdr.name, name, sizeof(hdr.name) - 1);
  hdr.max_pages = pages;
  hdr.flags = HDR_FLAG_ALLOCATED | flags;
  write_header(&hdr, page);

  PRINTF("Coffee: Reserved %u pages starting from %u for file %s\n",
      pages, page, name);

  file = load_file(page, &hdr);
  file->end = 0;
  watchdog_start();

  return file;
}
/*---------------------------------------------------------------------------*/
void
LPTMR_IRQHandler(void)
  {
    ENERGEST_ON(ENERGEST_TYPE_IRQ);

    watchdog_start();
    
    PRINTF("rtimer_arch_init compare event at 0x%4x.\n", rtimer_arch_now());

    LPTMR0_CMR = LPTMR_CMR_COMPARE(LPTMR_CMR_COMPARE_MASK);
    LPTMR0_CSR = (uint32_t) ((LPTMR0_CSR
        & (uint32_t) ~(uint32_t) (LPTMR_CSR_TIE_MASK))
    | (uint32_t) (LPTMR_CSR_TCF_MASK)); // Clear interrupt flag and disable interrupt

    rtimer_run_next();

    watchdog_stop();

    ENERGEST_OFF(ENERGEST_TYPE_IRQ);
  }
Beispiel #14
0
/**
 * stop wdt internal
 *
 */
void bmc_stop_wd_timer(void)
{
	if ((wd_timer.timer_use & WD_TIMER_START))
	{
		taskENTER_CRITICAL();

		/* set watchdog timer values */
		wd_timer.timer_use = WD_TIMER_USE_SMS_OS;
		wd_timer.timer_action = WD_TIMER_ACT_NO;
		wd_timer.initial_count = 0;
		wd_timer.present_count = 0;
		wd_timer.timer_use &= ~WD_TIMER_START;

		/* stop watchdog timer */
		watchdog_stop();
		debug_uart_printf(DBG_GRP_WDT, 1, "Watchdog timer stopped via %s\n", __FUNCTION__);

		taskEXIT_CRITICAL();
	}
}
Beispiel #15
0
int
main() {
    const struct CMUnitTest tests[] = {
        cmocka_unit_test(sr_new_tree_test),
        cmocka_unit_test(sr_new_trees_test),
        cmocka_unit_test(sr_node_set_name_test),
        cmocka_unit_test(sr_node_set_module_test),
        cmocka_unit_test(sr_node_set_str_data_test),
        cmocka_unit_test(sr_node_build_str_data_test),
        cmocka_unit_test(sr_node_add_child_test),
        cmocka_unit_test(sr_dup_tree_test),
        cmocka_unit_test(sr_dup_trees_test),
        cmocka_unit_test(sr_print_tree_test)
    };

    watchdog_start(300);
    int ret = cmocka_run_group_tests(tests, NULL, NULL);
    watchdog_stop();
    return ret;
}
Beispiel #16
0
void    watchdog_destroy(WATCHDOG *wp)
{
    const char *myname = "watchdog_destroy";

    watchdog_stop(wp);
    watchdog_curr = wp->saved_watchdog;
    if (sigaction(SIGALRM, &wp->saved_action, (struct sigaction *) 0) < 0)
	msg_fatal("%s: sigaction(SIGALRM): %m", myname);
    if (wp->saved_time)
	alarm(wp->saved_time);
    myfree((void *) wp);
#ifdef USE_WATCHDOG_PIPE
    if (watchdog_curr == 0) {
	event_disable_readwrite(watchdog_pipe[0]);
	(void) close(watchdog_pipe[0]);
	(void) close(watchdog_pipe[1]);
    }
#endif
    if (msg_verbose > 1)
	msg_info("%s: %p", myname, (void *) wp);
}
Beispiel #17
0
/*---------------------------------------------------------------------------*/
void
flash_setup(void)
{
  /* disable all interrupts to protect CPU
     during programming from system crash */
  dint();

  /* Clear interrupt flag1. */
  SFRIFG1 = 0;
  /* The IFG1 = 0; statement locks up contikimac - not sure if this
     statement needs to be here at all. I've removed it for now, since
     it seems to work, but leave this little note here in case someone
     stumbles over this code at some point. */

  /* Stop watchdog. */
  watchdog_stop();

  /* disable all NMI-Interrupt sources */
  sfrie = SFRIE1;
  SFRIE1 = 0x00;
}
Beispiel #18
0
//-----------------------------------------------------------------------------
// name: shutdown()
// desc: ...
//-----------------------------------------------------------------------------
void Digitalio::shutdown()
{
    if( !m_init ) return;

#ifndef __DISABLE_RTAUDIO__
    if( m_start )
    {
        //if( m_use_cb ) m_rtaudio->cancelStreamCallback();
        m_rtaudio->stopStream();
    }

    m_rtaudio->closeStream();
    SAFE_DELETE( m_rtaudio );
#endif // __DISABLE_RTAUDIO__

    m_init = FALSE;
    m_start = FALSE;
    
    // stop watchdog
    watchdog_stop();
}
Beispiel #19
0
void RTC_IRQHandler(void)
{
  ENERGEST_ON(ENERGEST_TYPE_IRQ);
  // Find reason of IRQ

  if(RTC_IntGet() & RTC_IF_COMP0)
  {
    watchdog_start();
    rtimer_run_next();
    watchdog_stop();
    // disable interrupt
    RTC_IntDisable(RTC_IF_COMP0);
  }
  else
  {
    PRINTF("%s: unknown reason for RTC interrupt\r\n",__func__);
  }

  // Clear interrupts
  RTC_IntClear(_RTC_IF_MASK);

  ENERGEST_OFF(ENERGEST_TYPE_IRQ);
}
Beispiel #20
0
/*---------------------------------------------------------------------------*/
int
cfs_coffee_format(void)
{
  unsigned i;

  PRINTF("Coffee: Formatting %u sectors", COFFEE_SECTOR_COUNT);

  *next_free = 0;

  watchdog_stop();
  for(i = 0; i < COFFEE_SECTOR_COUNT; i++) {
    COFFEE_ERASE(i);
    PRINTF(".");
  }
  watchdog_start();

  /* Formatting invalidates the file information. */
  memset(&protected_mem, 0, sizeof(protected_mem));

  PRINTF(" done!\n");

  return 0;
}
/* Program and starts the timer */
static int watchdog_config_and_start(u32 newtimeout, u32 newpretimeout)
{
	int ret;

	timeout = newtimeout;
	pre_timeout = newpretimeout;

	pr_info("timeout=%ds, pre_timeout=%ds\n", timeout, pre_timeout);

	/* Configure the watchdog */
	ret = watchdog_set_timeouts_and_start(pre_timeout, timeout);
	if (ret) {
		pr_err("%s: Cannot configure the watchdog\n", __func__);

		/* Make sure the watchdog timer is stopped */
		watchdog_stop();
		return ret;
	}

	watchdog_device.started = true;

	return 0;
}
Beispiel #22
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(preload_process, ev, data)
{
  PROCESS_BEGIN();

  etimer_set(&etimer, 5 * CLOCK_SECOND);
  PROCESS_WAIT_UNTIL(etimer_expired(&etimer));

  watchdog_stop();
  leds_on(LEDS_RED);
  
  preload();
  
  leds_on(LEDS_BLUE);
  
  printf("done\n");
  
  leds_off(LEDS_RED + LEDS_BLUE);
  watchdog_start();
  while(1) {
    PROCESS_WAIT_EVENT();
  }
  PROCESS_END();
}
Beispiel #23
0
int main ()
{
    watchdog_stop();

    set_mcu_speed_dco_mclk_16MHz_smclk_8MHz(); // set global clock

    /* Initialisation begin */
    leds_init();	// leds :')
    spi_init();	//
    cc2500_init();	// radio init
    #if defined(USER_RFCONFIG)
    cc2500_configure(& USER_RFCONFIG );
    #endif

    timerA_init(); // global timer
    timerA_register_cb(&timer_tick_cb); // protothread timer increment callback
    timerA_start_milliseconds(TIMER_PERIOD_MS);

    uart_init(UART_9600_SMCLK_8MHZ); // serial link

    printf("adc test application: temperature\n\n");

    adc10_start(); // temperature sensor

    __enable_interrupt();
        
    /* Initialisation end */

    while(1)
    {
        thread_periodic_capture(&pt[0]);
        thread_periodic_radio(&pt[1]);
        //do something
    }

    return 0;
}
Beispiel #24
0
static int watchdog_release(struct inode *inode, struct file *file)
{
	struct watchdog_device *wdd = file->private_data;
	int err = -EBUSY;

	/*
	 * We only stop the watchdog if we received the magic character
	 * or if WDIOF_MAGICCLOSE is not set. If nowayout was set then
	 * watchdog_stop will fail.
	 */
	if (!test_bit(WDOG_ACTIVE, &wdd->status))
		err = 0;
	else if (test_and_clear_bit(WDOG_ALLOW_RELEASE, &wdd->status) ||
		 !(wdd->info->options & WDIOF_MAGICCLOSE))
		err = watchdog_stop(wdd);

	/* If the watchdog was not stopped, send a keepalive ping */
	if (err < 0) {
		mutex_lock(&wdd->lock);
		if (!test_bit(WDOG_UNREGISTERED, &wdd->status))
			dev_crit(wdd->dev, "watchdog did not stop!\n");
		mutex_unlock(&wdd->lock);
		watchdog_ping(wdd);
	}

	/* Allow the owner module to be unloaded again */
	module_put(wdd->ops->owner);

	/* make sure that /dev/watchdog can be re-opened */
	clear_bit(WDOG_DEV_OPEN, &wdd->status);

	/* Note wdd may be gone after this, do not use after this! */
	if (wdd->ops->unref)
		wdd->ops->unref(wdd);

	return 0;
}
Beispiel #25
0
/*---------------------------------------------------------------------------*/
static int
cfs_garbage_collect(void)
{
  uint16_t sector;
  uint16_t active_pages, free_pages, obsolete_pages;
  uint8_t sectors_in_row, longest_row;
  
  watchdog_stop();
  
  PRINTF("Coffee: Running the file system garbage collector...\n");
  
  sectors_in_row = longest_row = 0;
  /* 
   * The garbage collector erases as many sectors as possible. A sector is
   * erasable if there are only free or obsolete pages in it.
   */
  for(sector = 0; sector < COFFEE_SIZE / COFFEE_SECTOR_SIZE; sector++) {
    get_sector_status(sector, &active_pages, &free_pages, &obsolete_pages);
    PRINTF("Coffee: Sector %u has %u active, %u free, and %u obsolete pages.\n",
	sector, active_pages, free_pages, obsolete_pages);
    if(active_pages == 0 && obsolete_pages > 0) {
      COFFEE_ERASE(sector);
      PRINTF("Coffee: Erased sector %d!\n", sector);
      ++sectors_in_row;
      if(sectors_in_row > longest_row) {
	longest_row = sectors_in_row;
      }
    } else {
      sectors_in_row = 0;
    }
  }

  watchdog_start();
  
  return longest_row * COFFEE_PAGES_PER_SECTOR;
}
Beispiel #26
0
/*---------------------------------------------------------------------------*/
int
main(int argc, char **argv)
{
  /*
   * Initalize hardware.
   */

  msp430_cpu_init();
  clock_init();
  leds_init();

  leds_on(LEDS_RED);

  clock_wait(2);

  uart1_init(115200); /* Must come before first printf */

#if WITH_UIP
  slip_arch_init(115200);
#endif /* WITH_UIP */

  clock_wait(1);

  leds_on(LEDS_GREEN);
  //ds2411_init();

  /* XXX hack: Fix it so that the 802.15.4 MAC address is compatible
     with an Ethernet MAC address - byte 0 (byte 2 in the DS ID)
     cannot be odd. */
  //ds2411_id[2] &= 0xfe;

  leds_on(LEDS_BLUE);
  //xmem_init();

  leds_off(LEDS_RED);
  rtimer_init();
  /*
   * Hardware initialization done!
   */

  node_id = NODE_ID;

  /* Restore node id if such has been stored in external mem */
  //node_id_restore();

  /* for setting "hardcoded" IEEE 802.15.4 MAC addresses */
#ifdef IEEE_802154_MAC_ADDRESS
  {
    uint8_t ieee[] = IEEE_802154_MAC_ADDRESS;
    //memcpy(ds2411_id, ieee, sizeof(uip_lladdr.addr));
    //ds2411_id[7] = node_id & 0xff;
  }
#endif

  //random_init(ds2411_id[0] + node_id);

  leds_off(LEDS_BLUE);
  /*
   * Initialize Contiki and our processes.
   */
  process_init();
  process_start(&etimer_process, NULL);

  ctimer_init();

  init_platform();

  set_rime_addr();

  cc2520_init();
  {
    uint8_t longaddr[8];
    uint16_t shortaddr;

    shortaddr = (rimeaddr_node_addr.u8[0] << 8) +
      rimeaddr_node_addr.u8[1];
    memset(longaddr, 0, sizeof(longaddr));
    rimeaddr_copy((rimeaddr_t *)&longaddr, &rimeaddr_node_addr);

    printf("MAC %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
           longaddr[0], longaddr[1], longaddr[2], longaddr[3],
           longaddr[4], longaddr[5], longaddr[6], longaddr[7]);

    cc2520_set_pan_addr(IEEE802154_PANID, shortaddr, longaddr);
  }
  cc2520_set_channel(RF_CHANNEL);

  printf(CONTIKI_VERSION_STRING " started. ");
  if(node_id > 0) {
    printf("Node id is set to %u.\n", node_id);
  } else {
    printf("Node id is not set.\n");
  }

#if WITH_UIP6
  /* memcpy(&uip_lladdr.addr, ds2411_id, sizeof(uip_lladdr.addr)); */
  memcpy(&uip_lladdr.addr, rimeaddr_node_addr.u8,
         UIP_LLADDR_LEN > RIMEADDR_SIZE ? RIMEADDR_SIZE : UIP_LLADDR_LEN);

  /* Setup nullmac-like MAC for 802.15.4 */
/*   sicslowpan_init(sicslowmac_init(&cc2520_driver)); */
/*   printf(" %s channel %u\n", sicslowmac_driver.name, RF_CHANNEL); */

  /* Setup X-MAC for 802.15.4 */
  queuebuf_init();
  NETSTACK_RDC.init();
  NETSTACK_MAC.init();
  NETSTACK_NETWORK.init();

  printf("%s %s, channel check rate %lu Hz, radio channel %u\n",
         NETSTACK_MAC.name, NETSTACK_RDC.name,
         CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1:
                         NETSTACK_RDC.channel_check_interval()),
         RF_CHANNEL);

  process_start(&tcpip_process, NULL);

  printf("Tentative link-local IPv6 address ");
  {
    uip_ds6_addr_t *lladdr;
    int i;
    lladdr = uip_ds6_get_link_local(-1);
    for(i = 0; i < 7; ++i) {
      printf("%02x%02x:", lladdr->ipaddr.u8[i * 2],
             lladdr->ipaddr.u8[i * 2 + 1]);
    }
    printf("%02x%02x\n", lladdr->ipaddr.u8[14], lladdr->ipaddr.u8[15]);
  }

  if(!UIP_CONF_IPV6_RPL) {
    uip_ipaddr_t ipaddr;
    int i;
    uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
    uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
    uip_ds6_addr_add(&ipaddr, 0, ADDR_TENTATIVE);
    printf("Tentative global IPv6 address ");
    for(i = 0; i < 7; ++i) {
      printf("%02x%02x:",
             ipaddr.u8[i * 2], ipaddr.u8[i * 2 + 1]);
    }
    printf("%02x%02x\n",
           ipaddr.u8[7 * 2], ipaddr.u8[7 * 2 + 1]);
  }

#else /* WITH_UIP6 */

  NETSTACK_RDC.init();
  NETSTACK_MAC.init();
  NETSTACK_NETWORK.init();

  printf("%s %s, channel check rate %lu Hz, radio channel %u\n",
         NETSTACK_MAC.name, NETSTACK_RDC.name,
         CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0? 1:
                         NETSTACK_RDC.channel_check_interval()),
         RF_CHANNEL);
#endif /* WITH_UIP6 */

#if !WITH_UIP && !WITH_UIP6
  uart1_set_input(serial_line_input_byte);
  serial_line_init();
#endif

  leds_off(LEDS_GREEN);

#if TIMESYNCH_CONF_ENABLED
  timesynch_init();
  timesynch_set_authority_level((rimeaddr_node_addr.u8[0] << 4) + 16);
#endif /* TIMESYNCH_CONF_ENABLED */

#if WITH_UIP
  process_start(&tcpip_process, NULL);
  process_start(&uip_fw_process, NULL);	/* Start IP output */
  process_start(&slip_process, NULL);

  slip_set_input_callback(set_gateway);

  {
    uip_ipaddr_t hostaddr, netmask;

    uip_init();

    uip_ipaddr(&hostaddr, 172,16,
	       rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1]);
    uip_ipaddr(&netmask, 255,255,0,0);
    uip_ipaddr_copy(&meshif.ipaddr, &hostaddr);

    uip_sethostaddr(&hostaddr);
    uip_setnetmask(&netmask);
    uip_over_mesh_set_net(&hostaddr, &netmask);
    /*    uip_fw_register(&slipif);*/
    uip_over_mesh_set_gateway_netif(&slipif);
    uip_fw_default(&meshif);
    uip_over_mesh_init(UIP_OVER_MESH_CHANNEL);
    printf("uIP started with IP address %d.%d.%d.%d\n",
           uip_ipaddr_to_quad(&hostaddr));
  }
#endif /* WITH_UIP */

  energest_init();
  ENERGEST_ON(ENERGEST_TYPE_CPU);

  watchdog_start();
  /* Stop the watchdog */
  watchdog_stop();

#if !PROCESS_CONF_NO_PROCESS_NAMES
  print_processes(autostart_processes);
#else /* !PROCESS_CONF_NO_PROCESS_NAMES */
  putchar('\n'); /* include putchar() */
#endif /* !PROCESS_CONF_NO_PROCESS_NAMES */
  autostart_start(autostart_processes);

  /*
   * This is the scheduler loop.
   */
  while(1) {

    int r;
    do {
      /* Reset watchdog. */
      watchdog_periodic();
      r = process_run();
    } while(r > 0);

    /*
     * Idle processing.
     */
    int s = splhigh();		/* Disable interrupts. */
    /* uart1_active is for avoiding LPM3 when still sending or receiving */
    if(process_nevents() != 0 || uart1_active()) {
      splx(s);                  /* Re-enable interrupts. */
    } else {
      static unsigned long irq_energest = 0;

      /* Re-enable interrupts and go to sleep atomically. */
      ENERGEST_OFF(ENERGEST_TYPE_CPU);
      ENERGEST_ON(ENERGEST_TYPE_LPM);
      /* We only want to measure the processing done in IRQs when we
	 are asleep, so we discard the processing time done when we
	 were awake. */
      energest_type_set(ENERGEST_TYPE_IRQ, irq_energest);
      watchdog_stop();
      _BIS_SR(GIE | SCG0 | SCG1 | CPUOFF); /* LPM3 sleep. This
                                              statement will block
                                              until the CPU is
                                              woken up by an
                                              interrupt that sets
                                              the wake up flag. */

      /* We get the current processing time for interrupts that was
         done during the LPM and store it for next time around.  */
      dint();
      irq_energest = energest_type_time(ENERGEST_TYPE_IRQ);
      eint();
      watchdog_start();
      ENERGEST_OFF(ENERGEST_TYPE_LPM);
      ENERGEST_ON(ENERGEST_TYPE_CPU);
    }
  }
}
Beispiel #27
0
PROCESS_THREAD(scanning, ev, data)
{
 PROCESS_BEGIN();
 
 // Initial operations
 leds_off(LEDS_ALL);
 watchdog_stop(); 
 
 // Avoiding wrong RSSI readings
 unsigned temp;
 CC2420_READ_REG(CC2420_AGCTST1, temp);
 CC2420_WRITE_REG(CC2420_AGCTST1, (temp + (1 << 8) + (1 << 13))); 
 
 // Selecting the channel	
 SPI_SETCHANNEL_SUPERFAST(357+((CHANNEL-11)*5));
 
 // Avoiding the initial wrong readings by discarding the wrong readings
 CC2420_SPI_ENABLE();
 unsigned long k=0;
 for (k=0; k<=15; k++) {MY_FASTSPI_GETRSSI(temp);}
 CC2420_SPI_DISABLE(); 
 
 static struct etimer et;
 while(1){
	 	 
	 #if VERBOSE
	 printf("#START (dBm: occurrencies)\n");
	 #endif
	 
	 // Resetting everything
	 for(k=0;k<BUFFER_SIZE;k++){	
		buffer0[k] = 0;
	 }
	 
	 dint();				// Disable interrupts
	 boost_cpu(); 			// Temporarily boost CPU speed
	 CC2420_SPI_ENABLE(); 	// Enable SPI
	
	 // Actual scanning 
	 static signed char rssi;
	 for(k=0; k<MAX_VALUE; k++){		
		MY_FASTSPI_GETRSSI(rssi);	
		buffer0[rssi+55]++;
	 }	
 
	 CC2420_SPI_DISABLE();	// Disable SPI
	 restore_cpu();			// Restore CPU speed
	 eint(); 				// Re-enable interrupts
 
	 // Printing the stored values in compressed form 
	 unsigned long sum_cca = 0;
	 unsigned long max = 0, max_value = 0;
	 for(temp=0; temp<BUFFER_SIZE; temp++) {	
		sum_cca += (temp * buffer0[temp]);
		if(buffer0[temp] > max){
			max = buffer0[temp];
			max_value = temp;
		}		
	 }
	 
	 // Printing the results of the CCA
	 float f_cca = (((float) sum_cca*1.0000) / MAX_VALUE)-100.0000;		
	 #if VERBOSE
		printf("Average noise: %ld.%04u\nStatistic Mode noise: %ld\n", (long) f_cca, (unsigned)((f_cca-floor(f_cca))*10000), max_value-100);
	 #else
		printf("%ld.%04u\n", (long) f_cca, (unsigned)((f_cca-floor(f_cca))*10000));
	 #endif
	 
	 #if VERBOSE
		printf("#END\n");
	 #endif
	 
	 // Waiting for timer
	 etimer_set(&et, PERIOD_TIME);
	 PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));	
 
 }
 
 PROCESS_WAIT_EVENT();
 
 PROCESS_END();
}
Beispiel #28
0
NORETURN multi_server_main(int argc, char **argv, MULTI_SERVER_FN service,...)
{
    const char *myname = "multi_server_main";
    VSTREAM *stream = 0;
    char   *root_dir = 0;
    char   *user_name = 0;
    int     debug_me = 0;
    int     daemon_mode = 1;
    char   *service_name = basename(argv[0]);
    int     delay;
    int     c;
    int     fd;
    va_list ap;
    MAIL_SERVER_INIT_FN pre_init = 0;
    MAIL_SERVER_INIT_FN post_init = 0;
    MAIL_SERVER_LOOP_FN loop = 0;
    int     key;
    char   *transport = 0;

#if 0
    char   *lock_path;
    VSTRING *why;

#endif
    int     alone = 0;
    int     zerolimit = 0;
    WATCHDOG *watchdog;
    char   *oname_val;
    char   *oname;
    char   *oval;
    const char *err;
    char   *generation;
    int     msg_vstream_needed = 0;
    int     redo_syslog_init = 0;

    /*
     * Process environment options as early as we can.
     */
    if (getenv(CONF_ENV_VERB))
	msg_verbose = 1;
    if (getenv(CONF_ENV_DEBUG))
	debug_me = 1;

    /*
     * Don't die when a process goes away unexpectedly.
     */
    signal(SIGPIPE, SIG_IGN);

    /*
     * Don't die for frivolous reasons.
     */
#ifdef SIGXFSZ
    signal(SIGXFSZ, SIG_IGN);
#endif

    /*
     * May need this every now and then.
     */
    var_procname = mystrdup(basename(argv[0]));
    set_mail_conf_str(VAR_PROCNAME, var_procname);

    /*
     * Initialize logging and exit handler. Do the syslog first, so that its
     * initialization completes before we enter the optional chroot jail.
     */
    msg_syslog_init(mail_task(var_procname), LOG_PID, LOG_FACILITY);
    if (msg_verbose)
	msg_info("daemon started");

    /*
     * Check the Postfix library version as soon as we enable logging.
     */
    MAIL_VERSION_CHECK;

    /*
     * Initialize from the configuration file. Allow command-line options to
     * override compiled-in defaults or configured parameter values.
     */
    mail_conf_suck();

    /*
     * Register dictionaries that use higher-level interfaces and protocols.
     */
    mail_dict_init();
 
    /*
     * After database open error, continue execution with reduced
     * functionality.
     */
    dict_allow_surrogate = 1;

    /*
     * Pick up policy settings from master process. Shut up error messages to
     * stderr, because no-one is going to see them.
     */
    opterr = 0;
    while ((c = GETOPT(argc, argv, "cdDi:lm:n:o:s:St:uvVz")) > 0) {
	switch (c) {
	case 'c':
	    root_dir = "setme";
	    break;
	case 'd':
	    daemon_mode = 0;
	    break;
	case 'D':
	    debug_me = 1;
	    break;
	case 'i':
	    mail_conf_update(VAR_MAX_IDLE, optarg);
	    break;
	case 'l':
	    alone = 1;
	    break;
	case 'm':
	    mail_conf_update(VAR_MAX_USE, optarg);
	    break;
	case 'n':
	    service_name = optarg;
	    break;
	case 'o':
	    oname_val = mystrdup(optarg);
	    if ((err = split_nameval(oname_val, &oname, &oval)) != 0)
		msg_fatal("invalid \"-o %s\" option value: %s", optarg, err);
	    mail_conf_update(oname, oval);
	    if (strcmp(oname, VAR_SYSLOG_NAME) == 0)
		redo_syslog_init = 1;
	    myfree(oname_val);
	    break;
	case 's':
	    if ((socket_count = atoi(optarg)) <= 0)
		msg_fatal("invalid socket_count: %s", optarg);
	    break;
	case 'S':
	    stream = VSTREAM_IN;
	    break;
	case 'u':
	    user_name = "setme";
	    break;
	case 't':
	    transport = optarg;
	    break;
	case 'v':
	    msg_verbose++;
	    break;
	case 'V':
	    if (++msg_vstream_needed == 1)
		msg_vstream_init(mail_task(var_procname), VSTREAM_ERR);
	    break;
	case 'z':
	    zerolimit = 1;
	    break;
	default:
	    msg_fatal("invalid option: %c", c);
	    break;
	}
    }

    /*
     * Initialize generic parameters.
     */
    mail_params_init();
    if (redo_syslog_init)
	msg_syslog_init(mail_task(var_procname), LOG_PID, LOG_FACILITY);

    /*
     * If not connected to stdin, stdin must not be a terminal.
     */
    if (daemon_mode && stream == 0 && isatty(STDIN_FILENO)) {
	msg_vstream_init(var_procname, VSTREAM_ERR);
	msg_fatal("do not run this command by hand");
    }

    /*
     * Application-specific initialization.
     */
    va_start(ap, service);
    while ((key = va_arg(ap, int)) != 0) {
	switch (key) {
	case MAIL_SERVER_INT_TABLE:
	    get_mail_conf_int_table(va_arg(ap, CONFIG_INT_TABLE *));
	    break;
	case MAIL_SERVER_LONG_TABLE:
	    get_mail_conf_long_table(va_arg(ap, CONFIG_LONG_TABLE *));
	    break;
	case MAIL_SERVER_STR_TABLE:
	    get_mail_conf_str_table(va_arg(ap, CONFIG_STR_TABLE *));
	    break;
	case MAIL_SERVER_BOOL_TABLE:
	    get_mail_conf_bool_table(va_arg(ap, CONFIG_BOOL_TABLE *));
	    break;
	case MAIL_SERVER_TIME_TABLE:
	    get_mail_conf_time_table(va_arg(ap, CONFIG_TIME_TABLE *));
	    break;
	case MAIL_SERVER_RAW_TABLE:
	    get_mail_conf_raw_table(va_arg(ap, CONFIG_RAW_TABLE *));
	    break;
	case MAIL_SERVER_NINT_TABLE:
	    get_mail_conf_nint_table(va_arg(ap, CONFIG_NINT_TABLE *));
	    break;
	case MAIL_SERVER_NBOOL_TABLE:
	    get_mail_conf_nbool_table(va_arg(ap, CONFIG_NBOOL_TABLE *));
	    break;
	case MAIL_SERVER_PRE_INIT:
	    pre_init = va_arg(ap, MAIL_SERVER_INIT_FN);
	    break;
	case MAIL_SERVER_POST_INIT:
	    post_init = va_arg(ap, MAIL_SERVER_INIT_FN);
	    break;
	case MAIL_SERVER_LOOP:
	    loop = va_arg(ap, MAIL_SERVER_LOOP_FN);
	    break;
	case MAIL_SERVER_EXIT:
	    multi_server_onexit = va_arg(ap, MAIL_SERVER_EXIT_FN);
	    break;
	case MAIL_SERVER_PRE_ACCEPT:
	    multi_server_pre_accept = va_arg(ap, MAIL_SERVER_ACCEPT_FN);
	    break;
	case MAIL_SERVER_PRE_DISCONN:
	    multi_server_pre_disconn = va_arg(ap, MAIL_SERVER_DISCONN_FN);
	    break;
	case MAIL_SERVER_IN_FLOW_DELAY:
	    multi_server_in_flow_delay = 1;
	    break;
	case MAIL_SERVER_SOLITARY:
	    if (stream == 0 && !alone)
		msg_fatal("service %s requires a process limit of 1",
			  service_name);
	    break;
	case MAIL_SERVER_UNLIMITED:
	    if (stream == 0 && !zerolimit)
		msg_fatal("service %s requires a process limit of 0",
			  service_name);
	    break;
	case MAIL_SERVER_PRIVILEGED:
	    if (user_name)
		msg_fatal("service %s requires privileged operation",
			  service_name);
	    break;
	default:
	    msg_panic("%s: unknown argument type: %d", myname, key);
	}
    }
    va_end(ap);

    if (root_dir)
	root_dir = var_queue_dir;
    if (user_name)
	user_name = var_mail_owner;

    /*
     * Can options be required?
     */
    if (stream == 0) {
	if (transport == 0)
	    msg_fatal("no transport type specified");
	if (strcasecmp(transport, MASTER_XPORT_NAME_INET) == 0)
	    multi_server_accept = multi_server_accept_inet;
	else if (strcasecmp(transport, MASTER_XPORT_NAME_UNIX) == 0)
	    multi_server_accept = multi_server_accept_local;
#ifdef MASTER_XPORT_NAME_PASS
	else if (strcasecmp(transport, MASTER_XPORT_NAME_PASS) == 0)
	    multi_server_accept = multi_server_accept_pass;
#endif
	else
	    msg_fatal("unsupported transport type: %s", transport);
    }

    /*
     * Retrieve process generation from environment.
     */
    if ((generation = getenv(MASTER_GEN_NAME)) != 0) {
	if (!alldig(generation))
	    msg_fatal("bad generation: %s", generation);
	OCTAL_TO_UNSIGNED(multi_server_generation, generation);
	if (msg_verbose)
	    msg_info("process generation: %s (%o)",
		     generation, multi_server_generation);
    }

    /*
     * Optionally start the debugger on ourself.
     */
    if (debug_me)
	debug_process();

    /*
     * Traditionally, BSD select() can't handle multiple processes selecting
     * on the same socket, and wakes up every process in select(). See TCP/IP
     * Illustrated volume 2 page 532. We avoid select() collisions with an
     * external lock file.
     */

    /*
     * XXX Can't compete for exclusive access to the listen socket because we
     * also have to monitor existing client connections for service requests.
     */
#if 0
    if (stream == 0 && !alone) {
	lock_path = concatenate(DEF_PID_DIR, "/", transport,
				".", service_name, (char *) 0);
	why = vstring_alloc(1);
	if ((multi_server_lock = safe_open(lock_path, O_CREAT | O_RDWR, 0600,
				      (struct stat *) 0, -1, -1, why)) == 0)
	    msg_fatal("open lock file %s: %s", lock_path, vstring_str(why));
	close_on_exec(vstream_fileno(multi_server_lock), CLOSE_ON_EXEC);
	myfree(lock_path);
	vstring_free(why);
    }
#endif

    /*
     * Set up call-back info.
     */
    multi_server_service = service;
    multi_server_name = service_name;
    multi_server_argv = argv + optind;

    /*
     * Run pre-jail initialization.
     */
    if (chdir(var_queue_dir) < 0)
	msg_fatal("chdir(\"%s\"): %m", var_queue_dir);
    if (pre_init)
	pre_init(multi_server_name, multi_server_argv);

    /*
     * Optionally, restrict the damage that this process can do.
     */
    resolve_local_init();
    tzset();
    chroot_uid(root_dir, user_name);

    /*
     * Run post-jail initialization.
     */
    if (post_init)
	post_init(multi_server_name, multi_server_argv);

    /*
     * Are we running as a one-shot server with the client connection on
     * standard input? If so, make sure the output is written to stdout so as
     * to satisfy common expectation.
     */
    if (stream != 0) {
	vstream_control(stream,
			VSTREAM_CTL_DOUBLE,
			VSTREAM_CTL_WRITE_FD, STDOUT_FILENO,
			VSTREAM_CTL_END);
	service(stream, multi_server_name, multi_server_argv);
	vstream_fflush(stream);
	multi_server_exit();
    }

    /*
     * Running as a semi-resident server. Service connection requests.
     * Terminate when we have serviced a sufficient number of clients, when
     * no-one has been talking to us for a configurable amount of time, or
     * when the master process terminated abnormally.
     */
    if (var_idle_limit > 0)
	event_request_timer(multi_server_timeout, (char *) 0, var_idle_limit);
    for (fd = MASTER_LISTEN_FD; fd < MASTER_LISTEN_FD + socket_count; fd++) {
	event_enable_read(fd, multi_server_accept, CAST_INT_TO_CHAR_PTR(fd));
	close_on_exec(fd, CLOSE_ON_EXEC);
    }
    event_enable_read(MASTER_STATUS_FD, multi_server_abort, (char *) 0);
    close_on_exec(MASTER_STATUS_FD, CLOSE_ON_EXEC);
    close_on_exec(MASTER_FLOW_READ, CLOSE_ON_EXEC);
    close_on_exec(MASTER_FLOW_WRITE, CLOSE_ON_EXEC);
    watchdog = watchdog_create(var_daemon_timeout, (WATCHDOG_FN) 0, (char *) 0);

    /*
     * The event loop, at last.
     */
    while (var_use_limit == 0 || use_count < var_use_limit || client_count > 0) {
	if (multi_server_lock != 0) {
	    watchdog_stop(watchdog);
	    if (myflock(vstream_fileno(multi_server_lock), INTERNAL_LOCK,
			MYFLOCK_OP_EXCLUSIVE) < 0)
		msg_fatal("select lock: %m");
	}
	watchdog_start(watchdog);
	delay = loop ? loop(multi_server_name, multi_server_argv) : -1;
	event_loop(delay);
    }
    multi_server_exit();
}
static int watchdog_suspend(struct device *dev)
{
	struct watchdog_data *wd = dev_get_drvdata(dev);
	watchdog_stop(wd);
	return 0;
}
static int watchdog_probe(struct platform_device *pdev)
{
	struct resource *res_src, *res_tmr;
	struct watchdog_data *wd;
	u32 src_value;
	int ret = 0;

	if (pdev->id != -1) {
		dev_err(&pdev->dev, "only id -1 supported\n");
		return -ENODEV;
	}

	wd = kzalloc(sizeof(*wd), GFP_KERNEL);
	if (!wd) {
		dev_err(&pdev->dev, "out of memory\n");
		return -ENOMEM;
	}

	res_src = request_mem_region(TEGRA_CLK_RESET_BASE, 4, pdev->name);
	if (!res_src) {
		dev_err(&pdev->dev,
			"unable to request mem region TEGRA_CLK_RESET_BASE\n");
		ret = -ENOMEM;
		goto err_request_mem_region_reset_base;
	}
	res_tmr = request_mem_region(TEGRA_TMR1_BASE, TEGRA_TMR1_SIZE,
				pdev->name);

	if (!res_tmr) {
		dev_err(&pdev->dev,
			"unable to request mem region TEGRA_TMR1_BASE\n");
		ret = -ENOMEM;
		goto err_request_mem_region_tmr1_base;
	}

	wd->wdt_source = ioremap(res_src->start, resource_size(res_src));
	if (!wd->wdt_source) {
		dev_err(&pdev->dev, "unable to map clk_reset registers\n");
		ret = -ENOMEM;
		goto err_ioremap_reset_base;
	}
	wd->wdt_timer = ioremap(res_tmr->start, resource_size(res_tmr));
	if (!wd->wdt_timer) {
		dev_err(&pdev->dev, "unable to map tmr1 registers\n");
		ret = -ENOMEM;
		goto err_ioremap_tmr1_base;
	}

	src_value = readl(wd->wdt_source);
	dev_info(&pdev->dev, "reset source register 0x%x\n", src_value);
	if (src_value & BIT(12))
		dev_info(&pdev->dev, "last reset due to watchdog timeout\n");

	/* the watchdog shouldn't be running, but call stop to also clear
	 * some state that might have persisted between boots
	 */
	watchdog_stop(wd);
	wd->timeout = WDT_TIMEOUT;
	wd->pet_interval = WDT_PET_INTERVAL;
	wd->wq = create_workqueue("pet_watchdog");
	if (!wd->wq) {
		dev_err(&pdev->dev, "unable to map tmr1 registers\n");
		ret = -ENOMEM;
		goto err_create_workqueue;
	}
	INIT_DELAYED_WORK(&wd->work, watchdog_workfunc);

	platform_set_drvdata(pdev, wd);

	dev_info(&pdev->dev, "Starting watchdog timer\n");
	watchdog_start(wd);
	return 0;
err_create_workqueue:
	iounmap(wd->wdt_source);
err_ioremap_tmr1_base:
	iounmap(wd->wdt_timer);
err_ioremap_reset_base:
	release_mem_region(res_src->start, resource_size(res_src));
err_request_mem_region_tmr1_base:
	release_mem_region(res_tmr->start, resource_size(res_tmr));
err_request_mem_region_reset_base:
	kfree(wd);
	return ret;
}