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;
}
void transmitIfBufferNotEmpty(char** pTransmit, char* pBufferHead, char* pBuffer, int* write) {
	if(*load) {
		  *load = 0;
	  }

	  char c = '\0';
	  if(*write) {
		  c = readBuffer(pTransmit, pBufferHead, pBuffer);
		  if(c != '\0' && c != 0x60 ) {
			  alt_putstr("writing: ");
			  alt_putchar(c);
			  alt_putstr("\n");
			  *write = 0;
			  *data_bus_output = c;
			  usleep(1000);
			  *load = 1;
			  *transmit_enable = 1;
			  //alt_putchar(c);
			  *data_bus_LEDs = (*load) | (*transmit_enable << 1) | (*character_sent << 2) | (*character_received << 3);
			  //*data_bus_LEDs = c;
			  usleep(500);
		  }
	  }
	  if(*character_sent) {
		  alt_putstr("char sent\n");
		  *write = 1;
		  *transmit_enable = 0;
	  }
}
void printIfCharacterReceive(int* read) {
	if(*character_received & *read) {
		*read = 0;
		char cRec = (*data_bus_input >> 1) & 0b0011111111;
		char parityBit = getParityBit(cRec);
		char calcParityBit = isEvenParity(cRec);
		if(parityBit == calcParityBit) {
			alt_putchar(cRec);
		}
	} else if(!(*character_received)) {
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");
	int i = 0;
	char hello[20] = "Hello, world! abc123";

	while (i < 20) {

		*transmit_enable = 0x0;
		*load = 0x0;
		//*parallel_out = c;
		*data_bus_output = (hello[i]);
		//getBits(*parallel_out);
		//alt_putstr("\n*parallel_out\n");
		//alt_putchar((*parallel_out >> 1));
		//alt_putchar(*parallel_out);
		*data_bus_output = setParity(*data_bus_output);
		//getBits(*parallel_out);
		//alt_putchar(getCharacter(*parallel_out));
		//alt_putstr("\ngetCharacter(*parallel_out)\n");
		//alt_putchar(getCharacter(*parallel_out));
		usleep(1000);
		*transmit_enable = 0x1;
		*load = 0x1;
		usleep(50);
		*load = 0x0;
		while (!*character_received) {
		}
		while (!*character_sent) {
		}
		*transmit_enable = 0x0;

		/*if (getParity(*parallel_in)) {
			alt_putstr("bad parity\n");
		} else {
			alt_putstr("good parity\n");
		}*/
		//getBits(*parallel_in);
		alt_putchar(getCharacter(*data_bus_input));
		//alt_putstr("\n");
		i++;
	}

	return 0;
}
Example #5
0
void uart_put (BYTE d)
{
	alt_putchar(d);
}