![](/media/cache/group/logo_thTzkVQ.jpg.50x50_q85.jpg)
NuMaker Transfer data UART to Ethernet
Fork of Serial-to-Ethernet by
BufferSerial/MyBuffer.cpp@9:b300117f3ed7, 16 months ago (annotated)
- Committer:
- cyliang
- Date:
- Mon Mar 06 05:36:05 2023 +0000
- Revision:
- 9:b300117f3ed7
- Parent:
- 6:014b1a469aed
Add M467 serial list
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 1 | |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 2 | /** |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 3 | * @file Buffer.cpp |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 4 | * @brief Software Buffer - Templated Ring Buffer for most data types |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 5 | * @author sam grove |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 6 | * @version 1.0 |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 7 | * @see |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 8 | * |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 9 | * Copyright (c) 2013 |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 10 | * |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 11 | * Licensed under the Apache License, Version 2.0 (the "License"); |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 12 | * you may not use this file except in compliance with the License. |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 13 | * You may obtain a copy of the License at |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 14 | * |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 15 | * http://www.apache.org/licenses/LICENSE-2.0 |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 16 | * |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 17 | * Unless required by applicable law or agreed to in writing, software |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 18 | * distributed under the License is distributed on an "AS IS" BASIS, |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 20 | * See the License for the specific language governing permissions and |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 21 | * limitations under the License. |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 22 | */ |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 23 | |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 24 | #include "MyBuffer.h" |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 25 | |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 26 | template <class T> |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 27 | MyBuffer<T>::MyBuffer(uint32_t size) |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 28 | { |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 29 | _buf = new T [size]; |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 30 | _size = size; |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 31 | clear(); |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 32 | |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 33 | return; |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 34 | } |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 35 | |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 36 | template <class T> |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 37 | MyBuffer<T>::~MyBuffer() |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 38 | { |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 39 | delete [] _buf; |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 40 | |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 41 | return; |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 42 | } |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 43 | |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 44 | template <class T> |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 45 | uint32_t MyBuffer<T>::getSize() |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 46 | { |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 47 | return this->_size; |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 48 | } |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 49 | |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 50 | template <class T> |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 51 | void MyBuffer<T>::clear(void) |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 52 | { |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 53 | _wloc = 0; |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 54 | _rloc = 0; |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 55 | memset(_buf, 0, _size); |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 56 | |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 57 | return; |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 58 | } |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 59 | |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 60 | template <class T> |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 61 | uint32_t MyBuffer<T>::peek(char c) |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 62 | { |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 63 | return 1; |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 64 | } |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 65 | |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 66 | // make the linker aware of some possible types |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 67 | template class MyBuffer<uint8_t>; |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 68 | template class MyBuffer<int8_t>; |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 69 | template class MyBuffer<uint16_t>; |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 70 | template class MyBuffer<int16_t>; |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 71 | template class MyBuffer<uint32_t>; |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 72 | template class MyBuffer<int32_t>; |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 73 | template class MyBuffer<uint64_t>; |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 74 | template class MyBuffer<int64_t>; |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 75 | template class MyBuffer<char>; |
SHLIU1@OANBE02333.nuvoton.com | 6:014b1a469aed | 76 | template class MyBuffer<wchar_t>; |