lpc-field

Template project for programming NXP's LPC1768 MCUs
git clone git://git.mdnr.space/lpc-field
Log | Files | Refs | README | LICENSE

lpc17xx_rit.c (6776B)


      1 /**********************************************************************
      2 * $Id$		lpc17xx_rit.c				2010-05-21
      3 *//**
      4 * @file		lpc17xx_rit.c
      5 * @brief	Contains all functions support for RIT firmware library on LPC17xx
      6 * @version	2.0
      7 * @date		21. May. 2010
      8 * @author	NXP MCU SW Application Team
      9 *
     10 * Copyright(C) 2010, NXP Semiconductor
     11 * All rights reserved.
     12 *
     13 ***********************************************************************
     14 * Software that is described herein is for illustrative purposes only
     15 * which provides customers with programming information regarding the
     16 * products. This software is supplied "AS IS" without any warranties.
     17 * NXP Semiconductors assumes no responsibility or liability for the
     18 * use of the software, conveys no license or title under any patent,
     19 * copyright, or mask work right to the product. NXP Semiconductors
     20 * reserves the right to make changes in the software without
     21 * notification. NXP Semiconductors also make no representation or
     22 * warranty that such application will be suitable for the specified
     23 * use without further testing or modification.
     24 * Permission to use, copy, modify, and distribute this software and its
     25 * documentation is hereby granted, under NXP Semiconductors'
     26 * relevant copyright in the software, without fee, provided that it
     27 * is used in conjunction with NXP Semiconductors microcontrollers.  This
     28 * copyright, permission, and disclaimer notice must appear in all copies of
     29 * this code.
     30 **********************************************************************/
     31 
     32 /* Peripheral group ----------------------------------------------------------- */
     33 /** @addtogroup RIT
     34  * @{
     35  */
     36 
     37 /* Includes ------------------------------------------------------------------- */
     38 #include "lpc17xx_rit.h"
     39 #include "lpc17xx_clkpwr.h"
     40 
     41 /* If this source file built with example, the LPC17xx FW library configuration
     42  * file in each example directory ("lpc17xx_libcfg.h") must be included,
     43  * otherwise the default FW library configuration file must be included instead
     44  */
     45 #ifdef __BUILD_WITH_EXAMPLE__
     46 #include "lpc17xx_libcfg.h"
     47 #else
     48 #include "lpc17xx_libcfg_default.h"
     49 #endif /* __BUILD_WITH_EXAMPLE__ */
     50 
     51 #ifdef _RIT
     52 
     53 /* Public Functions ----------------------------------------------------------- */
     54 /** @addtogroup RIT_Public_Functions
     55  * @{
     56  */
     57 
     58 /******************************************************************************//*
     59  * @brief 		Initial for RIT
     60  * 					- Turn on power and clock
     61  * 					- Setup default register values
     62  * @param[in]	RITx is RIT peripheral selected, should be: LPC_RIT
     63  * @return 		None
     64  *******************************************************************************/
     65 void RIT_Init(LPC_RIT_TypeDef *RITx)
     66 {
     67 	CHECK_PARAM(PARAM_RITx(RITx));
     68 	CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCRIT, ENABLE);
     69 	//Set up default register values
     70 	RITx->RICOMPVAL = 0xFFFFFFFF;
     71 	RITx->RIMASK	= 0x00000000;
     72 	RITx->RICTRL	= 0x0C;
     73 	RITx->RICOUNTER	= 0x00000000;
     74 	// Turn on power and clock
     75 
     76 }
     77 /******************************************************************************//*
     78  * @brief 		DeInitial for RIT
     79  * 					- Turn off power and clock
     80  * 					- ReSetup default register values
     81  * @param[in]	RITx is RIT peripheral selected, should be: LPC_RIT
     82  * @return 		None
     83  *******************************************************************************/
     84 void RIT_DeInit(LPC_RIT_TypeDef *RITx)
     85 {
     86 	CHECK_PARAM(PARAM_RITx(RITx));
     87 
     88 	// Turn off power and clock
     89 	CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCRIT, DISABLE);
     90 	//ReSetup default register values
     91 	RITx->RICOMPVAL = 0xFFFFFFFF;
     92 	RITx->RIMASK	= 0x00000000;
     93 	RITx->RICTRL	= 0x0C;
     94 	RITx->RICOUNTER	= 0x00000000;
     95 }
     96 
     97 /******************************************************************************//*
     98  * @brief 		Set compare value, mask value and time counter value
     99  * @param[in]	RITx is RIT peripheral selected, should be: LPC_RIT
    100  * @param[in]	time_interval: timer interval value (ms)
    101  * @return 		None
    102  *******************************************************************************/
    103 void RIT_TimerConfig(LPC_RIT_TypeDef *RITx, uint32_t time_interval)
    104 {
    105 	uint32_t clock_rate, cmp_value;
    106 	CHECK_PARAM(PARAM_RITx(RITx));
    107 
    108 	// Get PCLK value of RIT
    109 	clock_rate = CLKPWR_GetPCLK(CLKPWR_PCLKSEL_RIT);
    110 
    111 	/* calculate compare value for RIT to generate interrupt at
    112 	 * specified time interval
    113 	 * COMPVAL = (RIT_PCLK * time_interval)/1000
    114 	 * (with time_interval unit is millisecond)
    115 	 */
    116 	cmp_value = (clock_rate /1000) * time_interval;
    117 	RITx->RICOMPVAL = cmp_value;
    118 
    119 	/* Set timer enable clear bit to clear timer to 0 whenever
    120 	 * counter value equals the contents of RICOMPVAL
    121 	 */
    122 	RITx->RICTRL |= (1<<1);
    123 }
    124 
    125 
    126 /******************************************************************************//*
    127  * @brief 		Enable/Disable Timer
    128  * @param[in]	RITx is RIT peripheral selected, should be: LPC_RIT
    129  * @param[in]	NewState 	New State of this function
    130  * 					-ENABLE: Enable Timer
    131  * 					-DISABLE: Disable Timer
    132  * @return 		None
    133  *******************************************************************************/
    134 void RIT_Cmd(LPC_RIT_TypeDef *RITx, FunctionalState NewState)
    135 {
    136 	CHECK_PARAM(PARAM_RITx(RITx));
    137 	CHECK_PARAM(PARAM_FUNCTIONALSTATE(NewState));
    138 
    139 	//Enable or Disable Timer
    140 	if(NewState==ENABLE)
    141 	{
    142 		RITx->RICTRL |= RIT_CTRL_TEN;
    143 	}
    144 	else
    145 	{
    146 		RITx->RICTRL &= ~RIT_CTRL_TEN;
    147 	}
    148 }
    149 
    150 /******************************************************************************//*
    151  * @brief 		Timer Enable/Disable on debug
    152  * @param[in]	RITx is RIT peripheral selected, should be: LPC_RIT
    153  * @param[in]	NewState 	New State of this function
    154  * 					-ENABLE: The timer is halted whenever a hardware break condition occurs
    155  * 					-DISABLE: Hardware break has no effect on the timer operation
    156  * @return 		None
    157  *******************************************************************************/
    158 void RIT_TimerDebugCmd(LPC_RIT_TypeDef *RITx, FunctionalState NewState)
    159 {
    160 	CHECK_PARAM(PARAM_RITx(RITx));
    161 	CHECK_PARAM(PARAM_FUNCTIONALSTATE(NewState));
    162 
    163 	//Timer Enable/Disable on break
    164 	if(NewState==ENABLE)
    165 	{
    166 		RITx->RICTRL |= RIT_CTRL_ENBR;
    167 	}
    168 	else
    169 	{
    170 		RITx->RICTRL &= ~RIT_CTRL_ENBR;
    171 	}
    172 }
    173 /******************************************************************************//*
    174  * @brief 		Check whether interrupt flag is set or not
    175  * @param[in]	RITx is RIT peripheral selected, should be: LPC_RIT
    176  * @return 		Current interrupt status, could be: SET/RESET
    177  *******************************************************************************/
    178 IntStatus RIT_GetIntStatus(LPC_RIT_TypeDef *RITx)
    179 {
    180 	IntStatus result;
    181 	CHECK_PARAM(PARAM_RITx(RITx));
    182 	if((RITx->RICTRL&RIT_CTRL_INTEN)==1)	result= SET;
    183 	else return RESET;
    184 	//clear interrupt flag
    185 	RITx->RICTRL |= RIT_CTRL_INTEN;
    186 	return result;
    187 }
    188 
    189 /**
    190  * @}
    191  */
    192 
    193 #endif /* _RIT */
    194 
    195 /**
    196  * @}
    197  */
    198 
    199 /* --------------------------------- End Of File ------------------------------ */