Host software for the MAX30001 ECG, PACE, biopotential, bioimpedance, R-to-R peak sensor. Hosted on the MAX32630FTHR.

Dependencies:   SDFileSystem USBDevice max32630fthr

Fork of MAX30001-MAX32630FTHR-ECG-EVKIT by Maxim Integrated

Committer:
Emre.Eken@IST-LT-35101.maxim-ic.internal
Date:
Thu Apr 05 10:53:26 2018 +0300
Revision:
0:8e4630a71eb1
mbed os 5.8.1 compatible

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 1 /*******************************************************************************
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 2 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 3 *
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 4 * Permission is hereby granted, free of charge, to any person obtaining a
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 5 * copy of this software and associated documentation files (the "Software"),
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 6 * to deal in the Software without restriction, including without limitation
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 8 * and/or sell copies of the Software, and to permit persons to whom the
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 9 * Software is furnished to do so, subject to the following conditions:
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 10 *
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 11 * The above copyright notice and this permission notice shall be included
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 12 * in all copies or substantial portions of the Software.
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 13 *
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 20 * OTHER DEALINGS IN THE SOFTWARE.
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 21 *
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 22 * Except as contained in this notice, the name of Maxim Integrated
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 24 * Products, Inc. Branding Policy.
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 25 *
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 26 * The mere transfer of this software does not imply any licenses
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 27 * of trade secrets, proprietary technology, copyrights, patents,
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 28 * trademarks, maskwork rights, or any other form of intellectual
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 30 * ownership rights.
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 31 *******************************************************************************
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 32 */
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 33 #include "mbed.h"
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 34 #include "RpcFifo.h"
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 35
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 36 /****************************************************************************/
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 37 void fifo_init(fifo_t *fifo, void *mem, unsigned int length) {
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 38 // atomic FIFO access
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 39 __disable_irq();
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 40
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 41 fifo->rindex = 0;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 42 fifo->windex = 0;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 43 fifo->data = mem;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 44 fifo->length = length;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 45
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 46 __enable_irq();
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 47 }
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 48
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 49 /****************************************************************************/
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 50 int fifo_put8(fifo_t *fifo, uint8_t element) {
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 51 // Check if FIFO is full
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 52 if ((fifo->windex == (fifo->rindex - 1)) ||
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 53 ((fifo->rindex == 0) && (fifo->windex == (fifo->length - 1)))) {
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 54 return -1;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 55 }
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 56
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 57 // atomic FIFO access
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 58 __disable_irq();
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 59
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 60 // Put data into FIFO
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 61 ((uint8_t *)(fifo->data))[fifo->windex] = element;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 62
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 63 // Increment pointer
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 64 fifo->windex++;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 65 if (fifo->windex == fifo->length) {
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 66 fifo->windex = 0;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 67 }
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 68
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 69 __enable_irq();
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 70
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 71 return 0;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 72 }
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 73
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 74 /****************************************************************************/
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 75 int fifo_get8(fifo_t *fifo, uint8_t *element) {
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 76 // Check if FIFO is empty
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 77 if (fifo->rindex == fifo->windex)
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 78 return -1;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 79
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 80 // atomic FIFO access
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 81 __disable_irq();
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 82
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 83 // Get data from FIFO
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 84 *element = ((uint8_t *)(fifo->data))[fifo->rindex];
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 85
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 86 // Increment pointer
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 87 fifo->rindex++;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 88 if (fifo->rindex == fifo->length) {
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 89 fifo->rindex = 0;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 90 }
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 91
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 92 __enable_irq();
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 93
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 94 return 0;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 95 }
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 96
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 97 /****************************************************************************/
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 98 int fifo_put16(fifo_t *fifo, uint16_t element) {
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 99 // Check if FIFO is full
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 100 if ((fifo->windex == (fifo->rindex - 1)) ||
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 101 ((fifo->rindex == 0) && (fifo->windex == (fifo->length - 1)))) {
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 102 return -1;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 103 }
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 104
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 105 // atomic FIFO access
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 106 __disable_irq();
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 107
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 108 // Put data into FIFO
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 109 ((uint16_t *)(fifo->data))[fifo->windex] = element;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 110
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 111 // Increment pointer
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 112 fifo->windex++;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 113 if (fifo->windex == fifo->length) {
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 114 fifo->windex = 0;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 115 }
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 116
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 117 __enable_irq();
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 118
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 119 return 0;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 120 }
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 121
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 122 /****************************************************************************/
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 123 int fifo_get16(fifo_t *fifo, uint16_t *element) {
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 124 // Check if FIFO is empty
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 125 if (fifo->rindex == fifo->windex)
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 126 return -1;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 127
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 128 // atomic FIFO access
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 129 __disable_irq();
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 130
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 131 // Get data from FIFO
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 132 *element = ((uint16_t *)(fifo->data))[fifo->rindex];
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 133
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 134 // Increment pointer
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 135 fifo->rindex++;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 136 if (fifo->rindex == fifo->length) {
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 137 fifo->rindex = 0;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 138 }
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 139
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 140 __enable_irq();
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 141
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 142 return 0;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 143 }
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 144
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 145 /****************************************************************************/
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 146 int fifo_put32(fifo_t *fifo, uint32_t element) {
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 147 // Check if FIFO is full
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 148 if ((fifo->windex == (fifo->rindex - 1)) ||
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 149 ((fifo->rindex == 0) && (fifo->windex == (fifo->length - 1)))) {
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 150 return -1;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 151 }
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 152
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 153 // atomic FIFO access
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 154 __disable_irq();
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 155
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 156 // Put data into FIFO
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 157 ((uint32_t *)(fifo->data))[fifo->windex] = element;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 158
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 159 // Increment pointer
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 160 fifo->windex++;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 161 if (fifo->windex == fifo->length) {
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 162 fifo->windex = 0;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 163 }
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 164
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 165 __enable_irq();
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 166
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 167 return 0;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 168 }
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 169
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 170 /****************************************************************************/
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 171 int fifo_get32(fifo_t *fifo, uint32_t *element) {
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 172 // Check if FIFO is empty
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 173 if (fifo->rindex == fifo->windex)
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 174 return -1;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 175
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 176 // atomic FIFO access
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 177 __disable_irq();
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 178
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 179 // Get data from FIFO
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 180 *element = ((uint32_t *)(fifo->data))[fifo->rindex];
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 181
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 182 // Increment pointer
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 183 fifo->rindex++;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 184 if (fifo->rindex == fifo->length) {
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 185 fifo->rindex = 0;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 186 }
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 187
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 188 __enable_irq();
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 189
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 190 return 0;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 191 }
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 192 /****************************************************************************/
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 193 void fifo_clear(fifo_t *fifo) {
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 194 // atomic FIFO access
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 195 __disable_irq();
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 196
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 197 fifo->rindex = 0;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 198 fifo->windex = 0;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 199
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 200 __enable_irq();
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 201 }
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 202
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 203 /****************************************************************************/
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 204 int fifo_empty(fifo_t *fifo) { return (fifo->rindex == fifo->windex); }
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 205
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 206 /****************************************************************************/
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 207 int fifo_full(fifo_t *fifo) {
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 208 int retval;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 209
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 210 // atomic FIFO access
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 211 __disable_irq();
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 212 retval = ((fifo->windex == (fifo->rindex - 1)) ||
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 213 ((fifo->rindex == 0) && (fifo->windex == (fifo->length - 1))));
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 214 __enable_irq();
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 215
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 216 return retval;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 217 }
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 218
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 219 /****************************************************************************/
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 220 unsigned int fifo_level(fifo_t *fifo) {
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 221 uint16_t value;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 222
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 223 // atomic FIFO access
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 224 __disable_irq();
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 225
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 226 if (fifo->windex >= fifo->rindex) {
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 227 value = fifo->windex - fifo->rindex;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 228 } else {
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 229 value = fifo->length - fifo->rindex + fifo->windex;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 230 }
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 231
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 232 __enable_irq();
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 233
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 234 return value;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 235 }
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 236
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 237 /****************************************************************************/
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 238 unsigned int fifo_remaining(fifo_t *fifo) {
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 239 uint16_t value;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 240
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 241 // atomic FIFO access
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 242 __disable_irq();
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 243
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 244 if (fifo->rindex > fifo->windex) {
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 245 value = fifo->rindex - fifo->windex - 1;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 246 } else {
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 247 value = fifo->length - fifo->windex + fifo->rindex - 1;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 248 }
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 249
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 250 __enable_irq();
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 251
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 252 return value;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 253 }
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 254