Fork of Smoothie to port to mbed non-LPC targets.

Dependencies:   mbed

Fork of Smoothie by Stéphane Cachat

Committer:
Michael J. Spencer
Date:
Fri Feb 28 18:52:52 2014 -0800
Revision:
2:1df0b61d3b5a
Update to latest Smoothie.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Michael J. Spencer 2:1df0b61d3b5a 1 #ifdef __LPC17XX__
Michael J. Spencer 2:1df0b61d3b5a 2
Michael J. Spencer 2:1df0b61d3b5a 3 /**********************************************************************
Michael J. Spencer 2:1df0b61d3b5a 4 * $Id$ lpc17xx_systick.c 2010-05-21
Michael J. Spencer 2:1df0b61d3b5a 5 *//**
Michael J. Spencer 2:1df0b61d3b5a 6 * @file lpc17xx_systick.c
Michael J. Spencer 2:1df0b61d3b5a 7 * @brief Contains all functions support for SYSTICK firmware library
Michael J. Spencer 2:1df0b61d3b5a 8 * on LPC17xx
Michael J. Spencer 2:1df0b61d3b5a 9 * @version 2.0
Michael J. Spencer 2:1df0b61d3b5a 10 * @date 21. May. 2010
Michael J. Spencer 2:1df0b61d3b5a 11 * @author NXP MCU SW Application Team
Michael J. Spencer 2:1df0b61d3b5a 12 *
Michael J. Spencer 2:1df0b61d3b5a 13 * Copyright(C) 2010, NXP Semiconductor
Michael J. Spencer 2:1df0b61d3b5a 14 * All rights reserved.
Michael J. Spencer 2:1df0b61d3b5a 15 *
Michael J. Spencer 2:1df0b61d3b5a 16 ***********************************************************************
Michael J. Spencer 2:1df0b61d3b5a 17 * Software that is described herein is for illustrative purposes only
Michael J. Spencer 2:1df0b61d3b5a 18 * which provides customers with programming information regarding the
Michael J. Spencer 2:1df0b61d3b5a 19 * products. This software is supplied "AS IS" without any warranties.
Michael J. Spencer 2:1df0b61d3b5a 20 * NXP Semiconductors assumes no responsibility or liability for the
Michael J. Spencer 2:1df0b61d3b5a 21 * use of the software, conveys no license or title under any patent,
Michael J. Spencer 2:1df0b61d3b5a 22 * copyright, or mask work right to the product. NXP Semiconductors
Michael J. Spencer 2:1df0b61d3b5a 23 * reserves the right to make changes in the software without
Michael J. Spencer 2:1df0b61d3b5a 24 * notification. NXP Semiconductors also make no representation or
Michael J. Spencer 2:1df0b61d3b5a 25 * warranty that such application will be suitable for the specified
Michael J. Spencer 2:1df0b61d3b5a 26 * use without further testing or modification.
Michael J. Spencer 2:1df0b61d3b5a 27 **********************************************************************/
Michael J. Spencer 2:1df0b61d3b5a 28
Michael J. Spencer 2:1df0b61d3b5a 29 /* Peripheral group ----------------------------------------------------------- */
Michael J. Spencer 2:1df0b61d3b5a 30 /** @addtogroup SYSTICK
Michael J. Spencer 2:1df0b61d3b5a 31 * @{
Michael J. Spencer 2:1df0b61d3b5a 32 */
Michael J. Spencer 2:1df0b61d3b5a 33
Michael J. Spencer 2:1df0b61d3b5a 34 /* Includes ------------------------------------------------------------------- */
Michael J. Spencer 2:1df0b61d3b5a 35 #include "lpc17xx_systick.h"
Michael J. Spencer 2:1df0b61d3b5a 36 #include "lpc17xx_clkpwr.h"
Michael J. Spencer 2:1df0b61d3b5a 37
Michael J. Spencer 2:1df0b61d3b5a 38 /* If this source file built with example, the LPC17xx FW library configuration
Michael J. Spencer 2:1df0b61d3b5a 39 * file in each example directory ("lpc17xx_libcfg.h") must be included,
Michael J. Spencer 2:1df0b61d3b5a 40 * otherwise the default FW library configuration file must be included instead
Michael J. Spencer 2:1df0b61d3b5a 41 */
Michael J. Spencer 2:1df0b61d3b5a 42 #ifdef __BUILD_WITH_EXAMPLE__
Michael J. Spencer 2:1df0b61d3b5a 43 #include "lpc17xx_libcfg.h"
Michael J. Spencer 2:1df0b61d3b5a 44 #else
Michael J. Spencer 2:1df0b61d3b5a 45 #include "lpc17xx_libcfg_default.h"
Michael J. Spencer 2:1df0b61d3b5a 46 #endif /* __BUILD_WITH_EXAMPLE__ */
Michael J. Spencer 2:1df0b61d3b5a 47
Michael J. Spencer 2:1df0b61d3b5a 48
Michael J. Spencer 2:1df0b61d3b5a 49 #ifdef _SYSTICK
Michael J. Spencer 2:1df0b61d3b5a 50
Michael J. Spencer 2:1df0b61d3b5a 51 /* Public Functions ----------------------------------------------------------- */
Michael J. Spencer 2:1df0b61d3b5a 52 /** @addtogroup SYSTICK_Public_Functions
Michael J. Spencer 2:1df0b61d3b5a 53 * @{
Michael J. Spencer 2:1df0b61d3b5a 54 */
Michael J. Spencer 2:1df0b61d3b5a 55 /*********************************************************************//**
Michael J. Spencer 2:1df0b61d3b5a 56 * @brief Initial System Tick with using internal CPU clock source
Michael J. Spencer 2:1df0b61d3b5a 57 * @param[in] time time interval(ms)
Michael J. Spencer 2:1df0b61d3b5a 58 * @return None
Michael J. Spencer 2:1df0b61d3b5a 59 **********************************************************************/
Michael J. Spencer 2:1df0b61d3b5a 60 void SYSTICK_InternalInit(uint32_t time)
Michael J. Spencer 2:1df0b61d3b5a 61 {
Michael J. Spencer 2:1df0b61d3b5a 62 uint32_t cclk;
Michael J. Spencer 2:1df0b61d3b5a 63 float maxtime;
Michael J. Spencer 2:1df0b61d3b5a 64
Michael J. Spencer 2:1df0b61d3b5a 65 cclk = SystemCoreClock;
Michael J. Spencer 2:1df0b61d3b5a 66 /* With internal CPU clock frequency for LPC17xx is 'SystemCoreClock'
Michael J. Spencer 2:1df0b61d3b5a 67 * And limit 24 bit for RELOAD value
Michael J. Spencer 2:1df0b61d3b5a 68 * So the maximum time can be set:
Michael J. Spencer 2:1df0b61d3b5a 69 * 1/SystemCoreClock * (2^24) * 1000 (ms)
Michael J. Spencer 2:1df0b61d3b5a 70 */
Michael J. Spencer 2:1df0b61d3b5a 71 //check time value is available or not
Michael J. Spencer 2:1df0b61d3b5a 72 maxtime = (1<<24)/(SystemCoreClock / 1000) ;
Michael J. Spencer 2:1df0b61d3b5a 73 if(time > maxtime)
Michael J. Spencer 2:1df0b61d3b5a 74 //Error loop
Michael J. Spencer 2:1df0b61d3b5a 75 while(1);
Michael J. Spencer 2:1df0b61d3b5a 76 else
Michael J. Spencer 2:1df0b61d3b5a 77 {
Michael J. Spencer 2:1df0b61d3b5a 78 //Select CPU clock is System Tick clock source
Michael J. Spencer 2:1df0b61d3b5a 79 SysTick->CTRL |= ST_CTRL_CLKSOURCE;
Michael J. Spencer 2:1df0b61d3b5a 80 /* Set RELOAD value
Michael J. Spencer 2:1df0b61d3b5a 81 * RELOAD = (SystemCoreClock/1000) * time - 1
Michael J. Spencer 2:1df0b61d3b5a 82 * with time base is millisecond
Michael J. Spencer 2:1df0b61d3b5a 83 */
Michael J. Spencer 2:1df0b61d3b5a 84 SysTick->LOAD = (cclk/1000)*time - 1;
Michael J. Spencer 2:1df0b61d3b5a 85 }
Michael J. Spencer 2:1df0b61d3b5a 86 }
Michael J. Spencer 2:1df0b61d3b5a 87
Michael J. Spencer 2:1df0b61d3b5a 88 /*********************************************************************//**
Michael J. Spencer 2:1df0b61d3b5a 89 * @brief Initial System Tick with using external clock source
Michael J. Spencer 2:1df0b61d3b5a 90 * @param[in] freq external clock frequency(Hz)
Michael J. Spencer 2:1df0b61d3b5a 91 * @param[in] time time interval(ms)
Michael J. Spencer 2:1df0b61d3b5a 92 * @return None
Michael J. Spencer 2:1df0b61d3b5a 93 **********************************************************************/
Michael J. Spencer 2:1df0b61d3b5a 94 void SYSTICK_ExternalInit(uint32_t freq, uint32_t time)
Michael J. Spencer 2:1df0b61d3b5a 95 {
Michael J. Spencer 2:1df0b61d3b5a 96 float maxtime;
Michael J. Spencer 2:1df0b61d3b5a 97
Michael J. Spencer 2:1df0b61d3b5a 98 /* With external clock frequency for LPC17xx is 'freq'
Michael J. Spencer 2:1df0b61d3b5a 99 * And limit 24 bit for RELOAD value
Michael J. Spencer 2:1df0b61d3b5a 100 * So the maximum time can be set:
Michael J. Spencer 2:1df0b61d3b5a 101 * 1/freq * (2^24) * 1000 (ms)
Michael J. Spencer 2:1df0b61d3b5a 102 */
Michael J. Spencer 2:1df0b61d3b5a 103 //check time value is available or not
Michael J. Spencer 2:1df0b61d3b5a 104 maxtime = (1<<24)/(freq / 1000) ;
Michael J. Spencer 2:1df0b61d3b5a 105 if (time>maxtime)
Michael J. Spencer 2:1df0b61d3b5a 106 //Error Loop
Michael J. Spencer 2:1df0b61d3b5a 107 while(1);
Michael J. Spencer 2:1df0b61d3b5a 108 else
Michael J. Spencer 2:1df0b61d3b5a 109 {
Michael J. Spencer 2:1df0b61d3b5a 110 //Select external clock is System Tick clock source
Michael J. Spencer 2:1df0b61d3b5a 111 SysTick->CTRL &= ~ ST_CTRL_CLKSOURCE;
Michael J. Spencer 2:1df0b61d3b5a 112 /* Set RELOAD value
Michael J. Spencer 2:1df0b61d3b5a 113 * RELOAD = (freq/1000) * time - 1
Michael J. Spencer 2:1df0b61d3b5a 114 * with time base is millisecond
Michael J. Spencer 2:1df0b61d3b5a 115 */
Michael J. Spencer 2:1df0b61d3b5a 116 maxtime = (freq/1000)*time - 1;
Michael J. Spencer 2:1df0b61d3b5a 117 SysTick->LOAD = (freq/1000)*time - 1;
Michael J. Spencer 2:1df0b61d3b5a 118 }
Michael J. Spencer 2:1df0b61d3b5a 119 }
Michael J. Spencer 2:1df0b61d3b5a 120
Michael J. Spencer 2:1df0b61d3b5a 121 /*********************************************************************//**
Michael J. Spencer 2:1df0b61d3b5a 122 * @brief Enable/disable System Tick counter
Michael J. Spencer 2:1df0b61d3b5a 123 * @param[in] NewState System Tick counter status, should be:
Michael J. Spencer 2:1df0b61d3b5a 124 * - ENABLE
Michael J. Spencer 2:1df0b61d3b5a 125 * - DISABLE
Michael J. Spencer 2:1df0b61d3b5a 126 * @return None
Michael J. Spencer 2:1df0b61d3b5a 127 **********************************************************************/
Michael J. Spencer 2:1df0b61d3b5a 128 void SYSTICK_Cmd(FunctionalState NewState)
Michael J. Spencer 2:1df0b61d3b5a 129 {
Michael J. Spencer 2:1df0b61d3b5a 130 CHECK_PARAM(PARAM_FUNCTIONALSTATE(NewState));
Michael J. Spencer 2:1df0b61d3b5a 131
Michael J. Spencer 2:1df0b61d3b5a 132 if(NewState == ENABLE)
Michael J. Spencer 2:1df0b61d3b5a 133 //Enable System Tick counter
Michael J. Spencer 2:1df0b61d3b5a 134 SysTick->CTRL |= ST_CTRL_ENABLE;
Michael J. Spencer 2:1df0b61d3b5a 135 else
Michael J. Spencer 2:1df0b61d3b5a 136 //Disable System Tick counter
Michael J. Spencer 2:1df0b61d3b5a 137 SysTick->CTRL &= ~ST_CTRL_ENABLE;
Michael J. Spencer 2:1df0b61d3b5a 138 }
Michael J. Spencer 2:1df0b61d3b5a 139
Michael J. Spencer 2:1df0b61d3b5a 140 /*********************************************************************//**
Michael J. Spencer 2:1df0b61d3b5a 141 * @brief Enable/disable System Tick interrupt
Michael J. Spencer 2:1df0b61d3b5a 142 * @param[in] NewState System Tick interrupt status, should be:
Michael J. Spencer 2:1df0b61d3b5a 143 * - ENABLE
Michael J. Spencer 2:1df0b61d3b5a 144 * - DISABLE
Michael J. Spencer 2:1df0b61d3b5a 145 * @return None
Michael J. Spencer 2:1df0b61d3b5a 146 **********************************************************************/
Michael J. Spencer 2:1df0b61d3b5a 147 void SYSTICK_IntCmd(FunctionalState NewState)
Michael J. Spencer 2:1df0b61d3b5a 148 {
Michael J. Spencer 2:1df0b61d3b5a 149 CHECK_PARAM(PARAM_FUNCTIONALSTATE(NewState));
Michael J. Spencer 2:1df0b61d3b5a 150
Michael J. Spencer 2:1df0b61d3b5a 151 if(NewState == ENABLE)
Michael J. Spencer 2:1df0b61d3b5a 152 //Enable System Tick counter
Michael J. Spencer 2:1df0b61d3b5a 153 SysTick->CTRL |= ST_CTRL_TICKINT;
Michael J. Spencer 2:1df0b61d3b5a 154 else
Michael J. Spencer 2:1df0b61d3b5a 155 //Disable System Tick counter
Michael J. Spencer 2:1df0b61d3b5a 156 SysTick->CTRL &= ~ST_CTRL_TICKINT;
Michael J. Spencer 2:1df0b61d3b5a 157 }
Michael J. Spencer 2:1df0b61d3b5a 158
Michael J. Spencer 2:1df0b61d3b5a 159 /*********************************************************************//**
Michael J. Spencer 2:1df0b61d3b5a 160 * @brief Get current value of System Tick counter
Michael J. Spencer 2:1df0b61d3b5a 161 * @param[in] None
Michael J. Spencer 2:1df0b61d3b5a 162 * @return current value of System Tick counter
Michael J. Spencer 2:1df0b61d3b5a 163 **********************************************************************/
Michael J. Spencer 2:1df0b61d3b5a 164 uint32_t SYSTICK_GetCurrentValue(void)
Michael J. Spencer 2:1df0b61d3b5a 165 {
Michael J. Spencer 2:1df0b61d3b5a 166 return (SysTick->VAL);
Michael J. Spencer 2:1df0b61d3b5a 167 }
Michael J. Spencer 2:1df0b61d3b5a 168
Michael J. Spencer 2:1df0b61d3b5a 169 /*********************************************************************//**
Michael J. Spencer 2:1df0b61d3b5a 170 * @brief Clear Counter flag
Michael J. Spencer 2:1df0b61d3b5a 171 * @param[in] None
Michael J. Spencer 2:1df0b61d3b5a 172 * @return None
Michael J. Spencer 2:1df0b61d3b5a 173 **********************************************************************/
Michael J. Spencer 2:1df0b61d3b5a 174 void SYSTICK_ClearCounterFlag(void)
Michael J. Spencer 2:1df0b61d3b5a 175 {
Michael J. Spencer 2:1df0b61d3b5a 176 SysTick->CTRL &= ~ST_CTRL_COUNTFLAG;
Michael J. Spencer 2:1df0b61d3b5a 177 }
Michael J. Spencer 2:1df0b61d3b5a 178 /**
Michael J. Spencer 2:1df0b61d3b5a 179 * @}
Michael J. Spencer 2:1df0b61d3b5a 180 */
Michael J. Spencer 2:1df0b61d3b5a 181
Michael J. Spencer 2:1df0b61d3b5a 182 #endif /* _SYSTICK */
Michael J. Spencer 2:1df0b61d3b5a 183
Michael J. Spencer 2:1df0b61d3b5a 184 /**
Michael J. Spencer 2:1df0b61d3b5a 185 * @}
Michael J. Spencer 2:1df0b61d3b5a 186 */
Michael J. Spencer 2:1df0b61d3b5a 187
Michael J. Spencer 2:1df0b61d3b5a 188 /* --------------------------------- End Of File ------------------------------ */
Michael J. Spencer 2:1df0b61d3b5a 189
Michael J. Spencer 2:1df0b61d3b5a 190 #endif /* __LPC17XX__ */