⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 soc_eoc.c

📁 Infineon公司有一款实现SHDSL协议(ADSL协议的变种)的芯片
💻 C
📖 第 1 页 / 共 2 页
字号:
                                          working in receive direction        
                                          (the flag STATE_RX_ACTIVE          
                                          is set after the first RPF          
                                          or RME is detected).                */

                                       /* SOCRATES works not in receive           
                                          direction: received bytes           
                                          belong to a new frame.              */
   if (!(G_Eoc.State & STATE_RX_ACTIVE))
   {
                                       /* If there is something to            
                                          receive: use global buffer          */
      if (reccnt > 0)
      {
         G_Eoc.Rx_Curr = 0;
      }
      G_Eoc.State |= STATE_RX_ACTIVE;
      G_Eoc.Rx_Cnt = reccnt;
   }
                                       /* SOCRATES works already in receive       
                                          direction: received bytes           
                                          belong to an old frame.             */
   else 
   {
                                       /* This counter contains the           
                                          bytes which have been               
                                          received.                           */
      G_Eoc.Rx_Cnt += reccnt;
   }
                                       /* Read the bytes from the RFIFO       
                                          and update buffer pointer.          */
   if (reccnt)
   {
      if (G_Eoc.Rx_Curr + reccnt < EOC_RX_BUF_SIZE)
      {
         Soc_Read_Fifo(reccnt, &(G_Eoc.Rx_Buffer[G_Eoc.Rx_Curr])); 
         G_Eoc.Rx_Curr += reccnt;
      }
      else
      {
         Soc_Eoc_Reset(EOC_RX);
         V24_PRINT (("\n(SLOT %d) HDLC_E receive buffer overflow - ignoring data!", SLOT_NR));
         return;
      }
   }
                                       /* Reset RPF to confirm         
                                          that data is fetched and            
                                          RFIFO can be released.              */
   BFLD(SOCRATES_ISTA_E, SOCRATES_ISTA_E_RPF_E, 0x00);

                                       /* message not finished      */
   if (!lastblock)
      return;

                                       /* Report successful reception
                                          to the user.                        */
   Soc_Int_Fifo_Put (EOC_RX_INT, 0);
}

/*******************************************************************************
Description:
   Reports that a HDLC-EOC error has happened.
Arguments:
   reg - register content which indicated error type
Return Value:
   none
Remarks:
   none
*******************************************************************************/
void Soc_Eoc_Error_Interrupt (WORD8 reg)
{

    if (reg & (SOCRATES_ISTA_E_XDU_E | SOCRATES_ISTA_E_XDOV_E))
    {
        G_Eoc.Tx_Error = reg & (SOCRATES_ISTA_E_XDU_E | SOCRATES_ISTA_E_XDOV_E);
        Soc_Eoc_Reset (EOC_TX);
    }    

                                       /* Receive frame overflow error.        */
   if ((reg & SOCRATES_ISTA_E_RFO_E) == SOCRATES_ISTA_E_RFO_E)
   {
      Soc_Eoc_Reset (EOC_RX);
      G_Eoc.Rx_Error = SOCRATES_ISTA_E_RFO_E;
   } 

                                       /* Report indication to user.          */
   Soc_Int_Fifo_Put (EOC_ERROR_INT, 0);
}

/*******************************************************************************
Description:
   HDLC-EOC transmission finished is send to PC.
Arguments:
   none
Return Value:
   none
Remarks:
   none
*******************************************************************************/
void Soc_Eoc_Transmit_Ind (void)
{
   P_DDS_MSG pMsg;

                                       /* Send V24INT control messages  
                                          to serial interface.                */
   V24_PRINT (("\n(SLOT %d) i_Socrates_Eoc_Transmit", SLOT_NR));
   V24_PRINT ((": EOC message sent successful"));
   
                                       /* Check if message is available.       */
   if (DdsMsgGetNum () > 3)   
   {
                                       /* Send message to user.                */
      pMsg = DdsMsgAlloc(0);   
      pMsg->dst     = 0;
      pMsg->src     = MOD_ID_SOCRATES_MODULE;
      pMsg->id      = MSG_ID_SOCRATES_HDLC_E_TRANSMIT_IN;
      pMsg->length  = 0;
      DdsMsgSend (pMsg); 
   }   
   else
   {  
      V24_PRINT ((" Error allocating message"));
   }

   Soc_Reset_Transmit_Var();
}

