/******************** (C) COPYRIGHT 2005 STMicroelectronics ********************
* File Name          : main.c
* Author             : MCD Application Team
* Date First Issued  : 09/27/2005 :  V1.0
* Description        : CMU Main program Example
**********************************************************************************
* History:
* 09/27/2005 :  V1.0
**********************************************************************************
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH
* CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT
* OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT
* OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION
* CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*********************************************************************************/

/* Standard include ------------------------------------------------------------*/
#include "73x_lib.h"
/* Include of other module interface headers -----------------------------------*/
#include <UART0_stdio.h>
/* Local includes --------------------------------------------------------------*/
/* Private typedef -------------------------------------------------------------*/
/* Private define --------------------------------------------------------------*/
/* Private macro ---------------------------------------------------------------*/
/* Private variables -----------------------------------------------------------*/ 


CMU_InitTypeDef   CMU_InitStruct;
GPIO_InitTypeDef  GPIO2_InitStructure;


int main(void)
{
  u16 Delay = 0x0;
  u8  Repeat = 0x0;
  
#ifdef DEBUG
    debug();
#endif

  CFG_PeripheralClockConfig(CFG_CLK_GPIO2 , ENABLE);
  /* GPIO2 Configuration */
  GPIO2_InitStructure.GPIO_Mode = GPIO_Mode_OUT_PP;
  GPIO2_InitStructure.GPIO_Pins = GPIO_PIN_ALL ;
  GPIO_Init (GPIO2, &GPIO2_InitStructure);
  GPIO_WordWrite(GPIO2,0x0000);
  printf("\nCMU Example : Switch between external and internal oscillator\n");
  CMU_StructInit(&CMU_InitStruct);
  CMU_DeInit( );

 /*Infinite loop*/
  while(1)
  {
    /*Configure CMU to select the external Quartz as Main Clock (MCLK) */
    CMU_InitStruct.CMU_CKSEL0 = CMU_CKSEL0_CKOSC;
    CMU_Init (&CMU_InitStruct);

    printf("\nNow the external Oscillator is selected \n");
    for ( Repeat =0x10 ;Repeat !=0   ; Repeat --)
    {
      for(Delay = 0; Delay < 0xFFFF; Delay++);
      GPIO_WordWrite(GPIO2,~GPIO_WordRead(GPIO2));
    }

    /*Configure CMU to select the internal RC oscillator as Main Clock (MCLK) */
    CMU_InitStruct.CMU_CKSEL0 = CMU_CKSEL0_CKRC;
    CMU_Init (&CMU_InitStruct);
    
    printf("\nNow the internal Oscillator is selected \n");
    for ( Repeat =0x10 ;Repeat !=0   ; Repeat --)

    {
      for(Delay = 0; Delay < 0xFFFF; Delay++);
      GPIO_WordWrite(GPIO2,~GPIO_WordRead(GPIO2));
       }
 
   }
}
/******************* (C) COPYRIGHT 2005 STMicroelectronics *****END OF FILE****/

