int main() { int i; int id1, id2; struct _pulse pulse; // Request I/O privileges ThreadCtl( _NTO_TCTL_IO, 0 ); chid = ChannelCreate( 0 ); coid = ConnectAttach( 0, 0, chid, _NTO_SIDE_CHANNEL, 0 ); SIGEV_PULSE_INIT( &event1, coid, getprio(0), MY_PULSE_CODE1, 0 ); id1=InterruptAttach( SYSPAGE_ENTRY(qtime)->intr, &handler1, NULL, 0, 0 ); SIGEV_PULSE_INIT( &event2, coid, getprio(0), MY_PULSE_CODE2, 0 ); id2=InterruptAttach( SYSPAGE_ENTRY(qtime)->intr, &handler2, NULL, 0, 0 ); for( i = 0; i < 10; ++i ) { // Wait for ISR to wake us up MsgReceivePulse( chid, &pulse, sizeof( pulse ), NULL ); if(pulse.code == MY_PULSE_CODE1) { printf( "1000 events\n" ); } else if(pulse.code == MY_PULSE_CODE2) { printf( "2500 events\n" ); } } // Disconnect the ISR handler InterruptDetach(id1); InterruptDetach(id2); return 0; }
void SensorHAL::initInterrupt() { //Create channel for pulse notification if ((chid = ChannelCreate(0)) == -1) { printf("SensorHAL: Error in ChannelCreate\n"); } //Connect to channel if ((coid = ConnectAttach(0, 0, chid, _NTO_SIDE_CHANNEL, 0)) == -1) { printf("SensorHAL: Error in ConnectAttach\n"); } //Initialisiere ein sigevent als Pulse SIGEV_PULSE_INIT(&event, coid, SIGEV_PULSE_PRIO_INHERIT, PULSE_FROM_ISR, 0); //Get rights if (-1 == ThreadCtl(_NTO_TCTL_IO, 0)) { printf("ThreadCtl access failed\n"); exit(EXIT_FAILURE); } //Init Port A, B, C, if HAl doesnt already out8(PORT_CTRL, DIO_INIT); //Enable IRQs for PortB and PortC out8(DIO_INTERRUPT_ENABLE_REG, DIO_INTERRUPT_ENABLE_BC); //Reset IRQs out8(DIO_INTERRUPT_CLEAR_REG, 0x00); //Registriere die Interrupt Service Routine if ((interruptId = InterruptAttach(DIO_IRQ, ISR, &event, sizeof(event), 0)) == -1) { printf("SensorHAL: Error in InterruptAttach\n"); } }
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); } }
int omap3_attach_intr(omap3_spi_t *omap3) { if ((omap3->chid = ChannelCreate(_NTO_CHF_DISCONNECT | _NTO_CHF_UNBLOCK)) == -1) return -1; if ((omap3->coid = ConnectAttach(0, 0, omap3->chid, _NTO_SIDE_CHANNEL, 0)) == -1) goto fail0; omap3->spievent.sigev_notify = SIGEV_PULSE; omap3->spievent.sigev_coid = omap3->coid; omap3->spievent.sigev_code = OMAP3_SPI_EVENT; omap3->spievent.sigev_priority = omap3->prio; /* * Attach SPI interrupt */ omap3->iid_spi = InterruptAttach(omap3->irq_spi, spi_intr, omap3, 0, _NTO_INTR_FLAGS_TRK_MSK); if (omap3->iid_spi != -1) return 0; ConnectDetach(omap3->coid); fail0: ChannelDestroy(omap3->chid); return -1; }
void main(void) { WD_STOP(); ClockConfig(16); ScheduleTimerInit(); HardwareInit(); // attach function to SW1 falling edge interrupt InterruptAttach(GPIO(SW1), QueueButton, FALLING); _EINT(); LPM0; }
void main(void) { WD_STOP(); ClockConfig(16); HardwareInit(); // Init the timer ScheduleTimerInit(); // register a function and define its period CallbackRegister(BlinkLed1, 100ul * _MILLISECOND); // attach function to SW1 falling edge interrupt InterruptAttach(GPIO(SW1),ToggleEnable,FALLING); _EINT(); LPM0; }
int main (int argc, char *argv[]) { int chid; int coid; my_msg_type msg; chid = ChannelCreate(); coid = Connect(SELF_PID, chid); void * zeroPtr = MapPhysical(0, 4096 * 4); zeroPtr = zeroPtr; int handler_id = InterruptAttach(coid, 4, NULL); for (;;) { int msgid; int num = MessageReceive(chid, &msgid, &msg, sizeof(msg)); if (msgid != 0) { MessageReply(msgid, ERROR_NO_SYS, NULL, 0); } else { // Pulse received switch (msg.async.type) { case PULSE_TYPE_INTERRUPT: { InterruptComplete(handler_id); break; } default: { *((char *)NULL) = '\0'; break; } } } num = num; } InterruptDetach(handler_id); return 0; }
/**************************************************************************** REMARKS: Function to execute a service at ring 0. This is done using the clock interrupt handler since the code we attach to it will always run at ring 0. ****************************************************************************/ static void CallRing0(void) { #ifdef __QNXNTO__ uint clock_intno = SYSPAGE_ENTRY(qtime)->intr; #else uint clock_intno = 0; /* clock irq */ #endif int intrid; #ifdef __QNXNTO__ mlock((void*)&_PM_R0, sizeof(_PM_R0)); ThreadCtl(_NTO_TCTL_IO, 0); #endif #ifdef __QNXNTO__ if ((intrid = InterruptAttach(_NTO_INTR_CLASS_EXTERNAL | clock_intno, _PM_ring0_isr, (void*)&_PM_R0, sizeof(_PM_R0), _NTO_INTR_FLAGS_END)) == -1) { #else if ((intrid = qnx_hint_attach(clock_intno, _PM_ring0_isr, FP_SEG(&_PM_R0))) == -1) { #endif perror("Attach"); exit(-1); } while (_PM_R0.service != -1) ; #ifdef __QNXNTO__ InterruptDetach(intrid); #else qnx_hint_detach(intrid); #endif } /**************************************************************************** REMARKS: Flush the translation lookaside buffer. ****************************************************************************/ void PMAPI PM_flushTLB(void) { _PM_R0.service = R0_FLUSH_TLB; CallRing0(); }
// // Clean up the device then add it to the interrupt list and enable it. // void ser_attach_intr(DEV_OMAP *dev) { uintptr_t *port = dev->port; // interrupt sources except transmit and modem status interrupt unsigned ier = OMAP_IER_RHR|OMAP_IER_LS; // According to the National bug sheet you must wait for the transmit // holding register to be empty. do { } while((read_omap(port[OMAP_UART_LSR]) & OMAP_LSR_TXRDY) == 0); clear_device(port); dev->iid = InterruptAttach(dev->intr, ser_intr, dev, 0, 0); // Enable modem status interrupt (default) if (!dev->no_msr_int) { ier |= OMAP_IER_MS; } // Enable interrupt sources. write_omap(port[OMAP_UART_IER], ier); }
inline int isr_setup(omapl1xx_context_t *omapl1xx) { int err; if ((omapl1xx->lcd_chid = ChannelCreate(_NTO_CHF_DISCONNECT | _NTO_CHF_UNBLOCK)) == -1) { return -1; } if ((omapl1xx->lcd_coid = ConnectAttach(0, 0, omapl1xx->lcd_chid, _NTO_SIDE_CHANNEL, 0)) == -1) { err = errno; goto fail; } SIGEV_PULSE_INIT(&omapl1xx->lcd_event, omapl1xx->lcd_coid, omapl1xx->adapter->pulseprio, OMAPL1xx_LCD_INTERRUPT_PULSE, 0); omapl1xx->lcd_iid = InterruptAttach(_NTO_INTR_CLASS_EXTERNAL | omapl1xx->irq, omapl1xx_lcd_isr, (void *)omapl1xx, sizeof(*omapl1xx), _NTO_INTR_FLAGS_END | _NTO_INTR_FLAGS_TRK_MSK | _NTO_INTR_FLAGS_PROCESS); if (omapl1xx->lcd_iid == -1) { err = errno; goto fail2; } return 0; fail2: ConnectDetach(omapl1xx->lcd_coid); fail: ChannelDestroy(omapl1xx->lcd_chid); errno = err; return -1; }
void Sensorik::initInterrupts() { // create channel to receive pulse messages from the ISR isr_Chid = ChannelCreate(0); if (isr_Chid == -1) { perror("SensorikIntro: ChannelCreate isrChid failed"); exit(EXIT_FAILURE); } isr_coid = ConnectAttach(0, 0, isr_Chid, _NTO_SIDE_CHANNEL, 0); if (isr_coid == -1) { perror("SensorikIntro: ConnectAttach isr_coid failed"); exit(EXIT_FAILURE); } // attach ISR SIGEV_PULSE_INIT(&event, isr_coid, SIGEV_PULSE_PRIO_INHERIT, 0, 0); //attach conection between handler to an interrupt source interruptId = InterruptAttach(11, ISR, &event, sizeof(event), 0); if (interruptId == -1) { perror("SensorikIntro: InterruptAttach failed"); exit(EXIT_FAILURE); } // configure interrupts // reset irq status register out8(D_IOBASE + OFFS_INT_STATUS, 0); // disable interrupts for all ports (Bit 0-5) uint8_t int_ctrl = in8(D_IOBASE + OFFS_INT_CTRL); out8(D_IOBASE + OFFS_INT_CTRL, int_ctrl | 0b00111111); // enable interrupt for portB und portC (Bit 1 und 2) (S. 18) int_ctrl = in8(D_IOBASE + OFFS_INT_CTRL); out8(D_IOBASE + OFFS_INT_CTRL, int_ctrl & ~(PB_CTRL | PC_CTRL)); // read out port B and C valies portBstatus = in8(DIO_B); portCstatus = in8(DIO_B); }
static Boolean getTime (ClockDriver *self, TimeInternal *time) { #ifdef __QNXNTO__ static TimerIntData tmpData; int ret; uint64_t delta; double tick_delay; uint64_t clock_offset; struct timespec tp; if(!tDataUpdated) { memset(&tData, 0, sizeof(TimerIntData)); if(ThreadCtl(_NTO_TCTL_IO, 0) == -1) { ERROR(THIS_COMPONENT"QNX: could not give process I/O privileges"); return FALSE; } tData.cps = SYSPAGE_ENTRY(qtime)->cycles_per_sec; tData.ns_per_tick = 1000000000.0 / tData.cps; tData.prev_tsc = ClockCycles(); clock_gettime(CLOCK_REALTIME, &tp); tData.last_clock = timespec2nsec(&tp); ret = InterruptAttach(0, timerIntHandler, &tData, sizeof(TimerIntData), _NTO_INTR_FLAGS_END | _NTO_INTR_FLAGS_TRK_MSK); if(ret == -1) { ERROR(THIS_COMPONENT"QNX: could not attach to timer interrupt"); return FALSE; } tDataUpdated = TRUE; time->seconds = tp.tv_sec; time->nanoseconds = tp.tv_nsec; return; } memcpy(&tmpData, &tData, sizeof(TimerIntData)); delta = ClockCycles() - tmpData.prev_tsc; /* compute time since last clock update */ tick_delay = (double)delta / (double)tmpData.filtered_delta; clock_offset = (uint64_t)(tick_delay * tmpData.ns_per_tick * (double)tmpData.filtered_delta); /* not filtered yet */ if(tData.counter < 2) { clock_offset = 0; } DBGV("QNX getTime cps: %lld tick interval: %.09f, time since last tick: %lld\n", tmpData.cps, tmpData.filtered_delta * tmpData.ns_per_tick, clock_offset); nsec2timespec(&tp, tmpData.last_clock + clock_offset); time->seconds = tp.tv_sec; time->nanoseconds = tp.tv_nsec; return TRUE; #else #if defined(_POSIX_TIMERS) && (_POSIX_TIMERS > 0) struct timespec tp; if (clock_gettime(CLOCK_REALTIME, &tp) < 0) { PERROR(THIS_COMPONENT"clock_gettime() failed, exiting."); exit(0); } time->seconds = tp.tv_sec; time->nanoseconds = tp.tv_nsec; #else struct timeval tv; gettimeofday(&tv, 0); time->seconds = tv.tv_sec; time->nanoseconds = tv.tv_usec * 1000; #endif /* _POSIX_TIMERS */ #endif /* __QNXNTO__ */ return TRUE; }
int main(int argc, char *argv[]) { uint32_t l; int id, id2; my_data_t msg; int rcvid; name_attach_t *name; printf("Welcome Onda\n"); if (ThreadCtl(_NTO_TCTL_IO, 0) < 0) { perror(NULL); return -1; } name = name_attach(NULL, "onda", NAME_FLAG_ATTACH_GLOBAL); if (name == NULL) { perror("Error0\n"); return -1; } /* attach GPIO interrupt */ id = InterruptAttach (33, gpio_isr_handler, NULL, 0, _NTO_INTR_FLAGS_PROCESS); /* attach timer interrupt */ id2 = InterruptAttach (45, timer_isr_handler, NULL, 0, _NTO_INTR_FLAGS_PROCESS); gpio5 = mmap_device_io(OMAP3530_GPIO_SIZE, OMAP3530_GPIO5_BASE); if (gpio5 == MAP_DEVICE_FAILED) { perror(NULL); return -1; } //gpt3 = mmap_device_io(OMAP3530_GPT_SIZE, OMAP3530_GPT3_BASE); gpt9 = mmap_device_io(OMAP3530_GPT_SIZE, OMAP3530_GPT9_BASE); if (gpt9 == MAP_DEVICE_FAILED) { perror(NULL); return -1; } sys = mmap_device_io(OMAP3530_SYSCTL_SIZE, OMAP3530_SYSCTL_BASE); if (sys == MAP_DEVICE_FAILED) { perror(NULL); return -1; } /* selecting mode 4 function - GPIO 139 * selecting pullup and mode 4 function - GPIO 138 */ #define SYS_CONF ((4 << 16) | ((1 << 8) | (1<<3) | 4)) #define SYS_MASK ~(0x10F010F) l = (in32(sys + 0x168) & SYS_MASK) | SYS_CONF; //l = (in32(sys + 0x168) & ~(7<<16) ) | (4 << 16); //out32(sys + 0x168, ((1<<3 | 4) << 16) | (1<<3) | 4); out32(sys + 0x168, l); /* setting mode 2 - PWM */ l = (in32(sys + 0x174) & ~7 ) | 2; out32(sys + 0x174, l); /* setting the PIN 138 to input * setting the PIN 139 to output */ l = (in32(gpio5 + OMAP2420_GPIO_OE) & ~(1 << 11)) | 1 << 10; out32(gpio5 + OMAP2420_GPIO_OE, l); /* enabling interrupt on both levels on GPIO 139 */ out32(gpio5 + OMAP2420_GPIO_RISINGDETECT, l << 10); out32(gpio5 + OMAP2420_GPIO_FALLINGDETECT, l << 10); out32(gpio5 + OMAP2420_GPIO_SETIRQENABLE1, l << 10); /* make sure timer has stop */ out32(gpt9 + OMAP3530_GPT_TCLR, 0); /* enabling the interrupt */ out32(gpt9 + OMAP3530_GPT_TIER, 2); //comentar se PWM /* configuring PWM */ out32(gpt9 + OMAP3530_GPT_TCLR, (1<<12) | (1<<10) | (1<<7)); //-- PWM out32(gpio5 + OMAP2420_GPIO_SETDATAOUT, (1 << 11)); printf("Esperando requisições\n"); while (1) { rcvid = MsgReceive(name->chid, &msg, sizeof(msg), NULL); if (rcvid == -1) {/* Error condition, exit */ break; } /* name_open() sends a connect message, must EOK this */ if (msg.hdr.type == _IO_CONNECT) { MsgReply(rcvid, EOK, NULL, 0); continue; } /* Some other QNX IO message was received; reject it */ if (msg.hdr.type > _IO_BASE && msg.hdr.type <= _IO_MAX) { MsgError(rcvid, ENOSYS); continue; } switch (msg.hdr.subtype) { case 0x55: MsgReply(rcvid, EOK, &pincount, sizeof(pincount)); break; case 0x65: MsgReply(rcvid, EOK, &interval, sizeof(interval)); break; case 0x66: interval = msg.data; MsgReply(rcvid, EOK, &interval, sizeof(interval)); break; default: MsgReply(rcvid, EOK, NULL, 0); } } out32(gpt9 + OMAP3530_GPT_TCLR, 0); out32(gpt9 + OMAP3530_GPT_TIER, 0); InterruptDetach (id); InterruptDetach (id2); printf("Fim\n"); return EXIT_SUCCESS; }
int InterruptHookIdle(void (*handler)(uint64_t *, struct qtime_entry *), unsigned flags) { return(InterruptAttach(_NTO_HOOK_IDLE, (const struct sigevent *(*)())handler, NULL, 0, flags|_NTO_INTR_FLAGS_PROCESS)); }