Beispiel #1
0
static void readDat(){
	unsigned short accumulatedData = 0;
	int i;
	copyController(&prev_controller_state, controller_state);

	IOWR_8DIRECT(controller_out, 0, 0x01);
	IOWR_8DIRECT(controller_out, 0, 0x03);
	alt_busy_sleep(12);
	IOWR_8DIRECT(controller_out, 0, 0x01);
	alt_busy_sleep(6);

	accumulatedData = IORD_8DIRECT(controller_in, 0);

	for (i = 0; i < 16; i++)
	{
		IOWR_8DIRECT(controller_out, 0, 0x00);
		alt_busy_sleep(6);
		accumulatedData <<= 1;
		accumulatedData += IORD_8DIRECT(controller_in, 0);
		IOWR_8DIRECT(controller_out, 0, 0x01); // Pulse clock
		alt_busy_sleep(6);
	}

	IOWR_8DIRECT(leds, 0, accumulatedData);

	copyController(&controller_state, getControllerButtons(accumulatedData));
}
/*
 * Private function that polls write in progress bit EPCQ_RD_STATUS.
 *
 * Write in progress will be set if any of the following operations are in progress:
 * 	-WRITE STATUS REGISTER
 * 	-WRITE NONVOLATILE CONFIGURATION REGISTER
 * 	-PROGRAM
 * 	-ERASE
 *
 * Assumes EPCQ was configured correctly.
 *
 * If ALTERA_EPCQ_CONTROLLER_1US_TIMEOUT_VALUE is set, the function will time out after
 * a period of time determined by that value.
 *
 * Arguments:
 * - *epcq_flash_info: Pointer to EPCQ flash device structure.
 *  
 * Returns:
 * 0 -> success
 * -EINVAL -> Invalid arguments
 * -ETIME  -> Time out and skipping the looping after 0.7 sec.
 */
alt_32 static alt_epcq_poll_for_write_in_progress(alt_epcq_controller_dev* epcq_flash_info)
{  
    /* we'll want to implement timeout if a timeout value is specified */
#if ALTERA_EPCQ_CONTROLLER_1US_TIMEOUT_VALUE > 0
	alt_u32 timeout = ALTERA_EPCQ_CONTROLLER_1US_TIMEOUT_VALUE;
	alt_u16 counter = 0;
#endif

    /* return -EINVAL if epcq_flash_info is NULL */
	if(NULL == epcq_flash_info)
    {
    	return -EINVAL;
    }

	/* while Write in Progress bit is set, we wait */
	while((IORD_ALTERA_EPCQ_CONTROLLER_STATUS(epcq_flash_info->csr_base) &
			ALTERA_EPCQ_CONTROLLER_STATUS_WIP_MASK) ==
			ALTERA_EPCQ_CONTROLLER_STATUS_WIP_BUSY)
	{
        alt_busy_sleep(1); /* delay 1us */
#if ALTERA_EPCQ_CONTROLLER_1US_TIMEOUT_VALUE > 0
		if(timeout <= counter )
		{
			return -ETIME;
		}
		
		counter++;
#endif

	}

	return 0;
}
Beispiel #3
0
/********************************************************************
* 名    称:main()
* 功    能:等待按键中断,并输出控制相应的LED。
********************************************************************/
int main(void)
{      
    volatile alt_u32 key_state,old_state,new_state;
    old_state = 0x00;
    IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, old_state);//初始化LED全灭
    InitPIO();
    while(1) 
    { 
       if(0 != done)
       {
          /* 中断事件数量减1 */
          done--;
          alt_busy_sleep(5000); //延时5ms
          key_state = IORD_ALTERA_AVALON_PIO_DATA(KEY_PIO_BASE)&KEYCON;
          if(key_state == 0xff)   //如果是由短暂脉冲引起的中断则忽略
             continue;
        
          new_state = ~(old_state ^ key_state); // 四个按键全部按下时LED取反
          old_state = new_state;                // 保存LED的状态
          IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, new_state);
       }
    }
    return(0);
}
Beispiel #4
0
unsigned int ALT_USLEEP (unsigned int us)
#endif
{
  return alt_busy_sleep(us);
}