Example #1
0
/**
 * \brief Test watchdog setting
 *
 * This test sets the watchdog to trigger an interrupt every 100ms.
 *
 * \param test Current test case.
 */
static void run_wdt_test(const struct test_case *test)
{
	/* Clear watchdog if already enabled */
	wdt_restart(WDT);

	/* Enable WDT interrupt line from the core */
	NVIC_DisableIRQ(WDT_IRQn);
	NVIC_ClearPendingIRQ(WDT_IRQn);
	NVIC_SetPriority(WDT_IRQn, 4);
	NVIC_EnableIRQ(WDT_IRQn);

	/* Test1: Initialize WDT to trigger a reset after 100ms */
	wdt_init(WDT, WDT_MR_WDFIEN, 26, 26);

	delay_ms(50);
	test_assert_true(test, gs_wdt_triggered == 0, "Test1: unexpected watchdog interrupt!");

	/* Test2: Restart the watchdog */
	wdt_restart(WDT);
	delay_ms(50);
	test_assert_true(test, gs_wdt_triggered == 0, "Test2: unexpected watchdog interrupt!");
	
	/* Test 3: Trigger the watchdog interrupt (reset) */
	delay_ms(200);
	test_assert_true(test, gs_wdt_triggered == 1, "Test3: no watchdog interrupt received, expected one!");
}
Example #2
0
int main() {
	const Pin pins_stack[] = {PINS_STACK};
	PIO_Configure(pins_stack, PIO_LISTSIZE(pins_stack));

	brick_hardware_version[0] = BRICK_HARDWARE_VERSION_MAJOR;
	brick_hardware_version[1] = BRICK_HARDWARE_VERSION_MINOR;
	brick_hardware_version[2] = BRICK_HARDWARE_VERSION_REVISION;

	brick_init();
	wdt_restart();

#ifdef PROFILING
    profiling_init();
#endif

    if(usb_is_connected()) {
    	logi("Configure as USB device\n\r");
    	usb_init();
    	wdt_restart();

    	xTaskCreate(usb_message_loop,
    				(signed char *)"usb_ml",
    				2000,
    				NULL,
    				1,
    				(xTaskHandle *)NULL);
    } else {
    	usb_first_connection = false;
    	logi("Configure as Stack Participant (SPI)\n\r");
        spi_stack_slave_init();
        wdt_restart();

    	xTaskCreate(spi_stack_slave_message_loop,
    			    (signed char *)"spi_ml",
    			    2500,
    			    NULL,
    			    1,
    			    (xTaskHandle *)NULL);
    }

	dc_init();
	wdt_restart();

	brick_init_start_tick_task();
	wdt_restart();

	vTaskStartScheduler();
}
Example #3
0
// Switch into boot mode and reset
void EraseAndReset()
{
	cpu_irq_disable();

#if SAM4S
# define IFLASH_ADDR				IFLASH0_ADDR
# define IFLASH_PAGE_SIZE			IFLASH0_PAGE_SIZE
# define IFLASH_NB_OF_PAGES			(IFLASH0_SIZE / IFLASH_PAGE_SIZE)
#endif

#if SAM3XA
# define IFLASH_ADDR				IFLASH0_ADDR
# define IFLASH_PAGE_SIZE			IFLASH0_PAGE_SIZE
# define IFLASH_NB_OF_PAGES			((IFLASH1_ADDR + IFLASH1_SIZE - IFLASH_ADDR) / IFLASH_PAGE_SIZE)
#endif

    for(size_t i = 0; i <= IFLASH_NB_OF_PAGES; i++)
    {
    	wdt_restart(WDT);
        size_t pageStartAddr = IFLASH_ADDR + i * IFLASH_PAGE_SIZE;
        flash_unlock(pageStartAddr, pageStartAddr + IFLASH_PAGE_SIZE - 1, nullptr, nullptr);
    }

    flash_clear_gpnvm(1);			// tell the system to boot from ROM next time
	rstc_start_software_reset(RSTC);
	for(;;) {}
}
Example #4
0
/**
  * @brief  this function handles TIM5 global interrupt request.
  * @param  none
  * @retval none
  */
