JN5168 UART vAHI_Uart0RegisterCallback() Using

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

JN5168 UART vAHI_Uart0RegisterCallback() Using

2,627 Views
jiweigao
Contributor III
I added UART0 operations in JN-AN-1229-ZBPro-Application-Template-v1002, but UART0 is always unable to receive data, only send data, the callback function does not seem to work, I do not know where to set the wrong, how to set up to enter the callback function to process the receiving data, thank you!
PUBLIC void UART_vInit(void)
{
    /* Enable UART 0 */
    vAHI_UartEnable(UART);
    vAHI_UartReset(UART, TRUE, TRUE);
    vAHI_UartReset(UART, FALSE, FALSE);
    /* Set the clock divisor register to give required buad, this has to be done
       directly as the normal routines (in ROM) do not support all baud rates */
    UART_vSetBaudRate(UART_BAUD_RATE);
    vAHI_UartSetRTSCTS(UART, TRUE);
    vAHI_UartSetControl(UART, FALSE, FALSE, E_AHI_UART_WORD_LEN_8, TRUE, FALSE); /* [I SP001222_P1 279] */
    vAHI_UartSetInterrupt(UART, FALSE, FALSE, FALSE, TRUE, E_AHI_UART_FIFO_LEVEL_1);    // No TX ints!
    vAHI_Uart0RegisterCallback(APP_isrUart);
}
PUBLIC void APP_isrUart(uint32 u32Device, uint32 u32ItemBitmap)
{
 DBG_vPrintf(TRACE_UART, "isrUart\n");
 unsigned int irq = ((*((volatile uint32 *)(UART_START_ADR + 0x08))) >> 1) & 0x0007;
    uint8 u8Byte;
    if (irq & E_AHI_UART_INT_RXDATA) {
        uint8 u8Byte = u8AHI_UartReadData(UART);
        if(ZQ_bQueueSend(&APP_msgSerialRx, &u8Byte) == FALSE)
        {
            /* Failed to send the message to queue */
        }
    }
    if (irq & E_AHI_UART_INT_TX) {
        if(ZQ_bQueueReceive(&APP_msgSerialTx, &u8Byte) == TRUE)
        {
            vAHI_UartWriteData(UART, u8Byte);
            /* decrement activity counter for dequeued data */
        } else {
            /* disable tx interrupt as nothing to send */
            UART_vSetTxInterrupt(FALSE);
        }
    }
}
PRIVATE void vInitialiseApp(void)
{
    /* Initialise JenOS modules. Initialise Power Manager even on non-sleeping nodes
     * as it allows the device to doze when in the idle task
     */
    PWRM_vInit(E_AHI_SLEEP_OSCON_RAMON);
    /*
     *  Initialise the PDM, use an application supplied key (g_sKey),
     *  The key value can be set to the desired value here, or the key in eFuse can be used.
     *  To use the key stored in eFuse set the pointer to the key to Null, and remove the
     *  key structure here.
     */
#ifdef PDM_EEPROM
 PDM_eInitialise(63);
 PDM_vRegisterSystemCallback(vPdmEventHandlerCallback);
#else
 PDM_vInit(7, 1, 64 * 1024 , NULL, NULL, NULL, &g_sKey);
#endif
    /* Initialise Protocol Data Unit Manager */
    PDUM_vInit();
    UART_vInit();
    /* Register callback that provides information about stack errors */
    ZPS_vExtendedStatusSetCallback(vfExtendedStatusCallBack);
    /* initialise application */
    APP_vInitResources();
    APP_vSetUpHardware();
    /* initialise application */
    APP_vInitialiseRouter();
    app_vMainloop();
}

}
Tags (1)
9 Replies

1,461 Views
jiweigao
Contributor III

Hi Mario Ignacio Castaneda Lopez :

