These are the examples provided for [[/users/frank26080115/libraries/LPC1700CMSIS_Lib/]] Note, the entire "program" is not compilable!

Committer:
frank26080115
Date:
Sun Mar 20 05:38:56 2011 +0000
Revision:
0:bf7b9fba3924

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
frank26080115 0:bf7b9fba3924 1 /***********************************************************************//**
frank26080115 0:bf7b9fba3924 2 * @file nvic_priority.c
frank26080115 0:bf7b9fba3924 3 * @purpose This example used to test NVIC Grouping Priority function
frank26080115 0:bf7b9fba3924 4 * @version 1.0
frank26080115 0:bf7b9fba3924 5 * @date 18. June. 2010
frank26080115 0:bf7b9fba3924 6 * @author NXP MCU SW Application Team
frank26080115 0:bf7b9fba3924 7 *---------------------------------------------------------------------
frank26080115 0:bf7b9fba3924 8 * Software that is described herein is for illustrative purposes only
frank26080115 0:bf7b9fba3924 9 * which provides customers with programming information regarding the
frank26080115 0:bf7b9fba3924 10 * products. This software is supplied "AS IS" without any warranties.
frank26080115 0:bf7b9fba3924 11 * NXP Semiconductors assumes no responsibility or liability for the
frank26080115 0:bf7b9fba3924 12 * use of the software, conveys no license or title under any patent,
frank26080115 0:bf7b9fba3924 13 * copyright, or mask work right to the product. NXP Semiconductors
frank26080115 0:bf7b9fba3924 14 * reserves the right to make changes in the software without
frank26080115 0:bf7b9fba3924 15 * notification. NXP Semiconductors also make no representation or
frank26080115 0:bf7b9fba3924 16 * warranty that such application will be suitable for the specified
frank26080115 0:bf7b9fba3924 17 * use without further testing or modification.
frank26080115 0:bf7b9fba3924 18 **********************************************************************/
frank26080115 0:bf7b9fba3924 19 #include "lpc17xx_libcfg.h"
frank26080115 0:bf7b9fba3924 20 #include "lpc17xx_gpio.h"
frank26080115 0:bf7b9fba3924 21 #include "lpc17xx_nvic.h"
frank26080115 0:bf7b9fba3924 22 #include "lpc17xx_systick.h"
frank26080115 0:bf7b9fba3924 23 #include "lpc17xx_exti.h"
frank26080115 0:bf7b9fba3924 24 #include "lpc17xx_pinsel.h"
frank26080115 0:bf7b9fba3924 25
frank26080115 0:bf7b9fba3924 26 /* Example group ----------------------------------------------------------- */
frank26080115 0:bf7b9fba3924 27 /** @defgroup NVIC_Priority Priority
frank26080115 0:bf7b9fba3924 28 * @ingroup NVIC_Examples
frank26080115 0:bf7b9fba3924 29 * @{
frank26080115 0:bf7b9fba3924 30 */
frank26080115 0:bf7b9fba3924 31
frank26080115 0:bf7b9fba3924 32 /************************** PRIVATE DEFINTIONS*************************/
frank26080115 0:bf7b9fba3924 33 /* Interrupt mode
frank26080115 0:bf7b9fba3924 34 * - 0: Tail-chaining interrupt
frank26080115 0:bf7b9fba3924 35 * - 1: Late-arriving interrupt
frank26080115 0:bf7b9fba3924 36 */
frank26080115 0:bf7b9fba3924 37 #define INT_MODE 1
frank26080115 0:bf7b9fba3924 38
frank26080115 0:bf7b9fba3924 39 /************************** PRIVATE FUNCTIONS *************************/
frank26080115 0:bf7b9fba3924 40 void EINT0_IRQHandler(void);
frank26080115 0:bf7b9fba3924 41 void EINT3_IRQHandler(void);
frank26080115 0:bf7b9fba3924 42
frank26080115 0:bf7b9fba3924 43 void print_menu(void);
frank26080115 0:bf7b9fba3924 44 void delay (void);
frank26080115 0:bf7b9fba3924 45
frank26080115 0:bf7b9fba3924 46 /*----------------- INTERRUPT SERVICE ROUTINES --------------------------*/
frank26080115 0:bf7b9fba3924 47 /*********************************************************************//**
frank26080115 0:bf7b9fba3924 48 * @brief External interrupt 0 handler
frank26080115 0:bf7b9fba3924 49 * This interrupt occurs when pressing button INT0
frank26080115 0:bf7b9fba3924 50 * @param None
frank26080115 0:bf7b9fba3924 51 * @return None
frank26080115 0:bf7b9fba3924 52 ***********************************************************************/
frank26080115 0:bf7b9fba3924 53 void EINT0_IRQHandler(void)
frank26080115 0:bf7b9fba3924 54 {
frank26080115 0:bf7b9fba3924 55 uint8_t i;
frank26080115 0:bf7b9fba3924 56 EXTI_ClearEXTIFlag(0);
frank26080115 0:bf7b9fba3924 57 for (i= 0; i<10; i++)
frank26080115 0:bf7b9fba3924 58 {
frank26080115 0:bf7b9fba3924 59 GPIO_SetValue(1,(1<<29));
frank26080115 0:bf7b9fba3924 60 delay();
frank26080115 0:bf7b9fba3924 61 GPIO_ClearValue(1,(1<<29));
frank26080115 0:bf7b9fba3924 62 delay();
frank26080115 0:bf7b9fba3924 63 }
frank26080115 0:bf7b9fba3924 64 }
frank26080115 0:bf7b9fba3924 65
frank26080115 0:bf7b9fba3924 66 /*********************************************************************//**
frank26080115 0:bf7b9fba3924 67 * @brief External interrupt 3 handler
frank26080115 0:bf7b9fba3924 68 * This interrupt occurs when turn ADC potentiometer
frank26080115 0:bf7b9fba3924 69 * @param None
frank26080115 0:bf7b9fba3924 70 * @return None
frank26080115 0:bf7b9fba3924 71 ***********************************************************************/
frank26080115 0:bf7b9fba3924 72 void EINT3_IRQHandler(void)
frank26080115 0:bf7b9fba3924 73 {
frank26080115 0:bf7b9fba3924 74 uint8_t j;
frank26080115 0:bf7b9fba3924 75 if (GPIO_GetIntStatus(0, 25, 1))
frank26080115 0:bf7b9fba3924 76 {
frank26080115 0:bf7b9fba3924 77 GPIO_ClearInt(0,(1<<25));
frank26080115 0:bf7b9fba3924 78 for (j= 0; j<10; j++)
frank26080115 0:bf7b9fba3924 79 {
frank26080115 0:bf7b9fba3924 80 GPIO_SetValue(1,(1<<28));
frank26080115 0:bf7b9fba3924 81 delay();
frank26080115 0:bf7b9fba3924 82 GPIO_ClearValue(1,(1<<28));
frank26080115 0:bf7b9fba3924 83 delay();
frank26080115 0:bf7b9fba3924 84 }
frank26080115 0:bf7b9fba3924 85 }
frank26080115 0:bf7b9fba3924 86 }
frank26080115 0:bf7b9fba3924 87 /*-------------------------PRIVATE FUNCTIONS------------------------------*/
frank26080115 0:bf7b9fba3924 88 /*********************************************************************//**
frank26080115 0:bf7b9fba3924 89 * @brief delay function
frank26080115 0:bf7b9fba3924 90 * @param[in] none
frank26080115 0:bf7b9fba3924 91 * @return None
frank26080115 0:bf7b9fba3924 92 **********************************************************************/
frank26080115 0:bf7b9fba3924 93 void delay (void) {
frank26080115 0:bf7b9fba3924 94 unsigned int i;
frank26080115 0:bf7b9fba3924 95
frank26080115 0:bf7b9fba3924 96 for (i = 0; i < 0x400000; i++) {
frank26080115 0:bf7b9fba3924 97 }
frank26080115 0:bf7b9fba3924 98 }
frank26080115 0:bf7b9fba3924 99
frank26080115 0:bf7b9fba3924 100 /*-------------------------MAIN FUNCTION------------------------------*/
frank26080115 0:bf7b9fba3924 101 /*********************************************************************//**
frank26080115 0:bf7b9fba3924 102 * @brief c_entry: Main program body
frank26080115 0:bf7b9fba3924 103 * @param[in] None
frank26080115 0:bf7b9fba3924 104 * @return int
frank26080115 0:bf7b9fba3924 105 **********************************************************************/
frank26080115 0:bf7b9fba3924 106 int c_entry (void)
frank26080115 0:bf7b9fba3924 107 {
frank26080115 0:bf7b9fba3924 108 EXTI_InitTypeDef EXTICfg;
frank26080115 0:bf7b9fba3924 109 PINSEL_CFG_Type PinCfg;
frank26080115 0:bf7b9fba3924 110
frank26080115 0:bf7b9fba3924 111 /* Configure:
frank26080115 0:bf7b9fba3924 112 * + LED1: P1.28
frank26080115 0:bf7b9fba3924 113 * + LED2: P1.29
frank26080115 0:bf7b9fba3924 114 */
frank26080115 0:bf7b9fba3924 115 GPIO_SetDir(1, (1<<28)|(1<<29), 1);
frank26080115 0:bf7b9fba3924 116
frank26080115 0:bf7b9fba3924 117 /* Setting P2.10 as EINT0 */
frank26080115 0:bf7b9fba3924 118 PinCfg.Funcnum = 1;
frank26080115 0:bf7b9fba3924 119 PinCfg.OpenDrain = 0;
frank26080115 0:bf7b9fba3924 120 PinCfg.Pinmode = 0;
frank26080115 0:bf7b9fba3924 121 PinCfg.Pinnum = 10;
frank26080115 0:bf7b9fba3924 122 PinCfg.Portnum = 2;
frank26080115 0:bf7b9fba3924 123 PINSEL_ConfigPin(&PinCfg);
frank26080115 0:bf7b9fba3924 124
frank26080115 0:bf7b9fba3924 125 /* Initialize External 0 interrupt */
frank26080115 0:bf7b9fba3924 126 EXTI_Init();
frank26080115 0:bf7b9fba3924 127 EXTICfg.EXTI_Line = EXTI_EINT0;
frank26080115 0:bf7b9fba3924 128 /* edge sensitive */
frank26080115 0:bf7b9fba3924 129 EXTICfg.EXTI_Mode = EXTI_MODE_EDGE_SENSITIVE;
frank26080115 0:bf7b9fba3924 130 EXTICfg.EXTI_polarity = EXTI_POLARITY_LOW_ACTIVE_OR_FALLING_EDGE;
frank26080115 0:bf7b9fba3924 131 EXTI_Config(&EXTICfg);
frank26080115 0:bf7b9fba3924 132
frank26080115 0:bf7b9fba3924 133
frank26080115 0:bf7b9fba3924 134 #if (INT_MODE == 0) //same group, different sub-levels (Tail-chaining example)
frank26080115 0:bf7b9fba3924 135 NVIC_SetPriorityGrouping(4); //sets group priorities: 8 - subpriorities: 3
frank26080115 0:bf7b9fba3924 136 NVIC_SetPriority(EINT0_IRQn, 2); //000:10 (bit 7:3) assign eint0 to group 0, sub-priority 2 within group 0
frank26080115 0:bf7b9fba3924 137 NVIC_SetPriority(EINT3_IRQn, 1); //000:01 (bit 7:3) assign gpioint to group 0, sub-priority 1 within group 0
frank26080115 0:bf7b9fba3924 138 #else //different group - (Late-arriving example)
frank26080115 0:bf7b9fba3924 139 NVIC_SetPriorityGrouping(4); //sets group priorities: 8 - subpriorities: 3
frank26080115 0:bf7b9fba3924 140 NVIC_SetPriority(EINT0_IRQn, 0); //000:00 (bit 7:3) assign eint0 to group 0, sub-priority 0 within group 0
frank26080115 0:bf7b9fba3924 141 NVIC_SetPriority(EINT3_IRQn, 4); //001:00 (bit 7:3) assign GPIO int to group 1, sub-priority 0 within group 1
frank26080115 0:bf7b9fba3924 142 #endif
frank26080115 0:bf7b9fba3924 143
frank26080115 0:bf7b9fba3924 144 NVIC_EnableIRQ(EINT0_IRQn);
frank26080115 0:bf7b9fba3924 145 NVIC_EnableIRQ(EINT3_IRQn);
frank26080115 0:bf7b9fba3924 146
frank26080115 0:bf7b9fba3924 147 //Enable GPIO interrupt P0.25/AD0.2
frank26080115 0:bf7b9fba3924 148 GPIO_IntCmd(0,(1<<25),1);
frank26080115 0:bf7b9fba3924 149
frank26080115 0:bf7b9fba3924 150 while(1);
frank26080115 0:bf7b9fba3924 151 return 1;
frank26080115 0:bf7b9fba3924 152 }
frank26080115 0:bf7b9fba3924 153
frank26080115 0:bf7b9fba3924 154 /* With ARM and GHS toolsets, the entry point is main() - this will
frank26080115 0:bf7b9fba3924 155 allow the linker to generate wrapper code to setup stacks, allocate
frank26080115 0:bf7b9fba3924 156 heap area, and initialize and copy code and data segments. For GNU
frank26080115 0:bf7b9fba3924 157 toolsets, the entry point is through __start() in the crt0_gnu.asm
frank26080115 0:bf7b9fba3924 158 file, and that startup code will setup stacks and data */
frank26080115 0:bf7b9fba3924 159 int main(void) {
frank26080115 0:bf7b9fba3924 160 return c_entry();
frank26080115 0:bf7b9fba3924 161 }
frank26080115 0:bf7b9fba3924 162
frank26080115 0:bf7b9fba3924 163 #ifdef DEBUG
frank26080115 0:bf7b9fba3924 164 /*******************************************************************************
frank26080115 0:bf7b9fba3924 165 * @brief Reports the name of the source file and the source line number
frank26080115 0:bf7b9fba3924 166 * where the CHECK_PARAM error has occurred.
frank26080115 0:bf7b9fba3924 167 * @param[in] file Pointer to the source file name
frank26080115 0:bf7b9fba3924 168 * @param[in] line assert_param error line source number
frank26080115 0:bf7b9fba3924 169 * @return None
frank26080115 0:bf7b9fba3924 170 *******************************************************************************/
frank26080115 0:bf7b9fba3924 171 void check_failed(uint8_t *file, uint32_t line) {
frank26080115 0:bf7b9fba3924 172 /* User can add his own implementation to report the file name and line number,
frank26080115 0:bf7b9fba3924 173 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
frank26080115 0:bf7b9fba3924 174
frank26080115 0:bf7b9fba3924 175 /* Infinite loop */
frank26080115 0:bf7b9fba3924 176 while (1)
frank26080115 0:bf7b9fba3924 177 ;
frank26080115 0:bf7b9fba3924 178 }
frank26080115 0:bf7b9fba3924 179 #endif
frank26080115 0:bf7b9fba3924 180
frank26080115 0:bf7b9fba3924 181 /*
frank26080115 0:bf7b9fba3924 182 * @}
frank26080115 0:bf7b9fba3924 183 */