示例#1
0
// Make Robot Face the Nios
void faceNios(){
   int sound = 0, soundPrevious;
   int i = 0;
   char direction = 'C';
   int lowCount = 0, turnCount = 0;
   
   while (turnCount < 2){
     while(i < 6){
       sendChar(direction);
       sendChar('L');
       usleep(100*1000);
       sendChar('S');
       sendChar('P');
       usleep(20*1000);
       soundPrevious = sound;
       sound = IORD_ALTERA_AVALON_PIO_DATA(AUDIO_MID_BASE);
       if (i > 0){
         if (sound < soundPrevious)
            lowCount = lowCount + 1;
       }
       i++;
     }
   
     if(lowCount == 4){
       direction=(direction == 'C')?'U':'C';
       turnCount = turnCount + 1;
     }
     i = 0;
   }
   
   do{
     sendChar(direction);
     sendChar('L');
     usleep(50*1000);
     sendChar('S');
     sendChar('P');
     usleep(20*1000);
     soundPrevious = sound;
     sound = IORD_ALTERA_AVALON_PIO_DATA(AUDIO_MID_BASE);
   }while(sound > soundPrevious);
   
   direction=(direction == 'C')?'U':'C';
   
   sendChar(direction);
   sendChar('L');
   usleep(50*1000);
   sendChar('S');

}
示例#2
0
void Alarm()
{
	char message[24];
	if(alarm == 0x01&& alarm_en == 0x01)
	{
		Uart_send_n("AT+CIPSEND=0,24",15);
		Uart_send(0x0d);
    	Uart_send(0x0a);
    	usleep(1000000);
		strcpy(message,"Someone Has Broken In!!!");
		Uart_send_n(message,24);
		Uart_send(0x0d);
		Uart_send(0x0a);
		puts("f**k!!\n");

		IOWR_ALTERA_AVALON_PIO_DATA(LEDMODE_BASE,0x03);
	}
	else
	{
		unsigned int status = IORD_ALTERA_AVALON_PIO_DATA(LEDMODE_BASE);
		IOWR_ALTERA_AVALON_PIO_DATA(LEDMODE_BASE, status&0x01);
		puts("nothing!\n");

	}
}
示例#3
0
tEplKernel PUBLIC AppCbSync(void)
{
	tEplKernel EplRet = kEplSuccessful;
    int        nIdx;

#ifdef DIN_PIO_BASE
    bButtonInputs_l = IORD_ALTERA_AVALON_PIO_DATA(DIN_PIO_BASE);
#else
	bButtonInputs_l++;
#endif

#ifdef DOUT_PIO_BASE
    IOWR_ALTERA_AVALON_PIO_DATA(DOUT_PIO_BASE, bLedOutputs_l);
#endif

#ifdef LED_PIO_BASE
    IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, ~wDigitalOutputs_l);
