mbuspack.cpp

来自「coldfire5206芯片的boot程序」· C++ 代码 · 共 75 行

CPP
75
字号
#include  "bastype.h"

#include "mbuspack.h"


/**
 *  static variables define: Packet queues
 */
static MBusPackType sCAT24C021ReadPack[CAT24C021_READ_PACKQUE_LEN];
static MBusPackType sCAT24C021WritePack[CAT24C021_WRITE_PACKQUE_LEN];


/**
 *  Global variables define: Packet queue manager
 */
MBusPackQueType gCAT24C021ReadPackQue =
                      {0, 0, CAT24C021_READ_PACKQUE_LEN, sCAT24C021ReadPack};

MBusPackQueType gCAT24C021WritePackQue =
                      {0, 0, CAT24C021_WRITE_PACKQUE_LEN, sCAT24C021WritePack};

/**
 *  get one  MBusPacket from the given queue and save it to out
 *
 *  @param   theQue  the queue to be manipulated.
 *  @param   out     the address for storing the result
 *
 *  @return  <code>0</code> if queue is empty, operation failed
 *           <code>1</code> if queue isnot empty, operation succeed
 */
INT16  MBusPackQueGet(MBusPackQueType *theQue, MBusPackType** out)
{
   INT  ptr = theQue->getPtr;

   if ( ptr == theQue->putPtr )
      return 0;

   *out = &theQue->packQue[theQue->getPtr];

   ptr ++;
   if (theQue->queueLen <= ptr)
      ptr = 0;

   theQue->getPtr = ptr;
   
   return 1;
}


/**
 *  put one MBusPacket to the queue
 *
 *  @param   theQue  the queue to be manipulated.
 *  @param   in    the MBusPacket for putting
 *
 *  @return  <code>0</code> if queue is full, operation failed,
 *           <code>1</code> if queue is not full, success
 */
INT16  MBusPackQuePut(MBusPackQueType *theQue, MBusPackType* in)
{
   INT  ptr = theQue->putPtr;

   ptr ++;
   if (theQue->queueLen <= ptr)
      ptr = 0;

   if (ptr == theQue->getPtr)
      return 0;

   theQue->packQue[theQue->putPtr] = *in;

   theQue->putPtr = ptr;
   return 1;
}

⌨️ 快捷键说明

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