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.

关于串口中断

Other Parts Discussed in Thread: HALCOGEN, TMS570LS0432

在TI的库里面关于TMS570LS0432的串口接收中断,在HALCOGEN的SCI/LIN Global配置接收中断,在初始化时调用sciEnableNotification(UART,  SCI_RX_INT );就行了吗?

发生接收中断时,程序调到哪里?有两个函数:第一个能够查询也能够中断接收?中断接收岂不是需要调用了?

第二个 SVE是中断标志,SVE==11是接收中断?在SVE==11下添加自己的中断函数后,当用HALCOGEN重新生成代码,岂不是要把自己的中断函数冲没了?

1

void sciReceive(sciBASE_t *sci, uint32 length, uint8 * data)
{
/* USER CODE BEGIN (17) */
/* USER CODE END */

    if ((sci->SETINT & (uint32)SCI_RX_INT) == (uint32)SCI_RX_INT)
    {
        /* we are in interrupt mode */
       
        /* clear error flags */
        sci->FLR = ((uint32) SCI_FE_INT | (uint32) SCI_OE_INT | (uint32) SCI_PE_INT);

        g_sciTransfer_t.rx_length = length;
  /*SAFETYMCUSW 45 D MR:21.1 <APPROVED> "Valid non NULL input parameters are only allowed in this driver" */
        g_sciTransfer_t.rx_data   = data;
    }
    else
    {  
     /*SAFETYMCUSW 30 S MR:12.2,12.3 <APPROVED> "Used for data count in Transmit/Receive polling and Interrupt mode" */
        while (length > 0U)
        {
         /*SAFETYMCUSW 28 D MR:NA <APPROVED> "Potentially infinite loop found - Hardware Status check for execution sequence" */
            while ((sci->FLR & (uint32)SCI_RX_INT) == 0U)
            {
            } /* Wait */
   /*SAFETYMCUSW 45 D MR:21.1 <APPROVED> "Valid non NULL input parameters are only allowed in this driver" */
            *data = (uint8)(sci->RD & 0x000000FFU);
   /*SAFETYMCUSW 45 D MR:21.1 <APPROVED> "Valid non NULL input parameters are only allowed in this driver" */
   /*SAFETYMCUSW 567 S MR:17.1,17.4 <APPROVED> "Pointer operation required." */       
            data++;
   length--;
        }
    }

 

 

2void linHighLevelInterrupt(void)
{
    uint32 vec = scilinREG->INTVECT0;
 uint8 byte;
/* USER CODE BEGIN (29) */

/* USER CODE END */

    switch (vec)
    {
    case 1U:
        sciNotification(scilinREG, (uint32)SCI_WAKE_INT);
        break;
    case 3U:
        sciNotification(scilinREG, (uint32)SCI_PE_INT);
        break;
    case 6U:
        sciNotification(scilinREG, (uint32)SCI_FE_INT);
        break;
    case 7U:
        sciNotification(scilinREG, (uint32)SCI_BREAK_INT);
        break;
    case 9U:
        sciNotification(scilinREG, (uint32)SCI_OE_INT);
        break;

    case 11U:
        /* receive */
   byte = (uint8)(scilinREG->RD & 0x000000FFU);

            if (g_sciTransfer_t.rx_length > 0U)
            {
                *g_sciTransfer_t.rx_data = byte;
                /*SAFETYMCUSW 567 S MR:17.1,17.4 <APPROVED> "Pointer increment needed" */
                g_sciTransfer_t.rx_data++;
                g_sciTransfer_t.rx_length--;
                if (g_sciTransfer_t.rx_length == 0U)
                {
                    sciNotification(scilinREG, (uint32)SCI_RX_INT);
                }
            }
        break;

    case 12U:
        /* transmit */
  /*SAFETYMCUSW 30 S MR:12.2,12.3 <APPROVED> "Used for data count in Transmit/Receive polling and Interrupt mode" */
  --g_sciTransfer_t.tx_length;
        if ((g_sciTransfer_t.tx_length) > 0U)
        {
   uint8 txdata = *g_sciTransfer_t.tx_data;
            scilinREG->TD = (uint32)(txdata);
            /*SAFETYMCUSW 567 S MR:17.1,17.4 <APPROVED> "Pointer increment needed" */
            g_sciTransfer_t.tx_data++;
        }
        else
        {
            scilinREG->CLEARINT = SCI_TX_INT;
            sciNotification(scilinREG, (uint32)SCI_TX_INT);
        }
        break;

    default:
        /* phantom interrupt, clear flags and return */
        scilinREG->FLR = ~scilinREG->SETINTLVL & 0x07000303U;
        break;
    }
/* USER CODE BEGIN (30) */

  • 你好。

    1. 配置中断,你需要在VIM Channel那些页标签中进行配置对应中断。在主程序中还需要找开全局中断。

    2. SCI的中断函数在notification.c的sciNotification函数中。判断是哪个中断向量的,在你贴出的代码中调用sciNotification里有参数传递,可以用来判断中断源。

  • 你好 谢谢回复,我找到问题了:把中断指向函数void linHighLevelInterrupt(void)中的case 11(接收中断)的所有语句都去掉,只保留中断函数sciNotification(scilinREG, (uint32)SCI_RX_INT);这样接收中断就没问题,由于case11下的程序都是HALCOGEN生成的  这样岂不是要生成一次程序就要手动屏蔽一次那些语句?

     case 11U:
            /* receive */
    //   byte = (uint8)(scilinREG->RD & 0x000000FFU);

    //            if (g_sciTransfer_t.rx_length > 0U)
    //            {
    //                *g_sciTransfer_t.rx_data = byte;
                    /*SAFETYMCUSW 567 S MR:17.1,17.4 <APPROVED> "Pointer increment needed" */
    //                g_sciTransfer_t.rx_data++;
     //               g_sciTransfer_t.rx_length--;
    //                if (g_sciTransfer_t.rx_length == 0U)
     //               {
                        sciNotification(scilinREG, (uint32)SCI_RX_INT);
     //               }
    //            }
            break;

  • Halcogen生成的代码在使用中断时,加入了一个软件的Buffer,由g_sciTransfer_t这个结构体来维护。

    g_sciTransfer_t【1】用于LINSCI模块的发送和接收Buffer。

    所以,在初始化完成后,需要初始化g_sciTransfer_t【1】的发送和接收Buffer的相关设置(字节长度和Buffer指针)。

    如果需要每接收一个字节就调用sciNotification函数,那么可以按下面进行实始化

    g_sciTransfer_t.rx_length = 1;

    g_sciTransfer_t.rx_data = (自定义的接收Buffer起始地址);

    在调的sciNotification函数中,最后再次按上面的代码进行初始化,以准备下一次接收。

    这接的话,你就可以直接使用Halcogen生成的代码了。

  • 3Q,那原本的程序是表示length个字节调用sciNotification();那这样是不是必须是LENGTH的整数倍才能保证接收中断的接收数据不丢失,否则最后一次接收不到length个字节,这样最后一次的接收始终调用不了sciNotification();????