/* demo_main.c - HCS12 UART (SCI) serial I/O example for Dragon12-Plus
 * Copyright 2008 Colin D. Bennett <colin@gibibit.com>.
 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 *    This program is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 *
 * This program demonstrates the use of polled asynchronous serial I/O
 * on the HCS12 CPU. The HCS12 CPU has two SCI (UART) ports, SCI0 and SCI1.
 * We use SCI1 because SCI0 is reserved by DBug12. Connect to the connector 
 * P2 (the DB9 connector nearest to the power connector on the Dragon12-Plus
 * board) to use SCI1.
 *
 * The port baud rate and CPU frequency must be set (via UART_BAUD & F_CPU),
 * which is taken care of by the Makefile, via gcc '-D' options. We must
 * know the CPU clock frequency because the UART transmitter and receiver
 * run off of the same clock, divided by a certain value, which depends on
 * both the CPU clock rate and the baud rate. The actual calculation is done
 * in the hc12/setbaud.h utility header.
 *
 * Note: Be sure to disable hardware flow control (RTS/CTS) on your computer
 * when trying to communicate with the HCS12 CPU, since it is unsupported.
 */

#include "hc12drivers/uart_intr.h"
#include <stdint.h>

int main(void)
{
	uart_init();   /* Note: enables interrupts. */

	const char hello_str[] = 
		"Hello, World!\r\n"
		"Press SPACE to hear it again!\r\n";

	while (1)
	{
		/* Send hello, world string. */
		for (uint8_t i = 0; hello_str[i]; i++)
			uart_putchar(hello_str[i]);

		/* Wait for SPACE to be pressed. */
		while (uart_getchar() != ' ')
			/* Do nothing. */;
	}
}
