static long wdt_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { void __user *argp = (void __user *)arg; int __user *p = argp; int new_timeout; static const struct watchdog_info ident = { .options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE, .firmware_version = 1, .identity = "W83697UG WDT", }; switch (cmd) { case WDIOC_GETSUPPORT: if (copy_to_user(argp, &ident, sizeof(ident))) return -EFAULT; break; case WDIOC_GETSTATUS: case WDIOC_GETBOOTSTATUS: return put_user(0, p); case WDIOC_SETOPTIONS: { int options, retval = -EINVAL; if (get_user(options, p)) return -EFAULT; if (options & WDIOS_DISABLECARD) { wdt_disable(); retval = 0; } if (options & WDIOS_ENABLECARD) { wdt_ping(); retval = 0; } return retval; } case WDIOC_KEEPALIVE: wdt_ping(); break; case WDIOC_SETTIMEOUT: if (get_user(new_timeout, p)) return -EFAULT; if (wdt_set_heartbeat(new_timeout)) return -EINVAL; wdt_ping(); /* Fall */ case WDIOC_GETTIMEOUT: return put_user(timeout, p); default: return -ENOTTY; } return 0; } static int wdt_open(struct inode *inode, struct file *file) { if (test_and_set_bit(0, &wdt_is_open)) return -EBUSY; /* * Activate */ wdt_ping(); return nonseekable_open(inode, file); } static int wdt_close(struct inode *inode, struct file *file) { if (expect_close == 42) wdt_disable(); else { printk(KERN_CRIT PFX "Unexpected close, not stopping watchdog!\n"); wdt_ping(); } expect_close = 0; clear_bit(0, &wdt_is_open); return 0; } /* * Notifier for system down */ static int wdt_notify_sys(struct notifier_block *this, unsigned long code, void *unused) { if (code == SYS_DOWN || code == SYS_HALT) wdt_disable(); /* Turn the WDT off */ return NOTIFY_DONE; } /* * Kernel Interfaces */ static const struct file_operations wdt_fops = { .owner = THIS_MODULE, .llseek = no_llseek, .write = wdt_write, .unlocked_ioctl = wdt_ioctl, .open = wdt_open, .release = wdt_close, }; static struct miscdevice wdt_miscdev = { .minor = WATCHDOG_MINOR, .name = "watchdog", .fops = &wdt_fops, }; /* * The WDT needs to learn about soft shutdowns in order to * turn the timebomb registers off. */ static struct notifier_block wdt_notifier = { .notifier_call = wdt_notify_sys, }; static int __init wdt_init(void) { int ret; printk(KERN_INFO "WDT driver for the Winbond(TM) W83697UG/UF Super I/O chip initialising.\n"); if (wdt_set_heartbeat(timeout)) { wdt_set_heartbeat(WATCHDOG_TIMEOUT); printk(KERN_INFO PFX "timeout value must be 1<=timeout<=255, using %d\n", WATCHDOG_TIMEOUT); } if (!request_region(wdt_io, 1, WATCHDOG_NAME)) { printk(KERN_ERR PFX "I/O address 0x%04x already in use\n", wdt_io); ret = -EIO; goto out; } ret = w83697ug_init(); if (ret != 0) goto unreg_regions; ret = register_reboot_notifier(&wdt_notifier); if (ret != 0) { printk(KERN_ERR PFX "cannot register reboot notifier (err=%d)\n", ret); goto unreg_regions; } ret = misc_register(&wdt_miscdev); if (ret != 0) { printk(KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n", WATCHDOG_MINOR, ret); goto unreg_reboot; } printk(KERN_INFO PFX "initialized. timeout=%d sec (nowayout=%d)\n", timeout, nowayout); out: return ret; unreg_reboot: unregister_reboot_notifier(&wdt_notifier); unreg_regions: release_region(wdt_io, 1); goto out; } static void __exit wdt_exit(void) { misc_deregister(&wdt_miscdev); unregister_reboot_notifier(&wdt_notifier); release_region(wdt_io, 1); }
_start(void) { /* * Depending on the config parameter, enable or disable the WDT. */ #if !defined(CONFIG_HW_WATCHDOG) #if !defined(CONFIG_SYS_M2S) wdt_disable(); #endif #else wdt_enable(); #endif /* * Make sure interrupts are disabled. */ __disable_irq(); #ifdef CONFIG_LPC18XX_NORFLASH_BOOTSTRAP_WORKAROUND /* * Reload the whole U-Boot image from NOR flash. * The Boot ROM on LPC4350 parts cannot load more than 32KBytes * from NOR flash when booting. */ lpc18xx_bootstrap_from_norflash(); #endif /* CONFIG_LPC18XX_NORFLASH_BOOTSTRAP_WORKAROUND */ /* * Copy data and initialize BSS * This is in lieu of the U-boot "conventional" relocation * of code & data from Flash to RAM. * With Cortex-M3, we execute from NVRAM (internal Flash), * having relocated data to internal RAM (and having cleared the BSS * area in internal RAM as well) * Stack grows downwards; the stack base is set-up by the first * value in the first word in the vectors. */ memcpy(&_data_start, &_data_lma_start, &_data_end - &_data_start); memset(&_bss_start, 0, &_bss_end - &_bss_start); /* * Copy RAMCODE separately, if it is separated */ #if defined(CONFIG_MEM_RAMCODE_BASE) && defined(CONFIG_MEM_RAMCODE_LEN) memcpy(&_ramcode_start, &_ramcode_lma_start, &_ramcode_end - &_ramcode_start); #endif /* * In U-boot (armboot) lingvo, "go to the C code" - * in fact, with M3, we are at the C code from the very beginning. * In actuality, this is the jump to the ARM generic start code. * ... * Note initialization of _armboot_start below. The ARM generic * code expects that this variable is set to the upper boundary of * the malloc pool area. * For Cortex-M3, where we do not relocate the code to RAM, I set * the malloc pool right behind the stack. See how armboot_start * is defined in the CPU specific .lds file. */ _armboot_start = (unsigned long)&_mem_stack_base; start_armboot(); }
static void __exit avila_wdt_exit(void) { misc_deregister(&avila_wdt_miscdev); del_timer(&wdt_timer); wdt_disable(); }
int main(void) { /* Watchdog */ wdt_reset(); wdt_disable(); /* Ports */ DDRB = _BV(PINB0) | _BV(PINB2) | _BV(PINB3) | _BV(PINB5); DDRD = _BV(PIND5) | _BV(PIND7); PORTB = 0xff; //& (_BV(PINB0)); PORTC = 0xff; PORTD = 0xff;// & (_BV(PIND5) | _BV(PIND6) | _BV(PIND7)); /* Power saving */ set_sleep_mode(SLEEP_MODE_IDLE); //b = fifoCreate(255); vs1002Reset(); DDRD |= _BV(DDD1); UCSR0B = _BV(TXEN0) | _BV(RXEN0); // | _BV(RXCIE0); UBRR0L = 9; /* SPI */ SPCR = _BV(SPE) | _BV(MSTR) | _BV(SPR1) | _BV(SPR0); //SPSR = _BV(SPI2X); // 0x8000 + 6144 = 0x9800, 12.288MHz XTAL + clk-doubling /* Clock */ vs1002cmd_s(); SPDR = 0x02; loop_until_bit_is_set(SPSR, SPIF); SPDR = 0x03; loop_until_bit_is_set(SPSR, SPIF); SPDR = 0x98; loop_until_bit_is_set(SPSR, SPIF); SPDR = 0x00; loop_until_bit_is_set(SPSR, SPIF); vs1002cmd_e(); /* Mode: TEST */ vs1002cmd_s(); SPDR = 0x02; loop_until_bit_is_set(SPSR, SPIF); SPDR = 0x00; loop_until_bit_is_set(SPSR, SPIF); SPDR = 0x08; loop_until_bit_is_set(SPSR, SPIF); SPDR = 0x20; // Test loop_until_bit_is_set(SPSR, SPIF); vs1002cmd_e(); /* Volume */ vs1002cmd_s(); SPDR = 0x02; loop_until_bit_is_set(SPSR, SPIF); SPDR = 0x0b; loop_until_bit_is_set(SPSR, SPIF); SPDR = 0x00; loop_until_bit_is_set(SPSR, SPIF); SPDR = 0x00; loop_until_bit_is_set(SPSR, SPIF); vs1002cmd_e(); /* Test 1.500kHz sine */ vs1002data_s(); SPDR = 0x53; loop_until_bit_is_set(SPSR, SPIF); SPDR = 0xef; loop_until_bit_is_set(SPSR, SPIF); SPDR = 0x6e; loop_until_bit_is_set(SPSR, SPIF); SPDR = 0x28; loop_until_bit_is_set(SPSR, SPIF); SPDR = 0x00; loop_until_bit_is_set(SPSR, SPIF); SPDR = 0x00; loop_until_bit_is_set(SPSR, SPIF); SPDR = 0x00; loop_until_bit_is_set(SPSR, SPIF); SPDR = 0x00; loop_until_bit_is_set(SPSR, SPIF); vs1002data_e(); uint8_t t; for (t = 0; t < 125; t++) { _delay_ms(2); } /* End test */ vs1002data_s(); SPDR = 0x45; loop_until_bit_is_set(SPSR, SPIF); SPDR = 0x78; loop_until_bit_is_set(SPSR, SPIF); SPDR = 0x69; loop_until_bit_is_set(SPSR, SPIF); SPDR = 0x74; loop_until_bit_is_set(SPSR, SPIF); SPDR = 0x00; loop_until_bit_is_set(SPSR, SPIF); SPDR = 0x00; loop_until_bit_is_set(SPSR, SPIF); SPDR = 0x00; loop_until_bit_is_set(SPSR, SPIF); SPDR = 0x00; loop_until_bit_is_set(SPSR, SPIF); vs1002data_e(); /* Mode: PLAY */ vs1002cmd_s(); SPDR = 0x02; loop_until_bit_is_set(SPSR, SPIF); SPDR = 0x00; loop_until_bit_is_set(SPSR, SPIF); SPDR = 0x08; loop_until_bit_is_set(SPSR, SPIF); SPDR = 0x08; // STREAM loop_until_bit_is_set(SPSR, SPIF); vs1002cmd_e(); uint16_t i; uint8_t buffer[1000]; for (;;) { uartTx('.'); for (i = 0; i < 1000; i++) { loop_until_bit_is_set(UCSR0A, RXC0); buffer[i] = UDR0; } loop_until_bit_is_set(VS1002_DREQ_PORT, VS1002_DREQ_PIN); vs1002data_s(); for (i = 0; i < 1000; i++) { loop_until_bit_is_set(SPSR, SPIF); SPDR = buffer[i]; } vs1002data_e(); } }
void WatchdogAVR::disable() { // Disable the watchdog and clear any saved watchdog timer value. wdt_disable(); _wdto = -1; }
int main() { wdt_disable(); // no watchdog, just because I'm lazy // Configure I/O PORTS - All Digital Inputs (ARCADE) DDRB = 0; DDRC = 0; DDRD = 0; // Configure Pullups except for Pins PD2 and PD3 PORTB = 0xff; PORTC = 0xff; PORTD = 0xf3; // 1 1 1 1 0 0 1 1 // Configure ADC ADMUX = (1<<REFS0 | 1<<ADLAR ); // AREF = AVcc, Left Justified // 12000000/128 = 93750Hz ADCSRA = (1<<ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0); // ADC Enable and prescaler of 128 // Configure timer TCCR1B = _BV(CS12) | _BV(CS11); // timer is initialized, used to keep track of idle period // Start the show! usbInit(); // start v-usb usbDeviceDisconnect(); // enforce USB re-enumeration, do this while interrupts are disabled! _delay_ms(250); usbDeviceConnect(); sei(); // enable interrupts uint8_t to_send = 1; // boolean, true for first time while (1) { usbPoll(); // Initialize the report IDs // gamepad_report_1.report_id = 1; // no ID is sent. All data shall be within 8 bytes // Initialize report. No buttons pressed, directional at center gamepad_report_1.buttons8_1=0; gamepad_report_1.buttons12_9=0; gamepad_report_1.vXaxis=0; gamepad_report_1.vYaxis=0; gamepad_report_1.vZaxis=0; gamepad_report_1.vRXaxis=0; gamepad_report_1.vRYaxis=0; gamepad_report_1.vRZaxis=0; // Populate Analog Axes ADMUX = (ADMUX & 0xF8) | Xaxis; // Select X axis ADCSRA |= (1<<ADSC); // start single convertion while(ADCSRA & (1<<ADSC)); // wait for conversion to complete gamepad_report_1.vXaxis = 127-ADCH; ADMUX = (ADMUX & 0xF8) | Yaxis; // Select Y axis ADCSRA |= (1<<ADSC); // start single convertion while(ADCSRA & (1<<ADSC)); // wait for conversion to complete gamepad_report_1.vYaxis = 127-ADCH; ADMUX = (ADMUX & 0xF8) | Zaxis; // Select Z axis ADCSRA |= (1<<ADSC); // start single convertion while(ADCSRA & (1<<ADSC)); // wait for conversion to complete gamepad_report_1.vZaxis = 127-ADCH; ADMUX = (ADMUX & 0xF8) | RXaxis; // Select RX axis ADCSRA |= (1<<ADSC); // start single convertion while(ADCSRA & (1<<ADSC)); // wait for conversion to complete gamepad_report_1.vRXaxis = 127-ADCH; ADMUX = (ADMUX & 0xF8) | RYaxis; // Select RY axis ADCSRA |= (1<<ADSC); // start single convertion while(ADCSRA & (1<<ADSC)); // wait for conversion to complete gamepad_report_1.vRYaxis = 127-ADCH; ADMUX = (ADMUX & 0xF8) | RZaxis; // Select RZ axis ADCSRA |= (1<<ADSC); // start single convertion while(ADCSRA & (1<<ADSC)); // wait for conversion to complete gamepad_report_1.vRZaxis = 127-ADCH; // Populate buttons 1-7 if ( B3 ) gamepad_report_1.buttons8_1 += 1; if ( B4 ) gamepad_report_1.buttons8_1 += 2; if ( B5 ) gamepad_report_1.buttons8_1 += 4; if ( B6 ) gamepad_report_1.buttons8_1 += 8; if ( B7 ) gamepad_report_1.buttons8_1 += 16; if ( B8 ) gamepad_report_1.buttons8_1 += 32; if ( B9 ) gamepad_report_1.buttons8_1 += 64; if ( A9 ) gamepad_report_1.buttons8_1 += 128; // Populate buttons 12-9 if ( A8 ) gamepad_report_1.buttons12_9 += 1; if ( A7 ) gamepad_report_1.buttons12_9 += 2; if ( A6 ) gamepad_report_1.buttons12_9 += 4; if ( A5 ) gamepad_report_1.buttons12_9 += 8; // determine whether or not the report should be sent if ((TCNT1 > ((4 * (F_CPU / 1024000)) * idle_rate) || TCNT1 > 0x7FFF) && idle_rate != 0) {// using idle rate to_send = 1; } else {// or if data has changed if (memcmp(&gamepad_report_1, &gamepad_report_1_old, sizeof(gamepad_report_t)) != 0) { to_send = 1; } } usbPoll(); if (to_send != 0) { // send the data if needed usbSendHidReport(&gamepad_report_1, sizeof(gamepad_report_t)); TCNT1 = 0; // reset timer } usbPoll(); memcpy(&gamepad_report_1_old, &gamepad_report_1, sizeof(gamepad_report_t)); to_send = 0; // reset flag } return 0; }
/* ---------------------------------------------------------------------------- * セットアップ処理 * ---------------------------------------------------------------------------- */ void setup() { // Watchdog タイマ停止 MCUSR = 0; wdt_disable(); // SPI 設定 DDRB |= (1<<PORTB1); DDRB |= (1<<PORTB2); // Master 設定 SPCR |= (1<<MSTR); // ClockDivide 000 = 1/4 SPCR &= ~(1<<SPR1); SPCR &= ~(1<<SPR0); SPSR &= ~(1<<SPI2X); // MODE 0 SPCR &= ~(1<<CPOL); SPCR &= ~(1<<CPHA); // MSB First SPCR &= ~(1<<DORD); // SPI Enable SPCR |= (1<<SPE); // LED ポート出力 DDRC |= (1<<LED); PORTD = 0; Serial1.begin(); i2c.begin(); // リセット直後の時間待ち(1秒) for(int i = 0; i < 100; i++) { _delay_ms(10); } rtc.begin(); // 74HC595 DDRB |= (1<<HC595RCLK); PORTB &= ~(1<<HC595RCLK); // K155ID1 DDRB |= (1<<K155ID1_A); DDRB |= (1<<K155ID1_B); DDRB |= (1<<K155ID1_C); DDRB |= (1<<K155ID1_D); // IN12 カンマ DDRE |= (1<<COMMA); // EEPROM 読み出し eeprom_busy_wait(); displayDateIntervalValue = eeprom_read_word(&E_displayDateIntervalValue); eeprom_busy_wait(); displayDateSecondsValue = eeprom_read_word(&E_displayDateSecondsValue); eeprom_busy_wait(); userDataTimerValue = eeprom_read_word(&E_userDataTimerValue); eeprom_busy_wait(); dispTimeFormat = eeprom_read_byte(&E_dispTimeFormat); eeprom_busy_wait(); IN12BrightDaytime = eeprom_read_byte(&E_IN12BrightDaytime); eeprom_busy_wait(); IN12BrightNight = eeprom_read_byte(&E_IN12BrightNight); eeprom_busy_wait(); hourDaytime = eeprom_read_byte(&E_hourDaytime); eeprom_busy_wait(); hourNight = eeprom_read_byte(&E_hourNight); eeprom_busy_wait(); hour12_24format = eeprom_read_byte(&E_hour12_24format); // タイマー、カウンタ 0 初期化 // Disbale interrupt TIMSK0 &= ~(1<<OCIE0B); TIMSK0 &= ~(1<<OCIE0A); TIMSK0 &= ~(1<<TOIE0); // 比較一致タイマ/カウンタ解除(CTC)動作 TCCR0B &= ~(1<<WGM02); TCCR0A |= (1<<WGM01); TCCR0A &= ~(1<<WGM00); // clkI/O/64 (64分周) TCCR0B &= ~(1<<CS02); TCCR0B |= (1<<CS01); TCCR0B |= (1<<CS00); TCNT0 = 0; // 16MHz / 64 = 4us. 4us * 250 = 1.0ms OCR0A = 249; // set interrupt mask TIFR0 |= (1<<OCF0A); // Enable interrupt TIMSK0 |= (1<<OCIE0A); // Watchdog タイマ設定 wdt_enable(WDTO_1S); // 割り込み処理を有効にする sei(); }
/** Disables the watchdog timer. Should be specified to be run as soon as possible * according to atmel by putting in first. This is done in the declaration for this function. */ void wdt_init(void) { MCUSR = 0; wdt_disable(); return; }
/*----------------------------------------------------------------------------- * program start */ int main(void) { int sioHandle; uint8_t i; uint8_t u8; MCUSR = 0; wdt_disable(); /* get module address from EEPROM */ sMyAddr = eeprom_read_byte((const uint8_t *)MODUL_ADDRESS); for (i = 0; i < NUM_BUTTON_EVENT_ADDRESSES; i++) { sMySwitchAddr[i] = eeprom_read_byte((const uint8_t *)(BUTTON_EVENT_ADRESS_BASE + i)); } PortInit(); TimerInit(); SioInit(); SioRandSeed(MY_ADDR); sioHandle = SioOpen("USART0", eSioBaud9600, eSioDataBits8, eSioParityNo, eSioStopBits1, eSioModeHalfDuplex); SioSetIdleFunc(sioHandle, IdleSio); SioSetTransceiverPowerDownFunc(sioHandle, BusTransceiverPowerDown); BusTransceiverPowerDown(true); BusInit(sioHandle); spRxBusMsg = BusMsgBufGet(); /* enable global interrupts */ ENABLE_INT; i2c_slave(SLAVE_ADRESSE); button_register = 0; init_BJ(SLAVE_ADRESSE); for (i = 0; i < NR_OF_LEDS; i++) { u8 = eeprom_read_byte((const uint8_t *)(COLOR_LED_BASE + i)); set_LED(i, u8); sNewLedData[i / 2] |= (u8 & 0x0f) << ((i % 2) ? 4 : 0); } i2c_slave(SLAVE_ADRESSE); SendStartupMsg(); while (1) { Idle(); if (send_startup == 1) { init_BJ(SLAVE_ADRESSE); for (i = 0; i < NR_OF_LEDS; i++) { set_LED(i, eeprom_read_byte((const uint8_t *)(COLOR_LED_BASE + i))); } } sInputState = button_register; ProcessButton(sInputState); ProcessBus(); for (i = 0; i < BUS_SW16_LED_SIZE_SET_VALUE; i++) { if ((sNewLedData[i] & 0x0f) != (sLedData[i] & 0x0f) ) { // linke LED set_LED(i * 2, sNewLedData[i] & 0x0f); i2c_slave(SLAVE_ADRESSE); } if ((sNewLedData[i] & 0xf0) != (sLedData[i] & 0xf0) ) { // rechte LED set_LED(i * 2 + 1, (sNewLedData[i] & 0xf0) >> 4); i2c_slave(SLAVE_ADRESSE); } sLedData[i] = sNewLedData[i]; } }
void init_wdt(void) { MCUSR = 0; wdt_disable(); }
int main(void) { CanMessage tmp; /* Local Variables */ #if ( TERMINAL == 1 ) UART_Init(); /* UART */ ADC_Init(); /* ADC */ #endif GPIO_Init(); /* GPIO */ ExtINT_Init(); /* External Interrupt */ Timer_Init(); /* Timers */ SPI_Init(); /* SPI */ CanStatus res = CAN_Init(CAN_SPEED); /* Start CAN */ #if ( TERMINAL == 1 ) term_Start(res); /* Start Terminal */ #endif Msg_Init(); /* Construct Messages to be sent */ CAN_BufInit( &RxBuffer, CAN_RX_BUFFER_SIZE ); /* Initialize Receive Buffer */ CAN_BufInit( &TxBuffer, CAN_TX_BUFFER_SIZE ); /* Initialize Transmit Buffer */ sei(); /* Enable Global Interrupts */ /* ---------------------------*/ while(1){ wdt_enable(WDTO_1S); /* Enable Watchdog Timer for 2 second */ /* ------------------------------------------ */ /* Send Messages */ // Get Data ATOMIC_BLOCK( ATOMIC_FORCEON ){ if( CAN_BufState( &TxBuffer ) != BUFFER_EMPTY ){/* Check if empty */ CAN_BufDeq( &TxBuffer, &tmp ); /* Dequeue */ CAN_SendMsg( &tmp ); /* Send */ } } /* ------------------------------------------ */ /* Receive Messages */ ATOMIC_BLOCK( ATOMIC_FORCEON ){ /* Read Interrupt variables */ if( CAN_BufState( &RxBuffer ) != BUFFER_EMPTY ){/* Check if not empty */ CAN_BufDeq( &RxBuffer, &tmp ); /* Dequeue */ Msg_Chk( &tmp ); /* Check Received Message */ #if ( TERMINAL == 1 ) if( strm == MS_STREAM ) /* Enable Terminal Message Stream */ term_RxMsg( &tmp ); #endif } } /* ------------------------------------------ */ #if ( TERMINAL == 1 ) term_Main(); /* TERMINAL FOR DEBUGGING */ #endif } wdt_reset(); /* Reset Watchdog */ wdt_disable(); return 0; }
int main(void) { // Make sure our watchdog timer is disabled! wdt_reset(); MCUSR &= ~(1 << WDRF); wdt_disable(); // Start up the USART for serial communications // 25 corresponds to 38400 baud - see datasheet for more values USART_Init(25);// 103 corresponds to 9600, 8 corresponds to 115200 baud, 3 for 250000 // set the prescale for the USB for our 16 MHz clock CPU_PRESCALE(0); // Initialize our USB connection usb_init(); while (!usb_configured()){ LEDon(TXLED); _delay_ms(50); LEDoff(TXLED); _delay_ms(50); } // wait // Wait an extra second for the PC's operating system to load drivers // and do whatever it does to actually be ready for input // This wait also gives the Arduino bootloader time to timeout, // so the serial data you'll be properly aligned. _delay_ms(500); dataForController_t dataToSend; char buttonData1; char buttonData2; char buttonData3; while (1) { // Delay so we're not going too fast _delay_ms(10); // We get our data from the ATmega328p by writing which byte we // want from the dataForController_t, and then wait for the // ATmega328p to send that back to us. // The serialRead(number) function reads the serial port, and the // number is a timeout (in ms) so if there's a transmission error, // we don't stall forever. LEDon(TXLED); flushSerialRead(); serialWrite(0); buttonData1 = serialRead(25); serialWrite(1); buttonData2 = serialRead(25); serialWrite(2); buttonData3 = serialRead(25); serialWrite(3); dataToSend.leftStickX = serialRead(25); serialWrite(4); dataToSend.leftStickY = serialRead(25); serialWrite(5); dataToSend.rightStickX = serialRead(25); serialWrite(6); dataToSend.rightStickY= serialRead(25); serialWrite(7); dataToSend.centerStickX = serialRead(25); serialWrite(8); dataToSend.centerStickY= serialRead(25); LEDoff(TXLED); // Now, we take the button data we got in and input that information // into our controller data we want to send dataToSend.triangleOn = 1 & (buttonData1 >> 0); dataToSend.circleOn = 1 & (buttonData1 >> 1); dataToSend.squareOn = 1 & (buttonData1 >> 2); dataToSend.crossOn = 1 & (buttonData1 >> 3); dataToSend.l1On = 1 & (buttonData1 >> 4); dataToSend.l2On = 1 & (buttonData1 >> 5); dataToSend.l3On = 1 & (buttonData1 >> 6); dataToSend.r1On = 1 & (buttonData1 >> 7); dataToSend.r2On = 1 & (buttonData2 >> 0); dataToSend.r3On = 1 & (buttonData2 >> 1); dataToSend.selectOn = 1 & (buttonData2 >> 2); dataToSend.startOn = 1 & (buttonData2 >> 3); dataToSend.homeOn = 1 & (buttonData2 >> 4); dataToSend.dpadLeftOn = 1 & (buttonData2 >> 5); dataToSend.dpadUpOn = 1 & (buttonData2 >> 6); dataToSend.dpadRightOn = 1 & (buttonData2 >> 7); dataToSend.dpadDownOn = 1 & (buttonData3 >> 0); // Finally, we send the data out via the USB port sendPS3Data(dataToSend); } }
void _watchdogDefaultSetup (void) { wdt_disable (WDT); }
void watchdogDisable(void) { wdt_disable (WDT); }
void board_init(void) { #ifndef CONF_BOARD_KEEP_WATCHDOG_AT_INIT struct wdt_dev_inst wdt_inst; struct wdt_config wdt_cfg; wdt_get_config_defaults(&wdt_cfg); wdt_init(&wdt_inst, WDT, &wdt_cfg); wdt_disable(&wdt_inst); #endif /* Initialize IOPORT */ ioport_init(); /* Initialize LED0, turned off */ ioport_set_pin_dir(LED_0_PIN, IOPORT_DIR_OUTPUT); ioport_set_pin_level(LED_0_PIN, IOPORT_PIN_LEVEL_HIGH); /* Initialize SW0 */ ioport_set_pin_dir(BUTTON_0_PIN, IOPORT_DIR_INPUT); ioport_set_pin_mode(BUTTON_0_PIN, IOPORT_MODE_PULLUP); #ifdef CONF_BOARD_EIC /* Set push button as external interrupt pin */ ioport_set_pin_peripheral_mode(BUTTON_0_EIC_PIN, BUTTON_0_EIC_PIN_MUX | IOPORT_MODE_PULLUP); #else /* Push button as input: already done, it's the default pin state */ #endif #if (defined CONF_BOARD_BL) // Configure LCD backlight ioport_set_pin_dir(LCD_BL_GPIO, IOPORT_DIR_OUTPUT); ioport_set_pin_level(LCD_BL_GPIO, LCD_BL_INACTIVE_LEVEL); #endif #if defined (CONF_BOARD_COM_PORT) ioport_set_pin_peripheral_mode(COM_PORT_RX_PIN, COM_PORT_RX_MUX); ioport_set_pin_peripheral_mode(COM_PORT_TX_PIN, COM_PORT_TX_MUX); #endif #ifdef CONF_BOARD_TWIMS0 ioport_set_pin_peripheral_mode(PIN_PA23B_TWIMS0_TWD, MUX_PA23B_TWIMS0_TWD); ioport_set_pin_peripheral_mode(PIN_PA24B_TWIMS0_TWCK, MUX_PA24B_TWIMS0_TWCK); #endif #ifdef CONF_BOARD_TWIMS3 ioport_set_pin_peripheral_mode(PIN_PB14C_TWIMS3_TWD, MUX_PB14C_TWIMS3_TWD); ioport_set_pin_peripheral_mode(PIN_PB15C_TWIMS3_TWCK, MUX_PB15C_TWIMS3_TWCK); #endif #ifdef CONF_BOARD_USART0 ioport_set_pin_peripheral_mode(EXT1_PIN_UART_RX, EXT1_UART_RX_MUX); ioport_set_pin_peripheral_mode(EXT1_PIN_UART_TX, EXT1_UART_TX_MUX); #endif #if (defined CONF_BOARD_USB_PORT) ioport_set_pin_peripheral_mode(PIN_PA25A_USBC_DM, MUX_PA25A_USBC_DM); ioport_set_pin_peripheral_mode(PIN_PA26A_USBC_DP, MUX_PA26A_USBC_DP); # if defined(CONF_BOARD_USB_VBUS_DETECT) ioport_set_pin_dir(USB_VBUS_PIN, IOPORT_DIR_INPUT); # endif # if defined(CONF_BOARD_USB_ID_DETECT) ioport_set_pin_dir(USB_ID_PIN, IOPORT_DIR_INPUT); # endif # if defined(CONF_BOARD_USB_VBUS_CONTROL) ioport_set_pin_dir(USB_VBOF_PIN, IOPORT_DIR_OUTPUT); ioport_set_pin_level(USB_VBOF_PIN, USB_VBOF_INACTIVE_LEVEL); # endif #endif #ifdef CONF_BOARD_AT86RFX ioport_set_pin_peripheral_mode(AT86RFX_SPI_MISO, AT86RFX_SPI_MISO_FLAGS); ioport_set_pin_peripheral_mode(AT86RFX_SPI_MOSI, AT86RFX_SPI_MOSI_FLAGS); ioport_set_pin_peripheral_mode(AT86RFX_SPI_SCK, AT86RFX_SPI_SCK_FLAGS); ioport_set_pin_peripheral_mode(AT86RFX_SPI_CS_PIN, AT86RFX_SPI_CS_FLAGS); /* Initialize TRX_RST and SLP_TR as GPIO. */ ioport_set_pin_dir(AT86RFX_RST_PIN, IOPORT_DIR_OUTPUT); ioport_set_pin_level(AT86RFX_RST_PIN, IOPORT_PIN_LEVEL_HIGH); ioport_set_pin_dir(AT86RFX_SLP_PIN, IOPORT_DIR_OUTPUT); ioport_set_pin_level(AT86RFX_SLP_PIN, IOPORT_PIN_LEVEL_HIGH); #ifdef EXT_RF_FRONT_END_CTRL ioport_set_pin_dir(AT86RFX_CPS, IOPORT_DIR_OUTPUT); ioport_set_pin_level(AT86RFX_CPS, IOPORT_PIN_LEVEL_HIGH); ioport_set_pin_dir(AT86RFX_CSD, IOPORT_DIR_OUTPUT); ioport_set_pin_level(AT86RFX_CSD, IOPORT_PIN_LEVEL_HIGH); #endif #endif #if defined(CONF_BOARD_SPI) || defined(CONF_BOARD_SD_MMC_SPI) ioport_set_pin_peripheral_mode(PIN_PA21A_SPI_MISO, MUX_PA21A_SPI_MISO); ioport_set_pin_peripheral_mode(PIN_PA22A_SPI_MOSI, MUX_PA22A_SPI_MOSI); ioport_set_pin_peripheral_mode(PIN_PC30B_SPI_SCK, MUX_PC30B_SPI_SCK); #ifdef CONF_BOARD_SD_MMC_SPI /* Setting SD detection pin */ ioport_set_pin_dir(SD_MMC_0_CD_GPIO, IOPORT_DIR_INPUT); ioport_set_pin_mode(SD_MMC_0_CD_GPIO, IOPORT_MODE_PULLUP); /* Setting SD CS pin */ ioport_set_pin_peripheral_mode(SPI_NPCS0_GPIO, SPI_NPCS0_FLAGS); #endif #ifdef CONF_BOARD_SPI_NPCS0 ioport_set_pin_peripheral_mode(PIN_PC03A_SPI_NPCS0, MUX_PC03A_SPI_NPCS0); #endif #ifdef CONF_BOARD_SPI_NPCS1 ioport_set_pin_peripheral_mode(PIN_PB13B_SPI_NPCS1, MUX_PB13B_SPI_NPCS1); #endif #ifdef CONF_BOARD_SPI_NPCS2 ioport_set_pin_peripheral_mode(PIN_PB11B_SPI_NPCS2, MUX_PB11B_SPI_NPCS2); #endif #endif #ifdef CONF_BOARD_DACC_VOUT ioport_set_pin_peripheral_mode(DACC_VOUT_PIN, DACC_VOUT_MUX); #endif #ifdef CONF_BOARD_ACIFC ioport_set_pin_peripheral_mode(PIN_PA06E_ACIFC_ACAN0, MUX_PA06E_ACIFC_ACAN0); ioport_set_pin_peripheral_mode(PIN_PA07E_ACIFC_ACAP0, MUX_PA07E_ACIFC_ACAP0); #endif #ifdef CONF_BOARD_PARC ioport_set_pin_peripheral_mode(PIN_PA17D_PARC_PCCK, MUX_PA17D_PARC_PCCK); ioport_set_pin_peripheral_mode(PIN_PA09D_PARC_PCDATA0, MUX_PA09D_PARC_PCDATA0); ioport_set_pin_peripheral_mode(PIN_PA10D_PARC_PCDATA1, MUX_PA10D_PARC_PCDATA1); ioport_set_pin_peripheral_mode(PIN_PA11D_PARC_PCDATA2, MUX_PA11D_PARC_PCDATA2); ioport_set_pin_peripheral_mode(PIN_PA12D_PARC_PCDATA3, MUX_PA12D_PARC_PCDATA3); ioport_set_pin_peripheral_mode(PIN_PA13D_PARC_PCDATA4, MUX_PA13D_PARC_PCDATA4); ioport_set_pin_peripheral_mode(PIN_PA14D_PARC_PCDATA5, MUX_PA14D_PARC_PCDATA5); ioport_set_pin_peripheral_mode(PIN_PA15D_PARC_PCDATA6, MUX_PA15D_PARC_PCDATA6); ioport_set_pin_peripheral_mode(PIN_PA16D_PARC_PCDATA7, MUX_PA16D_PARC_PCDATA7); ioport_set_pin_peripheral_mode(PIN_PA18D_PARC_PCEN1, MUX_PA18D_PARC_PCEN1); ioport_set_pin_peripheral_mode(PIN_PA19D_PARC_PCEN2, MUX_PA19D_PARC_PCEN2); #endif #ifdef CONF_BOARD_OLED_UG_2832HSWEG04 ioport_set_pin_dir(UG_2832HSWEG04_DATA_CMD_GPIO, IOPORT_DIR_OUTPUT); ioport_set_pin_mode(UG_2832HSWEG04_DATA_CMD_GPIO, IOPORT_MODE_PULLUP); ioport_set_pin_dir(UG_2832HSWEG04_RESET_GPIO, IOPORT_DIR_OUTPUT); ioport_set_pin_mode(UG_2832HSWEG04_RESET_GPIO, IOPORT_MODE_PULLUP); #endif }
/** Special startup routine to check if the bootloader was started via a watchdog reset, and if the magic application * start key has been loaded into \ref MagicBootKey. If the bootloader started via the watchdog and the key is valid, * this will force the user application to start via a software jump. */ void Application_Jump_Check(void) { bool JumpToApplication = false; #if (BOARD == BOARD_LEONARDO) /* Enable pull-up on the IO13 pin so we can use it to select the mode */ PORTC |= (1 << 7); Delay_MS(10); /* If IO13 is not jumpered to ground, start the user application instead */ JumpToApplication = ((PINC & (1 << 7)) != 0); /* Disable pull-up after the check has completed */ PORTC &= ~(1 << 7); #elif ((BOARD == BOARD_XPLAIN) || (BOARD == BOARD_XPLAIN_REV1)) /* Disable JTAG debugging */ JTAG_DISABLE(); /* Enable pull-up on the JTAG TCK pin so we can use it to select the mode */ PORTF |= (1 << 4); Delay_MS(10); /* If the TCK pin is not jumpered to ground, start the user application instead */ JumpToApplication = ((PINF & (1 << 4)) != 0); /* Re-enable JTAG debugging */ JTAG_ENABLE(); #else /* Check if the device's BOOTRST fuse is set */ if (boot_lock_fuse_bits_get(GET_HIGH_FUSE_BITS) & FUSE_BOOTRST) { /* If the reset source was not an external reset or the key is correct, clear it and jump to the application */ if (!(MCUSR & (1 << EXTRF)) || (MagicBootKey == MAGIC_BOOT_KEY)) JumpToApplication = true; /* Clear reset source */ MCUSR &= ~(1 << EXTRF); } else { /* If the reset source was the bootloader and the key is correct, clear it and jump to the application; * this can happen in the HWBE fuse is set, and the HBE pin is low during the watchdog reset */ if ((MCUSR & (1 << WDRF)) && (MagicBootKey == MAGIC_BOOT_KEY)) JumpToApplication = true; /* Clear reset source */ MCUSR &= ~(1 << WDRF); } #endif /* Don't run the user application if the reset vector is blank (no app loaded) */ bool ApplicationValid = (pgm_read_word_near(0) != 0xFFFF); /* If a request has been made to jump to the user application, honor it */ if (JumpToApplication && ApplicationValid) { /* Turn off the watchdog */ MCUSR &= ~(1 << WDRF); wdt_disable(); /* Clear the boot key and jump to the user application */ MagicBootKey = 0; // cppcheck-suppress constStatement ((void (*)(void))0x0000)(); } }
int main(void) { wdt_disable(); #ifdef CSMV4 LED_ON_DDR |= _BV( LED_ON_PIN ); LED_ON_PORT |= _BV( LED_ON_PIN ); #endif led_init(); LED_ON(); spi_init(); // eeprom_factory_reset("xx"); eeprom_init(); // led_mode = 2; // if we had been restarted by watchdog check the REQ BootLoader byte in the // EEPROM ... // if(bit_is_set(MCUSR,WDRF) && eeprom_read_byte(EE_REQBL)) { // eeprom_write_byte( EE_REQBL, 0 ); // clear flag // start_bootloader(); // } // Setup the timers. Are needed for watchdog-reset #ifdef HAS_IRRX ir_init(); // IR uses highspeed TIMER0 for sampling OCR0A = 1; // Timer0: 0.008s = 8MHz/256/2 == 15625Hz #else OCR0A = 249; // Timer0: 0.008s = 8MHz/256/250 == 125Hz #endif TCCR0B = _BV(CS02); TCCR0A = _BV(WGM01); TIMSK0 = _BV(OCIE0A); TCCR1A = 0; TCCR1B = _BV(CS11) | _BV(WGM12); // Timer1: 1us = 8MHz/8 clock_prescale_set(clock_div_1); MCUSR &= ~(1 << WDRF); // Enable the watchdog wdt_enable(WDTO_2S); uart_init( UART_BAUD_SELECT_DOUBLE_SPEED(UART_BAUD_RATE,F_CPU) ); #ifdef HAS_DOGM dogm_init(); #endif fht_init(); tx_init(); input_handle_func = analyze_ttydata; display_channel = DISPLAY_USB; #ifdef HAS_RF_ROUTER rf_router_init(); display_channel |= DISPLAY_RFROUTER; #endif #ifdef HAS_DOGM display_channel |= DISPLAY_DOGM; #endif LED_OFF(); sei(); for(;;) { uart_task(); RfAnalyze_Task(); Minute_Task(); #ifdef HAS_FASTRF FastRF_Task(); #endif #ifdef HAS_RF_ROUTER rf_router_task(); #endif #ifdef HAS_ASKSIN rf_asksin_task(); #endif #ifdef HAS_MORITZ rf_moritz_task(); #endif #ifdef HAS_IRRX ir_task(); #endif } }
void get_mcusr(void) { MCUSR = 0; wdt_disable(); }
static int wdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) { void __user *argp = (void __user *)arg; int __user *p = argp; int new_timeout; static struct watchdog_info ident = { .options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE, .firmware_version = 1, .identity = "W83697HF WDT", }; switch (cmd) { case WDIOC_GETSUPPORT: if (copy_to_user(argp, &ident, sizeof(ident))) return -EFAULT; break; case WDIOC_GETSTATUS: case WDIOC_GETBOOTSTATUS: return put_user(0, p); case WDIOC_KEEPALIVE: wdt_ping(); break; case WDIOC_SETTIMEOUT: if (get_user(new_timeout, p)) return -EFAULT; if (wdt_set_heartbeat(new_timeout)) return -EINVAL; wdt_ping(); /* Fall */ case WDIOC_GETTIMEOUT: return put_user(timeout, p); case WDIOC_SETOPTIONS: { int options, retval = -EINVAL; if (get_user(options, p)) return -EFAULT; if (options & WDIOS_DISABLECARD) { wdt_disable(); retval = 0; } if (options & WDIOS_ENABLECARD) { wdt_enable(); retval = 0; } return retval; } default: return -ENOTTY; } return 0; } static int wdt_open(struct inode *inode, struct file *file) { if (test_and_set_bit(0, &wdt_is_open)) return -EBUSY; /* * Activate */ wdt_enable(); return nonseekable_open(inode, file); } static int wdt_close(struct inode *inode, struct file *file) { if (expect_close == 42) { wdt_disable(); } else { printk (KERN_CRIT PFX "Unexpected close, not stopping watchdog!\n"); wdt_ping(); } expect_close = 0; clear_bit(0, &wdt_is_open); return 0; } /* * Notifier for system down */ static int wdt_notify_sys(struct notifier_block *this, unsigned long code, void *unused) { if (code == SYS_DOWN || code == SYS_HALT) { /* Turn the WDT off */ wdt_disable(); } return NOTIFY_DONE; } /* * Kernel Interfaces */ static const struct file_operations wdt_fops = { .owner = THIS_MODULE, .llseek = no_llseek, .write = wdt_write, .ioctl = wdt_ioctl, .open = wdt_open, .release = wdt_close, }; static struct miscdevice wdt_miscdev = { .minor = WATCHDOG_MINOR, .name = "watchdog", .fops = &wdt_fops, }; /* * The WDT needs to learn about soft shutdowns in order to * turn the timebomb registers off. */ static struct notifier_block wdt_notifier = { .notifier_call = wdt_notify_sys, }; static int w83697hf_check_wdt(void) { if (!request_region(wdt_io, 2, WATCHDOG_NAME)) { printk (KERN_ERR PFX "I/O address 0x%x already in use\n", wdt_io); return -EIO; } printk (KERN_DEBUG PFX "Looking for watchdog at address 0x%x\n", wdt_io); w83697hf_unlock(); if (w83697hf_get_reg(0x20) == 0x60) { printk (KERN_INFO PFX "watchdog found at address 0x%x\n", wdt_io); w83697hf_lock(); return 0; } w83697hf_lock(); /* Reprotect in case it was a compatible device */ printk (KERN_INFO PFX "watchdog not found at address 0x%x\n", wdt_io); release_region(wdt_io, 2); return -EIO; } static int w83697hf_ioports[] = { 0x2e, 0x4e, 0x00 }; static int __init wdt_init(void) { int ret, i, found = 0; spin_lock_init(&io_lock); printk (KERN_INFO PFX "WDT driver for W83697HF/HG initializing\n"); if (wdt_io == 0) { /* we will autodetect the W83697HF/HG watchdog */ for (i = 0; ((!found) && (w83697hf_ioports[i] != 0)); i++) { wdt_io = w83697hf_ioports[i]; if (!w83697hf_check_wdt()) found++; } } else { if (!w83697hf_check_wdt()) found++; } if (!found) { printk (KERN_ERR PFX "No W83697HF/HG could be found\n"); ret = -EIO; goto out; } w83697hf_init(); wdt_disable(); /* Disable watchdog until first use */ if (wdt_set_heartbeat(timeout)) { wdt_set_heartbeat(WATCHDOG_TIMEOUT); printk (KERN_INFO PFX "timeout value must be 1<=timeout<=255, using %d\n", WATCHDOG_TIMEOUT); } ret = register_reboot_notifier(&wdt_notifier); if (ret != 0) { printk (KERN_ERR PFX "cannot register reboot notifier (err=%d)\n", ret); goto unreg_regions; } ret = misc_register(&wdt_miscdev); if (ret != 0) { printk (KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n", WATCHDOG_MINOR, ret); goto unreg_reboot; } printk (KERN_INFO PFX "initialized. timeout=%d sec (nowayout=%d)\n", timeout, nowayout); out: return ret; unreg_reboot: unregister_reboot_notifier(&wdt_notifier); unreg_regions: release_region(wdt_io, 2); goto out; } static void __exit wdt_exit(void) { misc_deregister(&wdt_miscdev); unregister_reboot_notifier(&wdt_notifier); release_region(wdt_io, 2); }
int main(void) { // Disable watchdog reset timer to prevent continious resets wdt_disable(); MCUSR = 0; can_start = 0; uint8_t status; arm_coordinate current_position; servo_init(); bus_init(BUS_ADDRESS_ARM); bus_register_receive(0, emergency_handler); bus_register_receive(1, control_claw); bus_register_receive(2, object_pickup); bus_register_receive(3, object_pickup); bus_register_receive(4, object_pickup); bus_register_receive(5, object_pickup); bus_register_receive(6, manual_target); bus_register_receive(7, manual_target); bus_register_receive(8, manual_target); bus_register_receive(9, manual_target); bus_register_receive(10, manual_target); bus_register_receive(11, update_manual_control); bus_register_receive(12, object_return); bus_register_receive(13, predefined_positions); // Wait for communication unit to say we can continue initialising /*while (!can_start) { // Delay is needed when looping flags such as this _delay_us(1); }*/ // Wait for servos to power on before setting initial parameters _delay_ms(100); arm_init(); _delay_ms(1000); // Make sure claw is open and arm is in a well defined state arm_claw_open(); arm_resting_position(); // XXX: Trick system into thinking we have reached a pickup station //while (bus_transmit(BUS_ADDRESS_SENSOR, 9, 1)); //object_side = LEFT; for (;;) { if (object_grab) { status = arm_move_to_coordinate(object_position); switch (status) { case 0: // Save position for when dropping off object last_object_position = object_position; // Perform movement to coordinate arm_move_perform_block(); // Wait for arm to stabilize _delay_ms(500); // Grip object and return to resting position if (arm_claw_close()) { display(0, "Picked object"); arm_resting_position(); has_object = 1; // Send command that arm picked up object to chassis while (bus_transmit(BUS_ADDRESS_CHASSIS, 2, 0)); } else { display(0, "Failed pickup"); arm_resting_position(); arm_claw_open(); has_object = 0; // Send command that no object was picked up object to chassis while (bus_transmit(BUS_ADDRESS_CHASSIS, 2, 2)); } break; case 1: display(0, "Invalid coordinate"); break; case 2: display(0, "No P found"); break; default: display(0, "Error %u", status); } object_grab = 0; } else if (object_drop_off) { // Move to the position where object was picked up status = arm_move_to_coordinate(last_object_position); switch (status) { case 0: // Perform movement to coordinate arm_move_perform_block(); // Wait for arm to stabilize _delay_ms(500); // Leave object and return to resting position if (arm_claw_open()) { display(0, "Left object"); arm_resting_position(); has_object = 0; } else { display(0, "Left no object"); arm_resting_position(); has_object = 1; } // Send command that arm is done to chassis while (bus_transmit(BUS_ADDRESS_CHASSIS, 2, 1)); break; case 1: display(0, "Invalid coordinate"); break; case 2: display(0, "No P found"); break; default: display(0, "Error %u", status); } object_drop_off = 0; } else if (has_manual_target) { display(1, "%d,%d,%d", manual_target_position.x, manual_target_position.y, (uint16_t)(manual_target_position.angle * 1000)); status = arm_move_to_coordinate(manual_target_position); if (status) { display(0, "Error %u", status); } else { arm_move_perform_block(); } has_manual_target = 0; } else if (manual_control_state) { // Update reference position when we start manual movement if (manual_control_state == 2) { arm_position(&manual_control_reference); manual_control_state = 1; } manual_control_reference.x += manual_control_change.x; manual_control_reference.y += manual_control_change.y; manual_control_reference.angle += manual_control_change.angle; if (!arm_move_to_coordinate(manual_control_reference)) { //arm_move_perform_block(); arm_move_perform(); _delay_ms(100); } } else if (manual_control_claw) { if (manual_control_claw == 1) { display(0, "Claw close"); arm_claw_close(); } else { display(0, "Claw open"); arm_claw_open(); } manual_control_claw = 0; } else if (predefined_position_move) { switch (predefined_position_move) { case 1: arm_resting_position(); break; } predefined_position_move = 0; } } }
int main() { cli(); wdt_disable(); // To make sure nothing weird happens init_tlc5940(); init_spi(); init_ps(); init_blank_timer(); init_effect_timer(); init_playlist(); initUSART(); sei(); hcsr04_start_continuous_meas(); adc_start(); serial_boot_report(); // Select correct startup mode pick_startup_mode(); while(1) { /* Serial processing is implementation specific and defined in * serial_common.c */ process_serial(); switch (mode) { case MODE_SLEEP: // Fall through to MODE_IDLE case MODE_IDLE: // No operation sleep_if_no_traffic(); break; case MODE_PLAYLIST: ticks = centisecs(); if (ticks > effect_length) { next_effect(); init_current_effect(); } // no need to break! // fall to MODE_EFFECT on purpose case MODE_EFFECT: // If a buffer is not yet flipped, wait interrupts if (flags.may_flip) { sleep_if_no_traffic(); break; } // Update clock ticks = centisecs(); /* Go back to serial handler if drawing time * is reached. By doing this we avoid serial * port slowdown when FPS is low */ if (ticks < next_draw_at ) { sleep_if_no_traffic(); break; } /* Restart effect if maximum ticks is * reached. This may result a glitch but is * better than the effect to stop. */ if (ticks == ~0) { init_current_effect(); ticks = 0; } // Update sensor values sensors.distance1 = hcsr04_get_distance_in_cm(); sensors.distance2 = hcsr04_get_distance_in_cm(); //TODO: use separate sensor sensors.ambient_light = adc_get(0) >> 2; sensors.sound_pressure_level = adc_get(1) >> 2; // Do the actual drawing draw_t draw = (draw_t)pgm_get(effect->draw,word); if (draw != NULL) { draw(); allow_flipping(true); } // Update time when next drawing is allowed next_draw_at = ticks + pgm_get(effect->minimum_ticks,byte); break; } } return 0; }
void watchdog_stop() { wdt_disable(); }
void get_mcucsr(void) { mcucsr_mirror = MCUCSR; MCUCSR = 0; wdt_disable(); }
// //----------------------------------------------------------------------------------------- // Setup Ports, timers, start the works and never return, unless reset // by the watchdog timer // then - do everything, all over again //----------------------------------------------------------------------------------------- // int main(void) { MCUSR &= ~(1 << WDRF); // Disable watchdog if enabled by bootloader/fuses wdt_disable(); clock_prescale_set(clock_div_1); // with 16MHz crystal this means CLK=16000000 //------------------------------------------ // 16-bit Timer1 Initialization TCCR1A = 0; //start the timer TCCR1B = (1 << CS12); // prescale Timer1 by CLK/256 // 16000000 Hz / 256 = 62500 ticks per second // 16-bit = 2^16 = 65536 maximum ticks for Timer1 // 65536 / 62500 = ~1.05 seconds // so Timer1 will overflow back to 0 about every 1 seconds // Timer1val = TCNT1; // get current Timer1 value //------------------------------------------ // Init and set output for LEDS LED_DDR = LED; LED_PORT = 0; EXTLED_DDR = EXT_G_LED | EXT_R_LED; // Init Green and Red LEDs EXTLED_PORT = 0; //------------------------------------------ // Init Pushbutton input ENC_PUSHB_DDR = ENC_PUSHB_DDR & ~ENC_PUSHB_PIN; // Set pin for input ENC_PUSHB_PORT= ENC_PUSHB_PORT | ENC_PUSHB_PIN; // Set pull up //------------------------------------------ // Set run time parameters to Factory default under certain conditions // // Enforce "Factory default settings" when firmware is run for the very first time after // a fresh firmware installation with a new "serial number" in the COLDSTART_REF #define // This may be necessary if there is garbage in the EEPROM, preventing startup // To activate, roll "COLDSTART_REF" Serial Number in the PM.h file if (eeprom_read_byte(&E.EEPROM_init_check) != R.EEPROM_init_check) { eeprom_write_block(&R, &E, sizeof(E)); // Initialize eeprom to "factory defaults". } else { eeprom_read_block(&R, &E, sizeof(E)); // Load the persistent data from eeprom } uint8_t i2c_status = I2C_Init(); // Initialize I2C comms lcd_Init(); // Init the LCD // Initialize the LCD bargraph, load the bargraph custom characters lcd_bargraph_Init(); //------------------------------------------ // LCD Print Version and I2C information (6 seconds in total during startup) lcdClear(); lcdGotoXY(0,0); lcdPrintData(STARTUPDISPLAY1,strlen(STARTUPDISPLAY1)); lcdGotoXY(0,1); lcdPrintData(STARTUPDISPLAY2,strlen(STARTUPDISPLAY2)); _delay_ms(300); lcdGotoXY(20-strlen(STARTUPDISPLAY3),1); lcdPrintData(STARTUPDISPLAY3,strlen(STARTUPDISPLAY3)); _delay_ms(200); lcdGotoXY(20-strlen(STARTUPDISPLAY4),2); lcdPrintData(STARTUPDISPLAY4,strlen(STARTUPDISPLAY4)); _delay_ms(2500); lcdGotoXY(0,3); lcdPrintData(STARTUPDISPLAY5,strlen(STARTUPDISPLAY5)); sprintf(lcd_buf,"V%s", VERSION); lcdGotoXY(20-strlen(lcd_buf),3); lcdPrintData(lcd_buf, strlen(lcd_buf)); _delay_ms(2000); lcdGotoXY(0,3); if (i2c_status==1) lcdPrintData("AD7991-0 detected ",20); else if (i2c_status==2) lcdPrintData("AD7991-1 detected ",20); else lcdPrintData("Using built-in A/D ",20); // No I2C device detected, // we will be using the builtin 10 bit ADs if (R.USB_data) // Enumerate USB serial port, if USB Serial Data enabled { usb_init(); // Initialize USB communications Status&=~USB_AVAILABLE; // Disable USB communications until checked if actually available } _delay_ms(1000); //wdt_enable(WDTO_1S); // Start the Watchdog Timer, 1 second encoder_Init(); // Init Rotary encoder Menu_Mode = DEFAULT_MODE; // Power Meter Mode is normal default Status |= MODE_CHANGE | MODE_DISPLAY; // Force a Display of Mode Intro when starting up // Start the works, we're in business while (1) { maintask(); // Do useful stuff if (R.USB_data) // Do the below if USB Port has been enabled { // If USB port is available and not busy, then use it - otherwise mark it as blocked. if (usb_configured() && (usb_serial_get_control() & USB_SERIAL_DTR)) { Status |= USB_AVAILABLE; // Enable USB communications EXTLED_PORT |= EXT_G_LED; // Turn Green LED On usb_read_serial(); } else { Status&=~USB_AVAILABLE; // Clear USB Available Flag to disable USB communications EXTLED_PORT &= ~EXT_G_LED; // Turn Green LED off, if previously on } } } }
void init_disable_watchdog() { MCUSR = 0; wdt_disable(); }
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(); } } }
static long stmp3xxx_wdt_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { void __user *argp = (void __user *)arg; int __user *p = argp; int new_heartbeat, opts; int ret = -ENOTTY; switch (cmd) { case WDIOC_GETSUPPORT: ret = copy_to_user(argp, &ident, sizeof(ident)) ? -EFAULT : 0; break; case WDIOC_GETSTATUS: ret = put_user(0, p); break; case WDIOC_GETBOOTSTATUS: ret = put_user(boot_status, p); break; case WDIOC_SETOPTIONS: if (get_user(opts, p)) { ret = -EFAULT; break; } if (opts & WDIOS_DISABLECARD) wdt_disable(); else if (opts & WDIOS_ENABLECARD) wdt_ping(); else { pr_debug("%s: unknown option 0x%x\n", __func__, opts); ret = -EINVAL; break; } ret = 0; break; case WDIOC_KEEPALIVE: wdt_ping(); ret = 0; break; case WDIOC_SETTIMEOUT: if (get_user(new_heartbeat, p)) { ret = -EFAULT; break; } if (new_heartbeat <= 0 || new_heartbeat > MAX_HEARTBEAT) { ret = -EINVAL; break; } heartbeat = new_heartbeat; wdt_ping(); /* */ case WDIOC_GETTIMEOUT: ret = put_user(heartbeat, p); break; } return ret; }
static uint8_t cmd_bot(char* extra_args, char* output, uint8_t output_len, uint8_t stream) { wdt_disable(); enter_bootloader(); return 0; }
int main(void) { // uint8_t i; uint8_t mcustate; // turn boost off TCCR0B = 0; BOOST_DDR |= _BV(BOOST); BOOST_PORT &= ~_BV(BOOST); // pull boost fet low // check if we were reset mcustate = MCUSR; MCUSR = 0; wdt_disable(); // now turn it back on... 2 second time out //WDTCSR |= _BV(WDP0) | _BV(WDP1) | _BV(WDP2); //WDTCSR = _BV(WDE); wdt_enable(WDTO_2S); kickthedog(); // we lost power at some point so lets alert the user // that the time may be wrong (the clock still works) timeunknown = 1; // have we read the time & date from eeprom? restored = 0; // setup uart uart_init(BRRL_192); //DEBUGP("VFD Clock"); DEBUGP("!"); //DEBUGP("turning on anacomp"); // set up analog comparator ACSR = _BV(ACBG) | _BV(ACIE); // use bandgap, intr. on toggle! // settle! if (ACSR & _BV(ACO)) { // hmm we should not interrupt here ACSR |= _BV(ACI); // even in low power mode, we run the clock DEBUGP("clock init"); clock_init(); } else { // we aren't in low power mode so init stuff // init io's initbuttons(); VFDSWITCH_PORT &= ~_BV(VFDSWITCH); DEBUGP("turning on buttons"); // set up button interrupts DEBUGP("turning on alarmsw"); // set off an interrupt if alarm is set or unset EICRA = _BV(ISC00); EIMSK = _BV(INT0); displaymode = SHOW_TIME; DEBUGP("vfd init"); vfd_init(); dimmer_init(); DEBUGP("boost init"); brightness_level = eeprom_read_byte((uint8_t *)EE_BRIGHT); boost_init(brightness_level); sei(); region = eeprom_read_byte((uint8_t *)EE_REGION); DEBUGP("speaker init"); speaker_init(); beep(4000, 1); DEBUGP("clock init"); clock_init(); DEBUGP("alarm init"); setalarmstate(); } DEBUGP("done"); while (1) { //_delay_ms(100); kickthedog(); //uart_putc_hex(ACSR); if (ACSR & _BV(ACO)) { // DEBUGP("SLEEPYTIME"); gotosleep(); continue; } //DEBUGP("."); if (just_pressed & 0x1) { just_pressed = 0; switch(displaymode) { case (SHOW_TIME): displaymode = SET_ALARM; display_str("set alarm"); set_alarm(); break; case (SET_ALARM): displaymode = SET_TIME; display_str("set time"); set_time(); timeunknown = 0; break; case (SET_TIME): displaymode = SET_DATE; display_str("set date"); set_date(); break; case (SET_DATE): displaymode = SET_BRIGHTNESS; display_str("set brit"); set_brightness(); break; case (SET_BRIGHTNESS): displaymode = SET_DIMMER; display_str("set dimr"); set_dimmer(); break; case (SET_DIMMER): displaymode = SET_VOLUME; display_str("set vol "); set_volume(); break; case (SET_VOLUME): displaymode = SET_REGION; display_str("set regn"); set_region(); break; /* case (SET_REGION): displaymode = SET_SNOOZE; display_str("set snoz"); set_snooze(); break; */ default: displaymode = SHOW_TIME; } } else if ((just_pressed & 0x2) || (just_pressed & 0x4)) { just_pressed = 0; displaymode = NONE; display_date(DAY); kickthedog(); delayms(1500); kickthedog(); displaymode = SHOW_TIME; } } }
void board_init(void) { #ifndef CONF_BOARD_KEEP_WATCHDOG_AT_INIT struct wdt_dev_inst wdt_inst; struct wdt_config wdt_cfg; wdt_get_config_defaults(&wdt_cfg); wdt_init(&wdt_inst, WDT, &wdt_cfg); wdt_disable(&wdt_inst); #endif // Initialize IOPORTs ioport_init(); // Put all pins to default state (input & pull-up) uint32_t pin; for (pin = PIN_PA00; pin <= PIN_PC31; pin ++) { // Skip output pins to configure later if (pin == LED0_GPIO || pin == LCD_BL_GPIO #ifdef CONF_BOARD_RS485 || pin == RS485_USART_CTS_PIN #endif /* PA02 is not configured as it is driven by hardware configuration */ || pin == PIN_PA02) { continue; } ioport_set_pin_dir(pin, IOPORT_DIR_INPUT); ioport_set_pin_mode(pin, IOPORT_MODE_PULLUP); } /* Configure the pins connected to LEDs as output and set their * default initial state to high (LEDs off). */ ioport_set_pin_dir(LED0_GPIO, IOPORT_DIR_OUTPUT); ioport_set_pin_level(LED0_GPIO, LED0_INACTIVE_LEVEL); #ifdef CONF_BOARD_EIC // Set push button as external interrupt pin ioport_set_pin_peripheral_mode(GPIO_PUSH_BUTTON_EIC_PIN, GPIO_PUSH_BUTTON_EIC_PIN_MUX); ioport_set_pin_peripheral_mode(GPIO_UNIT_TEST_EIC_PIN, GPIO_UNIT_TEST_EIC_PIN_MUX); #else // Push button as input: already done, it's the default pin state #endif #if (defined CONF_BOARD_BL) // Configure LCD backlight ioport_set_pin_dir(LCD_BL_GPIO, IOPORT_DIR_OUTPUT); ioport_set_pin_level(LCD_BL_GPIO, LCD_BL_INACTIVE_LEVEL); #endif #if (defined CONF_BOARD_USB_PORT) ioport_set_pin_peripheral_mode(PIN_PA25A_USBC_DM, MUX_PA25A_USBC_DM); ioport_set_pin_peripheral_mode(PIN_PA26A_USBC_DP, MUX_PA26A_USBC_DP); # if defined(CONF_BOARD_USB_VBUS_DETECT) # if defined(USB_VBUS_EIC) ioport_set_pin_peripheral_mode(USB_VBUS_EIC, USB_VBUS_EIC_MUX|USB_VBUS_FLAGS); # elif defined(USB_VBUS_PIN) ioport_set_pin_dir(USB_VBUS_PIN, IOPORT_DIR_INPUT); # else # warning USB_VBUS pin not defined # endif # endif # if defined(CONF_BOARD_USB_ID_DETECT) # if defined(USB_ID_EIC) ioport_set_pin_peripheral_mode(USB_ID_EIC, USB_ID_EIC_MUX|USB_ID_FLAGS); # elif defined(USB_ID_PIN) ioport_set_pin_dir(USB_ID_PIN, IOPORT_DIR_INPUT); # else # warning USB_ID pin not defined # endif # endif # if defined(CONF_BOARD_USB_VBUS_CONTROL) # if defined(USB_VBOF_PIN) ioport_set_pin_dir(USB_VBOF_PIN, IOPORT_DIR_OUTPUT); ioport_set_pin_level(USB_VBOF_PIN, USB_VBOF_INACTIVE_LEVEL); # else # warning USB_VBOF pin not defined # endif # if defined(CONF_BOARD_USB_VBUS_ERR_DETECT) # if defined(USB_VBERR_EIC) ioport_set_pin_peripheral_mode(USB_VBERR_EIC, USB_VBERR_EIC_MUX|USB_VBERR_FLAGS); # elif defined(USB_VBERR_PIN) ioport_set_pin_dir(USB_VBERR_PIN, IOPORT_DIR_INPUT); # else # warning USB_VBERR pin not defined # endif # endif # endif /* !(defined CONF_BOARD_USB_NO_VBUS_CONTROL) */ #endif /* (defined CONF_BOARD_USB_PORT) */ #if defined (CONF_BOARD_COM_PORT) ioport_set_pin_peripheral_mode(COM_PORT_RX_PIN, COM_PORT_RX_MUX); ioport_set_pin_peripheral_mode(COM_PORT_TX_PIN, COM_PORT_TX_MUX); #endif #if defined (CONF_BOARD_BM_USART) ioport_set_pin_peripheral_mode(BM_USART_RX_PIN, BM_USART_RX_MUX); ioport_set_pin_peripheral_mode(BM_USART_TX_PIN, BM_USART_TX_MUX); #endif #ifdef CONF_BOARD_SPI ioport_set_pin_peripheral_mode(PIN_PC04A_SPI_MISO, MUX_PC04A_SPI_MISO); ioport_set_pin_peripheral_mode(PIN_PC05A_SPI_MOSI, MUX_PC05A_SPI_MOSI); ioport_set_pin_peripheral_mode(PIN_PC06A_SPI_SCK, MUX_PC06A_SPI_SCK); #ifdef CONF_BOARD_SPI_NPCS0 ioport_set_pin_peripheral_mode(PIN_PA02B_SPI_NPCS0, MUX_PA02B_SPI_NPCS0); #endif #ifdef CONF_BOARD_SPI_NPCS2 ioport_set_pin_peripheral_mode(PIN_PC00A_SPI_NPCS2, MUX_PC00A_SPI_NPCS2); #endif #ifdef CONF_BOARD_SPI_NPCS3 ioport_set_pin_peripheral_mode(PIN_PC01A_SPI_NPCS3, MUX_PC01A_SPI_NPCS3); #endif #endif #ifdef CONF_BOARD_RS485 ioport_set_pin_peripheral_mode(RS485_USART_RX_PIN, RS485_USART_RX_MUX); ioport_set_pin_peripheral_mode(RS485_USART_TX_PIN, RS485_USART_TX_MUX); ioport_set_pin_peripheral_mode(RS485_USART_RTS_PIN, RS485_USART_RTS_MUX); ioport_set_pin_dir(RS485_USART_CTS_PIN, IOPORT_DIR_OUTPUT); ioport_set_pin_level(RS485_USART_CTS_PIN, IOPORT_PIN_LEVEL_LOW); #endif #ifdef CONF_BOARD_TWIMS1 ioport_set_pin_peripheral_mode(TWIMS1_TWI_SCL_PIN, TWIMS1_TWI_SCL_MUX); ioport_set_pin_peripheral_mode(TWIMS1_TWI_SDA_PIN, TWIMS1_TWI_SDA_MUX); #endif #ifdef CONF_BOARD_USART0 ioport_set_pin_peripheral_mode(USART0_RX_PIN, USART0_RX_MUX); ioport_set_pin_peripheral_mode(USART0_TX_PIN, USART0_TX_MUX); #endif #ifdef CONF_BOARD_DACC_VOUT ioport_set_pin_peripheral_mode(DACC_VOUT_PIN, DACC_VOUT_MUX); #endif #ifdef CONF_BOARD_ACIFC ioport_set_pin_peripheral_mode(PIN_PA06E_ACIFC_ACAN0, MUX_PA06E_ACIFC_ACAN0); ioport_set_pin_peripheral_mode(PIN_PA07E_ACIFC_ACAP0, MUX_PA07E_ACIFC_ACAP0); #endif #ifdef CONF_BOARD_ABDACB_PORT ioport_set_pin_peripheral_mode(ABDACB_AUDIO0_PIN, ABDACB_AUDIO0_MUX); ioport_set_pin_peripheral_mode(ABDACB_AUDIO1_PIN, ABDACB_AUDIO1_MUX); #endif }