repo time

Dependencies:   mbed MAX14720 MAX30205 USBDevice

Committer:
darienf
Date:
Tue Apr 06 06:41:40 2021 +0000
Revision:
20:6d2af70c92ab
another repo

Who changed what in which revision?

UserRevisionLine numberNew contents of line
darienf 20:6d2af70c92ab 1 /*******************************************************************************
darienf 20:6d2af70c92ab 2 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
darienf 20:6d2af70c92ab 3 *
darienf 20:6d2af70c92ab 4 * Permission is hereby granted, free of charge, to any person obtaining a
darienf 20:6d2af70c92ab 5 * copy of this software and associated documentation files (the "Software"),
darienf 20:6d2af70c92ab 6 * to deal in the Software without restriction, including without limitation
darienf 20:6d2af70c92ab 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
darienf 20:6d2af70c92ab 8 * and/or sell copies of the Software, and to permit persons to whom the
darienf 20:6d2af70c92ab 9 * Software is furnished to do so, subject to the following conditions:
darienf 20:6d2af70c92ab 10 *
darienf 20:6d2af70c92ab 11 * The above copyright notice and this permission notice shall be included
darienf 20:6d2af70c92ab 12 * in all copies or substantial portions of the Software.
darienf 20:6d2af70c92ab 13 *
darienf 20:6d2af70c92ab 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
darienf 20:6d2af70c92ab 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
darienf 20:6d2af70c92ab 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
darienf 20:6d2af70c92ab 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
darienf 20:6d2af70c92ab 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
darienf 20:6d2af70c92ab 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
darienf 20:6d2af70c92ab 20 * OTHER DEALINGS IN THE SOFTWARE.
darienf 20:6d2af70c92ab 21 *
darienf 20:6d2af70c92ab 22 * Except as contained in this notice, the name of Maxim Integrated
darienf 20:6d2af70c92ab 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
darienf 20:6d2af70c92ab 24 * Products, Inc. Branding Policy.
darienf 20:6d2af70c92ab 25 *
darienf 20:6d2af70c92ab 26 * The mere transfer of this software does not imply any licenses
darienf 20:6d2af70c92ab 27 * of trade secrets, proprietary technology, copyrights, patents,
darienf 20:6d2af70c92ab 28 * trademarks, maskwork rights, or any other form of intellectual
darienf 20:6d2af70c92ab 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
darienf 20:6d2af70c92ab 30 * ownership rights.
darienf 20:6d2af70c92ab 31 *******************************************************************************
darienf 20:6d2af70c92ab 32 */
darienf 20:6d2af70c92ab 33 #include "Test_MAX30001.h"
darienf 20:6d2af70c92ab 34 #include "Test_Utilities.h"
darienf 20:6d2af70c92ab 35
darienf 20:6d2af70c92ab 36 uint32_t testing_max30001 = 0;
darienf 20:6d2af70c92ab 37 uint32_t testing_ecg_flags[4];
darienf 20:6d2af70c92ab 38
darienf 20:6d2af70c92ab 39 //******************************************************************************
darienf 20:6d2af70c92ab 40 void test_MAX30001(void (*outputString)(const char *)) {
darienf 20:6d2af70c92ab 41 int totalPass = 1;
darienf 20:6d2af70c92ab 42 int pass;
darienf 20:6d2af70c92ab 43 uint32_t foundEcg = 0;
darienf 20:6d2af70c92ab 44 uint32_t foundBioz = 0;
darienf 20:6d2af70c92ab 45 uint32_t foundPace = 0;
darienf 20:6d2af70c92ab 46 uint32_t foundRtoR = 0;
darienf 20:6d2af70c92ab 47 uint32_t id;
darienf 20:6d2af70c92ab 48 char str2[128];
darienf 20:6d2af70c92ab 49 int partVersion; // 0 = 30004
darienf 20:6d2af70c92ab 50 // 1 = 30001
darienf 20:6d2af70c92ab 51 // 2 = 30002
darienf 20:6d2af70c92ab 52 // 3 = 30003
darienf 20:6d2af70c92ab 53 Timer timer;
darienf 20:6d2af70c92ab 54 MAX30001 *max30001;
darienf 20:6d2af70c92ab 55 max30001 = Peripherals::max30001();
darienf 20:6d2af70c92ab 56
darienf 20:6d2af70c92ab 57 // read the id
darienf 20:6d2af70c92ab 58 max30001->max30001_reg_read(MAX30001::INFO, &id);
darienf 20:6d2af70c92ab 59 // read id twice because it needs to be read twice
darienf 20:6d2af70c92ab 60 max30001->max30001_reg_read(MAX30001::INFO, &id);
darienf 20:6d2af70c92ab 61 partVersion = id >> 12;
darienf 20:6d2af70c92ab 62 partVersion = partVersion & 0x3;
darienf 20:6d2af70c92ab 63
darienf 20:6d2af70c92ab 64 // display header
darienf 20:6d2af70c92ab 65 if (partVersion == 0)
darienf 20:6d2af70c92ab 66 outputString("Testing MAX30004|");
darienf 20:6d2af70c92ab 67 if (partVersion == 1) {
darienf 20:6d2af70c92ab 68 outputString("Testing MAX30001|");
darienf 20:6d2af70c92ab 69 outputString("Testing ECG, RtoR, BioZ, PACE|");
darienf 20:6d2af70c92ab 70 }
darienf 20:6d2af70c92ab 71 if (partVersion == 2)
darienf 20:6d2af70c92ab 72 outputString("Testing MAX30002|");
darienf 20:6d2af70c92ab 73 if (partVersion == 3) {
darienf 20:6d2af70c92ab 74 outputString("Testing MAX30003|");
darienf 20:6d2af70c92ab 75 outputString("Only Testing ECG and RtoR|");
darienf 20:6d2af70c92ab 76 }
darienf 20:6d2af70c92ab 77 sprintf(str2, "Device ID = 0x%06X|", id);
darienf 20:6d2af70c92ab 78 outputString(str2);
darienf 20:6d2af70c92ab 79
darienf 20:6d2af70c92ab 80 // clear testing flags
darienf 20:6d2af70c92ab 81 testing_ecg_flags[TESTING_ECG_FLAG] = 0;
darienf 20:6d2af70c92ab 82 testing_ecg_flags[TESTING_BIOZ_FLAG] = 0;
darienf 20:6d2af70c92ab 83 testing_ecg_flags[TESTING_PACE_FLAG] = 0;
darienf 20:6d2af70c92ab 84 testing_ecg_flags[TESTING_RTOR_FLAG] = 0;
darienf 20:6d2af70c92ab 85
darienf 20:6d2af70c92ab 86 // start streams
darienf 20:6d2af70c92ab 87 testing_max30001 = 1;
darienf 20:6d2af70c92ab 88 if (partVersion == 1)
darienf 20:6d2af70c92ab 89 outputString("Start Streaming ECG, RtoR, PACE, BIOZ, CAL enabled, "
darienf 20:6d2af70c92ab 90 "verifying streams...|");
darienf 20:6d2af70c92ab 91 if (partVersion == 3)
darienf 20:6d2af70c92ab 92 outputString(
darienf 20:6d2af70c92ab 93 "Start Streaming ECG, RtoR, CAL enabled, verifying streams...|");
darienf 20:6d2af70c92ab 94 // max30001_CAL_InitStart(0b1, 0b1, 0b1, 0b011, 0x7FF, 0b0);
darienf 20:6d2af70c92ab 95 max30001->max30001_CAL_InitStart(0b1, 0b1, 0b1, 0b011, 0x7FF, 0b0);
darienf 20:6d2af70c92ab 96 max30001->max30001_ECG_InitStart(0b1, 0b1, 0b1, 0b0, 0b10, 0b11, 0x1F, 0b00,
darienf 20:6d2af70c92ab 97 0b00, 0b0, 0b01);
darienf 20:6d2af70c92ab 98 if (partVersion == 1)
darienf 20:6d2af70c92ab 99 max30001->max30001_PACE_InitStart(0b1, 0b0, 0b0, 0b1, 0x0, 0b0, 0b00, 0b0,
darienf 20:6d2af70c92ab 100 0b0);
darienf 20:6d2af70c92ab 101 if (partVersion == 1)
darienf 20:6d2af70c92ab 102 max30001->max30001_BIOZ_InitStart(0b1, 0b1, 0b1, 0b10, 0b11, 0b00, 7, 0b0,
darienf 20:6d2af70c92ab 103 0b010, 0b0, 0b10, 0b00, 0b00, 2, 0b0,
darienf 20:6d2af70c92ab 104 0b111, 0b0000);
darienf 20:6d2af70c92ab 105 max30001->max30001_RtoR_InitStart(0b1, 0b0011, 0b1111, 0b00, 0b0011, 0b000001,
darienf 20:6d2af70c92ab 106 0b00, 0b000, 0b01);
darienf 20:6d2af70c92ab 107 max30001->max30001_Rbias_FMSTR_Init(0b01, 0b10, 0b1, 0b1, 0b00);
darienf 20:6d2af70c92ab 108 max30001->max30001_synch();
darienf 20:6d2af70c92ab 109
darienf 20:6d2af70c92ab 110 // look for each stream
darienf 20:6d2af70c92ab 111 timer.start();
darienf 20:6d2af70c92ab 112 while (1) {
darienf 20:6d2af70c92ab 113 if ((foundEcg == 0) && (testing_ecg_flags[TESTING_ECG_FLAG] == 1)) {
darienf 20:6d2af70c92ab 114 foundEcg = 1;
darienf 20:6d2af70c92ab 115 outputString("ECG Stream: PASS|");
darienf 20:6d2af70c92ab 116 }
darienf 20:6d2af70c92ab 117 if ((foundBioz == 0) && (testing_ecg_flags[TESTING_BIOZ_FLAG] == 1)) {
darienf 20:6d2af70c92ab 118 foundBioz = 1;
darienf 20:6d2af70c92ab 119 outputString("Bioz Stream: PASS|");
darienf 20:6d2af70c92ab 120 }
darienf 20:6d2af70c92ab 121 if ((foundPace == 0) && (testing_ecg_flags[TESTING_PACE_FLAG] == 1)) {
darienf 20:6d2af70c92ab 122 foundPace = 1;
darienf 20:6d2af70c92ab 123 outputString("PACE Stream: PASS|");
darienf 20:6d2af70c92ab 124 }
darienf 20:6d2af70c92ab 125 if ((foundRtoR == 0) && (testing_ecg_flags[TESTING_RTOR_FLAG] == 1)) {
darienf 20:6d2af70c92ab 126 foundRtoR = 1;
darienf 20:6d2af70c92ab 127 outputString("RtoR Stream: PASS|");
darienf 20:6d2af70c92ab 128 }
darienf 20:6d2af70c92ab 129 if ((foundEcg == 1) && (foundBioz == 1) && (foundPace == 1) &&
darienf 20:6d2af70c92ab 130 (foundRtoR == 1) && (partVersion == 1)) {
darienf 20:6d2af70c92ab 131 break;
darienf 20:6d2af70c92ab 132 }
darienf 20:6d2af70c92ab 133 if ((foundEcg == 1) && (foundRtoR == 1) && (partVersion == 3)) {
darienf 20:6d2af70c92ab 134 break;
darienf 20:6d2af70c92ab 135 }
darienf 20:6d2af70c92ab 136 if (timer.read() >= TESTING_MAX30001_TIMEOUT_SECONDS) {
darienf 20:6d2af70c92ab 137 break;
darienf 20:6d2af70c92ab 138 }
darienf 20:6d2af70c92ab 139 }
darienf 20:6d2af70c92ab 140 timer.stop();
darienf 20:6d2af70c92ab 141 if (foundEcg == 0) {
darienf 20:6d2af70c92ab 142 outputString("ECG Stream: FAIL|");
darienf 20:6d2af70c92ab 143 totalPass &= pass;
darienf 20:6d2af70c92ab 144 }
darienf 20:6d2af70c92ab 145 if ((foundBioz == 0) && (partVersion == 1)) {
darienf 20:6d2af70c92ab 146 outputString("Bioz Stream: FAIL|");
darienf 20:6d2af70c92ab 147 totalPass &= pass;
darienf 20:6d2af70c92ab 148 }
darienf 20:6d2af70c92ab 149 if ((foundPace == 0) && (partVersion == 1)) {
darienf 20:6d2af70c92ab 150 outputString("PACE Stream: FAIL|");
darienf 20:6d2af70c92ab 151 totalPass &= pass;
darienf 20:6d2af70c92ab 152 }
darienf 20:6d2af70c92ab 153 if (foundRtoR == 0) {
darienf 20:6d2af70c92ab 154 outputString("RtoR Stream: FAIL|");
darienf 20:6d2af70c92ab 155 totalPass &= pass;
darienf 20:6d2af70c92ab 156 }
darienf 20:6d2af70c92ab 157
darienf 20:6d2af70c92ab 158 // stop all streams
darienf 20:6d2af70c92ab 159 max30001->max30001_Stop_ECG();
darienf 20:6d2af70c92ab 160 if (partVersion == 1)
darienf 20:6d2af70c92ab 161 max30001->max30001_Stop_PACE();
darienf 20:6d2af70c92ab 162 if (partVersion == 1)
darienf 20:6d2af70c92ab 163 max30001->max30001_Stop_BIOZ();
darienf 20:6d2af70c92ab 164 max30001->max30001_Stop_RtoR();
darienf 20:6d2af70c92ab 165 testing_max30001 = 0;
darienf 20:6d2af70c92ab 166 // final results
darienf 20:6d2af70c92ab 167 outputString("Result: ");
darienf 20:6d2af70c92ab 168 _printPassFail(totalPass, 0, outputString);
darienf 20:6d2af70c92ab 169 }