I took a closer look at JN-AN-1069. In UART_vInterrupt, if ((u32ItemBitmap & 0xFF) == E_AHI_UART_INT_RXDATA ||(u32ItemBitmap & 0xFF) == E_AHI_UART_INT_TIMEOUT) of the parts added vAHI_UartWriteData(E_AHI_UART_0, 0xFF),But runtime Coordinator does not print out char FF,Description does not enter UART0 receive interrupt,Data processing is done through main loop medium  CRD_vMain()->CRD_vMcpsDcfmInd()->CRD_vIndData()->WUART_vRx(),is not handled by interruption. If it is handled by interrupts, you should see the print character FF.
PRIVATE void UART_vInterrupt(uint32 u32Device,uint32 u32ItemBitmap)
{
 uint8 u8ModemStatus;
 uint8 u8RxChar;
 uint8 u8Uart = 0xFF;
 uint8 u8Data;
 bool_t bAdd;
 /* Which uart ? */
 if (u32Device == E_AHI_DEVICE_UART0) u8Uart = E_AHI_UART_0;
 if (u32Device == E_AHI_DEVICE_UART1) u8Uart = E_AHI_UART_1;
 /* Interrupt is for a valid uart and it is open? */
    if (u8Uart < 2 && asUart[u8Uart].bOpened)
    {
        /* Ready to transmit ? */
        if ((u32ItemBitmap & 0xFF) == E_AHI_UART_INT_TX)
        {
   /* We will service this interrupt but might generate another */
   asUart[u8Uart].bTxInt = FALSE;
        }
  /* Modem status changed ? */
  if ((u32ItemBitmap & 0xFF) == E_AHI_UART_INT_MODEM)
  {
   /* Read modem status */
   u8ModemStatus = u8AHI_UartReadModemStatus(u8Uart);
   /* Has CTS changed ? */
   if (u8ModemStatus & E_AHI_UART_MS_DCTS)
   {
    /* Controlling flow from application using CTS ? */
    if (asUart[u8Uart].bRtsCts == TRUE)
    {
     /* Note current CTS setting (CTS bit set means CTS has cleared) */
     asUart[u8Uart].bCts = (u8ModemStatus & 0x10) ? FALSE : TRUE;
     /* Enabling transmit ? */
     if (asUart[u8Uart].bCts)
     {
      UART_bTxEnable(u8Uart, UART_ABLE_UARTIO);
     }
     /* Disabling transmit ? */
     else
     {
      UART_bTxDisable(u8Uart, UART_ABLE_UARTIO);
     }
    }
   }
  }
     /* Data to receive ? */
        if ((u32ItemBitmap & 0xFF) == E_AHI_UART_INT_RXDATA ||
         (u32ItemBitmap & 0xFF) == E_AHI_UART_INT_TIMEOUT)
        {
         vAHI_UartWriteData(E_AHI_UART_0, 0xFF);
         vAHI_UartWriteData(E_AHI_UART_0, 0xFF);
         vAHI_UartWriteData(E_AHI_UART_0, 0xFF);
         /* While there is data in the receive fifo */
   while (u8AHI_UartReadLineStatus(u8Uart) & E_AHI_UART_LS_DR)
   {
    /* Receive character from UART */
    u8RxChar = u8AHI_UartReadData(u8Uart);
    /* Using XON/XOFF flow control and this is an XON/XOFF character ? */
    if (asUart[u8Uart].bXonXoff == TRUE &&
       (u8RxChar == CHAR_XON || u8RxChar == CHAR_XOFF))
    {
     /* Enabling transmit ? */
     if (u8RxChar == CHAR_XON)
     {
      UART_bTxEnable(u8Uart, UART_ABLE_UARTIO);
     }
     /* Disabling transmit ? */
     else
     {
      UART_bTxDisable(u8Uart, UART_ABLE_UARTIO);
     }
    }
    else
    {
     /* Stats ? */
     #if UART_STATS
     {
      /* Increment received character counter */
      asUart[u8Uart].u32Rxed++;
     }
     #endif
     /* Add character to receive queue */
     bAdd = QUEUE_bPut(asUart[u8Uart].psRxQueue, u8RxChar);
     /* Added ? */
     if (bAdd)
     {
      /* Reached a low amount of free space ? */
      if (QUEUE_bLowReached(asUart[u8Uart].psRxQueue))
      {
       /* Disable receive there is now room in the queue */
       UART_bRxDisable(u8Uart, UART_ABLE_UARTIO);
      }
     }
    }
   }
        }
        /* Ready to transmit ? */
        if ((u32ItemBitmap & 0xFF) == E_AHI_UART_INT_TX)
        {
   /* Did we not service the last tx interrupt ? */
   if (asUart[u8Uart].bTxInt == FALSE)
   {
    /* Allowed to transmit ? */
    if(asUart[u8Uart].u8TxDisable == 0)
    {
     /* Got some data in the queue ? */
     if(! QUEUE_bEmpty_Int(asUart[u8Uart].psTxQueue))
     //if(asUart[u8Uart].psTxQueue->u16Tail != asUart[u8Uart].psTxQueue->u16Head)
     {
      uint8 u8Write;
      bool_t bGet = TRUE;
      /* Write up to 16 bytes of data to fifo */
      for (u8Write = 0;
        u8Write < 16 && bGet == TRUE;
        u8Write++)
      {
       /* Attempt to get byte from queue */
       bGet = QUEUE_bGet(asUart[u8Uart].psTxQueue, &u8Data);
       /* Got a byte ? */
       if (bGet == TRUE)
       {
        /* Output to UART */
        vAHI_UartWriteData(u8Uart, u8Data);
        /* Note we serviced the interrupt, tx interrupts will continue */
        asUart[u8Uart].bTxInt = TRUE;
        /* Stats ? */
        #if UART_STATS
        {
         /* Increment transmitted character counter */
         asUart[u8Uart].u32Txed++;
        }
        #endif
       }
      }
     }
    }
   }
        }
    }
}
0 Kudos

