Ningkai Wu / Mbed 2 deprecated test_spi_ble

Dependencies:   mbed-rtos mbed

Committer:
wninghj
Date:
Thu Apr 05 21:26:10 2018 +0000
Revision:
0:39b7f3158ebe
TEAM12 DJ;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wninghj 0:39b7f3158ebe 1 /**************************************************************************/
wninghj 0:39b7f3158ebe 2 /*!
wninghj 0:39b7f3158ebe 3 @file Adafruit_FIFO.h
wninghj 0:39b7f3158ebe 4 @author hathach
wninghj 0:39b7f3158ebe 5
wninghj 0:39b7f3158ebe 6 @section LICENSE
wninghj 0:39b7f3158ebe 7
wninghj 0:39b7f3158ebe 8 Software License Agreement (BSD License)
wninghj 0:39b7f3158ebe 9
wninghj 0:39b7f3158ebe 10 Copyright (c) 2015, Adafruit Industries (adafruit.com)
wninghj 0:39b7f3158ebe 11 All rights reserved.
wninghj 0:39b7f3158ebe 12
wninghj 0:39b7f3158ebe 13 Redistribution and use in source and binary forms, with or without
wninghj 0:39b7f3158ebe 14 modification, are permitted provided that the following conditions are met:
wninghj 0:39b7f3158ebe 15 1. Redistributions of source code must retain the above copyright
wninghj 0:39b7f3158ebe 16 notice, this list of conditions and the following disclaimer.
wninghj 0:39b7f3158ebe 17 2. Redistributions in binary form must reproduce the above copyright
wninghj 0:39b7f3158ebe 18 notice, this list of conditions and the following disclaimer in the
wninghj 0:39b7f3158ebe 19 documentation and/or other materials provided with the distribution.
wninghj 0:39b7f3158ebe 20 3. Neither the name of the copyright holders nor the
wninghj 0:39b7f3158ebe 21 names of its contributors may be used to endorse or promote products
wninghj 0:39b7f3158ebe 22 derived from this software without specific prior written permission.
wninghj 0:39b7f3158ebe 23
wninghj 0:39b7f3158ebe 24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
wninghj 0:39b7f3158ebe 25 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
wninghj 0:39b7f3158ebe 26 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
wninghj 0:39b7f3158ebe 27 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
wninghj 0:39b7f3158ebe 28 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
wninghj 0:39b7f3158ebe 29 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
wninghj 0:39b7f3158ebe 30 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
wninghj 0:39b7f3158ebe 31 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
wninghj 0:39b7f3158ebe 32 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
wninghj 0:39b7f3158ebe 33 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
wninghj 0:39b7f3158ebe 34 */
wninghj 0:39b7f3158ebe 35 /**************************************************************************/
wninghj 0:39b7f3158ebe 36
wninghj 0:39b7f3158ebe 37 #ifndef _Adafruit_FIFO_H_
wninghj 0:39b7f3158ebe 38 #define _Adafruit_FIFO_H_
wninghj 0:39b7f3158ebe 39
wninghj 0:39b7f3158ebe 40 #include <stdint.h>
wninghj 0:39b7f3158ebe 41 #include <stdbool.h>
wninghj 0:39b7f3158ebe 42
wninghj 0:39b7f3158ebe 43 class Adafruit_FIFO
wninghj 0:39b7f3158ebe 44 {
wninghj 0:39b7f3158ebe 45 private:
wninghj 0:39b7f3158ebe 46 uint8_t* m_buffer ; ///< buffer pointer
wninghj 0:39b7f3158ebe 47 uint16_t m_depth ; ///< max items
wninghj 0:39b7f3158ebe 48 uint8_t m_item_size ; ///< size of each item
wninghj 0:39b7f3158ebe 49 bool m_overwritable ;
wninghj 0:39b7f3158ebe 50 volatile uint16_t m_count ; ///< number of items in queue
wninghj 0:39b7f3158ebe 51 volatile uint16_t m_wr_idx ; ///< write pointer
wninghj 0:39b7f3158ebe 52 volatile uint16_t m_rd_idx ; ///< read pointer
wninghj 0:39b7f3158ebe 53
wninghj 0:39b7f3158ebe 54 public:
wninghj 0:39b7f3158ebe 55 // Constructor
wninghj 0:39b7f3158ebe 56 Adafruit_FIFO(void* buffer, uint16_t depth, uint8_t item_size, bool overwrite);
wninghj 0:39b7f3158ebe 57
wninghj 0:39b7f3158ebe 58 void clear(void);
wninghj 0:39b7f3158ebe 59 bool peek(void* buffer);
wninghj 0:39b7f3158ebe 60 bool peekAt(uint16_t position, void * p_buffer);
wninghj 0:39b7f3158ebe 61
wninghj 0:39b7f3158ebe 62 bool write(void const* item);
wninghj 0:39b7f3158ebe 63 uint16_t write_n(void const * data, uint16_t n);
wninghj 0:39b7f3158ebe 64
wninghj 0:39b7f3158ebe 65 bool read(void* buffer);
wninghj 0:39b7f3158ebe 66 uint16_t read_n (void * buffer, uint16_t n);
wninghj 0:39b7f3158ebe 67
wninghj 0:39b7f3158ebe 68 inline bool empty(void) { return m_count == 0; }
wninghj 0:39b7f3158ebe 69 inline bool full(void) { return m_count == m_depth; }
wninghj 0:39b7f3158ebe 70 inline uint16_t count(void) { return m_count; }
wninghj 0:39b7f3158ebe 71 inline uint16_t remaining(void) { return m_depth - m_count; }
wninghj 0:39b7f3158ebe 72 };
wninghj 0:39b7f3158ebe 73
wninghj 0:39b7f3158ebe 74 #endif /* _Adafruit_FIFO_H_ */