/******************************************************************************
*     $Date: 2004/11/19 20:19:52 $
*     $RCSfile: sysace_rebooter.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 "xparameters.h"
#include "xuartns550_l.h"
#include "xsysace_l.h"
#include "xio.h"

#define SYSACE_BASEADDR XPAR_OPB_SYSACE_0_BASEADDR
#define UART_BASEADDR   XPAR_OPB_UART16550_0_BASEADDR
#define UART_CLOCK      XPAR_XUARTNS550_CLOCK_HZ
#if !SIM
#define UART_BAUDRATE 9600                      /* real hardware */
#else
#define UART_BAUDRATE (UART_CLOCK / 16 / 3)     /* simulation */
#endif

int main()
{
    int c;
    XUartNs550_SetBaud(UART_BASEADDR, UART_CLOCK, UART_BAUDRATE);
    XUartNs550_mSetLineControlReg(UART_BASEADDR, XUN_LCR_8_DATA_BITS);

    printf("This program issues a command to system ace to cause\r\n");
    printf("it to reboot to the System ACE address entered below\r\n\r\n");
    printf("Which System ACE config address would you like to reboot to (0-7)?\r\n");
    do
    {
      c = getchar();
    }  while (((char) c != '0') & ((char) c != '1')
            & ((char) c != '2') & ((char) c != '3')
            & ((char) c != '4') & ((char) c != '5')
            & ((char) c != '6') & ((char) c != '7'));
    printf("\r\n\r\nRebooting to System ACE configuration address... %c\r\n",c);

    c = (char) c - '0';
    XSysAce_RegWrite16(SYSACE_BASEADDR + XSA_BMR_OFFSET, XSA_BMR_16BIT_MASK);
    XSysAce_mSetControlReg(SYSACE_BASEADDR, XSA_CR_CFGRESET_MASK);
    XSysAce_mSetControlReg(SYSACE_BASEADDR, (c << XSA_CR_CFGADDR_SHIFT) |
	                                        XSA_CR_FORCECFGADDR_MASK |
					                        XSA_CR_CFGMODE_MASK |
					                        XSA_CR_CFGSTART_MASK);
    while (1);

    return 0;
}