1,461 Views
mario_castaneda
NXP TechSupport
NXP TechSupport

Hi JiWei Gao,

This is my UART interrupt configuration.

/* Set UART interrupts */
vAHI_UartSetInterrupt(u8Uart,
            asUart[u8Uart].bRtsCts,      /* ModemStatus */
            TRUE,                    /* RxLineStatus */
            TRUE,                    /* TxFifoEmpty */
            TRUE,                       /* RxData */
            E_AHI_UART_FIFO_LEVEL_1);‍‍‍‍‍‍‍

Could you please try with another value? a Printable character.

vAHI_UartWriteData(E_AHI_UART_0, 0x31);

Let me know your findings.

Best Regards,

Mario

0 Kudos

1,461 Views
lucasip
Contributor I

Hi Mario,

I have the same problem as JiWei ,and I added UART0 operations in JN-AN-1189-zigbee-HA-demo

The UART interrupt (APP_myisrUart(uint32 u32Device, uint32 u32ItemBitmap)) never work,and did not print "isrUart".

How to set up to enter the callback function to process the receiving data?

My UART code as below:

PUBLIC void UART_vInit(void)
{
/* Enable UART 0 */
//vAHI_UartEnable(UART);
bAHI_UartEnable(UART, //uint8 u8Uart,
txbuf, //uint8 *pu8TxBufAd,
(uint8)16, //uint16 u16TxBufLen,
rxbuf, //uint8 *pu8RxBufAd,
(uint8)127); //uint16 u16RxBufLen);

vAHI_UartReset(UART, TRUE, TRUE);
vAHI_UartReset(UART, FALSE, FALSE);

/* Set the clock divisor register to give required buad, this has to be done
directly as the normal routines (in ROM) do not support all baud rates */
UART_vSetBaudRate(UART_BAUD_RATE);
//DBG_vPrintf(TRACE_START, "I THINK IS OK \n");
vAHI_UartSetRTSCTS(UART, TRUE);
vAHI_UartSetControl(UART, FALSE, FALSE, E_AHI_UART_WORD_LEN_8, TRUE, FALSE); /* [I SP001222_P1 279] */
vAHI_Uart0RegisterCallback(APP_myisrUart);
vAHI_UartSetInterrupt(UART, TRUE, TRUE, TRUE, TRUE, E_AHI_UART_FIFO_LEVEL_1); // No TX ints!
DBG_vPrintf(UART_STAR, "I THINK IT IS OK2 \n");


}


PUBLIC void APP_myisrUart(uint32 u32Device, uint32 u32ItemBitmap)
{
DBG_vPrintf(UART_STAR, "isrUart\n");
UART_vTxChar('\n');
UART_vTxChar('i');
UART_vTxChar('s');
UART_vTxChar('r');
UART_vTxChar('U');
UART_vTxChar('\n');
UART_vTxChar('\n');
unsigned int irq = ((*((volatile uint32 *)(UART_START_ADR + 0x08))) >> 1) & 0x0007;
// uint8 u8Byte;
if (irq & E_AHI_UART_INT_RXDATA) {
uint8 u8Byte = u8AHI_UartReadData(UART);
DBG_vPrintf(UART_STAR, "RXUart\n");
// /* if(OS_eGetMessageStatus(&APP_msgSerialRx, &u8Byte) == FALSE)
// {
// /* Failed to send the message to queue */
// }*/
}
if (irq & E_AHI_UART_INT_TX) {

//if(OS_eGetMessageStatus(&APP_msgSerialTx, &u8Byte) == TRUE)
// {
// vAHI_UartWriteData(UART, u8Byte);
/* decrement activity counter for dequeued data */
// } else {
/* disable tx interrupt as nothing to send */
// UART_vSetTxInterrupt(FALSE);
// }
}
}

