ME11B Sample Code in Maxim Integrated Team
Dependencies: BMI160 max32630hsp3 MemoryLCD USBDevice
Fork of Host_Software_MAX32664GWEB_HR_EXTENDED by
Drivers/USBDevice/USBSerial/CircBuffer.h@0:ac4dea3e2894, 2019-03-18 (annotated)
- Committer:
- seyhmus.cacina
- Date:
- Mon Mar 18 10:21:53 2019 +0300
- Revision:
- 0:ac4dea3e2894
ME11B Sample Code First Commit
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| seyhmus.cacina | 0:ac4dea3e2894 | 1 | /* Copyright (c) 2010-2011 mbed.org, MIT License |
| seyhmus.cacina | 0:ac4dea3e2894 | 2 | * |
| seyhmus.cacina | 0:ac4dea3e2894 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
| seyhmus.cacina | 0:ac4dea3e2894 | 4 | * and associated documentation files (the "Software"), to deal in the Software without |
| seyhmus.cacina | 0:ac4dea3e2894 | 5 | * restriction, including without limitation the rights to use, copy, modify, merge, publish, |
| seyhmus.cacina | 0:ac4dea3e2894 | 6 | * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the |
| seyhmus.cacina | 0:ac4dea3e2894 | 7 | * Software is furnished to do so, subject to the following conditions: |
| seyhmus.cacina | 0:ac4dea3e2894 | 8 | * |
| seyhmus.cacina | 0:ac4dea3e2894 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
| seyhmus.cacina | 0:ac4dea3e2894 | 10 | * substantial portions of the Software. |
| seyhmus.cacina | 0:ac4dea3e2894 | 11 | * |
| seyhmus.cacina | 0:ac4dea3e2894 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
| seyhmus.cacina | 0:ac4dea3e2894 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| seyhmus.cacina | 0:ac4dea3e2894 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
| seyhmus.cacina | 0:ac4dea3e2894 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| seyhmus.cacina | 0:ac4dea3e2894 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| seyhmus.cacina | 0:ac4dea3e2894 | 17 | */ |
| seyhmus.cacina | 0:ac4dea3e2894 | 18 | |
| seyhmus.cacina | 0:ac4dea3e2894 | 19 | #ifndef CIRCBUFFER_H |
| seyhmus.cacina | 0:ac4dea3e2894 | 20 | #define CIRCBUFFER_H |
| seyhmus.cacina | 0:ac4dea3e2894 | 21 | |
| seyhmus.cacina | 0:ac4dea3e2894 | 22 | template <class T, int Size> |
| seyhmus.cacina | 0:ac4dea3e2894 | 23 | class CircBuffer { |
| seyhmus.cacina | 0:ac4dea3e2894 | 24 | public: |
| seyhmus.cacina | 0:ac4dea3e2894 | 25 | CircBuffer():write(0), read(0){} |
| seyhmus.cacina | 0:ac4dea3e2894 | 26 | bool isFull() { |
| seyhmus.cacina | 0:ac4dea3e2894 | 27 | return ((write + 1) % size == read); |
| seyhmus.cacina | 0:ac4dea3e2894 | 28 | }; |
| seyhmus.cacina | 0:ac4dea3e2894 | 29 | |
| seyhmus.cacina | 0:ac4dea3e2894 | 30 | bool isEmpty() { |
| seyhmus.cacina | 0:ac4dea3e2894 | 31 | return (read == write); |
| seyhmus.cacina | 0:ac4dea3e2894 | 32 | }; |
| seyhmus.cacina | 0:ac4dea3e2894 | 33 | |
| seyhmus.cacina | 0:ac4dea3e2894 | 34 | void queue(T k) { |
| seyhmus.cacina | 0:ac4dea3e2894 | 35 | if (isFull()) { |
| seyhmus.cacina | 0:ac4dea3e2894 | 36 | read++; |
| seyhmus.cacina | 0:ac4dea3e2894 | 37 | read %= size; |
| seyhmus.cacina | 0:ac4dea3e2894 | 38 | } |
| seyhmus.cacina | 0:ac4dea3e2894 | 39 | buf[write++] = k; |
| seyhmus.cacina | 0:ac4dea3e2894 | 40 | write %= size; |
| seyhmus.cacina | 0:ac4dea3e2894 | 41 | } |
| seyhmus.cacina | 0:ac4dea3e2894 | 42 | |
| seyhmus.cacina | 0:ac4dea3e2894 | 43 | uint16_t available() { |
| seyhmus.cacina | 0:ac4dea3e2894 | 44 | return (write >= read) ? write - read : size - read + write; |
| seyhmus.cacina | 0:ac4dea3e2894 | 45 | }; |
| seyhmus.cacina | 0:ac4dea3e2894 | 46 | |
| seyhmus.cacina | 0:ac4dea3e2894 | 47 | bool dequeue(T * c) { |
| seyhmus.cacina | 0:ac4dea3e2894 | 48 | bool empty = isEmpty(); |
| seyhmus.cacina | 0:ac4dea3e2894 | 49 | if (!empty) { |
| seyhmus.cacina | 0:ac4dea3e2894 | 50 | *c = buf[read++]; |
| seyhmus.cacina | 0:ac4dea3e2894 | 51 | read %= size; |
| seyhmus.cacina | 0:ac4dea3e2894 | 52 | } |
| seyhmus.cacina | 0:ac4dea3e2894 | 53 | return(!empty); |
| seyhmus.cacina | 0:ac4dea3e2894 | 54 | }; |
| seyhmus.cacina | 0:ac4dea3e2894 | 55 | |
| seyhmus.cacina | 0:ac4dea3e2894 | 56 | private: |
| seyhmus.cacina | 0:ac4dea3e2894 | 57 | volatile uint16_t write; |
| seyhmus.cacina | 0:ac4dea3e2894 | 58 | volatile uint16_t read; |
| seyhmus.cacina | 0:ac4dea3e2894 | 59 | static const int size = Size+1; //a modern optimizer should be able to remove this so it uses no ram. |
| seyhmus.cacina | 0:ac4dea3e2894 | 60 | T buf[Size+1]; |
| seyhmus.cacina | 0:ac4dea3e2894 | 61 | }; |
| seyhmus.cacina | 0:ac4dea3e2894 | 62 | |
| seyhmus.cacina | 0:ac4dea3e2894 | 63 | #endif |

Health Sensor Board Embedded Heart Rate Algorithm Sensor Hub + ECG, Wearables Ev Kit MAXREFDES101#