Beispiel #1
0
void initInterrupts(void){

	// PS2
	 alt_up_ps2_dev * ps2_device = alt_up_ps2_open_dev(PS2_NAME);

	  if(ps2_device == NULL){
	    printf("can't find PS/2 device\n");
	    return 1;
	  }

	  alt_up_ps2_clear_fifo (ps2_device) ;

	  alt_irq_register(PS2_IRQ, ps2_device, ps2_isr);
	  // register the PS/2 interrupt
	  IOWR_8DIRECT(PS2_BASE,4,1);


	  // button

	  IOWR_ALTERA_AVALON_PIO_EDGE_CAP(PUSH_BUTTON_BASE, 0x7);

	    // enable interrupts for all buttons
	    IOWR_ALTERA_AVALON_PIO_IRQ_MASK(PUSH_BUTTON_BASE, 0x7);
	  alt_irq_register(PUSH_BUTTON_IRQ, NULL, button_interrupts_function);
//
//
	  	 // frequency analyzer
	  alt_irq_register(FREQUENCY_ANALYSER_IRQ,(void*)&frequency_value, frequency_interrupt_function);
}
Beispiel #2
0
int main(void){
	int i;	// different values for period
	int j;	// different values for duty cycles
	int k;	// different values for background task

	for(i=1; i<=14; i+=2){
		for(j =1; j<=14; j+=3){
			for(k = 10; k<=10000; k*=10){
				/* ----Periodic Polling with Timer Interrupt---- */
				init(i, j);
				#ifdef TIMER_1_BASE
				alt_u32 timerPeriod;  // 32 bit period used for timer
				// calculate timer period for 20 micro seconds
				timerPeriod = TIMER_1_FREQ/50000;
				// initialize timer interrupt vector
				alt_irq_register(TIMER_1_IRQ, (void*)0, timer_ISR);
				// initialize timer period
				IOWR(TIMER_1_BASE, 2, (alt_u16)timerPeriod);
				IOWR(TIMER_1_BASE, 3, (alt_u16)(timerPeriod >> 16));
				// clear timer interrupt bit in status register
				IOWR(TIMER_1_BASE, 0, 0x0);
				// initialize timer control - start timer, run continuously, enable interrupts
				IOWR(TIMER_1_BASE, 1, 0x7);
				#endif
				printf("Periodic Polling Period:%d DutyCycle:%d BkgTsk:%d \n", i,j,k);
				eventCounter = 0;
				while(eventCounter < 100){
					background(k);
				}
				finalize();
				usleep(100);

				/* ----Pulse Interrupt---- */
				init(i, j);
				// set up the interrupt vector
				alt_irq_register(PIO_PULSE_IRQ, (void*)0, pulse_ISR );
				// reset the edge capture register by writing to it (any value will do)
				IOWR(PIO_PULSE_BASE, 3, 0x0);
				// enable interrupts for all four buttons
				IOWR(PIO_PULSE_BASE, 2, 0x1);
				printf("Interrupt Period:%d DutyCycle:%d BkgTsk:%d \n", i,j,k);
				eventCounterPulse = 0;
				while(eventCounterPulse < 100){
					background(k);
				}
				finalize();
				usleep(100);
			}
		}
	}
}
Beispiel #3
0
xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )
{
	/* Create the queues used to hold Rx and Tx characters. */
	xRxedChars = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed char ) );
	xCharsForTx = xQueueCreate( uxQueueLength + 1, ( unsigned portBASE_TYPE ) sizeof( signed char ) );

	/* If the queues were created correctly then setup the serial port hardware. */
	if( ( xRxedChars != serINVALID_QUEUE ) && ( xCharsForTx != serINVALID_QUEUE ) )
	{
		portENTER_CRITICAL();
		{
			uartControl = ALTERA_AVALON_UART_CONTROL_RTS_MSK | ALTERA_AVALON_UART_CONTROL_RRDY_MSK | ALTERA_AVALON_UART_CONTROL_DCTS_MSK;
			IOWR_ALTERA_AVALON_UART_CONTROL( UART_BASE, uartControl ); 
		  
		    /* register the interrupt handler */
			alt_irq_register ( UART_IRQ, NULL, vUARTInterruptHandler );
		}
		portEXIT_CRITICAL();
	}
	else
	{
		return ( xComPortHandle ) 0;
	}
    return ( xComPortHandle ) 1;
}
Beispiel #4
0
void rt_hw_uart_init(void)
{
    // init uart
    set_baudrate(115200);
    IOWR_ALTERA_AVALON_UART_CONTROL(RS232_BASE, 0x80);//接收中断使能
    IOWR_ALTERA_AVALON_UART_STATUS(RS232_BASE, 0x0); // clean status
    alt_irq_register(RS232_IRQ, NULL, uart_isr);

    // register device
    uart_device.type = RT_Device_Class_Char;
    /* device interface */
    uart_device.init 	    = rt_uart_init;
    uart_device.open 	    = rt_uart_open;
    uart_device.close       = rt_uart_close;
    uart_device.read 	    = rt_uart_read;
    uart_device.write       = rt_uart_write;
    uart_device.control     = rt_uart_control;

    uart_device.user_data   = RT_NULL;
    uart_device.rx_indicate = RT_NULL;
    uart_device.tx_complete = RT_NULL;

    rt_device_register(&uart_device,
                       "uart", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_STREAM | RT_DEVICE_FLAG_INT_RX);
}
Beispiel #5
0
int main()
{
	int readdata = 0;
	int offset = 0;
	int toggle = 0;

	int data = 0xDEAD;

	// Register IRQ
	alt_irq_register(0, 0, interruptServiceRoutine);

	// Enable DMA
	IOWR_32DIRECT(REGFILE_FINAL_0_BASE, DMACTRL, 0x1);

	// Set DMA start address to 0
	IOWR_32DIRECT(REGFILE_FINAL_0_BASE, DMAFSTART, 0);

	// Write DMA line pitch
	IOWR_32DIRECT(REGFILE_FINAL_0_BASE, DMALPITCH, LINE_PITCH);

	// Set Grab start address to 0
	IOWR_32DIRECT(REGFILE_FINAL_0_BASE, GFSTART, 0);

	// Enable a snapshot and write 10 to GMODE // MUST BE STARTED AT 10
	IOWR_32DIRECT(REGFILE_FINAL_0_BASE, GCTRL, 0x51);

	// Write the line pitch
	IOWR_32DIRECT(REGFILE_FINAL_0_BASE, GLPITCH, LINE_PITCH);

	while (1)
	{
	}
	return 0;
}
Beispiel #6
0
int main ()
{
    /* set interrupt capability for the Button PIO. */
    IOWR_ALTERA_AVALON_PIO_IRQ_MASK(DE2_PIO_KEYS4_BASE, 0xf);
    /* Reset the edge capture register. */
    IOWR_ALTERA_AVALON_PIO_EDGE_CAP(DE2_PIO_KEYS4_BASE, 0x0);
    // Register the ISR for buttons
    alt_irq_register(DE2_PIO_KEYS4_IRQ, NULL, Key_InterruptHandler);

    /* The alarm for calling the timer function */
    static alt_alarm alarm;
    /* Register the flashing function for the timer */
    if (alt_alarm_start (&alarm,alt_ticks_per_second(),show,NULL) < 0)
    {
        printf ("No system clock available\n");
    }

    int current_prime = 0;
    while (TRUE)
    {
        current_prime = next_prime(current_prime);
        printf("\nNext Prime is %d",current_prime);
    }

    return 0;
}
Beispiel #7
0
// Function Name: phase2_interruptsync
// Function Purpose: Performs the necessary steps to set up interrupt
// 					 generation for pio_pulse to generate an interrupt when
//					 an edge is detected from the output signal of the EGM.
//					 When the interrupts are generated, they are handled by
// 					 the ISR called timer_ISR(). After the interrupt setup
//					 procedures are complete, the init() function is called
//					 to set up the EGM. A conditional while loop is used to run
// 					 the background task while 100 pulses have not been
// 					 captured yet. After 100 pulses have been captured,
// 					 the test results are outputted and global variables used
// 					 are reset for a clean testing environment.
// Function Parameters:
//			period: the period of each pulse outputted by the EGM (input*81.93us)
//			dutycycle: the duration for which the signal is held high (input*period/16)
//			granularity: the maximum number of task units to complete per each call to
//						 background()
void phase2_interruptsync(int period, int dutycycle, int granularity)
{
	  /* set up the interrupt vector for pio_pulse, indicating pulse_ISR
	     as the ISR */
	  alt_irq_register( PIO_PULSE_IRQ, (void*)0, pulse_ISR );

	  /* reset the edge capture register by writing 0x0 to it */
	  IOWR_ALTERA_AVALON_PIO_EDGE_CAP(PIO_PULSE_BASE, 0x0);

	  /* set the interrupt request mask and enable interrupts */
	  IOWR_ALTERA_AVALON_PIO_IRQ_MASK(PIO_PULSE_BASE, 0x1);

	  init(period, dutycycle);
	  while(numPulses < 100)
	  {
	  	background(granularity);
	  }
	  printf("INTERRUPT SYNCHRONIZATION - PERIOD: %d\t DUTYCYCLE: %d\t GRANULARITY: %d\t\n", period, dutycycle, granularity);
	  finalize();
	  numPulses = 0;
	  numEdges = 0;
	  previous_pulse = 0;

	  // Make the thread sleep for 0.5s to provide enough time for the
	  // finalize() method to output all of its data to the console.
	  usleep(500000);
}
void initAnimate(struct Cursor* cursor) {
	int timer = 3000000;
	IOWR_16DIRECT(TIMESTAMP_BASE, 8, timer & 0xFFFF);
	IOWR_16DIRECT(TIMESTAMP_BASE, 12, timer >> 16);
	IOWR_16DIRECT(TIMESTAMP_BASE, 4, 0x07);
	alt_irq_register(TIMESTAMP_IRQ, cursor, (void*)animate_ISR);
}
Beispiel #9
0
master* master_init() {
	//init sd
	sd_init();

	//allocates memory
	master* m = (master*)malloc(sizeof(master));
	m->l = malloc(sizeof(level));
	m->c = malloc(sizeof(charac));
	//m->o = malloc(sizeof(object));
	m->o = &box;
	m->co = &co;
	m->spikes = &spikes;
	m->box_3 = &box_3;
	m->box_1 = &box_1;
	m->flag = &flag;


	srand(time(NULL));


	m->ab = malloc(sizeof(audio_buffer));

	//audio init
	av_config_setup();
	m->ab->audio_dev = alt_up_audio_open_dev(AUDIO_NAME); //audio setup

	reset_audio_buffer(m->ab); //init circular buffer
	preload_sfx(SFX, m->ab); //preloads sfx
	//TODO: fix sfx
	preload_sfx1("coin.wav", m->ab);

	alt_irq_register(AUDIO_IRQ,m->ab,(alt_isr_func)audio_isr);

	return m;
}
Beispiel #10
0
void Uart_init()
{
	IOWR_ALTERA_AVALON_UART_CONTROL(RS232_BASE,0x80);
	IOWR_ALTERA_AVALON_UART_STATUS(RS232_BASE,0x0);
	alt_irq_register(RS232_IRQ,NULL,Uart_ISR);

}
Beispiel #11
0
void periodic_polling(int period, int dutyCycle, int granularity)
{
	flag = 0;
	printf("Results for periodic polling with init(%d , %d) and granularity of %d \n", period, dutyCycle, granularity);

#ifdef TIMER_1_BASE
	alt_u32 timerPeriod;
	// calculate timer period for 1 seconds
	timerPeriod = TIMER_1_FREQ >> 16;

	// initialize timer interrupt vector
	alt_irq_register(TIMER_1_IRQ, (void*)0, timer_ISR);

	// initialize timer period
	IOWR(TIMER_1_BASE, 2, (alt_u16)timerPeriod);
	IOWR(TIMER_1_BASE, 3, (alt_u16)(timerPeriod >> 16));

	// clear timer interrupt bit in status register
	IOWR(TIMER_1_BASE, 0, 0x0);

	// initialize timer control -  stop timer, start timer, run continuously, enable interrupts
	IOWR(TIMER_1_BASE, 1, 0x4);
#endif

	init(period, dutyCycle);
	while(flag < 100)
	{
		background(granularity);
		// initialize timer control -  stop timer, start timer, run continuously, enable interrupts
		IOWR(TIMER_1_BASE, 1, 0x7);
	}
	finalize();
}
Beispiel #12
0
void interrupt(int period, int dutyCycle, int granularity)
{
	printf("Results for periodic polling with init(%d , %d)and granularity of %d \n", period, dutyCycle, granularity);
	init(period, dutyCycle);
	flag = 0;

#ifdef PIO_PULSE_BASE
	//initialize the pulse PIO

	//enable interrupts
	IOWR(PIO_PULSE_BASE, 2, 1);
	IOWR(PIO_PULSE_BASE, 3, 0);
	//set up the interrupt vector
	alt_irq_register( PIO_PULSE_IRQ, (void*)0, pulse_ISR );


#endif
	//printf("flag2:%d\n", flag);

	while(flag < 100)
	{
		background(granularity);
	}
	finalize();
}
Beispiel #13
0
void initAudioBuffer() {
	int timer = 3000000;
	IOWR_16DIRECT(AUDIOBUFFERPROCESS_BASE, 8, timer & 0xFFFF);
	IOWR_16DIRECT(AUDIOBUFFERPROCESS_BASE, 12, timer >> 16);
	IOWR_16DIRECT(AUDIOBUFFERPROCESS_BASE, 4, 0x08);
	alt_irq_register(AUDIOBUFFERPROCESS_IRQ, NULL, (void*)mix_ISR);

}
Beispiel #14
0
void timerInit(void)
{
    TIMER->STATUS.WORD = 0;
    TIMER->PERIODL = 50000000;
    TIMER->PERIODH = 50000000 >> 16;
    TIMER->CONTROL.WORD = 7;
    alt_irq_register(TIMER1_IRQ, (void *)TIMER1_BASE, timerISR);
}
Beispiel #15
0
void playCongrat()
{
	// register isr
	sound_data_counter = 0;
	alt_irq_register(AUDIO_IRQ, 0x0, congrat_isr);
	// enable interrupt
	alt_irq_enable(AUDIO_IRQ);
	alt_up_audio_enable_write_interrupt(audio_dev);
}
Beispiel #16
0
//Setups up required aspects for the program to run.
void Setup(){
	SD_card_init();
	init_mbr();
	init_bs();
	init_audio_codec();

	IOWR(BUTTON_PIO_BASE, 2, 0xf);
	IOWR(BUTTON_PIO_BASE, 3, 0x0);
	alt_irq_register(BUTTON_PIO_IRQ, (void*)0, button_ISR);
}
Beispiel #17
0
void audio_init (void *isr)
{
  audio_isr = isr;

  // Register internal interrupt handler
  alt_irq_register (AUDIO_IRQ, NULL, (alt_isr_func) audio_isr);

  // Enable interrupts from audio module
  *audio_ptr |= AUDIO_RE_MASK;
}
Beispiel #18
0
/*System initialization function. Should be called before your while(1)*/
void system_initialization(){
	/*Hard-code to 1 right here, you can use ISR
	 *to change the value by yourself
	*/
	uartStartRecvFlag = 1;

	 /*Open Uart port and ready to transmit and receive*/
	 uart = open(UART_NAME, O_ACCMODE);
	 if(!uart){
		 printf("failed to open uart\n");
		 //return 0;
	 } else {
		 printf("Uart ready!\n");
	 }

	 //Interrupts Registrations
	 alt_irq_register(switch0_id, (void *)&switch0, handle_switch0_interrupt);
	 alt_irq_register(switch1_id, (void *)&switch1, handle_switch1_interrupt);
	 alt_irq_register(key0_id, (void *)&key0, handle_key0_interrupt);
	 alt_irq_register(key1_id, (void *)&key1, handle_key1_interrupt);
	 alt_irq_register(key2_id, (void *)&key2, handle_key2_interrupt);
	 alt_irq_register(key3_id, (void *)&key3, handle_key3_interrupt);
	 alt_irq_register(leftready_id, (void *)&leftready, handle_leftready_interrupt_test);
	 alt_irq_register(rightready_id, (void *)&rightready, handle_rightready_interrupt_test);

	 /*Interrupt enable -> mask to enable it*/
	 IOWR_ALTERA_AVALON_PIO_IRQ_MASK(SWITCH0_BASE, 1);
	 IOWR_ALTERA_AVALON_PIO_IRQ_MASK(SWITCH1_BASE, 1);
	 IOWR_ALTERA_AVALON_PIO_IRQ_MASK(KEY0_BASE, 1);
	 IOWR_ALTERA_AVALON_PIO_IRQ_MASK(KEY1_BASE, 1);
	 IOWR_ALTERA_AVALON_PIO_IRQ_MASK(KEY2_BASE, 1);
	 IOWR_ALTERA_AVALON_PIO_IRQ_MASK(KEY3_BASE, 1);
	 IOWR_ALTERA_AVALON_PIO_IRQ_MASK(LEFTREADY_BASE, 1);
	 IOWR_ALTERA_AVALON_PIO_IRQ_MASK(RIGHTREADY_BASE, 1);

	 /*Reset edge capture bit*/
	 IOWR_ALTERA_AVALON_PIO_EDGE_CAP(SWITCH0_BASE, 0);
	 IOWR_ALTERA_AVALON_PIO_EDGE_CAP(SWITCH1_BASE, 0);
	 IOWR_ALTERA_AVALON_PIO_EDGE_CAP(KEY0_BASE, 0);
	 IOWR_ALTERA_AVALON_PIO_EDGE_CAP(KEY1_BASE, 0);
	 IOWR_ALTERA_AVALON_PIO_EDGE_CAP(KEY2_BASE, 0);
	 IOWR_ALTERA_AVALON_PIO_EDGE_CAP(KEY3_BASE, 0);
	 IOWR_ALTERA_AVALON_PIO_EDGE_CAP(LEFTREADY_BASE, 0);
	 IOWR_ALTERA_AVALON_PIO_EDGE_CAP(RIGHTREADY_BASE, 0);

	 /*turn off all LEDs*/
	 IOWR_ALTERA_AVALON_PIO_DATA(LED_BASE, 0x00);

	 /*initialize SPI transmission*/
	 IOWR_ALTERA_AVALON_PIO_DATA(CS_BASE, 1); // ~CS low
	 IOWR_ALTERA_AVALON_PIO_DATA(SCLK_BASE, 0); // Initialize SCLK to high
}
Beispiel #19
0
/********************************************************************
* 名    称:InitPIO()
* 功    能:初始化LED_PIO为输出,KEY为输入,开中断,清边沿捕获寄存器
* 入口参数:无
* 出口参数:无
********************************************************************/
void InitPIO(void)
{ 
/* 初始化LED_PIO为输出,KEY为输入 */
IOWR_ALTERA_AVALON_PIO_DIRECTION(LED_PIO_BASE, LEDCON);
IOWR_ALTERA_AVALON_PIO_DIRECTION(KEY_PIO_BASE, 0x00);
/* 开KEY的中断 */
IOWR_ALTERA_AVALON_PIO_IRQ_MASK(KEY_PIO_BASE, KEYCON);
/* 清边沿捕获寄存器 */ 
IOWR_ALTERA_AVALON_PIO_EDGE_CAP(KEY_PIO_BASE, 0x00);
/* 注册中断服务子程序 */
alt_irq_register(KEY_PIO_IRQ, NULL, KeyDown_interrupts); 
}
struct SwitchController* initSwitchController(void)
{
	struct SwitchController* this = (struct SwitchController*)malloc(sizeof(struct SwitchController));
	this->switches = 0;
	this->switch_listener = NULL;
	this->listener_context = NULL;