#endif

    for (nIdx = 0; nIdx < 15; nIdx++)
    {
        abVirtualInputs_l[nIdx] = (~abVirtualOutputs_l[nIdx])-1;
    }
    abVirtualInputs_l[15] = (~bButtonInputs_l)-1;
    abVirtualInputs_l[16] = (~bLedOutputs_l)-1;

    for (nIdx = 0; nIdx < 8; nIdx++)
    {
        adwVirtualInputs_l[nIdx] = (~adwVirtualOutputs_l[nIdx])-1;
    }

    return EplRet;
}
示例#4
0
static void switches_isr(void* context, alt_u32 id){
    INT8U value = IORD_ALTERA_AVALON_PIO_DATA(SWITCHES_BASE);
    if (value & 1){
        OSSemPost(songSem);
    }
    IOWR_ALTERA_AVALON_PIO_EDGE_CAP(SWITCHES_BASE, 0);
}
示例#5
0
int main(void) {
	 system_initialization();
     // set frequency
	 // sampleFrequency = 0x000C; //8k
	 sampleFrequency = 0x0019; //32k
	 //sampleFrequency = 0x0023; //44.1k
	 //sampleFrequency = 0x0001; //48k
	 aic23_demo[8] = sampleFrequency;
	 AIC23_demo();
	 int i;

	 /*Your main infinity while loop*/
	 while(1){
		 IOWR_ALTERA_AVALON_PIO_DATA(LED_BASE, IORD_ALTERA_AVALON_PIO_DATA(SWITCH0_BASE));
		 // send 512 data to matlab
		 if(uartStartSendFlag){
			for (i = 0; i < UART_BUFFER_SIZE; i++){
				uart_sendInt16(datatest[i]);
			}
			uartStartSendFlag = 0;
		 }
	 }

	 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
	 /*!!!!!!!YOUR CODE SHOULD NEVER REACH HERE AND BELOW!!!!!!!*/
	 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
	 return 0;
}
示例#6
0
文件: main.c 项目: gongal/ARCap
/* Interrupt service routine triggered whenever the status of the IR emitter pushbutton changes. */
static void isr_on_ir_pushbutton( void * context) {
	// Read the state of the pushbutton and post it to the queue.
	int state = IR_PUSHBUTTON_MESSAGE + IORD_ALTERA_AVALON_PIO_DATA(IR_PUSHBUTTON_BASE);
	OSQPost(queue, (void*)state);
	// Mask to mark the end of the ISR?
	IOWR_ALTERA_AVALON_PIO_EDGE_CAP(IR_PUSHBUTTON_BASE, IR_PUSHBUTTON_BIT_CLEARING_EDGE_REGISTER);
}
示例#7
0
static int ReadSwitches(void){
	alt_16 switch_value = 0;
	alt_8 mask = 0x00ff;
	// read the 16-bit value of switches combinations, if a switch is on, then it is 1, otherwise, it is just 0.
	switch_value = IORD_ALTERA_AVALON_PIO_DATA(SWITCH_PIO_BASE);
	switch_value &= mask;
	return switch_value;
}
示例#8
0
文件: main.cpp 项目: gongal/ARCap
/* Interrupt service routine triggered whenever the status of the IR emitter pushbutton changes. */
static void isr_on_ir_pushbutton(void * context) {
	// Read the state of the pushbutton and post it to the queue.
	//printf("Pressed\n");
	int message = IR_QUEUE_SEND_BASE + IORD_ALTERA_AVALON_PIO_DATA(PIO_KEY_LEFT_BASE);
	OSQPost(ir_queue, (void*)message);
	// Mask to mark the end of the ISR.
	IOWR_ALTERA_AVALON_PIO_EDGE_CAP(PIO_KEY_LEFT_BASE, PIO_KEY_LEFT_BIT_CLEARING_EDGE_REGISTER);
}
示例#9
0
void checkKeypad()
{
	memset(button, 0, sizeof(int)*17); //quickley resets the  button array
	int temp = 0;
	int temp2 = 0;
	button[PRESSED] = 0;

	IOWR_ALTERA_AVALON_PIO_DATA(KEY_OUT_BASE, 0x01); // enable first colum
	temp = IORD_ALTERA_AVALON_PIO_DATA(PORT_A_BASE);//read button inputs
	if ( temp != 0  ) {
		button[PRESSED] =  1;	// check if any butons pressed.
		button[M1] = CHECK_BIT(temp, 0);
		button[UPLEFT] = CHECK_BIT(temp, 1);
		button[LEFT] = CHECK_BIT(temp, 2);
		button[DOWNLEFT] = CHECK_BIT(temp, 3);
	}
	IOWR_ALTERA_AVALON_PIO_DATA(KEY_OUT_BASE, 0x02); // enable 2nd colum
	temp = IORD_ALTERA_AVALON_PIO_DATA(PORT_A_BASE);//read button inputs
	if ( temp != 0  ) {
		button[PRESSED] = 1;	// check if any butons pressed.
		button[M2] = CHECK_BIT(temp, 0);
		button[UP] = CHECK_BIT(temp, 1);
		button[STOP] = CHECK_BIT(temp, 2);
		button[DOWN] = CHECK_BIT(temp, 3);
	}
	IOWR_ALTERA_AVALON_PIO_DATA(KEY_OUT_BASE, 0x04); // enable 3rd colum
	temp = IORD_ALTERA_AVALON_PIO_DATA(PORT_A_BASE);//read button inputs
	if ( temp != 0  ) {
		button[PRESSED] = 1;	// check if any butons pressed.
		button[M3] = CHECK_BIT(temp, 0);
		button[UPRIGHT] = CHECK_BIT(temp, 1);
		button[RIGHT] = CHECK_BIT(temp, 2);
		button[DOWNRIGHT] = CHECK_BIT(temp, 3);
	}
	IOWR_ALTERA_AVALON_PIO_DATA(KEY_OUT_BASE, 0x08); // enable last colum
	temp = IORD_ALTERA_AVALON_PIO_DATA(PORT_A_BASE);//read button inputs
	if ( temp != 0  ) {
		button[PRESSED] = 1;	// check if any butons pressed.
		button[DELETE] = CHECK_BIT(temp, 0);
		button[PLAY] = CHECK_BIT(temp, 1);
		button[RECORD] = CHECK_BIT(temp, 2);
		button[SHIFT] = CHECK_BIT(temp, 3);
	}
	return;
}
示例#10
0
void load_user_inputs(void){

	int user_input = IORD_ALTERA_AVALON_PIO_DATA(SLIDE_SWITCH_BASE);
	int i;
	for( i = 0; i<NO_OF_LOADS; i++){
		loads[i] = user_input & 1<<i ? 1 : 0;
	}

}
示例#11
0
int getAngle(int right,int left){
      angleFlag = 0;
      IOWR_ALTERA_AVALON_PIO_DATA(ANGLE_START_BASE, 0);
      IOWR_ALTERA_AVALON_PIO_DATA(DIST_LOUT_BASE, left);
      IOWR_ALTERA_AVALON_PIO_DATA(DIST_ROUT_BASE, right);
      IOWR_ALTERA_AVALON_PIO_DATA(ANGLE_START_BASE, 1);
      while (!angleFlag);
      return IORD_ALTERA_AVALON_PIO_DATA(ANGLE_BASE);
}
示例#12
0
/* Poll one of the switches and send a message to the LCD task */
void taskSW(void* pdata) {
	while (1) {
		if (IORD_ALTERA_AVALON_PIO_DATA(SWITCH_BASE) == 1) {
			err = OSQPost(SWQ, SW_WRITE);
		} else {
			err = OSQPost(SWQ, SW_READ);
		}
		OSTimeDlyHMSM(0, 0, 0, 50);
	}
}
示例#13
0
void getDistances(int * right,int * left,int * back){
  
  do{
      distFlag = 0;
      //set start timing line low
      IOWR_ALTERA_AVALON_PIO_DATA(START_TIME_BASE, 0);
      //send ping command and wait for transfer to complete
      sendChar('P');
      //start timing
      IOWR_ALTERA_AVALON_PIO_DATA(ANGLE_START_BASE, 1);
      //wait for distance measure to finish
      while (!distFlag);
      // Store the distance values
      *left = IORD_ALTERA_AVALON_PIO_DATA(DIST_L_BASE);
      *right = IORD_ALTERA_AVALON_PIO_DATA(DIST_R_BASE);
      *back = IORD_ALTERA_AVALON_PIO_DATA(DIST_B_BASE);
  }while(!(*left&&*right&&*back));
  
}   
示例#14
0
int main() {
	alt_u32 current_value=1;
	alt_u32 current_state=3;
	alt_u8 current_direction=0;
	alt_u32 keys;

	printf("Program running (UART)...\n");
	fprintf(stderr, "Program running (LCD)...\n");

	while (1) {
		//reading the current state of the keys
		keys = IORD_ALTERA_AVALON_PIO_DATA(KEYS_BASE);

		//switching speeds if necessary
		if ((keys != 7) && (keys != current_state)) {
			if (keys == 3){
				printf("speed set to 250 ms\n");
				fprintf(stderr, "\nSpeed set 250 ms");
			}
			else if (keys == 5){
				printf("speed set to 150 ms\n");
				fprintf(stderr, "\nSpeed set 150 ms");
			}
			else if (keys == 6){
				printf("speed set to 50 ms\n");
				fprintf(stderr, "\nSpeed set 50 ms");
			}
			else
				printf("keys != 3, 5, or 6. Stop hitting multiple buttons.");
			current_state = keys;
		}

		//switching direction if necessary
		if ((current_direction == 0) && (current_value == (1 << 25)))
			current_direction = 1;
		else if ((current_direction == 1) && (current_value == 1))
			current_direction = 0;
		//moving the light
		else if (current_direction == 0)
			current_value = current_value << 1;
		else
			current_value = current_value >> 1;
		//updating the lights
		IOWR_ALTERA_AVALON_PIO_DATA(LEDS_BASE, current_value);

		//sleep
		if (current_state == 3)
			usleep(250000);
		else if (current_state == 5)
			usleep(125000);
		else
			usleep(50000);
	}
	return 0;
}
示例#15
0
// Frequency Analyzer VHDL interrupt
void frequency_interrupt_function(void* context, alt_u32 id){

	BaseType_t xHigherPriorityTaskWoken = pdFALSE;
	uint32_t value;

	configASSERT(xTaskToNotify != NULL);
	value = IORD_ALTERA_AVALON_PIO_DATA(FREQUENCY_ANALYSER_BASE);
	xTaskNotifyFromISR( xFreqTask, value, eSetBits, &xHigherPriorityTaskWoken );
	//printf("frequecny ISR %d\n", frequency_value);
	//printf("HANDLE: %d\n",(int)xTaskToNotify);
	portEND_SWITCHING_ISR( xHigherPriorityTaskWoken );
}
示例#16
0
// Function Name: phase2_tightpolling
// Function Purpose: The init() function is first called to set up the EGM.
// 					 A finite for-loop for 100 iterations is started and set
//					 to capture rising and falling edges while trying to run
//					 the background() task after a rising edge has been
// 					 detected. 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_tightpolling(int period, int dutycycle, int granularity)
{
	// Call init() with the period and dutycycle parameters to set up the
	// EGM and iterate 100 times through the code in the for-loop to capture
	// 100 pulses. As explained by the TA Bahaedinne Jlassi in the ECE 224 lab
	// sessions, the for-loop is guaranteed to terminate after capturing 100
	// pulses because the bottom of the for-loop can only be reached after
	// capturing both a rising edge and a falling edge.
	int i;
	init(period, dutycycle);
	for(i=0; i<100; i++)
	{
		// Assume that the initial state of the pulse is at the 0 level.
		// While the detected state is still 0, do nothing. Otherwise, write
		// a '1' to the data register of pio_response to indicate a rising
		// edge.
		while(IORD_ALTERA_AVALON_PIO_DATA(PIO_PULSE_BASE) == 0) {}
		IOWR_ALTERA_AVALON_PIO_DATA(PIO_RESPONSE_BASE, 0x1);

		// After the rising edge has been captured, try running the background
		// task to see the tradeoffs in trying to complete background task
		// units and trying to catch pulses from the EGM at the same time.
		background(granularity);

		// Since it is now assumed that the state of the pulse is now at the
		// 1 level, do nothing while the detected state is still 1. Otherwise,
		// write a '0' to the data register of pio_response to indicate a
		// falling edge. Re-iterate through the for-loop to detect the next
		// pulse.
		while(IORD_ALTERA_AVALON_PIO_DATA(PIO_PULSE_BASE) == 1) {}
		IOWR_ALTERA_AVALON_PIO_DATA(PIO_RESPONSE_BASE, 0x0);
	}
	printf("TIGHT POLLING - PERIOD: %d\t DUTYCYCLE: %d\t GRANULARITY: %d\t\n",
			period, dutycycle, granularity);
	finalize();

	// 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);
}
示例#17
0
//------------------------------------------------------------------------------
UINT8 gpio_getNodeid(void)
{
    UINT8       nodeId;
    UINT32      hpsSwStatus = 0x0;
    UINT32      fpgaSwStatus = 0x0;

    hpsSwStatus = alt_gpio_port_data_read(ALT_GPIO_PORTC, HPS_DIPSW_ALL_BIT_MASK);

#ifdef HOST_0_DIPSW_PIO_BASE
    fpgaSwStatus = IORD_ALTERA_AVALON_PIO_DATA(HOST_0_DIPSW_PIO_BASE);
#endif

    nodeId = (UINT8)((FPGA_DIPSW_NET_VAL(fpgaSwStatus) << HOST_0_DIPSW_PIO_DATA_WIDTH) | HPS_DIPSW_NET_VAL(hpsSwStatus));

    return nodeId;
}
示例#18
0
文件: lab0.c 项目: eriknore/il2206
void pollkey()
{
    int btn_reg;
    btn_reg = IORD_ALTERA_AVALON_PIO_DATA(DE2_PIO_KEYS4_BASE);
    btn_reg = (~btn_reg) & 0xf;
    switch (btn_reg)
    {
    case 1:
        run = !run;
        break;
    case 2:
        tick (&timeloc);
        break;
    case 4:
        timeloc = 0x0000;
        break;
    case 8:
        timeloc = 0x5957;
        break;
    default:
        break;
    }
}
示例#19
0
void welcome()//led welcum
{
	char message[22];
	if(ringbell == 0x01)
	{
		Uart_send_n("AT+CIPSEND=0,21",15);
		Uart_send(0x0d);
    	Uart_send(0x0a);
    	usleep(1000000);
		strcpy(message,"You'v Got A Visitor!!");
		Uart_send_n(message,21);
		Uart_send(0x0d);
		Uart_send(0x0a);


		IOWR_ALTERA_AVALON_PIO_DATA(LEDMODE_BASE, 0x03);
	}
	else
	{
		unsigned int status = IORD_ALTERA_AVALON_PIO_DATA(LEDMODE_BASE);
		IOWR_ALTERA_AVALON_PIO_DATA(LEDMODE_BASE, status&0x02);
	}
}
示例#20
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);
}
int read_program(){
	volatile unsigned char memory[256]={};
	volatile int i;
	volatile uint16_t t;

	//プログラムカウンタリセット、プログラム読み出し動作へ切り替え
	IOWR_ALTERA_AVALON_PIO_DATA(PIO_MODE_SELOUT_BASE, 0x4);
	usleep(20000);
	IOWR_ALTERA_AVALON_PIO_DATA(PIO_KEYOUT_BASE, 0xF);
	usleep(20000);
	IOWR_ALTERA_AVALON_PIO_DATA(PIO_KEYOUT_BASE, 0xD);
	usleep(20000);
	IOWR_ALTERA_AVALON_PIO_DATA(PIO_KEYOUT_BASE, 0xF);
	usleep(20000);
	IOWR_ALTERA_AVALON_PIO_DATA(PIO_MODE_SELOUT_BASE, 0x6);
	usleep(20000);
	for(i=0;i<256;i++){

		IOWR_ALTERA_AVALON_PIO_DATA(PIO_KEYOUT_BASE, 0xE);
		usleep(10000);
		t=IORD_ALTERA_AVALON_PIO_DATA(PIO_DATAIN_BASE);
		IOWR_ALTERA_AVALON_PIO_DATA(PIO_KEYOUT_BASE, 0xF);
		usleep(10000);

		memory[i]=(t & 0x000F)|(t & 0x00F0);
		//alt_printf("%x ",i);
	}

	for(i=0;i<256;i++){
		alt_printf("%x,",memory[i]);
	}

	IOWR_ALTERA_AVALON_PIO_DATA(PIO_MODE_SELOUT_BASE, 0x0);
	IOWR_ALTERA_AVALON_PIO_DATA(PIO_KEYOUT_BASE, 0x0);
	return 0;
}
示例#22
0
int main()
{

  int count = 1;
  int delay;
  int aux;



  FILE *fp_UART=0;

  FILE *fp_LCD=0;


  fp_UART = fopen(UART_NAME,"w"); // open UART for write
  fp_LCD = fopen(LCD_NAME,"w"); // open LCD for write

  if(fp_LCD==0) {
	  printf("\nError Opening %s\n\n",LCD_NAME);
  }
  else {
	  printf("LCD opened, ready for access\n");
  	  fprintf(fp_LCD,"Primer mensaje");
  }

  if(fp_UART==0) {
	  printf("\nError Opening %s\n\n",UART_NAME);
  }
  else {
	  printf("UART opened, ready for access\n");

  }

  printf("Hello from Nios 15!\n");

  //fprintf(fp_UART,"--------------------------\r\n");

  fprintf(fp_LCD,"Hola guapo");

  while(1) {
	  //aux=IORD_ALTERA_AVALON_PIO_DATA(PIO_SW_BASE);

	  //IOWR_ALTERA_AVALON_PIO_DATA(PIO_LEDR_BASE, aux);

	  if (IORD_ALTERA_AVALON_PIO_DATA(PIO_RDYDATA_BASE) == 1) { // !Empty
		  IOWR_ALTERA_AVALON_PIO_DATA(PIO_DATAREAD_BASE, 0x02); //Enable
		  IOWR_ALTERA_AVALON_PIO_DATA(PIO_DATAREAD_BASE, 0x03); //ENABLE +CLCK
		  IOWR_ALTERA_AVALON_PIO_DATA(PIO_DATAREAD_BASE, 0x00);
		  aux=IORD_ALTERA_AVALON_PIO_DATA(PIO_DATA_BASE);
		  fprintf(fp_UART,"%d\r\n",aux);
		  fprintf(fp_LCD,"D: %d N: %d\r\n\r\n", aux , count);
		  count++;
	  }


	 IOWR_ALTERA_AVALON_PIO_DATA(PIO_DATAREAD_BASE, 0x01);
	 IOWR_ALTERA_AVALON_PIO_DATA(PIO_DATAREAD_BASE, 0x00);  //0x00 clock



	 // printf("Laura es gorrina %d!\n",count);
	//  fprintf(fp,"%s:%d%s","Hola UART",count,"\n");
  }

 // fclose (fp);

  return 0;
}
示例#23
0
void playSong(void* pdata)
{
    
    fprintf(lcd, "%c%s", esc, LCD_CLR);
    fprintf(lcd, "%c%s%s\n", esc, TOP_LINE, "KEYBOARD MODE");
    fprintf(lcd, "%c%s%s\n", esc, BOTTOM_LINE, "KEYBOARD MODE");
    
    while (1)
    {
    INT8U err;
    OSSemPend(songSem,0,&err);
    fprintf(lcd, "%c%s", esc, LCD_CLR);
    fprintf(lcd, "%c%s%s\n", esc, TOP_LINE, "NOW PLAYING TETRIS THEME A");
    fprintf(lcd, "%c%s%s\n", esc, BOTTOM_LINE, "NOW PLAYING TETRIS THEME A");
    
    INT8U value = IORD_ALTERA_AVALON_PIO_DATA(SWITCHES_BASE);
    
    if (value & 1)
    {
    if (err==OS_ERR_PEVENT_NULL){
        printf("PEVENT NULL");
    }
    if (err==OS_ERR_EVENT_TYPE){
        printf("EVENT TYPE");
    }
    if (err) printf("%d, %d", err, OS_NO_ERR);
    int note0[] = { 71,-1,68,69,71,-1,69,67,
                    64,-1,64,69,72,-1,71,69,
                    68,-1,-1,69,71,-1,72,-1,
                    69,-1,64,-1,64,-1,-1,-1,
                    0,65,-1,69,72,-1,71,69,
                    67,-1,-1,64,67,-1,65,64,
                    68,-1,-1,69,71,-1,72,-1,
                    69,-1,64,-1,64,-1,0,0   };   
    int note1[] = { 76,-1,76,72,74,-1,72,71,
                    69,-1,69,72,76,-1,74,72,
                    71,-1,-1,72,74,-1,76,-1,
                    72,-1,69,-1,69,-1,-1,-1,
                    0,74,-1,77,81,-1,79,77,
                    76,-1,-1,72,76,-1,74,72,
                    71,-1,-1,72,74,-1,76,-1,
                    72,-1,69,-1,69,-1,0,0};  
    int i;
    for (i=0;i<64;i++){
        if (note0[i] == -1){
            //do nothing
        }else if (note0[i] == 0){
            *note_table[0] = 0;   
        }else{
            *note_table[0] = (120 << 12) | (INT8U) note0[i];
        }
        if (note1[i] == -1){
            //do nothing
        }else if (note1[i] == 0){
            *note_table[1] = 0;   
        }else{
            *note_table[1] = (120 << 12) | (INT8U) note1[i];
        }
        OSTimeDlyHMSM(0, 0, 0, 250);
    }
    for (i=0;i<64;i++){
        if (note0[i] == -1){
            //do nothing
        }else if (note0[i] == 0){
            *note_table[0] = 0;   
        }else{
            *note_table[0] = (120 << 12) | (INT8U) note0[i];
        }
        if (note1[i] == -1){
            //do nothing
        }else if (note1[i] == 0){
            *note_table[1] = 0;   
        }else{
            *note_table[1] = (120 << 12) | (INT8U) note1[i];
        }
        OSTimeDlyHMSM(0, 0, 0, 250);
    }
    }
    
    fprintf(lcd, "%c%s", esc, LCD_CLR);
    fprintf(lcd, "%c%s%s\n", esc, TOP_LINE, "KEYBOARD MODE");
    fprintf(lcd, "%c%s%s\n", esc, BOTTOM_LINE, "KEYBOARD MODE");
    
    OSSemPend(songSem,0,&err);
    fprintf(lcd, "%c%s%s\n", esc, TOP_LINE, "NOW PLAYING STAIRWAY TO HEAVEN");
    fprintf(lcd, "%c%s%s\n", esc, BOTTOM_LINE, "NOW PLAYING STAIRWAY TO HEAVEN");
    
    if (value & 1)
    {
    if (err==OS_ERR_PEVENT_NULL){
        printf("PEVENT NULL");
    }
    if (err==OS_ERR_EVENT_TYPE){
        printf("EVENT TYPE");
    }
    if (err) printf("%d, %d", err, OS_NO_ERR);
    int note0[] = {0,60,64,69,71,64,60,71,
                    72,64,60,72,66,62,57,66,
                    64,60,57,60,-1,64,60,57,
                    55,57,57,-1,-1,-1,0,0,
                    0,60,64,69,71,64,60,71,
                    72,64,60,72,66,62,57,66,
                    64,60,57,60,-1,64,60,57,
                    55,57,57,-1,-1,-1,0,0,
                    -1,52,55,64,66,62,57,65,
                    64,60,57,64,62,60,-1,-1,
                    60,55,52,60,67,59,55,67,
                    57,57,57,-1,-1,-1,0,0};   
    int note1[] = {57,-1,-1,-1,56,-1,-1,-1,
                    55,-1,-1,-1,54,-1,-1,-1,
                    53,-1,-1,-1,-1,-1,-1,-1,
                    47,45,45,-1,-1,45,53,52,
                    45,-1,-1,-1,56,-1,-1,-1,
                    55,-1,-1,-1,54,-1,-1,-1,
                    53,-1,-1,-1,-1,-1,-1,-1,
                    47,45,45,-1,-1,-1,45,47,
                    48,-1,-1,-1,50,-1,-1,-1,
                    53,-1,-1,-1,45,-1,45,47,
                    48,-1,-1,-1,43,-1,-1,-1,
                    50,50,50,-1,-1,-1,0,0};  
    int i;
    for (i=0;i<96;i++){
        if (note0[i] == -1){
            //do nothing
        }else if (note0[i] == 0){
            *note_table[0] = 0;   
        }else{
            *note_table[0] = (120 << 12) | (INT8U) note0[i];
        }
        if (note1[i] == -1){
            //do nothing
        }else if (note1[i] == 0){
            *note_table[1] = 0;   
        }else{
            *note_table[1] = (120 << 12) | (INT8U) note1[i];
        }
        OSTimeDlyHMSM(0, 0, 0, 600);
    }
    }
    fprintf(lcd, "%c%s", esc, LCD_CLR);
    fprintf(lcd, "%c%s%s\n", esc, TOP_LINE, "KEYBOARD MODE");
    fprintf(lcd, "%c%s%s\n", esc, BOTTOM_LINE, "KEYBOARD MODE");
    }
}
示例#24
0
文件: lab3.c 项目: jibinbabu/jibcode
/********************************************************************************
 * This program demonstrates use of the Ethernet in the DE2i-150 board.
********************************************************************************/
int main(void){

	// Open the sgdma transmit device
	sgdma_tx_dev = alt_avalon_sgdma_open ("/dev/sgdma_tx");
	if (sgdma_tx_dev == NULL) {
		alt_printf ("Error: could not open scatter-gather dma transmit device\n");
		//return -1;
	} else alt_printf ("Opened scatter-gather dma transmit device\n");

	// Open the sgdma receive device
	sgdma_rx_dev = alt_avalon_sgdma_open ("/dev/sgdma_rx");
	if (sgdma_rx_dev == NULL) {
		alt_printf ("Error: could not open scatter-gather dma receive device\n");
		//return -1;
	} else alt_printf ("Opened scatter-gather dma receive device\n");



	// Set interrupts for the sgdma receive device
	alt_avalon_sgdma_register_callback( sgdma_rx_dev, (alt_avalon_sgdma_callback) rx_ethernet_isr, 0x00000014, NULL );

	// Create sgdma receive descriptor
	alt_avalon_sgdma_construct_stream_to_mem_desc( &rx_descriptor, &rx_descriptor_end, (alt_u32 *)rx_frame, 0, 0 );

	// Set up non-blocking transfer of sgdma receive descriptor
	alt_avalon_sgdma_do_async_transfer( sgdma_rx_dev, &rx_descriptor );



	// Triple-speed Ethernet MegaCore base address
	volatile int * tse = (int *) TSE_BASE;

	// Specify the addresses of the PHY devices to be accessed through MDIO interface
	*(tse + 0x0F) = 0x10;

	// Disable read and write transfers and wait
	*(tse + 0x02) = *(tse + 0x02) | 0x00800220;
	while ( *(tse + 0x02) != ( *(tse + 0x02) | 0x00800220 ) );


	//MAC FIFO Configuration
	*(tse + 0x09 ) = TSE_TRANSMIT_FIFO_DEPTH-16;
	*(tse + 0x0E ) = 3;
	*(tse + 0x0D ) = 8;
	*(tse + 0x07 ) =TSE_RECEIVE_FIFO_DEPTH-16;
	*(tse + 0x0C ) = 8;
	*(tse + 0x0B ) = 8;
	*(tse + 0x0A ) = 0;
	*(tse + 0x08 ) = 0;

	// Initialize the MAC address
	*(tse + 0x03) = 0x17231C00;
	*(tse + 0x04) = 0x0000CB4A;

	// MAC function configuration
	*(tse + 0x05) = 1518;
	*(tse + 0x17) = 12;
	*(tse + 0x06) = 0xFFFF;
	*(tse + 0x02) = 0x00800220;


	// Software reset the PHY chip and wait
	*(tse + 0x02) =  0x00802220;
	while ( *(tse + 0x02) != ( 0x00800220 )  ) alt_printf( "Hi" );

	// Enable read and write transfers, gigabit Ethernet operation and promiscuous mode
	
	*(tse + 0x02) = *(tse + 0x02) | 0x0080023B;

	while ( *(tse + 0x02) != ( *(tse + 0x02) | 0x0080023B ) ) ;


	while (1) {

		print=in;
		in= IORD_ALTERA_AVALON_PIO_DATA(SWITCH_BASE); //read the input from the switch
		IOWR_ALTERA_AVALON_PIO_DATA(LED_BASE, in); //switch on or switch off the LED

		if (in==1){

			if (print != in){
				IOWR_ALTERA_AVALON_PIO_DATA(LED_BASE, 0x0100);
				alt_printf( "Switch on LED \n" );		
			}
		}
		else{
			if (print != in) {
				IOWR_ALTERA_AVALON_PIO_DATA(LED_BASE, 0x0000);
				alt_printf( "Switch off LED \n" );
			}
		}
	}

	return 0;
}
示例#25
0
int main()
{

    int count = 1;
    int delay;
    int aux;



    FILE *fp_UART=0;

    FILE *fp_LCD=0;


    fp_UART = fopen(UART_NAME,"w"); // open UART for write
    fp_LCD = fopen(LCD_NAME,"w"); // open LCD for write

    if(fp_LCD==0) {
        printf("\nError Opening %s\n\n",LCD_NAME);
    }
    else {
        printf("LCD opened, ready for access\n");
        fprintf(fp_LCD,"Primer mensaje");
    }

    if(fp_UART==0) {
        printf("\nError Opening %s\n\n",UART_NAME);
    }
    else {
        printf("UART opened, ready for access\n");

    }

    printf("Hello from Nios 11!\n");

    fprintf(fp_UART,"--------------------------\r\n");

    while(1) {
        aux=IORD_ALTERA_AVALON_PIO_DATA(PIO_SW_BASE);

        IOWR_ALTERA_AVALON_PIO_DATA(PIO_LEDR_BASE, aux);

        // delay = 0;
        //while(delay < 3000000) {
        //	  delay++;
        // }

        if (IORD_ALTERA_AVALON_PIO_DATA(PIO_RDYDATA_BASE) == 1) {
            IOWR_ALTERA_AVALON_PIO_DATA(PIO_DATAREAD_BASE, 0x02);
            IOWR_ALTERA_AVALON_PIO_DATA(PIO_DATAREAD_BASE, 0x03);
            IOWR_ALTERA_AVALON_PIO_DATA(PIO_DATAREAD_BASE, 0x00);
            aux=IORD_ALTERA_AVALON_PIO_DATA(PIO_DATA_BASE);
            fprintf(fp_UART,"Dato: %d  \t Nuemro de dato: %d\r\n", aux , count);
            fprintf(fp_LCD,"D: %d N: %d\r\n\r\n", aux , count);
            if (count % 16 == 0) {
                fprintf(fp_UART,"--------------------------\r\n");
            }
            count++;
        }


        IOWR_ALTERA_AVALON_PIO_DATA(PIO_DATAREAD_BASE, 0x01);
        IOWR_ALTERA_AVALON_PIO_DATA(PIO_DATAREAD_BASE, 0x00);



        // printf("Laura es gorrina %d!\n",count);
        //  fprintf(fp,"%s:%d%s","Hola UART",count,"\n");
    }

// fclose (fp);

    return 0;
}
示例#26
0
int openPowerlink(void)
{
    const BYTE              abMacAddr[] = {MAC_ADDR};
    static tEplApiInitParam EplApiInitParam = {0};
	// needed for process var
	tEplObdSize         	ObdSize;
	tEplKernel 				EplRet;
	unsigned int			uiVarEntries;

    fShutdown_l = FALSE;

	////////////////////////
	// setup th EPL Stack //
	////////////////////////

	// set EPL init parameters
    EplApiInitParam.m_uiSizeOfStruct = sizeof (EplApiInitParam);

#ifdef NODESWITCH_SPI_BASE
    // read node-ID from hex switch on baseboard, which is connected via SPI shift register
    IOWR_ALTERA_AVALON_SPI_TXDATA(NODESWITCH_SPI_BASE, 0xFF);   // generate pulse for latching inputs
    while ((IORD_ALTERA_AVALON_SPI_STATUS(NODESWITCH_SPI_BASE) & ALTERA_AVALON_SPI_STATUS_RRDY_MSK) == 0)
    {   // wait
    }
    EplApiInitParam.m_uiNodeId = IORD_ALTERA_AVALON_SPI_RXDATA(NODESWITCH_SPI_BASE);
#endif
#ifdef NODESWITCH_PIO_BASE
    EplApiInitParam.m_uiNodeId = IORD_ALTERA_AVALON_PIO_DATA(NODESWITCH_PIO_BASE);
#endif

    if (EplApiInitParam.m_uiNodeId == EPL_C_ADR_INVALID)
    {
        EplApiInitParam.m_uiNodeId = NODEID; // defined at the top of this file!
    }

    EPL_MEMCPY(EplApiInitParam.m_abMacAddress, abMacAddr, sizeof(EplApiInitParam.m_abMacAddress));
    EplApiInitParam.m_abMacAddress[5] = (BYTE) EplApiInitParam.m_uiNodeId;

    // calculate IP address
    EplApiInitParam.m_dwIpAddress = (0xFFFFFF00 & IP_ADDR) | EplApiInitParam.m_uiNodeId;
	EplApiInitParam.m_uiIsochrTxMaxPayload = 256;
	EplApiInitParam.m_uiIsochrRxMaxPayload = 256;
	EplApiInitParam.m_dwPresMaxLatency = 2000;
	EplApiInitParam.m_dwAsndMaxLatency = 2000;
	EplApiInitParam.m_fAsyncOnly = FALSE;
	EplApiInitParam.m_dwFeatureFlags = -1;
	EplApiInitParam.m_dwCycleLen = CYCLE_LEN;
	EplApiInitParam.m_uiPreqActPayloadLimit = 36;
	EplApiInitParam.m_uiPresActPayloadLimit = 36;
	EplApiInitParam.m_uiMultiplCycleCnt = 0;
	EplApiInitParam.m_uiAsyncMtu = 1500;
	EplApiInitParam.m_uiPrescaler = 2;
	EplApiInitParam.m_dwLossOfFrameTolerance = 500000;
	EplApiInitParam.m_dwAsyncSlotTimeout = 3000000;
	EplApiInitParam.m_dwWaitSocPreq = 0;
	EplApiInitParam.m_dwDeviceType = -1;
	EplApiInitParam.m_dwVendorId = -1;
	EplApiInitParam.m_dwProductCode = -1;
	EplApiInitParam.m_dwRevisionNumber = -1;
	EplApiInitParam.m_dwSerialNumber = -1;
	EplApiInitParam.m_dwSubnetMask = SUBNET_MASK;
	EplApiInitParam.m_dwDefaultGateway = 0;
    EplApiInitParam.m_dwApplicationSwDate = 1;       // PDL_LocVerApplSw_REC.ApplSwDate_U32 on programmable device or date portion of NMT_ManufactSwVers_VS on non-programmable device
	EplApiInitParam.m_pfnCbEvent = AppCbEvent;
    EplApiInitParam.m_pfnCbSync  = AppCbSync;
    EplApiInitParam.m_pfnObdInitRam = EplObdInitRam;
    EplApiInitParam.m_dwSyncResLatency = EPL_C_DLL_T_IFG;

	// initialize EPL stack
    printf("init EPL Stack with node-ID 0x%02X:\n", EplApiInitParam.m_uiNodeId);
	EplRet = EplApiInitialize(&EplApiInitParam);
	if(EplRet != kEplSuccessful) {
        printf("init EPL Stack... error %X\n\n", EplRet);
		goto Exit;
    }
    printf("init EPL Stack...ok\n\n");

	// link process variables used by CN to object dictionary
    printf("linking process vars:\n");
    ObdSize = sizeof(bButtonInputs_l);
    uiVarEntries = 1;
    EplRet = EplApiLinkObject(0x6000, &bButtonInputs_l, &uiVarEntries, &ObdSize, 0x01);
    if (EplRet != kEplSuccessful)
    {
        printf("linking process vars... error\n\n");
        goto ExitShutdown;
    }

    ObdSize = sizeof(abVirtualInputs_l[0]);
    uiVarEntries = 17;
    EplRet = EplApiLinkObject(0x2000, abVirtualInputs_l, &uiVarEntries, &ObdSize, 0x01);
    if (EplRet != kEplSuccessful)
    {
        printf("linking process vars... error\n\n");
        goto ExitShutdown;
    }

    ObdSize = sizeof(adwVirtualInputs_l[0]);
    uiVarEntries = 8;
    EplRet = EplApiLinkObject(0x2001, adwVirtualInputs_l, &uiVarEntries, &ObdSize, 0x01);
    if (EplRet != kEplSuccessful)
    {
        printf("linking process vars... error\n\n");
        goto ExitShutdown;
    }

    ObdSize = sizeof(wDigitalOutputs_l);
    uiVarEntries = 1;
    EplRet = EplApiLinkObject(0x6300, &wDigitalOutputs_l, &uiVarEntries, &ObdSize, 0x01);
    if (EplRet != kEplSuccessful)
    {
        printf("linking process vars... error\n\n");
        goto ExitShutdown;
    }

    ObdSize = sizeof(bLedOutputs_l);
    uiVarEntries = 1;
    EplRet = EplApiLinkObject(0x6200, &bLedOutputs_l, &uiVarEntries, &ObdSize, 0x01);
    if (EplRet != kEplSuccessful)
    {
        printf("linking process vars... error\n\n");
        goto ExitShutdown;
    }

    ObdSize = sizeof(abVirtualOutputs_l[0]);
    uiVarEntries = 15;
    EplRet = EplApiLinkObject(0x2200, abVirtualOutputs_l, &uiVarEntries, &ObdSize, 0x01);
    if (EplRet != kEplSuccessful)
    {
        printf("linking process vars... error\n\n");
        goto ExitShutdown;
    }

    ObdSize = sizeof(adwVirtualOutputs_l[0]);
    uiVarEntries = 8;
    EplRet = EplApiLinkObject(0x2201, adwVirtualOutputs_l, &uiVarEntries, &ObdSize, 0x01);
    if (EplRet != kEplSuccessful)
    {
        printf("linking process vars... error\n\n");
        goto ExitShutdown;
    }
	printf("linking process vars... ok\n\n");

	// start the EPL stack
    printf("start EPL Stack...\n");
	EplRet = EplApiExecNmtCommand(kEplNmtEventSwReset);
    if (EplRet != kEplSuccessful) {
        printf("start EPL Stack... error\n\n");
        goto ExitShutdown;
    }
    printf("start EPL Stack... ok\n\n");

    printf("NIOS II with openPowerlink is ready!\n\n");

#ifdef LED_PIO_BASE
    IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, 0xFF);
