This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

C6748 UART 服务函数中 中断源ID为0问题



系统中存在3个中断服务函数,其中UART 中断配置为self,优先级为12;还有GPIO中断优先级为8,配置为ALL;

在中断服务函数中:以中断方式接受数据,可以正常接受数据;以非中断、阻塞的方式发送数据;

为什么会在中断里面  u32int_id = UARTIntStatus(SOC_UART_1_REGS);的数值会出现  0 的情况呢?????

中断处理代码为:

void UARTISR ()

{

    GR_U32 u32int_id = 0;

    GR_U32 u32fifo_status = 0;

   

    // 确定中断源

    u32int_id = UARTIntStatus(SOC_UART_1_REGS);

    // 发送中断

    if (UART_INTID_TX_EMPTY == u32int_id)

    {

        if (DalUartSendBusy(UART1))

        {

        }

    }

     // 接收中断

    else if (UART_INTID_RX_DATA == u32int_id)

    {

    }

   else

{

//  

}

Printf(":%d:\r\n",u32int_id);

}

  • 在任务中,发送数据前,置位标志位1,填好第一包使能发送中断,后续发送在中断中处理,中断发送结束后,置位标志位为0,并关闭发送中断;

    在中断中接受数据,接受完一帧数据后,发送给任务处理;

    在发送数据的同时,下发数据,会出现不进入中断的情况:

    任务实现代码如下:

    while (tUart1Buf.s32SendStatus)

        {

            DalOsTaskSleep(1);

        }

        if (u16DataLen > 0)

        {

            tUart1Buf.s32SendStatus = 1;

            tUart1Buf.u32SendBufLen = u16DataLen;

            tUart1Buf.u32SendBufPos = 0;

            memcpy(tUart1Buf.u8SendBuf,pu8Data,u16DataLen);

            //tUart1Buf.s32SendStatus = 1;

            UARTIntDisable(SOC_UART_1_REGS, UART_INT_TX_EMPTY);

            if (DalUartSendBusy(UART1))

            {

            u16Count = 0;

                while ((tUart1Buf.u32SendBufPos < tUart1Buf.u32SendBufLen) && (u16Count < 16))

                {

                    HWREG(SOC_UART_1_REGS + UART_THR) = tUart1Buf.u8SendBuf[tUart1Buf.u32SendBufPos];

                    tUart1Buf.u32SendBufPos++;

                    u16Count++;

                }

            }

            UARTIntEnable(SOC_UART_1_REGS, UART_INT_TX_EMPTY);

        }

        while (tUart1Buf.s32SendStatus)

        {

            DalOsTaskSleep(1);

        }    

    中断处理代码为:

    void UARTISR ()

    {

        GR_U32 u32int_id = 0;

        GR_U32 u32fifo_status = 0;

        GR_U8 u8CharData = 0;//收到的1字节数据

        GR_U32 u32SerialData= 0;

        GR_U16 u16Class = 0,u16Type = 0;

        GR_U16 u16PutCharCount = 0, u32Temp;

       

        // 确定中断源

        u32int_id = UARTIntStatus(SOC_UART_1_REGS);

        //IntEventClear(SYS_INT_UART1_INT);

       

        // 发送中断

        if (UART_INTID_TX_EMPTY == u32int_id)

        {

            if (DalUartSendBusy(UART1))

            {

                while ((tUart1Buf.u32SendBufPos < tUart1Buf.u32SendBufLen) && (u16PutCharCount < 16))

                {

                    HWREG(SOC_UART_1_REGS + UART_THR) = tUart1Buf.u8SendBuf[tUart1Buf.u32SendBufPos];

                    tUart1Buf.u32SendBufPos++;

                    u16PutCharCount++;

                }

                /*

                if (tUart1Buf.u32SendBufPos == tUart1Buf.u32SendBufLen)

                {

                    tUart1Buf.u32SendBufPos = 0;

                    tUart1Buf.u32SendBufLen = 0;

                    tUart1Buf.s32SendStatus = 0;

                    UARTIntDisable(SOC_UART_1_REGS, UART_INT_TX_EMPTY);

                }

                */

            }

            ///*

            if (DalUartSendBusy(UART1))

            {

                if (tUart1Buf.u32SendBufPos == tUart1Buf.u32SendBufLen)

                {

                    tUart1Buf.u32SendBufPos = 0;

                    tUart1Buf.u32SendBufLen = 0;

                    tUart1Buf.s32SendStatus = 0;

                    //UARTIntDisable(SOC_UART_1_REGS, UART_INT_TX_EMPTY);

                }

            }

            //*/

        }

     

        // 接收中断

        if (UART_INTID_RX_DATA == u32int_id)

        {

            u32fifo_status = DalUartReadBusy(UART_PORT);

            vCommPortTimersEnable();

            while (u32fifo_status)

            {

               //接收串口数据,放到全局缓冲区中

                DalUartCharGet(UART_PORT, (GR_S8 *)&u8CharData, 0);           

       //  拷贝至全局数组中

      …………………………

                u32fifo_status = DalUartReadBusy(UART_PORT);

            }

        }

     

     

        // 接收错误

        if (UART_INTID_RX_LINE_STAT == u32int_id)

        {

            GRPrintf(":%d:\r\n",u32int_id);

           

            u32Temp = UARTRxErrorGet(SOC_UART_1_REGS);

            while(u32Temp)

            {

                while(DalUartReadBusy(UART_PORT))

                {

                    // RBR 读一个字节

                    UARTCharGetNonBlocking(SOC_UART_1_REGS);

                }

                u32Temp = UARTRxErrorGet(SOC_UART_1_REGS); 

            }

        }

        else if ((UART_INTID_RX_LINE_STAT != u32int_id)

                && (UART_INTID_RX_DATA != u32int_id)

                && (UART_INTID_TX_EMPTY != u32int_id))

        {

            u32int_id = u32int_id;

            //GRPrintf(":%d:\r\n",u32int_id);

        }

    }

  • Shine Zhang 大神给个答复
  • UART不是全双工的么,可以同时收发啊