/*
 *-----------------------------------------------------------------------------
 * The confidential and proprietary information contained in this file may
 * only be used by a person authorised under and to the extent permitted
 * by a subsisting licensing agreement from ARM Limited.
 *
 *            (C) COPYRIGHT 2010-2011 ARM Limited.
 *                ALL RIGHTS RESERVED
 *
 * This entire notice must be reproduced on all copies of this file
 * and copies of this file may only be made by a person if such person is
 * permitted to do so under the terms of a subsisting license agreement
 * from ARM Limited.
 *
 *      SVN Information
 *
 *      Checked In          : $Date: 2011/06/07 04:46:00 $
 *
 *      Revision            : $Revision: 1.1 $
 *
 *      Release Information : BP200-r0p0-00rel0
 *-----------------------------------------------------------------------------
 */

 /*

 UART functions for retargetting

 */
#include "hhd32f0xx.h"

void UartStdOutInit(void)
{
  HHD_SYSCON->SYSAHBCLKCTRL |= 1<<12;	//enable UART0 PCLK

  HHD_SYSCON->UART0CLKDIV=1;
  HHD_UART0->BAUDDIV = 416;//0x15c; //0xa7;
  HHD_UART0->CTRL    = 0x03<<22; // High speed test mode, TX only
//  XDP_GPIO1->ALTFUNCSET = (1<<5);
  return;
}
// Output a character
unsigned char UartPutc(unsigned char my_ch)
{
//  while ((XDP_UART0->STATE & 1)); // Wait if Transmit Holding register is full
  while ((HHD_UART0->STATE & 4)) // Wait if Transmit Holding register is full
  {
//    XDP_SYSCON->UART0CLKDIV=1;
//    XDP_UART0->BAUDDIV = 0x15c; //0xa7;
    HHD_UART0->CTRL    = 0x03<<22;
  }
  HHD_UART0->TDR = my_ch; // write to transmit holding register
  return (my_ch);
}
// Get a character
unsigned char UartGetc(void)
{
  while ((HHD_UART0->STATE & 2)==0); // Wait if Receive Holding register is empty
  return (HHD_UART0->RDR);
}

void UartEndSimulation(void)
{
  UartPutc((char) 0x4); // End of simulation
  while(1);
}

