uart 通过 io 口中断和 timer 读取: 读取到下降沿中断,然后定时半个周期去读取一次数据(9600: 52)
#if ET_TYPEC_EARPGONE_UI
//AT(.com_text.kkk)
//const char str_kk[]="isr:%x-\n";
//AT(.com_text.kkk)
//const char str_kk22[]="bit:%x-\n";
//AT(.com_text.kkk)
//const char str_kk11[]="r\n";
//AT(.com_text.kkk)
//const char str_kk333[]="1\n";
//AT(.com_text.kkk)
//const char str_kk444[]="0\n";
u8 timerCnt=0;
u32 receivData=0;
u8 readCnt=0;
u8 readDataBuf[4]={0,0,0,0};
u8 curReceiveDataCnt=0;
u8 printfFlag=0;
#define EDGE_INT_PORT (IO_PA6 - 1)
AT(.com_text.isr) FIQ
void timer2_ex_isr(void)
{
if (TMR3CON & BIT(16))//(TMR2CON & BIT(16))
{
TMR3CPND = BIT(16);//TMR2CPND = BIT(16);
if(timerCnt<20)//(timerCnt++%2 == 1)
{
#if 1
if(timerCnt%2==0)
{
if(GPIOA & BIT(6))
{
//receivData|=BIT(8);
receivData|=BIT(timerCnt/2);
}
//receivData = receivData>>1;
readCnt++;
}
#else
if(1)//((timerCnt+1)%2==1)
{
if(GPIOA & BIT(6))
{
//receivData|=BIT(0);
receivData|=BIT(timerCnt);
}
//receivData = receivData<<1;
readCnt++;
}
#endif
timerCnt++;
if(timerCnt==19)
{
//printf(str_kk,(receivData>>1) & 0xFF);
readCnt=0;
timerCnt=0;
receivData=(receivData>>1) & 0xFF;
TMR3CON &= ~BIT(0); //timer disable;
PORTINTEDG |= BIT(EDGE_INT_PORT);//下降沿触发
#if 1
if(curReceiveDataCnt<4)
readDataBuf[curReceiveDataCnt++]=receivData;
receivData=0;
if(curReceiveDataCnt >=4 )
{
printfFlag=1;
curReceiveDataCnt=0;
msg_enqueue(EVT_ASR_HANDLE);
}
#endif
}
}
#if 0
if(GPIOA & BIT(6)){
printf(str_kk333);
kk=1;
//GPIOBSET = BIT(2);
}else{
printf(str_kk444);
kk=0;
//GPIOBCLR = BIT(2);
}
#endif
}
}
AT(.com_text.spi1_cs) FIQ
void cs_edge_isr(void)
{
if(WKUPEDG & BIT(22))//fall
{
WKUPCPND = BIT(22);
//printf(str_kk11);
TMR3CON |= BIT(0);
PORTINTEDG &= ~BIT(EDGE_INT_PORT);
//GPIOBCLR = BIT(2);
}
}
void timer2_init_ex(void)
{
printf("timer3_init_ex\n");
#if 1
TMR3CON = BIT(7); //Timer overflow interrupt enable
TMR3CNT = 0;
TMR3PR = 52 - 1; //500ms, select xosc26_div 1M clk
//TMR3CON |= BIT(2) | BIT(0); //Timer works in Counter Mode
TMR3CON |= BIT(2);
sys_irq_init(IRQ_TMR3_VECTOR, 1, timer2_ex_isr);
//---
GPIOAFEN &= ~BIT(6);//set PB6 to GPIO
GPIOADE |= BIT(6);//set PB6 to digital IO
GPIOADIR |= BIT(6);//set PB6 to input
PORTINTEDG |= BIT(EDGE_INT_PORT);//下降沿触发
PORTINTEN |= BIT(EDGE_INT_PORT);//interrupt enable
WKUPCPND = (BIT(22) | BIT(23));//clear pending
WKUPEDG |= BIT(6);//ports falling edge
WKUPCON |= BIT(6) | BIT(16);//wakeup 6and7 enable, interrupt enable
sys_irq_init(IRQ_PORT_VECTOR, 1, cs_edge_isr);
#else
sys_irq_init(IRQ_TMR2_VECTOR, 0, timer2_ex_isr);
TMR2CNT = 0;
TMR2PR = 52 - 1; //110ms Timer overflow interrupt
TMR2CON = BIT(8) | BIT(7) | BIT(5) | BIT(2) | BIT(1) | BIT(0); //capture & overflow interrupt enable, falling edge, Capture Mode
#endif
//GPIOBFEN &= ~BIT(2);
//GPIOBDE |= BIT(2);
//GPIOBDIR &= ~BIT(2);
//GPIOBSET = BIT(2);
}
#endif