Пример #1
0
static void led_display(){
	alt_16 switch_value = 0;
	int i = 0;
	switch_value = ReadSwitches();
	_Bool press_flag = true;
	edge_capture = 0;
	init_button_pio();
	while(1 == 1){
		if(edge_capture && press_flag){
			press_flag = false;
			edge_capture = 0;
			switch_value = ReadSwitches();
			/*displaying switches' value to LED or seven-segment*/
			for(i = 0; i < 8; i ++){
				if (edge_capture && !press_flag){//get interruption from button release
					edge_capture = 0;
					press_flag = true;
				}else if(edge_capture)//get interruption from reseting the switches
					break;
				/*If the next bit is 1 then turn on the led*/
				if (switch_value & 1)
					LED_on();
				else
				/*If the next bit is 0 then turn off the led*/
					LED_off();
				switch_value >>=  1;
			}
			LED_off();
		}else if(edge_capture){//get interruption from button release
Пример #2
0
void init_interrupts()
{

	init_button_pio();
	init_dma0();

	//init_jtag_uart();
}
Пример #3
0
static void TestButtons( void )
{
  volatile alt_u8 led;
  int read_result = 0;
  _Bool flag = true;
  /* Variable which holds the last value of edge_capture to avoid
   * "double counting" button/switch presses
   */
  /* Initialize the Buttons/Switches (SW0-SW3) */
  init_button_pio();
  edge_capture = 0;
  led = 0x0;

  while (1 == 1)
  {
	  read_result = IORD(LED_PIO_BASE,0);

      switch (edge_capture)
      {
        case 0x1:
        	//if flag == true
        	if(read_result && flag){
        		printf("1pressed button1 and edge_capture = %d.\n",edge_capture);
        		led = 0x0;
        		edge_capture = 0;
        		IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, led);
        		flag = false;
        	}

        	else if(flag){
        		printf("2pressed button1 and edge_capture = %d.\n",edge_capture);
        		led = 0x1;
        		IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, led);
        		edge_capture = 0;
        		flag = false;
        	//	usleep(1000000);
        	}
        	else{
        		flag = true;
        		edge_capture = 0;
        	}

          break;
          /*You can add other button controllers here
           *  with case 0x2, case 0x4, case 0x8
           * */
      }
  }
  /* Disable the button pio. */
  disable_button_pio();
  usleep(2000000);
  return;
}
Пример #4
0
/*
 * SSSSimpleSocketServerTask()
 * 
 * This MicroC/OS-II thread spins forever after first establishing a listening
 * socket for our sss connection, binding it, and listening. Once setup,
 * it perpetually waits for incoming data to either the listening socket, or
 * (if a connection is active), the sss data socket. When data arrives, 
 * the approrpriate routine is called to either accept/reject a connection 
 * request, or process incoming data.
 */
void SSSSimpleSocketServerTask()
{
  // Объявления используемых переменных
	int errcode;
	int is_alive;
	int flag_exit = 0;
	char buffer_in[1024];
	char buffer_out[3] = {'1','\r','\n'};
	int len_buff = 1024;
	int fd_listen;
	struct sockaddr_in addr;
	edge_capture = 0xF;

    // Регистрируем обработчик прерываний от кнопок
	init_button_pio();

  while (1)
  {
	  // Создаем сокет, если не удалось создать, выдаем сообщение в консоль
	  if ((fd_listen = socket(AF_INET, SOCK_STREAM, 0)) < 0)
	  {
	      alt_NetworkErrorHandler(EXPANDED_DIAGNOSIS_CODE,"[sss_task] Socket creation failed");
	  }
	  // Инициализируем структуру sockaddr_in, указав семейство адресов,
	  // IP-адрес и номер порта серверного приложения
	  // (для примера см. simple_socket_server)
	  addr.sin_family = AF_INET;
	  addr.sin_port = htons(SSS_PORT);
	  addr.sin_addr.s_addr = inet_addr("192.168.21.171");

	  // Устанавливаем соединение с сервером
	  errcode = connect(fd_listen, (struct sockaddr *)&addr, sizeof(addr));
	  if (errcode)
	  {
		  printf("Unable to connect to server!\n");
		  return;
	  }

	  // Получаем меню от сервера, выводим в консоль
	  errcode = recv(fd_listen, &buffer_in, len_buff, 0);
	  if (errcode == SOCKET_ERROR)
	  {
		  printf("Unable to get data from server!\n");
	 	  return;
	  }

	  printf(buffer_in);

	  is_alive = 1;
	  do
	  {
		  // Ожидаем сообщение о нажатии кнопки от обработчика прерывания

		  if (edge_capture != NONE_PRESSED)  // if button pressed
		  {
			  switch(edge_capture) {
		      	  case (BTN_RIGHT_PRESSED):
		      			buffer_out[0] = 'q';
		      	  	  	flag_exit = 1;
		      	  	  	break;
		          case (BTN_LEFT_PRESSED):
						buffer_out[0] = '1';
		        		break;
		          case (BTN_CNTR_LEFT):
						buffer_out[0] = '2';
		                break;
		          case (BTN_CNTR_RIGHT):
						buffer_out[0] = '3';
		        		break;
		      }


		  // Отправляем соответствующую команду на сервер
		  errcode = send(fd_listen, &buffer_out, 3, 0);
      	  if (errcode == SOCKET_ERROR)
      	  {
      		  printf("Unable to send data to server!\n");
      		  return;
      	  }
	       edge_capture = 0xF;
		  // Если была отправлена команда 'q', выходим из внутреннего
		  // цикла
	      if (flag_exit) {
	    	  flag_exit = 0;
	    	  break;
	      }
	      // В противном случае получаем ответ от сервера, выводим его
		  // в консоль
	      errcode = recv(fd_listen, &buffer_in, len_buff, 0);
	      if (errcode == SOCKET_ERROR)
	      {
	    	  printf("Unable to get data from server!\n");
	      	  return;
	      }
	      printf(buffer_in);
		  }
	  }
	  while (is_alive);

	  // Разрываем соединение
	  errcode = socketclose(fd_listen);
	  if (errcode == SOCKET_ERROR)
	  {
		  printf("Unable to close connection!\n");
	  	  return;
	  }

	  printf("Connection closed.\n");

	  // Ожидаем сообщение о нажатии кнопки от обработчика прерывания
	  // Перед повторным установлением соединения
	  while (edge_capture == NONE_PRESSED);
  } /* while (1) */

}
Пример #5
0
int main()
{
  //Initialize Functions
  SD_card_init();
  init_mbr();
  init_bs();
  init_audio_codec();

  //Setup Push Buttons
  init_button_pio();


  // Initialize Variables
  bytePerCluster = BPB_BytsPerSec * BPB_SecPerClus;

  //play_music(0 , 1);
  //play_music(0 , 2);
  //play_music(0 , 3);
  //play_music(5 , 4);

  stop_flag = 1;
  file_number = 0;
  init_music();
  delay_cnt = 0;
  delay_flag = 0;

  while(1){
	  if(stop_flag == 0){

		  if(edge_capture == 0x01){
			  //stop music
			  stop_flag = 1;
		  }

		  else if(edge_capture == 0x02){
			  // play music
			  delay_cnt = 0;
			  delay_flag = 0;
			  play_type = IORD(SWITCH_PIO_BASE, 0) & 0x07;
			  LCD_Display(returnData.Name, play_type);
			  play_music(play_type);
		  }

		  else if(edge_capture == 0x04){
			  printf("File Number is %d\n",file_number);
			  init_music();
			  usleep(250000);
		  }

		  else if(edge_capture == 0x08){
			  if(file_number < 2 )
				  file_number = 0;
			  else
				  file_number -= 2;

			  init_music();
		  }
	  }
  }

  return 0;
}
Пример #6
0
int main(void)
{
	// open the Character LCD port
	char_lcd_dev = alt_up_character_lcd_open_dev ("/dev/LCD");
	/* Initialize the character display */
	alt_up_character_lcd_init(char_lcd_dev);


	// Initially writes the start time of timer to lcd
	write_time_to_buffer(top_row, seconds, minutes, hours, am_pm_mode);
	hex_write_date(month, day, year);
	
	// Initialize the switches
	int * sw_ptr = (int *) SW_BASE;
	int sw_values;
	int oldvalue = 0x00000000;
	
	// Masks for individual switches
	int MASK_17 = 0x00020000;
	int MASK_16 = 0x00010000;
	int MASK_1 = 0x00000002;
	int MASK_0 = 0x00000001;
	
	int is_fast = 0; //use to tell other function if sped up, 0 = slow, 1 = fast
	int clk_modify = 0; //if 0, clock isn't being changed, if 1 clock is being changed
	int alarm_modify = 0; //if 0 alarm isn't being changed, if 1, alarm is being changed
	
	// Initialize the Timers
	init_timer_0(&tenths);
	
	// Tracker to see when the time changes
	int old_tenths = 0;
	
	// Initialize the KEY port
	init_button_pio();
	
	// continually 
	while(1)  {
		// check the state of the context integer updated by various ISR functions	
		// Act accordingly, which means
		
		// Update the switch_values
		sw_values = *(sw_ptr);
		
		//check if sw17 is up and if it is, then speed up the timer
		if((sw_values & MASK_17) == 0x00020000 && oldvalue == 0x00000000){
			speed_up();
			oldvalue = sw_values & MASK_17;
			is_fast = 1;
		}
		//check if sw17 is down and if it is then slow down the timer
		else if ((sw_values & MASK_17) == 0x00000000 && oldvalue == 0x00020000) { 
			slow_down(); 
			oldvalue = sw_values & MASK_17;
			is_fast = 0;
		}
		
		// Allow user to change the time if SW0 is up
		if((sw_values & MASK_0) == 0x00000001){ 
			clk_modify = 1;
		}
		else{ 
			clk_modify = 0;
		}
		
		// Buttons increment the hours, minutes, and seconds, respectively to Key3, Key2, and Key1
		if(clk_modify == 1 && alarm_modify == 0 && alarm == 0){
			// Handle if a key was pressed
			if (edge_capture) {
				handle_key_press_time();
			}
		}
		
		// Allow user to change the alarm if SW1 is up
		if((sw_values & MASK_1) == 0x00000002){
			alarm_modify = 1;
			alt_up_character_lcd_set_cursor_pos(char_lcd_dev, 0, 1);
			alt_up_character_lcd_string(char_lcd_dev, bot_row);
		}
		else{ 
			alarm_modify = 0;
			alt_up_character_lcd_set_cursor_pos(char_lcd_dev, 0, 1);
			alt_up_character_lcd_string(char_lcd_dev, "                ");
		}
		
		// Buttons increment the hours, minutes, and seconds, respectively to Key3, Key2, and Key1
 		if(alarm_modify == 1 && clk_modify == 0 && alarm == 0){
			// Handle if a key was pressed
			if (edge_capture) {
				handle_key_press_alarm_set();
			}
		}
		
		// Check if alarm should go off yet
		if(hours == alarm_hours && minutes == alarm_minutes && seconds == 0){ 
			alarm = 1; 
			init_timer_1(&half_second);
		}
		
		// While alarm is going off
		if( alarm == 1 ){
			if (half_second % 2) {
				// Turn hex on
				hex_on();
			}
			else {
				// Turn hex off
				hex_off();
			}
			if( edge_capture) {
				handle_key_press_alarm();
			}
		} 
		else { stop_timer_1(); }

		// Check SW16 for "AM_PM" enable or "24" mode enable
		//		If the switch is enabled, then we turn on 24 hour mode
		//		Else we turn on AM / PM Mode
		// TODO: Optimize so that it doesn't assign something every loop cycle. Maybe we could slim it down
		if((sw_values & MASK_16) == MASK_16 ) {
			am_pm_mode = 0;
		}
		else {
			am_pm_mode = 1;
		}
		
		// Update the clock
		if (tenths != old_tenths) {
			// Call the util.h function to update the time
			update_time(top_row, &old_tenths, &tenths, &seconds, &minutes, &hours, &day, &month, &year, am_pm_mode, 0);

			// Write the updated time to the display
			alt_up_character_lcd_set_cursor_pos(char_lcd_dev, 0, 0);
			alt_up_character_lcd_string(char_lcd_dev, top_row);
		}
		
	}
	
	return 0;
}