void board_init() { gpio_init(); clock_init(); antenna_init(); antenna_external(); leds_init(); debugpins_init(); button_init(); bsp_timer_init(); radiotimer_init(); uart_init(); radio_init(); i2c_init(); }
void jtag_init(void) { gpio_init(); writel(BASE_CLK_SEL(CLK_PLL1), BASE_PERIPH_CLK); spin(1000); // configure for SGPIO_OUT/OEN control writel(CFG_OUT_GPIO | CFG_OE_GPIO, SGPIO_OUT_CFG(POS_TDO)); writel(CFG_OUT_GPIO | CFG_OE_GPIO, SGPIO_OUT_CFG(POS_TCK)); writel(CFG_OUT_GPIO | CFG_OE_GPIO, SGPIO_OUT_CFG(POS_TDI)); writel(CFG_OUT_GPIO | CFG_OE_GPIO, SGPIO_OUT_CFG(POS_TMS)); // TCK=0 TDI=0 TMS=0 TDO=input writel(0, SGPIO_OUT); writel(BIT_TCK | BIT_TDI | BIT_TMS, SGPIO_OEN); }
int main(void) { char c; clock_init(); /* 初始化时钟 */ gpio_init(); while (1) { PH_DAT = 0x0fff0000; delay(100000); PH_DAT = 0x0000ffff; delay(100000); } return 0; }
int main() { int time = 0; gpio_state state = LOW; int touch = 1; gpio_init(); /**************** insert your code here ******************/ set_gpio_state(state); /*********************************************************/ }
void *timer_func(void *arg) { LOG_DEBUG("run thread %" PRIkernel_pid "\n", thread_getpid()); #if defined(WORKER_THREAD_PIN_1) && defined(WORKER_THREAD_PIN_2) gpio_init((*(timer_arg_t *)(arg)).pin, GPIO_OUT); #endif while (1) { #if defined(WORKER_THREAD_PIN_1) && defined(WORKER_THREAD_PIN_2) gpio_set((*(timer_arg_t *)(arg)).pin); gpio_clear((*(timer_arg_t *)(arg)).pin); #endif xtimer_usleep(*(uint32_t *)(arg)); } }
static void on_bus_acquired(GDBusConnection *connection, const gchar *name, gpointer user_data) { ObjectSkeleton *object; //g_print ("Acquired a message bus connection: %s\n",name); manager = g_dbus_object_manager_server_new(dbus_object_path); gchar *s; s = g_strdup_printf("%s/%s",dbus_object_path,instance_name); object = object_skeleton_new(s); g_free(s); Button* button = button_skeleton_new(); object_skeleton_set_button(object, button); g_object_unref(button); //define method callbacks g_signal_connect(button, "handle-is-on", G_CALLBACK(on_is_on), NULL); /* user_data */ g_signal_connect(button, "handle-sim-press", G_CALLBACK(on_button_press), NULL); /* user_data */ /* Export the object (@manager takes its own reference to @object) */ g_dbus_object_manager_server_set_connection(manager, connection); g_dbus_object_manager_server_export(manager, G_DBUS_OBJECT_SKELETON(object)); g_object_unref(object); // get gpio device paths int rc = GPIO_OK; do { rc = gpio_init(connection,&gpio_button); if(rc != GPIO_OK) { break; } rc = gpio_open_interrupt(&gpio_button,on_button_interrupt,object); if(rc != GPIO_OK) { break; } } while(0); if(rc != GPIO_OK) { printf("ERROR PowerButton: GPIO setup (rc=%d)\n",rc); } }
int adc_init(adc_t line) { if (line >= ADC_NUMOF) { DEBUG("adc_init: invalid ADC line (%d)!\n", line); return -1; } cc2538_soc_adc_t *adca = SOC_ADC; /* stop random number generator, and set STSEL = 1 */ adca->cc2538_adc_adccon1.ADCCON1 = 0x3c; /* disable any DMA, continous ADC settings */ adca->ADCCON2 = 0x0; /* configure ADC GPIO as analog input */ gpio_init(adc_config[line], GPIO_IN_ANALOG); return 0; }
//---------------------------------------------------------------------- // board early init routine void board_early_init(void) { #if 0 #define CS2 (32*0+23) __gpio_as_output(CS2); while(1) { int i; __gpio_set_pin(CS2); i=480000; while(i--); __gpio_clear_pin(CS2); i=480000; while(i--); } #endif gpio_init(); }
int main(void) { qm_rtc_config_t rtc_cfg; unsigned int count = 0; /* Maximum number of 3-second iterations. */ const unsigned int loop_max = 5; gpio_init(); gpio_set_out(BOARD_LED_PIN, 0); /* Configure the onboard LED pin. */ /* Clear Screen. */ QM_PUTS("Starting: Power Profiler"); QM_PUTS("Low power mode example."); QM_PRINTF("Increment = %d\n", QM_RTC_ALARM_SECOND(CLK_RTC_DIV_1)); clk_periph_enable(CLK_PERIPH_RTC_REGISTER | CLK_PERIPH_CLK); /* Initialise RTC configuration: Run, but don't interrupt. */ rtc_cfg.init_val = 0; rtc_cfg.alarm_en = 0; rtc_cfg.alarm_val = QM_RTC_ALARM_SECOND(CLK_RTC_DIV_1); rtc_cfg.callback = rtc_example_callback; rtc_cfg.prescaler = CLK_RTC_DIV_1; qm_rtc_set_config(QM_RTC_0, &rtc_cfg); qm_irq_request(QM_IRQ_RTC_0_INT, qm_rtc_0_isr); test_clock_rates(); /* Enable the RTC Interrupt. */ rtc_cfg.alarm_en = 1; qm_rtc_set_config(QM_RTC_0, &rtc_cfg); count = 0; while (++count < loop_max) { QM_PRINTF("\nC:%d R:%d => ", count, rtc_tick); slow_mode_test(); halt_test(); sleep_test(); #if DEEP_SLEEP deep_sleep_test(); #endif } QM_PUTS("Finished: Power Profiler"); return 0; }
int main(void) { CPU_INT08U os_err; NVIC_Configuration( ); gpio_init( ) ; uart1_init( ); //console port rtc_init(); ADCTEMP_Configuration( ); /* Enable CRC clock */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_CRC, ENABLE); led_init_all( ); led_on(POWER_LED); //GSM_PM_ON; //while ( 1 ) ;//for upgrade GSM fw GSM_PM_OFF; GPS_PM_OFF; CAN_PM_OFF; /* Initialize "uC/OS-II, The Real-Time Kernel". */ OSInit(); //include: OSTime = 0L; os_err = OSTaskCreateExt((void (*)(void *)) app_task_manager, /* Create the start task.*/ (void * ) 0, (OS_STK * )&app_task_manager_stk[APP_TASK_MANAGER_STK_SIZE - 1], (INT8U ) APP_TASK_MANAGER_PRIO, (INT16U ) APP_TASK_MANAGER_PRIO, (OS_STK * )&app_task_manager_stk[0], (INT32U ) APP_TASK_MANAGER_STK_SIZE, (void * ) 0, (INT16U )(OS_TASK_OPT_STK_CLR | OS_TASK_OPT_STK_CHK)); #if (OS_TASK_NAME_SIZE >= 11) OSTaskNameSet(APP_TASK_MANAGER_PRIO, (CPU_INT08U *)"Start Task", &os_err); #endif OSStart(); /* Start multitasking (i.e. give control to uC/OS-II). */ return (0); }
void auto_init_gpio(void) { for (unsigned int i = 0; i < SAUL_GPIO_NUMOF; i++) { const saul_gpio_params_t *p = &saul_gpio_params[i]; LOG_DEBUG("[auto_init_saul] initializing GPIO #%u\n", i); saul_gpios[i] = p->pin; saul_reg_entries[i].dev = &(saul_gpios[i]); saul_reg_entries[i].name = p->name; saul_reg_entries[i].driver = &gpio_saul_driver; /* initialize the GPIO pin */ gpio_init(p->pin, p->mode); /* add to registry */ saul_reg_add(&(saul_reg_entries[i])); } }
int main(void){ twi_master_init(); init_sensor(); ble_stack_init(); timers_init(); gpio_init(); gap_params_init(); services_init(); advertising_init(); conn_params_init(); sec_params_init(); advertising_start(); while(true){ power_manage(); } }
int main(void) { #if defined(MAIN_THREAD_PIN) gpio_t main_pin = MAIN_THREAD_PIN; gpio_init(main_pin, GPIO_OUT); #endif #if defined(WORKER_THREAD_PIN_1) && defined(WORKER_THREAD_PIN_2) timer_arg_t sleep_timer1 = { TEST_SLEEP_TIME_1, WORKER_THREAD_PIN_1 }; timer_arg_t sleep_timer2 = { TEST_SLEEP_TIME_2, WORKER_THREAD_PIN_2 }; #else uint32_t sleep_timer1 = TEST_SLEEP_TIME_1; uint32_t sleep_timer2 = TEST_SLEEP_TIME_2; #endif LOG_DEBUG("[INIT]\n"); thread_create(stack_timer1, TEST_TIMER_STACKSIZE, 2, THREAD_CREATE_STACKTEST, timer_func, &sleep_timer1, "timer1"); thread_create(stack_timer2, TEST_TIMER_STACKSIZE, 3, THREAD_CREATE_STACKTEST, timer_func, &sleep_timer2, "timer2"); uint32_t now = 0; uint32_t start = xtimer_now_usec(); uint32_t until = start + (TEST_TIME_S * US_PER_SEC); uint32_t interval = TEST_INTERVAL_MS * US_PER_MS; xtimer_ticks32_t last_wakeup = xtimer_now(); puts("[START]"); while ((now = xtimer_now_usec()) < until) { unsigned percent = (100 * (now - start)) / (until - start); #if defined(MAIN_THREAD_PIN) gpio_set(main_pin); #endif xtimer_periodic_wakeup(&last_wakeup, interval); #if defined(MAIN_THREAD_PIN) gpio_clear(main_pin); #endif printf("Testing (%3u%%)\n", percent); } puts("Testing (100%)"); puts("[SUCCESS]"); return 0; }
int main(void){ //whether to blink LED2 uint8_t blink=1; //temporally UART data holder uint8_t byte=0; //initialize system SystemInit(); //initialize UART5 with 8-N-1 settings, 57600 baudrate init_uart(UART5_BASE_PTR,periph_clk_khz,57600); //clear all interrupts and enable interrupts nvic->ICPR[2] |= 1 << (87 & 0x1F); //Clear Pending Interrupts nvic->ISER[2] |= 1 << (87 & 0x1F); //Enable Interrupts //initialize GPIO ports gpio_init(); //Loop forever while(true) { //use polling method to echo back data when available if(data_available()){ byte = uart_read(); if(byte==0xD) puts((uint8_t *)"\r\n"); //send new line character else if ((byte >= 0x30)&&(byte <= 0x39)){ byte = byte - (0x30); //Evaluate the hexadecimal that has been sent from terminal 0-9 display(byte); //Display function is written in the gpio.h } else if ((byte >= 0x41)&&(byte <= 0x46)){ byte = byte - (0x37); //Evaluate the hexadecimal sent from terminal Uppercase letters A-F display(byte); } else if ((byte >= 0x61)&&(byte <= 0x66)){ byte = byte - (0x57); //Evaluate hexadecimal sent Lowercase letters a-f display(byte); } else{ display(byte); //Show nothing Hopefully } delay(); } } }
void user_init(void) { uart_init(BIT_RATE_115200, BIT_RATE_250000); os_delay_us(1000000); memset(dmx_channels, 127, TWINKL_CHANNEL_COUNT); gpio_init(); twinkl_init(); os_timer_disarm(&dmx_update_timer); os_timer_setfn(&dmx_update_timer, (os_timer_func_t *)dmx_update, NULL); system_os_task(dmx_task, DMX_TASK_PRIO, dmx_task_queue, DMX_TASK_QUEUE_LENGTH); WIFI_Connect(wifi_ssid, wifi_password, wifiConnectCb); }
static void sleep_50ms(void) { struct timespec rem, req = { .tv_sec = 0, .tv_nsec = 50000000 }; while (nanosleep(&req, &rem)) req = rem; } static int reset(void) { if (gpio_init(GPIO_21) < 0 || gpio_set_direction(GPIO_21, GPIO_OUTPUT) < 0) return -1; if (gpio_set_value(GPIO_21, 0) < 0) return -1; sleep_50ms(); if (gpio_set_value(GPIO_21, 1) < 0) return -1; sleep_50ms(); sleep_50ms(); return 0; } int attiny88_enable(void) { uint8_t pixels[64*3]; /* Reset Atmel Chip otherwise it hangs the I2C bus. */ if (reset() < 0) { fprintf(stderr, "attiny88: Failed to reset chip.\n"); return -1; } /* Switch off LED's */ memset(pixels, 0, sizeof(pixels)); return attiny88_set_leds_state(pixels); }
int adt7310_init(adt7310_t *dev, spi_t spi, gpio_t cs) { int status; uint8_t reg = 0; /* write device descriptor */ dev->spi = spi; dev->cs = cs; dev->initialized = false; dev->high_res = false; /* CS */ gpio_init(dev->cs, GPIO_DIR_OUT, GPIO_NOPULL); gpio_set(dev->cs); #if ENABLE_DEBUG for (int i = 0; i < 8; ++i) { uint16_t dbg_reg = 0; status = adt7310_read_reg(dev, i, sizeof(dbg_reg), (uint8_t *)&dbg_reg); if (status != 0) { printf("Error reading address 0x%02x", i); } dbg_reg = HTONS(dbg_reg); printf("%02x: %04" PRIx16 "\n", i, dbg_reg); } #endif /* Read ID register from device */ status = adt7310_read_reg(dev, ADT7310_REG_ID, ADT7310_REG_SIZE_ID, ®); if (status != 0) { /* SPI bus error */ return -1; } if ((reg & ADT7310_REG_ID_MASK_MANUFACTURER_ID) != ADT7310_EXPECTED_MANUF_ID) { /* Wrong part ID */ return -2; } /* Set a configuration, go to shut down mode to save power until the sensor is needed. */ if (adt7310_set_config(dev, ADT7310_MODE_SHUTDOWN) != 0) { /* communication error */ return -3; } dev->initialized = true; return 0; }
int main(int argc, char *argv[]) { int i; gpio_init(); for(i = 7; i < 12; i++) { gpio_inout(i, E_GPIO_OUT); } for(i = 7; i < 12; i++) { gpio_write(i, 1); sleep(1); gpio_write(i, 0); } return 0; }
int main() { NVIC_Configuration(); //中断优先级分组 delay_init(); // usart_init(9600); // puts("初始化完成"); gpio_init(); while(1) { // led1 = !led1; // delay_ms(250); } }
int nvram_spi_init(nvram_t *dev, nvram_spi_params_t *spi_params, size_t size) { dev->size = size; if (size > 0x100 && spi_params->address_count == 1) { dev->write = nvram_spi_write_9bit_addr; dev->read = nvram_spi_read_9bit_addr; } else { dev->write = nvram_spi_write; dev->read = nvram_spi_read; } dev->extra = spi_params; gpio_init(spi_params->cs, GPIO_OUT); gpio_set(spi_params->cs); return 0; }
int main(void) { // There are a lot of dependencies in the order of these inits. // Don't change the ordering unless you understand this. // Inits can assume that all memory has been zeroed by either // a hardware reset or a watchdog timer reset. cli(); // system and drivers sys_init(); // system hardware setup - must be first rtc_init(); // real time counter xio_init(); // xmega io subsystem sig_init(); // signal flags st_init(); // stepper subsystem - must precede gpio_init() gpio_init(); // switches and parallel IO pwm_init(); // pulse width modulation drivers - must follow gpio_init() // application structures tg_init(STD_INPUT); // tinyg controller (controller.c) - must be first app init; reqs xio_init() cfg_init(); // config records from eeprom - must be next app init mp_init(); // motion planning subsystem cm_init(); // canonical machine - must follow cfg_init() sp_init(); // spindle PWM and variables // now bring up the interupts and get started PMIC_SetVectorLocationToApplication(); // as opposed to boot ROM PMIC_EnableHighLevel(); // all levels are used, so don't bother to abstract them PMIC_EnableMediumLevel(); PMIC_EnableLowLevel(); sei(); // enable global interrupts rpt_print_system_ready_message();// (LAST) announce system is ready _unit_tests(); // run any unit tests that are enabled tg_canned_startup(); // run any pre-loaded commands while (true) { // if (tg.network == NET_MASTER) { // tg_repeater(); // } else if (tg.network == NET_SLAVE) { // tg_receiver(); // } else { tg_controller(); // NET_STANDALONE // } } }
/***************************************************************************//** * @brief main *******************************************************************************/ int main(void) { ad7768_dev *dev; gpio_device gpio_dev; adc_core core; ad7768_setup(&dev, default_init_param); /* Configure HDL */ gpio_set_direction(&dev->gpio_dev, GPIO_UP_FORMAT_1, GPIO_OUT); gpio_set_value(&dev->gpio_dev, GPIO_UP_FORMAT_1, 0); gpio_set_direction(&dev->gpio_dev, GPIO_UP_FORMAT_0, GPIO_OUT); gpio_set_value(&dev->gpio_dev, GPIO_UP_FORMAT_0, 0); gpio_set_direction(&dev->gpio_dev, GPIO_UP_CRC_ENABLE, GPIO_OUT); gpio_set_value(&dev->gpio_dev, GPIO_UP_CRC_ENABLE, dev->crc_sel ? 1 : 0); gpio_set_direction(&dev->gpio_dev, GPIO_UP_CRC_4_OR_16_N, GPIO_OUT); gpio_set_value(&dev->gpio_dev, GPIO_UP_CRC_4_OR_16_N, dev->crc_sel == AD7768_CRC_4 ? 1 : 0); gpio_dev.type = AXI_GPIO; gpio_dev.device_id = XPAR_AD7768_GPIO_DEVICE_ID; gpio_init(&gpio_dev); ad7768_evb_clear_status(&gpio_dev); if (ad7768_evb_verify_status(&gpio_dev)) printf("Interface errors\n"); else printf("Interface OK\n"); core.dmac_baseaddr = AD7768_DMA_BASEADDR; core.no_of_channels = 8; core.resolution = 24; printf("Capture samples...\n"); adc_capture(core, 1024, ADC_DDR_BASEADDR); printf("Capture done\n"); if (ad7768_evb_verify_status(&gpio_dev)) printf("Interface errors\n"); else printf("Interface OK\n"); return 0; }
int main(void) { //configure trigger GPIO nrf_gpio_cfg_output(TRIGGER_GPIO_PIN_NO); nrf_gpio_pin_clear(TRIGGER_GPIO_PIN_NO); nrf_gpio_cfg_output(12); nrf_gpio_pin_clear(12); //prepare led GPIO by setting its GPIO to output nrf_gpio_cfg_output(LED_GPIO_NO); //configure UART (38400, 8N1, appropriate ports) uart_config(TX_PIN_NO, RX_PIN_NO); dbg_setDebugFct(uart_putstring_nonl); dbg_debugModule("Starting...\n"); //initialize TOF measurement timer timer1_init(); //initialize TOF GPIO gpio_init(); //initialize HFCLK for radio (TimeToEdge uses it as well, but configures elsewhere) //hfclkInit(); BTNS_INIT(1, gbtnsDataPtr); //init buttons handling btns_addGpioteBtn(gbtnsDataPtr, TD_BTN_S1_IO_NO, TD_BTN_S1_IO_CHANNEL, termdev_priv_btnPress, gbtnsDataPtr); // btns_addGpioteBtn(gbtnsDataPtr, TD_BTN_S2_IO_NO, TD_BTN_S2_IO_CHANNEL, termdev_priv_btnPress, gbtnsDataPtr); __enable_irq(); dbg_debugModule("Started.\n"); uint32_t counter = 0; while (1 == 1) { if (0 != timer_delay_ready) { timer_delay_ready = 0; dbg_debugModule("STOPPED: TOF: %d\n", timer_delay); } } return 0; }
void board_init(void) { /* initialize the CPU */ cpu_init(); /* initialize the board's LED */ gpio_init(LED0_PIN, GPIO_OUT); LED0_OFF; /* disable bootloader's USB */ RCC->APB1ENR &= ~RCC_APB1ENR_USBEN; /* disable bootloader's TIMER update interrupt */ TIM2->DIER &= ~(TIM_DIER_UIE); /* remap USART1 to PB7 and PB6 */ AFIO->MAPR |= AFIO_MAPR_USART1_REMAP; }
void machine_init(struct fnode * dev) { # if CONFIG_SYS_CLOCK == 216000000 rcc_clock_setup_hse_3v3(&hse_25mhz_3v3[CLOCK_3V3_216MHZ]); # else #error No valid clock speed selected for STM32F729 Discovery #endif #ifdef CONFIG_DEVGPIO gpio_init(dev, gpio_addrs, NUM_GPIOS); #endif #ifdef CONFIG_DEVUART uart_init(dev, uart_addrs, NUM_UARTS); #endif #ifdef CONFIG_RNG rng_init(dev, rng_addrs, NUM_RNGS); #endif }
/* * Disable all interrupts except GPIO interrupt 0, which is for pins 0-31. This * interrupt is IRQ 49, so bit 17 of the second register (BCM2835 ARM * Peripherals Manual, top of page 113). */ void kdriver_init() { gpio_init(); // Ensure all interrupts are disabled. PUT32(RPI_INT_DISABLE_1, 0xFFFFFFFF); PUT32(RPI_INT_DISABLE_2, 0xFFFFFFFF); // We'll be hooking up a button to Pin 23, so set it up appropriately. gpio_set_input(GPIO_PIN23); gpio_set_pullup(GPIO_PIN23); gpio_detect_falling_edge(GPIO_PIN23); // Enable GPIO interrupt 0 PUT32(RPI_INT_ENABLE_2, 0x00100000); // Enable interrupts system_enable_interrupts(); }
void tg_system_reset(void) { cli(); // These inits are order dependent: _tg_debug_init(); // (0) inits for the debug system sys_init(); // (1) system hardware setup xio_init(); // (2) xmega io subsystem tg_init(STD_INPUT); // (3) tinyg controller (arg is std devices) sig_init(); // (4) signal flags rtc_init(); // (5) real time counter st_init(); // (6) stepper subsystem (must run before gp_init()) gpio_init(); // (7) switches and parallel IO PMIC_EnableMediumLevel();// enable TX interrupts for init reporting sei(); // enable global interrupts cfg_init(); // (8) get config record from eeprom (reqs xio) tg_announce(); // print version string }
/** * * Main function that setups up GPIO and runs OS on zedboard * * * Parameters: * * @return void */ int main( void ) { /* initialize GPIOs */ gpio_init(); /* Start the GPIO task */ gpio_start(NULL); /* start the FreeRTOS scheduler * - will run all tasks * - should not terminate */ vTaskStartScheduler(); /* loop forever in case the scheduler terminates */ for( ;; ); }
/* * cpu irq handler */ void __init nxp_cpu_irq_init(void) { pr_debug("%s:%d\n", __func__, __LINE__); __gic_init(GIC_DIST_BASE, (void __iomem *)GIC_CPUI_BASE); gpio_init(GPIO_INT_BASE , IRQ_GPIO_START, GPIO_INT_MASK, 0); /* 64 ~ 223 (A,B,C,D,E) */ alive_init(ALIVE_INT_BASE, IRQ_ALIVE_START, ALIVE_INT_MASK, 0); /* 224 ~ 231 */ #ifdef CONFIG_FIQ init_FIQ(); #endif /* wake up source from idle */ irq_set_irq_wake(IRQ_PHY_CLKPWR_ALIVEIRQ + GIC_PHY_OFFSET, 1); #if PM_RTC_WAKE irq_set_irq_wake(IRQ_PHY_CLKPWR_RTCIRQ + GIC_PHY_OFFSET, 1); #endif }
void cycle11 (void) { if (do_cycle11 == 1) { // Set Halt set_halt_until_mbus_tx(); gpio_init(0xFFFF); // All Output gpio_write_data(0xF0F0); // 1111 0000 1111 0000 gpio_kill_bit(15); // 0111 0000 1111 0000 gpio_set_bit(1); // 0111 0000 1111 0010 gpio_set_2bits(11, 8); // 0111 1001 1111 0010 gpio_kill_bit(12); // 0110 1001 1111 0010 if (gpio_get_data() == 0xF2) {pass (0xC, gpio_get_data());} else {fail (0xC, gpio_get_data());} gpio_close(); } }