00001 /**********************************************************************************************************************\ 00002 00003 C++ library for Atmel AVR microcontrollers 00004 Copyright (C) 2007 Lauri Kirikal, Mikk Leini, MT� TT� Robotiklubi 00005 00006 This program is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU General Public License 00008 as published by the Free Software Foundation; either version 2 00009 of the License, or (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 00020 See http://creativecommons.org/licenses/GPL/2.0/ 00021 00022 MT� TT� Robotiklubi http://www.robotiklubi.ee robotiklubi@gmail.com 00023 Lauri Kirikal laurikirikal@gmail.com 00024 Mikk Leini mikk.leini@gmail.com 00025 00026 \**********************************************************************************************************************/ 00027 00028 #ifndef __AVR_CPP_BASE_QUEUE_H__ 00029 #define __AVR_CPP_BASE_QUEUE_H__ 00030 00031 00032 /**********************************************************************************************************************\ 00033 00034 AVRCppLib collection objects 00035 00036 \**********************************************************************************************************************/ 00037 00038 namespace AVRCpp 00039 { 00040 namespace Collection 00041 { 00042 00043 00044 /**********************************************************************************************************************\ 00045 00046 Base queue (FIFO) class 00047 00048 This class should never be instantized directly! 00049 00050 \**********************************************************************************************************************/ 00051 00052 template <typename DataType, typename SizeType, typename ListType> class BaseQueue 00053 { 00054 protected: 00055 ListType data; 00056 volatile SizeType write_pointer; 00057 volatile SizeType read_pointer; 00058 00059 struct 00060 { 00061 volatile uint8_t is_full : 1; 00062 }; 00063 00064 public: 00065 00069 inline void Clear() 00070 { 00071 this->write_pointer = 0; 00072 this->read_pointer = 0; 00073 this->is_full = 0; 00074 } 00075 00079 BaseQueue() 00080 { 00081 Clear(); 00082 } 00083 00087 inline bool IsEmpty(void) 00088 { 00089 return ((this->read_pointer == this->write_pointer) && (this->is_full == 0)); 00090 } 00091 00095 inline bool IsFull(void) 00096 { 00097 return this->is_full; 00098 } 00099 00104 inline DataType &Front() 00105 { 00106 return this->data[this->read_pointer]; 00107 } 00108 00113 inline DataType &Back() 00114 { 00115 return this->data[this->write_pointer]; 00116 } 00117 00118 }; // class BaseQueue 00119 00120 00121 /**********************************************************************************************************************/ 00122 00123 } // namespace Collection 00124 00125 } // namespace AVRCpp 00126 00127 00128 /**********************************************************************************************************************/ 00129 00130 #endif // ifndef __AVR_CPP_BASE_QUEUE_H__
MTÜ TTÜ Robotiklubi |