able to build lpc11u with IAR
clean ending warming with IAR
This commit is contained in:
		
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @@ -1,64 +1,64 @@ | ||||
| /**************************************************************************//** | ||||
|  * @file     system_LPC11Uxx.h | ||||
|  * @brief    CMSIS Cortex-M0 Device Peripheral Access Layer Header File | ||||
|  *           for the NXP LPC11Uxx Device Series | ||||
|  * @version  V1.10 | ||||
|  * @date     24. November 2010 | ||||
|  * | ||||
|  * @note | ||||
|  * Copyright (C) 2009-2010 ARM Limited. All rights reserved. | ||||
|  * | ||||
|  * @par | ||||
|  * ARM Limited (ARM) is supplying this software for use with Cortex-M  | ||||
|  * processor based microcontrollers.  This file can be freely distributed  | ||||
|  * within development tools that are supporting such ARM based processors.  | ||||
|  * | ||||
|  * @par | ||||
|  * THIS SOFTWARE IS PROVIDED "AS IS".  NO WARRANTIES, WHETHER EXPRESS, IMPLIED | ||||
|  * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF | ||||
|  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. | ||||
|  * ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR | ||||
|  * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. | ||||
|  * | ||||
|  ******************************************************************************/ | ||||
|  | ||||
|  | ||||
| #ifndef __SYSTEM_LPC11Uxx_H | ||||
| #define __SYSTEM_LPC11Uxx_H | ||||
|  | ||||
| #ifdef __cplusplus | ||||
| extern "C" { | ||||
| #endif | ||||
|  | ||||
| #include <stdint.h> | ||||
|  | ||||
| extern uint32_t SystemCoreClock;     /*!< System Clock Frequency (Core Clock)  */ | ||||
|  | ||||
|  | ||||
| /** | ||||
|  * Initialize the system | ||||
|  * | ||||
|  * @param  none | ||||
|  * @return none | ||||
|  * | ||||
|  * @brief  Setup the microcontroller system. | ||||
|  *         Initialize the System and update the SystemCoreClock variable. | ||||
|  */ | ||||
| extern void SystemInit (void); | ||||
|  | ||||
| /** | ||||
|  * Update SystemCoreClock variable | ||||
|  * | ||||
|  * @param  none | ||||
|  * @return none | ||||
|  * | ||||
|  * @brief  Updates the SystemCoreClock with current core Clock  | ||||
|  *         retrieved from cpu registers. | ||||
|  */ | ||||
| extern void SystemCoreClockUpdate (void); | ||||
|  | ||||
| #ifdef __cplusplus | ||||
| } | ||||
| #endif | ||||
|  | ||||
| #endif /* __SYSTEM_LPC11Uxx_H */ | ||||
| /**************************************************************************//** | ||||
|  * @file     system_LPC11Uxx.h | ||||
|  * @brief    CMSIS Cortex-M0 Device Peripheral Access Layer Header File | ||||
|  *           for the NXP LPC11Uxx Device Series | ||||
|  * @version  V1.10 | ||||
|  * @date     24. November 2010 | ||||
|  * | ||||
|  * @note | ||||
|  * Copyright (C) 2009-2010 ARM Limited. All rights reserved. | ||||
|  * | ||||
|  * @par | ||||
|  * ARM Limited (ARM) is supplying this software for use with Cortex-M | ||||
|  * processor based microcontrollers.  This file can be freely distributed | ||||
|  * within development tools that are supporting such ARM based processors. | ||||
|  * | ||||
|  * @par | ||||
|  * THIS SOFTWARE IS PROVIDED "AS IS".  NO WARRANTIES, WHETHER EXPRESS, IMPLIED | ||||
|  * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF | ||||
|  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. | ||||
|  * ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR | ||||
|  * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. | ||||
|  * | ||||
|  ******************************************************************************/ | ||||
|  | ||||
|  | ||||
| #ifndef __SYSTEM_LPC11Uxx_H | ||||
| #define __SYSTEM_LPC11Uxx_H | ||||
|  | ||||
| #ifdef __cplusplus | ||||
| extern "C" { | ||||
| #endif | ||||
|  | ||||
| #include <stdint.h> | ||||
|  | ||||
| extern uint32_t SystemCoreClock;     /*!< System Clock Frequency (Core Clock)  */ | ||||
|  | ||||
|  | ||||
| /** | ||||
|  * Initialize the system | ||||
|  * | ||||
|  * @param  none | ||||
|  * @return none | ||||
|  * | ||||
|  * @brief  Setup the microcontroller system. | ||||
|  *         Initialize the System and update the SystemCoreClock variable. | ||||
|  */ | ||||
| extern void SystemInit (void); | ||||
|  | ||||
| /** | ||||
|  * Update SystemCoreClock variable | ||||
|  * | ||||
|  * @param  none | ||||
|  * @return none | ||||
|  * | ||||
|  * @brief  Updates the SystemCoreClock with current core Clock | ||||
|  *         retrieved from cpu registers. | ||||
|  */ | ||||
| extern void SystemCoreClockUpdate (void); | ||||
|  | ||||
| #ifdef __cplusplus | ||||
| } | ||||
| #endif | ||||
|  | ||||
| #endif /* __SYSTEM_LPC11Uxx_H */ | ||||
|   | ||||
| @@ -1,279 +1,279 @@ | ||||
| /**************************************************************************//** | ||||
|  * @file     core_cm0.c | ||||
|  * @brief    CMSIS Cortex-M0 Core Peripheral Access Layer Source File | ||||
|  * @version  V2.00 | ||||
|  * @date     10. September 2010 | ||||
|  * | ||||
|  * @note | ||||
|  * Copyright (C) 2009-2010 ARM Limited. All rights reserved. | ||||
|  * | ||||
|  * @par | ||||
|  * ARM Limited (ARM) is supplying this software for use with Cortex-M  | ||||
|  * processor based microcontrollers.  This file can be freely distributed  | ||||
|  * within development tools that are supporting such ARM based processors.  | ||||
|  * | ||||
|  * @par | ||||
|  * THIS SOFTWARE IS PROVIDED "AS IS".  NO WARRANTIES, WHETHER EXPRESS, IMPLIED | ||||
|  * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF | ||||
|  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. | ||||
|  * ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR | ||||
|  * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. | ||||
|  * | ||||
|  ******************************************************************************/ | ||||
|  | ||||
| #include <stdint.h> | ||||
|  | ||||
| /* define compiler specific symbols */ | ||||
| #if defined ( __CC_ARM   ) | ||||
|   #define __ASM            __asm                                      /*!< asm keyword for ARM Compiler          */ | ||||
|   #define __INLINE         __inline                                   /*!< inline keyword for ARM Compiler       */ | ||||
|  | ||||
| #elif defined ( __ICCARM__ ) | ||||
|   #define __ASM           __asm                                       /*!< asm keyword for IAR Compiler          */ | ||||
|   #define __INLINE        inline                                      /*!< inline keyword for IAR Compiler. Only avaiable in High optimization mode! */ | ||||
|  | ||||
| #elif defined   (  __GNUC__  ) | ||||
|   #define __ASM            __asm                                      /*!< asm keyword for GNU Compiler          */ | ||||
|   #define __INLINE         inline                                     /*!< inline keyword for GNU Compiler       */ | ||||
|  | ||||
| #elif defined   (  __TASKING__  ) | ||||
|   #define __ASM            __asm                                      /*!< asm keyword for TASKING Compiler      */ | ||||
|   #define __INLINE         inline                                     /*!< inline keyword for TASKING Compiler   */ | ||||
|  | ||||
| #endif | ||||
|  | ||||
|  | ||||
| /* ##########################  Core Instruction Access  ######################### */ | ||||
|  | ||||
| #if defined ( __CC_ARM   ) /*------------------ RealView Compiler ----------------*/ | ||||
|  | ||||
| /** \brief  Reverse byte order (16 bit) | ||||
|  | ||||
|     This function reverses the byte order in two unsigned short values. | ||||
|  | ||||
|     \param [in]    value  Value to reverse | ||||
|     \return               Reversed value | ||||
|  */ | ||||
| #if (__ARMCC_VERSION < 400677) | ||||
| __ASM uint32_t __REV16(uint32_t value) | ||||
| { | ||||
|   rev16 r0, r0 | ||||
|   bx lr | ||||
| } | ||||
| #endif /* __ARMCC_VERSION  */  | ||||
|  | ||||
|  | ||||
| /** \brief  Reverse byte order in signed short value | ||||
|  | ||||
|     This function reverses the byte order in a signed short value with sign extension to integer. | ||||
|  | ||||
|     \param [in]    value  Value to reverse | ||||
|     \return               Reversed value | ||||
|  */ | ||||
| #if (__ARMCC_VERSION < 400677) | ||||
| __ASM int32_t __REVSH(int32_t value) | ||||
| { | ||||
|   revsh r0, r0 | ||||
|   bx lr | ||||
| } | ||||
| #endif /* __ARMCC_VERSION  */  | ||||
|  | ||||
|  | ||||
| /** \brief  Remove the exclusive lock | ||||
|  | ||||
|     This function removes the exclusive lock which is created by LDREX. | ||||
|  | ||||
|  */ | ||||
| #if (__ARMCC_VERSION < 400000) | ||||
| __ASM void __CLREX(void) | ||||
| { | ||||
|   clrex | ||||
| } | ||||
| #endif /* __ARMCC_VERSION  */  | ||||
|  | ||||
|  | ||||
| #elif (defined (__ICCARM__)) /*---------------- ICC Compiler ---------------------*/ | ||||
| /* obsolete */ | ||||
| #elif (defined (__GNUC__)) /*------------------ GNU Compiler ---------------------*/ | ||||
| /* obsolete */ | ||||
| #elif (defined (__TASKING__)) /*--------------- TASKING Compiler -----------------*/ | ||||
| /* obsolete */ | ||||
| #endif | ||||
|  | ||||
|  | ||||
| /* ###########################  Core Function Access  ########################### */ | ||||
|  | ||||
| #if defined ( __CC_ARM   ) /*------------------ RealView Compiler ----------------*/ | ||||
|  | ||||
| /** \brief  Get Control Register | ||||
|  | ||||
|     This function returns the content of the Control Register. | ||||
|  | ||||
|     \return               Control Register value | ||||
|  */ | ||||
| #if       (__ARMCC_VERSION <  400000) | ||||
| __ASM uint32_t __get_CONTROL(void) | ||||
| { | ||||
|   mrs r0, control | ||||
|   bx lr | ||||
| } | ||||
| #endif /*  __ARMCC_VERSION  */  | ||||
|  | ||||
|  | ||||
| /** \brief  Set Control Register | ||||
|  | ||||
|     This function writes the given value to the Control Register. | ||||
|  | ||||
|     \param [in]    control  Control Register value to set | ||||
|  */ | ||||
| #if       (__ARMCC_VERSION <  400000) | ||||
| __ASM void __set_CONTROL(uint32_t control) | ||||
| { | ||||
|   msr control, r0 | ||||
|   bx lr | ||||
| } | ||||
| #endif /*  __ARMCC_VERSION  */  | ||||
|  | ||||
|  | ||||
| /** \brief  Get ISPR Register | ||||
|  | ||||
|     This function returns the content of the ISPR Register. | ||||
|  | ||||
|     \return               ISPR Register value | ||||
|  */ | ||||
| #if       (__ARMCC_VERSION <  400000) | ||||
| __ASM uint32_t __get_IPSR(void) | ||||
| { | ||||
|   mrs r0, ipsr | ||||
|   bx lr | ||||
| } | ||||
| #endif /*  __ARMCC_VERSION  */  | ||||
|  | ||||
|  | ||||
| /** \brief  Get APSR Register | ||||
|  | ||||
|     This function returns the content of the APSR Register. | ||||
|  | ||||
|     \return               APSR Register value | ||||
|  */ | ||||
| #if       (__ARMCC_VERSION <  400000) | ||||
| __ASM uint32_t __get_APSR(void) | ||||
| { | ||||
|   mrs r0, apsr | ||||
|   bx lr | ||||
| } | ||||
| #endif /*  __ARMCC_VERSION  */  | ||||
|  | ||||
|  | ||||
| /** \brief  Get xPSR Register | ||||
|  | ||||
|     This function returns the content of the xPSR Register. | ||||
|  | ||||
|     \return               xPSR Register value | ||||
|  */ | ||||
| #if       (__ARMCC_VERSION <  400000) | ||||
| __ASM uint32_t __get_xPSR(void) | ||||
| { | ||||
|   mrs r0, xpsr | ||||
|   bx lr | ||||
| } | ||||
| #endif /*  __ARMCC_VERSION  */  | ||||
|  | ||||
|  | ||||
| /** \brief  Get Process Stack Pointer | ||||
|  | ||||
|     This function returns the current value of the Process Stack Pointer (PSP). | ||||
|  | ||||
|     \return               PSP Register value | ||||
|  */ | ||||
| #if       (__ARMCC_VERSION <  400000) | ||||
| __ASM uint32_t __get_PSP(void) | ||||
| { | ||||
|   mrs r0, psp | ||||
|   bx lr | ||||
| } | ||||
| #endif /*  __ARMCC_VERSION  */  | ||||
|  | ||||
|  | ||||
| /** \brief  Set Process Stack Pointer | ||||
|  | ||||
|     This function assigns the given value to the Process Stack Pointer (PSP). | ||||
|  | ||||
|     \param [in]    topOfProcStack  Process Stack Pointer value to set | ||||
|  */ | ||||
| #if       (__ARMCC_VERSION <  400000) | ||||
| __ASM void __set_PSP(uint32_t topOfProcStack) | ||||
| { | ||||
|   msr psp, r0 | ||||
|   bx lr | ||||
| } | ||||
| #endif /*  __ARMCC_VERSION  */  | ||||
|  | ||||
|  | ||||
| /** \brief  Get Main Stack Pointer | ||||
|  | ||||
|     This function returns the current value of the Main Stack Pointer (MSP). | ||||
|  | ||||
|     \return               MSP Register value | ||||
|  */ | ||||
| #if       (__ARMCC_VERSION <  400000) | ||||
| __ASM uint32_t __get_MSP(void) | ||||
| { | ||||
|   mrs r0, msp | ||||
|   bx lr | ||||
| } | ||||
| #endif /*  __ARMCC_VERSION  */  | ||||
|  | ||||
|  | ||||
| /** \brief  Set Main Stack Pointer | ||||
|  | ||||
|     This function assigns the given value to the Main Stack Pointer (MSP). | ||||
|  | ||||
|     \param [in]    topOfMainStack  Main Stack Pointer value to set | ||||
|  */ | ||||
| #if       (__ARMCC_VERSION <  400000) | ||||
| __ASM void __set_MSP(uint32_t mainStackPointer) | ||||
| { | ||||
|   msr msp, r0 | ||||
|   bx lr | ||||
| } | ||||
| #endif /*  __ARMCC_VERSION  */  | ||||
|  | ||||
|  | ||||
| /** \brief  Get Priority Mask | ||||
|  | ||||
|     This function returns the current state of the priority mask bit from the Priority Mask Register. | ||||
|  | ||||
|     \return               Priority Mask value | ||||
|  */ | ||||
| #if       (__ARMCC_VERSION <  400000) | ||||
| __ASM uint32_t __get_PRIMASK(void) | ||||
| { | ||||
|   mrs r0, primask | ||||
|   bx lr | ||||
| } | ||||
| #endif /*  __ARMCC_VERSION  */  | ||||
|  | ||||
|  | ||||
| /** \brief  Set Priority Mask | ||||
|  | ||||
|     This function assigns the given value to the Priority Mask Register. | ||||
|  | ||||
|     \param [in]    priMask  Priority Mask | ||||
|  */ | ||||
| #if       (__ARMCC_VERSION <  400000) | ||||
| __ASM void __set_PRIMASK(uint32_t priMask) | ||||
| { | ||||
|   msr primask, r0 | ||||
|   bx lr | ||||
| } | ||||
| #endif /*  __ARMCC_VERSION  */  | ||||
|   | ||||
|  | ||||
| #elif (defined (__ICCARM__)) /*---------------- ICC Compiler ---------------------*/ | ||||
| /* obsolete */ | ||||
| #elif (defined (__GNUC__)) /*------------------ GNU Compiler ---------------------*/ | ||||
| /* obsolete */ | ||||
| #elif (defined (__TASKING__)) /*--------------- TASKING Compiler -----------------*/ | ||||
| /* obsolete */ | ||||
| #endif | ||||
| /**************************************************************************//** | ||||
|  * @file     core_cm0.c | ||||
|  * @brief    CMSIS Cortex-M0 Core Peripheral Access Layer Source File | ||||
|  * @version  V2.00 | ||||
|  * @date     10. September 2010 | ||||
|  * | ||||
|  * @note | ||||
|  * Copyright (C) 2009-2010 ARM Limited. All rights reserved. | ||||
|  * | ||||
|  * @par | ||||
|  * ARM Limited (ARM) is supplying this software for use with Cortex-M | ||||
|  * processor based microcontrollers.  This file can be freely distributed | ||||
|  * within development tools that are supporting such ARM based processors. | ||||
|  * | ||||
|  * @par | ||||
|  * THIS SOFTWARE IS PROVIDED "AS IS".  NO WARRANTIES, WHETHER EXPRESS, IMPLIED | ||||
|  * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF | ||||
|  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. | ||||
|  * ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR | ||||
|  * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. | ||||
|  * | ||||
|  ******************************************************************************/ | ||||
|  | ||||
| #include <stdint.h> | ||||
|  | ||||
| /* define compiler specific symbols */ | ||||
| #if defined ( __CC_ARM   ) | ||||
|   #define __ASM            __asm                                      /*!< asm keyword for ARM Compiler          */ | ||||
|   #define __INLINE         __inline                                   /*!< inline keyword for ARM Compiler       */ | ||||
|  | ||||
| #elif defined ( __ICCARM__ ) | ||||
|   #define __ASM           __asm                                       /*!< asm keyword for IAR Compiler          */ | ||||
|   #define __INLINE        inline                                      /*!< inline keyword for IAR Compiler. Only avaiable in High optimization mode! */ | ||||
|  | ||||
| #elif defined   (  __GNUC__  ) | ||||
|   #define __ASM            __asm                                      /*!< asm keyword for GNU Compiler          */ | ||||
|   #define __INLINE         inline                                     /*!< inline keyword for GNU Compiler       */ | ||||
|  | ||||
| #elif defined   (  __TASKING__  ) | ||||
|   #define __ASM            __asm                                      /*!< asm keyword for TASKING Compiler      */ | ||||
|   #define __INLINE         inline                                     /*!< inline keyword for TASKING Compiler   */ | ||||
|  | ||||
| #endif | ||||
|  | ||||
|  | ||||
| /* ##########################  Core Instruction Access  ######################### */ | ||||
|  | ||||
| #if defined ( __CC_ARM   ) /*------------------ RealView Compiler ----------------*/ | ||||
|  | ||||
| /** \brief  Reverse byte order (16 bit) | ||||
|  | ||||
|     This function reverses the byte order in two unsigned short values. | ||||
|  | ||||
|     \param [in]    value  Value to reverse | ||||
|     \return               Reversed value | ||||
|  */ | ||||
| #if (__ARMCC_VERSION < 400677) | ||||
| __ASM uint32_t __REV16(uint32_t value) | ||||
| { | ||||
|   rev16 r0, r0 | ||||
|   bx lr | ||||
| } | ||||
| #endif /* __ARMCC_VERSION  */ | ||||
|  | ||||
|  | ||||
| /** \brief  Reverse byte order in signed short value | ||||
|  | ||||
|     This function reverses the byte order in a signed short value with sign extension to integer. | ||||
|  | ||||
|     \param [in]    value  Value to reverse | ||||
|     \return               Reversed value | ||||
|  */ | ||||
| #if (__ARMCC_VERSION < 400677) | ||||
| __ASM int32_t __REVSH(int32_t value) | ||||
| { | ||||
|   revsh r0, r0 | ||||
|   bx lr | ||||
| } | ||||
| #endif /* __ARMCC_VERSION  */ | ||||
|  | ||||
|  | ||||
| /** \brief  Remove the exclusive lock | ||||
|  | ||||
|     This function removes the exclusive lock which is created by LDREX. | ||||
|  | ||||
|  */ | ||||
| #if (__ARMCC_VERSION < 400000) | ||||
| __ASM void __CLREX(void) | ||||
| { | ||||
|   clrex | ||||
| } | ||||
| #endif /* __ARMCC_VERSION  */ | ||||
|  | ||||
|  | ||||
| #elif (defined (__ICCARM__)) /*---------------- ICC Compiler ---------------------*/ | ||||
| /* obsolete */ | ||||
| #elif (defined (__GNUC__)) /*------------------ GNU Compiler ---------------------*/ | ||||
| /* obsolete */ | ||||
| #elif (defined (__TASKING__)) /*--------------- TASKING Compiler -----------------*/ | ||||
| /* obsolete */ | ||||
| #endif | ||||
|  | ||||
|  | ||||
| /* ###########################  Core Function Access  ########################### */ | ||||
|  | ||||
| #if defined ( __CC_ARM   ) /*------------------ RealView Compiler ----------------*/ | ||||
|  | ||||
| /** \brief  Get Control Register | ||||
|  | ||||
|     This function returns the content of the Control Register. | ||||
|  | ||||
|     \return               Control Register value | ||||
|  */ | ||||
| #if       (__ARMCC_VERSION <  400000) | ||||
| __ASM uint32_t __get_CONTROL(void) | ||||
| { | ||||
|   mrs r0, control | ||||
|   bx lr | ||||
| } | ||||
| #endif /*  __ARMCC_VERSION  */ | ||||
|  | ||||
|  | ||||
| /** \brief  Set Control Register | ||||
|  | ||||
|     This function writes the given value to the Control Register. | ||||
|  | ||||
|     \param [in]    control  Control Register value to set | ||||
|  */ | ||||
| #if       (__ARMCC_VERSION <  400000) | ||||
| __ASM void __set_CONTROL(uint32_t control) | ||||
| { | ||||
|   msr control, r0 | ||||
|   bx lr | ||||
| } | ||||
| #endif /*  __ARMCC_VERSION  */ | ||||
|  | ||||
|  | ||||
| /** \brief  Get ISPR Register | ||||
|  | ||||
|     This function returns the content of the ISPR Register. | ||||
|  | ||||
|     \return               ISPR Register value | ||||
|  */ | ||||
| #if       (__ARMCC_VERSION <  400000) | ||||
| __ASM uint32_t __get_IPSR(void) | ||||
| { | ||||
|   mrs r0, ipsr | ||||
|   bx lr | ||||
| } | ||||
| #endif /*  __ARMCC_VERSION  */ | ||||
|  | ||||
|  | ||||
| /** \brief  Get APSR Register | ||||
|  | ||||
|     This function returns the content of the APSR Register. | ||||
|  | ||||
|     \return               APSR Register value | ||||
|  */ | ||||
| #if       (__ARMCC_VERSION <  400000) | ||||
| __ASM uint32_t __get_APSR(void) | ||||
| { | ||||
|   mrs r0, apsr | ||||
|   bx lr | ||||
| } | ||||
| #endif /*  __ARMCC_VERSION  */ | ||||
|  | ||||
|  | ||||
| /** \brief  Get xPSR Register | ||||
|  | ||||
|     This function returns the content of the xPSR Register. | ||||
|  | ||||
|     \return               xPSR Register value | ||||
|  */ | ||||
| #if       (__ARMCC_VERSION <  400000) | ||||
| __ASM uint32_t __get_xPSR(void) | ||||
| { | ||||
|   mrs r0, xpsr | ||||
|   bx lr | ||||
| } | ||||
| #endif /*  __ARMCC_VERSION  */ | ||||
|  | ||||
|  | ||||
| /** \brief  Get Process Stack Pointer | ||||
|  | ||||
|     This function returns the current value of the Process Stack Pointer (PSP). | ||||
|  | ||||
|     \return               PSP Register value | ||||
|  */ | ||||
| #if       (__ARMCC_VERSION <  400000) | ||||
| __ASM uint32_t __get_PSP(void) | ||||
| { | ||||
|   mrs r0, psp | ||||
|   bx lr | ||||
| } | ||||
| #endif /*  __ARMCC_VERSION  */ | ||||
|  | ||||
|  | ||||
| /** \brief  Set Process Stack Pointer | ||||
|  | ||||
|     This function assigns the given value to the Process Stack Pointer (PSP). | ||||
|  | ||||
|     \param [in]    topOfProcStack  Process Stack Pointer value to set | ||||
|  */ | ||||
| #if       (__ARMCC_VERSION <  400000) | ||||
| __ASM void __set_PSP(uint32_t topOfProcStack) | ||||
| { | ||||
|   msr psp, r0 | ||||
|   bx lr | ||||
| } | ||||
| #endif /*  __ARMCC_VERSION  */ | ||||
|  | ||||
|  | ||||
| /** \brief  Get Main Stack Pointer | ||||
|  | ||||
|     This function returns the current value of the Main Stack Pointer (MSP). | ||||
|  | ||||
|     \return               MSP Register value | ||||
|  */ | ||||
| #if       (__ARMCC_VERSION <  400000) | ||||
| __ASM uint32_t __get_MSP(void) | ||||
| { | ||||
|   mrs r0, msp | ||||
|   bx lr | ||||
| } | ||||
| #endif /*  __ARMCC_VERSION  */ | ||||
|  | ||||
|  | ||||
| /** \brief  Set Main Stack Pointer | ||||
|  | ||||
|     This function assigns the given value to the Main Stack Pointer (MSP). | ||||
|  | ||||
|     \param [in]    topOfMainStack  Main Stack Pointer value to set | ||||
|  */ | ||||
| #if       (__ARMCC_VERSION <  400000) | ||||
| __ASM void __set_MSP(uint32_t mainStackPointer) | ||||
| { | ||||
|   msr msp, r0 | ||||
|   bx lr | ||||
| } | ||||
| #endif /*  __ARMCC_VERSION  */ | ||||
|  | ||||
|  | ||||
| /** \brief  Get Priority Mask | ||||
|  | ||||
|     This function returns the current state of the priority mask bit from the Priority Mask Register. | ||||
|  | ||||
|     \return               Priority Mask value | ||||
|  */ | ||||
| #if       (__ARMCC_VERSION <  400000) | ||||
| __ASM uint32_t __get_PRIMASK(void) | ||||
| { | ||||
|   mrs r0, primask | ||||
|   bx lr | ||||
| } | ||||
| #endif /*  __ARMCC_VERSION  */ | ||||
|  | ||||
|  | ||||
| /** \brief  Set Priority Mask | ||||
|  | ||||
|     This function assigns the given value to the Priority Mask Register. | ||||
|  | ||||
|     \param [in]    priMask  Priority Mask | ||||
|  */ | ||||
| #if       (__ARMCC_VERSION <  400000) | ||||
| __ASM void __set_PRIMASK(uint32_t priMask) | ||||
| { | ||||
|   msr primask, r0 | ||||
|   bx lr | ||||
| } | ||||
| #endif /*  __ARMCC_VERSION  */ | ||||
|  | ||||
|  | ||||
| #elif (defined (__ICCARM__)) /*---------------- ICC Compiler ---------------------*/ | ||||
| /* obsolete */ | ||||
| #elif (defined (__GNUC__)) /*------------------ GNU Compiler ---------------------*/ | ||||
| /* obsolete */ | ||||
| #elif (defined (__TASKING__)) /*--------------- TASKING Compiler -----------------*/ | ||||
| /* obsolete */ | ||||
| #endif | ||||
|   | ||||
| @@ -1,451 +1,451 @@ | ||||
| /****************************************************************************** | ||||
|  * @file     system_LPC11Uxx.c | ||||
|  * @purpose  CMSIS Cortex-M3 Device Peripheral Access Layer Source File | ||||
|  *           for the NXP LPC13xx Device Series | ||||
|  * @version  V1.10 | ||||
|  * @date     24. November 2010 | ||||
|  * | ||||
|  * @note | ||||
|  * Copyright (C) 2009-2010 ARM Limited. All rights reserved. | ||||
|  * | ||||
|  * @par | ||||
|  * ARM Limited (ARM) is supplying this software for use with Cortex-M  | ||||
|  * processor based microcontrollers.  This file can be freely distributed  | ||||
|  * within development tools that are supporting such ARM based processors.  | ||||
|  * | ||||
|  * @par | ||||
|  * THIS SOFTWARE IS PROVIDED "AS IS".  NO WARRANTIES, WHETHER EXPRESS, IMPLIED | ||||
|  * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF | ||||
|  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. | ||||
|  * ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR | ||||
|  * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. | ||||
|  * | ||||
|  ******************************************************************************/ | ||||
|  | ||||
|  | ||||
| #include <stdint.h> | ||||
| #include "LPC11Uxx.h" | ||||
|  | ||||
| /* | ||||
| //-------- <<< Use Configuration Wizard in Context Menu >>> ------------------ | ||||
| */ | ||||
|  | ||||
| /*--------------------- Clock Configuration ---------------------------------- | ||||
| // | ||||
| // <e> Clock Configuration | ||||
| //   <h> System Oscillator Control Register (SYSOSCCTRL) | ||||
| //     <o1.0>      BYPASS: System Oscillator Bypass Enable | ||||
| //                     <i> If enabled then PLL input (sys_osc_clk) is fed | ||||
| //                     <i> directly from XTALIN and XTALOUT pins. | ||||
| //     <o1.9>      FREQRANGE: System Oscillator Frequency Range | ||||
| //                     <i> Determines frequency range for Low-power oscillator. | ||||
| //                   <0=> 1 - 20 MHz | ||||
| //                   <1=> 15 - 25 MHz | ||||
| //   </h> | ||||
| // | ||||
| //   <h> Watchdog Oscillator Control Register (WDTOSCCTRL) | ||||
| //     <o2.0..4>   DIVSEL: Select Divider for Fclkana | ||||
| //                     <i> wdt_osc_clk = Fclkana/ (2 <20> (1 + DIVSEL)) | ||||
| //                   <0-31> | ||||
| //     <o2.5..8>   FREQSEL: Select Watchdog Oscillator Analog Output Frequency (Fclkana) | ||||
| //                   <0=> Undefined | ||||
| //                   <1=> 0.5 MHz | ||||
| //                   <2=> 0.8 MHz | ||||
| //                   <3=> 1.1 MHz | ||||
| //                   <4=> 1.4 MHz | ||||
| //                   <5=> 1.6 MHz | ||||
| //                   <6=> 1.8 MHz | ||||
| //                   <7=> 2.0 MHz | ||||
| //                   <8=> 2.2 MHz | ||||
| //                   <9=> 2.4 MHz | ||||
| //                   <10=> 2.6 MHz | ||||
| //                   <11=> 2.7 MHz | ||||
| //                   <12=> 2.9 MHz | ||||
| //                   <13=> 3.1 MHz | ||||
| //                   <14=> 3.2 MHz | ||||
| //                   <15=> 3.4 MHz | ||||
| //   </h> | ||||
| // | ||||
| //   <h> System PLL Control Register (SYSPLLCTRL) | ||||
| //                   <i> F_clkout = M * F_clkin = F_CCO / (2 * P) | ||||
| //                   <i> F_clkin must be in the range of  10 MHz to  25 MHz | ||||
| //                   <i> F_CCO   must be in the range of 156 MHz to 320 MHz | ||||
| //     <o3.0..4>   MSEL: Feedback Divider Selection | ||||
| //                     <i> M = MSEL + 1 | ||||
| //                   <0-31> | ||||
| //     <o3.5..6>   PSEL: Post Divider Selection | ||||
| //                   <0=> P = 1 | ||||
| //                   <1=> P = 2 | ||||
| //                   <2=> P = 4 | ||||
| //                   <3=> P = 8 | ||||
| //   </h> | ||||
| // | ||||
| //   <h> System PLL Clock Source Select Register (SYSPLLCLKSEL) | ||||
| //     <o4.0..1>   SEL: System PLL Clock Source | ||||
| //                   <0=> IRC Oscillator | ||||
| //                   <1=> System Oscillator | ||||
| //                   <2=> Reserved | ||||
| //                   <3=> Reserved | ||||
| //   </h> | ||||
| // | ||||
| //   <h> Main Clock Source Select Register (MAINCLKSEL) | ||||
| //     <o5.0..1>   SEL: Clock Source for Main Clock | ||||
| //                   <0=> IRC Oscillator | ||||
| //                   <1=> Input Clock to System PLL | ||||
| //                   <2=> WDT Oscillator | ||||
| //                   <3=> System PLL Clock Out | ||||
| //   </h> | ||||
| // | ||||
| //   <h> System AHB Clock Divider Register (SYSAHBCLKDIV) | ||||
| //     <o6.0..7>   DIV: System AHB Clock Divider | ||||
| //                     <i> Divides main clock to provide system clock to core, memories, and peripherals. | ||||
| //                     <i> 0 = is disabled | ||||
| //                   <0-255> | ||||
| //   </h> | ||||
| // | ||||
| //   <h> USB PLL Control Register (USBPLLCTRL) | ||||
| //                   <i> F_clkout = M * F_clkin = F_CCO / (2 * P) | ||||
| //                   <i> F_clkin must be in the range of  10 MHz to  25 MHz | ||||
| //                   <i> F_CCO   must be in the range of 156 MHz to 320 MHz | ||||
| //     <o7.0..4>   MSEL: Feedback Divider Selection | ||||
| //                     <i> M = MSEL + 1 | ||||
| //                   <0-31> | ||||
| //     <o7.5..6>   PSEL: Post Divider Selection | ||||
| //                   <0=> P = 1 | ||||
| //                   <1=> P = 2 | ||||
| //                   <2=> P = 4 | ||||
| //                   <3=> P = 8 | ||||
| //   </h> | ||||
| // | ||||
| //   <h> USB PLL Clock Source Select Register (USBPLLCLKSEL) | ||||
| //     <o8.0..1>   SEL: USB PLL Clock Source | ||||
| //                     <i> USB PLL clock source must be switched to System Oscillator for correct USB operation | ||||
| //                   <0=> IRC Oscillator | ||||
| //                   <1=> System Oscillator | ||||
| //                   <2=> Reserved | ||||
| //                   <3=> Reserved | ||||
| //   </h> | ||||
| // | ||||
| //   <h> USB Clock Source Select Register (USBCLKSEL) | ||||
| //     <o9.0..1>   SEL: System PLL Clock Source | ||||
| //                   <0=> USB PLL out | ||||
| //                   <1=> Main clock | ||||
| //                   <2=> Reserved | ||||
| //                   <3=> Reserved | ||||
| //   </h> | ||||
| // | ||||
| //   <h> USB Clock Divider Register (USBCLKDIV) | ||||
| //     <o10.0..7>  DIV: USB Clock Divider | ||||
| //                     <i> Divides USB clock to 48 MHz. | ||||
| //                     <i> 0 = is disabled | ||||
| //                   <0-255> | ||||
| //   </h> | ||||
| // </e> | ||||
| */ | ||||
| #define CLOCK_SETUP           1 | ||||
| #define SYSOSCCTRL_Val        0x00000000              // Reset: 0x000 | ||||
| #define WDTOSCCTRL_Val        0x00000000              // Reset: 0x000 | ||||
| #define SYSPLLCTRL_Val        0x00000023              // Reset: 0x000 | ||||
| #define SYSPLLCLKSEL_Val      0x00000001              // Reset: 0x000 | ||||
| #define MAINCLKSEL_Val        0x00000003              // Reset: 0x000 | ||||
| #define SYSAHBCLKDIV_Val      0x00000001              // Reset: 0x001 | ||||
| #define USBPLLCTRL_Val        0x00000023              // Reset: 0x000 | ||||
| #define USBPLLCLKSEL_Val      0x00000001              // Reset: 0x000 | ||||
| #define USBCLKSEL_Val         0x00000000              // Reset: 0x000 | ||||
| #define USBCLKDIV_Val         0x00000001              // Reset: 0x001 | ||||
|  | ||||
| /* | ||||
| //-------- <<< end of configuration section >>> ------------------------------ | ||||
| */ | ||||
|  | ||||
| /*---------------------------------------------------------------------------- | ||||
|   Check the register settings | ||||
|  *----------------------------------------------------------------------------*/ | ||||
| #define CHECK_RANGE(val, min, max)                ((val < min) || (val > max)) | ||||
| #define CHECK_RSVD(val, mask)                     (val & mask) | ||||
|  | ||||
| /* Clock Configuration -------------------------------------------------------*/ | ||||
| #if (CHECK_RSVD((SYSOSCCTRL_Val),  ~0x00000003)) | ||||
|    #error "SYSOSCCTRL: Invalid values of reserved bits!" | ||||
| #endif | ||||
|  | ||||
| #if (CHECK_RSVD((WDTOSCCTRL_Val),  ~0x000001FF)) | ||||
|    #error "WDTOSCCTRL: Invalid values of reserved bits!" | ||||
| #endif | ||||
|  | ||||
| #if (CHECK_RANGE((SYSPLLCLKSEL_Val), 0, 2)) | ||||
|    #error "SYSPLLCLKSEL: Value out of range!" | ||||
| #endif | ||||
|  | ||||
| #if (CHECK_RSVD((SYSPLLCTRL_Val),  ~0x000001FF)) | ||||
|    #error "SYSPLLCTRL: Invalid values of reserved bits!" | ||||
| #endif | ||||
|  | ||||
| #if (CHECK_RSVD((MAINCLKSEL_Val),  ~0x00000003)) | ||||
|    #error "MAINCLKSEL: Invalid values of reserved bits!" | ||||
| #endif | ||||
|  | ||||
| #if (CHECK_RANGE((SYSAHBCLKDIV_Val), 0, 255)) | ||||
|    #error "SYSAHBCLKDIV: Value out of range!" | ||||
| #endif | ||||
|  | ||||
| #if (CHECK_RANGE((USBPLLCLKSEL_Val), 0, 1)) | ||||
|    #error "USBPLLCLKSEL: Value out of range!" | ||||
| #endif | ||||
|  | ||||
| #if (CHECK_RSVD((USBPLLCTRL_Val),  ~0x000001FF)) | ||||
|    #error "USBPLLCTRL: Invalid values of reserved bits!" | ||||
| #endif | ||||
|  | ||||
| #if (CHECK_RANGE((USBCLKSEL_Val), 0, 1)) | ||||
|    #error "USBCLKSEL: Value out of range!" | ||||
| #endif | ||||
|  | ||||
| #if (CHECK_RANGE((USBCLKDIV_Val), 0, 255)) | ||||
|    #error "USBCLKDIV: Value out of range!" | ||||
| #endif | ||||
|  | ||||
|  | ||||
| /*---------------------------------------------------------------------------- | ||||
|   DEFINES | ||||
|  *----------------------------------------------------------------------------*/ | ||||
|      | ||||
| /*---------------------------------------------------------------------------- | ||||
|   Define clocks | ||||
|  *----------------------------------------------------------------------------*/ | ||||
| #define __XTAL            (12000000UL)    /* Oscillator frequency             */ | ||||
| #define __SYS_OSC_CLK     (    __XTAL)    /* Main oscillator frequency        */ | ||||
| #define __IRC_OSC_CLK     (12000000UL)    /* Internal RC oscillator frequency */ | ||||
|  | ||||
|  | ||||
| #define __FREQSEL   ((WDTOSCCTRL_Val >> 5) & 0x0F) | ||||
| #define __DIVSEL   (((WDTOSCCTRL_Val & 0x1F) << 1) + 2) | ||||
|  | ||||
| #if (CLOCK_SETUP)                         /* Clock Setup              */ | ||||
|   #if  (__FREQSEL ==  0) | ||||
|     #define __WDT_OSC_CLK        ( 0)                  /* undefined */ | ||||
|   #elif (__FREQSEL ==  1) | ||||
|     #define __WDT_OSC_CLK        ( 500000 / __DIVSEL) | ||||
|   #elif (__FREQSEL ==  2) | ||||
|     #define __WDT_OSC_CLK        ( 800000 / __DIVSEL) | ||||
|   #elif (__FREQSEL ==  3) | ||||
|     #define __WDT_OSC_CLK        (1100000 / __DIVSEL) | ||||
|   #elif (__FREQSEL ==  4) | ||||
|     #define __WDT_OSC_CLK        (1400000 / __DIVSEL) | ||||
|   #elif (__FREQSEL ==  5) | ||||
|     #define __WDT_OSC_CLK        (1600000 / __DIVSEL) | ||||
|   #elif (__FREQSEL ==  6) | ||||
|     #define __WDT_OSC_CLK        (1800000 / __DIVSEL) | ||||
|   #elif (__FREQSEL ==  7) | ||||
|     #define __WDT_OSC_CLK        (2000000 / __DIVSEL) | ||||
|   #elif (__FREQSEL ==  8) | ||||
|     #define __WDT_OSC_CLK        (2200000 / __DIVSEL) | ||||
|   #elif (__FREQSEL ==  9) | ||||
|     #define __WDT_OSC_CLK        (2400000 / __DIVSEL) | ||||
|   #elif (__FREQSEL == 10) | ||||
|     #define __WDT_OSC_CLK        (2600000 / __DIVSEL) | ||||
|   #elif (__FREQSEL == 11) | ||||
|     #define __WDT_OSC_CLK        (2700000 / __DIVSEL) | ||||
|   #elif (__FREQSEL == 12) | ||||
|     #define __WDT_OSC_CLK        (2900000 / __DIVSEL) | ||||
|   #elif (__FREQSEL == 13) | ||||
|     #define __WDT_OSC_CLK        (3100000 / __DIVSEL) | ||||
|   #elif (__FREQSEL == 14) | ||||
|     #define __WDT_OSC_CLK        (3200000 / __DIVSEL) | ||||
|   #else | ||||
|     #define __WDT_OSC_CLK        (3400000 / __DIVSEL) | ||||
|   #endif | ||||
|  | ||||
|   /* sys_pllclkin calculation */ | ||||
|   #if   ((SYSPLLCLKSEL_Val & 0x03) == 0) | ||||
|     #define __SYS_PLLCLKIN           (__IRC_OSC_CLK) | ||||
|   #elif ((SYSPLLCLKSEL_Val & 0x03) == 1) | ||||
|     #define __SYS_PLLCLKIN           (__SYS_OSC_CLK) | ||||
|   #else | ||||
|     #define __SYS_PLLCLKIN           (0) | ||||
|   #endif | ||||
|  | ||||
|   #define  __SYS_PLLCLKOUT         (__SYS_PLLCLKIN * ((SYSPLLCTRL_Val & 0x01F) + 1)) | ||||
|  | ||||
|   /* main clock calculation */ | ||||
|   #if   ((MAINCLKSEL_Val & 0x03) == 0) | ||||
|     #define __MAIN_CLOCK             (__IRC_OSC_CLK) | ||||
|   #elif ((MAINCLKSEL_Val & 0x03) == 1) | ||||
|     #define __MAIN_CLOCK             (__SYS_PLLCLKIN) | ||||
|   #elif ((MAINCLKSEL_Val & 0x03) == 2) | ||||
|     #if (__FREQSEL ==  0) | ||||
|       #error "MAINCLKSEL: WDT Oscillator selected but FREQSEL is undefined!" | ||||
|     #else | ||||
|       #define __MAIN_CLOCK           (__WDT_OSC_CLK) | ||||
|     #endif | ||||
|   #elif ((MAINCLKSEL_Val & 0x03) == 3) | ||||
|     #define __MAIN_CLOCK             (__SYS_PLLCLKOUT) | ||||
|   #else | ||||
|     #define __MAIN_CLOCK             (0) | ||||
|   #endif | ||||
|  | ||||
|   #define __SYSTEM_CLOCK             (__MAIN_CLOCK / SYSAHBCLKDIV_Val)          | ||||
|  | ||||
| #else | ||||
|   #define __SYSTEM_CLOCK             (__IRC_OSC_CLK) | ||||
| #endif  // CLOCK_SETUP  | ||||
|  | ||||
|  | ||||
| /*---------------------------------------------------------------------------- | ||||
|   Clock Variable definitions | ||||
|  *----------------------------------------------------------------------------*/ | ||||
| uint32_t SystemCoreClock = __SYSTEM_CLOCK;/*!< System Clock Frequency (Core Clock)*/ | ||||
|  | ||||
|  | ||||
| /*---------------------------------------------------------------------------- | ||||
|   Clock functions | ||||
|  *----------------------------------------------------------------------------*/ | ||||
| void SystemCoreClockUpdate (void)            /* Get Core Clock Frequency      */ | ||||
| { | ||||
|   uint32_t wdt_osc = 0; | ||||
|  | ||||
|   /* Determine clock frequency according to clock register values             */ | ||||
|   switch ((LPC_SYSCON->WDTOSCCTRL >> 5) & 0x0F) { | ||||
|     case 0:  wdt_osc =       0; break; | ||||
|     case 1:  wdt_osc =  500000; break; | ||||
|     case 2:  wdt_osc =  800000; break; | ||||
|     case 3:  wdt_osc = 1100000; break; | ||||
|     case 4:  wdt_osc = 1400000; break; | ||||
|     case 5:  wdt_osc = 1600000; break; | ||||
|     case 6:  wdt_osc = 1800000; break; | ||||
|     case 7:  wdt_osc = 2000000; break; | ||||
|     case 8:  wdt_osc = 2200000; break; | ||||
|     case 9:  wdt_osc = 2400000; break; | ||||
|     case 10: wdt_osc = 2600000; break; | ||||
|     case 11: wdt_osc = 2700000; break; | ||||
|     case 12: wdt_osc = 2900000; break; | ||||
|     case 13: wdt_osc = 3100000; break; | ||||
|     case 14: wdt_osc = 3200000; break; | ||||
|     case 15: wdt_osc = 3400000; break; | ||||
|   } | ||||
|   wdt_osc /= ((LPC_SYSCON->WDTOSCCTRL & 0x1F) << 1) + 2; | ||||
|   | ||||
|   switch (LPC_SYSCON->MAINCLKSEL & 0x03) { | ||||
|     case 0:                             /* Internal RC oscillator             */ | ||||
|       SystemCoreClock = __IRC_OSC_CLK; | ||||
|       break; | ||||
|     case 1:                             /* Input Clock to System PLL          */ | ||||
|       switch (LPC_SYSCON->SYSPLLCLKSEL & 0x03) { | ||||
|           case 0:                       /* Internal RC oscillator             */ | ||||
|             SystemCoreClock = __IRC_OSC_CLK; | ||||
|             break; | ||||
|           case 1:                       /* System oscillator                  */ | ||||
|             SystemCoreClock = __SYS_OSC_CLK; | ||||
|             break; | ||||
|           case 2:                       /* Reserved                           */ | ||||
|           case 3:                       /* Reserved                           */ | ||||
|             SystemCoreClock = 0; | ||||
|             break; | ||||
|       } | ||||
|       break; | ||||
|     case 2:                             /* WDT Oscillator                     */ | ||||
|       SystemCoreClock = wdt_osc; | ||||
|       break; | ||||
|     case 3:                             /* System PLL Clock Out               */ | ||||
|       switch (LPC_SYSCON->SYSPLLCLKSEL & 0x03) { | ||||
|           case 0:                       /* Internal RC oscillator             */ | ||||
|             if (LPC_SYSCON->SYSPLLCTRL & 0x180) { | ||||
|               SystemCoreClock = __IRC_OSC_CLK; | ||||
|             } else { | ||||
|               SystemCoreClock = __IRC_OSC_CLK * ((LPC_SYSCON->SYSPLLCTRL & 0x01F) + 1); | ||||
|             } | ||||
|             break; | ||||
|           case 1:                       /* System oscillator                  */ | ||||
|             if (LPC_SYSCON->SYSPLLCTRL & 0x180) { | ||||
|               SystemCoreClock = __SYS_OSC_CLK; | ||||
|             } else { | ||||
|               SystemCoreClock = __SYS_OSC_CLK * ((LPC_SYSCON->SYSPLLCTRL & 0x01F) + 1); | ||||
|             } | ||||
|             break; | ||||
|           case 2:                       /* Reserved                           */ | ||||
|           case 3:                       /* Reserved                           */ | ||||
|             SystemCoreClock = 0; | ||||
|             break; | ||||
|       } | ||||
|       break; | ||||
|   } | ||||
|  | ||||
|   SystemCoreClock /= LPC_SYSCON->SYSAHBCLKDIV;   | ||||
|  | ||||
| } | ||||
|  | ||||
| /** | ||||
|  * Initialize the system | ||||
|  * | ||||
|  * @param  none | ||||
|  * @return none | ||||
|  * | ||||
|  * @brief  Setup the microcontroller system. | ||||
|  *         Initialize the System. | ||||
|  */ | ||||
| void SystemInit (void) { | ||||
|   volatile uint32_t i; | ||||
|  | ||||
| #if (CLOCK_SETUP)                                 /* Clock Setup              */ | ||||
|  | ||||
| #if ((SYSPLLCLKSEL_Val & 0x03) == 1) | ||||
|   LPC_SYSCON->PDRUNCFG     &= ~(1 << 5);          /* Power-up System Osc      */ | ||||
|   LPC_SYSCON->SYSOSCCTRL    = SYSOSCCTRL_Val; | ||||
|   for (i = 0; i < 200; i++) __NOP(); | ||||
| #endif | ||||
|  | ||||
|   LPC_SYSCON->SYSPLLCLKSEL  = SYSPLLCLKSEL_Val;   /* Select PLL Input         */ | ||||
|   LPC_SYSCON->SYSPLLCLKUEN  = 0x01;               /* Update Clock Source      */ | ||||
|   LPC_SYSCON->SYSPLLCLKUEN  = 0x00;               /* Toggle Update Register   */ | ||||
|   LPC_SYSCON->SYSPLLCLKUEN  = 0x01; | ||||
|   while (!(LPC_SYSCON->SYSPLLCLKUEN & 0x01));     /* Wait Until Updated       */ | ||||
| #if ((MAINCLKSEL_Val & 0x03) == 3)                /* Main Clock is PLL Out    */ | ||||
|   LPC_SYSCON->SYSPLLCTRL    = SYSPLLCTRL_Val; | ||||
|   LPC_SYSCON->PDRUNCFG     &= ~(1 << 7);          /* Power-up SYSPLL          */ | ||||
|   while (!(LPC_SYSCON->SYSPLLSTAT & 0x01));	      /* Wait Until PLL Locked    */ | ||||
| #endif | ||||
|  | ||||
| #if (((MAINCLKSEL_Val & 0x03) == 2) ) | ||||
|   LPC_SYSCON->WDTOSCCTRL    = WDTOSCCTRL_Val; | ||||
|   LPC_SYSCON->PDRUNCFG     &= ~(1 << 6);          /* Power-up WDT Clock       */ | ||||
|   for (i = 0; i < 200; i++) __NOP(); | ||||
| #endif | ||||
|  | ||||
|   LPC_SYSCON->MAINCLKSEL    = MAINCLKSEL_Val;     /* Select PLL Clock Output  */ | ||||
|   LPC_SYSCON->MAINCLKUEN    = 0x01;               /* Update MCLK Clock Source */ | ||||
|   LPC_SYSCON->MAINCLKUEN    = 0x00;               /* Toggle Update Register   */ | ||||
|   LPC_SYSCON->MAINCLKUEN    = 0x01; | ||||
|   while (!(LPC_SYSCON->MAINCLKUEN & 0x01));       /* Wait Until Updated       */ | ||||
|  | ||||
|   LPC_SYSCON->SYSAHBCLKDIV  = SYSAHBCLKDIV_Val; | ||||
|  | ||||
| #if ((USBCLKDIV_Val & 0x1FF) != 0)                /* USB clock is used        */ | ||||
|   LPC_SYSCON->PDRUNCFG     &= ~(1 << 10);         /* Power-up USB PHY         */ | ||||
|  | ||||
| #if ((USBCLKSEL_Val & 0x003) == 0)                /* USB clock is USB PLL out */ | ||||
|   LPC_SYSCON->PDRUNCFG     &= ~(1 <<  8);         /* Power-up USB PLL         */ | ||||
|   LPC_SYSCON->USBPLLCLKSEL  = USBPLLCLKSEL_Val;   /* Select PLL Input         */ | ||||
|   LPC_SYSCON->USBPLLCLKUEN  = 0x01;               /* Update Clock Source      */ | ||||
|   LPC_SYSCON->USBPLLCLKUEN  = 0x00;               /* Toggle Update Register   */ | ||||
|   LPC_SYSCON->USBPLLCLKUEN  = 0x01; | ||||
|   while (!(LPC_SYSCON->USBPLLCLKUEN & 0x01));     /* Wait Until Updated       */ | ||||
|   LPC_SYSCON->USBPLLCTRL    = USBPLLCTRL_Val; | ||||
|   while (!(LPC_SYSCON->USBPLLSTAT   & 0x01));     /* Wait Until PLL Locked    */ | ||||
|   LPC_SYSCON->USBCLKSEL     = 0x00;               /* Select USB PLL           */ | ||||
| #endif | ||||
|  | ||||
|   LPC_SYSCON->USBCLKSEL     = USBCLKSEL_Val;      /* Select USB Clock         */ | ||||
|   LPC_SYSCON->USBCLKDIV     = USBCLKDIV_Val;      /* Set USB clock divider    */ | ||||
|  | ||||
| #else                                             /* USB clock is not used    */                         | ||||
|   LPC_SYSCON->PDRUNCFG     |=  (1 << 10);         /* Power-down USB PHY       */ | ||||
|   LPC_SYSCON->PDRUNCFG     |=  (1 <<  8);         /* Power-down USB PLL       */ | ||||
| #endif | ||||
|  | ||||
| #endif | ||||
|  | ||||
|   /* System clock to the IOCON needs to be enabled or | ||||
|   most of the I/O related peripherals won't work. */ | ||||
|   LPC_SYSCON->SYSAHBCLKCTRL |= (1<<16); | ||||
|  | ||||
| } | ||||
| /****************************************************************************** | ||||
|  * @file     system_LPC11Uxx.c | ||||
|  * @purpose  CMSIS Cortex-M3 Device Peripheral Access Layer Source File | ||||
|  *           for the NXP LPC13xx Device Series | ||||
|  * @version  V1.10 | ||||
|  * @date     24. November 2010 | ||||
|  * | ||||
|  * @note | ||||
|  * Copyright (C) 2009-2010 ARM Limited. All rights reserved. | ||||
|  * | ||||
|  * @par | ||||
|  * ARM Limited (ARM) is supplying this software for use with Cortex-M | ||||
|  * processor based microcontrollers.  This file can be freely distributed | ||||
|  * within development tools that are supporting such ARM based processors. | ||||
|  * | ||||
|  * @par | ||||
|  * THIS SOFTWARE IS PROVIDED "AS IS".  NO WARRANTIES, WHETHER EXPRESS, IMPLIED | ||||
|  * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF | ||||
|  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. | ||||
|  * ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR | ||||
|  * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. | ||||
|  * | ||||
|  ******************************************************************************/ | ||||
|  | ||||
|  | ||||
| #include <stdint.h> | ||||
| #include "LPC11Uxx.h" | ||||
|  | ||||
| /* | ||||
| //-------- <<< Use Configuration Wizard in Context Menu >>> ------------------ | ||||
| */ | ||||
|  | ||||
| /*--------------------- Clock Configuration ---------------------------------- | ||||
| // | ||||
| // <e> Clock Configuration | ||||
| //   <h> System Oscillator Control Register (SYSOSCCTRL) | ||||
| //     <o1.0>      BYPASS: System Oscillator Bypass Enable | ||||
| //                     <i> If enabled then PLL input (sys_osc_clk) is fed | ||||
| //                     <i> directly from XTALIN and XTALOUT pins. | ||||
| //     <o1.9>      FREQRANGE: System Oscillator Frequency Range | ||||
| //                     <i> Determines frequency range for Low-power oscillator. | ||||
| //                   <0=> 1 - 20 MHz | ||||
| //                   <1=> 15 - 25 MHz | ||||
| //   </h> | ||||
| // | ||||
| //   <h> Watchdog Oscillator Control Register (WDTOSCCTRL) | ||||
| //     <o2.0..4>   DIVSEL: Select Divider for Fclkana | ||||
| //                     <i> wdt_osc_clk = Fclkana/ (2 <20> (1 + DIVSEL)) | ||||
| //                   <0-31> | ||||
| //     <o2.5..8>   FREQSEL: Select Watchdog Oscillator Analog Output Frequency (Fclkana) | ||||
| //                   <0=> Undefined | ||||
| //                   <1=> 0.5 MHz | ||||
| //                   <2=> 0.8 MHz | ||||
| //                   <3=> 1.1 MHz | ||||
| //                   <4=> 1.4 MHz | ||||
| //                   <5=> 1.6 MHz | ||||
| //                   <6=> 1.8 MHz | ||||
| //                   <7=> 2.0 MHz | ||||
| //                   <8=> 2.2 MHz | ||||
| //                   <9=> 2.4 MHz | ||||
| //                   <10=> 2.6 MHz | ||||
| //                   <11=> 2.7 MHz | ||||
| //                   <12=> 2.9 MHz | ||||
| //                   <13=> 3.1 MHz | ||||
| //                   <14=> 3.2 MHz | ||||
| //                   <15=> 3.4 MHz | ||||
| //   </h> | ||||
| // | ||||
| //   <h> System PLL Control Register (SYSPLLCTRL) | ||||
| //                   <i> F_clkout = M * F_clkin = F_CCO / (2 * P) | ||||
| //                   <i> F_clkin must be in the range of  10 MHz to  25 MHz | ||||
| //                   <i> F_CCO   must be in the range of 156 MHz to 320 MHz | ||||
| //     <o3.0..4>   MSEL: Feedback Divider Selection | ||||
| //                     <i> M = MSEL + 1 | ||||
| //                   <0-31> | ||||
| //     <o3.5..6>   PSEL: Post Divider Selection | ||||
| //                   <0=> P = 1 | ||||
| //                   <1=> P = 2 | ||||
| //                   <2=> P = 4 | ||||
| //                   <3=> P = 8 | ||||
| //   </h> | ||||
| // | ||||
| //   <h> System PLL Clock Source Select Register (SYSPLLCLKSEL) | ||||
| //     <o4.0..1>   SEL: System PLL Clock Source | ||||
| //                   <0=> IRC Oscillator | ||||
| //                   <1=> System Oscillator | ||||
| //                   <2=> Reserved | ||||
| //                   <3=> Reserved | ||||
| //   </h> | ||||
| // | ||||
| //   <h> Main Clock Source Select Register (MAINCLKSEL) | ||||
| //     <o5.0..1>   SEL: Clock Source for Main Clock | ||||
| //                   <0=> IRC Oscillator | ||||
| //                   <1=> Input Clock to System PLL | ||||
| //                   <2=> WDT Oscillator | ||||
| //                   <3=> System PLL Clock Out | ||||
| //   </h> | ||||
| // | ||||
| //   <h> System AHB Clock Divider Register (SYSAHBCLKDIV) | ||||
| //     <o6.0..7>   DIV: System AHB Clock Divider | ||||
| //                     <i> Divides main clock to provide system clock to core, memories, and peripherals. | ||||
| //                     <i> 0 = is disabled | ||||
| //                   <0-255> | ||||
| //   </h> | ||||
| // | ||||
| //   <h> USB PLL Control Register (USBPLLCTRL) | ||||
| //                   <i> F_clkout = M * F_clkin = F_CCO / (2 * P) | ||||
| //                   <i> F_clkin must be in the range of  10 MHz to  25 MHz | ||||
| //                   <i> F_CCO   must be in the range of 156 MHz to 320 MHz | ||||
| //     <o7.0..4>   MSEL: Feedback Divider Selection | ||||
| //                     <i> M = MSEL + 1 | ||||
| //                   <0-31> | ||||
| //     <o7.5..6>   PSEL: Post Divider Selection | ||||
| //                   <0=> P = 1 | ||||
| //                   <1=> P = 2 | ||||
| //                   <2=> P = 4 | ||||
| //                   <3=> P = 8 | ||||
| //   </h> | ||||
| // | ||||
| //   <h> USB PLL Clock Source Select Register (USBPLLCLKSEL) | ||||
| //     <o8.0..1>   SEL: USB PLL Clock Source | ||||
| //                     <i> USB PLL clock source must be switched to System Oscillator for correct USB operation | ||||
| //                   <0=> IRC Oscillator | ||||
| //                   <1=> System Oscillator | ||||
| //                   <2=> Reserved | ||||
| //                   <3=> Reserved | ||||
| //   </h> | ||||
| // | ||||
| //   <h> USB Clock Source Select Register (USBCLKSEL) | ||||
| //     <o9.0..1>   SEL: System PLL Clock Source | ||||
| //                   <0=> USB PLL out | ||||
| //                   <1=> Main clock | ||||
| //                   <2=> Reserved | ||||
| //                   <3=> Reserved | ||||
| //   </h> | ||||
| // | ||||
| //   <h> USB Clock Divider Register (USBCLKDIV) | ||||
| //     <o10.0..7>  DIV: USB Clock Divider | ||||
| //                     <i> Divides USB clock to 48 MHz. | ||||
| //                     <i> 0 = is disabled | ||||
| //                   <0-255> | ||||
| //   </h> | ||||
| // </e> | ||||
| */ | ||||
| #define CLOCK_SETUP           1 | ||||
| #define SYSOSCCTRL_Val        0x00000000              // Reset: 0x000 | ||||
| #define WDTOSCCTRL_Val        0x00000000              // Reset: 0x000 | ||||
| #define SYSPLLCTRL_Val        0x00000023              // Reset: 0x000 | ||||
| #define SYSPLLCLKSEL_Val      0x00000001              // Reset: 0x000 | ||||
| #define MAINCLKSEL_Val        0x00000003              // Reset: 0x000 | ||||
| #define SYSAHBCLKDIV_Val      0x00000001              // Reset: 0x001 | ||||
| #define USBPLLCTRL_Val        0x00000023              // Reset: 0x000 | ||||
| #define USBPLLCLKSEL_Val      0x00000001              // Reset: 0x000 | ||||
| #define USBCLKSEL_Val         0x00000000              // Reset: 0x000 | ||||
| #define USBCLKDIV_Val         0x00000001              // Reset: 0x001 | ||||
|  | ||||
| /* | ||||
| //-------- <<< end of configuration section >>> ------------------------------ | ||||
| */ | ||||
|  | ||||
| /*---------------------------------------------------------------------------- | ||||
|   Check the register settings | ||||
|  *----------------------------------------------------------------------------*/ | ||||
| #define CHECK_RANGE(val, min, max)                ((val < min) || (val > max)) | ||||
| #define CHECK_RSVD(val, mask)                     (val & mask) | ||||
|  | ||||
| /* Clock Configuration -------------------------------------------------------*/ | ||||
| #if (CHECK_RSVD((SYSOSCCTRL_Val),  ~0x00000003)) | ||||
|    #error "SYSOSCCTRL: Invalid values of reserved bits!" | ||||
| #endif | ||||
|  | ||||
| #if (CHECK_RSVD((WDTOSCCTRL_Val),  ~0x000001FF)) | ||||
|    #error "WDTOSCCTRL: Invalid values of reserved bits!" | ||||
| #endif | ||||
|  | ||||
| #if (CHECK_RANGE((SYSPLLCLKSEL_Val), 0, 2)) | ||||
|    #error "SYSPLLCLKSEL: Value out of range!" | ||||
| #endif | ||||
|  | ||||
| #if (CHECK_RSVD((SYSPLLCTRL_Val),  ~0x000001FF)) | ||||
|    #error "SYSPLLCTRL: Invalid values of reserved bits!" | ||||
| #endif | ||||
|  | ||||
| #if (CHECK_RSVD((MAINCLKSEL_Val),  ~0x00000003)) | ||||
|    #error "MAINCLKSEL: Invalid values of reserved bits!" | ||||
| #endif | ||||
|  | ||||
| #if (CHECK_RANGE((SYSAHBCLKDIV_Val), 0, 255)) | ||||
|    #error "SYSAHBCLKDIV: Value out of range!" | ||||
| #endif | ||||
|  | ||||
| #if (CHECK_RANGE((USBPLLCLKSEL_Val), 0, 1)) | ||||
|    #error "USBPLLCLKSEL: Value out of range!" | ||||
| #endif | ||||
|  | ||||
| #if (CHECK_RSVD((USBPLLCTRL_Val),  ~0x000001FF)) | ||||
|    #error "USBPLLCTRL: Invalid values of reserved bits!" | ||||
| #endif | ||||
|  | ||||
| #if (CHECK_RANGE((USBCLKSEL_Val), 0, 1)) | ||||
|    #error "USBCLKSEL: Value out of range!" | ||||
| #endif | ||||
|  | ||||
| #if (CHECK_RANGE((USBCLKDIV_Val), 0, 255)) | ||||
|    #error "USBCLKDIV: Value out of range!" | ||||
| #endif | ||||
|  | ||||
|  | ||||
| /*---------------------------------------------------------------------------- | ||||
|   DEFINES | ||||
|  *----------------------------------------------------------------------------*/ | ||||
|  | ||||
| /*---------------------------------------------------------------------------- | ||||
|   Define clocks | ||||
|  *----------------------------------------------------------------------------*/ | ||||
| #define __XTAL            (12000000UL)    /* Oscillator frequency             */ | ||||
| #define __SYS_OSC_CLK     (    __XTAL)    /* Main oscillator frequency        */ | ||||
| #define __IRC_OSC_CLK     (12000000UL)    /* Internal RC oscillator frequency */ | ||||
|  | ||||
|  | ||||
| #define __FREQSEL   ((WDTOSCCTRL_Val >> 5) & 0x0F) | ||||
| #define __DIVSEL   (((WDTOSCCTRL_Val & 0x1F) << 1) + 2) | ||||
|  | ||||
| #if (CLOCK_SETUP)                         /* Clock Setup              */ | ||||
|   #if  (__FREQSEL ==  0) | ||||
|     #define __WDT_OSC_CLK        ( 0)                  /* undefined */ | ||||
|   #elif (__FREQSEL ==  1) | ||||
|     #define __WDT_OSC_CLK        ( 500000 / __DIVSEL) | ||||
|   #elif (__FREQSEL ==  2) | ||||
|     #define __WDT_OSC_CLK        ( 800000 / __DIVSEL) | ||||
|   #elif (__FREQSEL ==  3) | ||||
|     #define __WDT_OSC_CLK        (1100000 / __DIVSEL) | ||||
|   #elif (__FREQSEL ==  4) | ||||
|     #define __WDT_OSC_CLK        (1400000 / __DIVSEL) | ||||
|   #elif (__FREQSEL ==  5) | ||||
|     #define __WDT_OSC_CLK        (1600000 / __DIVSEL) | ||||
|   #elif (__FREQSEL ==  6) | ||||
|     #define __WDT_OSC_CLK        (1800000 / __DIVSEL) | ||||
|   #elif (__FREQSEL ==  7) | ||||
|     #define __WDT_OSC_CLK        (2000000 / __DIVSEL) | ||||
|   #elif (__FREQSEL ==  8) | ||||
|     #define __WDT_OSC_CLK        (2200000 / __DIVSEL) | ||||
|   #elif (__FREQSEL ==  9) | ||||
|     #define __WDT_OSC_CLK        (2400000 / __DIVSEL) | ||||
|   #elif (__FREQSEL == 10) | ||||
|     #define __WDT_OSC_CLK        (2600000 / __DIVSEL) | ||||
|   #elif (__FREQSEL == 11) | ||||
|     #define __WDT_OSC_CLK        (2700000 / __DIVSEL) | ||||
|   #elif (__FREQSEL == 12) | ||||
|     #define __WDT_OSC_CLK        (2900000 / __DIVSEL) | ||||
|   #elif (__FREQSEL == 13) | ||||
|     #define __WDT_OSC_CLK        (3100000 / __DIVSEL) | ||||
|   #elif (__FREQSEL == 14) | ||||
|     #define __WDT_OSC_CLK        (3200000 / __DIVSEL) | ||||
|   #else | ||||
|     #define __WDT_OSC_CLK        (3400000 / __DIVSEL) | ||||
|   #endif | ||||
|  | ||||
|   /* sys_pllclkin calculation */ | ||||
|   #if   ((SYSPLLCLKSEL_Val & 0x03) == 0) | ||||
|     #define __SYS_PLLCLKIN           (__IRC_OSC_CLK) | ||||
|   #elif ((SYSPLLCLKSEL_Val & 0x03) == 1) | ||||
|     #define __SYS_PLLCLKIN           (__SYS_OSC_CLK) | ||||
|   #else | ||||
|     #define __SYS_PLLCLKIN           (0) | ||||
|   #endif | ||||
|  | ||||
|   #define  __SYS_PLLCLKOUT         (__SYS_PLLCLKIN * ((SYSPLLCTRL_Val & 0x01F) + 1)) | ||||
|  | ||||
|   /* main clock calculation */ | ||||
|   #if   ((MAINCLKSEL_Val & 0x03) == 0) | ||||
|     #define __MAIN_CLOCK             (__IRC_OSC_CLK) | ||||
|   #elif ((MAINCLKSEL_Val & 0x03) == 1) | ||||
|     #define __MAIN_CLOCK             (__SYS_PLLCLKIN) | ||||
|   #elif ((MAINCLKSEL_Val & 0x03) == 2) | ||||
|     #if (__FREQSEL ==  0) | ||||
|       #error "MAINCLKSEL: WDT Oscillator selected but FREQSEL is undefined!" | ||||
|     #else | ||||
|       #define __MAIN_CLOCK           (__WDT_OSC_CLK) | ||||
|     #endif | ||||
|   #elif ((MAINCLKSEL_Val & 0x03) == 3) | ||||
|     #define __MAIN_CLOCK             (__SYS_PLLCLKOUT) | ||||
|   #else | ||||
|     #define __MAIN_CLOCK             (0) | ||||
|   #endif | ||||
|  | ||||
|   #define __SYSTEM_CLOCK             (__MAIN_CLOCK / SYSAHBCLKDIV_Val) | ||||
|  | ||||
| #else | ||||
|   #define __SYSTEM_CLOCK             (__IRC_OSC_CLK) | ||||
| #endif  // CLOCK_SETUP | ||||
|  | ||||
|  | ||||
| /*---------------------------------------------------------------------------- | ||||
|   Clock Variable definitions | ||||
|  *----------------------------------------------------------------------------*/ | ||||
| uint32_t SystemCoreClock = __SYSTEM_CLOCK;/*!< System Clock Frequency (Core Clock)*/ | ||||
|  | ||||
|  | ||||
| /*---------------------------------------------------------------------------- | ||||
|   Clock functions | ||||
|  *----------------------------------------------------------------------------*/ | ||||
| void SystemCoreClockUpdate (void)            /* Get Core Clock Frequency      */ | ||||
| { | ||||
|   uint32_t wdt_osc = 0; | ||||
|  | ||||
|   /* Determine clock frequency according to clock register values             */ | ||||
|   switch ((LPC_SYSCON->WDTOSCCTRL >> 5) & 0x0F) { | ||||
|     case 0:  wdt_osc =       0; break; | ||||
|     case 1:  wdt_osc =  500000; break; | ||||
|     case 2:  wdt_osc =  800000; break; | ||||
|     case 3:  wdt_osc = 1100000; break; | ||||
|     case 4:  wdt_osc = 1400000; break; | ||||
|     case 5:  wdt_osc = 1600000; break; | ||||
|     case 6:  wdt_osc = 1800000; break; | ||||
|     case 7:  wdt_osc = 2000000; break; | ||||
|     case 8:  wdt_osc = 2200000; break; | ||||
|     case 9:  wdt_osc = 2400000; break; | ||||
|     case 10: wdt_osc = 2600000; break; | ||||
|     case 11: wdt_osc = 2700000; break; | ||||
|     case 12: wdt_osc = 2900000; break; | ||||
|     case 13: wdt_osc = 3100000; break; | ||||
|     case 14: wdt_osc = 3200000; break; | ||||
|     case 15: wdt_osc = 3400000; break; | ||||
|   } | ||||
|   wdt_osc /= ((LPC_SYSCON->WDTOSCCTRL & 0x1F) << 1) + 2; | ||||
|  | ||||
|   switch (LPC_SYSCON->MAINCLKSEL & 0x03) { | ||||
|     case 0:                             /* Internal RC oscillator             */ | ||||
|       SystemCoreClock = __IRC_OSC_CLK; | ||||
|       break; | ||||
|     case 1:                             /* Input Clock to System PLL          */ | ||||
|       switch (LPC_SYSCON->SYSPLLCLKSEL & 0x03) { | ||||
|           case 0:                       /* Internal RC oscillator             */ | ||||
|             SystemCoreClock = __IRC_OSC_CLK; | ||||
|             break; | ||||
|           case 1:                       /* System oscillator                  */ | ||||
|             SystemCoreClock = __SYS_OSC_CLK; | ||||
|             break; | ||||
|           case 2:                       /* Reserved                           */ | ||||
|           case 3:                       /* Reserved                           */ | ||||
|             SystemCoreClock = 0; | ||||
|             break; | ||||
|       } | ||||
|       break; | ||||
|     case 2:                             /* WDT Oscillator                     */ | ||||
|       SystemCoreClock = wdt_osc; | ||||
|       break; | ||||
|     case 3:                             /* System PLL Clock Out               */ | ||||
|       switch (LPC_SYSCON->SYSPLLCLKSEL & 0x03) { | ||||
|           case 0:                       /* Internal RC oscillator             */ | ||||
|             if (LPC_SYSCON->SYSPLLCTRL & 0x180) { | ||||
|               SystemCoreClock = __IRC_OSC_CLK; | ||||
|             } else { | ||||
|               SystemCoreClock = __IRC_OSC_CLK * ((LPC_SYSCON->SYSPLLCTRL & 0x01F) + 1); | ||||
|             } | ||||
|             break; | ||||
|           case 1:                       /* System oscillator                  */ | ||||
|             if (LPC_SYSCON->SYSPLLCTRL & 0x180) { | ||||
|               SystemCoreClock = __SYS_OSC_CLK; | ||||
|             } else { | ||||
|               SystemCoreClock = __SYS_OSC_CLK * ((LPC_SYSCON->SYSPLLCTRL & 0x01F) + 1); | ||||
|             } | ||||
|             break; | ||||
|           case 2:                       /* Reserved                           */ | ||||
|           case 3:                       /* Reserved                           */ | ||||
|             SystemCoreClock = 0; | ||||
|             break; | ||||
|       } | ||||
|       break; | ||||
|   } | ||||
|  | ||||
|   SystemCoreClock /= LPC_SYSCON->SYSAHBCLKDIV; | ||||
|  | ||||
| } | ||||
|  | ||||
| /** | ||||
|  * Initialize the system | ||||
|  * | ||||
|  * @param  none | ||||
|  * @return none | ||||
|  * | ||||
|  * @brief  Setup the microcontroller system. | ||||
|  *         Initialize the System. | ||||
|  */ | ||||
| void SystemInit (void) { | ||||
|   volatile uint32_t i; | ||||
|  | ||||
| #if (CLOCK_SETUP)                                 /* Clock Setup              */ | ||||
|  | ||||
| #if ((SYSPLLCLKSEL_Val & 0x03) == 1) | ||||
|   LPC_SYSCON->PDRUNCFG     &= ~(1 << 5);          /* Power-up System Osc      */ | ||||
|   LPC_SYSCON->SYSOSCCTRL    = SYSOSCCTRL_Val; | ||||
|   for (i = 0; i < 200; i++) __NOP(); | ||||
| #endif | ||||
|  | ||||
|   LPC_SYSCON->SYSPLLCLKSEL  = SYSPLLCLKSEL_Val;   /* Select PLL Input         */ | ||||
|   LPC_SYSCON->SYSPLLCLKUEN  = 0x01;               /* Update Clock Source      */ | ||||
|   LPC_SYSCON->SYSPLLCLKUEN  = 0x00;               /* Toggle Update Register   */ | ||||
|   LPC_SYSCON->SYSPLLCLKUEN  = 0x01; | ||||
|   while (!(LPC_SYSCON->SYSPLLCLKUEN & 0x01));     /* Wait Until Updated       */ | ||||
| #if ((MAINCLKSEL_Val & 0x03) == 3)                /* Main Clock is PLL Out    */ | ||||
|   LPC_SYSCON->SYSPLLCTRL    = SYSPLLCTRL_Val; | ||||
|   LPC_SYSCON->PDRUNCFG     &= ~(1 << 7);          /* Power-up SYSPLL          */ | ||||
|   while (!(LPC_SYSCON->SYSPLLSTAT & 0x01));	      /* Wait Until PLL Locked    */ | ||||
| #endif | ||||
|  | ||||
| #if (((MAINCLKSEL_Val & 0x03) == 2) ) | ||||
|   LPC_SYSCON->WDTOSCCTRL    = WDTOSCCTRL_Val; | ||||
|   LPC_SYSCON->PDRUNCFG     &= ~(1 << 6);          /* Power-up WDT Clock       */ | ||||
|   for (i = 0; i < 200; i++) __NOP(); | ||||
| #endif | ||||
|  | ||||
|   LPC_SYSCON->MAINCLKSEL    = MAINCLKSEL_Val;     /* Select PLL Clock Output  */ | ||||
|   LPC_SYSCON->MAINCLKUEN    = 0x01;               /* Update MCLK Clock Source */ | ||||
|   LPC_SYSCON->MAINCLKUEN    = 0x00;               /* Toggle Update Register   */ | ||||
|   LPC_SYSCON->MAINCLKUEN    = 0x01; | ||||
|   while (!(LPC_SYSCON->MAINCLKUEN & 0x01));       /* Wait Until Updated       */ | ||||
|  | ||||
|   LPC_SYSCON->SYSAHBCLKDIV  = SYSAHBCLKDIV_Val; | ||||
|  | ||||
| #if ((USBCLKDIV_Val & 0x1FF) != 0)                /* USB clock is used        */ | ||||
|   LPC_SYSCON->PDRUNCFG     &= ~(1 << 10);         /* Power-up USB PHY         */ | ||||
|  | ||||
| #if ((USBCLKSEL_Val & 0x003) == 0)                /* USB clock is USB PLL out */ | ||||
|   LPC_SYSCON->PDRUNCFG     &= ~(1 <<  8);         /* Power-up USB PLL         */ | ||||
|   LPC_SYSCON->USBPLLCLKSEL  = USBPLLCLKSEL_Val;   /* Select PLL Input         */ | ||||
|   LPC_SYSCON->USBPLLCLKUEN  = 0x01;               /* Update Clock Source      */ | ||||
|   LPC_SYSCON->USBPLLCLKUEN  = 0x00;               /* Toggle Update Register   */ | ||||
|   LPC_SYSCON->USBPLLCLKUEN  = 0x01; | ||||
|   while (!(LPC_SYSCON->USBPLLCLKUEN & 0x01));     /* Wait Until Updated       */ | ||||
|   LPC_SYSCON->USBPLLCTRL    = USBPLLCTRL_Val; | ||||
|   while (!(LPC_SYSCON->USBPLLSTAT   & 0x01));     /* Wait Until PLL Locked    */ | ||||
|   LPC_SYSCON->USBCLKSEL     = 0x00;               /* Select USB PLL           */ | ||||
| #endif | ||||
|  | ||||
|   LPC_SYSCON->USBCLKSEL     = USBCLKSEL_Val;      /* Select USB Clock         */ | ||||
|   LPC_SYSCON->USBCLKDIV     = USBCLKDIV_Val;      /* Set USB clock divider    */ | ||||
|  | ||||
| #else                                             /* USB clock is not used    */ | ||||
|   LPC_SYSCON->PDRUNCFG     |=  (1 << 10);         /* Power-down USB PHY       */ | ||||
|   LPC_SYSCON->PDRUNCFG     |=  (1 <<  8);         /* Power-down USB PLL       */ | ||||
| #endif | ||||
|  | ||||
| #endif | ||||
|  | ||||
|   /* System clock to the IOCON needs to be enabled or | ||||
|   most of the I/O related peripherals won't work. */ | ||||
|   LPC_SYSCON->SYSAHBCLKCTRL |= (1<<16); | ||||
|  | ||||
| } | ||||
|   | ||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @@ -1,64 +1,64 @@ | ||||
| /**************************************************************************** | ||||
|  *   $Id:: gpio.h 6172 2011-01-13 18:22:51Z usb00423                        $ | ||||
|  *   Project: NXP LPC11Uxx software example | ||||
|  * | ||||
|  *   Description: | ||||
|  *     This file contains definition and prototype for GPIO. | ||||
|  * | ||||
|  **************************************************************************** | ||||
|  * Software that is described herein is for illustrative purposes only | ||||
|  * which provides customers with programming information regarding the | ||||
|  * products. This software is supplied "AS IS" without any warranties. | ||||
|  * NXP Semiconductors assumes no responsibility or liability for the | ||||
|  * use of the software, conveys no license or title under any patent, | ||||
|  * copyright, or mask work right to the product. NXP Semiconductors | ||||
|  * reserves the right to make changes in the software without | ||||
|  * notification. NXP Semiconductors also make no representation or | ||||
|  * warranty that such application will be suitable for the specified | ||||
|  * use without further testing or modification. | ||||
| ****************************************************************************/ | ||||
| #ifndef __GPIO_H  | ||||
| #define __GPIO_H | ||||
|  | ||||
| #define CHANNEL0	0 | ||||
| #define CHANNEL1	1 | ||||
| #define CHANNEL2	2 | ||||
| #define CHANNEL3	3 | ||||
| #define CHANNEL4	4 | ||||
| #define CHANNEL5	5 | ||||
| #define CHANNEL6	6 | ||||
| #define CHANNEL7	7 | ||||
|  | ||||
| #define PORT0		0 | ||||
| #define PORT1		1 | ||||
|  | ||||
| #define GROUP0		0 | ||||
| #define GROUP1		1 | ||||
|  | ||||
| void FLEX_INT0_IRQHandler(void); | ||||
| void FLEX_INT1_IRQHandler(void); | ||||
| void FLEX_INT2_IRQHandler(void); | ||||
| void FLEX_INT3_IRQHandler(void); | ||||
| void FLEX_INT4_IRQHandler(void); | ||||
| void FLEX_INT5_IRQHandler(void); | ||||
| void FLEX_INT6_IRQHandler(void); | ||||
| void FLEX_INT7_IRQHandler(void); | ||||
| void GINT0_IRQHandler(void); | ||||
| void GINT1_IRQHandler(void); | ||||
| void GPIOInit( void ); | ||||
| void GPIOSetFlexInterrupt( uint32_t channelNum, uint32_t portNum, uint32_t bitPosi, | ||||
| 		uint32_t sense, uint32_t event ); | ||||
| void GPIOFlexIntEnable( uint32_t channelNum, uint32_t event ); | ||||
| void GPIOFlexIntDisable( uint32_t channelNum, uint32_t event ); | ||||
| uint32_t GPIOFlexIntStatus( uint32_t channelNum ); | ||||
| void GPIOFlexIntClear( uint32_t channelNum ); | ||||
| void GPIOSetGroupedInterrupt( uint32_t groupNum, uint32_t *bitPattern, uint32_t logic, | ||||
| 		uint32_t sense, uint32_t *eventPattern ); | ||||
| uint32_t GPIOGetPinValue( uint32_t portNum, uint32_t bitPosi ); | ||||
| void GPIOSetBitValue( uint32_t portNum, uint32_t bitPosi, uint32_t bitVal ); | ||||
| void GPIOSetDir( uint32_t portNum, uint32_t bitPosi, uint32_t dir ); | ||||
|  | ||||
| #endif /* end __GPIO_H */ | ||||
| /***************************************************************************** | ||||
| **                            End Of File | ||||
| ******************************************************************************/ | ||||
| /**************************************************************************** | ||||
|  *   $Id:: gpio.h 6172 2011-01-13 18:22:51Z usb00423                        $ | ||||
|  *   Project: NXP LPC11Uxx software example | ||||
|  * | ||||
|  *   Description: | ||||
|  *     This file contains definition and prototype for GPIO. | ||||
|  * | ||||
|  **************************************************************************** | ||||
|  * Software that is described herein is for illustrative purposes only | ||||
|  * which provides customers with programming information regarding the | ||||
|  * products. This software is supplied "AS IS" without any warranties. | ||||
|  * NXP Semiconductors assumes no responsibility or liability for the | ||||
|  * use of the software, conveys no license or title under any patent, | ||||
|  * copyright, or mask work right to the product. NXP Semiconductors | ||||
|  * reserves the right to make changes in the software without | ||||
|  * notification. NXP Semiconductors also make no representation or | ||||
|  * warranty that such application will be suitable for the specified | ||||
|  * use without further testing or modification. | ||||
| ****************************************************************************/ | ||||
| #ifndef __GPIO_H | ||||
| #define __GPIO_H | ||||
|  | ||||
| #define CHANNEL0	0 | ||||
| #define CHANNEL1	1 | ||||
| #define CHANNEL2	2 | ||||
| #define CHANNEL3	3 | ||||
| #define CHANNEL4	4 | ||||
| #define CHANNEL5	5 | ||||
| #define CHANNEL6	6 | ||||
| #define CHANNEL7	7 | ||||
|  | ||||
| #define PORT0		0 | ||||
| #define PORT1		1 | ||||
|  | ||||
| #define GROUP0		0 | ||||
| #define GROUP1		1 | ||||
|  | ||||
| void FLEX_INT0_IRQHandler(void); | ||||
| void FLEX_INT1_IRQHandler(void); | ||||
| void FLEX_INT2_IRQHandler(void); | ||||
| void FLEX_INT3_IRQHandler(void); | ||||
| void FLEX_INT4_IRQHandler(void); | ||||
| void FLEX_INT5_IRQHandler(void); | ||||
| void FLEX_INT6_IRQHandler(void); | ||||
| void FLEX_INT7_IRQHandler(void); | ||||
| void GINT0_IRQHandler(void); | ||||
| void GINT1_IRQHandler(void); | ||||
| void GPIOInit( void ); | ||||
| void GPIOSetFlexInterrupt( uint32_t channelNum, uint32_t portNum, uint32_t bitPosi, | ||||
| 		uint32_t sense, uint32_t event ); | ||||
| void GPIOFlexIntEnable( uint32_t channelNum, uint32_t event ); | ||||
| void GPIOFlexIntDisable( uint32_t channelNum, uint32_t event ); | ||||
| uint32_t GPIOFlexIntStatus( uint32_t channelNum ); | ||||
| void GPIOFlexIntClear( uint32_t channelNum ); | ||||
| void GPIOSetGroupedInterrupt( uint32_t groupNum, uint32_t *bitPattern, uint32_t logic, | ||||
| 		uint32_t sense, uint32_t *eventPattern ); | ||||
| uint32_t GPIOGetPinValue( uint32_t portNum, uint32_t bitPosi ); | ||||
| void GPIOSetBitValue( uint32_t portNum, uint32_t bitPosi, uint32_t bitVal ); | ||||
| void GPIOSetDir( uint32_t portNum, uint32_t bitPosi, uint32_t dir ); | ||||
|  | ||||
| #endif /* end __GPIO_H */ | ||||
| /***************************************************************************** | ||||
| **                            End Of File | ||||
| ******************************************************************************/ | ||||
|   | ||||
| @@ -1,238 +1,238 @@ | ||||
| /***************************************************************************** | ||||
|  *   uart.c:  UART API file for NXP LPC11xx Family Microprocessors | ||||
|  * | ||||
|  *   Copyright(C) 2008, NXP Semiconductor | ||||
|  *   All rights reserved. | ||||
|  * | ||||
|  *   History | ||||
|  *   2009.12.07  ver 1.00    Preliminary version, first Release | ||||
|  * | ||||
| ******************************************************************************/ | ||||
|  | ||||
| #include <stdint.h> | ||||
| #include "LPC11Uxx.h" | ||||
| #include "lpc11uxx_uart.h" | ||||
|  | ||||
| volatile uint32_t UARTStatus; | ||||
| volatile uint8_t  UARTTxEmpty = 1; | ||||
| volatile uint8_t  UARTBuffer[BUFSIZE]; | ||||
| volatile uint32_t UARTCount = 0; | ||||
|  | ||||
| /***************************************************************************** | ||||
| ** Function name:		UART_IRQHandler | ||||
| ** | ||||
| ** Descriptions:		UART interrupt handler | ||||
| ** | ||||
| ** parameters:			None | ||||
| ** Returned value:		None | ||||
| **  | ||||
| *****************************************************************************/ | ||||
| void UART_IRQHandler(void) | ||||
| { | ||||
|   uint8_t IIRValue, LSRValue; | ||||
|   uint8_t Dummy = Dummy; | ||||
|  | ||||
|   IIRValue = LPC_USART->IIR; | ||||
|      | ||||
|   IIRValue >>= 1;			/* skip pending bit in IIR */ | ||||
|   IIRValue &= 0x07;			/* check bit 1~3, interrupt identification */ | ||||
|   if (IIRValue == IIR_RLS)		/* Receive Line Status */ | ||||
|   { | ||||
|     LSRValue = LPC_USART->LSR; | ||||
|     /* Receive Line Status */ | ||||
|     if (LSRValue & (LSR_OE | LSR_PE | LSR_FE | LSR_RXFE | LSR_BI)) | ||||
|     { | ||||
|       /* There are errors or break interrupt */ | ||||
|       /* Read LSR will clear the interrupt */ | ||||
|       UARTStatus = LSRValue; | ||||
|       Dummy = LPC_USART->RBR;	/* Dummy read on RX to clear  | ||||
| 								interrupt, then bail out */ | ||||
|       return; | ||||
|     } | ||||
|     if (LSRValue & LSR_RDR)	/* Receive Data Ready */			 | ||||
|     { | ||||
|       /* If no error on RLS, normal ready, save into the data buffer. */ | ||||
|       /* Note: read RBR will clear the interrupt */ | ||||
|       UARTBuffer[UARTCount++] = LPC_USART->RBR; | ||||
|       if (UARTCount == BUFSIZE) | ||||
|       { | ||||
|         UARTCount = 0;		/* buffer overflow */ | ||||
|       }	 | ||||
|     } | ||||
|   } | ||||
|   else if (IIRValue == IIR_RDA)	/* Receive Data Available */ | ||||
|   { | ||||
|     /* Receive Data Available */ | ||||
|     UARTBuffer[UARTCount++] = LPC_USART->RBR; | ||||
|     if (UARTCount == BUFSIZE) | ||||
|     { | ||||
|       UARTCount = 0;		/* buffer overflow */ | ||||
|     } | ||||
|   } | ||||
|   else if (IIRValue == IIR_CTI)	/* Character timeout indicator */ | ||||
|   { | ||||
|     /* Character Time-out indicator */ | ||||
|     UARTStatus |= 0x100;		/* Bit 9 as the CTI error */ | ||||
|   } | ||||
|   else if (IIRValue == IIR_THRE)	/* THRE, transmit holding register empty */ | ||||
|   { | ||||
|     /* THRE interrupt */ | ||||
|     LSRValue = LPC_USART->LSR;		/* Check status in the LSR to see if | ||||
| 								valid data in U0THR or not */ | ||||
|     if (LSRValue & LSR_THRE) | ||||
|     { | ||||
|       UARTTxEmpty = 1; | ||||
|     } | ||||
|     else | ||||
|     { | ||||
|       UARTTxEmpty = 0; | ||||
|     } | ||||
|   } | ||||
|   return; | ||||
| } | ||||
|  | ||||
| #if MODEM_TEST | ||||
| /***************************************************************************** | ||||
| ** Function name:		ModemInit | ||||
| ** | ||||
| ** Descriptions:		Initialize UART0 port as modem, setup pin select. | ||||
| ** | ||||
| ** parameters:			None | ||||
| ** Returned value:		None | ||||
| **  | ||||
| *****************************************************************************/ | ||||
| void ModemInit( void ) | ||||
| { | ||||
|   LPC_IOCON->PIO2_0 &= ~0x07;    /* UART I/O config */ | ||||
|   LPC_IOCON->PIO2_0 |= 0x01;     /* UART DTR */ | ||||
|   LPC_IOCON->PIO0_7 &= ~0x07;    /* UART I/O config */ | ||||
|   LPC_IOCON->PIO0_7 |= 0x01;     /* UART CTS */ | ||||
|   LPC_IOCON->PIO1_5 &= ~0x07;    /* UART I/O config */ | ||||
|   LPC_IOCON->PIO1_5 |= 0x01;     /* UART RTS */ | ||||
| #if 1  | ||||
|   LPC_IOCON->DSR_LOC	= 0; | ||||
|   LPC_IOCON->PIO2_1 &= ~0x07;    /* UART I/O config */ | ||||
|   LPC_IOCON->PIO2_1 |= 0x01;     /* UART DSR */ | ||||
|  | ||||
|   LPC_IOCON->DCD_LOC	= 0; | ||||
|   LPC_IOCON->PIO2_2 &= ~0x07;    /* UART I/O config */ | ||||
|   LPC_IOCON->PIO2_2 |= 0x01;     /* UART DCD */ | ||||
|  | ||||
|   LPC_IOCON->RI_LOC	= 0; | ||||
|   LPC_IOCON->PIO2_3 &= ~0x07;    /* UART I/O config */ | ||||
|   LPC_IOCON->PIO2_3 |= 0x01;     /* UART RI */ | ||||
|  | ||||
| #else | ||||
|   LPC_IOCON->DSR_LOC = 1; | ||||
|   LPC_IOCON->PIO3_1 &= ~0x07;    /* UART I/O config */ | ||||
|   LPC_IOCON->PIO3_1 |= 0x01;     /* UART DSR */ | ||||
|  | ||||
|   LPC_IOCON->DCD_LOC = 1; | ||||
|   LPC_IOCON->PIO3_2 &= ~0x07;    /* UART I/O config */ | ||||
|   LPC_IOCON->PIO3_2 |= 0x01;     /* UART DCD */ | ||||
|  | ||||
|   LPC_IOCON->RI_LOC = 1; | ||||
|   LPC_IOCON->PIO3_3 &= ~0x07;    /* UART I/O config */ | ||||
|   LPC_IOCON->PIO3_3 |= 0x01;     /* UART RI */ | ||||
| #endif | ||||
|   LPC_USART->MCR = 0xC0;          /* Enable Auto RTS and Auto CTS. */			 | ||||
|   return; | ||||
| } | ||||
| #endif | ||||
|  | ||||
| /***************************************************************************** | ||||
| ** Function name:		UARTInit | ||||
| ** | ||||
| ** Descriptions:		Initialize UART0 port, setup pin select, | ||||
| **				clock, parity, stop bits, FIFO, etc. | ||||
| ** | ||||
| ** parameters:			UART baudrate | ||||
| ** Returned value:		None | ||||
| **  | ||||
| *****************************************************************************/ | ||||
| void UARTInit(uint32_t baudrate) | ||||
| { | ||||
|   uint32_t Fdiv; | ||||
|   uint32_t regVal; | ||||
|  | ||||
|   UARTTxEmpty = 1; | ||||
|   UARTCount = 0; | ||||
|    | ||||
|   NVIC_DisableIRQ(UART_IRQn); | ||||
|  | ||||
|   LPC_IOCON->PIO0_18 &= ~0x07;    /*  UART I/O config */ | ||||
|   LPC_IOCON->PIO0_18 |= 0x01;     /* UART RXD */ | ||||
|   LPC_IOCON->PIO0_19 &= ~0x07;	 | ||||
|   LPC_IOCON->PIO0_19 |= 0x01;     /* UART TXD */ | ||||
|   /* Enable UART clock */ | ||||
|   LPC_SYSCON->SYSAHBCLKCTRL |= (1<<12); | ||||
|   LPC_SYSCON->UARTCLKDIV = 0x1;     /* divided by 1 */ | ||||
|  | ||||
|   LPC_USART->LCR = 0x83;            /* 8 bits, no Parity, 1 Stop bit */ | ||||
|   regVal = LPC_SYSCON->UARTCLKDIV; | ||||
|  | ||||
|   Fdiv = (((SystemCoreClock*LPC_SYSCON->SYSAHBCLKDIV)/regVal)/16)/baudrate ;	/*baud rate */ | ||||
|  | ||||
|   LPC_USART->DLM = Fdiv / 256;							 | ||||
|   LPC_USART->DLL = Fdiv % 256; | ||||
|   LPC_USART->LCR = 0x03;		/* DLAB = 0 */ | ||||
|   LPC_USART->FCR = 0x07;		/* Enable and reset TX and RX FIFO. */ | ||||
|  | ||||
|   /* Read to clear the line status. */ | ||||
|   regVal = LPC_USART->LSR; | ||||
|  | ||||
|   /* Ensure a clean start, no data in either TX or RX FIFO. */ | ||||
| // CodeRed - added parentheses around comparison in operand of & | ||||
|   while (( LPC_USART->LSR & (LSR_THRE|LSR_TEMT)) != (LSR_THRE|LSR_TEMT) ); | ||||
|   while ( LPC_USART->LSR & LSR_RDR ) | ||||
|   { | ||||
| 	regVal = LPC_USART->RBR;	/* Dump data from RX FIFO */ | ||||
|   } | ||||
|   | ||||
|   /* Enable the UART Interrupt */ | ||||
|   NVIC_EnableIRQ(UART_IRQn); | ||||
|  | ||||
| #if CONFIG_UART_ENABLE_INTERRUPT==1 | ||||
| #if CONFIG_UART_ENABLE_TX_INTERRUPT==1 | ||||
|   LPC_USART->IER = IER_RBR | IER_THRE | IER_RLS;	/* Enable UART interrupt */ | ||||
| #else | ||||
|   LPC_USART->IER = IER_RBR | IER_RLS;	/* Enable UART interrupt */ | ||||
| #endif | ||||
| #endif | ||||
|   return; | ||||
| } | ||||
|  | ||||
| /***************************************************************************** | ||||
| ** Function name:		UARTSend | ||||
| ** | ||||
| ** Descriptions:		Send a block of data to the UART 0 port based | ||||
| **				on the data length | ||||
| ** | ||||
| ** parameters:		buffer pointer, and data length | ||||
| ** Returned value:	None | ||||
| **  | ||||
| *****************************************************************************/ | ||||
| void UARTSend(uint8_t *BufferPtr, uint32_t Length) | ||||
| { | ||||
|    | ||||
|   while ( Length != 0 ) | ||||
|   { | ||||
| 	  /* THRE status, contain valid data */ | ||||
| #if CONFIG_UART_ENABLE_TX_INTERRUPT==1 | ||||
| 	  /* Below flag is set inside the interrupt handler when THRE occurs. */ | ||||
|       while ( !(UARTTxEmpty & 0x01) ); | ||||
| 	  LPC_USART->THR = *BufferPtr; | ||||
|       UARTTxEmpty = 0;	/* not empty in the THR until it shifts out */ | ||||
| #else | ||||
| 	  while ( !(LPC_USART->LSR & LSR_THRE) ); | ||||
| 	  LPC_USART->THR = *BufferPtr; | ||||
| #endif | ||||
|       BufferPtr++; | ||||
|       Length--; | ||||
|   } | ||||
|   return; | ||||
| } | ||||
|  | ||||
| /****************************************************************************** | ||||
| **                            End Of File | ||||
| ******************************************************************************/ | ||||
| /***************************************************************************** | ||||
|  *   uart.c:  UART API file for NXP LPC11xx Family Microprocessors | ||||
|  * | ||||
|  *   Copyright(C) 2008, NXP Semiconductor | ||||
|  *   All rights reserved. | ||||
|  * | ||||
|  *   History | ||||
|  *   2009.12.07  ver 1.00    Preliminary version, first Release | ||||
|  * | ||||
| ******************************************************************************/ | ||||
|  | ||||
| #include <stdint.h> | ||||
| #include "LPC11Uxx.h" | ||||
| #include "lpc11uxx_uart.h" | ||||
|  | ||||
| volatile uint32_t UARTStatus; | ||||
| volatile uint8_t  UARTTxEmpty = 1; | ||||
| volatile uint8_t  UARTBuffer[BUFSIZE]; | ||||
| volatile uint32_t UARTCount = 0; | ||||
|  | ||||
| /***************************************************************************** | ||||
| ** Function name:		UART_IRQHandler | ||||
| ** | ||||
| ** Descriptions:		UART interrupt handler | ||||
| ** | ||||
| ** parameters:			None | ||||
| ** Returned value:		None | ||||
| ** | ||||
| *****************************************************************************/ | ||||
| void UART_IRQHandler(void) | ||||
| { | ||||
|   uint8_t IIRValue, LSRValue; | ||||
|   uint8_t Dummy = Dummy; | ||||
|  | ||||
|   IIRValue = LPC_USART->IIR; | ||||
|  | ||||
|   IIRValue >>= 1;			/* skip pending bit in IIR */ | ||||
|   IIRValue &= 0x07;			/* check bit 1~3, interrupt identification */ | ||||
|   if (IIRValue == IIR_RLS)		/* Receive Line Status */ | ||||
|   { | ||||
|     LSRValue = LPC_USART->LSR; | ||||
|     /* Receive Line Status */ | ||||
|     if (LSRValue & (LSR_OE | LSR_PE | LSR_FE | LSR_RXFE | LSR_BI)) | ||||
|     { | ||||
|       /* There are errors or break interrupt */ | ||||
|       /* Read LSR will clear the interrupt */ | ||||
|       UARTStatus = LSRValue; | ||||
|       Dummy = LPC_USART->RBR;	/* Dummy read on RX to clear | ||||
| 								interrupt, then bail out */ | ||||
|       return; | ||||
|     } | ||||
|     if (LSRValue & LSR_RDR)	/* Receive Data Ready */ | ||||
|     { | ||||
|       /* If no error on RLS, normal ready, save into the data buffer. */ | ||||
|       /* Note: read RBR will clear the interrupt */ | ||||
|       UARTBuffer[UARTCount++] = LPC_USART->RBR; | ||||
|       if (UARTCount == BUFSIZE) | ||||
|       { | ||||
|         UARTCount = 0;		/* buffer overflow */ | ||||
|       } | ||||
|     } | ||||
|   } | ||||
|   else if (IIRValue == IIR_RDA)	/* Receive Data Available */ | ||||
|   { | ||||
|     /* Receive Data Available */ | ||||
|     UARTBuffer[UARTCount++] = LPC_USART->RBR; | ||||
|     if (UARTCount == BUFSIZE) | ||||
|     { | ||||
|       UARTCount = 0;		/* buffer overflow */ | ||||
|     } | ||||
|   } | ||||
|   else if (IIRValue == IIR_CTI)	/* Character timeout indicator */ | ||||
|   { | ||||
|     /* Character Time-out indicator */ | ||||
|     UARTStatus |= 0x100;		/* Bit 9 as the CTI error */ | ||||
|   } | ||||
|   else if (IIRValue == IIR_THRE)	/* THRE, transmit holding register empty */ | ||||
|   { | ||||
|     /* THRE interrupt */ | ||||
|     LSRValue = LPC_USART->LSR;		/* Check status in the LSR to see if | ||||
| 								valid data in U0THR or not */ | ||||
|     if (LSRValue & LSR_THRE) | ||||
|     { | ||||
|       UARTTxEmpty = 1; | ||||
|     } | ||||
|     else | ||||
|     { | ||||
|       UARTTxEmpty = 0; | ||||
|     } | ||||
|   } | ||||
|   return; | ||||
| } | ||||
|  | ||||
| #if MODEM_TEST | ||||
| /***************************************************************************** | ||||
| ** Function name:		ModemInit | ||||
| ** | ||||
| ** Descriptions:		Initialize UART0 port as modem, setup pin select. | ||||
| ** | ||||
| ** parameters:			None | ||||
| ** Returned value:		None | ||||
| ** | ||||
| *****************************************************************************/ | ||||
| void ModemInit( void ) | ||||
| { | ||||
|   LPC_IOCON->PIO2_0 &= ~0x07;    /* UART I/O config */ | ||||
|   LPC_IOCON->PIO2_0 |= 0x01;     /* UART DTR */ | ||||
|   LPC_IOCON->PIO0_7 &= ~0x07;    /* UART I/O config */ | ||||
|   LPC_IOCON->PIO0_7 |= 0x01;     /* UART CTS */ | ||||
|   LPC_IOCON->PIO1_5 &= ~0x07;    /* UART I/O config */ | ||||
|   LPC_IOCON->PIO1_5 |= 0x01;     /* UART RTS */ | ||||
| #if 1 | ||||
|   LPC_IOCON->DSR_LOC	= 0; | ||||
|   LPC_IOCON->PIO2_1 &= ~0x07;    /* UART I/O config */ | ||||
|   LPC_IOCON->PIO2_1 |= 0x01;     /* UART DSR */ | ||||
|  | ||||
|   LPC_IOCON->DCD_LOC	= 0; | ||||
|   LPC_IOCON->PIO2_2 &= ~0x07;    /* UART I/O config */ | ||||
|   LPC_IOCON->PIO2_2 |= 0x01;     /* UART DCD */ | ||||
|  | ||||
|   LPC_IOCON->RI_LOC	= 0; | ||||
|   LPC_IOCON->PIO2_3 &= ~0x07;    /* UART I/O config */ | ||||
|   LPC_IOCON->PIO2_3 |= 0x01;     /* UART RI */ | ||||
|  | ||||
| #else | ||||
|   LPC_IOCON->DSR_LOC = 1; | ||||
|   LPC_IOCON->PIO3_1 &= ~0x07;    /* UART I/O config */ | ||||
|   LPC_IOCON->PIO3_1 |= 0x01;     /* UART DSR */ | ||||
|  | ||||
|   LPC_IOCON->DCD_LOC = 1; | ||||
|   LPC_IOCON->PIO3_2 &= ~0x07;    /* UART I/O config */ | ||||
|   LPC_IOCON->PIO3_2 |= 0x01;     /* UART DCD */ | ||||
|  | ||||
|   LPC_IOCON->RI_LOC = 1; | ||||
|   LPC_IOCON->PIO3_3 &= ~0x07;    /* UART I/O config */ | ||||
|   LPC_IOCON->PIO3_3 |= 0x01;     /* UART RI */ | ||||
| #endif | ||||
|   LPC_USART->MCR = 0xC0;          /* Enable Auto RTS and Auto CTS. */ | ||||
|   return; | ||||
| } | ||||
| #endif | ||||
|  | ||||
| /***************************************************************************** | ||||
| ** Function name:		UARTInit | ||||
| ** | ||||
| ** Descriptions:		Initialize UART0 port, setup pin select, | ||||
| **				clock, parity, stop bits, FIFO, etc. | ||||
| ** | ||||
| ** parameters:			UART baudrate | ||||
| ** Returned value:		None | ||||
| ** | ||||
| *****************************************************************************/ | ||||
| void UARTInit(uint32_t baudrate) | ||||
| { | ||||
|   uint32_t Fdiv; | ||||
|   uint32_t regVal; | ||||
|  | ||||
|   UARTTxEmpty = 1; | ||||
|   UARTCount = 0; | ||||
|  | ||||
|   NVIC_DisableIRQ(UART_IRQn); | ||||
|  | ||||
|   LPC_IOCON->PIO0_18 &= ~0x07;    /*  UART I/O config */ | ||||
|   LPC_IOCON->PIO0_18 |= 0x01;     /* UART RXD */ | ||||
|   LPC_IOCON->PIO0_19 &= ~0x07; | ||||
|   LPC_IOCON->PIO0_19 |= 0x01;     /* UART TXD */ | ||||
|   /* Enable UART clock */ | ||||
|   LPC_SYSCON->SYSAHBCLKCTRL |= (1<<12); | ||||
|   LPC_SYSCON->UARTCLKDIV = 0x1;     /* divided by 1 */ | ||||
|  | ||||
|   LPC_USART->LCR = 0x83;            /* 8 bits, no Parity, 1 Stop bit */ | ||||
|   regVal = LPC_SYSCON->UARTCLKDIV; | ||||
|  | ||||
|   Fdiv = (((SystemCoreClock*LPC_SYSCON->SYSAHBCLKDIV)/regVal)/16)/baudrate ;	/*baud rate */ | ||||
|  | ||||
|   LPC_USART->DLM = Fdiv / 256; | ||||
|   LPC_USART->DLL = Fdiv % 256; | ||||
|   LPC_USART->LCR = 0x03;		/* DLAB = 0 */ | ||||
|   LPC_USART->FCR = 0x07;		/* Enable and reset TX and RX FIFO. */ | ||||
|  | ||||
|   /* Read to clear the line status. */ | ||||
|   regVal = LPC_USART->LSR; | ||||
|  | ||||
|   /* Ensure a clean start, no data in either TX or RX FIFO. */ | ||||
| // CodeRed - added parentheses around comparison in operand of & | ||||
|   while (( LPC_USART->LSR & (LSR_THRE|LSR_TEMT)) != (LSR_THRE|LSR_TEMT) ); | ||||
|   while ( LPC_USART->LSR & LSR_RDR ) | ||||
|   { | ||||
| 	regVal = LPC_USART->RBR;	/* Dump data from RX FIFO */ | ||||
|   } | ||||
|  | ||||
|   /* Enable the UART Interrupt */ | ||||
|   NVIC_EnableIRQ(UART_IRQn); | ||||
|  | ||||
| #if CONFIG_UART_ENABLE_INTERRUPT==1 | ||||
| #if CONFIG_UART_ENABLE_TX_INTERRUPT==1 | ||||
|   LPC_USART->IER = IER_RBR | IER_THRE | IER_RLS;	/* Enable UART interrupt */ | ||||
| #else | ||||
|   LPC_USART->IER = IER_RBR | IER_RLS;	/* Enable UART interrupt */ | ||||
| #endif | ||||
| #endif | ||||
|   return; | ||||
| } | ||||
|  | ||||
| /***************************************************************************** | ||||
| ** Function name:		UARTSend | ||||
| ** | ||||
| ** Descriptions:		Send a block of data to the UART 0 port based | ||||
| **				on the data length | ||||
| ** | ||||
| ** parameters:		buffer pointer, and data length | ||||
| ** Returned value:	None | ||||
| ** | ||||
| *****************************************************************************/ | ||||
| void UARTSend(uint8_t *BufferPtr, uint32_t Length) | ||||
| { | ||||
|  | ||||
|   while ( Length != 0 ) | ||||
|   { | ||||
| 	  /* THRE status, contain valid data */ | ||||
| #if CONFIG_UART_ENABLE_TX_INTERRUPT==1 | ||||
| 	  /* Below flag is set inside the interrupt handler when THRE occurs. */ | ||||
|       while ( !(UARTTxEmpty & 0x01) ); | ||||
| 	  LPC_USART->THR = *BufferPtr; | ||||
|       UARTTxEmpty = 0;	/* not empty in the THR until it shifts out */ | ||||
| #else | ||||
| 	  while ( !(LPC_USART->LSR & LSR_THRE) ); | ||||
| 	  LPC_USART->THR = *BufferPtr; | ||||
| #endif | ||||
|       BufferPtr++; | ||||
|       Length--; | ||||
|   } | ||||
|   return; | ||||
| } | ||||
|  | ||||
| /****************************************************************************** | ||||
| **                            End Of File | ||||
| ******************************************************************************/ | ||||
|   | ||||
| @@ -1,55 +1,55 @@ | ||||
| /***************************************************************************** | ||||
|  *   uart.h:  Header file for NXP LPC1xxx Family Microprocessors | ||||
|  * | ||||
|  *   Copyright(C) 2008, NXP Semiconductor | ||||
|  *   All rights reserved. | ||||
|  * | ||||
|  *   History | ||||
|  *   2009.12.07  ver 1.00    Preliminary version, first Release | ||||
|  * | ||||
| ******************************************************************************/ | ||||
| #ifndef __UART_H  | ||||
| #define __UART_H | ||||
|  | ||||
| #define RS485_ENABLED		0 | ||||
| #define TX_INTERRUPT		0		/* 0 if TX uses polling, 1 interrupt driven. */ | ||||
| #define MODEM_TEST			0 | ||||
|  | ||||
| #define IER_RBR		0x01 | ||||
| #define IER_THRE	0x02 | ||||
| #define IER_RLS		0x04 | ||||
|  | ||||
| #define IIR_PEND	0x01 | ||||
| #define IIR_RLS		0x03 | ||||
| #define IIR_RDA		0x02 | ||||
| #define IIR_CTI		0x06 | ||||
| #define IIR_THRE	0x01 | ||||
|  | ||||
| #define LSR_RDR		0x01 | ||||
| #define LSR_OE		0x02 | ||||
| #define LSR_PE		0x04 | ||||
| #define LSR_FE		0x08 | ||||
| #define LSR_BI		0x10 | ||||
| #define LSR_THRE	0x20 | ||||
| #define LSR_TEMT	0x40 | ||||
| #define LSR_RXFE	0x80 | ||||
|  | ||||
| #define BUFSIZE		0x40 | ||||
|  | ||||
| /* RS485 mode definition. */ | ||||
| #define RS485_NMMEN		(0x1<<0) | ||||
| #define RS485_RXDIS		(0x1<<1) | ||||
| #define RS485_AADEN		(0x1<<2) | ||||
| #define RS485_SEL		(0x1<<3) | ||||
| #define RS485_DCTRL		(0x1<<4) | ||||
| #define RS485_OINV		(0x1<<5) | ||||
|  | ||||
| void ModemInit( void ); | ||||
| void UARTInit(uint32_t Baudrate); | ||||
| void UART_IRQHandler(void); | ||||
| void UARTSend(uint8_t *BufferPtr, uint32_t Length); | ||||
|  | ||||
| #endif /* end __UART_H */ | ||||
| /***************************************************************************** | ||||
| **                            End Of File | ||||
| ******************************************************************************/ | ||||
| /***************************************************************************** | ||||
|  *   uart.h:  Header file for NXP LPC1xxx Family Microprocessors | ||||
|  * | ||||
|  *   Copyright(C) 2008, NXP Semiconductor | ||||
|  *   All rights reserved. | ||||
|  * | ||||
|  *   History | ||||
|  *   2009.12.07  ver 1.00    Preliminary version, first Release | ||||
|  * | ||||
| ******************************************************************************/ | ||||
| #ifndef __UART_H | ||||
| #define __UART_H | ||||
|  | ||||
| #define RS485_ENABLED		0 | ||||
| #define TX_INTERRUPT		0		/* 0 if TX uses polling, 1 interrupt driven. */ | ||||
| #define MODEM_TEST			0 | ||||
|  | ||||
| #define IER_RBR		0x01 | ||||
| #define IER_THRE	0x02 | ||||
| #define IER_RLS		0x04 | ||||
|  | ||||
| #define IIR_PEND	0x01 | ||||
| #define IIR_RLS		0x03 | ||||
| #define IIR_RDA		0x02 | ||||
| #define IIR_CTI		0x06 | ||||
| #define IIR_THRE	0x01 | ||||
|  | ||||
| #define LSR_RDR		0x01 | ||||
| #define LSR_OE		0x02 | ||||
| #define LSR_PE		0x04 | ||||
| #define LSR_FE		0x08 | ||||
| #define LSR_BI		0x10 | ||||
| #define LSR_THRE	0x20 | ||||
| #define LSR_TEMT	0x40 | ||||
| #define LSR_RXFE	0x80 | ||||
|  | ||||
| #define BUFSIZE		0x40 | ||||
|  | ||||
| /* RS485 mode definition. */ | ||||
| #define RS485_NMMEN		(0x1<<0) | ||||
| #define RS485_RXDIS		(0x1<<1) | ||||
| #define RS485_AADEN		(0x1<<2) | ||||
| #define RS485_SEL		(0x1<<3) | ||||
| #define RS485_DCTRL		(0x1<<4) | ||||
| #define RS485_OINV		(0x1<<5) | ||||
|  | ||||
| void ModemInit( void ); | ||||
| void UARTInit(uint32_t Baudrate); | ||||
| void UART_IRQHandler(void); | ||||
| void UARTSend(uint8_t *BufferPtr, uint32_t Length); | ||||
|  | ||||
| #endif /* end __UART_H */ | ||||
| /***************************************************************************** | ||||
| **                            End Of File | ||||
| ******************************************************************************/ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 hathach
					hathach