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