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

📄 bfifo.h

📁 Jan 04, 2007 1. Add SPI support, see spi.h and spi.c 2. Add driver.h 3. Modified keyboard modu
💻 H
字号:
/** * 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 25, 2006 * */#ifndef __BYTEFIFO_H__#define __BYTEFIFO_H__#include "common.h"#include "sync.h"#define FIFO_IS_EMPTY 1#define FIFO_IS_FULLY 2#ifndef __ASSEMBLER__/* These only work in C program *//** * Define data structrue of ByteFifo * The queue's max capability is 256 bytes */typedef struct SyncLock {  Semaphore not_fully;  Semaphore not_empty;  Mutex mutex;} SyncLock;typedef struct ByteFifo {  __volatile__ unsigned char  status;  __volatile__ unsigned char  mxsize;    // The max capability   __volatile__ unsigned char  readps;    // The Read pointer  __volatile__ unsigned char  writps;    // The Write pointer  unsigned char *buffer;  SyncLock* sync;} ByteFifo;/** * A macro to ease the declaration of ByeFifo definition. * USAGE: BYTEFIFO(uart_tx, 16); * * @param name, The name of the ByteFifo * @param mxsize, The max capability of the Fifo */#define BYTEFIFO(name, mxsize)                    \  unsigned char name##_fifo[mxsize];		  \  SyncLock name##_sync ={			  \    {TYPE_SEMAPHORE, mxsize, {NULL}},             \    {TYPE_SEMAPHORE, 0, {NULL}},                  \    {TYPE_MUTEX, 1, {NULL}}                       \  };                                              \  ByteFifo name = {				  \    FIFO_IS_EMPTY, mxsize, 0, 0,                  \    &name##_fifo[0],		                  \    &name##_sync                                  \  }#define NAKEDFIFO(name, mxsize)                   \  unsigned char name##_fifo[mxsize];		  \  ByteFifo name = {				  \    FIFO_IS_EMPTY, mxsize, 0, 0,                  \    &name##_fifo[0],		                  \    NULL                                          \  }/** * Test whether the fifo is fully * * @param ByteFifo*, The pointer to the ByteFifo * @return unsigned char, 1: fully, 0: not fully */INTERFACE unsigned char is_fully(ByteFifo*);/** * Test whether the fifo is empty * * @param ByteFifo*, The pointer to the ByteFifo * @return unsigned char, 1: empty, 0: not empty */INTERFACE unsigned char is_empty(ByteFifo*);/** * 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 */ INTERFACE unsigned char get_byte(ByteFifo*);/** * 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 */INTERFACE void put_byte(ByteFifo*, unsigned char);/** * 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*);/** * 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*, unsigned char);#endif /* !__ASSEMBLER__ */#endif /* __BYTEFIFO_H__ */

⌨️ 快捷键说明

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