/** ###################################################################
**     This component module is generated by Processor Expert. Do not modify it.
**     Filename    : Cpu.c
**     Project     : CoulombMeter
**     Processor   : MKL25Z128VLK4
**     Component   : MKL25Z128LK4_4SDK
**     Version     : Component 1.2.0, Driver 01.00, CPU db: 3.00.000
**     Repository  : KSDK 1.3.0
**     Datasheet   : KL25P80M48SF0RM, Rev.3, Sep 2012
**     Compiler    : GNU C Compiler
**     Date/Time   : 2017-05-03, 19:57, # CodeGen: 49
**     Abstract    :
**
**     Settings    :
**
**     Contents    :
**         SystemInit            - void SystemInit(void);
**         SystemCoreClockUpdate - void SystemCoreClockUpdate(void);
**
**     (c) Freescale Semiconductor, Inc.
**     2004 All Rights Reserved
**
**     Copyright : 1997 - 2015 Freescale Semiconductor, Inc. 
**     All Rights Reserved.
**     
**     Redistribution and use in source and binary forms, with or without modification,
**     are permitted provided that the following conditions are met:
**     
**     o Redistributions of source code must retain the above copyright notice, this list
**       of conditions and the following disclaimer.
**     
**     o Redistributions in binary form must reproduce the above copyright notice, this
**       list of conditions and the following disclaimer in the documentation and/or
**       other materials provided with the distribution.
**     
**     o Neither the name of Freescale Semiconductor, Inc. nor the names of its
**       contributors may be used to endorse or promote products derived from this
**       software without specific prior written permission.
**     
**     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
**     ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
**     WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
**     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
**     ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
**     (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
**     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
**     ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
**     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
**     SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**     
**     http: www.freescale.com
**     mail: support@freescale.com
** ###################################################################*/
/*!
** @file Cpu.c
** @version 01.00
** @brief
**
*/         
/*!
**  @addtogroup Cpu_module Cpu module documentation
**  @{
*/         

/* MODULE Cpu. */

/* {Default RTOS Adapter} No RTOS includes */
#include "Cpu.h"
#include "Events.h"


