查看: 1767|回复: 0

[其他] 刚接触XDP512 关于中断的问题,请指点

[复制链接]

该用户从未签到

1

主题

1

帖子

0

新手上路

Rank: 1

积分
5
最后登录
2017-4-9
发表于 2017-4-9 12:15:35 | 显示全部楼层 |阅读模式
我用XDP512实现了一个简单的PIT定时器和SCI0的串口收发。程序可以正常运行,但是就是在XGATE里面定义的全局变量StartIarCheckflag并且,如果在串口收到命令StartIarCheckflag就置1,现在串口能进去,但是发现StartIarCheckflag置1后,主函数里面却不能进入if(StartIarCheckflag)这个判断里面。
还有就是PIT为啥放入XGATE里面就是不起作用呢?
程序如下,请大家给予指导。谢谢
主函数如下:

extern unsigned char  StartIarCheckflag;

void PIT_inits(void){
                                        //定时间断初始化函数 1ms定时间断设置
  PITCFLMT_PITE=0;                      //关PIT
  PITCE_PCE0=1;                         //定时器通道0使能
  PITMTLD0=40-1;                        //8位定时器初值设定,40分频,在40MHzBusClock下,为1MHz。即1us
  PITLD0=1000-1;                        //16位定时器初值设定。1000*1us=1ms
  PITINTE_PINTE0=1;                     //定时器间断通道0间断使能
  PITCFLMT_PITE=1;                      //使能PIT
}
void Sci0_Init(void){

  SCI0BD = BUSCLK/16/BAUD;      //设置SCI0波特率为9600
  SCI0CR1 = 0x00;              //设置SCI0为正常模式,八位数据位,无奇偶校验
  SCI0CR2 = 0x2c;             //允许接收和发送数据,允许接收中断功能
}


void SCI_send(unsigned char data)
{
  while(!SCI1SR1_TDRE);         //等待发送数据寄存器(缓冲器)为空
  SCI1DRL = data;
}

void main(void) {
  
  SysInit();
  IO_Init();
  PIT_inits();
  SetupXGATE();
  delay(30);
  Sci0_Init();
  IsConttonFlag=0;
    EnableInterrupts;
  for(;;) {
  
    if(timeLed==500) {
         timeLed=0;
        LED1=~LED1;
     }
    if(StartIarCheckflag==1) {
       StartIarCheckflag = 0;
      if(CheckNum==200) {//200ms检测一次
        CheckNum=0;
      if(CheckIraMainUse==1) {//检测
         CheckCnt++;
         LED2=~LED2;
      if(CheckCnt>=5) {
          CheckCnt=0;
          IsConttonFlag=1;//有棉花

        }
      } else{
        CheckCnt=0;
        IsConttonFlag=0; //无棉花
        LED2=1;

      }
     }
    }  
  } /* loop forever */
  /* please make sure that you never leave main */
}

/*************************************************************/
/*                         中断函数                          */
/*************************************************************/
#pragma CODE_SEG __NEAR_SEG NON_BANKED
void interrupt 66 PIT0(void)  //1ms 定时器中断
{
  //中断执行程序
  timeLed++;
  CheckNum++;
  PITTF_PTF0 = 1;   //清中断标志
}
//////协处理器里面中断

#include <hidef.h>      /* common defines and macros */
#include "xgate.h"
#include <mc9s12xdp512.h>       /* derivative information */
#include"myDef.h"

#include"externDef.h"
//变量定义

unsigned int   rcvdata0;
unsigned char  rcvendflag0;
unsigned char  StartIarCheckflag;
unsigned  char  scistatus0; //sci1
unsigned  char  rcvcharnum0 ;     






// put your handler variables here
typedef struct {
  int counter;
} MyDataType;

static MyDataType MyData= {
  0
};

// interrupt handler
interrupt void SoftwareTrigger0_Handler(MyDataType* __restrict pData) {
  
  // put your own code here
  pData->counter++;
  if (pData->counter > 100)  {
    pData->counter= 0;
    shared_counter++;
  }
}


