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

📄 ml_buf.c

📁 是一个手机功能的模拟程序
💻 C
📖 第 1 页 / 共 2 页
字号:
|                                                                              |
|  Return       : XMK_OVERFLOW     Ringbuffer full, the new entry has over-    |
|                                  written the last one.                       |
|                 XMK_ERROR        Error, i.e.illegal length                   |
|                 XMK_OKAY         No overflow occurred.                       |
|                                                                              |
|                                                                              |
+------------------------------------------------------------------------------+
*/
/*-FHDR E*/

/*+FDEF E*/

#ifndef XNOPROTO
   /* ANSI - Style */
   int  xmk_RingWrite (xmk_T_RING xmk_RAM_ptr p_controlblock, char xmk_RAM_ptr p_entry, int xlen)

#else
   /* Kernighan-Ritchie-Style */
   int              xmk_RingWrite (p_controlblock, p_entry, xlen)
   xmk_T_RING        xmk_RAM_ptr p_controlblock;
   char              xmk_RAM_ptr p_entry;
   int               xlen;
#endif

/*-FDEF E*/
{
  int result = XMK_OKAY;
  int len;


  #ifdef XMK_USE_MAX_ERR_CHECK
    if (xlen > ENTRYSIZE)
    {
       return (XMK_ERROR);
    }
  #endif

  XMK_BEGIN_CRITICAL_PATH;

  if (COUNTER >= MAXIMUM)
  {
    /*
    ** no place to write, use the last one ...
    */
    COUNTER = MAXIMUM      ;
    result  = XMK_OVERFLOW ;
    if (XMK_CTRL == XMK_FIFO)
    {
      XMK_END_CRITICAL_PATH;

      /*
      ** no overwrite if fifo control is used ....
      */
      return (XMK_OVERFLOW);
    }
  }
  else
  {
    /*
    ** there is another place ...
    */
    COUNTER ++;
  }

  /*
  ** if writepointer points behind the ringbuffer ...
  */
  if (WRITEPTR >= (BUFFERADR + BUFFERSIZE))
  {
    WRITEPTR = BUFFERADR ;
  }

  /*
  ** 8051x compiler needs this temporary variable at this location
  */    
  len = xlen;


  /*
  ** in any case write destructive ..
  */
  COPY (WRITEPTR, p_entry, len);

  /*
  ** increment writepointer ...
  */
  INCR_WRITEPTR ;

  XMK_END_CRITICAL_PATH;

  /*
  ** return with the result ...
  */
  return (result);

} /* END OF FUNCTION */


/*+FHDR E*/
/*
+------------------------------------------------------------------------------+
|  Functionname : xmk_RingRead                                                 |
|  Author       : S&P Media GmbH Germany                                       |
+------------------------------------------------------------------------------+
|                                                                              |
|                                                                              |
|  Description  :                                                              |
|  This functions reads data from the tracebuffer. The caller receives a       |
|  pointer to the entry or a NULL pointer, if no entry was found.              |
|  XMK_OKAY      : OK, 1 entry has been read and was copied into p_dest.t      |
|  XMK_EMPTY     : OK, no entry found (buffer empty)                           |
|  XMK_ERROR     : Error, the entry, which is to be read from the buffer, is   |
|                  greater than the dimension of the destination buffer.       |
|                                                                              |
|  Parameter    : xmk_T_RING      * Pointer to tracebuffercontrolblock.        |
|                 char            * p_dest Pointer to destination, where       |
|                                   the entry is to be copied into.            |
|                                   the entry is to be copied into.            |
|                 int               destlen buffersize of destination for      |
|                                   errorcheck.                                |
|  Return       : int               XMK_OKAY |XMK_EMPTY | XMK_ERROR            |
|                                                                              |
+------------------------------------------------------------------------------+
*/
/*-FHDR E*/

/*+FDEF E*/

#ifndef XNOPROTO
   /* ANSI - Style */
   int            xmk_RingRead ( xmk_T_RING xmk_RAM_ptr p_controlblock, 
                                 char xmk_RAM_ptr p_dest,
                                 int    destlen )
#else
   /* Kernighan-Ritchie-Style */
   int            xmk_RingRead ( p_controlblock, p_dest, destlen )
   xmk_T_RING     xmk_RAM_ptr p_controlblock;
   char           xmk_RAM_ptr p_dest;
   int            destlen;
#endif

/*-FDEF E*/
{
  int len;

  if (! COUNTER)
  {
    /*
    ** nothing to read ...
    */
    return (XMK_EMPTY);
  }

  XMK_BEGIN_CRITICAL_PATH;

  COUNTER --;

  /*
  ** check if destination buffer is large enough ....
  */
  if (ENTRYSIZE > destlen)
  {
    XMK_END_CRITICAL_PATH;
    return (XMK_ERROR);
  }

  /*
  ** prepare return value ...
  ** 8051x compiler needs this temporary variable at this location
  */    
  len = destlen;

  /*
  ** in any case write destructive ..
  */
  COPY (p_dest, READPTR, len);

  /*
  ** increment readpointer  ...
  */
  INCR_READPTR ;

  /*
  ** if readpointer points behind the ringbuffer ...
  */
  if (READPTR >= (BUFFERADR + BUFFERSIZE))
  {
    READPTR = BUFFERADR ;
  }

  XMK_END_CRITICAL_PATH;

  /*
  ** return with the result ...
  */
  return (XMK_OKAY);

} /* END OF FUNCTION */

/*+FHDR E*/
/*
+------------------------------------------------------------------------------+
|  Functionname : xmk_RingQuery                                                |
|  Author       : S&P Media GmbH Germany                                       |
+------------------------------------------------------------------------------+
|                                                                              |
|                                                                              |
|  Description  :                                                              |
|  This functions returns the amount of free entries in the ringbuffer to the  |
|  caller.                                                                     |
|                                                                              |
|  Parameter    : xmk_T_RING      * Pointer to ringbuffer controlblock.        |
|                                                                              |
|  Return       : int               Amount of free entries or 0, if no entry   |
|                                   left free.                                 |
|                                                                              |
+------------------------------------------------------------------------------+
*/
/*-FHDR E*/

/*+FDEF E*/

#ifndef XNOPROTO
   /* ANSI - Style */
   int               xmk_RingQuery ( xmk_T_RING  xmk_RAM_ptr p_controlblock )

#else
   /* Kernighan-Ritchie-Style */
   int               xmk_RingQuery ( p_controlblock )
   xmk_T_RING        xmk_RAM_ptr p_controlblock;
#endif

/*-FDEF E*/
{
    /*
    ** Check if buffer initialized correctly
    */
  #ifdef XMK_USE_MAX_ERR_CHECK
    /*
    ** Check if buffer initialization is correct, and if counter is consistent
    */
    if ((MAXIMUM == 0) || (COUNTER > MAXIMUM)) return (0);
  #endif

  return ( MAXIMUM - COUNTER );

} /* END OF FUNCTION */

#endif /* __ML_BUF_C_ */

⌨️ 快捷键说明

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