/*
*	Get the library include files - we only use one
*/

#include <stdio_format.h>

/*
*	Get the vararg related GCC include file
*/

#include <stdarg.h>

/*
*	Get the include file that declares the chip setup routines
*/

#include "hardware.h"

/*
*	Local prototypes
*
*	We add the 'noreturn' attribute to main, because it should never
*	return (it's an embedded gizmo, there's nowhere to return).
*/

void	main( void ) __attribute__((noreturn));

static int	printf( const char *fmt, ... );
static int	uart_out( void **unused, const char *data, size_t len );

/*
*	This is the entry point of the system
*/

void	main( void )
{
	HardwareInit();
	printf( "Hello, world!\r\n" );
	for ( ;; );
}

/*
*	This is the printf() function, using the UART
*/

static	int	printf( const char *fmt, ... )
{
va_list	arg;
int		ret;

	va_start( arg, fmt );
	ret = print_flt( fmt, arg, -1, uart_out, NULL, NULL );
	va_end( arg );
	return ret;
}

/*
*	Helper function for printf
*/

static int	uart_out( void **unused, const char *data, size_t len )
{
	(void) unused;
	while ( len-- ) UartPutc( *data++ );
	return 1;
}