#ifdef __cplusplus
extern "C" {
#endif

/*
** ===================================================================
**     Method      :  Common_Init (component MKL25Z128LK4_4SDK)
**     Description :
**         Initialization of registers for that there is no 
**         initialization component.
**     Parameters  : None
**     Returns     : Nothing
** ===================================================================
*/
#if CPU_COMMON_INIT
void Common_Init(void)
{
  /* This function contains initialization code which is not part of initialization 
     methods of peripheral initialization (Init) components used in the project.  
     This function is generated depending on Init components present 
     in the project. To remove initialization of a register from the Common_Init() 
     add Init component that includes initialization of this register.
     This function is also affected by after reset value optimization property 
     available in Component view\Generator_Configurations\Active configuration\
     Optimizations\Utilize after reset values. */
  /* SIM_SCGC5: PORTD=1,PORTA=1 */
  SIM_SCGC5 |= (SIM_SCGC5_PORTD_MASK | SIM_SCGC5_PORTA_MASK);
  /* NVIC_ICER: CLRENA31=0,CLRENA30=0,CLRENA29=0,CLRENA28=0,CLRENA27=0,CLRENA26=0,CLRENA25=0,CLRENA24=0,CLRENA23=0,CLRENA22=0,CLRENA21=0,CLRENA20=0,CLRENA19=0,CLRENA18=0,CLRENA17=0,CLRENA16=0,CLRENA15=0,CLRENA14=0,CLRENA13=0,CLRENA12=0,CLRENA11=0,CLRENA10=0,CLRENA9=0,CLRENA8=0,CLRENA7=0,CLRENA6=0,CLRENA5=0,CLRENA4=0,CLRENA3=0,CLRENA2=0,CLRENA1=0,CLRENA0=0 */
  NVIC_ICER = 0x00U;
  /* NVIC_IPR7: PRI_31=0,PRI_30=0 */
  NVIC_IPR7 &= (uint32_t)~(uint32_t)(
                NVIC_IP_PRI_31(0x03) |
                NVIC_IP_PRI_30(0x03)
               );
  /* NVIC_ISER: SETENA31=1,SETENA30=1,SETENA29=0,SETENA28=0,SETENA27=0,SETENA26=0,SETENA25=0,SETENA24=0,SETENA23=0,SETENA22=0,SETENA21=0,SETENA20=0,SETENA19=0,SETENA18=0,SETENA17=0,SETENA16=0,SETENA15=0,SETENA14=0,SETENA13=0,SETENA12=0,SETENA11=0,SETENA10=0,SETENA9=0,SETENA8=0,SETENA7=0,SETENA6=0,SETENA5=0,SETENA4=0,SETENA3=0,SETENA2=0,SETENA1=0,SETENA0=0 */
  NVIC_ISER = (NVIC_ISER_SETENA31_MASK | NVIC_ISER_SETENA30_MASK);
}

#endif /* CPU_COMMON_INIT */
/*
** ===================================================================
**     Method      :  Components_Init (component MKL25Z128LK4_4SDK)
**     Description :
**         Initialization of components (with exception for Peripheral
**         Initialization Components which are initialized in 
**         Peripherals_Init() method).
**         For example, if automatic initialization feature 
**         is enabled in LDD component then its Init method call 
**         is executed in Components_Init() method.
**     Parameters  : None
**     Returns     : Nothing
** ===================================================================
*/
#if CPU_COMPONENTS_INIT
void Components_Init(void)
{

  /*! tpmTmr1 Auto initialization start */
  TPM_DRV_Init(tpmTmr1_IDX, &tpmTmr1_InitConfig0);
  TPM_DRV_SetClock(tpmTmr1_IDX, kTpmClockSourceModuleClk, kTpmDividedBy128);
  TPM_DRV_PwmStart(tpmTmr1_IDX, &tpmTmr1_ChnConfig0, 0U);
  /*! tpmTmr1 Auto initialization end */
  
  /*! gpio1 Auto initialization start */
  GPIO_DRV_Init(NULL,gpio1_OutConfig0);
  /*! gpio1 Auto initialization end */
  
  /*! i2cCom1 Auto initialization start */
  I2C_DRV_MasterInit(i2cCom1_IDX, &i2cCom1_MasterState);
  I2C_DRV_MasterSetBaudRate(i2cCom1_IDX, &i2cCom1_MasterConfig0);
  /*! i2cCom1 Auto initialization end */
  
  /*! uartCom1 Auto initialization start */
  UART_DRV_Init(uartCom1_IDX,&uartCom1_State,&uartCom1_InitConfig0);
  /*! uartCom1 Auto initialization end */
    
  /*! DbgCs1 Auto initialization start */
  /* Debug console initialization */
  DbgConsole_Init(BOARD_DEBUG_UART_INSTANCE, DEBUG_UART_BAUD, DEBUG_UART_TYPE);
  /*! DbgCs1 Auto initialization end */
  /*! pitTimer1 Auto initialization start */
  NVIC_SetPriority(PIT_IRQn, 1U);
  OSA_InstallIntHandler(PIT_IRQn,  pitTimer1_IRQHandler);
  PIT_DRV_Init(pitTimer1_IDX,true);
  PIT_DRV_InitChannel(pitTimer1_IDX,pitTimer1_CHANNEL,&pitTimer1_InitConfig0);
  /*! pitTimer1 Auto initialization end */
  /*! tpmTmr2 Auto initialization start */
  TPM_DRV_Init(tpmTmr2_IDX, &tpmTmr2_InitConfig0);
  TPM_DRV_SetClock(tpmTmr2_IDX, kTpmClockSourceModuleClk, kTpmDividedBy1);
  TPM_DRV_InputCaptureEnable(tpmTmr2_IDX, 1U, kTpmRiseOrFallEdge, 65535U, false);          
  /*! tpmTmr2 Auto initialization end */
  
  /*! adConv1 Auto initialization start */
  ADC16_DRV_Init(adConv1_IDX, &adConv1_InitConfig0);
  ADC16_DRV_ConfigConvChn(adConv1_IDX, 0U, &adConv1_ChnConfig0);
  /*! adConv1 Auto initialization end */

}
#endif /* CPU_COMPONENTS_INIT */


#ifdef __cplusplus
}
#endif

/* END Cpu. */