// interrupt handler for all others
interrupt void ErrorHandler(int dataptr) {
  int chanNum= dataptr;
  asm BRK;
}

#ifdef SCI_Xgate

interrupt void SCI0_ISR_X(){ // for communication test

if(SCI0SR1_RDRF==1){  //接受数据寄存器满标志位
  rcvdata0 = SCI0DRL;
  if(rcvendflag0==0){
      if(rcvdata0==0x80){ //握手信号
        
      } else if(rcvdata0==0x81){ //红外检测命令
      
         StartIarCheckflag=1;             ///启动红外检测                        
         
      }else if(rcvdata0==0x82){  //压力检测命令
        
      }
    }
  }        

}

interrupt void SCI1_ISR_X(){  // for main communication     

if(SCI1SR1_RDRF==1){
}
}

interrupt void SCI3_ISR_X(){  // for main communication     

if(SCI3SR1_RDRF==1){
}
}

interrupt void SCI4_ISR_X(){  // no use  
  if(SCI4SR1_RDRF==1){
    }                                    
}

#endif  
#pragma CONST_SEG XGATE_VECTORS  /* assign the vector table in separate segment for dedicated placement in linker parameter file */

const XGATE_TableEntry XGATE_VectorTable[] = {
                         // Channel # = Vector address / 2
  /* channel 0..8 are not used, first used must match macro XGATE_VECTOR_OFFSET in xgate.h */
  {ErrorHandler, 0x09},  // Channel 09 - Reserved
  {ErrorHandler, 0x0A},  // Channel 0A - Reserved
  {ErrorHandler, 0x0B},  // Channel 0B - Reserved
  {ErrorHandler, 0x0C},  // Channel 0C - Reserved
  {ErrorHandler, 0x0D},  // Channel 0D - Reserved
  {ErrorHandler, 0x0E},  // Channel 0E - Reserved
  {ErrorHandler, 0x0F},  // Channel 0F - Reserved
  {ErrorHandler, 0x10},  // Channel 10 - Reserved
  {ErrorHandler, 0x11},  // Channel 11 - Reserved
  {ErrorHandler, 0x12},  // Channel 12 - Reserved
  {ErrorHandler, 0x13},  // Channel 13 - Reserved
  {ErrorHandler, 0x14},  // Channel 14 - Reserved
  {ErrorHandler, 0x15},  // Channel 15 - Reserved
  {ErrorHandler, 0x16},  // Channel 16 - Reserved
  {ErrorHandler, 0x17},  // Channel 17 - Reserved
  {ErrorHandler, 0x18},  // Channel 18 - Reserved
  {ErrorHandler, 0x19},  // Channel 19 - Reserved
  {ErrorHandler, 0x1A},  // Channel 1A - Reserved
  {ErrorHandler, 0x1B},  // Channel 1B - Reserved
  {ErrorHandler, 0x1C},  // Channel 1C - Reserved
  {ErrorHandler, 0x1D},  // Channel 1D - Reserved
  {ErrorHandler, 0x1E},  // Channel 1E - Reserved
  {ErrorHandler, 0x1F},  // Channel 1F - Reserved
  {ErrorHandler, 0x20},  // Channel 20 - Reserved
  {ErrorHandler, 0x21},  // Channel 21 - Reserved
  {ErrorHandler, 0x22},  // Channel 22 - Reserved
  {ErrorHandler, 0x23},  // Channel 23 - Reserved
  {ErrorHandler, 0x24},  // Channel 24 - Reserved
  {ErrorHandler, 0x25},  // Channel 25 - Reserved
  {ErrorHandler, 0x26},  // Channel 26 - Reserved
  {ErrorHandler, 0x27},  // Channel 27 - Reserved
  {ErrorHandler, 0x28},  // Channel 28 - Reserved
  {ErrorHandler, 0x29},  // Channel 29 - Reserved
  {ErrorHandler, 0x2A},  // Channel 2A - Reserved
  {ErrorHandler, 0x2B},  // Channel 2B - Reserved
  {ErrorHandler, 0x2C},  // Channel 2C - Reserved
  {ErrorHandler, 0x2D},  // Channel 2D - Reserved
  {ErrorHandler, 0x2E},  // Channel 2E - Reserved
  {ErrorHandler, 0x2F},  // Channel 2F - Reserved
  {ErrorHandler, 0x30},  // Channel 30 - XSRAM20K Access Violation
  {ErrorHandler, 0x31},  // Channel 31 - XGATE Software Error Interrupt     
  {ErrorHandler, 0x32},  // Channel 32 - XGATE Software Trigger 7           
  {ErrorHandler, 0x33},  // Channel 33 - XGATE Software Trigger 6           
  {ErrorHandler, 0x34},  // Channel 34 - XGATE Software Trigger 5           
  {ErrorHandler, 0x35},  // Channel 35 - XGATE Software Trigger 4           
  {ErrorHandler, 0x36},  // Channel 36 - XGATE Software Trigger 3           
  {ErrorHandler, 0x37},  // Channel 37 - XGATE Software Trigger 2           
  {ErrorHandler, 0x38},  // Channel 38 - XGATE Software Trigger 1           
  {(XGATE_Function)SoftwareTrigger0_Handler, (int)&MyData},  // Channel 39 - XGATE Software Trigger 0      
  {ErrorHandler, 0x3A},  // Channel 3A - Periodic Interrupt Timer
  //{(XGATE_Function)PIT_ISR, 0x3A},  // Channel 3A - Periodic Interrupt Timer
  {ErrorHandler, 0x3B},  // Channel 3B - Periodic Interrupt Timer           
  {ErrorHandler, 0x3C},  // Channel 3C - Periodic Interrupt Timer           
  {ErrorHandler, 0x3D},  // Channel 3D - Periodic Interrupt Timer           
  {ErrorHandler, 0x3E},  // Channel 3E - Reserved                           
  {ErrorHandler, 0x3F},  // Channel 3F - Autonomous Periodical interrupt API
  {ErrorHandler, 0x40},  // Channel 40 - Low Voltage interrupt LVI
  {ErrorHandler, 0x41},  // Channel 41 - IIC1 Bus                 
  {ErrorHandler, 0x42},  // Channel 42 - SCI5                     
  //{ErrorHandler, 0x43},  // Channel 43 - SCI4                     
  //{ErrorHandler, 0x44},  // Channel 44 - SCI3   
  {(XGATE_Function)SCI4_ISR_X,0x43},  // Channel 43 - SCI4                     
  {(XGATE_Function)SCI3_ISR_X,0x44},  // Channel 44 - SCI3                  
  {ErrorHandler, 0x45},  // Channel 45 - SCI2                     
  {ErrorHandler, 0x46},  // Channel 46 - PWM Emergency Shutdown   
  {ErrorHandler, 0x47},  // Channel 47 - Port P Interrupt         
  {ErrorHandler, 0x48},  // Channel 48 - CAN4 transmit            
  {ErrorHandler, 0x49},  // Channel 49 - CAN4 receive            
  {ErrorHandler, 0x4A},  // Channel 4A - CAN4 errors              
  {ErrorHandler, 0x4B},  // Channel 4B - CAN4 wake-up            
  {ErrorHandler, 0x4C},  // Channel 4C - CAN3 transmit            
  {ErrorHandler, 0x4D},  // Channel 4D - CAN3 receive            
  {ErrorHandler, 0x4E},  // Channel 4E - CAN3 errors              
  {ErrorHandler, 0x4F},  // Channel 4F - CAN3 wake-up            
  {ErrorHandler, 0x50},  // Channel 50 - CAN2 transmit
  {ErrorHandler, 0x51},  // Channel 51 - CAN2 receive
  {ErrorHandler, 0x52},  // Channel 52 - CAN2 errors  
  {ErrorHandler, 0x53},  // Channel 53 - CAN2 wake-up
  {ErrorHandler, 0x54},  // Channel 54 - CAN1 transmit
  {ErrorHandler, 0x55},  // Channel 55 - CAN1 receive
  {ErrorHandler, 0x56},  // Channel 56 - CAN1 errors  
  {ErrorHandler, 0x57},  // Channel 57 - CAN1 wake-up
  {ErrorHandler, 0x58},  // Channel 58 - CAN0 transmit
  {ErrorHandler, 0x59},  // Channel 59 - CAN0 receive
  {ErrorHandler, 0x5A},  // Channel 5A - CAN0 errors  
  {ErrorHandler, 0x5B},  // Channel 5B - CAN0 wake-up
  {ErrorHandler, 0x5C},  // Channel 5C - FLASH
  {ErrorHandler, 0x5D},  // Channel 5D - EEPROM
  {ErrorHandler, 0x5E},  // Channel 5E - SPI2  
  {ErrorHandler, 0x5F},  // Channel 5F - SPI1
  {ErrorHandler, 0x60},  // Channel 60 - IIC0 Bus                        
  {ErrorHandler, 0x61},  // Channel 61 - Reserved                        
  {ErrorHandler, 0x62},  // Channel 62 - CRG Self Clock Mode              
  {ErrorHandler, 0x63},  // Channel 63 - CRG PLL lock                     
  {ErrorHandler, 0x64},  // Channel 64 - Pulse Accumulator B Overflow     
  {ErrorHandler, 0x65},  // Channel 65 - Modulus Down Counter underflow   
  {ErrorHandler, 0x66},  // Channel 66 - Port H                           
  {ErrorHandler, 0x67},  // Channel 67 - Port J                           
  {ErrorHandler, 0x68},  // Channel 68 - ATD1                             
  {ErrorHandler, 0x69},  // Channel 69 - ATD0                             
//  {ErrorHandler, 0x6A},  // Channel 6A - SCI1                             
// {ErrorHandler, 0x6B},  // Channel 6B - SCI0   
  {(XGATE_Function)SCI1_ISR_X,0x6A},  // Channel 6A - SCI1
  {(XGATE_Function)SCI0_ISR_X,0x6B},  // Channel 6B - SCI0                              
  {ErrorHandler, 0x6C},  // Channel 6C - SPI0                             
  {ErrorHandler, 0x6D},  // Channel 6D - Pulse accumulator input edge     
  {ErrorHandler, 0x6E},  // Channel 6E - Pulse accumulator A overflow     
  {ErrorHandler, 0x6F},  // Channel 6F - Enhanced Capture Timer overflow  
  {ErrorHandler, 0x70},  // Channel 70 - Enhanced Capture Timer channel 7                                 
  {ErrorHandler, 0x71},  // Channel 71 - Enhanced Capture Timer channel 6
  {ErrorHandler, 0x72},  // Channel 72 - Enhanced Capture Timer channel 5
  {ErrorHandler, 0x73},  // Channel 73 - Enhanced Capture Timer channel 4
  {ErrorHandler, 0x74},  // Channel 74 - Enhanced Capture Timer channel 3
  {ErrorHandler, 0x75},  // Channel 75 - Enhanced Capture Timer channel 2
  {ErrorHandler, 0x76},  // Channel 76 - Enhanced Capture Timer channel 1
  {ErrorHandler, 0x77},  // Channel 77 - Enhanced Capture Timer channel 0
  {ErrorHandler, 0x78},  // Channel 78 - Real Time Interrupt
  {ErrorHandler, 0x79},  // Channel 79 - IRQ
};


我知道答案 目前已有0人回答
回复

使用道具 举报

您需要登录后才可以回帖 注册/登录

本版积分规则

关闭

站长推荐上一条 /3 下一条

Archiver|手机版|小黑屋|恩智浦技术社区

GMT+8, 2025-7-20 08:39 , Processed in 0.083384 second(s), 21 queries , MemCache On.

Powered by Discuz! X3.4

Copyright © 2001-2024, Tencent Cloud.

快速回复 返回顶部 返回列表