#endif

    while(1)
    {
        EplApiProcess();
        if (fShutdown_l == TRUE)
            break;
    }

ExitShutdown:
    printf("Shutdown EPL Stack\n");
    EplApiShutdown(); //shutdown node

Exit:
	return EplRet;
}
int switches_pressed(void)
{
  return IORD_ALTERA_AVALON_PIO_DATA(DE2_PIO_TOGGLES18_BASE);    
}
示例#28
0
void test_alarm_en()
{

	alarm_en = IORD_ALTERA_AVALON_PIO_DATA(ALARM_EN_BASE)&0x01;
}
示例#29
0
void test_alarm()
{

	alarm = IORD_ALTERA_AVALON_PIO_DATA(ALARM_BASE)&0x01;
}
示例#30
0
/*
void led_init()
{
	unsigned int led_data;
	unsigned int i;

	//led_data = 0x01;
	//IOWR_ALTERA_AVALON_PIO_DATA(LED18_OUT_BASE,led_data);
	for(i=0;i<18;i++)
		{
			led_data = 0x01 << i;
			//led_data = 0xff;
			IOWR_ALTERA_AVALON_PIO_DATA(LED18_OUT_BASE,led_data);
			usleep(500000);
		}

}
*/
void test_key()//refreshing the key val
{

	ringbell = IORD_ALTERA_AVALON_PIO_DATA(SIGTAP_BASE)&0x01;
}