void WDT_Handler(void)
{
	/* Clear status bit to acknowledge interrupt by dummy read. */
	wdt_get_status(WDT);
	/* Restart the WDT counter. */
	wdt_restart(WDT);
}
Example #5
0
void SysTick_Handler(void)
{
	if (sysTickHook())
		return;

	wdt_restart(WDT);							// kick the watchdog

	TimeTick_Increment();						// increment tick count each ms
}
Example #6
0
void mico_wdg_reload( void )
{

#ifndef MICO_DISABLE_WATCHDOG
  wdt_restart(WDT);
#else
  return;
#endif
}
Example #7
0
/**
 *  \brief Handler for watchdog interrupt.
 */
void WDT_Handler(void)
{
	puts("Enter watchdog interrupt.\r");

	/* Clear status bit to acknowledge interrupt by dummy read. */
	wdt_get_status(WDT);
	/* Restart the WDT counter. */
	wdt_restart(WDT);
	puts("The watchdog timer was restarted.\r");
}
Example #8
0
void ForeverHang ( const bool keepWatchdogHappy ) throw()
{
  __disable_irq();

  for ( ; ; )
  {
    if ( keepWatchdogHappy )
      wdt_restart( WDT );
  }
}
Example #9
0
void ResetBoard ( const bool triggerWatchdogDuringWait )
{
  __disable_irq();

  rstc_start_software_reset( RSTC );

  while ( true )
  {
    // If we do not keep the watchdog happy and it times out during this wait,
    // the reset reason will be wrong when the board starts the next time around.

    if ( triggerWatchdogDuringWait )
      wdt_restart( WDT );
  }
}
Example #10
0
int main() {

	brick_init();
	led_init();
	Pin ch_st = PIN_CH_ST;
	PIO_Configure(&ch_st, 1);
	while(1) {	
		if(PIO_Get(&ch_st)) {
			led_toggle(LED_STD_BLUE);
		}
		else {
			led_on(LED_STD_BLUE);
		}
		SLEEP_MS(100);
		wdt_restart();
	}
}
Example #11
0
File: main.c Project: 12019/openpcd
int main(void)
{
	/* initialize LED and debug unit */
	led_init();
	sysirq_init();
	AT91F_DBGU_Init();

	AT91F_PIOA_CfgPMC();
	wdt_init();
	pit_init();
	blinkcode_init();

	/* initialize USB */
	req_ctx_init();
	usbcmd_gen_init();
	udp_open();

	/* call application specific init function */
	_init_func();

	// Enable User Reset and set its minimal assertion to 960 us
	AT91C_BASE_RSTC->RSTC_RMR =
	    AT91C_RSTC_URSTEN | (0x4 << 8) | (unsigned int)(0xA5 << 24);

#ifdef DEBUG_CLOCK_PA6
	AT91F_PMC_EnablePCK(AT91C_BASE_PMC, 0, AT91C_PMC_CSS_PLL_CLK);
	AT91F_PIO_CfgPeriph(AT91C_BASE_PIOA, 0, AT91C_PA6_PCK0);
#endif

	/* switch on first led */
	led_switch(2, 1);

	DEBUGPCRF("entering main (idle) loop");
	while (1) {
		/* Call application specific main idle function */
		_main_func();
		dbgu_rb_flush();
		
		/* restart watchdog timer */
		wdt_restart();
#ifdef CONFIG_IDLE
		//cpu_idle();
#endif
	}
}
Example #12
0
void brick_tick_task(void *parameters) {
	const uint8_t tick_type = *((uint8_t*)parameters);
	unsigned long last_wake_time = xTaskGetTickCount();
	while(true) {
		wdt_restart();
		tick_task(tick_type);
		taskYIELD();
		bricklet_tick_task(tick_type);
		led_tick_task(tick_type);
		usb_detect_task(tick_type);

		// 1ms resolution
		unsigned long tick_count = xTaskGetTickCount();
		if(tick_count > last_wake_time + 2) {
			last_wake_time = tick_count - 1;
		}

		vTaskDelayUntil(&last_wake_time, 1);
	}
}
Example #13
0
/**
 * Get Autodetect Impedance mode.
 */
