各位达人:
我使用两个定时器中断timer0,timer1,在timer1中断服务程序中开启了全局中断。
这样timer0可以抢占timer1的中断服务。抢占工作能够工作。但是运行一段时间后,程序跑飞。
这个工程调用startware库。
求高手指点
#include <math.h>
#include <interrupt.h>
#include <soc_C6748.h>
#include <timer.h>
#include <gpio.h>
#include <hw_psc_C6748.h>
#include <hw_types.h>
#include <hw_syscfg0_C6748.h>
#include <hw_pllc_C6748.h>
#include <emifa.h>
#include <hw_uart.h>
// Prototype statements for functions found within this file.
//interrupt void wakeint_isr(void);
static void cpu_timer0_isr(void); // LED Only
static void cpu_timer1_isr(void); // main loop
static void cpu_timer2_isr(void);
void GpioLedPinMuxSetup(void);
void Delay(volatile unsigned int count);
void PLL0Init(unsigned char clk_src, unsigned char pllm,unsigned char prediv, unsigned char postdiv );
void BlPlatformConfig(void);
void GpioNVRamPinMuxSetup();
void AdSetup();
//interrupt void acicRxFifoIsr(void);
//double sin(double x);
//double cos(double x);
void main(void);
void acia_fifo_init(void);
void acib_fifo_init(void);
//void acic_fifo_init(void);
//void wait_here(void);
//void error(void);
void VarIInit(void);
void VarFInit(void);
void ParaInit(void);
void ad_update(void);
void ad_data(void);
void RTC_Read_Out(void);
void RTC_Write(void);
void FFT32Calc(void);
void FFT128Calc(void);
void RMSCalc(void);
void LCDTxOut(void);
#define LED_GP8_10 139
#define LED_GP8_8 137
#define LED_GP8_9 138
#define LED_GP1_10 27
#define LED_GP1_9 26
#define LED_GP1_15 32
#define LED_GP2_12 45
#define PLL_CLK_SRC 0
#define PLL0_MUL 17
#define PLL0_PREDIV 0
#define PLL0_POSTDIV 0
#define CSDO *(unsigned int *)0x4000
#define CSAD0 *(int *)0x4400
#define CSAD1 *(int *)0x4800
#define PI 3.14159f
#define ADKV 6090.28E-8
#define ADKI 5389.58E-8
#define DeltaWT 0.125*2*PI/20
#define PI23 2*PI/3
#define PI16 1*PI/6
#define PI2 PI/2
#define Ts 1.25e-4
#define AD_RESET 15
#define AD_START 99
#define AD_FILTER0 100
#define AD_FILTER1 101
#define AD_FILTER2 14
#define AD_BUSY 13
#define NVRam_Start 0x62000000
// Global variables used in this example: in .ebss
unsigned int RTCChgFlg,RMSCalcFlg,LCDViewFlg,LCDTxFlg,LCDTxNum,Year[5];
unsigned int D2aCount,CPULedCount,CpuSyncCount,LCD01msCount,P000[16],WT;
unsigned int FFT32CalcFlg,FFTAllTxFlg,FFT128CalcFlg,FFT128ChnNum;
unsigned int Led1Count,Led2Count;
short adValue[8],ADIRaw[6],LCDRx[16],LCDTx[784];
float ADFRaw[6],AD_Data[10],AD_Data0[1],AD_Data32[32][6],P000_F[16],VIrms[7],Valph,Vbeta,Ialph,Ibeta,PQCOS[4];
float FFTResult[31],FFT32Result[31][6],Xfft[32],Yfft[32][2],YfftP[32][2];
float FFTResult128[31],FFFT128Result[64],Xfft128[128],Yfft128[128][2],YfftP128[128][2];
float PNV_PTR[16],D2A_PTR[960],LCDWavOld,LCDWavNew,LCDWavTmp;
extern short DCoffset[8];
extern float SIN[128],COS[128];
extern unsigned int FFT32Flg,FFT32Data,FFTAllFlg,FFTAllCount,LCD01msFlg,LCD01msTs,LCD01msPar[3],LCDViewNum,FFTChnNum,FFTN[32],FFTN128[128];
extern unsigned int FFT128Flg,FFT128Data;
void main(void)
{
unsigned int i,LCD01msTmp;
TimerDisable(SOC_TMR_0_REGS,TMR_TIMER12);
TimerDisable(SOC_TMR_1_REGS,TMR_TIMER12);
BlPlatformConfig();
PSCModuleControl(SOC_PSC_1_REGS, HW_PSC_GPIO, PSC_POWERDOMAIN_ALWAYS_ON,PSC_MDCTL_NEXT_ENABLE); // 初始化LED对应的GPIO
// UARTPuts("Init GPIO PSC\n",-1);
GpioLedPinMuxSetup(); // 设置pinmux
// UARTPuts("Setup PINMUX\n",-1);
GPIODirModeSet(SOC_GPIO_0_REGS, LED_GP8_10, GPIO_DIR_OUTPUT); // 设置IO为输出
GPIODirModeSet(SOC_GPIO_0_REGS, LED_GP8_9, GPIO_DIR_OUTPUT);
GPIODirModeSet(SOC_GPIO_0_REGS, LED_GP8_8, GPIO_DIR_OUTPUT);
GPIODirModeSet(SOC_GPIO_0_REGS, LED_GP1_10, GPIO_DIR_OUTPUT);
GPIODirModeSet(SOC_GPIO_0_REGS, LED_GP1_15, GPIO_DIR_OUTPUT);
GPIODirModeSet(SOC_GPIO_0_REGS, LED_GP1_9, GPIO_DIR_OUTPUT);
GPIODirModeSet(SOC_GPIO_0_REGS, LED_GP2_12, GPIO_DIR_OUTPUT);
PSCModuleControl(SOC_PSC_0_REGS,HW_PSC_EMIFA,PSC_POWERDOMAIN_ALWAYS_ON,PSC_MDCTL_NEXT_ENABLE ); // NVRam
GpioNVRamPinMuxSetup();
HWREG(SOC_EMIFA_0_REGS+EMIFA_CE3CFG) |= 1; // 设置16位 //NVRAM setup for 16 bits, must be before ADsetup
AdSetup();
HWREG(SOC_EMIFA_0_REGS+EMIFA_CE4CFG) |= 1; //AD setup for 16 bits
TimerConfigure(SOC_TMR_0_REGS,TMR_CFG_64BIT_CLK_INT); // Timer0 initialization
TimerPeriodSet(SOC_TMR_0_REGS,TMR_TIMER12,0x7FFFFFF); // EA6 for 0.15625,3A98 for 0.625
TimerPeriodSet(SOC_TMR_0_REGS,TMR_TIMER34,0);
TimerConfigure(SOC_TMR_1_REGS,TMR_CFG_64BIT_CLK_INT); // Timer1 initialization
TimerPeriodSet(SOC_TMR_1_REGS,TMR_TIMER12,0x7FFFFFF);
TimerPeriodSet(SOC_TMR_1_REGS,TMR_TIMER34,0);
IntDSPINTCInit(); // 设置中断
IntRegister(C674X_MASK_INT4,cpu_timer0_isr); // Int4 – T0
IntEventMap(C674X_MASK_INT4,SYS_INT_T64P0_TINT12);
IntEnable(C674X_MASK_INT4);
IntRegister(C674X_MASK_INT5,cpu_timer1_isr); // Int5 – T1
IntEventMap(C674X_MASK_INT5,SYS_INT_T64P1_TINT12);
IntEnable(C674X_MASK_INT5);
IntGlobalEnable();
HWREGH(NVRam_Start+0) = 0x1234;
HWREGH(NVRam_Start+2) = 0x5678;
GPIOPinWrite(SOC_GPIO_0_REGS,LED_GP8_9,1); // 1 CPU 0
GPIOPinWrite(SOC_GPIO_0_REGS,LED_GP8_8,1); // 2 CPU 1
GPIOPinWrite(SOC_GPIO_0_REGS,LED_GP8_10,1); // 3 COMM
TimerCounterSet(SOC_TMR_0_REGS,TMR_TIMER12,0);
TimerCounterSet(SOC_TMR_1_REGS,TMR_TIMER12,0);
TimerIntEnable(SOC_TMR_0_REGS,TMR_INT_TMR12_NON_CAPT_MODE);
TimerIntEnable(SOC_TMR_1_REGS,TMR_INT_TMR12_NON_CAPT_MODE);
TimerEnable(SOC_TMR_0_REGS,TMR_TIMER12,TMR_ENABLE_CONT );
TimerEnable(SOC_TMR_1_REGS,TMR_TIMER12,TMR_ENABLE_CONT );
for(;;)
{
}
}
static void cpu_timer0_isr(void)
{
unsigned int d = 0x3FFFFFF;
GPIOPinWrite(SOC_GPIO_0_REGS,LED_GP8_9,0); // LED1
// ServiceDog();
TimerIntDisable(SOC_TMR_0_REGS,TMR_INT_TMR12_NON_CAPT_MODE);
IntEventClear(SYS_INT_T64P0_TINT12);
TimerIntStatusClear(SOC_TMR_0_REGS,TMR_INT_TMR12_NON_CAPT_MODE);
while(–d);
TimerIntEnable(SOC_TMR_0_REGS,TMR_INT_TMR12_NON_CAPT_MODE);
GPIOPinWrite(SOC_GPIO_0_REGS,LED_GP8_9,1); // LED1
}
static void cpu_timer1_isr(void)
{
GPIOPinWrite(SOC_GPIO_0_REGS,LED_GP8_8,0);
IntGlobalEnable();
unsigned int d = 0x3FFFFFF;
TimerIntDisable(SOC_TMR_1_REGS,TMR_INT_TMR12_NON_CAPT_MODE);
IntEventClear(SYS_INT_T64P1_TINT12);
TimerIntStatusClear(SOC_TMR_1_REGS,TMR_INT_TMR12_NON_CAPT_MODE);
while(–d);
TimerIntEnable(SOC_TMR_1_REGS,TMR_INT_TMR12_NON_CAPT_MODE);
GPIOPinWrite(SOC_GPIO_0_REGS,LED_GP8_8,1);
}
void GpioLedPinMuxSetup(){
unsigned int savePinmux = 0;
// GP8[10] PINMUX18.31_28
savePinmux = (HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(18))) &
~(SYSCFG_PINMUX18_PINMUX18_31_28);
HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(18)) =
( (SYSCFG_PINMUX18_PINMUX18_31_28_GPIO8_10 << SYSCFG_PINMUX18_PINMUX18_31_28_SHIFT) \
| savePinmux );
// GP8[8] PINMUX19.7_4
savePinmux = (HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(19))) &
~(SYSCFG_PINMUX19_PINMUX19_7_4);
HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(19)) =
( (SYSCFG_PINMUX19_PINMUX19_7_4_GPIO8_8 << SYSCFG_PINMUX19_PINMUX19_7_4_SHIFT) \
| savePinmux );
// GP8[9] PINMUX19.3_0
savePinmux = (HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(19))) &
~(SYSCFG_PINMUX19_PINMUX19_3_0_GPIO8_9);
HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(19)) =
( (SYSCFG_PINMUX19_PINMUX19_3_0_GPIO8_9 << SYSCFG_PINMUX19_PINMUX19_3_0_SHIFT) \
| savePinmux );
savePinmux = (HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(2))) &
~(SYSCFG_PINMUX2_PINMUX2_23_20 | SYSCFG_PINMUX2_PINMUX2_27_24 |SYSCFG_PINMUX2_PINMUX2_3_0 );
HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(2)) =
( (SYSCFG_PINMUX2_PINMUX2_23_20_GPIO1_10 << SYSCFG_PINMUX2_PINMUX2_23_20_SHIFT) \
| (SYSCFG_PINMUX2_PINMUX2_27_24_GPIO1_9 << SYSCFG_PINMUX2_PINMUX2_27_24_SHIFT) \
| (SYSCFG_PINMUX2_PINMUX2_3_0_GPIO1_15 << SYSCFG_PINMUX2_PINMUX2_3_0_SHIFT ) \
| savePinmux );
savePinmux = (HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(5))) &
~(SYSCFG_PINMUX5_PINMUX5_15_12);
HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(5)) =
( (SYSCFG_PINMUX5_PINMUX5_15_12_GPIO2_12 << SYSCFG_PINMUX5_PINMUX5_15_12_SHIFT) \
| savePinmux );
}
void BlPlatformConfig(void)
{
/* Unlock kick registers (necessary on C6748) */
HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_KICK0R) = SYSCFG_KICK0R_UNLOCK;
HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_KICK1R) = SYSCFG_KICK1R_UNLOCK;
HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_SUSPSRC) &= SYSCFG_SUSPSRC_I2C0SRC |
SYSCFG_SUSPSRC_UART2SRC |
SYSCFG_SUSPSRC_SPI1SRC |
SYSCFG_SUSPSRC_TIMER64P_0SRC |
SYSCFG_SUSPSRC_TIMER64P_1SRC;
/* Set the PLL0 to generate 300MHz for ARM */
PLL0Init(PLL_CLK_SRC, PLL0_MUL, PLL0_PREDIV, PLL0_POSTDIV);
}
void PLL0Init(unsigned char clk_src, unsigned char pllm,
unsigned char prediv, unsigned char postdiv )
{
HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_CFGCHIP0) &=
~SYSCFG_CFGCHIP0_PLL_MASTER_LOCK;
/* PLLENSRC must be cleared before PLLEN bit have any effect */
HWREG(SOC_PLLC_0_REGS + PLLC_PLLCTL) &= ~PLLC_PLLCTL_PLLENSRC;
/* PLLCTL.EXTCLKSRC bit 9 should be left at 0 */
HWREG(SOC_PLLC_0_REGS + PLLC_PLLCTL) &= ~PLLC_PLLCTL_EXTCLKSRC;
/*PLLEN = 0 put pll in bypass mode */
HWREG(SOC_PLLC_0_REGS + PLLC_PLLCTL) &= ~PLLC_PLLCTL_PLLEN;
/*wait for 2 counts to switch pll to the by pass mode */
Delay(2);
/*Select the Clock Mode bit 8 as External Clock or On Chip Oscilator */
HWREG(SOC_PLLC_0_REGS + PLLC_PLLCTL) &= ~PLLC_PLLCTL_CLKMODE;
HWREG(SOC_PLLC_0_REGS + PLLC_PLLCTL) |= (clk_src << 8);
/* Clear the PLLRST to reset the PLL */
HWREG(SOC_PLLC_0_REGS + PLLC_PLLCTL) &= ~PLLC_PLLCTL_PLLRST;
/*Disable PLL out */
HWREG(SOC_PLLC_0_REGS + PLLC_PLLCTL) |= PLLC_PLLCTL_PLLDIS;
/* PLL initialization sequece, power up the PLL */
HWREG(SOC_PLLC_0_REGS + PLLC_PLLCTL) &= ~PLLC_PLLCTL_PLLPWRDN;
HWREG(SOC_PLLC_0_REGS + PLLC_PLLCTL) &= ~PLLC_PLLCTL_PLLDIS;
/* Wait for 300 counts */
Delay(300);
HWREG(SOC_PLLC_0_REGS + PLLC_PLLM) = pllm;
/* Program the required multiplier value */
HWREG(SOC_PLLC_0_REGS + PLLC_PREDIV) = PLLC_PREDIV_PREDEN | prediv;
HWREG(SOC_PLLC_0_REGS + PLLC_POSTDIV) = PLLC_POSTDIV_POSTDEN | postdiv;
/* Check for the GOSTAT bit in PLLSTAT to clear to 0 to indicate that
no GO operation is currently in progress */
while (HWREG(SOC_PLLC_0_REGS + PLLC_PLLSTAT) & PLLC_PLLSTAT_GOSTAT );
/* divider values are assigned */
// HWREG(SOC_PLLC_0_REGS + PLLC_PLLDIV3) = PLLC_PLLDIV3_D3EN | 31;
HWREG(SOC_PLLC_0_REGS + PLLC_PLLCMD) |= PLLC_PLLCMD_GOSET;
/*Wait for the Gostat bit in PLLSTAT to clear to 0
( completion of phase alignment) */
while (HWREG(SOC_PLLC_0_REGS + PLLC_PLLSTAT) & PLLC_PLLSTAT_GOSTAT);
/* Wait for 40 counts */
Delay(40);
/* set the PLLRST bit in PLLCTL to 1,bring the PLL out of reset */
HWREG(SOC_PLLC_0_REGS + PLLC_PLLCTL) |= PLLC_PLLCTL_PLLRST;
/* Wait for 300 counts*/
Delay (300);
/*removing pll from bypass mode */
HWREG(SOC_PLLC_0_REGS + PLLC_PLLCTL) |= PLLC_PLLCTL_PLLEN;
/* set PLL lock bit */
HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_CFGCHIP0) |=
(0x01 << SYSCFG_CFGCHIP0_PLL_MASTER_LOCK_SHIFT )
& SYSCFG_CFGCHIP0_PLL_MASTER_LOCK ;
}
void Delay(volatile unsigned int count)
{
while(count–);
}
void GpioNVRamPinMuxSetup(){
unsigned int savePinmux = 0;
savePinmux = HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(5)) & \
~( SYSCFG_PINMUX5_PINMUX5_27_24 );
HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(5)) = \
( (SYSCFG_PINMUX5_PINMUX5_27_24_EMA_BA1 << SYSCFG_PINMUX5_PINMUX5_27_24_SHIFT) | \
savePinmux);
savePinmux = HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(7)) & \
~( SYSCFG_PINMUX7_PINMUX7_23_20|SYSCFG_PINMUX7_PINMUX7_19_16|SYSCFG_PINMUX17_PINMUX17_7_4 );
HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(7)) = \
( (SYSCFG_PINMUX7_PINMUX7_23_20_NEMA_OE << SYSCFG_PINMUX7_PINMUX7_23_20_SHIFT) | \
(SYSCFG_PINMUX7_PINMUX7_19_16_NEMA_WE << SYSCFG_PINMUX7_PINMUX7_19_16_SHIFT) | \
(SYSCFG_PINMUX7_PINMUX7_7_4_NEMA_CS3 << SYSCFG_PINMUX7_PINMUX7_7_4_SHIFT) | \
savePinmux);
HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(8)) = \
( (SYSCFG_PINMUX8_PINMUX8_31_28_EMA_D8 << SYSCFG_PINMUX8_PINMUX8_31_28_SHIFT) |\
(SYSCFG_PINMUX8_PINMUX8_27_24_EMA_D9 << SYSCFG_PINMUX8_PINMUX8_27_24_SHIFT) |\
(SYSCFG_PINMUX8_PINMUX8_23_20_EMA_D10 << SYSCFG_PINMUX8_PINMUX8_23_20_SHIFT)|\
(SYSCFG_PINMUX8_PINMUX8_19_16_EMA_D11 << SYSCFG_PINMUX8_PINMUX8_19_16_SHIFT)|\
(SYSCFG_PINMUX8_PINMUX8_15_12_EMA_D12 << SYSCFG_PINMUX8_PINMUX8_15_12_SHIFT)|\
(SYSCFG_PINMUX8_PINMUX8_11_8_EMA_D13 << SYSCFG_PINMUX8_PINMUX8_11_8_SHIFT)|\
(SYSCFG_PINMUX8_PINMUX8_7_4_EMA_D14 << SYSCFG_PINMUX8_PINMUX8_7_4_SHIFT)|\
(SYSCFG_PINMUX8_PINMUX8_3_0_EMA_D15 << SYSCFG_PINMUX8_PINMUX8_3_0_SHIFT));
savePinmux = HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(6)) & \
~( SYSCFG_PINMUX6_PINMUX6_19_16|SYSCFG_PINMUX6_PINMUX6_23_20);
HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(6)) = \
( (SYSCFG_PINMUX6_PINMUX6_19_16_NEMA_WE_DQM0 <<SYSCFG_PINMUX6_PINMUX6_19_16_SHIFT) |\
(SYSCFG_PINMUX6_PINMUX6_23_20_NEMA_WE_DQM1 <<SYSCFG_PINMUX6_PINMUX6_23_20_SHIFT) |\
savePinmux);
HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(12)) = \
( (SYSCFG_PINMUX12_PINMUX12_31_28_EMA_A0 << SYSCFG_PINMUX12_PINMUX12_31_28_SHIFT) |\
(SYSCFG_PINMUX12_PINMUX12_27_24_EMA_A1 << SYSCFG_PINMUX12_PINMUX12_27_24_SHIFT) |\
(SYSCFG_PINMUX12_PINMUX12_23_20_EMA_A2 << SYSCFG_PINMUX12_PINMUX12_23_20_SHIFT) |\
(SYSCFG_PINMUX12_PINMUX12_19_16_EMA_A3 << SYSCFG_PINMUX12_PINMUX12_19_16_SHIFT) |\
(SYSCFG_PINMUX12_PINMUX12_15_12_EMA_A4 << SYSCFG_PINMUX12_PINMUX12_15_12_SHIFT) |\
(SYSCFG_PINMUX12_PINMUX12_11_8_EMA_A5 << SYSCFG_PINMUX12_PINMUX12_11_8_SHIFT) |\
(SYSCFG_PINMUX12_PINMUX12_7_4_EMA_A6 << SYSCFG_PINMUX12_PINMUX12_7_4_SHIFT) |\
(SYSCFG_PINMUX12_PINMUX12_3_0_EMA_A7 << SYSCFG_PINMUX12_PINMUX12_3_0_SHIFT));
HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(11)) = \
( (SYSCFG_PINMUX11_PINMUX11_31_28_EMA_A8 << SYSCFG_PINMUX11_PINMUX11_31_28_SHIFT) |\
(SYSCFG_PINMUX11_PINMUX11_27_24_EMA_A9 << SYSCFG_PINMUX11_PINMUX11_27_24_SHIFT) |\
(SYSCFG_PINMUX11_PINMUX11_23_20_EMA_A10 << SYSCFG_PINMUX11_PINMUX11_23_20_SHIFT) |\
(SYSCFG_PINMUX11_PINMUX11_19_16_EMA_A11 << SYSCFG_PINMUX11_PINMUX11_19_16_SHIFT) |\
(SYSCFG_PINMUX11_PINMUX11_15_12_EMA_A12 << SYSCFG_PINMUX11_PINMUX11_15_12_SHIFT) |\
(SYSCFG_PINMUX11_PINMUX11_11_8_EMA_A13 << SYSCFG_PINMUX11_PINMUX11_11_8_SHIFT) |\
(SYSCFG_PINMUX11_PINMUX11_7_4_EMA_A14 << SYSCFG_PINMUX11_PINMUX11_7_4_SHIFT) |\
(SYSCFG_PINMUX11_PINMUX11_3_0_EMA_A15 << SYSCFG_PINMUX11_PINMUX11_3_0_SHIFT));
HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(9)) = \
( (SYSCFG_PINMUX9_PINMUX9_31_28_EMA_D0 << SYSCFG_PINMUX9_PINMUX9_31_28_SHIFT) |\
(SYSCFG_PINMUX9_PINMUX9_27_24_EMA_D1 << SYSCFG_PINMUX9_PINMUX9_27_24_SHIFT) |\
(SYSCFG_PINMUX9_PINMUX9_23_20_EMA_D2 << SYSCFG_PINMUX9_PINMUX9_23_20_SHIFT) |\
(SYSCFG_PINMUX9_PINMUX9_19_16_EMA_D3 << SYSCFG_PINMUX9_PINMUX9_19_16_SHIFT) |\
(SYSCFG_PINMUX9_PINMUX9_15_12_EMA_D4 << SYSCFG_PINMUX9_PINMUX9_15_12_SHIFT) |\
(SYSCFG_PINMUX9_PINMUX9_11_8_EMA_D5 << SYSCFG_PINMUX9_PINMUX9_11_8_SHIFT) |\
(SYSCFG_PINMUX9_PINMUX9_7_4_EMA_D6 << SYSCFG_PINMUX9_PINMUX9_7_4_SHIFT) |\
(SYSCFG_PINMUX9_PINMUX9_3_0_EMA_D7 << SYSCFG_PINMUX9_PINMUX9_3_0_SHIFT));
savePinmux = HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(10)) & \
~( SYSCFG_PINMUX10_PINMUX10_31_28 | SYSCFG_PINMUX10_PINMUX10_27_24 | SYSCFG_PINMUX10_PINMUX10_23_20);
HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(10)) = \
( (SYSCFG_PINMUX10_PINMUX10_31_28_EMA_A16 << SYSCFG_PINMUX10_PINMUX10_31_28_SHIFT) |\
(SYSCFG_PINMUX10_PINMUX10_27_24_EMA_A17 << SYSCFG_PINMUX10_PINMUX10_27_24_SHIFT) |\
(SYSCFG_PINMUX10_PINMUX10_23_20_EMA_A18 << SYSCFG_PINMUX10_PINMUX10_23_20_SHIFT) |\
savePinmux);
}
void AdSetup(){
int j;
unsigned int savePinmux = 0;
savePinmux = HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(0)) & \
~( (SYSCFG_PINMUX0_PINMUX0_15_12)|(SYSCFG_PINMUX0_PINMUX0_11_8)|SYSCFG_PINMUX0_PINMUX0_7_4);
HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(0)) = \
( (SYSCFG_PINMUX0_PINMUX0_15_12_GPIO0_12 <<SYSCFG_PINMUX0_PINMUX0_15_12_SHIFT) |\
(SYSCFG_PINMUX0_PINMUX0_11_8_GPIO0_13 <<SYSCFG_PINMUX0_PINMUX0_11_8_SHIFT) |\
(SYSCFG_PINMUX0_PINMUX0_7_4_GPIO0_14 <<SYSCFG_PINMUX0_PINMUX0_7_4_SHIFT) |\
savePinmux);
savePinmux = HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(7)) & \
~( (SYSCFG_PINMUX7_PINMUX7_11_8));
HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(7)) = \
( (SYSCFG_PINMUX7_PINMUX7_11_8_NEMA_CS4 <<SYSCFG_PINMUX7_PINMUX7_11_8_SHIFT) |\
savePinmux);
savePinmux = HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(19)) & \
~( (SYSCFG_PINMUX19_PINMUX19_19_16)|(SYSCFG_PINMUX19_PINMUX19_15_12)|(SYSCFG_PINMUX19_PINMUX19_11_8));
HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(19))= \
( (SYSCFG_PINMUX19_PINMUX19_19_16_GPIO6_2 <<SYSCFG_PINMUX19_PINMUX19_19_16_SHIFT) |\
(SYSCFG_PINMUX19_PINMUX19_15_12_GPIO6_3 << SYSCFG_PINMUX19_PINMUX19_15_12_SHIFT) |\
(SYSCFG_PINMUX19_PINMUX19_11_8_GPIO6_4 << SYSCFG_PINMUX19_PINMUX19_11_8_SHIFT) |\
savePinmux);
GPIODirModeSet(SOC_GPIO_0_REGS, AD_RESET, GPIO_DIR_OUTPUT);
GPIODirModeSet(SOC_GPIO_0_REGS, AD_START, GPIO_DIR_OUTPUT);
GPIODirModeSet(SOC_GPIO_0_REGS, AD_FILTER0, GPIO_DIR_OUTPUT);
GPIODirModeSet(SOC_GPIO_0_REGS, AD_FILTER1, GPIO_DIR_OUTPUT);
GPIODirModeSet(SOC_GPIO_0_REGS, AD_FILTER2, GPIO_DIR_OUTPUT);
GPIODirModeSet(SOC_GPIO_0_REGS, AD_BUSY, GPIO_DIR_INPUT);
GPIOPinWrite(SOC_GPIO_0_REGS,AD_RESET,1);
for(j=0;j<1000;++j);
GPIOPinWrite(SOC_GPIO_0_REGS,AD_RESET,0);
GPIOPinWrite(SOC_GPIO_0_REGS,AD_FILTER0,0);
GPIOPinWrite(SOC_GPIO_0_REGS,AD_FILTER1,0);
GPIOPinWrite(SOC_GPIO_0_REGS,AD_FILTER2,0);
}
Tony Tang:
amanda sun
static void cpu_timer1_isr(void){ GPIOPinWrite(SOC_GPIO_0_REGS,LED_GP8_8,0); IntGlobalEnable(); unsigned int d = 0x3FFFFFF; TimerIntDisable(SOC_TMR_1_REGS,TMR_INT_TMR12_NON_CAPT_MODE); IntEventClear(SYS_INT_T64P1_TINT12); TimerIntStatusClear(SOC_TMR_1_REGS,TMR_INT_TMR12_NON_CAPT_MODE);
while(–d);
TimerIntEnable(SOC_TMR_1_REGS,TMR_INT_TMR12_NON_CAPT_MODE); GPIOPinWrite(SOC_GPIO_0_REGS,LED_GP8_8,1);}
上面才是关键代码,那些无关的代码着实有点眼乱。
直接调用IntGlobalEnable();没做IRP的保护,肯定会出问题的。具体参考:sprufe8b