Bluetooth SPI MBED

Dependencies:   mbed-rtos mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Adafruit_FIFO.h Source File

Adafruit_FIFO.h

Go to the documentation of this file.
00001 /**************************************************************************/
00002 /*!
00003     @file     Adafruit_FIFO.h
00004     @author   hathach
00005 
00006     @section LICENSE
00007 
00008     Software License Agreement (BSD License)
00009 
00010     Copyright (c) 2015, Adafruit Industries (adafruit.com)
00011     All rights reserved.
00012 
00013     Redistribution and use in source and binary forms, with or without
00014     modification, are permitted provided that the following conditions are met:
00015     1. Redistributions of source code must retain the above copyright
00016     notice, this list of conditions and the following disclaimer.
00017     2. Redistributions in binary form must reproduce the above copyright
00018     notice, this list of conditions and the following disclaimer in the
00019     documentation and/or other materials provided with the distribution.
00020     3. Neither the name of the copyright holders nor the
00021     names of its contributors may be used to endorse or promote products
00022     derived from this software without specific prior written permission.
00023 
00024     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
00025     EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00026     WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00027     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
00028     DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00029     (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00030     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00031     ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00032     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00033     SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00034 */
00035 /**************************************************************************/
00036 
00037 #ifndef _Adafruit_FIFO_H_
00038 #define _Adafruit_FIFO_H_
00039 
00040 #include <stdint.h>
00041 #include <stdbool.h>
00042 
00043 class Adafruit_FIFO
00044 {
00045   private:
00046              uint8_t* m_buffer       ; ///< buffer pointer
00047              uint16_t m_depth        ; ///< max items
00048              uint8_t  m_item_size    ; ///< size of each item
00049              bool     m_overwritable ;
00050     volatile uint16_t m_count        ; ///< number of items in queue
00051     volatile uint16_t m_wr_idx       ; ///< write pointer
00052     volatile uint16_t m_rd_idx       ; ///< read pointer
00053 
00054   public:
00055     // Constructor
00056     Adafruit_FIFO(void* buffer, uint16_t depth, uint8_t item_size, bool overwrite);
00057 
00058     void clear(void);
00059     bool peek(void* buffer);
00060     bool peekAt(uint16_t position, void * p_buffer);
00061 
00062     bool write(void const* item);
00063     uint16_t write_n(void const * data, uint16_t n);
00064 
00065     bool read(void* buffer);
00066     uint16_t read_n (void * buffer, uint16_t n);
00067 
00068     inline bool     empty(void)     { return m_count == 0; }
00069     inline bool     full(void)      { return m_count == m_depth; }
00070     inline uint16_t count(void)     { return m_count; }
00071     inline uint16_t remaining(void) { return m_depth - m_count; }
00072 };
00073 
00074 #endif /* _Adafruit_FIFO_H_ */