int main(){
	alt_putstr("Hello from Nios II!\n");

	printf("Enter 'G' to begin...");

	char input = alt_getchar();

	while ('G' != input) {
		input = alt_getchar();
	}

	if (input == 'G') {
		printf("You're in!");
		/* Event loop never exits. */
		while (1){
			if (*switches & 0x01) {
				*leds = (~(*switches)) | ((*switches) & (0x01));
			}
			else {
				*leds = *switches;
			}
		}
	}
	return 0;
}
Exemple #2
0
int getPlayerNum() {
	alt_putstr("Are you player 1 or player 2? \n");
	int num = alt_getchar();
	if (num == '\n') {
		num = alt_getchar();
	}

	return num;
}
int main()
{ 


	volatile uint16_t t;
	volatile uint16_t buff[2] = {0,0};

	IOWR_ALTERA_AVALON_PIO_DATA(PIO_MODE_SELOUT_BASE, 0x0);
	IOWR_ALTERA_AVALON_PIO_DATA(PIO_KEYOUT_BASE, 0x7);
	//alt_putstr("Hello from Nios II!\n");
	/* Event loop never exits. */

	while (1) {
		t = alt_getchar();
		//alt_printf("%x",t);
		buff[1] = buff[0];
		buff[0] = t;

		if(buff[1] == 'W' && buff[0] == 'R'){
			//alt_putstr("write start\n");
			write_program();
		}
		else if(buff[1] == 'R' && buff[0] == 'D'){
			//alt_putstr("read start\n");
			read_program();
		}

	}
	return 0;
}
int main()
{ 
	alt_putstr("Hello from Nios II!\n");
	alt_putstr("Input the char you would like to send.\n");
	alt_putchar(*parallel_in);
	alt_putstr("\n");
	int c = alt_getchar();
	alt_putstr("\n");

	*transmit_enable = 0x0;
	*load = 0x0;
	*parallel_out = c;
	usleep(1000);
	*transmit_enable = 0x1;
	*load = 0x1;
	usleep(50);
	*load = 0x0;

	while (!*char_sent) {
	}
	*transmit_enable = 0x0;

	while (!*char_received) {
	}

	alt_putchar(*parallel_in);
	alt_putstr("\n");

	return 0;
}
 int main() {
	char input = 'A';
	int i;
	int j;
	*enable = 0x0F;
	while (input != 'E') {
		alt_putstr("\nTo READ type 'R' and press enter.\n");
		alt_putstr("\nTo WRITE type 'W' and press enter.\n");
		alt_putstr("\nTo exit the program, enter 'E'\n");
		input = alt_getchar();
		//scanf("%c", &input);
		// input = getchar();

		if (input == 'R') {
			*readWrite = 0x0F; // read
			*address = 0x0;
			for (j = 0; j < 127; j = j + 1) {
				*address += 1;
				*leds = *data;
			}
			//while (1) {
				//*leds = *data;
			//}
		} else if (input == 'W') {
			*readWrite = 0x0; // write
			*address = 0x0;
			for (i = 127; i > 0; i = i - 1) {
				*data = i;
				*address += 1;
			}
		}
	}

	return 0;
}
Exemple #6
0
// convenience routines for updating the pwm controlled led
void update_led_pwm()
{
  char input;
  char ch;
  int intensity;
  int i;

    //clear out the other LEDs
    update_led(0);

    alt_printf("On a scale of 0 to 9, enter the desired LED intensity\n");
    input = alt_getchar();
    alt_getchar();
    if (input == '0')
        intensity = 0;
    else if (input == '1')
        intensity = 4;
    else if (input == '2')
        intensity = 8;
    else if (input == '3')
        intensity = 16;
    else if (input == '4')
        intensity = 32;
    else if (input == '5')
        intensity = 64;
    else if (input == '6')
        intensity = 128;
    else if (input == '7')
        intensity = 256;
    else if (input == '8')
        intensity = 512;
    else if (input == '9')
        intensity = 1023;
    else {
        intensity = 0;
        alt_printf("INVALID ENTRY");
    }
    alt_printf("Setting PWM value to 0x%x  (Max value is 0x3ff)\n",intensity);
//    while ((ch = alt_getchar()) != '\n' && ch != EOF); // do this to flush the input buffer since fflush(stdin) is not recommended
    IOWR_SIMPLE_PWM(LED_PWM_BASE, intensity);
}
int main(){ 
	alt_putstr("Hello from Nios II!\n");
	
	char input;
	
	input = alt_getchar();
	
	if (input == 'G') {	
		/* Event loop never exits. */
		while (1){
			if (*(switches & 0x01) == 0) {
				*leds = *switches;
			}
			else {
				*leds = ~*switches;				
			}
		}	
	}
  return 0;
}
Exemple #8
0
 int main() {
	int input = 'A';
	int i;

	while (input != 'E') {
		alt_putstr("\n");
		alt_putstr("\nTo READ type 'R' and press enter.\n");
		alt_putstr("\nTo WRITE type 'W' and press enter.\n");
		alt_putstr("\nTo exit the program, enter 'E'\n");
		input = alt_getchar();

		if (input == 'R') {
			*enable = 0x0;
			*readWrite = 0x1; // read
			for (i = 0; i < 128; i++) {
				IOWR_ALTERA_AVALON_PIO_DIRECTION(*data, 0xFF);
				(*address) = i;
				*leds = *data;
				alt_printf("%x \n", *data);
				usleep(1000);
			}
			input = 'A';
			alt_printf("Read complete\n");

		} else if (input == 'W') {
			*enable = 0x0;
			*readWrite = 0x0; // write
			IOWR_ALTERA_AVALON_PIO_DIRECTION(*data, 0x00000000);

			for (i = 0; i < 128; i++) {
				*address = i;
				*data = 0x00000000;
				*data = 127 - i;
				alt_printf("%x\n", *data);
			}
			input = 'A';
		}
	}

	return 0;
}
int write_program(){
	volatile unsigned char program[256]={};
	volatile int i;
	volatile uint16_t t;

	alt_printf("%x",0xFF); //受信準備完了したことを伝える
	for(i=0;i<256;i++){
		//一度すべてのコードを受け取る
		program[i] = alt_getchar();
	}

	//プログラムカウンタリセット、プログラム書き込みモードへ切り替え
	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, 0x7);
	usleep(20000);

	//書き込み
	for(i=0;i<256;i++){
		t=0x100 | program[i]; //先頭に1を付加してPIOを有効化する
		IOWR_ALTERA_AVALON_PIO_DATA(PIO_IO_INOUT_BASE, t);
		IOWR_ALTERA_AVALON_PIO_DATA(PIO_KEYOUT_BASE, 0xE);
		usleep(10000);
		IOWR_ALTERA_AVALON_PIO_DATA(PIO_KEYOUT_BASE, 0xF);
		usleep(10000);
	}

	//復帰
	IOWR_ALTERA_AVALON_PIO_DATA(PIO_IO_INOUT_BASE, 0x0);
	IOWR_ALTERA_AVALON_PIO_DATA(PIO_MODE_SELOUT_BASE, 0x0);
	IOWR_ALTERA_AVALON_PIO_DATA(PIO_KEYOUT_BASE, 0x0);
	return 0;

}
 int main() {
	char input = 'A';
	int i;
	int j;
	//*enable = 0x0F;
	while (input != 'E') {
		alt_putstr("\nTo READ type 'R' and press enter.\n");
		alt_putstr("\nTo WRITE type 'W' and press enter.\n");
		alt_putstr("\nTo exit the program, enter 'E'\n");
		input = alt_getchar();
		//scanf("%c", &input);
		// input = getchar();

		if (input == 'R') {
			*enable = 0x0F;
			*readWrite = 0x0F; // read
			for (j = 0; j < 127; j = j + 1) {
				usleep(100000);
				(*address) = j;
				*leds = *data;

				alt_printf("sad%h   ", *data);
			}


		} else if (input == 'W') {
			*enable = 0x00;
			*readWrite = 0x0; // write
			*address = 0x0;
			for (i = 127; i > 0; i = i - 1) {
				*data = i;
				(*address) += 1;
			}
		}
	}

	return 0;
}
void readKeyboardToBuffer(char** pBufferHead, char** pBuffer) {
	char newC = alt_getchar();
	if(newC > 31 && newC < 128) {
		writeBuffer(newC, pBufferHead, pBuffer);
	}
}
Exemple #12
0
BYTE uart_get (void)
{
    return alt_getchar();
}
Exemple #13
0
int main (int argc, char* argv[], char* envp[])
{


//dane=0;
	/**
	 * Inicjalizacja danych do szyfrowania
	 */


printf("Rozpoczecie dzialania programu\n");
	//init_3des ( key11,  key12,  key21,  key22,  key31,  key32);


	//Otworzenie transmitujacego SGDMA dla TSE0
		sgdma_tx_dev = alt_avalon_sgdma_open ("/dev/sgdma_tx");
		if (sgdma_tx_dev == NULL) {
			alt_printf ("Error: nie mozna otworzyc scatter-gather dma transmit device dla TSE0\n");
			return -1;
		} else alt_printf ("Otworzono scatter-gather dma transmit device dla TSE0\n");

		//Otworzenie odbierajacego SGDMA dla TSE0
		sgdma_rx_dev = alt_avalon_sgdma_open ("/dev/sgdma_rx");
		if (sgdma_rx_dev == NULL) {
			alt_printf ("Error:  nie mozna otworzyc scatter-gather dma receive device dla TSE0\n");
			return -1;
		} else alt_printf ("Otworzno scatter-gather dma receive devicedla TSE0\n");
		printf ("System uruchomiony\n");
		alt_avalon_sgdma_register_callback( sgdma_rx_dev, (alt_avalon_sgdma_callback) rx_ethernet_isr, 0x00000014, NULL );

		// Utworzenie odbiorczego deskryptora sgdma
		alt_avalon_sgdma_construct_stream_to_mem_desc( &rx_descriptor, &rx_descriptor_end, (alt_u32 *)rx_frame, 0, 0 );

		alt_avalon_sgdma_do_async_transfer( sgdma_rx_dev, &rx_descriptor );

		// Uruchomienie drugiego SGDMA
		//
		//
		//Otworzenie transmitujacego SGDMA dla TSE1
		alt_avalon_sgdma_do_async_transfer( sgdma_rx_dev1, &rx_descriptor1 );
		sgdma_tx_dev1 = alt_avalon_sgdma_open ("/dev/sgdma_tx1");
			if (sgdma_tx_dev1 == NULL) {
				alt_printf ("Error: nie mozna otworzyc scatter-gather dma transmit device dla TSE1\n");
					return -1;
				} else alt_printf ("Otworzono scatter-gather dma transmit device dla TSE1\n");

			//Otworzenie odbierajacego SGDMA dla TSE1
			sgdma_rx_dev1 = alt_avalon_sgdma_open ("/dev/sgdma_rx1");
			if (sgdma_rx_dev1 == NULL) {
				alt_printf ("Error:  nie mozna otworzyc scatter-gather dma receive device dla TSE1\n");
				return -1;
			} else alt_printf ("Otworzno scatter-gather dma receive devicedla TSE1\n");
			printf ("System uruchomiony\n");

			alt_avalon_sgdma_register_callback( sgdma_rx_dev1, (alt_avalon_sgdma_callback) rx_ethernet_isr1, 0x00000014, NULL );

			//// Utworzenie odbiorczego deskryoptora sgdma
			alt_avalon_sgdma_construct_stream_to_mem_desc( &rx_descriptor1, &rx_descriptor_end1,(alt_u32 *) rx_frame1, 0, 0 );

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

		//Uruchomienie trzeciego SGDMA

			//Otworzenie SGDMA memory to memory dla obslugi wymiany pamieci pomiedzy SRAM a glowna pamiecia
			/*sgdma_read_3des = alt_avalon_sgdma_open ("/dev/sgdma_0");
			if (sgdma_read_3des == NULL) {
				alt_printf ("Error: Nie mozna otworzyc scatter-gather dma memory-memory device dla obslugi pamieci SRAM\n");
				return -1;
			} else alt_printf ("Otworzono scatter-gather dma memory-memory device dla obslugi pamieci SRAM\n");
*/
		printf ("Cale SGDMA uruchomione\n");
		/*
		 * weryfikacja_szyfrowania ();
		weryfikacja_deszyfrowania();
		przygotowanie_danych();
		test_wydajnosc ();
		test_wydajnosci_sram();
		*/
		// adresy bazoweTriple-speed Ethernet MegaCore
		volatile int * tse = (int *) ETH_TSE_BASE;
		//volatile int * tse = (int *) 0x103400;
		volatile int * tse1 = (int *) ETH_TSE1_BASE;
		//volatile int * tse1 = (int *) 0x103000;
		// Ustawienie adresu MAC 01-60-6E-11-02-0F na oba moduly TSE
		*(tse + 0x03) = 0x116E6001;
		*(tse + 0x04) = 0x00000F02;
		*(tse1 + 0x03) = 0x116E6001;
		*(tse1 + 0x04) = 0x00000F01;
	//	alt_tse_mac_set_common_speed(ETH_TSE_BASE,2);
		printf ("Ustalenie adresu MAC\n");
	// Okreslenie adresow urzadzen PHY do ktorych dostep odbywac sie bedzie przez interfejs MDIO
		 *(tse + 0x0F) = 0x10;
		*(tse + 0x10) = 0x11;
		// Okreslenie adresow urzadzen PHY do ktorych dostep odbywac sie bedzie przez interfejs MDIO
		/// *(tse1 + 0x0F) = 0x10;
		/// *(tse1 + 0x10) = 0x11;
		 // Write to register 20 of the PHY chip for Ethernet port 0 to set up line loopback
		 //*(tse + 0x94 ) = 0x4000;
		 // Ustawienie crossoveru dla obu PHY
		// *(tse + 0xA0) = *(tse + 0xA0) | 0x0060;
		/// *(tse1 + 0xB0) = *(tse1 + 0xB0) | 0x0060;
		*(tse + 0x94) = 0x4000;


		 //Uruchomienie crosoveru dla PHY
		  *(tse + 0x90) = *(tse + 0x90) | 0x0060;
			//  *(tse1 + 0xB0) = *(tse1 + 0xB0) | 0x0060;
			 // Wprowadzenie opoznienia zegara wejsciowego i wyjsciowego

			///	 *(tse1 + 0xB4) = *(tse1 + 0xB4) | 0x0082;
		  *(tse + 0x94) = *(tse + 0x94) | 0x0082;

		 // *(tse + 2) = *(tse + 2) | 0x02000043;
		  // Software reset obu chipow PHY
		  *(tse + 0x80) = *(tse + 0x80) | 0x8000;
		  	while ( *(tse + 0x80) & 0x8000  )
		  		;
		 		// *(tse + 0x02) = *(tse + 0x02) | 0x2000;
		 	//	 while ( *(tse + 0x02) & 0x2000  ) ; //sprawdzenie czy reset sie zakonczyl (sw_reset=0)
	///	 		 *(tse1 + 0xA0) = *(tse1 + 0xA0) | 0x8000;
	///	 		while ( *(tse1 + 0xA0) & 0x8000  ) 			 ;
		 // Umozliwienie zapisu i odczytu oraz przesylania ramek z blednie wyliczonym CRC
		 	printf("Udany reset obu modulow");
///		 *(tse1 + 2) = *(tse1 + 2) | 0x02000043;
		// *(tse + 2 ) = *(tse + 2) | 0x0000004B;
		 *(tse + 2) = *(tse + 2) |0x040001F3;
		 alt_printf( "send> " );
		 text_length = 0;
		// wprowadzenie_kluczy(); //Wprowadzenie wartosci kluczy ktore mialy byc uzywane przy transmisji Ethernet

		while (1) {

			char new_char;
		//	tx_frame[16] = '\0';


			while ( (new_char = alt_getchar()) != '\n'  ) {

				if (new_char == 0x08 && text_length > 0) {
					alt_printf( "%c", new_char );
					text_length--;

					// Maintain the terminal character after the text
					tx_frame[16 + text_length] = '\0';

				} else if (text_length < 45) {
					//alt_printf( "%c", new_char );
					unsigned int bajt1, tmp;
					unsigned char bajt2=0x1024000;
					unsigned char szyfr_new_char;


					//szyfr_new_char=IORD(SZYFRXOR_0_BASE,0);
					// Add the new character to the output text
					tx_frame[16 + text_length] = new_char;
					text_length++;
					//printf ("wewnatrz tu	 tu");
					tx_frame[16 + text_length] = '\0';
					//alt_printf( "%c", szyfr_new_char );
				//	printf( "x%2X", new_char);
			//		printf( "x%2X", szyfr_new_char);
				//	printf( "x%2X", bajt2);
				//	printf ("%s", rx_frame);
					//printf( "x%2X", bajt2);
				}
			}
		//	*phy1 = *(tse + 0x2C);
			//printf("Liczba odebranych pakietow: %X",phy1);
			alt_printf( "\nsend> " );
			text_length = 0;
			//usleep(2000000);

			//alt_avalon_sgdma_construct_mem_to_stream_desc( &tx_descriptor, &tx_descriptor_end, rx_frame, 90, 0, 1, 1, 0 );
			//alt_avalon_sgdma_do_async_transfer( sgdma_tx_dev, &tx_descriptor );
			//while (alt_avalon_sgdma_check_descriptor_status(&tx_descriptor) != 0)
			//	;
		}


		 while(1)
		 {	//printf("petla while odbieranie i wysylanie");

		//	 while (alt_avalon_sgdma_check_descriptor_status(&rx_descriptor) != 0);

			// printf("petla while odbieranie i wysylanie");

		 }
		return 0;

}