/*******************************************************************************
Description:
   HDLC-EOC data received is send to PC. Also the last byte of the message is 
   interpreted as error indicator.
Arguments:
   none
Return Value:
   none
Remarks:
   none
*******************************************************************************/
void Soc_Eoc_Receive_Ind (void)
{
   P_DDS_MSG pMsg;
   WORD16 i;

   /* Send V24INT control messages  
   to serial interface.                */
   V24_PRINT (("\n(SLOT %d) i_Socrates_Eoc_Receive", SLOT_NR));
   V24_PRINT ((": DATA="));
   for (i = 0;i < G_Eoc.Rx_Cnt; i++)
      V24_PRINT (("0x%02X,", G_Eoc.Rx_Buffer[i]));

   /* evaluate last byte (RSTAT_E) */
   if (G_Eoc.Rx_Buffer[G_Eoc.Rx_Cnt-1] & SOCRATES_RSTAT_E_CSRF_E)
      V24_PRINT ((" Control sequence not valid!"));
   if (G_Eoc.Rx_Buffer[G_Eoc.Rx_Cnt-1] & SOCRATES_RSTAT_E_RDO_E)
      V24_PRINT ((" Receive data overflow!"));
   if (!(G_Eoc.Rx_Buffer[G_Eoc.Rx_Cnt-1] & SOCRATES_RSTAT_E_FCS_E))
      V24_PRINT ((" FCS incorrect!"));
   if (G_Eoc.Rx_Buffer[G_Eoc.Rx_Cnt-1] & SOCRATES_RSTAT_E_RAB_E)
      V24_PRINT ((" Message aborted!"));
   /* Check if message is available.       */
   if (DdsMsgGetNum () > 3)   
   {                                    /* send length, first and last eight bytes */
      if (G_Eoc.Rx_Cnt > 16)
      {
         pMsg = DdsMsgAlloc(18);   
         pMsg->length  = 18;
         MsgWriteWord16 (pMsg, 0, G_Eoc.Rx_Cnt);
         for (i = 0;i < 8; i++)
         {
            MsgWriteWord8 (pMsg, 2+i, G_Eoc.Rx_Buffer[i]);
            MsgWriteWord8 (pMsg, 2+i+8, G_Eoc.Rx_Buffer[i+G_Eoc.Rx_Cnt-8]);
         }
      }
      else
      {
         /* Send message to user.                */
         pMsg = DdsMsgAlloc(G_Eoc.Rx_Cnt+2);   
         pMsg->length  = G_Eoc.Rx_Cnt+2;
         MsgWriteWord16 (pMsg, 0, G_Eoc.Rx_Cnt);
         for (i = 0;i < G_Eoc.Rx_Cnt; i++)
            MsgWriteWord8 (pMsg, 2+i, G_Eoc.Rx_Buffer[i]);
      }
      pMsg->dst     = 0;
      pMsg->src     = MOD_ID_SOCRATES_MODULE;
      pMsg->id      = MSG_ID_SOCRATES_HDLC_E_RECEIVE_IN;
      DdsMsgSend (pMsg);
   }
   else
   {  
      V24_PRINT ((" Error allocating message"));
   }

                                          /* Reset variables for next HDLC-EOC 
                                          reception.                          */
   Soc_Reset_Receive_Var();
}

/*******************************************************************************
Description:
   HDLC-EOC error is send to PC.
Arguments:
   none
Return Value:
   none
Remarks:
   none
*******************************************************************************/
void Soc_Eoc_Error_Ind (void)
{
   P_DDS_MSG pMsg;

                                       /* Send V24INT control messages  
                                          to serial interface.                */
   V24_PRINT (("\n(SLOT %d) i_Socrates_Eoc_Error:", SLOT_NR));

   if (G_Eoc.Tx_Error & SOCRATES_ISTA_E_XDU_E)
        V24_PRINT ((" transmit data underrun!"));

   if (G_Eoc.Tx_Error & SOCRATES_ISTA_E_XDOV_E)
        V24_PRINT ((" transmit data overflow!"));

   if (G_Eoc.Rx_Error & SOCRATES_ISTA_E_RFO_E)
        V24_PRINT ((" receive frame overflow!"));

                                       /* Check if message is available.      */
   if (DdsMsgGetNum () > 3)   
   {
                                       /* Send message to user.                */
      pMsg = DdsMsgAlloc(2);   
      MsgWriteWord8 (pMsg, 0, G_Eoc.Tx_Error);
      MsgWriteWord8 (pMsg, 1, G_Eoc.Rx_Error);
      pMsg->dst     = 0;
      pMsg->src     = MOD_ID_SOCRATES_MODULE;
      pMsg->id      = MSG_ID_SOCRATES_HDLC_E_ERROR_IN;
      pMsg->length  = 2;
      DdsMsgSend (pMsg);
   }     
   else
   {  
      V24_PRINT ((" Error allocating message"));
   }
}

/* ============================= */
/* Local function definition     */
/* ============================= */

/*******************************************************************************
Description:
   Reads data bytes from the HDLC-EOC FIFO.
Arguments:
   cnt    - number of bytes to be read
   buffer - pointer to buffer for first data byte
Return Value:
   none
Remarks:
   none
*******************************************************************************/
static void Soc_Read_Fifo(WORD8 cnt, WORD8* buffer)
{
   while (cnt--)
   {
      *buffer++ = In(SOCRATES_RFIFO_E);
   }
}

/*******************************************************************************
Description:
   Fills the HDLC-EOC buffer with data bytes.
Arguments:
   cnt    - number of bytes to be written
   buffer - pointer to first data byte
Return Value:
   none
Remarks:
   none
*******************************************************************************/
static void Soc_Write_Fifo(WORD8 cnt, WORD8* buffer)
{
   while (cnt--)
   {
      Out(SOCRATES_XFIFO_E, *buffer++);
   }
}

/*******************************************************************************
Description:
   Resets all variables for HDLC-EOC receive direction.
Arguments:
   none
Return Value:
   none
Remarks:
   none
*******************************************************************************/
static void Soc_Reset_Receive_Var(void)   
{
   G_Eoc.Rx_Curr = 0;
   G_Eoc.Rx_Cnt  = 0;
   G_Eoc.State   &= ~STATE_RX_ACTIVE;
}

/*******************************************************************************
Description:
   Resets all variables for HDLC-EOC transmit direction.
Arguments:
   none
Return Value:
   none
Remarks:
   none
*******************************************************************************/
static void Soc_Reset_Transmit_Var(void)   
{
   G_Eoc.Tx_Cnt = 0;
   G_Eoc.Tx_Curr = 0;
   G_Eoc.State &= ~STATE_TX_ACTIVE;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -