Ejemplo n.º 1
0
//Copy the message of msgSize bytes from (buf + tail) to msg
//Make sure we don' lose messages that split from the end of buf to the beginning
//Update the tail and count by adding msgSize to tail and subtracting it from count
void CircularBuffer::pull(CircularBuffer *_this, void* msg, int msgSize)
{
  int splitMsg;

  if(_this->count > 0)
  {
    //We don't want to throw away any messages
    //  See if the tail is near the end of the buffer
    if((CIRCBUF_SIZE - this->tail - msgSize) >= 0)
    {
        //Copy the message from (buf+tail) to msg
        memcpy(msg, (this->buf + this->tail), msgSize);
    }
    else
    {
      splitMsg = (CIRCBUF_SIZE - this->tail);   //# of bytes before end of buffer
      //Copy up to the end of the buffer
      memcpy(msg, (this->buf + this->tail), splitMsg);
      //Copy the rest of the message from the start of the buffer
      memcpy(((unsigned char*)msg + splitMsg), this->buf, (msgSize - splitMsg));
    }
    //Update the tail and count, modulo_inc does the wrapping of buf (255 to 0)
    _this->tail = modulo_inc(_this->tail, msgSize, CIRCBUF_SIZE);
    _this->count -= msgSize;
  }
}
Ejemplo n.º 2
0
//Place one byte on the buffer and update head and count
void CircularBuffer::push(CircularBuffer *_this, const unsigned char c)
{
  if(_this->count < CIRCBUF_SIZE)
  {
    _this->buf[_this->head] = c;
    _this->head = modulo_inc (_this->head, 1, CIRCBUF_SIZE);
    ++_this->count;  
  }
}
Ejemplo n.º 3
0
void ringBufS_put (ringBufS *_this, volatile unsigned short int c)
{
    if (_this->count < RBUF_SIZE)
    {
      _this->buf[_this->head] = c;
      _this->head = modulo_inc (_this->head, RBUF_SIZE);
      ++_this->count;
    }
}
Ejemplo n.º 4
0
/**
 * \brief Add data to one of the arrays pointed to by the address
 *        at au32Addr[head].
 *
 *  If .count < RBUF_SIZE, head is incremented, count is incremented
 *  and the next available 32-bit address is returned.
 *
 * @param _this pointer to the ring buffer
 * @param pu32Val 32-bit address at au32Addr[head] is returned
 */
void rbuf_put (T_RING_BUF *_this, uint32_t * pu32Val)
{
    if (_this->count < RBUF_SIZE)
    {
    	*pu32Val = _this->au32Addr[_this->head];
      _this->head = modulo_inc (_this->head, RBUF_SIZE);
      ++_this->count;
    }
}
Ejemplo n.º 5
0
/**
 * \brief Get the oldest data in the buffer (First In).
 * @param _this
 * @param pu8Val --> au32Addr[tail] returned here.
 * @return T if there is data in the buffer, F otherwise
 */
uint8_t rbuf_get (T_RING_BUF *_this, uint32_t * pu32Val)
{
	uint8_t bOk = 1;

    if (_this->count>0)
    {

    	*pu32Val = _this->au32Addr[_this->tail];
      _this->tail = modulo_inc (_this->tail, RBUF_SIZE);
      --_this->count;
    }
    else{ bOk = 0; }
    return bOk;
}
Ejemplo n.º 6
0
int ringBufS_get (ringBufS *_this)
{
   int c;
   if (_this->count>0)
   {
     c           = _this->buf[_this->tail];
     _this->tail = modulo_inc (_this->tail, RBUF_SIZE);
     --_this->count;
   }
   else
   {
     c = -1;
   }
   return (c);
}