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

📄 bfifo.c

📁 Jan 04, 2007 1. Add SPI support, see spi.h and spi.c 2. Add driver.h 3. Modified keyboard modu
💻 C
字号:
/** * Copyright (c) 2006-2008 iWESUN (ShenZhen) Inf. * All rights reserved.  *  * Redistribution and use in source and binary forms, with or without modification,  * are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, *    this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, *    this list of conditions and the following disclaimer in the documentation *    and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products *    derived from this software without specific prior written permission.  * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY  * OF SUCH DAMAGE. * * This file is part of the AvrcX MTOS *  * Author: Winter Hu  <winter.hu@gmail.com> * Create: Nov 26, 2006 * */#include "bfifo.h"/** * Test whether the fifo is fully * * @param ByteFifo*, The pointer to the ByteFifo * @return unsigned char, 1: fully, 0: not fully */unsigned char is_fully(ByteFifo* pFifo){  return (pFifo->status & FIFO_IS_FULLY) ? TRUE : FALSE;}/** * Test whether the fifo is empty * * @param ByteFifo*, The pointer to the ByteFifo * @return unsigned char, 1: empty, 0: not empty */unsigned char is_empty(ByteFifo* pFifo){  return (pFifo->status & FIFO_IS_EMPTY) ? TRUE : FALSE;}/** * Gets the first byte from the fifo front * This method could be blocked if fifo is empty in user mode. * * @param ByteFifo*, The pointer to the ByteFifo * @retrun unsigned char, the byte pop from fifo front */ unsigned char get_byte(ByteFifo* pFifo){    P(&(pFifo->sync->not_empty));    P(&(pFifo->sync->mutex));  unsigned char b = fifo_getbyte(pFifo);  V(&(pFifo->sync->mutex));  V(&(pFifo->sync->not_fully));  return b;}/** * Puts a byte to the fifo tail * This method could be blocked if fifo is fully in user mode. *  * @param ByteFifo*, The pointer to the ByteFifo * @param unsigned char, The byte need puts into the queue */void put_byte(ByteFifo* pFifo, unsigned char b){  P(&(pFifo->sync->not_fully));  P(&(pFifo->sync->mutex));    fifo_putbyte(pFifo, b);  V(&(pFifo->sync->mutex));  V(&(pFifo->sync->not_empty));}/** * Get a byte from byte fifo * Return -1 if fifo is empty * * @param ByteFifo*, The pointer to the fifo * @return int, the data. -1 means fifo is empty */int fifo_getbyte(ByteFifo* pFifo){  if (pFifo->status & FIFO_IS_EMPTY) return -1;  int b = *(pFifo->buffer+pFifo->readps);    pFifo->readps++;  pFifo->readps = (pFifo->readps >= pFifo->mxsize) ? 0 : pFifo->readps;  if (pFifo->readps == pFifo->writps){    pFifo->status |= FIFO_IS_EMPTY;  }else{    pFifo->status &= ~FIFO_IS_FULLY;  }    return b;}/** * Put a byte to byte fifo * Return -1 if fifo is fully * * @param ByteFifo*, The pointer to the fifo * @param unsigned char, the byte need to put * @return int, the byte had put into fifo, -1 means fifo is fully */int fifo_putbyte(ByteFifo* pFifo, unsigned char b){  if (pFifo->status & FIFO_IS_FULLY) return -1;  *(pFifo->buffer+pFifo->writps) = b;  pFifo->writps++;  pFifo->writps = (pFifo->writps >= pFifo->mxsize) ? 0 : pFifo->writps;  if (pFifo->writps == pFifo->readps){    pFifo->status |= FIFO_IS_FULLY;  }else{    pFifo->status &= ~FIFO_IS_EMPTY;  }  return (int) b;}

⌨️ 快捷键说明

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