static void get_impedance_mode(void)
{
	uint8_t uc_char;

	puts(MENU_IMPEDANCE);

	while (1) {
		while (uart_read(CONSOLE_UART, &uc_char)) {
			/* Restart watchdog */
			wdt_restart(WDT);
		}
		switch (uc_char) {
		case '0':
			auto_impedance_mode();
			printf("Autodetec mode selected\r\n");
			break;

		case '1':
			fix_impedance_mode(HI_STATE);
			printf("Fix high impedance mode selected\r\n");
			break;

		case '2':
			fix_impedance_mode(LO_STATE);
			printf("Fix low impedance mode selected\r\n");
			break;

		case '3':
			fix_impedance_mode(VLO_STATE);
			printf("Fix very low impedance mode selected\r\n");
			break;

		default:
			continue;
		}
		printf(MENU_CONSOLE);
		fflush(stdout);
		break;
	}
}
Example #14
0
/**
 * \brief Application entry point for wdt_irq example.
 *
 * \return Unused (ANSI-C compatibility).
 */
int main(void)
{
	uint32_t wdt_mode, timeout_value;

	/* Initialize the system */
	sysclk_init();
	board_init();

	/* Configure pins of console UART, LED and push button on board. */
	configure_console();
	configure_led();

	/* Output example information. */
	puts(STRING_HEADER);

	/* Initialize reset counter */
	ul_rst_counter = RST_MS_COUNTER;

	/* Systick configuration. */
	puts("Configure systick to get 1ms tick period.\r");
	if (SysTick_Config(sysclk_get_cpu_hz() / 1000)) {
		puts("-F- Systick configuration error\r");
	}

	/* Get timeout value. */
	timeout_value = wdt_get_timeout_value(WDT_PERIOD * 1000,
			BOARD_FREQ_SLCK_XTAL);
	if (timeout_value == WDT_INVALID_ARGUMENT) {
		while (1) {
			/* Invalid timeout value, error. */
		}
	}
	/* Configure WDT to trigger an interrupt (or reset). */
	wdt_mode = WDT_MR_WDFIEN |  /* Enable WDT fault interrupt. */
			WDT_MR_WDRPROC   |  /* WDT fault resets processor only. */
			WDT_MR_WDDBGHLT  |  /* WDT stops in debug state. */
			WDT_MR_WDIDLEHLT;   /* WDT stops in idle state. */
	/* Initialize WDT with the given parameters. */
	wdt_init(WDT, wdt_mode, timeout_value, timeout_value);
	printf("Enable watchdog with %d microseconds period\n\r",
			(int)wdt_get_us_timeout_period(WDT, BOARD_FREQ_SLCK_XTAL));

	/* Configure and enable WDT interrupt. */
	NVIC_DisableIRQ(WDT_IRQn);
	NVIC_ClearPendingIRQ(WDT_IRQn);
	NVIC_SetPriority(WDT_IRQn, 0);
	NVIC_EnableIRQ(WDT_IRQn);

	printf("After %u seconds the system enters in a deadlock loop.\n\r", (int)ul_rst_counter/1000);

	while (1) {

		if (g_b_systick_event == true) {
			g_b_systick_event = false;

			/* Toggle LED at the given period. */
			if ((g_ul_ms_ticks % BLINK_PERIOD) == 0) {
#if (SAM4CM)
				LED_Toggle(LED4);
#else
				LED_Toggle(LED0);
#endif
			}

			/* Restart watchdog at the given period. */
			if ((g_ul_ms_ticks % WDT_RESTART_PERIOD) == 0) {
				wdt_restart(WDT);
			}
		}

		/* Simulate deadlock when reset counter is reset. */
		if (!ul_rst_counter) {
			puts("Program enters infinite loop for triggering watchdog interrupt.\r");
			while (1) {
			}
		}
	}
}
Example #15
0
void monitor(void){
  uint32_t prev_tick=0;

  //allocate memory for buffers and flush them
  cmd_buf = membag_alloc(CMD_BUF_SIZE);
  if(!cmd_buf)
    core_panic();
  memset(cmd_buf,0x0,CMD_BUF_SIZE);
  //initialize the power packet buffers
  tx_pkt = &power_pkts[0];
  cur_pkt = &power_pkts[1];
  //both are empty
  tx_pkt->status = POWER_PKT_EMPTY;
  cur_pkt->status = POWER_PKT_EMPTY;

  //initialize runtime configs
  wemo_config.echo = false;
  wemo_config.debug_level = DEBUG_ERROR;
  wemo_config.collect_data = true; //collect power data

  //check if we are on USB
  if(gpio_pin_is_high(VBUS_PIN)){
    rgb_led_set(LED_LT_BLUE,0); 
    //don't start wifi because we are configuring
    b_wifi_enabled=false;
    //don't collect power data
    wemo_config.collect_data = false;
  }
  //check if the plug is in calibrate mode
  if(wemo_config.calibrate){
    //start the calibration PWM
    pwm_channel_enable_interrupt(PWM,CAL_PWM_CHANNEL,CAL_PWM_CHANNEL);
    pwm_channel_enable(PWM,CAL_PWM_CHANNEL);
    //don't start wifi because we are in calibration mode
    b_wifi_enabled=false;
    wemo_config.standalone = true;
    wemo_config.collect_data = false;
    //indicate cal mode with a purple LED
    rgb_led_set(LED_PURPLE,0);
  }
  //check if reset is pressed
  if(gpio_pin_is_low(BUTTON_PIN)){
    //erase the configs
    memset(wemo_config.nilm_id,0x0,MAX_CONFIG_LEN);
    memset(wemo_config.nilm_ip_addr,0x0,MAX_CONFIG_LEN);
    memset(wemo_config.wifi_ssid,0x0,MAX_CONFIG_LEN);
    memset(wemo_config.wifi_pwd,0x0,MAX_CONFIG_LEN);
    //save the erased config
    fs_write_config();
    core_log("erased config");
    //erase the stored data 
    
    //spin until button is released
    rgb_led_set(LED_ORANGE,500);
    while(gpio_pin_is_low(BUTTON_PIN));
    rgb_led_set(LED_ORANGE,0); //disable blink
  }
  //setup WIFI
  if(b_wifi_enabled){
    if(wifi_init()!=0){
      rgb_led_set(LED_PURPLE,0);
    }
    else{
      //good to go! turn light green
      rgb_led_set(LED_LT_GREEN,0);
    }
  }
  //initialize the wifi_rx buffer and flag
  wifi_rx_buf_full = false;
  memset(wifi_rx_buf,0x0,WIFI_RX_BUF_SIZE);
  while (1) {
    //***** SYS TICK ACTIONS ******
    if(sys_tick!=prev_tick){
      //check if there is a valid wemo sample
      if(wemo_sample.valid==true && wemo_config.collect_data){
	core_log_power_data(&wemo_sample);
      }
      wemo_read_power();
      wdt_restart(WDT);
      prev_tick = sys_tick;
    }
    //check for pending data from the Internet
    if(wifi_rx_buf_full){
      core_process_wifi_data();
      wifi_rx_buf_full=false;
    }
    //see if we have any commands to run
    if(cmd_buf_full){
      runcmd(cmd_buf); //  run it
      //clear the buffer
      cmd_buf_idx = 0;
      memset(cmd_buf,0x0,CMD_BUF_SIZE);
      if(wemo_config.echo)
	printf("\r> "); //print the prompt
      cmd_buf_full=false;
    }
  }
    
}
Example #16
0
void watchdogReset(void)
{
	wdt_restart (WDT);
}