Thanks 

Lucas

0 Kudos

1,461 Views
khactrung
Contributor II

Hi Lucas,

I have fixed it as follow:

- Edit file irq_JN516x.S, then add APP_isrUart  :

PIC_ChannelPriorities:
.byte 0 # pwm1 priority
.byte 0 # pwm2 priority
.byte 15 # system controller priority
.byte 7 # MAC priority
.byte 0 # AES priority
.byte 0 # PHY priority
.byte 5 # uart0 priority
.byte 0 # uart1 priority

PIC_SwVectTable:
.word vUnclaimedInterrupt # 0
.word vUnclaimedInterrupt # 1
.word vUnclaimedInterrupt # 2
.word vUnclaimedInterrupt # 3
.word vUnclaimedInterrupt # 4
.word APP_isrUart # 5
.word vUnclaimedInterrupt # 6

Regards,

Khac Trung.

1,461 Views
chengchang_tong
Contributor I

that's useful,thanks

0 Kudos

1,461 Views
文斌钟
Contributor I

That works. Thanks.

0 Kudos

1,461 Views
mario_castaneda
NXP TechSupport
NXP TechSupport

Hi Lucas,

Did you solve this issue?

Regards,

Mario

0 Kudos

1,461 Views
mario_castaneda
NXP TechSupport
NXP TechSupport

Hi JiWei,

          /* Enable UART */
          vAHI_UartEnable(u8Uart);
          /* Reset UART */
          vAHI_UartReset(u8Uart, TRUE, TRUE);
          vAHI_UartReset(u8Uart, FALSE, FALSE);
          /* Note we've opened the UART */
          asUart[u8Uart].bOpened = TRUE;
         /* Allow use of RTS/CTS pins with UART if required */
             vAHI_UartSetRTSCTS(u8Uart, asUart[u8Uart].bRtsCts);
          /* Set baud rate */
          vAHI_UartSetBaudDivisor(u8Uart, u16Divisor);
          /* Set control */
          vAHI_UartSetControl(u8Uart, bEvenParity, bEnableParity, u8WordLength, bOneStopBit, (asUart[u8Uart].u8RxDisable == 0) ? TRUE : FALSE);
          /* Using RTS/CTS flow control ? */
          if (asUart[u8Uart].bRtsCts)
          {
               /* Start with RTS on */
               UART_vRts(u8Uart, (asUart[u8Uart].u8RxDisable == 0) ? TRUE : FALSE);
               /* Is CTS bit set meaning CTS is off ? */
               if (u8AHI_UartReadModemStatus(u8Uart) & 0x10)
               {
                    /* Start with transmit disabled */
                    asUart[u8Uart].u8TxDisable |= UART_ABLE_UARTIO;
               }
          }
          /* Not JenOS ? */
          #if !UART_JENOS
          {
               /* Register callback for appropriate UART */
               if (u8Uart == E_AHI_UART_0) vAHI_Uart0RegisterCallback(UART_vInterrupt);
               if (u8Uart == E_AHI_UART_1) vAHI_Uart1RegisterCallback(UART_vInterrupt);
          }
          #endif

          /* Set UART interrupts */
          vAHI_UartSetInterrupt(u8Uart,
                                     asUart[u8Uart].bRtsCts,             /* ModemStatus */
                                     FALSE,                                /* RxLineStatus */
                                     TRUE,                                     /* TxFifoEmpty */
                                     TRUE,                                     /* RxData */
                                     E_AHI_UART_FIFO_LEVEL_14);

For a better reference please  take a look to the JN-AN-1069

For the debug purpose, please

Enable this in the makefile:

  • TRACE ?=1

Let me know your findings

Regards,

Mario

0 Kudos

1,461 Views
jiweigao
Contributor III
I tried to add the print character FF to the receive portion of the Coordianrot UART interrupt in the routine jn-an-1069, but the Coordiantor and Enddevice were able to communicate normally, but the coordiantor terminals did not see the printable FF characters , after a careful look at the routine, it is found that the data processing is handled through function calls in the main loop, and is not handled through the UART interrupt!
0 Kudos