求教,最近在学UCOSIII,MCU是NXP LPC1768,现在出现的问题是配置了定时中断,无法进中断
。有何解法,我有个没使用UCOSIII的可以进中断的代码,他们的定时配置是一样的,。
[mw_shl_code=c,true]static void Timer_Config(void)
{
PINSEL_CFG_Type PinCfg;
// Conifg P1.28 as MAT0.0
PinCfg.Funcnum=3;
PinCfg.OpenDrain=0;
PinCfg.Pinmode=0;
PinCfg.Pinnum=28;
PinCfg.Portnum=1;
PINSEL_ConfigPin(&
inCfg);
TIM_TIMERCFG_Type TIM_ConfigStruct;
TIM_MATCHCFG_Type TIM_MatchConfigStruct;
TIM_ConfigStruct.PrescaleOption=TIM_PRESCALE_USVAL;//微秒预分频值
TIM_ConfigStruct.PrescaleValue=100;//100us
// use channel 0, MR0
TIM_MatchConfigStruct.MatchChannel=0;//MR0
// Enable interrupt when MR0 matches the value in TC register
TIM_MatchConfigStruct.IntOnMatch=ENABLE;
//Enable reset on MR0: TIMER will reset if MR0 matches it
TIM_MatchConfigStruct.ResetOnMatch=ENABLE;//
//Stop on MR0 if MR0 matches it
TIM_MatchConfigStruct.StopOnMatch=DISABLE;
//Toggle MR0.0 pin if MR0 matches it
TIM_MatchConfigStruct.ExtMatchOutputType=TIM_EXTMATCH_TOGGLE;//状态翻转
// Set Match value, count value of 10000 (10000 * 100uS = 1000000us = 1s --> 1 Hz)
TIM_MatchConfigStruct.MatchValue=10000;//10*100us=1ms
// Set configuration for Tim_config and Tim_MatchConfig
TIM_Init(LPC_TIM0,TIM_TIMER_MODE,&TIM_ConfigStruct);
TIM_ConfigMatch(LPC_TIM0,&TIM_MatchConfigStruct);
/* preemption = 1, sub-priority = 1 */
NVIC_SetPriority(TIMER0_IRQn, ((0x01<<3)|0x01));
/* Enable interrupt for timer 0 */
NVIC_EnableIRQ(TIMER0_IRQn);
// To start timer 0
TIM_Cmd(LPC_TIM0,ENABLE);
}[/mw_shl_code]
[mw_shl_code=c,true]void TIMER0_IRQHandler(void)
{
OSIntEnter();
if (TIM_GetIntStatus(LPC_TIM0, TIM_MR0_INT)== SET)
{
_DBG_("Match interrupt occur...");
}
TIM_ClearIntPending(LPC_TIM0, TIM_MR0_INT);
OSIntExit();
}[/mw_shl_code]
[mw_shl_code=asm,true];/**************************************************************************//**
; * @file startup_LPC17xx.s
; * @brief CMSIS Cortex-M3 Core Device Startup File for
; * NXP LPC17xx Device Series
; * @version V1.10
; * @date 06. April 2011
; *
; * @note
; * Copyright (C) 2009-2011 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.
; *
; ******************************************************************************/
; *------- <<< Use Configuration Wizard in Context Menu >>> ------------------
; <h> Stack Configuration
; <o> Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>
Stack_Size EQU 0x00000200
AREA STACK, NOINIT, READWRITE, ALIGN=3
Stack_Mem SPACE Stack_Size
__initial_sp
; <h> Heap Configuration
; <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>
Heap_Size EQU 0x00000000
AREA HEAP, NOINIT, READWRITE, ALIGN=3
__heap_base
Heap_Mem SPACE Heap_Size
__heap_limit
PRESERVE8
THUMB
; Vector Table Mapped to Address 0 at Reset
AREA RESET, DATA, READONLY
EXPORT __Vectors
__Vectors DCD __initial_sp ; Top of Stack
DCD Reset_Handler ; Reset Handler
DCD NMI_Handler ; NMI Handler
DCD HardFault_Handler ; Hard Fault Handler
DCD MemManage_Handler ; MPU Fault Handler
DCD BusFault_Handler ; Bus Fault Handler
DCD UsageFault_Handler ; Usage Fault Handler
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD SVC_Handler ; SVCall Handler
DCD DebugMon_Handler ; Debug Monitor Handler
DCD 0 ; Reserved
DCD OS_CPU_PendSVHandler ; PendSV Handler
DCD OS_CPU_SysTickHandler ; SysTick Handler
; External Interrupts
DCD WDT_IRQHandler ; 16: Watchdog Timer
DCD TIMER0_IRQHandler ; 17: Timer0
DCD TIMER1_IRQHandler ; 18: Timer1
DCD TIMER2_IRQHandler ; 19: Timer2
DCD TIMER3_IRQHandler ; 20: Timer3
DCD UART0_IRQHandler ; 21: UART0
DCD UART1_IRQHandler ; 22: UART1
DCD UART2_IRQHandler ; 23: UART2
DCD UART3_IRQHandler ; 24: UART3
DCD PWM1_IRQHandler ; 25: PWM1
DCD I2C0_IRQHandler ; 26: I2C0
DCD I2C1_IRQHandler ; 27: I2C1
DCD I2C2_IRQHandler ; 28: I2C2
DCD SPI_IRQHandler ; 29: SPI
DCD SSP0_IRQHandler ; 30: SSP0
DCD SSP1_IRQHandler ; 31: SSP1
DCD PLL0_IRQHandler ; 32: PLL0 Lock (Main PLL)
DCD RTC_IRQHandler ; 33: Real Time Clock
DCD EINT0_IRQHandler ; 34: External Interrupt 0
DCD EINT1_IRQHandler ; 35: External Interrupt 1
DCD EINT2_IRQHandler ; 36: External Interrupt 2
DCD EINT3_IRQHandler ; 37: External Interrupt 3
DCD ADC_IRQHandler ; 38: A/D Converter
DCD BOD_IRQHandler ; 39: Brown-Out Detect
DCD USB_IRQHandler ; 40: USB
DCD CAN_IRQHandler ; 41: CAN
DCD DMA_IRQHandler ; 42: General Purpose DMA
DCD I2S_IRQHandler ; 43: I2S
DCD ENET_IRQHandler ; 44: Ethernet
DCD RIT_IRQHandler ; 45: Repetitive Interrupt Timer
DCD MCPWM_IRQHandler ; 46: Motor Control PWM
DCD QEI_IRQHandler ; 47: Quadrature Encoder Interface
DCD PLL1_IRQHandler ; 48: PLL1 Lock (USB PLL)
DCD USBActivity_IRQHandler ; 49: USB Activity interrupt to wakeup
DCD CANActivity_IRQHandler ; 50: CAN Activity interrupt to wakeup
IF
NOT:
EF:NO_CRP
AREA |.ARM.__at_0x02FC|, CODE, READONLY
CRP_Key DCD 0xFFFFFFFF
ENDIF
AREA |.text|, CODE, READONLY
; Reset Handler
Reset_Handler PROC
EXPORT Reset_Handler [WEAK]
IMPORT SystemInit
IMPORT __main
LDR R0, =SystemInit
BLX R0
LDR R0, =__main
BX R0
ENDP
; Dummy Exception Handlers (infinite loops which can be modified)
NMI_Handler PROC
EXPORT NMI_Handler [WEAK]
B .
ENDP
HardFault_Handler
PROC
EXPORT HardFault_Handler [WEAK]
B .
ENDP
MemManage_Handler
PROC
EXPORT MemManage_Handler [WEAK]
B .
ENDP
BusFault_Handler
PROC
EXPORT BusFault_Handler [WEAK]
B .
ENDP
UsageFault_Handler
PROC
EXPORT UsageFault_Handler [WEAK]
B .
ENDP
SVC_Handler PROC
EXPORT SVC_Handler [WEAK]
B .
ENDP
DebugMon_Handler
PROC
EXPORT DebugMon_Handler [WEAK]
B .
ENDP
OS_CPU_PendSVHandler PROC
EXPORT OS_CPU_PendSVHandler [WEAK]
B .
ENDP
OS_CPU_SysTickHandler PROC
EXPORT OS_CPU_SysTickHandler [WEAK]
B .
ENDP
Default_Handler PROC
EXPORT WDT_IRQHandler [WEAK]
EXPORT TIMER0_IRQHandler [WEAK]
EXPORT TIMER1_IRQHandler [WEAK]
EXPORT TIMER2_IRQHandler [WEAK]
EXPORT TIMER3_IRQHandler [WEAK]
EXPORT UART0_IRQHandler [WEAK]
EXPORT UART1_IRQHandler [WEAK]
EXPORT UART2_IRQHandler [WEAK]
EXPORT UART3_IRQHandler [WEAK]
EXPORT PWM1_IRQHandler [WEAK]
EXPORT I2C0_IRQHandler [WEAK]
EXPORT I2C1_IRQHandler [WEAK]
EXPORT I2C2_IRQHandler [WEAK]
EXPORT SPI_IRQHandler [WEAK]
EXPORT SSP0_IRQHandler [WEAK]
EXPORT SSP1_IRQHandler [WEAK]
EXPORT PLL0_IRQHandler [WEAK]
EXPORT RTC_IRQHandler [WEAK]
EXPORT EINT0_IRQHandler [WEAK]
EXPORT EINT1_IRQHandler [WEAK]
EXPORT EINT2_IRQHandler [WEAK]
EXPORT EINT3_IRQHandler [WEAK]
EXPORT ADC_IRQHandler [WEAK]
EXPORT BOD_IRQHandler [WEAK]
EXPORT USB_IRQHandler [WEAK]
EXPORT CAN_IRQHandler [WEAK]
EXPORT DMA_IRQHandler [WEAK]
EXPORT I2S_IRQHandler [WEAK]
EXPORT ENET_IRQHandler [WEAK]
EXPORT RIT_IRQHandler [WEAK]
EXPORT MCPWM_IRQHandler [WEAK]
EXPORT QEI_IRQHandler [WEAK]
EXPORT PLL1_IRQHandler [WEAK]
EXPORT USBActivity_IRQHandler [WEAK]
EXPORT CANActivity_IRQHandler [WEAK]
WDT_IRQHandler
TIMER0_IRQHandler
TIMER1_IRQHandler
TIMER2_IRQHandler
TIMER3_IRQHandler
UART0_IRQHandler
UART1_IRQHandler
UART2_IRQHandler
UART3_IRQHandler
PWM1_IRQHandler
I2C0_IRQHandler
I2C1_IRQHandler
I2C2_IRQHandler
SPI_IRQHandler
SSP0_IRQHandler
SSP1_IRQHandler
PLL0_IRQHandler
RTC_IRQHandler
EINT0_IRQHandler
EINT1_IRQHandler
EINT2_IRQHandler
EINT3_IRQHandler
ADC_IRQHandler
BOD_IRQHandler
USB_IRQHandler
CAN_IRQHandler
DMA_IRQHandler
I2S_IRQHandler
ENET_IRQHandler
RIT_IRQHandler
MCPWM_IRQHandler
QEI_IRQHandler
PLL1_IRQHandler
USBActivity_IRQHandler
CANActivity_IRQHandler
B .
ENDP
ALIGN
; User Initial Stack & Heap
IF
EF:__MICROLIB
EXPORT __initial_sp
EXPORT __heap_base
EXPORT __heap_limit
ELSE
IMPORT __use_two_region_memory
EXPORT __user_initial_stackheap
__user_initial_stackheap
LDR R0, = Heap_Mem
LDR R1, =(Stack_Mem + Stack_Size)
LDR R2, = (Heap_Mem + Heap_Size)
LDR R3, = Stack_Mem
BX LR
ALIGN
ENDIF
END
[/mw_shl_code]
怀疑是启动文件的问题,大家能帮我看看吗?
已经解决,发现是在UCOSIII的BSP_Init()初始化时钟后,我加入的初始化GPIO,UART,Timer后有个中断向量表的初始化和关闭中断函数,把中断关掉了,我把Timer_Config();调整到CSP_IntInit();和 CSP_IntDisAll(CSP_INT_CTRL_NBR_MAIN);的后面后可以正常进入中断,输出中断的调试信息了。
原子哥帮忙看看,常规的是不是要把所有的GPIO,UART。Timer,SPI等等的外设初始化都移至CSP_IntDisAll(CSP_INT_CTRL_NBR_MAIN);的后面去。
[mw_shl_code=c,true]* BSP_Init()
*
* Description : Initialize the Board Support Package (BSP).
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : Application.
*
* Note(s) : (1) The PLL0 Frequency is determined by:
*
* Fcco = (2 x M x Fin) / N
*
* where M = PLL0 Multipler
* N = PLL0 Pre-dividier
* Fin = PLL0 Input Frequency (Main oscillator).
*
* (2) PLL0 settings must meet the following:
* Fin is in the range of 32Khz to 50 Mhz.
* Fcco is in the range of 275 Mhz to 550 Mhz
*
* (3) The LPC17xx CPU frequency is determined by:
*
* CPU_freq = Fcc0 / CPU_Div
*
* (4) The USB clock frequency is determined by:
*
* USB_Clk = M x Fosc x P, or USB_clk = Fcco / (2 x P)
*
* Fcco = Fosc x 2 x M x 2 x P
*
* where Fcco = PLL1 output frequency.
* M = PLL1 multiplier.
* P = PLL1 pre-divider.
* Fosc = Oscialltor frequency.
*
* (5) The PLL1 inputs and settings must meet the following criteria:
* Fosc is in the range of 10 Mhz to 25 Mhz.
* USBClk is 48 Mhz
* Fcco is in the range of 156 Mhz to 320 Mhz
*
* (6) In this example the LPC1768 operates:
*
* PLL0_Fcco = 2 x 25 x 12 / 2
* PLL0_Fcco = 300mhz
*
* CPU_freq = 300 Mhz / 3
* = 100 Mhz
*
* PLL1_Fcc0 = 12 x 4 x 2 x 2 = 192 Mhz.
* USB_Clk = 12 x 4 = 48 Mhz.
*********************************************************************************************************
*/
void BSP_Init (void)
{
CPU_INT16U reg_to;
CPU_INT32U reg_val;
CPU_SR_ALLOC();
/* ---------------- CLOCK INITIALIZATION -------------- */
BSP_REG_FLASHCFG = BSP_MSK_FLASHCFG_CLK_6 /* Set 6 cycles to acces the Flash memory. */
| BSP_MSK_FLASHCFG_RST_VAL;
/* ----------- MAIN OSCILLATOR INITIALIZATION --------- */
DEF_BIT_CLR(BSP_REG_SCS, BSP_BIT_SCS_OSCRANGE); /* Set the main oscillator range */
reg_to = BSP_VAL_MAX_TO;
DEF_BIT_SET(BSP_REG_SCS, BSP_BIT_SCS_OSCEN); /* Enable the Main Oscillator */
/* Wait until the main oscillator is enabled. */
while (DEF_BIT_IS_CLR(BSP_REG_SCS, BSP_BIT_SCS_OSCSTAT) &&
(reg_to > 0u)) {
reg_to--;
}
if (reg_to == 0u) { /* Configuration fail */
return;
}
BSP_REG_PCLKSEL0 = DEF_BIT_NONE; /* All peripheral clock runrs at CPU_Clk / 4 = 25 Mhz */
BSP_REG_PCLKSEL1 = DEF_BIT_NONE;
/* ------------------ PLL0 CONFIGURATION -------------- */
reg_val = (((25u - 1u) << 0u) & BSP_MSK_PLLCFG0_MSEL) /* PLL0 values M = 25 & N = 2 (see note #6) */
| ((( 2u - 1u) << 16u) & BSP_MSK_PLLCFG0_NSEL);
/* 1. Disconnect PLL0 with one feed sequence if PLL ... */
/* ... already connected. */
if (DEF_BIT_IS_SET(BSP_REG_PLLSTAT(0u), BSP_BIT_PLLSTAT_PLLC0_STAT)) {
DEF_BIT_CLR(BSP_REG_PLLCTRL(0u), BSP_BIT_PLLCTRL_PLLC);
BSP_PLL_FEED_SEQ(0u);
}
DEF_BIT_CLR(BSP_REG_PLLCTRL(0u), BSP_BIT_PLLCTRL_PLLE); /* 2. Disable PLL0 with one feed sequence */
BSP_PLL_FEED_SEQ(0u);
BSP_REG_CCLKCFG = (1u - 1u); /* 3. Change the CPU clock divider setting to speed ... */
/* ... operation without PLL0 */
BSP_REG_CLKSRCSEL = BSP_BIT_CLKSRCSEL_MAIN; /* 4. Select the main osc. as the PLL0 clock source */
BSP_REG_PLLCFG(0u) = reg_val; /* 5. Write to the PLLCFG and make it effective with... */
BSP_PLL_FEED_SEQ(0u) /* ... one one feed sequence */
DEF_BIT_SET(BSP_REG_PLLCTRL(0u), BSP_BIT_PLLCTRL_PLLE); /* 6. Enable PLL0 with one feed sequence */
BSP_PLL_FEED_SEQ(0u);
BSP_REG_CCLKCFG = (3u - 1u); /* 7. Change the CPU clock divider setting for ... */
/* ... operation with PLL0 */
reg_to = BSP_VAL_MAX_TO; /* 8. Wait for PLL0 to achieve lock by monitoring ... */
/* ... the PLOCK0 bit in the PLL0STAT */
while (DEF_BIT_IS_CLR(BSP_REG_PLLSTAT(0u), BSP_BIT_PLLSTAT_PLOCK0) &&
(reg_to > 0u)) {
reg_to--;
}
if (reg_to == 0u) {
return;
}
DEF_BIT_SET(BSP_REG_PLLCTRL(0u), BSP_BIT_PLLCTRL_PLLC); /* 9. Connect PLL0 with one feed sequence */
BSP_PLL_FEED_SEQ(0u);
/* ------------------ PLL1 CONFIGURATION -------------- */
reg_val = (((4u - 1u) << 0u) & BSP_MSK_PLLCFG1_MSEL) /* PLL1 values M = 4; P = 2 coded as '01' (see note #6) */
| (((0x01u ) << 5u) & BSP_MSK_PLLCFG1_NSEL);
DEF_BIT_CLR(BSP_REG_PLLCTRL(1u), BSP_BIT_PLLCTRL_PLLC); /* 1. Disconnect PLL1 with one feed sequence */
BSP_PLL_FEED_SEQ(1u);
DEF_BIT_CLR(BSP_REG_PLLCTRL(1u), BSP_BIT_PLLCTRL_PLLE); /* 2. Disable PLL1 with one feed sequence */
BSP_PLL_FEED_SEQ(1u);
BSP_REG_PLLCFG(1u) = reg_val; /* 3. Write to the PLLCFG and make it effective with... */
BSP_PLL_FEED_SEQ(1u); /* ... one one feed sequence */
DEF_BIT_SET(BSP_REG_PLLCTRL(1u), BSP_BIT_PLLCTRL_PLLE); /* 4. Enable PLL1 with one feed sequence */
BSP_PLL_FEED_SEQ(1u);
reg_to = BSP_VAL_MAX_TO; /* 5. Wait for PLL1 to achieve lock by monitoring ... */
/* ... the PLOCK1 bit in the PLL1STAT */
while (DEF_BIT_IS_CLR(BSP_REG_PLLSTAT(1u), BSP_BIT_PLLSTAT_PLOCK1) &&
(reg_to > 0u)) {
reg_to--;
}
if (reg_to == 0u) {
return;
}
DEF_BIT_SET(BSP_REG_PLLCTRL(1u), BSP_BIT_PLLCTRL_PLLC); /* 6. Connect PLL1 with one feed sequence */
BSP_PLL_FEED_SEQ(1u);
BSP_REG_FLASHCFG = BSP_MSK_FLASHCFG_CLK_5 /* Set 5 cycles to acces the Flash memory. */
| BSP_MSK_FLASHCFG_RST_VAL;
//初始化GPIO,时钟
GPIO_Config();
// UART0_DebugConfig();
debug_frmwrk_init();//PC串口 UART0初始化
//NetDevice_Config();//配置设备的IP、网关、子网掩码、MAC地址等参数
UART3_Config();
Timer_Config();
CSP_IntInit();
CSP_IntDisAll(CSP_INT_CTRL_NBR_MAIN);
}
[/mw_shl_code]
一周热门 更多>