main (int argc, char **argv) { int id; setvbuf (stdout, NULL, _IOLBF, 0); printf ("%s: starting...\n", progname); // request I/O privity ThreadCtl(_NTO_TCTL_IO, 0 ); // set up an event for the handler or the kernel to use to wake up // this thread. Use whatever type of event and event handling you want SIGEV_INTR_INIT( &int_event ); // either register an interrupt handler or the event id = InterruptAttach(0, hdlr, NULL, 0, _NTO_INTR_FLAGS_TRK_MSK ); while (1) { // block here waiting for the event InterruptWait(0, NULL ); // if using a high frequency interrupt, don't print every interrupt printf ("%s: we got an event after 1500 timer ticks and unblocked\n", progname); } }
static err_t gpio_init(Drive_Gpio *t) { Drive_Gpio *cthis = ( Drive_Gpio *)t ; uint32_t tmp_reg = 0; gpio_cfg *config = cthis->config; int i = 0; assert( config->intr_line < 2); cthis->gpio_vbase = mmap_device_io( AM335X_GPIO_SIZE, GpioBase[ config->pin_group]); #ifdef DEBUG_GPIO TRACE_INFO("Drive Piling :%s-%s-%d \r\n", __FILE__, __func__, __LINE__); TRACE_INFO("pin config 0x%04x \r\n", rd_pin_conf( config->pin_ctrl_off)); return EXIT_SUCCESS; #else if (cthis->gpio_vbase == MAP_DEVICE_FAILED) { return ERROR_T( gpio_init_mapio_fail); } gpioModuleConfig[ config->pin_group](); GPIOModuleEnable( cthis->gpio_vbase); //配置引脚方向为输入 tmp_reg = in32( cthis->gpio_vbase + GPIO_OE ); tmp_reg |= 1 << config->pin_number; out32( cthis->gpio_vbase + GPIO_OE, tmp_reg ); //使能消抖 tmp_reg=in32( cthis->gpio_vbase + GPIO_DEBOUNCENABLE); tmp_reg &=~( 1 << config->pin_number); tmp_reg |= ( 1 << config->pin_number); out32( cthis->gpio_vbase + GPIO_DEBOUNCENABLE, tmp_reg); //消抖时间 out32( cthis->gpio_vbase + GPIO_DEBOUNCINGTIME, ( config->debou_time )); //配置中断监测类型 for( i = 0; i < 4; i ++) { if( ( ( 1 << i) & config->intr_type) ) { //使能该类型 tmp_reg = in32( cthis->gpio_vbase + GPIO_DETECT(i)); tmp_reg |= 1 << config->pin_number; out32(cthis->gpio_vbase + GPIO_DETECT(i), tmp_reg); } else { //禁止其他类型 tmp_reg = in32( cthis->gpio_vbase + GPIO_DETECT(i)); tmp_reg &= ~(1 << config->pin_number); out32(cthis->gpio_vbase + GPIO_DETECT(i), tmp_reg); } } //使能引脚中断 // tmp_reg = in32( cthis->gpio_vbase + GPIO_IRQSTATUS_SET( config->intr_line)); // tmp_reg |= 1 << config->pin_number; // out32(cthis->gpio_vbase + GPIO_IRQSTATUS_SET( config->intr_line), tmp_reg); #ifdef DEBUG_GPIO dump_gpio_reg( cthis->gpio_vbase); #endif SIGEV_INTR_INIT( &cthis->isr_event ); cthis->irq_id = InterruptAttach_r ( GpioIntNum[ config->intr_line][ config->pin_group], gpioExtInteIsr, cthis, 1, _NTO_INTR_FLAGS_END ); return EXIT_SUCCESS; #endif }