Buffer from Sam Grove changed to have static instead of dynamic memory allocation. Fixed size to 256B.

Dependents:   BufferedSerialStatic

Fork of Buffer by Sam Grove

Committer:
goranirnas
Date:
Mon May 28 14:34:02 2018 +0000
Revision:
7:e80960adb2ad
Parent:
6:89564915f2a7
Updated buffer to use static memory allocation. Buffer size 256B.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sam_grove 6:89564915f2a7 1
sam_grove 6:89564915f2a7 2 /**
sam_grove 6:89564915f2a7 3 * @file Buffer.cpp
sam_grove 6:89564915f2a7 4 * @brief Software Buffer - Templated Ring Buffer for most data types
sam_grove 6:89564915f2a7 5 * @author sam grove
sam_grove 6:89564915f2a7 6 * @version 1.0
sam_grove 6:89564915f2a7 7 * @see
sam_grove 6:89564915f2a7 8 *
sam_grove 6:89564915f2a7 9 * Copyright (c) 2013
sam_grove 6:89564915f2a7 10 *
sam_grove 6:89564915f2a7 11 * Licensed under the Apache License, Version 2.0 (the "License");
sam_grove 6:89564915f2a7 12 * you may not use this file except in compliance with the License.
sam_grove 6:89564915f2a7 13 * You may obtain a copy of the License at
sam_grove 6:89564915f2a7 14 *
sam_grove 6:89564915f2a7 15 * http://www.apache.org/licenses/LICENSE-2.0
sam_grove 6:89564915f2a7 16 *
sam_grove 6:89564915f2a7 17 * Unless required by applicable law or agreed to in writing, software
sam_grove 6:89564915f2a7 18 * distributed under the License is distributed on an "AS IS" BASIS,
sam_grove 6:89564915f2a7 19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
sam_grove 6:89564915f2a7 20 * See the License for the specific language governing permissions and
sam_grove 6:89564915f2a7 21 * limitations under the License.
sam_grove 6:89564915f2a7 22 */
sam_grove 6:89564915f2a7 23
sam_grove 6:89564915f2a7 24 #include "MyBuffer.h"
sam_grove 6:89564915f2a7 25
sam_grove 6:89564915f2a7 26 template <class T>
goranirnas 7:e80960adb2ad 27 MyBuffer<T>::MyBuffer()
sam_grove 6:89564915f2a7 28 {
goranirnas 7:e80960adb2ad 29 _size = MyBuffer::BUFFER_SIZE;
sam_grove 6:89564915f2a7 30 clear();
sam_grove 6:89564915f2a7 31
sam_grove 6:89564915f2a7 32 return;
sam_grove 6:89564915f2a7 33 }
sam_grove 6:89564915f2a7 34
sam_grove 6:89564915f2a7 35 template <class T>
sam_grove 6:89564915f2a7 36 MyBuffer<T>::~MyBuffer()
sam_grove 6:89564915f2a7 37 {
sam_grove 6:89564915f2a7 38 delete [] _buf;
sam_grove 6:89564915f2a7 39
sam_grove 6:89564915f2a7 40 return;
sam_grove 6:89564915f2a7 41 }
sam_grove 6:89564915f2a7 42
sam_grove 6:89564915f2a7 43 template <class T>
sam_grove 6:89564915f2a7 44 uint32_t MyBuffer<T>::getSize()
sam_grove 6:89564915f2a7 45 {
sam_grove 6:89564915f2a7 46 return this->_size;
sam_grove 6:89564915f2a7 47 }
sam_grove 6:89564915f2a7 48
sam_grove 6:89564915f2a7 49 template <class T>
sam_grove 6:89564915f2a7 50 void MyBuffer<T>::clear(void)
sam_grove 6:89564915f2a7 51 {
sam_grove 6:89564915f2a7 52 _wloc = 0;
sam_grove 6:89564915f2a7 53 _rloc = 0;
sam_grove 6:89564915f2a7 54 memset(_buf, 0, _size);
sam_grove 6:89564915f2a7 55
sam_grove 6:89564915f2a7 56 return;
sam_grove 6:89564915f2a7 57 }
sam_grove 6:89564915f2a7 58
sam_grove 6:89564915f2a7 59 template <class T>
sam_grove 6:89564915f2a7 60 uint32_t MyBuffer<T>::peek(char c)
sam_grove 6:89564915f2a7 61 {
sam_grove 6:89564915f2a7 62 return 1;
sam_grove 6:89564915f2a7 63 }
sam_grove 6:89564915f2a7 64
sam_grove 6:89564915f2a7 65 // make the linker aware of some possible types
sam_grove 6:89564915f2a7 66 template class MyBuffer<uint8_t>;
sam_grove 6:89564915f2a7 67 template class MyBuffer<int8_t>;
sam_grove 6:89564915f2a7 68 template class MyBuffer<uint16_t>;
sam_grove 6:89564915f2a7 69 template class MyBuffer<int16_t>;
sam_grove 6:89564915f2a7 70 template class MyBuffer<uint32_t>;
sam_grove 6:89564915f2a7 71 template class MyBuffer<int32_t>;
sam_grove 6:89564915f2a7 72 template class MyBuffer<uint64_t>;
sam_grove 6:89564915f2a7 73 template class MyBuffer<int64_t>;
sam_grove 6:89564915f2a7 74 template class MyBuffer<char>;
sam_grove 6:89564915f2a7 75 template class MyBuffer<wchar_t>;