/******************************************************************************
*     $Date: 2004/10/25 22:08:45 $
*     $RCSfile: flash_hello.c,v $
*******************************************************************************

*******************************************************************************
*
*     XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS"
*     SOLELY FOR USE IN DEVELOPING PROGRAMS AND SOLUTIONS FOR
*     XILINX DEVICES.  BY PROVIDING THIS DESIGN, CODE, OR INFORMATION
*     AS ONE POSSIBLE IMPLEMENTATION OF THIS FEATURE, APPLICATION
*     OR STANDARD, XILINX IS MAKING NO REPRESENTATION THAT THIS
*     IMPLEMENTATION IS FREE FROM ANY CLAIMS OF INFRINGEMENT,
*     AND YOU ARE RESPONSIBLE FOR OBTAINING ANY RIGHTS YOU MAY REQUIRE
*     FOR YOUR IMPLEMENTATION.  XILINX EXPRESSLY DISCLAIMS ANY
*     WARRANTY WHATSOEVER WITH RESPECT TO THE ADEQUACY OF THE
*     IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OR
*     REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE FROM CLAIMS OF
*     INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
*     FOR A PARTICULAR PURPOSE.
*     
*     (c) Copyright 2004 Xilinx, Inc.
*     All rights reserved.
*
******************************************************************************/
#include <stdio.h>
#include "xuartns550_l.h"
#include "xparameters.h"
#include "xromlcd.h"
#include "xio.h"
#include "xbasic_types.h"
#include "xstatus.h"
#include "xtft.h"
#include "xtft_l.h"
#include "bootload_graphics.h"

#define UART_BASEADDR XPAR_OPB_UART16550_0_BASEADDR
#define UART_CLOCK    XPAR_XUARTNS550_CLOCK_HZ
#define TFT_DEVICE_ID XPAR_PLB_TFT_CNTLR_REF_0_DEVICE_ID
#define STATUS_CHECK(Status) { if (Status != XST_SUCCESS) { return Status; } }

#if !SIM
#define UART_BAUDRATE 9600                      /* real hardware */
#else
#define UART_BAUDRATE (UART_CLOCK / 16 / 3)     /* simulation */
#endif


#define ESCAPE          0x1b

void echo()
{
  char s;
  
  do {
    s = XUartNs550_RecvByte(UART_BASEADDR);
    if(s == '\r')
      XUartNs550_SendByte(UART_BASEADDR, '\n');
    XUartNs550_SendByte(UART_BASEADDR, s); 
  } while (s != ESCAPE);
}

int main()
{
  char *lcd_text = "Design #0 Loaded";
  XTft Tft;
  XStatus Status;
  Xuint32 i;
  char *vga_text = "This is flash configuration 0";

  XUartNs550_SetBaud(UART_BASEADDR, UART_CLOCK, UART_BAUDRATE);
  XUartNs550_mSetLineControlReg(UART_BASEADDR, XUN_LCR_8_DATA_BITS);

  /* Initialize TFT */
  Status = XTft_Initialize(&Tft, TFT_DEVICE_ID);
  STATUS_CHECK(Status);
  
  /* Initialize TFT and display */
  XTft_SetColor(&Tft, 0x00ffffff, 0x00404040);
  XTft_ClearScreen(&Tft);
  XTft_SetPos(&Tft, 5, 0);
  XTft_WriteColorString(&Tft, "The FPGA has been configured from the Linear Flash memory", 0x00FFFFFF, 0x00404040);
  XTft_SetPos(&Tft, 5, 15);
  vga_text[28] = CONFIGURATION + '0'; 
  XTft_WriteColorString(&Tft, vga_text, 0x00FFFFFF, 0x00404040);
  XTft_SetPos(&Tft, 5, 45);
  XTft_WriteColorString(&Tft, "The configuration process is:", 0x00FFFFFF, 0x00404040);
  XTft_SetPos(&Tft, 5, 60);
  XTft_WriteColorString(&Tft, "1. A design was run that reads .bit files from the Compact Flash\n\r", 0x00FFFFFF, 0x00404040);
  XTft_SetPos(&Tft, 5, 75);
  XTft_WriteColorString(&Tft, "   and stores the files in the Linear Flash.", 0x00FFFFFF, 0x00404040);
  XTft_SetPos(&Tft, 5, 90);
  XTft_WriteColorString(&Tft, "   One .bit file contains both the hardware design and this program.", 0x00FFFFFF, 0x00404040);
  XTft_SetPos(&Tft, 5, 105);
  XTft_WriteColorString(&Tft, "2. The XC95144XL reads the Linear Flash while simultaneously", 0x00FFFFFF, 0x00404040);
  XTft_SetPos(&Tft, 5, 120);
  XTft_WriteColorString(&Tft, "   configuring the FPGA.", 0x00FFFFFF, 0x00404040);

  print("\n\rThe FPGA has been configured from the Linear Flash memory\n\r");
  xil_printf("This is flash configuration %d\n\r", CONFIGURATION);
  xil_printf("On the reference design, this bit file is at memory location 0x%08X\n\r",
             0x28000000 + (CONFIGURATION * 0x100000));
  print("\n\r\n\r");

  print("The configuration process is:\n\r");
  print("1. A design was run that reads .bit files from the Compact Flash\n\r");
  print("   and stores the files in the Linear Flash.\n\r");
  print("   One .bit file contains both the hardware design and this program.\n\r");
  print("2. The XC95144XL reads the Linear Flash while simultaneously\n\r");
  print("   configuring the FPGA.\n\r");
  
  /* print directions to LCD screen */
  XromLCDOn();
  XromLCDInit();

  lcd_text[8] = CONFIGURATION + '0';
  XromLCDPrintString (lcd_text, "Using Flash+CPLD");

  while (1) {}
  return 0;
}

