RTX – расширение реального времени для Windows NT

       

Interrup.shtml


// Generate an interrupt // with the digital outs // Jumper any digital out [3-10] to IR INPUT [1] // Jumper GND [11] to IR ENABLE [2] #include <windows.h>

#include <rtapi.h>

#define CT_PORT ((unsigned char *) 0x340) #define CT_PORT_9513DATA  (CT_PORT + 0) #define CT_PORT_9513CMD (CT_PORT + 1) #define CT_PORT_9513STATUS (CT_PORT + 1) #define CT_PORT_DI (CT_PORT + 2) #define CT_PORT_DO  (CT_PORT + 3) #define CT_PORT_SPACE (CT_PORT_DO - CT_PORT_9513DATA + 1) #define CT_BASE_PORT_9513DATA(BASE) ((unsigned char *)((BASE) 0)) #define CT_BASE_PORT_9513CMD(BASE) ((unsigned char *)((BASE) + 1)) #define CT_BASE_PORT_9513STATUS(BASE) ((unsigned char *)((BASE) + 1)) #define CT_BASE_PORT_DI(BASE) ((unsigned char *)((BASE) + 2)) #define CT_BASE_PORT_DO(BASE) ((unsigned char *)((BASE) + 3)) int ihc = 0 ; int ihc2 = 0 ; int limit = 30 ;

void RTFCNDCL InterruptHandler(void * unused) { RtWritePortUchar(CT_BASE_PORT_DO(CT_PORT), 0x00) ; ihc + +; } TestIncrease = 1 ;

main() { HANDLE hInterrupt ; int i ; printf("Simple Interrupt Attach Handler Functional Test") ; // Enable CT range of ports { if ( !RtEnablePortIo(CT_PORT, CT_PORT_SPACE)) { (void)printf("RtEnablePortIo(0x%x, 0x%x) failed\n", CT_PORT, CT_PORT_SPACE) ; return 1 ; } // Attach the interupt vector to the interrupt handler hInterrupt = RtAttachInterruptVector(NULL, 0, InterruptHandler, (void *)&TestIncrease, 1, 1, 0, 7, 7) ; if ( NULL == hInterrupt ) { printf("Could not register interrupt handler (%d)\n", GetLastError()) ; return 2 ; } for(i=0; i<limit; i++) { Sleep(1*1000) ; //Pulse the interrupt RtWritePortUchar(CT_BASE_PORT_DO(CT_PORT), 0xff) ; } // Determine what happened. if ( limit != ihc ) { printf("FAIL\n") ; else { printf("Got %d interrupts\n", limit) ; } RtReleaseInterruptVector(hInterrupt) ; RtWritePortUchar(CT_BASE_PORT_DO(CT_PORT), 0) ; RtWritePortUchar(CT_BASE_PORT_DO(CT_PORT), 0) ; }



Содержание раздела