/** * Initialize keyboard ports and softtimer */ void kbd_init(void) { #if CONFIG_KBD_BEEP MOD_CHECK(buzzer); #endif KBD_HW_INIT; /* Init handlers lists */ LIST_INIT(&kbd_handlers); LIST_INIT(&kbd_rawHandlers); /* Add debounce keyboard handler */ kbd_debHandler.hook = kbd_debHandlerFunc; kbd_debHandler.pri = 100; /* high priority */ kbd_debHandler.flags = KHF_RAWKEYS; kbd_addHandler(&kbd_debHandler); #if CONFIG_KBD_LONGPRESS /* Add long pression keyboard handler */ kbd_lngHandler.hook = kbd_lngHandlerFunc; kbd_lngHandler.pri = 90; /* high priority */ kbd_lngHandler.flags = KHF_RAWKEYS; kbd_addHandler(&kbd_lngHandler); #endif /* Add repeat keyboard handler */ kbd_rptHandler.hook = kbd_rptHandlerFunc; kbd_rptHandler.pri = 80; /* high priority */ kbd_rptHandler.flags = KHF_RAWKEYS; kbd_addHandler(&kbd_rptHandler); /* Add default keyboard handler */ kbd_defHandler.hook = kbd_defHandlerFunc; kbd_defHandler.pri = -128; /* lowest priority */ kbd_addHandler(&kbd_defHandler); #if CONFIG_KBD_OBSERVER observer_InitSubject(&kbd_subject); #endif #if CONFIG_KBD_POLL == KBD_POLL_SOFTINT MOD_CHECK(timer); /* Add kbd handler to soft timers list */ event_initSoftint(&kbd_timer.expire, kbd_softint, NULL); timer_setDelay(&kbd_timer, ms_to_ticks(KBD_CHECK_INTERVAL)); timer_add(&kbd_timer); #else #error "Define keyboard poll method" #endif MOD_INIT(kbd); }
/** * Init ADC hardware. */ void adc_hw_init(void) { /* * Select channel 0 as default, * result right adjusted. */ ADMUX = 0; #if CONFIG_ADC_AVR_REF == ADC_AVR_AREF /* External voltage at AREF as analog ref source */ /* None */ #elif CONFIG_ADC_AVR_REF == ADC_AVR_AVCC /* AVCC as analog ref source */ ADMUX |= BV(REFS0); #elif CONFIG_ADC_AVR_REF == ADC_AVR_INT256 /* Internal 2.56V as ref source */ ADMUX |= BV(REFS1) | BV(REFS0); #else #error Unsupported ADC ref value. #endif #if defined(ADCSRB) /* Disable Auto trigger source: ADC in Free running mode. */ ADCSRB = 0; #endif /* Enable ADC, disable autotrigger mode. */ ADCSRA = BV(ADEN); #if CONFIG_KERN MOD_CHECK(proc); ADCSRA |= BV(ADIE); #endif /* Set convertion frequency */ #if CONFIG_ADC_AVR_DIVISOR == 2 ADCSRA |= BV(ADPS0); #elif CONFIG_ADC_AVR_DIVISOR == 4 ADCSRA |= BV(ADPS1); #elif CONFIG_ADC_AVR_DIVISOR == 8 ADCSRA |= BV(ADPS1) | BV(ADPS0); #elif CONFIG_ADC_AVR_DIVISOR == 16 ADCSRA |= BV(ADPS2); #elif CONFIG_ADC_AVR_DIVISOR == 32 ADCSRA |= BV(ADPS2) | BV(ADPS0); #elif CONFIG_ADC_AVR_DIVISOR == 64 ADCSRA |= BV(ADPS2) | BV(ADPS1); #elif CONFIG_ADC_AVR_DIVISOR == 128 ADCSRA |= BV(ADPS2) | BV(ADPS1) | BV(ADPS0); #else #error Unsupported ADC prescaler value. #endif /* Start a convertion to init ADC hw */ adc_hw_read(); }
/* * Initialize a USB HID keyboard device. * * TODO: support more than one device at the same time. */ int usbkbd_init(UNUSED_ARG(int, unit)) { #if CONFIG_KERN MOD_CHECK(proc); #endif usb_keyboard_hw_init(); while (!hid_keyboard_configured) cpu_relax(); return 0; }
/* Low-level usb-serial device initialization */ static int usb_serial_hw_init(void) { #if CONFIG_KERN MOD_CHECK(proc); #endif if (usb_deviceRegister(&usb_serial) < 0) return -1; LOG_INFO("usb-serial: registered new USB interface driver\n"); return 0; }
/** * Setup all needed to test dataflash memory * */ int dataflash_testSetup(void) { kfile_testSetup(); LOG_INFO("KFILE setup..ok\n"); LOG_INFO("Check if kernel is enable (if enable you should see the assert message.)\n"); SILENT_ASSERT("bertos/drv/dataflash_test.c:119: Assertion failed: !CONFIG_KERN"); ASSERT(!CONFIG_KERN); /* * This test use a kfile_test module, * so should include source in your makefile. */ MOD_CHECK(kfile_test); timer_init(); LOG_INFO("Timer init..ok\n"); /* * Init SPI module and dataflash driver. */ // Open SPI comunication channel spimaster_init(&spi_fd, 0); LOG_INFO("SPI0 init..ok\n"); ser_setbaudrate(&spi_fd, 5000000UL); LOG_INFO("SPI0 set baudrate..ok\n"); //Init dataflash memory dataflash_hw_init(); LOG_INFO("DATAFLASH HW..ok\n"); if (dataflash_init(&dflash_fd, &spi_fd.fd, DATAFLASH_MEM_MODEL, DATAFLASH_FUNC_CS_SET, DATAFLASH_FUNC_RESET)) LOG_INFO("DATAFLASH init..ok\n"); else LOG_ERR("DATAFLASH init..fail\n"); //Fill tmp buffer with rand chars. for (int i = 0; i < DATAFLASH_TEST_STR_LEN; i++) { #if DATAFLASH_USE_RAND_FUNC #include <stdlib.h> //Rand() test_buf[i] = (uint8_t)rand(); #else test_buf[i] = (i & 0xff); #endif } LOG_INFO("Fill tmp buff..ok\n"); return 0; }
void CDemoMFCDlg::OnCheckAndThrow() { OnFailingCheck("\nThis will throw an exception"); try { int a = 5; MOD_CHECK(rbEQUAL(10, a), throw 1); MessageBox("Error: no exception thrown!!"); } catch (int) { MessageBox("Exception was thrown"); } }
void timer_hw_init(void) { sysirq_init(); cpu_flags_t flags; MOD_CHECK(sysirq); IRQ_SAVE_DISABLE(flags); PIT_MR = TIMER_HW_CNT; /* Register system interrupt handler. */ sysirq_setHandler(SYSIRQ_PIT, timer_handler); /* Enable interval timer and interval timer interrupts */ PIT_MR |= BV(PITEN); sysirq_setEnable(SYSIRQ_PIT, true); /* Reset counters, this is needed to start timer and interrupt flags */ uint32_t dummy = PIVR; (void) dummy; IRQ_RESTORE(flags); }
/** * Init a PCF8574 on the bus with addr \a addr. * \return true if device is found, false otherwise. */ bool pcf8574_init(Pcf8574 *pcf, pcf8574_addr addr) { MOD_CHECK(i2c); pcf->addr = addr; return pcf8574_get(pcf) != EOF; }