int test_falling(struct harness_t *harness_p) { int i; struct pcint_driver_t pcint; pin_write(&pin, 1); count = 0; BTASSERT(pcint_init(&pcint, &pcint_a9_dev, PCINT_TRIGGER_FALLING_EDGE, isr, NULL) == 0); BTASSERT(pcint_start(&pcint) == 0); /* 10 falling, 9 rising edges. */ for (i = 0; i < 10; i++) { pin_write(&pin, 1); time_busy_wait_us(10000); pin_write(&pin, 0); time_busy_wait_us(10000); } BTASSERT(pcint_stop(&pcint) == 0); /* The interrupt is disabled, no increment. */ pin_write(&pin, 1); time_busy_wait_us(10000); pin_write(&pin, 0); time_busy_wait_us(10000); std_printf(FSTR("count: %d\r\n"), count); BTASSERT(count == 10); return (0); }
int main(void) { char wdrst = 0; uint8_t mcusr; mcusr = MCUSR; if ( mcusr & _BV(WDRF) ) { wdrst = 1; } MCUSR = 0; wdt_disable(); cli(); #ifdef LED1 LED1 = 1; #endif uart_init(UART_BAUD_SELECT_DOUBLE_SPEED(115200,F_CPU)); stdout = &mystdout; sei(); if ( wdrst ) { kputs("\n***WATCHDOG RESET***\n"); } wdt_enable(WDTO_8S); wdt_reset(); kputs("\nSetting DDR registers\n"); DDRA = DDRA_SETTING; DDRB = DDRB_SETTING; DDRC = DDRC_SETTING; DDRD = DDRD_SETTING; DIDR0 = 0; DIDR1 = 0; /* kputs("Hi i2c\n"); i2c_init(); kputs("Hi humid\n"); humid_init(); humid_sleep(); kputs("Hi accel\n"); accel_init(); accel_sleep(); kputs("Hi light\n"); light_init(); light_sleep(); kputs("Hi PIR\n"); pir_wake(); kputs("Hi RTC\n"); rtctimer_init(); kputs("Go away RTC\n"); DDRC &= 0x3F; PORTC |= 0xC0; kputs("Go to sleep\n"); uart_flush(); ACSR = (1<<ACD); LED1 = LED2 = 0; cli(); wdt_disable(); SMCR = (2<<SM0) | (1<<SE); //Enable Power-Down Mode while(1) { asm volatile ("sleep"); // __sleep(); // Go to sleep } */ kputs("Initializing PCINT\n"); pcint_init(); kputs("Initializing Reports\n"); report_init(); board_init_devices(); kputs("Initializing wireless mote\n"); wdt_reset(); datalink_init(); /* PIR_VCC = 1; while(1) { if(PIR_OUT_PIN) { kputs("ON\n"); } else { kputs("OFF\n"); } _delay_ms(50); }*/ kputs("Powering down all devices\n"); board_power_down_devices(); kputs("Init logic subsystem\n"); logic_init(); /* kputs("Turning on always-on devices\n"); pir_wake(); accel_wake(); */ board_setup_reporting(); kputs("Starting RTC clock\n"); rtctimer_init(); rtctimer_set_periodic_alarm(report_interval_needed(),&rtc_timer_cb); wdt_reset(); wdt_disable(); while(1) { //wdt_enable(WDTO_2S); //wdt_reset(); pcint_check(); rtctimer_check_alarm(); wdt_disable(); datalink_tick(); #ifdef USE_PN532 rtc_timer_cb(); // causes monitor list to be run #else #if defined LOW_POWER // do we have a RTC clock and battery-powered avr_sleep(); #else avr_doze(); #endif #endif } }