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
Date:
Tue Jul 24 15:22:35 2018 +0300
Revision:
13:6031b0bd9773
Parent:
0:8e4630a71eb1
.hgtags is added.

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 "RpcServer.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 #include "Streaming.h"
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 36 #include "Peripherals.h"
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 37 #include "MAX30001.h"
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 38 #include "Test_MAX30001.h"
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 39 #include "Peripherals.h"
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 40
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 41 bool streaming = FALSE;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 42 bool dataLogging = FALSE;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 43
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 44 /**
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 45 * @brief Encodes a 0x55 0xAA signature and a simple checksum to the id byte in
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 46 * the 32 bit field
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 47 * @param id Streaming ID
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 48 */
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 49 uint32_t StreamIdChecksumCalculate(uint32_t id) {
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 50 uint32_t sum;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 51 uint32_t calculated;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 52 sum = 0x55;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 53 sum += 0xAA;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 54 sum += id;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 55 sum &= 0xFF;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 56 sum = sum << 8;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 57 calculated = 0x55AA0000 + sum + id;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 58 return calculated;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 59 }
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 60
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 61 /**
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 62 * @brief Creates a packet that will be streamed via USB or saved into flash
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 63 * datalog memory
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 64 * @brief the packet created will be inserted into a fifo to be streamed at a
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 65 * later time
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 66 * @param id Streaming ID
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 67 * @param buffer Pointer to a uint32 array that contains the data to include in
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 68 * the packet
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 69 * @param number Number of elements in the buffer
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 70 */
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 71 void StreamPacketUint32(uint32_t id, uint32_t *buffer, uint32_t number) {
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 72 uint32_t checksumId;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 73 if (streaming == TRUE || dataLogging == TRUE) {
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 74 checksumId = StreamIdChecksumCalculate(id);
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 75 StreamFifoId(checksumId);
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 76 StreamFifoTimeStamp();
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 77 StreamFifoLength(number);
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 78 StreamFifoUint32Array(buffer, number);
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 79 }
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 80 if (testing_max30001 == 1) {
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 81 if (id == MAX30001_DATA_ECG)
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 82 testing_ecg_flags[TESTING_ECG_FLAG] = 1;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 83 if (id == MAX30001_DATA_BIOZ)
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 84 testing_ecg_flags[TESTING_BIOZ_FLAG] = 1;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 85 if (id == MAX30001_DATA_PACE)
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 86 testing_ecg_flags[TESTING_PACE_FLAG] = 1;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 87 if (id == MAX30001_DATA_RTOR)
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 88 testing_ecg_flags[TESTING_RTOR_FLAG] = 1;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 89 }
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 /**
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 93 * @brief Insert a buffer into the out going fifo
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 94 * @param buffer Array of uint32 to send to the fifo
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 95 * @param len Length of the array
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 96 */
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 97 int StreamFifoUint32Array(uint32_t buffer[], uint32_t len) {
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 98 int status;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 99 uint32_t i;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 100 for (i = 0; i < len; i++) {
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 101 status = fifo_put32(GetStreamOutFifo(), buffer[i]);
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 102 if (status == -1) {
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 103 printf("FIFO_OF!");
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 104 fflush(stdout);
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 105 while (1)
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 106 ;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 107 }
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 108 }
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 109 return 0;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 110 }
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 111
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 112 /**
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 113 * @brief Insert a timestamp into the out going fifo
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 114 */
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 115 int StreamFifoTimeStamp(void) {
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 116 int status;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 117 // uint32_t timer = timestamp_GetCurrent(); //RTC_GetVal();
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 118 uint32_t timer = (uint32_t)Peripherals::timestampTimer()->read_us();
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 119 status = fifo_put32(GetStreamOutFifo(), timer);
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 120 if (status == -1) {
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 121 printf("FIFO_OF!");
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 122 fflush(stdout);
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 123 while (1)
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 124 ;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 125 }
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 126 return 0;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 127 }
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 128
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 129 /**
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 130 * @brief Insert a packet id into the out going fifo
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 131 * @param id The uint32 packet id
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 132 */
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 133 int StreamFifoId(uint32_t id) {
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 134 int status;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 135 status = fifo_put32(GetStreamOutFifo(), id);
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 136 if (status == -1) {
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 137 printf("FIFO_OF!");
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 138 fflush(stdout);
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 139 while (1)
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 140 ;
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 * @brief Insert a length value into the out going fifo
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 147 * @param length A uint32 number representing a length
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 148 */
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 149 int StreamFifoLength(uint32_t length) {
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 150 int status;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 151 status = fifo_put32(GetStreamOutFifo(), length);
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 152 if (status == -1) {
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 153 printf("FIFO_OF!");
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 154 fflush(stdout);
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 155 while (1)
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 156 ;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 157 }
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 158 return 0;
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 159 }
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 160
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 161 /**
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 162 * @brief Return a value that indicates if the system is streaming data
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 163 * @returns Returns a one or zero value
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 164 */
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 165 uint8_t IsStreaming(void) { return streaming; }
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 166
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 167 /**
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 168 * @brief Set a flag to indicate if streaming is enabled
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 169 * @param state A one or zero value
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 170 */
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 171 void SetStreaming(uint8_t state) { streaming = state; }
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 172
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 173 /**
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 174 * @brief Set a flag to indicate if datalogging is enabled
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 175 * @param state A one or zero value
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 176 */
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 177 void SetDataLoggingStream(uint8_t state) { dataLogging = state; }
Emre.Eken@IST-LT-35101.maxim-ic.internal 0:8e4630a71eb1 178