	alt_irq_register(SWITCHES_IRQ, this, (void*) switch_ISR);
	IOWR_ALTERA_AVALON_PIO_EDGE_CAP(SWITCHES_BASE, 0);
	IOWR_ALTERA_AVALON_PIO_IRQ_MASK(SWITCHES_BASE, 0);
	return this;
}
Beispiel #21
0
static void disable_button_pio()
{
  /* Disable interrupts from the button_pio PIO component. */
  IOWR_ALTERA_AVALON_PIO_IRQ_MASK(BUTTON_PIO_BASE, 0x0);
  /* Un-register the IRQ handler by passing a null handler. */
#ifdef ALT_ENHANCED_INTERRUPT_API_PRESENT
  alt_ic_isr_register(BUTTON_PIO_IRQ_INTERRUPT_CONTROLLER_ID, BUTTON_PIO_IRQ,
    NULL, NULL, NULL);
#else
  alt_irq_register( BUTTON_PIO_IRQ, NULL, NULL );
#endif
}
Beispiel #22
0
int main()
{
  usigned_char pb1_flag = 0x0;
  usigned_char pb2_flag = 0x0;
  
  volatile u_char timer1_count_flag = 0x0;
  while (1)
  {
	  /* Set interrupt for PB1 and PB2. Save state of switches. */
	  alt_irq_register( BUTTON_PIO_IRQ, (void*)0, button_ISR ); // PB ISR setup.
      IOWR(BUTTON_PIO_BASE, 3, 0x0); // Reset edge capture register.
	  IOWR(BUTTON_PIO_BASE, 2, 0x3); // Enable interrupts for 2 PBs.
	  // Save stat eof switches
	  
	  /* Initialize timer 0 */
	  alt_u32 timerPeriod; // 32 bit period used for timer
	  timerPeriod = 1 * TIMER_0_FREQ; // 1 second frequency
	  IOWR( TIMER_0_BASE, 2, (alt_u16)timerPeriod );
      IOWR( TIMER_0_BASE, 3, (alt_u16)(timerPeriod >> 16) );
      
      /* Initalize timer 1 */
	  
	  // Initialize timer interrupt vector
      alt_irq_register( TIMER_0_IRQ, (void *)0, TIMER_ISR );
	  // Clear timer interrupt bit in status register
      IOWR( TIMER_0_BASE, 0, 0x0 );
	  
	  // Initialize timer control - start timer, run continuously, enable interrupts
      IOWR( TIMER_0_BASE, 1, 0x7 );
	  
	  /* If PB1 start timer 1 interrupt. After every second, add to LED byte. Output. */
	  // if timer1_count_flag > 7 reset flag and stop timer.
	  // Else, output to the leds.
	  
	  /* If PB2 start timer 2 interrupt. After every second, add to LCD byte. Output. */
	  
  }
  return( 0 );
}
Beispiel #23
0
void init(){
     /* Recast the edge_capture pointer to match the
    alt_irq_register() function prototype. */
  void* distFlag_ptr = (void*) &distFlag;
  void* angleFlag_ptr = (void*) &angleFlag;
  void* graphicsFlag_ptr = (void*) &graphicsFlag;
  
   // Enable distance calc interrupt
  IOWR_ALTERA_AVALON_PIO_IRQ_MASK(DIST_READY_BASE, 1);
  // Reset the edge capture register
  IOWR_ALTERA_AVALON_PIO_EDGE_CAP(DIST_READY_BASE, 0x0);
  // Register the ISR
  alt_irq_register(DIST_READY_IRQ, distFlag_ptr,distance_interrupt );
  
     // Enable anlge calc interrupt
  IOWR_ALTERA_AVALON_PIO_IRQ_MASK(ANGLE_BASE, 1);
  // Reset the edge capture register
  IOWR_ALTERA_AVALON_PIO_EDGE_CAP(ANGLE_BASE, 0x0);
  // Register the ISR
  alt_irq_register(ANGLE_READY_IRQ,angleFlag_ptr , angle_interrupt);
  
   // Enable graphics interrupt
  IOWR_ALTERA_AVALON_PIO_IRQ_MASK(GRAPHICS_READY_BASE, 1);
  // Reset the edge capture register
  IOWR_ALTERA_AVALON_PIO_EDGE_CAP(GRAPHICS_READY_BASE, 0x0);
  // Register the ISR
  alt_irq_register(GRAPHICS_READY_IRQ, graphicsFlag_ptr, graphics_interrupt);
  
  //clear screen
  int i,g;
  for(i=-9;i<18;i++){
    for(g=-7;g<14;g++){
        drawRect(i,g,0);
    }
  }
  drawRect(0,0,0xF00);
  
  
}
Beispiel #24
0
int main(void) {
	//Registering the timer interrupt request
	alt_irq_register(TIMER_0_IRQ, (void*) 0, TIMER_ISR);

	//Establishing the timer's period
	IOWR(TIMER_0_BASE, 2, (alt_u16)TIMER_0_FREQ);
	IOWR(TIMER_0_BASE, 3, (alt_u16)(TIMER_0_FREQ >> 16));

	//Clear the timer bit in register and initialise
	IOWR(TIMER_0_BASE, 0, 0x0);
	IOWR(TIMER_0_BASE, 1, 0x7);

	//Initialise the interrupt request
	alt_irq_register(BUTTON_PIO_IRQ, (void*) 0, button_ISR);

	IOWR(BUTTON_PIO_BASE, 2, 0xF);
	IOWR(BUTTON_PIO_BASE, 3, 0x0);
	IOWR(LED_PIO_BASE, 0, 0x00);
	IOWR(SEVEN_SEG_PIO_BASE,0, 0xffff);

	while (1) {	}
	return (0);
}
Beispiel #25
0
/* Initialize the button_pio. */
static void init_button_pio()
{
	/* Recast the edge_capture pointer to match the
	alt_irq_register() function prototype. */
	void* edge_capture_ptr = (void*) &edge_capture;
	/* Enable all 4 button interrupts. */
	IOWR_ALTERA_AVALON_PIO_IRQ_MASK(KEY_BASE, 0xf);
	/* Reset the edge capture register. */
	IOWR_ALTERA_AVALON_PIO_EDGE_CAP(KEY_BASE, 0x0);
	/* Register the ISR. */
	alt_irq_register( 	KEY_IRQ,
						edge_capture_ptr,
						handle_button_interrupts );
}
Beispiel #26
0
int set_audio_interrupt(alt_up_audio_dev *audio, volatile int edge_capture_thing)
{
    // Need to disable both audio interrupts before setting them up
    // otherwise you get stuck in them when they are setup
    alt_up_audio_disable_read_interrupt(audio);
    alt_up_audio_disable_write_interrupt(audio);

    void *edge_pointer = (void*)&edge_capture_thing;
	#ifdef ALT_ENHANCED_INTERRUPT_API_PRESENT
	return alt_ic_isr_register(AUDIO_CORE_IRQ_INTERRUPT_CONTROLLER_ID,
			AUDIO_CORE_IRQ, playMusicISR, edge_pointer, 0x0);
	#else
	return alt_irq_register(AUDIO_CORE_IRQ, edge_pointer, playMusicISR);
	#endif
}
static void init_button_pio()
{
    /* initialize the push button interrupt vector */
    alt_irq_register( BUTTON_PIO_IRQ, (void*) 0, BUTTON_ISR);

    /* Reset the edge capture register. */
    IOWR_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE, 0x0);

    /* Enable all 4 button interrupts. */
    IOWR_ALTERA_AVALON_PIO_IRQ_MASK(BUTTON_PIO_BASE, 0xf);

    /* Initialize Variables */
    edge_capture = 0;

}
Beispiel #28
0
void altera_modular_adc_init(alt_modular_adc_dev* dev, alt_32 ic_id, alt_32 irq)
{
    extern alt_llist altera_modular_adc_list;
    alt_dev_llist_insert((alt_dev_llist*) dev, &altera_modular_adc_list);
	
	if ((0 <= ic_id) && (0 <= irq))
	{
          /* Install IRQ handler */
	  #ifdef ALT_ENHANCED_INTERRUPT_API_PRESENT
              alt_ic_isr_register(ic_id, irq, alt_adc_irq, 
                      dev, NULL);
          #else
             alt_irq_register(irq, dev, alt_adc_irq);
          #endif 
	}
}
/**
 * Initiating UART Core with:
 * 115200 Baudrate
 * refer to /documentation/n2cpu_nii51010.pdf for more info
 */
