MAX32620HSP (MAXREFDES100) RPC Example for Graphical User Interface

Dependencies:   USBDevice

Fork of HSP_Release by Jerry Bradshaw

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Streaming.cpp Source File

Streaming.cpp

00001 /*******************************************************************************
00002  * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
00003  *
00004  * Permission is hereby granted, free of charge, to any person obtaining a
00005  * copy of this software and associated documentation files (the "Software"),
00006  * to deal in the Software without restriction, including without limitation
00007  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00008  * and/or sell copies of the Software, and to permit persons to whom the
00009  * Software is furnished to do so, subject to the following conditions:
00010  *
00011  * The above copyright notice and this permission notice shall be included
00012  * in all copies or substantial portions of the Software.
00013  *
00014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00015  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00016  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00017  * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
00018  * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00019  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00020  * OTHER DEALINGS IN THE SOFTWARE.
00021  *
00022  * Except as contained in this notice, the name of Maxim Integrated
00023  * Products, Inc. shall not be used except as stated in the Maxim Integrated
00024  * Products, Inc. Branding Policy.
00025  *
00026  * The mere transfer of this software does not imply any licenses
00027  * of trade secrets, proprietary technology, copyrights, patents,
00028  * trademarks, maskwork rights, or any other form of intellectual
00029  * property whatsoever. Maxim Integrated Products, Inc. retains all
00030  * ownership rights.
00031  *******************************************************************************
00032  */
00033 #include "RpcServer.h"
00034 #include "RpcFifo.h"
00035 #include "Streaming.h"
00036 #include "Peripherals.h"
00037 #include "Test_MAX30101.h"
00038 #include "Test_MAX30001.h"
00039 #include "MAX30001.h"
00040 #include "MAX30101.h"
00041 #include "Peripherals.h"
00042 
00043 bool streaming = FALSE;
00044 bool dataLogging = FALSE;
00045 
00046 /**
00047 * @brief Encodes a 0x55 0xAA signature and a simple checksum to the id byte in
00048 * the 32 bit field
00049 * @param id Streaming ID
00050 */
00051 uint32_t StreamIdChecksumCalculate(uint32_t id) {
00052   uint32_t sum;
00053   uint32_t calculated;
00054   sum = 0x55;
00055   sum += 0xAA;
00056   sum += id;
00057   sum &= 0xFF;
00058   sum = sum << 8;
00059   calculated = 0x55AA0000 + sum + id;
00060   return calculated;
00061 }
00062 
00063 /**
00064 * @brief Creates a packet that will be streamed via USB or saved into flash
00065 * datalog memory
00066 * @brief the packet created will be inserted into a fifo to be streamed at a
00067 * later time
00068 * @param id Streaming ID
00069 * @param buffer Pointer to a uint32 array that contains the data to include in
00070 * the packet
00071 * @param number Number of elements in the buffer
00072 */
00073 void StreamPacketUint32(uint32_t id, uint32_t *buffer, uint32_t number) {
00074   uint32_t checksumId;
00075   if (streaming == TRUE || dataLogging == TRUE) {
00076     checksumId = StreamIdChecksumCalculate(id);
00077     StreamFifoId(checksumId);
00078     StreamFifoTimeStamp();
00079     StreamFifoLength(number);
00080     StreamFifoUint32Array(buffer, number);
00081   }
00082   if (testing_max30001 == 1) {
00083     if (id == MAX30001_DATA_ECG)
00084       testing_ecg_flags[TESTING_ECG_FLAG] = 1;
00085     if (id == MAX30001_DATA_BIOZ)
00086       testing_ecg_flags[TESTING_BIOZ_FLAG] = 1;
00087     if (id == MAX30001_DATA_PACE)
00088       testing_ecg_flags[TESTING_PACE_FLAG] = 1;
00089     if (id == MAX30001_DATA_RTOR)
00090       testing_ecg_flags[TESTING_RTOR_FLAG] = 1;
00091   }
00092   if (testing_max30101 == 1) {
00093     if (id == (MAX30101_OXIMETER_DATA + 1))
00094       testing_max30101_flags[TESTING_HR_FLAG] = 1;
00095     if (id == (MAX30101_OXIMETER_DATA + 2))
00096       testing_max30101_flags[TESTING_SPO2_FLAG] = 1;
00097     if (id == (MAX30101_OXIMETER_DATA + 3))
00098       testing_max30101_flags[TESTING_MULTI_FLAG] = 1;
00099   }
00100 }
00101 
00102 /**
00103 * @brief Insert a buffer into the out going fifo
00104 * @param buffer Array of uint32 to send to the fifo
00105 * @param len Length of the array
00106 */
00107 int StreamFifoUint32Array(uint32_t buffer[], uint32_t len) {
00108   int status;
00109   uint32_t i;
00110   for (i = 0; i < len; i++) {
00111     status = fifo_put32(GetStreamOutFifo(), buffer[i]);
00112     if (status == -1) {
00113       printf("FIFO_OF!");
00114       fflush(stdout);
00115       while (1)
00116         ;
00117     }
00118   }
00119   return 0;
00120 }
00121 
00122 /**
00123 * @brief Insert a timestamp into the out going fifo
00124 */
00125 int StreamFifoTimeStamp(void) {
00126   int status;
00127   // uint32_t timer = timestamp_GetCurrent(); //RTC_GetVal();
00128   uint32_t timer = (uint32_t)Peripherals::timestampTimer()->read_us();
00129   status = fifo_put32(GetStreamOutFifo(), timer);
00130   if (status == -1) {
00131     printf("FIFO_OF!");
00132     fflush(stdout);
00133     while (1)
00134       ;
00135   }
00136   return 0;
00137 }
00138 
00139 /**
00140 * @brief Insert a packet id into the out going fifo
00141 * @param id The uint32 packet id
00142 */
00143 int StreamFifoId(uint32_t id) {
00144   int status;
00145   status = fifo_put32(GetStreamOutFifo(), id);
00146   if (status == -1) {
00147     printf("FIFO_OF!");
00148     fflush(stdout);
00149     while (1)
00150       ;
00151   }
00152   return 0;
00153 }
00154 
00155 /**
00156 * @brief Insert a length value into the out going fifo
00157 * @param length A uint32 number representing a length
00158 */
00159 int StreamFifoLength(uint32_t length) {
00160   int status;
00161   status = fifo_put32(GetStreamOutFifo(), length);
00162   if (status == -1) {
00163     printf("FIFO_OF!");
00164     fflush(stdout);
00165     while (1)
00166       ;
00167   }
00168   return 0;
00169 }
00170 
00171 /**
00172 * @brief Return a value that indicates if the system is streaming data
00173 * @returns Returns a one or zero value
00174 */
00175 uint8_t IsStreaming(void) { return streaming; }
00176 
00177 /**
00178 * @brief Set a flag to indicate if streaming is enabled
00179 * @param state A one or zero value
00180 */
00181 void SetStreaming(uint8_t state) { streaming = state; }
00182 
00183 /**
00184 * @brief Set a flag to indicate if datalogging is enabled
00185 * @param state A one or zero value
00186 */
00187 void SetDataLoggingStream(uint8_t state) { dataLogging = state; }