int main() { init_platform(); XIOModule_Initialize(&gpo, XPAR_IOMODULE_0_DEVICE_ID); // Initialize the GPO module microblaze_register_handler(XIOModule_DeviceInterruptHandler, XPAR_IOMODULE_0_DEVICE_ID); // register the interrupt handler XIOModule_Start(&gpo); // start the GPO module XIOModule_Connect(&gpo, XIN_IOMODULE_FIT_1_INTERRUPT_INTR, timerTick, NULL); // register timerTick() as our interrupt handler XIOModule_Enable(&gpo, XIN_IOMODULE_FIT_1_INTERRUPT_INTR); // enable the interrupt microblaze_enable_interrupts(); // enable global interrupts u8 leds = 0; while (1){ // write the LED value to port 1 (you can have up to 4 ports) XIOModule_DiscreteWrite(&gpo, 1, leds++); xil_printf("%d", leds); xil_printf(","); delay(500); // delay one half second } return 0; }
void Initialize() { XGpio_Initialize(&Dips, XPAR_DIP_DEVICE_ID); XGpio_SetDataDirection(&Dips, 1, 0xff); XGpio_Initialize(&Btns, XPAR_BUTTON_DEVICE_ID); XGpio_SetDataDirection(&Btns, 1, 0xff); XIntc_Initialize(&intCtrl, XPAR_AXI_INTC_0_DEVICE_ID); XGpio_InterruptEnable(&Btns, 1); XGpio_InterruptGlobalEnable(&Btns); XGpio_InterruptEnable(&Dips, 1); XGpio_InterruptGlobalEnable(&Dips); XIntc_Enable(&intCtrl, XPAR_AXI_INTC_0_BUTTON_IP2INTC_IRPT_INTR); XIntc_Enable(&intCtrl, XPAR_AXI_INTC_0_DIP_IP2INTC_IRPT_INTR); XIntc_Connect(&intCtrl, XPAR_AXI_INTC_0_BUTTON_IP2INTC_IRPT_INTR, (XInterruptHandler)PushBtnHandler, (void *)0); XIntc_Connect(&intCtrl, XPAR_AXI_INTC_0_DIP_IP2INTC_IRPT_INTR, (XInterruptHandler)SwitchHandler,(void *)0); microblaze_enable_interrupts(); microblaze_register_handler((XInterruptHandler)XIntc_InterruptHandler, (void *)&intCtrl); XIntc_Start(&intCtrl, XIN_REAL_MODE); }
int TmrCtrIntr(XIntc * IntcInstancePtr, XTmrCtr * TmrCtrInstancePtr, u16 DeviceID, u16 IntrID, u8 TmrCtrNumber){ int Status; /*连接一个设备句柄,当识别中断后,与中断源相关的句柄将运行。IntcInstancePtr为中断控制器, IntrID为定时器的中断号,XTmrCtr_InterruptHandler为中断的句柄,TmrCtrInstancePtr为回调参数。*/ Status = XIntc_Connect(IntcInstancePtr, IntrID, (XInterruptHandler)XTmrCtr_InterruptHandler, (void *)TmrCtrInstancePtr); if(Status != XST_SUCCESS) return XST_FAILURE; //启动中断控制器 Status = XIntc_Start(IntcInstancePtr, XIN_REAL_MODE); if(Status != XST_SUCCESS) return XST_FAILURE; //使能中断 XIntc_Enable(IntcInstancePtr, IntrID); //允许处理器处理中断 microblaze_enable_interrupts(); if(Status != XST_SUCCESS) return XST_FAILURE; //设定用于定时器的句柄 XTmrCtr_SetHandler(TmrCtrInstancePtr, timer_int_handler, TmrCtrInstancePtr); //设置定时器选项 XTmrCtr_SetOptions(TmrCtrInstancePtr, TmrCtrNumber, XTC_INT_MODE_OPTION | XTC_AUTO_RELOAD_OPTION); //设置定时器计数的周期数加到1s(在50MHZ条件下) //中断为 = 0xFFFFFFFF - 0x2FAF080(=50000000) => 0xFD050F80 XTmrCtr_SetResetValue(TmrCtrInstancePtr, TmrCtrNumber, 0xFD050F80); //启动定时器 XTmrCtr_Start(TmrCtrInstancePtr, TmrCtrNumber); xil_printf("The value of count = %d\n\r", count); return XST_SUCCESS; }
/** * Enable Exceptions. * * @return None. * * @note None. * ******************************************************************************/ void Xil_ExceptionEnable(void) { #ifdef MICROBLAZE_EXCEPTIONS_ENABLED microblaze_enable_exceptions(); #endif microblaze_enable_interrupts(); }
// Enable interrupts by using a simple interrupt routine. If more complex // interrupt routine is needed, you must create your own interrupt handler routine. void sound_initInterupts() { microblaze_register_handler(sound_interrupt_handler, NULL); XIntc_EnableIntr(XPAR_INTC_0_BASEADDR, XPAR_AXI_AC97_0_INTERRUPT_MASK); XIntc_MasterEnable(XPAR_INTC_0_BASEADDR); microblaze_enable_interrupts(); }
void initInterrupts() { microblaze_register_handler(interrupt_handler_dispatcher, NULL); XIntc_EnableIntr(XPAR_INTC_0_BASEADDR, (XPAR_FIT_TIMER_0_INTERRUPT_MASK | XPAR_DMA_CONTROLLER_0_INTERRUPT_MASK)); XIntc_MasterEnable(XPAR_INTC_0_BASEADDR); microblaze_enable_interrupts(); }
void interrupts_init() { microblaze_register_handler(interrupt_handler_dispatcher, NULL); // Enable interrupts from FIT, GPIO block, and AC97 XIntc_EnableIntr(XPAR_INTC_0_BASEADDR, (XPAR_FIT_TIMER_0_INTERRUPT_MASK | XPAR_PUSH_BUTTONS_5BITS_IP2INTC_IRPT_MASK | XPAR_AXI_AC97_0_INTERRUPT_MASK)); XIntc_MasterEnable(XPAR_INTC_0_BASEADDR); microblaze_enable_interrupts(); }
void initButtonInterrupt(XIntc controller) { btnIntCtrl = controller; xil_printf("\r\nInitialising button interrupts..."); lBtnStateOld = 0x00000000; XGpio_Initialize(&pshBtns, BTNS_DEVICE_ID); XIntc_Connect(&controller, BTNS_IRPT_ID, PushBtnHandler, &pshBtns); XIntc_Enable(&controller, BTNS_IRPT_ID); microblaze_register_handler(XIntc_DeviceInterruptHandler, INTC_DEVICE_ID); microblaze_enable_interrupts(); XIntc_Start(&controller, XIN_REAL_MODE); xil_printf("done"); }
int btn_method(){ XStatus Status= XST_SUCCESS; if(btn_initialize()!=XST_SUCCESS) return XST_FAILURE; Status = XIntc_Initialize(&intCtrl_Btn, INTC_DEVICE_ID); if ( Status != XST_SUCCESS ) { if( Status == XST_DEVICE_NOT_FOUND ) { xil_printf("Interrupt Controller: XST_DEVICE_NOT_FOUND...\r\n"); } else { xil_printf("Interrupt Controller: A different error from XST_DEVICE_NOT_FOUND...\r\n"); } xil_printf("Interrupt controller: driver failed to be initialized...\r\n"); return XST_FAILURE; } xil_printf("Interrupt controller: driver initialized!\r\n"); Status = XIntc_Connect(&intCtrl_Btn, BTN_IR_ID, btn_handler, &Btn); if ( Status != XST_SUCCESS ) { xil_printf("Failed to connect the application handlers to the interrupt controller...\r\n"); return XST_FAILURE; } xil_printf("Connected to Interrupt Controller!\r\n"); XIntc_Enable(&intCtrl_Btn, BTN_IR_ID); microblaze_register_handler((XInterruptHandler)XIntc_DeviceInterruptHandler,INTC_DEVICE_ID);//Because it is 0? microblaze_enable_interrupts(); XGpio_InterruptEnable(&Btn,BTN_IR_MASK); XGpio_InterruptGlobalEnable(&Btn); Status = XIntc_Start(&intCtrl_Btn, XIN_REAL_MODE); if (Status != XST_SUCCESS) { xil_printf("Failed to start the interrupt controller...\r\n"); return XST_FAILURE; } print("Interrupt controller Started!\n\r "); return XST_SUCCESS; }
/* * This function setups the interrupt system so interrupts can occur for the * IIC device. The function is application-specific since the actual system may * or may not have an interrupt controller. The IIC device could be directly * connected to a processor without an interrupt controller. The user should * modify this function to fit the application. * * @param IicInstPtr contains a pointer to the instance of the IIC device * which is going to be connected to the interrupt controller. * * @return XST_SUCCESS if successful else XST_FAILURE. * * @note None. */ int SetupInterruptSystem(XIic * IicInstPtr) { int Status; if (InterruptController.IsStarted == XIL_COMPONENT_IS_STARTED) { return XST_SUCCESS; } /* * Initialize the interrupt controller driver so that it's ready to use. */ Status = XIntc_Initialize(&InterruptController, INTC_DEVICE_ID); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Connect the device driver handler that will be called when an * interrupt for the device occurs, the handler defined above performs * the specific interrupt processing for the device. */ Status = XIntc_Connect(&InterruptController, IIC_INTR_ID, (XInterruptHandler) XIic_InterruptHandler, IicInstPtr); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Start the interrupt controller so interrupts are enabled for all * devices that cause interrupts. */ Status = XIntc_Start(&InterruptController, XIN_REAL_MODE); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Enable the interrupts for the IIC device. */ XIntc_Enable(&InterruptController, IIC_INTR_ID); /* * Enable the Microblaze Interrupts. */ microblaze_enable_interrupts(); return XST_SUCCESS; }
void start_intc(void) { // Setting Interupt controller xil_printf("\r\nSetting up Interrupt Controller:\r\n"); //Initialize exception handling xil_printf(" Initialize exception handling\r\n"); microblaze_enable_exceptions(); // Register external interrupt handler xil_printf(" Register external interrupt handler\r\n"); microblaze_register_handler((XInterruptHandler)XIntc_DeviceInterruptHandler, (void *)XPAR_XPS_INTC_0_DEVICE_ID); // // Register UART interrupt handler // // xil_printf(" Register UART interrupt handler\r\n"); // XIntc_RegisterHandler(XPAR_INTC_0_BASEADDR,XPAR_INTC_0_RS232_INTERRUPT_INTR, // (XInterruptHandler)uart_int_handler,(void *)XPAR_RS232_BASEADDR); // Register OPB_FX2 interrupt handler xil_printf(" Register I2C_SLAVE interrupt handler\r\n"); XIntc_RegisterHandler(XPAR_INTC_0_BASEADDR,XPAR_XPS_INTC_0_XPS_I2C_SLAVE_0_IP2INTC_IRPT_INTR, (XInterruptHandler)i2c_slave_int_handler,(void *)XPAR_XPS_I2C_SLAVE_0_BASEADDR); // Enable timer interrupts // // xil_printf(" Register OPB_TIMER interrupt handler\r\n"); // XIntc_mMasterEnable(XPAR_OPB_TIMER_0_BASEADDR); // Start the interrupt controller // XIntc_SetIntrSvcOption( XPAR_INTC_0_BASEADDR, XIN_SVC_ALL_ISRS_OPTION); // Enable uart interrupt in the interrupt controller xil_printf(" Enable interrupts in the interrupt controller\r\n"); XIntc_EnableIntr(XPAR_INTC_0_BASEADDR, // XPAR_RS232_INTERRUPT_MASK | // XPAR_XPS_TIMER_0_INTERRUPT_MASK | // XPAR_OPB_FX2_0_INTERRUPT_MASK | XPAR_XPS_I2C_SLAVE_0_IP2INTC_IRPT_MASK); xil_printf(" Start the interrupt controller\r\n"); XIntc_MasterEnable(XPAR_INTC_0_BASEADDR); // Enable uart interrupts // // xil_printf(" Enable uart interrupt in Uartlite\r\n"); // XUartLite_mEnableIntr(XPAR_RS232_BASEADDR); // xil_printf(" Enable all interrupts in XPS_FX2\r\n"); // Enable MB interrupts // xil_printf(" Enable MB interrupts\r\n"); microblaze_enable_interrupts(); }
int interruptManager (unsigned int * framePointer0) { init_platform(); // Initialize the GPIO peripherals. int success; // Used for CPU utilization. Uncomment if desired // XTmrCtr_Initialize(instPtr, 0); success = XGpio_Initialize(&gpPB, XPAR_PUSH_BUTTONS_5BITS_DEVICE_ID); // Set the push button peripheral to be inputs. XGpio_SetDataDirection(&gpPB, 1, 0x0000001F); // Enable the global GPIO interrupt for push buttons. XGpio_InterruptGlobalEnable(&gpPB); // Enable all interrupts in the push button peripheral. XGpio_InterruptEnable(&gpPB, 0xFFFFFFFF); // Reset the XAC97 Chip XAC97_HardReset(XPAR_AXI_AC97_0_BASEADDR); XAC97_mSetControl(XPAR_AXI_AC97_0_BASEADDR, AC97_ENABLE_IN_FIFO_INTERRUPT); XAC97_mSetControl(AC97_ExtendedAudioStat, AC97_EXTENDED_AUDIO_CONTROL_VRA); setVolLevel(AC97_VOL_MAX); clearAllSounds(); microblaze_register_handler(interrupt_handler_dispatcher, NULL); XIntc_EnableIntr(XPAR_INTC_0_BASEADDR, (XPAR_FIT_TIMER_0_INTERRUPT_MASK | XPAR_PUSH_BUTTONS_5BITS_IP2INTC_IRPT_MASK | XPAR_AXI_AC97_0_INTERRUPT_MASK)); XIntc_MasterEnable(XPAR_INTC_0_BASEADDR); microblaze_enable_interrupts(); // Uncomment for CPU utilization stats /*XTmrCtr Timer; XTmrCtr *instPtr = &Timer; XTmrCtr_Initialize(instPtr, 0); XTmrCtr_Start(instPtr, 0);*/ while(!isEndOfGame()); // Program never ends. // Uncomment for CPU utilization stats /*XTmrCtr_Stop(instPtr, 0); int val = (int) XTmrCtr_GetValue(instPtr, 0); xil_printf("%d\n\r", val);*/ clearAllSounds(); XAC97_ClearFifos(XPAR_AXI_AC97_0_BASEADDR); drawGameOver(); cleanup_platform(); return 0; }
void init_all(void) { XIntc_Initialize(&intc, XPAR_XPS_INTC_0_DEVICE_ID); microblaze_enable_interrupts(); XIntc_mMasterEnable(XPAR_INTC_0_BASEADDR); XUartLite_mEnableIntr(XPAR_UARTLITE_0_BASEADDR); //// пецхярпюжхъ напюанрвхйнб //////////////////////////////////////////// XIntc_RegisterHandler(XPAR_XPS_INTC_0_BASEADDR, XPAR_INTC_0_UARTLITE_0_VEC_ID, (XInterruptHandler)handler_RS232, (void *)0); XIntc_RegisterHandler(XPAR_XPS_INTC_0_BASEADDR, XPAR_INTC_0_TMRCTR_0_VEC_ID, (XInterruptHandler)handler_Timer, (void *)0); /////////////////////////////////////////////////////////////////////////////// //// мюярпнийю рюилепю ////////////////////////////////////////////////////// XTmrCtr_mSetLoadReg(XPAR_XPS_TIMER_0_BASEADDR, 0, 0x61a8 //(25 MHz / 25000 = 1mS //0x124F8//(75 MHz : 75.000 = 1 mS ); XIntc_mEnableIntr(XPAR_INTC_0_BASEADDR, // XPAR_XPS_TIMER_0_INTERRUPT_MASK | XPAR_XPS_UARTLITE_0_INTERRUPT_MASK); XTmrCtr_mSetControlStatusReg(XPAR_XPS_TIMER_0_BASEADDR, 0, XTC_CSR_ENABLE_TMR_MASK | XTC_CSR_ENABLE_INT_MASK | XTC_CSR_AUTO_RELOAD_MASK | XTC_CSR_DOWN_COUNT_MASK); ///////////////////////////////////////////////////////////////////////////////// ///////// мюярпнийю сярпниярб ббндю-бшбндю //////////////////////////////////// XGpio_Initialize(&photo, XPAR_XPS_GPIO_0_DEVICE_ID); XGpio_Initialize(&ircom, XPAR_XPS_GPIO_1_DEVICE_ID); XGpio_Initialize(&kt, XPAR_XPS_GPIO_2_DEVICE_ID); XGpio_SetDataDirection(&photo, 1, 0xffffffff); // ББНД XGpio_SetDataDirection(&photo, 2, 0x00); // БШБНД XGpio_SetDataDirection(&ircom, 1, 0x00); // БШБНД XGpio_SetDataDirection(&ircom, 2, 0x00); // БШБНД XGpio_SetDataDirection(&kt, 1, 0x00); // БШБНД };
void initInterrupts() { // Initialize the GPIO peripherals. NOTE: We wait to do this till after the HDMI to ensure that nothing happens before the HDMI is enabled. XGpio_Initialize(&gpPB, XPAR_PUSH_BUTTONS_5BITS_DEVICE_ID); // Set the push button peripheral to be inputs. XGpio_SetDataDirection(&gpPB, 1, 0x0000001F); XGpio_Initialize(&gpswitches, XPAR_SLIDE_SWITCHES_8BITS_DEVICE_ID); XGpio_SetDataDirection(&gpswitches, 1, 0x000000FF); microblaze_register_handler(interrupt_handler_dispatcher, NULL); XIntc_EnableIntr(XPAR_INTC_0_BASEADDR, (XPAR_PIT_0_INTERRUPT_MASK | XPAR_PUSH_BUTTONS_5BITS_IP2INTC_IRPT_MASK | XPAR_AXI_AC97_0_INTERRUPT_MASK | XPAR_PS2CTRL_0_INTERRUPT_MASK)); XIntc_MasterEnable(XPAR_INTC_0_BASEADDR); microblaze_enable_interrupts(); }
int main (void) { init_platform(); // Initialize the GPIO peripherals. XGpio_Initialize(&gpPB, XPAR_PUSH_BUTTONS_5BITS_DEVICE_ID); // Set the push button peripheral to be inputs. XGpio_SetDataDirection(&gpPB, 1, 0x0000001F); // Enable the global GPIO interrupt for push buttons. XGpio_InterruptGlobalEnable(&gpPB); // Enable all interrupts in the push button peripheral. XGpio_InterruptEnable(&gpPB, 0xFFFFFFFF); pit_init(); pit_load_value(1000000); // init to 10 ms pit_enable_load(); pit_enable_interrupts(); pit_enable_count(); microblaze_register_handler(interrupt_handler_dispatcher, NULL); XIntc_EnableIntr(XPAR_INTC_0_BASEADDR, (XPAR_PIT_0_MYINTERRUPT_MASK | XPAR_PUSH_BUTTONS_5BITS_IP2INTC_IRPT_MASK)); XIntc_MasterEnable(XPAR_INTC_0_BASEADDR); microblaze_enable_interrupts(); // Tell stdin that it gets zero! none! (as far as buffering goes) setvbuf(stdin, NULL, _IONBF, 0); while(1){ // blocking call: wait until a character is present char input = getchar(); // Handle the UART control of game uartControl_handle(input); } cleanup_platform(); return 0; }
void system_init(void) { init_tft(); // initialiser xps_tft init_interrupt_controller(); system_enable_caches(); microblaze_enable_interrupts(); system_init_network(); clear_screen(); // effacer la page vidéo avec du noir font_init(XPAR_FLASH_MEM0_BASEADDR, TFT_FB_ADDR); sound_init(); htmlParserInit(); connection_set_HTML_handler(DM_parseHTMLPage); connection_set_WAV_handler(wav_parse); //connection_set_BMP_handler(BMP_html_parser_handler); history_init(); DM_init(); command_line_init(); }
void interrupts_init() { microblaze_register_handler(interrupt_handler_dispatcher, NULL); // Enable interrupts from FIT, GPIO block, and AC97 // XIntc_EnableIntr(XPAR_INTC_0_BASEADDR, // (XPAR_FIT_TIMER_0_INTERRUPT_MASK | XPAR_PUSH_BUTTONS_5BITS_IP2INTC_IRPT_MASK // | XPAR_AXI_AC97_0_INTERRUPT_MASK)); // Enable interrupts from the PIT, GPIO block, and AC97 XIntc_EnableIntr(XPAR_INTC_0_BASEADDR, (XPAR_PIT_0_MYINTERRUPT_MASK | XPAR_PUSH_BUTTONS_5BITS_IP2INTC_IRPT_MASK | XPAR_AXI_AC97_0_INTERRUPT_MASK | XPAR_DMA_CTRL_0_INTERRUPT_MASK)); XAC97_mSetControl(XPAR_AXI_AC97_0_BASEADDR, AC97_ENABLE_IN_FIFO_INTERRUPT); XIntc_MasterEnable(XPAR_INTC_0_BASEADDR); pit_load_value(1000000); pit_enable_load(); pit_enable_count(); pit_enable_interrupts(); microblaze_enable_interrupts(); }
int main() { init_platform(); INT_IER=0x01; //next three lines enable interrupts (I don't think order matters) INT_MER=0x03; microblaze_enable_interrupts(); port2_direction = 7; port2_IPIER = 1; port2_GIER=0x80000000; int i; int ii; char tail = 0; //---------------------------------------------------------- Event Que while(1){ if(tail!= head){ xil_printf("%d\r\n", que[tail]); tail++; port2_IPIER = 0; for (i=0;i<50;i++){ for (ii=0;ii<65000;ii++){ } } port2_IPIER=0x1; } #comment added Dr. Hummel } //this is what I am adding here cleanup_platform(); return 0; }
int main (void) { int old_count = 0; gpio_init(); XGpio_DiscreteWrite(&led,1,0); XGpio_DiscreteWrite(&ledPush,1,0x1); xil_printf("-- Entering main() --\r\n"); XTmrCtr_Initialize(&XTC, XPAR_OPB_TIMER_1_DEVICE_ID ); XTmrCtr_SetOptions(&XTC, 0, XTC_DOWN_COUNT_OPTION | XTC_INT_MODE_OPTION | XTC_AUTO_RELOAD_OPTION ); XTmrCtr_SetHandler(&XTC, TimerCounterHandler, &XTC); microblaze_register_handler( (XInterruptHandler)XTmrCtr_InterruptHandler, &XTC ); microblaze_enable_interrupts(); XTmrCtr_SetResetValue ( &XTC, 0, 50*1000000L ); XTmrCtr_Start( &XTC, 0 ); XGpio_DiscreteWrite(&ledPush,1,0x3); while(1) { if (gpio_check()) break; if ( old_count != intr_count ) { xil_printf(" TmrCtr update %d\r\n", intr_count ); XGpio_DiscreteWrite(&led,1,3); XGpio_DiscreteWrite(&ledPush,1,0x10 | (intr_count&0xF)); old_count = intr_count; } } if ( XTmrCtr_IsExpired( &XTC, 0 ) ) { xil_printf(" TmrCtr Timed out\r\n" ); } else { xil_printf(" TmrCtr un-Timeout\r\n" ); } XTmrCtr_Stop(&XTC, 0 ); microblaze_disable_interrupts(); XGpio_DiscreteWrite(&ledPush,1,0x10); xil_printf("-- Exiting main() --\r\n"); return 0; }
// Main program loop int main(void){ // Clock is 50 MHz TLR0 = 56818; //TLR0 = 1; TCSR0 = 0b10000; // 0b0000 1110 0010 TCSR0 = 0x000000D2; // TODO: Enable interrupts INTC_IER = TIMER0_INTR_MASK; INTC_MER = 0b11; // This call will allow event to interrupt MicroBlaze core microblaze_enable_interrupts(); for(;;){ // Print a debug message to the console printf( "channel0 = %05d\t" "channel1 = %05d\t" "channel2 = %05d\t" "primaryIsrCount = %03d\t" "timerIsrCount = %03d\t" "adcIsrCount = %03d\n", channel0, channel1, channel2, primaryIsrCount, timerIsrCount, adcIsrCount ); printf("%d", TCR0); } return 0; }
int main (void) { init_platform(); // Initialize the GPIO peripherals. int success = XGpio_Initialize(&gpPB, XPAR_PUSH_BUTTONS_5BITS_DEVICE_ID); // Set the push button peripheral to be inputs. XGpio_SetDataDirection(&gpPB, 1, 0x0000001F); // Enable the global GPIO interrupt for push buttons. XGpio_InterruptGlobalEnable(&gpPB); // Enable all interrupts in the push button peripheral. XGpio_InterruptEnable(&gpPB, 0xFFFFFFFF); microblaze_register_handler(interrupt_handler_dispatcher, NULL); custom_XIntc_EnableIntr(XPAR_INTC_0_BASEADDR, (XPAR_FIT_TIMER_0_INTERRUPT_MASK | XPAR_PUSH_BUTTONS_5BITS_IP2INTC_IRPT_MASK)); custom_XIntc_MasterEnable(XPAR_INTC_0_BASEADDR); microblaze_enable_interrupts(); while(1); // Program never ends. cleanup_platform(); return 0; }
//Add a new IP to the Interrupt controller void Interrupt_Config(XIntc *InstancePtr, u16 DeviceId) { Xuint32 IntMasc; int Status; if (InstancePtr->IsReady == 0) { Status = XIntc_Initialize(InstancePtr, DeviceId); if (Status != XST_SUCCESS) { xil_printf("Interruptions Initialization Fail \n\r"); } } u32 dir; //Interrupts Connected Status = XIntc_Connect(InstancePtr, 1,(XInterruptHandler) Interrupt_coreA_HW, (void *)dir); Status = XIntc_Connect(InstancePtr, 2,(XInterruptHandler) Interrupt_coreC_HW, (void *)dir); Status = XIntc_Connect(InstancePtr, 3,(XInterruptHandler) Interrupt_coreD_HW, (void *)dir); Status = XIntc_Connect(InstancePtr, 4,(XInterruptHandler) Interrupt_coreE_HW, (void *)dir); //Initialize interruptions Status = XIntc_Start(InstancePtr, XIN_REAL_MODE); IntMasc = 0xFF; XIntc_EnableIntr(InstancePtr->BaseAddress, IntMasc); microblaze_enable_interrupts(); }
void init_interrupt_controller() { XStatus Status; XStatus StatusRC5; XIo_Out32(XPAR_VGA_PERIPH_MEM_0_S_AXI_MEM0_BASEADDR + 0x54, 0x1E0); //init terminal counter on 524 XIo_Out32(XPAR_VGA_PERIPH_MEM_0_S_AXI_MEM0_BASEADDR + 0x58, 1); //enable timer //initialize interrupt controller Status = XIntc_Initialize (&Intc, XPAR_INTC_0_DEVICE_ID); if (Status != XST_SUCCESS) xil_printf ("\r\nInterrupt controller initialization failure"); else xil_printf("\r\nInterrupt controller initialized"); // Connect interrupt_handler Status = XIntc_Connect (&Intc, 0, (XInterruptHandler) vga_interrupt_handler, (void *)0); //StatusRC5 = XIntc_Connect (&Intc, 1, (XInterruptHandler) rc5_interrupt_handler, (void *)0); if (Status != XST_SUCCESS) xil_printf ("\r\nRegistering MY_TIMER Interrupt Failed"); else xil_printf("\r\nMY_TIMER Interrupt registered"); //if (StatusRC5 != XST_SUCCESS) // xil_printf ("\r\nRegistering MY_TIMER Interrupt Failed"); // else // xil_printf("\r\nMY_TIMER Interrupt registered"); //Start the interrupt controller in real mode Status = XIntc_Start(&Intc, XIN_REAL_MODE); //Enable interrupt controller XIntc_Enable (&Intc, 0); microblaze_enable_interrupts(); }
//--------------------------------------------------------------------------- // // Function: enableInterrupts // // Description: enable the microblaze interrupt // // Parameters: void // // Returns: void // // State: // //--------------------------------------------------------------------------- void enableInterrupts(void) { //enable microblaze interrupts microblaze_enable_interrupts(); }
int main() { XStatus Status; u32 btnsw, old_btnsw = 0x000000FF; int rotcnt, old_rotcnt = 0x1000; bool done = false; // initialize devices and set up interrupts, etc. Status = do_init(); if (Status != XST_SUCCESS) { LCD_setcursor(1,0); LCD_wrstring("****** ERROR *******"); LCD_setcursor(2,0); LCD_wrstring("INIT FAILED- EXITING"); exit(XST_FAILURE); } // initialize the global variables timestamp = 0; pwm_freq = INITIAL_FREQUENCY; pwm_duty = INITIAL_DUTY_CYCLE; clkfit = 0; new_perduty = false; // start the PWM timer and kick of the processing by enabling the Microblaze interrupt PWM_SetParams(&PWMTimerInst, pwm_freq, pwm_duty); PWM_Start(&PWMTimerInst); microblaze_enable_interrupts(); // display the greeting LCD_setcursor(1,0); LCD_wrstring(" PWM LIB TEST R0"); LCD_setcursor(2,0); LCD_wrstring(" by Roy Kravitz "); NX3_writeleds(0x000000FF); delay_msecs(2000); NX3_writeleds(0x00000000); // write the static text to the display LCD_clrd(); LCD_setcursor(1,0); LCD_wrstring("G|FR: DCY: %"); LCD_setcursor(2,0); LCD_wrstring("Vavg: "); // main loop do { // check rotary encoder pushbutton to see if it's time to quit NX3_readBtnSw(&btnsw); if (btnsw & msk_BTN_ROT) { done = true; } else { new_perduty = false; if (btnsw != old_btnsw) { switch (btnsw & PWM_FREQ_MSK) { case 0x00: pwm_freq = PWM_FREQ_10HZ; break; case 0x01: pwm_freq = PWM_FREQ_100HZ; break; case 0x02: pwm_freq = PWM_FREQ_1KHZ; break; case 0x03: pwm_freq = PWM_FREQ_10KHZ; break; case 0x04: pwm_freq = PWM_FREQ_50KHZ; break; case 0x05: pwm_freq = PWM_FREQ_100KHZ; break; case 0x06: pwm_freq = PWM_FREQ_150KHZ; break; case 0x07: pwm_freq = PWM_FREQ_200KHZ; break; } old_btnsw = btnsw; new_perduty = true; } // read rotary count and handle duty cycle changes // limit duty cycle to 0% to 99% ROT_readRotcnt(&rotcnt); if (rotcnt != old_rotcnt) { pwm_duty = MAX(0, MIN(rotcnt, 99)); old_rotcnt = rotcnt; new_perduty = true; } // update generated frequency and duty cycle if (new_perduty) { u32 freq, dutycycle; float vavg; char s[10]; // set the new PWM parameters - PWM_SetParams stops the timer Status = PWM_SetParams(&PWMTimerInst, pwm_freq, pwm_duty); if (Status == XST_SUCCESS) { PWM_GetParams(&PWMTimerInst, &freq, &dutycycle); update_lcd(freq, dutycycle, 1); vavg = dutycycle * .01 * 3.3; voltstostrng(vavg, s); LCD_setcursor(2,5); LCD_wrstring(s); PWM_Start(&PWMTimerInst); } } } } while (!done); // wait until rotary encoder button is released do { NX3_readBtnSw(&btnsw); delay_msecs(10); } while ((btnsw & msk_BTN_ROT) == 0x80); // and say goodbye LCD_clrd(); LCD_wrstring("That's all folks"); delay_msecs(2000); LCD_clrd(); exit(XST_SUCCESS); }
int main (void) { XGpio dip; int dip_check; static XPs2 Ps2Inst; XPs2_Config *ConfigPtr; u32 StatusReg; u32 BytesReceived; u8 RxBuffer; int key_count=0; int i; status=PVP; int x_cur=7, y_cur=7, x_pos=0, y_pos=0; XGpio_Initialize(&dip, XPAR_DIP_SWITCHES_8BITS_DEVICE_ID); XGpio_SetDataDirection(&dip, 1, 0xffffffff); ConfigPtr = XPs2_LookupConfig(XPAR_XPS_PS2_0_0_DEVICE_ID); XPs2_CfgInitialize(&Ps2Inst, ConfigPtr, ConfigPtr->BaseAddress); XIntc_RegisterHandler(XPAR_XPS_INTC_0_BASEADDR, XPAR_XPS_INTC_0_XPS_TIMER_0_INTERRUPT_INTR, (XInterruptHandler) timer_int_handler, (void *)XPAR_XPS_TIMER_0_BASEADDR); XIntc_MasterEnable(XPAR_XPS_INTC_0_BASEADDR); XIntc_EnableIntr(XPAR_XPS_INTC_0_BASEADDR, 0x1); XTmrCtr_SetLoadReg(XPAR_XPS_TIMER_0_BASEADDR, 0, 333333); XTmrCtr_SetControlStatusReg(XPAR_XPS_TIMER_0_BASEADDR, 0, XTC_CSR_INT_OCCURED_MASK | XTC_CSR_LOAD_MASK ); XIntc_EnableIntr(XPAR_XPS_TIMER_0_BASEADDR, XPAR_XPS_TIMER_0_INTERRUPT_MASK); XTmrCtr_SetControlStatusReg(XPAR_XPS_TIMER_0_BASEADDR, 0, XTC_CSR_ENABLE_TMR_MASK | XTC_CSR_ENABLE_INT_MASK | XTC_CSR_AUTO_RELOAD_MASK | XTC_CSR_DOWN_COUNT_MASK); microblaze_enable_interrupts(); InitializeGame(x_cur, y_cur);status=PVP; xil_printf("-- Game Starts! --\r\n"); xil_printf("\r\nHuman Player's turn!\r\n"); int vga_input; vga_input=(0<<24)+(0<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(1<<24)+(0<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(2<<24)+(0<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(3<<24)+(0<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(4<<24)+(0<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(5<<24)+(0<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(6<<24)+(0<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(7<<24)+(0<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(8<<24)+(0<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(9<<24)+(0<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(0<<24)+(17<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(1<<24)+(17<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(2<<24)+(17<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(3<<24)+(17<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(4<<24)+(17<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(5<<24)+(17<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(6<<24)+(17<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(7<<24)+(17<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(8<<24)+(17<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(9<<24)+(17<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(0<<24)+(29<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(1<<24)+(29<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(2<<24)+(29<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(3<<24)+(29<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(4<<24)+(29<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(5<<24)+(29<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(6<<24)+(29<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(7<<24)+(29<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(8<<24)+(29<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(9<<24)+(29<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(0<<24)+(8<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(1<<24)+(8<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(2<<24)+(8<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(3<<24)+(8<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(4<<24)+(8<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(5<<24)+(8<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(6<<24)+(8<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(7<<24)+(8<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(8<<24)+(8<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(9<<24)+(8<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(9<<24)+(1<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(9<<24)+(2<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(9<<24)+(3<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(9<<24)+(4<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(9<<24)+(5<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(9<<24)+(6<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(9<<24)+(7<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(9<<24)+(8<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(9<<24)+(9<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(9<<24)+(10<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(9<<24)+(11<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(9<<24)+(12<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(9<<24)+(13<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(9<<24)+(14<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(9<<24)+(15<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(9<<24)+(16<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(9<<24)+(17<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(9<<24)+(18<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(9<<24)+(19<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(9<<24)+(20<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(9<<24)+(21<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(9<<24)+(22<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(9<<24)+(23<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(9<<24)+(24<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(9<<24)+(25<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(9<<24)+(26<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(9<<24)+(27<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(9<<24)+(28<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(9<<24)+(29<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); vga_input=(9<<24)+(30<<16)+(1<<8)+3; VGA_IP_mWriteReg(XPAR_VGA_IP_0_BASEADDR, 0, vga_input); while (1) { if (turn==HUMAN_PLAYER || (turn==COMPUTER_PLAYER && status==PVP)) { do { if (turn==COMPUTER_PLAYER && status==PVC) break; dip_check=XGpio_DiscreteRead(&dip, 1); StatusReg = XPs2_GetStatus(&Ps2Inst); }while((StatusReg & XPS2_STATUS_RX_FULL) == 0); BytesReceived = XPs2_Recv(&Ps2Inst, &RxBuffer, 1); key_count=(key_count+1)%3; if (key_count==0) { if (RxBuffer==0x21&& win_flag==0) { DrawNumber(level,3,2,EMPTY); if(level==1) level=2; else level=1; if(status==PVC ) DrawNumber(level,3,2,0); else if(status==CVP) DrawNumber(level,3,2,1); else DrawNumber(level,3,2,EMPTY); } if (RxBuffer==0x1D && win_flag==0) { EraseCursor(x_cur, y_cur); if (y_cur<=0) y_cur=14; else y_cur--; DrawChess(x_cur, y_cur, CURSOR); } if (RxBuffer==0x1B && win_flag==0) { EraseCursor(x_cur, y_cur); if (y_cur>=14) y_cur=0; else y_cur++; DrawChess(x_cur, y_cur, CURSOR); } if (RxBuffer==0x1C && win_flag==0) { EraseCursor(x_cur, y_cur); if (x_cur<=0) x_cur=14; else x_cur--; DrawChess(x_cur, y_cur, CURSOR); } if (RxBuffer==0x23 && win_flag==0) { EraseCursor(x_cur, y_cur); if (x_cur>=14) x_cur=0; else x_cur++; DrawChess(x_cur, y_cur, CURSOR); } if (RxBuffer==0x5A && win_flag==0) { DrawBack(3,1119,EMPTY); if (board_state[x_cur][y_cur]==EMPTY) { if(status==CVP) DrawChess(x_cur, y_cur, 1-turn); else DrawChess(x_cur, y_cur, turn); board_state[x_cur][y_cur]=turn; board_record[BackTimes].x=x_cur; board_record[BackTimes].y=y_cur; BackTimes++; count=0; time0=0; if (turn==COMPUTER_PLAYER) step_flag=1; if (CheckWin(x_cur,y_cur,turn)==1) { xil_printf("\r\nHuman Player wins!\r\n"); win_flag=1; DrawWinning(0, 1, EMPTY); if(status==CVP) DrawWinning(0, 1, 1-turn); else DrawWinning(0, 1, turn); } if (CheckBan(x_cur,y_cur,turn)==1){ xil_printf("\r\nComputer Player wins!\r\n"); win_flag=1; DrawWinning(0, 1, EMPTY); if(status==CVP) DrawWinning(0, 1, turn); else DrawWinning(0, 1, 1-turn); } else { if (turn==HUMAN_PLAYER) turn=COMPUTER_PLAYER; else turn=HUMAN_PLAYER; xil_printf("\r\nComputer Player's turn!\r\n"); } } } if (RxBuffer==0x29 && turn==HUMAN_PLAYER && win_flag==0) { count=0;time0=0; if (status==PVP) { x_cur=7; y_cur=7; for (i=0; i<256; i++) { board_record[i].x=0; board_record[i].y=0; } InitializeGame(x_cur, y_cur);status=PVP; DrawStatus(1, 21, EMPTY,status); status=PVC; DrawNumber(level,3,2,0); DrawStatus(1, 21, COMPUTER_PLAYER,status); } else if(status==PVC) { x_cur=7; y_cur=7; for (i=0; i<256; i++) { board_record[i].x=0; board_record[i].y=0; } InitializeGame(x_cur, y_cur);status=PVP; DrawStatus(1, 21, EMPTY,status); status=CVP; DrawNumber(level,3,2,1); DrawStatus(1, 21, COMPUTER_PLAYER,status); turn=COMPUTER_PLAYER; } else if(status==CVP) { x_cur=7; y_cur=7; for (i=0; i<256; i++) { board_record[i].x=0; board_record[i].y=0; } InitializeGame(x_cur, y_cur);status=PVP; DrawStatus(1, 21, EMPTY,status); status=PVP; DrawStatus(1, 21, COMPUTER_PLAYER,status); } } if (RxBuffer==0x76) { x_cur=7; y_cur=7; for (i=0; i<256; i++) { board_record[i].x=0; board_record[i].y=0; } InitializeGame(x_cur, y_cur);status=PVP; } if (RxBuffer==0x2D) { if(BackTimes>0){ BackTimes--; x_cur=board_record[BackTimes].x; y_cur=board_record[BackTimes].y; board_state[x_cur][y_cur]=EMPTY; DrawChess(x_cur,y_cur,EMPTY); turn=1-turn; if(status==PVC) { BackTimes--; x_cur=board_record[BackTimes].x; y_cur=board_record[BackTimes].y; board_state[x_cur][y_cur]=EMPTY; DrawChess(x_cur,y_cur,EMPTY); turn=HUMAN_PLAYER; } DrawBack(3,1119,turn); } } } } if (turn==COMPUTER_PLAYER && (status==PVC ||status==CVP )&& win_flag==0) { if (step_flag==0) { if (x_cur-1<0) x_pos=x_cur+1; else x_pos=x_cur-1; y_pos=y_cur; step_flag=1; } else { if(level==2||level==3){ EvaluateComputerMove(board_state, 0, MIN_INFINITY, MAX_INFINITY, 0, 0); x_pos=maxMoveX; y_pos=maxMoveY; xil_printf("\r\n computer \r\n");} else { everyScore(Computer); current_pos=best(Computer); x_pos=current_pos.y; y_pos=current_pos.x; xil_printf("\r\n computer \r\n"); } } xil_printf("\r\n%x, %x\r\n", x_pos, y_pos); if(status==CVP) DrawChess(x_pos, y_pos, 1-turn); else DrawChess(x_pos, y_pos, turn); board_state[x_pos][y_pos]=COMPUTER_PLAYER; board_record[BackTimes].x=x_pos; board_record[BackTimes].y=y_pos; BackTimes++; count=0; time0=0; if (CheckWin(x_pos, y_pos, turn)) { xil_printf("\r\nComputer Player wins!\r\n"); win_flag=1; DrawWinning(0,1, EMPTY); if(status==CVP) DrawWinning(0,1, 1-turn); else DrawWinning(0,1, turn); turn=HUMAN_PLAYER; } else { turn=HUMAN_PLAYER; xil_printf("\r\nHuman Player's turn!\r\n"); } } } return 0; }
/** * This function setups the interrupt system such that interrupts can occur * for the timer counter. This function is application specific since the actual * system may or may not have an interrupt controller. The timer counter could * be directly connected to a processor without an interrupt controller. The * user should modify this function to fit the application. * * @param IntcInstancePtr is a pointer to the Interrupt Controller * driver Instance * @param TmrCtrInstancePtr is a pointer to the XTmrCtr driver Instance * @param DeviceId is the XPAR_<TmrCtr_instance>_DEVICE_ID value from * xparameters.h * @param IntrId is XPAR_<INTC_instance>_<TmrCtr_instance>_INTERRUPT_INTR * value from xparameters.h * @param TmrCtrNumber is the number of the timer to which this * handler is associated with. * * @return XST_SUCCESS if the Test is successful, otherwise XST_FAILURE * * @note This function contains an infinite loop such that if interrupts are * not working it may never return. * ******************************************************************************/ static XStatus TmrCtrSetupIntrSystem(XIntc* IntcInstancePtr, XTmrCtr* TmrCtrInstancePtr, Xuint16 DeviceId, Xuint16 IntrId, Xuint8 TmrCtrNumber) { XStatus Status; #ifndef TESTAPP_GEN /* * Initialize the interrupt controller driver so that * it's ready to use, specify the device ID that is generated in * xparameters.h */ Status = XIntc_Initialize(IntcInstancePtr, INTC_DEVICE_ID); if (Status != XST_SUCCESS) { return XST_FAILURE; } #endif /* * Connect a device driver handler that will be called when an interrupt * for the device occurs, the device driver handler performs the specific * interrupt processing for the device */ Status = XIntc_Connect(IntcInstancePtr, IntrId, (XInterruptHandler)XTmrCtr_InterruptHandler, (void *)TmrCtrInstancePtr); if (Status != XST_SUCCESS) { return XST_FAILURE; } #ifndef TESTAPP_GEN /* * Start the interrupt controller such that interrupts are enabled for * all devices that cause interrupts, specific real mode so that * the timer counter can cause interrupts thru the interrupt controller. */ Status = XIntc_Start(&InterruptController, XIN_REAL_MODE); if (Status != XST_SUCCESS) { return XST_FAILURE; } #endif /* * Enable the interrupt for the timer counter */ XIntc_Enable(IntcInstancePtr, IntrId); #ifndef TESTAPP_GEN /* * Enable the Interrupts on the Microblaze */ microblaze_enable_interrupts(); #endif return XST_SUCCESS; }
int timer_method() { XStatus Status; Status = XST_SUCCESS; Status = XIntc_Initialize(&intCtrl_Timer, TIMER_DEVICE_ID); if ( Status != XST_SUCCESS ) { if( Status == XST_DEVICE_NOT_FOUND ) { xil_printf("Interrupt Controller: XST_DEVICE_NOT_FOUND...\r\n"); } else { xil_printf("Interrupt Controller: A different error from XST_DEVICE_NOT_FOUND...\r\n"); } xil_printf("Interrupt controller: driver failed to be initialized...\r\n"); return XST_FAILURE; } xil_printf("Interrupt controller: driver initialized!\r\n"); Status = XIntc_Connect(&intCtrl_Timer,TIMER_IR_ID,(XInterruptHandler)timer_handler, &Timer_tmrctr); if ( Status != XST_SUCCESS ) { xil_printf("Failed to connect the application handlers to the interrupt controller...\r\n"); return XST_FAILURE; } xil_printf("Connected to Interrupt Controller!\r\n"); Status = XIntc_Start(&intCtrl_Timer, XIN_REAL_MODE); if ( Status != XST_SUCCESS ) { xil_printf("Failed to start Interrupt Controller: ...\r\n"); return XST_FAILURE; } xil_printf("Interrupt Controller Started!\r\n"); XIntc_Enable(&intCtrl_Timer, TIMER_IR_ID ); Status = XTmrCtr_Initialize(&Timer_tmrctr, INTC_DEVICE_ID); if ( Status != XST_SUCCESS ) { xil_printf("Timer initialization failed...\r\n"); return XST_FAILURE; } xil_printf("Timer Initialized !\r\n"); /* * Enable the interrupt of the timer counter so interrupts will occur * and use auto reload mode such that the timer counter will reload * itself automatically and continue repeatedly, without this option * it would expire once only */ XTmrCtr_SetOptions(&Timer_tmrctr, 0, XTC_INT_MODE_OPTION | XTC_AUTO_RELOAD_OPTION); /* * Set a reset value for the timer counter such that it will expire * eariler than letting it roll over from 0, the reset value is loaded * into the timer counter when it is started */ XTmrCtr_SetResetValue(&Timer_tmrctr, 0, 0xFFFFFFFF-RESET_VALUE); // 0x17D7840 = 25*10^6 clk cycles @ 50MHz = 500ms /* * Register the intc device driver’s handler with the Standalone * software platform’s interrupt table */ microblaze_register_handler((XInterruptHandler)XIntc_DeviceInterruptHandler,(void*)TIMER_DEVICE_ID); microblaze_enable_interrupts(); /* * Start the timer counter such that it's incrementing by default, * then wait for it to timeout a number of times */ XTmrCtr_Start(&Timer_tmrctr, 0); xil_printf("Timer Started!\r\n"); return XST_SUCCESS; }
// Main program loop int main(void) { //Clock for the timer is 50 MHz //Set the Timer register //The timer is TLR0/50MHz TLR0 = 56818; //Load the timer register // 0b0000 1110 0010 TCSR0 = 0b10000; //Setup the timer interrupts, modes and such TCSR0 = 0x000000D2; //Enable interrupts //INTC_IER = TIMER0_INTR_MASK; INTC_IER = ADC_INTR_MASK; //Disable Master and Hardware interrupt of the system. INTC_MER = 0b0; // This call will allow event to interrupt MicroBlaze core microblaze_enable_interrupts(); for(;;) { ADC_CTRL = 0x00000001; asm("nop"); asm("nop"); asm("nop"); asm("nop"); while(ADC_STATUS & 1); channel0 = (ADC_STATUS & 0x0FFF0000) >> 16; ADC_CTRL = 0x00000000; ADC_CTRL = 0x00010001; asm("nop"); asm("nop"); asm("nop"); asm("nop"); while(ADC_STATUS & 1); channel1 = (ADC_STATUS & 0x0FFF0000) >> 16; ADC_CTRL = 0x00010000; ADC_CTRL = 0x00020001; asm("nop"); asm("nop"); asm("nop"); asm("nop"); while(ADC_STATUS & 1); channel2 = (ADC_STATUS & 0x0FFF0000) >> 16; ADC_CTRL = 0x00020000; // Print a debug message to the console printf( "channel0 = %05d\t" "channel1 = %05d\t" "channel2 = %05d\t" "primaryIsrCount = %03d\t" "timerIsrCount = %03d\t" "adcIsrCount = %03d\n", channel0, channel1, channel2, primaryIsrCount, timerIsrCount, adcIsrCount ); } return 0; }
/** * * This function setups the interrupt system so interrupts can occur for the * TEMAC. This function is application-specific since the actual system may or * may not have an interrupt controller. The TEMAC could be directly connected * to a processor without an interrupt controller. The user should modify this * function to fit the application. * * @param IntcInstancePtr is a pointer to the instance of the Intc component. * @param TemacInstancePtr is a pointer to the instance of the Temac * component. * @param TemacIntrId is the Interrupt ID and is typically * XPAR_<INTC_instance>_<TEMAC_instance>_IP2INTC_IRPT_INTR * value from xparameters.h. * * @return XST_SUCCESS if successful, otherwise XST_FAILURE. * * @note None. * ******************************************************************************/ static int TemacSetupIntrSystem(XIntc *IntcInstancePtr, XLlTemac *TemacInstancePtr, XLlDma *DmaInstancePtr, u16 TemacIntrId, u16 DmaRxIntrId, u16 DmaTxIntrId) { XLlDma_BdRing * TxRingPtr = &XLlDma_GetTxRing(DmaInstancePtr); XLlDma_BdRing * RxRingPtr = &XLlDma_GetRxRing(DmaInstancePtr); int Status; #ifndef TESTAPP_GEN /* * Initialize the interrupt controller and connect the ISR */ Status = XIntc_Initialize(IntcInstancePtr, INTC_DEVICE_ID); if (Status != XST_SUCCESS) { TemacUtilErrorTrap("Unable to intialize the interrupt controller"); return XST_FAILURE; } #endif Status = XIntc_Connect(IntcInstancePtr, TemacIntrId, (XInterruptHandler) TemacErrorHandler, TemacInstancePtr); Status |= XIntc_Connect(IntcInstancePtr, DmaTxIntrId, (XInterruptHandler) TxIntrHandler, TxRingPtr); Status |= XIntc_Connect(IntcInstancePtr, DmaRxIntrId, (XInterruptHandler) RxIntrHandler, RxRingPtr); if (Status != XST_SUCCESS) { TemacUtilErrorTrap("Unable to connect ISR to interrupt controller"); return XST_FAILURE; } #ifndef TESTAPP_GEN /* * Start the interrupt controller */ Status = XIntc_Start(IntcInstancePtr, XIN_REAL_MODE); if (Status != XST_SUCCESS) { TemacUtilErrorTrap("Error starting intc"); return XST_FAILURE; } #endif /* * Enable interrupts from the hardware */ XIntc_Enable(IntcInstancePtr, TemacIntrId); XIntc_Enable(IntcInstancePtr, DmaTxIntrId); XIntc_Enable(IntcInstancePtr, DmaRxIntrId); #ifndef TESTAPP_GEN #ifdef __PPC__ /* * Initialize the PPC exception table */ XExc_Init(); /* * Register the interrupt controller with the exception table */ XExc_RegisterHandler(XEXC_ID_NON_CRITICAL_INT, (XExceptionHandler) XIntc_InterruptHandler, IntcInstancePtr); /* * Enable non-critical exceptions */ XExc_mEnableExceptions(XEXC_NON_CRITICAL); #else /* * Connect the interrupt controller interrupt handler to the hardware * interrupt handling logic in the microblaze processor. */ microblaze_register_handler((XInterruptHandler) XIntc_InterruptHandler, IntcInstancePtr); /* * Enable interrupts in the Microblaze */ microblaze_enable_interrupts(); #endif #endif return XST_SUCCESS; }