/******************** (C) COPYRIGHT 2003 STMicroelectronics ********************
* File Name          : main.c
* Author             : MCD Application Team
* Date First Issued  : 03/07/2003
* Description        : This file gives an example on the use of the One Pulse
*                      Mode.
********************************************************************************
* History:
*  03/07/2003 : First Version
*  30/11/2004 : V2.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.
*******************************************************************************/

#include "71x_lib.h"

/*
 The Device is configured to generate a pulse on the output compare A pin (OUT) with
 length of 0x1F timer period. The pulse generation is activated by an external
 rising edge on the input capture A (IN2). In this example an external wave generator
 is connected to the ICAP A pin and the output compare A is visualized on the
 scope.

                  ______        ______        ______
                 |      |      |      |      |      |
            _____|      |______|      |______|      |___
                  ___           ___           ___
                 |   |         |   |         |   |
            _____|   |_________|   |_________|   |______
                 <-->
                  Pulse Length
*/

#define T1_OCMP_A 0x80
#define T3_ICAP_A 0x02

int main(void)
{
  #ifdef DEBUG
  debug ();
  #endif

  //---------------------------------------------------------------------------
  // Initialization
  //---------------------------------------------------------------------------
  // Configure the GPIO1 Port
  // Timer 1 Output Compare function pin (P1.7) configured as Alternate
  // function pushpull.
  GPIO_Config (GPIO1 , T1_OCMP_A, GPIO_AF_PP );
  // Timer 3 Input Capture A (P1.1) configured as input TTL state
  GPIO_Config (GPIO1 , T3_ICAP_A , GPIO_IN_TRI_TTL );
  // Inisialize the Timer 1 registers to reset values
  TIM_Init ( TIM1 );
  // Inisialize the Timer 3 registers to reset values
  TIM_Init ( TIM3 );

  //---------------------------------------------------------------------------
  // Configure the TIM3
  //---------------------------------------------------------------------------
  // Configure the TIM Prescaler
//  TIM_PrescalerConfig ( TIM3, 0x7F );
  TIM_PrescalerConfig ( TIM1, 0x1 );
  TIM_PrescalerConfig ( TIM3, 0x0 );

  // Configure the TIM1 Output Compare Function :
  //   The OCMPA pin is configured to toggle from Low level to High level after
  //   0x3000 timer ticks.
  TIM_OPModeConfig ( TIM1, 0x1F, TIM_HIGH, TIM_LOW, TIM_RISING );
  //                  |      |      |         |        |
  //         TIM 1 <--+      |      |         |        +--> Activation edge on ICAP_A
  //                         |      |         |
  //        Pulse Length  <--+      |         +--> Level After The pulse
  //                                |
  //  Level During the Pulse    <---+

  // Start the Counter
  TIM_CounterConfig ( TIM1, TIM_START );
  // Start the Counter
  TIM_CounterConfig ( TIM3, TIM_START );

  while (1);
}
