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