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

📄 pppasync.c

📁 用于嵌入式系统的TCP/IP协议栈
💻 C
📖 第 1 页 / 共 3 页
字号:
      ++ppp->public.ni.ipkts;      ppp->uart.rbuf->length = ppp->uart.received;      ppp->uart.rbuf->ip_data = ppp;      if (NetPostMsg(pppDataInd, ppp->uart.rbuf, ATTN_REQ))        tcpRetBuf(&ppp->uart.rbuf);#if DEBUG      printf("Normal AHDLC receive, len %u\n", ppp->uart.received);#endif      /*---------------------------------------------------------------*/      /* Return if all received data has been processed.               */      /*---------------------------------------------------------------*/      if (length == 0)      {        ppp->uart.rbuf = NULL;        return;      }      /*---------------------------------------------------------------*/      /* Return if unable to allocate another network buffer.          */      /*---------------------------------------------------------------*/      ppp->uart.rbuf = tcpGetBuf(ppp->rbuf_size);      if (ppp->uart.rbuf == NULL)      {        ++ppp->public.ni.ierrs;        vjhc_toss(&ppp->comp);        ppp->uart.hunt = TRUE;        return;      }      /*---------------------------------------------------------------*/      /* Reset buffer variables to start next frame.                   */      /*---------------------------------------------------------------*/reset_buffer:      ppp->uart.rx_dst = ppp->uart.rbuf->ip_pkt;      ppp->uart.received = 0;      ppp->uart.escaped = FALSE;      ppp->uart.rx_crc = CRC16_START;    }  }}/***********************************************************************//* uartDataReq: Called by serial driver to get data to transmit        *//*                                                                     *//*      Inputs: handle = pointer to PPP control block                  *//*              dst = pointer to driver's transmit buffer              *//*              space = amount of room left in transmit buffer         *//*              increment = amount to add to dst after each char       *//*                                                                     *//*     Returns: Number of characters placed in transmit buffer         *//*                                                                     *//***********************************************************************/int uartDataReq(void *handle, ui8 *dst, int space, int increment){  PPP ppp = handle;  NetBuf *buf;  ui8 *src, ch;  int length, initial_space = space;#if OS_FATAL_CHECK  /*-------------------------------------------------------------------*/  /* Verify PPP identifier.                                            */  /*-------------------------------------------------------------------*/  if (ppp < &Ppps[0] || ppp > &Ppps[MAX_PPP_INTF - 1] || !ppp->rbuf_size)    SysFatalError(EFAULT);#endif  /*-------------------------------------------------------------------*/  /* Set idle flag and return zero if outbound buffer queue is empty.  */  /*-------------------------------------------------------------------*/  if ((ppp->uart.tx_head == NULL) || (space == 0))  {    ppp->uart.idle = TRUE;    return 0;  }  /*-------------------------------------------------------------------*/  /* Initialize indices from current buffer.                           */  /*-------------------------------------------------------------------*/  src = ppp->uart.tx_head->ip_pkt;  length = ppp->uart.tx_head->length;  /*-------------------------------------------------------------------*/  /* Loop until out of buffer space or packet data.                    */  /*-------------------------------------------------------------------*/  for (;;)  {    /*-----------------------------------------------------------------*/    /* Check if there is a flag or escaped character to send.          */    /*-----------------------------------------------------------------*/    if (ppp->uart.next_char)    {      ch = ppp->uart.next_char;      ppp->uart.next_char = 0;    }    /*-----------------------------------------------------------------*/    /* Else process next data or CRC character.                        */    /*-----------------------------------------------------------------*/    else    {      /*---------------------------------------------------------------*/      /* Predecrement to track progress in transmitting data, CRC, and */      /* ending flag. Done now because two options below "continue".   */      /*---------------------------------------------------------------*/      --length;      /*---------------------------------------------------------------*/      /* Check if there is another data character to process.          */      /*---------------------------------------------------------------*/      if (length >= 0)      {        /*-------------------------------------------------------------*/        /* Read next character and update CRC.                         */        /*-------------------------------------------------------------*/        ch = *src++;        ppp->uart.tx_crc = pppfcs(ppp->uart.tx_crc, ch);        /*-------------------------------------------------------------*/        /* If this region empty, check for another region to process.  */        /*-------------------------------------------------------------*/        if (length == 0)        {          if (ppp->uart.tx_head->app_len)          {            length = ppp->uart.tx_head->app_len;            ppp->uart.tx_head->app_len = 0;            src = ppp->uart.tx_head->app_data;          }          else if (ppp->uart.tx_head->app_len2)          {            length = ppp->uart.tx_head->app_len2;            ppp->uart.tx_head->app_len2 = 0;            src = ppp->uart.tx_head->app_data2;          }        }      }      /*---------------------------------------------------------------*/      /* Else invert CRC and prepare to output first CRC character.    */      /*---------------------------------------------------------------*/      else if (length == -1)      {        ppp->uart.tx_crc = ~ppp->uart.tx_crc;        ch = (ui8)ppp->uart.tx_crc;      }      /*---------------------------------------------------------------*/      /* Else prepare second CRC output character and then reset CRC.  */      /*---------------------------------------------------------------*/      else if (length == -2)      {        ch = (ui8)(ppp->uart.tx_crc >> 8);        ppp->uart.tx_crc = CRC16_START;      }      /*---------------------------------------------------------------*/      /* Else prepare closing flag to frame packet.                    */      /*---------------------------------------------------------------*/      else if (length == -3)      {        ppp->uart.next_char = PPP_FLAG;        continue;      }      /*---------------------------------------------------------------*/      /* Else completely finished outputting previous packet.          */      /*---------------------------------------------------------------*/      else if (length == -4)      {        /*-------------------------------------------------------------*/        /* Return transmitted packet to TargetTCP.                     */        /*-------------------------------------------------------------*/        buf = ppp->uart.tx_head;        ppp->uart.tx_head = ppp->uart.tx_head->next;        tcpRetBuf(&buf);        ++ppp->public.ni.opkts;        /*-------------------------------------------------------------*/        /* If transmit buffer queue is empty, break.                   */        /*-------------------------------------------------------------*/        if (ppp->uart.tx_head == NULL)        {          /*-----------------------------------------------------------*/          /* Set idle flag if breaking before anything sent to UART.   */          /*-----------------------------------------------------------*/          if (initial_space == space)            ppp->uart.idle = TRUE;          break;        }        /*-------------------------------------------------------------*/        /* Else initialize indices for next buffer and continue.       */        /*-------------------------------------------------------------*/        else        {          src = ppp->uart.tx_head->ip_pkt;          length = ppp->uart.tx_head->length;          continue;        }      }      /*---------------------------------------------------------------*/      /* Escape the characters that need it.                           */      /*---------------------------------------------------------------*/      if (((ch < SP_CHAR) && (ppp->uart.tx_head->type == kLCP)) ||          (ppp->tx_accm[ch >> 5] & (1 << (ch & 0x1F))))      {        ppp->uart.next_char = ch ^ PPP_ESCAPE_BIT;        ch = PPP_ESCAPE;      }    }    /*-----------------------------------------------------------------*/    /* Write character to transmitter and update pointer.              */    /*-----------------------------------------------------------------*/    *dst = ch;    dst += increment;    /*-----------------------------------------------------------------*/    /* If out of space, must break.                                    */    /*-----------------------------------------------------------------*/    if (--space == 0)    {      /*---------------------------------------------------------------*/      /* If buffer hasn't been released, save src and length values.   */      /*---------------------------------------------------------------*/      if (ppp->uart.tx_head)      {        ppp->uart.tx_head->ip_pkt = src;        ppp->uart.tx_head->length = length;      }      break;    }  }  /*-------------------------------------------------------------------*/  /* Return the number of characters transferred to UART.              */  /*-------------------------------------------------------------------*/  return initial_space - space;}/***********************************************************************//*    pppAlloc: Allocate a PPP control block                           *//*                                                                     *//***********************************************************************/void *pppAlloc(void){  int i;  PPP ppp;#if OS_FATAL_CHECK  /*-------------------------------------------------------------------*/  /* Verify protocol has been initialized.                             */  /*-------------------------------------------------------------------*/  if (!Net.Initialized)    SysFatalError(ENETDOWN);#endif  /*-------------------------------------------------------------------*/  /* Acquire exclusive access to TargetTCP internals.                  */  /*-------------------------------------------------------------------*/  semPend(Net.IntSem, WAIT_FOREVER);  /*-------------------------------------------------------------------*/  /* Look for free PPP control block.                                  */  /*-------------------------------------------------------------------*/  for (i = 0;; ++i, ++PppIndex)  {    /*-----------------------------------------------------------------*/    /* Keep static index within bounds.                                */    /*-----------------------------------------------------------------*/    if (PppIndex > MAX_PPP_INTF - 1)      PppIndex = 0;    /*-----------------------------------------------------------------*/    /* Break if control block is free.                                 */    /*-----------------------------------------------------------------*/    if (Ppps[PppIndex].rbuf_size == 0)      break;    /*-----------------------------------------------------------------*/    /* If none are free, return error.                                 */    /*-----------------------------------------------------------------*/    if (i == MAX_PPP_INTF - 1)    {      semPost(Net.IntSem);      NetError(NULL, EMFILE);      return NULL;

⌨️ 快捷键说明

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