void diverInitUART(int baud) {
	//Each Bit in the control register enables an IRQ for a corresponding bit in the status register.
	int control = ALTERA_AVALON_UART_CONTROL_RRDY_MSK | //enable Read Interrupts
	ALTERA_AVALON_UART_CONTROL_E_MSK; //enable Exceptions for each Interrupt
	IOWR_ALTERA_AVALON_UART_CONTROL(UART_0_BASE, control); //write contorl bitmask in the control register

	IOWR_ALTERA_AVALON_UART_STATUS(UART_0_BASE, 0x00); //writing 0 in the status Register clears the dcts,e,toe,roe,brk,fe, and pe bits

	//writing up the Baudrate-divisor
	//setting Baudrate-divisor: div = clk / desired Baudrate + 0,5
	int divisor = (int) (50000000 / baud + 0.5);  //div will be 434
	IOWR_ALTERA_AVALON_UART_DIVISOR(UART_0_BASE, divisor);

	//install IRQ service routine
	alt_irq_register(UART_0_IRQ, 0, (alt_isr_func) ISRUART);
	alt_irq_enable(UART_0_IRQ);
}
Beispiel #30
0
void EnableKeyInterrupt(void){
    int error;
    
    // enable interrupt, 2-keybutton
    IOWR_ALTERA_AVALON_PIO_IRQ_MASK(KEY_BASE,0x03);
    
    // clear capture flag
    IOWR_ALTERA_AVALON_PIO_EDGE_CAP(KEY_BASE,0);
    //

    bKeyPressed = FALSE;
    // register interrupt isr    
    error = alt_irq_register (KEY_IRQ, 0, KEY_ISR);
    if (error)
        printf("Failed to register interrut\r\n");
    
}