//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
// Copyright (C) 2006-2007, Freescale Semiconductor, Inc. All Rights Reserved.
// THIS SOURCE CODE, AND ITS USE AND DISTRIBUTION, IS SUBJECT TO THE TERMS
// AND CONDITIONS OF THE APPLICABLE LICENSE AGREEMENT

#include <bsp.h>

UINT32 WdogInit(UINT32 TimeoutMSec);

// Timer already initialized to ~1 kHz (1 ms tick) in PMCPlatformInit
extern PCSP_EPIT_REG g_pEPIT;

void msWait(unsigned nMilliseconds)
{
   
   UINT32 startCount, maxCount;
   
   if (g_pEPIT == NULL) {
      OALMSG(OAL_ERROR, (TEXT("msWait: ERROR - Timer not initialized\r\n")));
      return;
   }
   
   startCount = EPIT_CNT_COUNT_MAX - INREG32(&g_pEPIT->CNT);
   maxCount = startCount + nMilliseconds;
   
   // wait for nMilliseconds number of ticks
   while ((EPIT_CNT_COUNT_MAX - INREG32(&g_pEPIT->CNT)) < maxCount);
   
}

void ResetSystem(void)
{
   // Get uncached virtual addresses for Watchdog
   WdogInit(500);
   
   for (;;);
   
   // Should never get to this point...
   //
}


