MAX32620HSP (MAXREFDES100) RPC Example for Graphical User Interface

Dependencies:   USBDevice

Fork of HSP_Release by Jerry Bradshaw

This is an example program for the MAX32620HSP (MAXREFDES100 Health Sensor Platform). It demonstrates all the features of the platform and works with a companion graphical user interface (GUI) to help evaluate/configure/monitor the board. Go to the MAXREFDES100 product page and click on "design resources" to download the companion software. The GUI connects to the board through an RPC interface on a virtual serial port over the USB interface.

The RPC interface provides access to all the features of the board and is available to interface with other development environments such Matlab. This firmware provides realtime data streaming through the RPC interface over USB, and also provides the ability to log the data to flash for untethered battery operation. The data logging settings are configured through the GUI, and the GUI also provides the interface to download logged data.

Details on the RPC interface can be found here: HSP RPC Interface Documentation

Windows

With this program loaded, the MAX32620HSP will appear on your computer as a serial port. On Mac and Linux, this will happen by default. For Windows, you need to install a driver: HSP serial port windows driver

For more details about this platform and how to use it, see the MAXREFDES100 product page.

Committer:
jbradshaw
Date:
Tue Apr 25 10:47:10 2017 -0500
Revision:
3:8e9b9f5818aa
Parent:
0:e4a10ed6eb92
Removed Bulk Erasing, instead a small number of bytes are sampled from each and every page to determine if sector is "dirty", if so sector is erased
Prevents device from sleeping when the firmware detects a series of binary flash page RPC transfers, this increases flash page transfers by %450
when 200mS elapse with the last flash page transfer, normal sleep behaviour is resumed

Who changed what in which revision?

UserRevisionLine numberNew 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 "ServiceNonInterrupt.h"
jbradshaw 0:e4a10ed6eb92 34 #include "Streaming.h"
jbradshaw 0:e4a10ed6eb92 35 #include "BMP280.h"
jbradshaw 0:e4a10ed6eb92 36 #include "PacketFifo.h"
jbradshaw 0:e4a10ed6eb92 37 #include "MAX30205.h"
jbradshaw 0:e4a10ed6eb92 38 #include "Stream.h"
jbradshaw 0:e4a10ed6eb92 39 #include "BMP280.h"
jbradshaw 0:e4a10ed6eb92 40 #include "PacketFifo.h"
jbradshaw 0:e4a10ed6eb92 41 #include "Peripherals.h"
jbradshaw 0:e4a10ed6eb92 42 #include "Device_Logging.h"
jbradshaw 0:e4a10ed6eb92 43
jbradshaw 0:e4a10ed6eb92 44 /// timer used for devices that do not have interrupt capability
jbradshaw 0:e4a10ed6eb92 45 static Timer nonInterruptTimer;
jbradshaw 0:e4a10ed6eb92 46
jbradshaw 0:e4a10ed6eb92 47 /// reference to logging object for the BMP280
jbradshaw 0:e4a10ed6eb92 48 extern Device_Logging *bmp280_Logging;
jbradshaw 0:e4a10ed6eb92 49 /// reference to logging object for the MAX30205 (instance 0)
jbradshaw 0:e4a10ed6eb92 50 extern Device_Logging *MAX30205_0_Logging;
jbradshaw 0:e4a10ed6eb92 51 /// reference to logging object for the MAX30205 (instance 1)
jbradshaw 0:e4a10ed6eb92 52 extern Device_Logging *MAX30205_1_Logging;
jbradshaw 0:e4a10ed6eb92 53
jbradshaw 0:e4a10ed6eb92 54 /**
jbradshaw 0:e4a10ed6eb92 55 * @brief Initialize the book keeping variables for non interrupt devices
jbradshaw 0:e4a10ed6eb92 56 */
jbradshaw 0:e4a10ed6eb92 57 void ServiceNonInterrupt_Init(void) {
jbradshaw 0:e4a10ed6eb92 58 // clear out the next time member in the device logging class
jbradshaw 0:e4a10ed6eb92 59 // this is so that the devices are sampled the very first go-around
jbradshaw 0:e4a10ed6eb92 60 bmp280_Logging->setNextSampleTime(0);
jbradshaw 0:e4a10ed6eb92 61 MAX30205_0_Logging->setNextSampleTime(0);
jbradshaw 0:e4a10ed6eb92 62 MAX30205_1_Logging->setNextSampleTime(0);
jbradshaw 0:e4a10ed6eb92 63 }
jbradshaw 0:e4a10ed6eb92 64
jbradshaw 0:e4a10ed6eb92 65 /**
jbradshaw 0:e4a10ed6eb92 66 * @brief Stop the 1 second timer
jbradshaw 0:e4a10ed6eb92 67 */
jbradshaw 0:e4a10ed6eb92 68 void ServiceNonInterrupt_StartTimer(void) {
jbradshaw 0:e4a10ed6eb92 69 nonInterruptTimer.start();
jbradshaw 0:e4a10ed6eb92 70 nonInterruptTimer.reset();
jbradshaw 0:e4a10ed6eb92 71 }
jbradshaw 0:e4a10ed6eb92 72
jbradshaw 0:e4a10ed6eb92 73 /**
jbradshaw 0:e4a10ed6eb92 74 * @brief Stop the 1 second timer
jbradshaw 0:e4a10ed6eb92 75 */
jbradshaw 0:e4a10ed6eb92 76 void ServiceNonInterrupt_StopTimer(void) { nonInterruptTimer.stop(); }
jbradshaw 0:e4a10ed6eb92 77
jbradshaw 0:e4a10ed6eb92 78 /**
jbradshaw 0:e4a10ed6eb92 79 * @brief Get the current count of the timer
jbradshaw 0:e4a10ed6eb92 80 * @return timer count in seconds
jbradshaw 0:e4a10ed6eb92 81 */
jbradshaw 0:e4a10ed6eb92 82 static int ServiceNonInterrupt_GetTimerCount(void) {
jbradshaw 0:e4a10ed6eb92 83 return nonInterruptTimer.read();
jbradshaw 0:e4a10ed6eb92 84 }
jbradshaw 0:e4a10ed6eb92 85
jbradshaw 0:e4a10ed6eb92 86 /**
jbradshaw 0:e4a10ed6eb92 87 * @brief Log the BMP280 sensor value if it is time
jbradshaw 0:e4a10ed6eb92 88 * @param deviceLogging pointer to object that keeps track of logging for a
jbradshaw 0:e4a10ed6eb92 89 * device
jbradshaw 0:e4a10ed6eb92 90 */
jbradshaw 0:e4a10ed6eb92 91 void ServiceNonInterrupt_BMP280(Device_Logging *deviceLogging) {
jbradshaw 0:e4a10ed6eb92 92 int currentTime;
jbradshaw 0:e4a10ed6eb92 93 uint32_t bmp280_data[2]; // index 0 - Temp (deg C), index 1 - Press (Pa).
jbradshaw 0:e4a10ed6eb92 94 // Divide the result by 10 to get the correct answer.
jbradshaw 0:e4a10ed6eb92 95 float temp_C, press_P;
jbradshaw 0:e4a10ed6eb92 96 int nextTime;
jbradshaw 0:e4a10ed6eb92 97
jbradshaw 0:e4a10ed6eb92 98 if (deviceLogging->isLoggingEnabled() == 0)
jbradshaw 0:e4a10ed6eb92 99 return;
jbradshaw 0:e4a10ed6eb92 100 currentTime = ServiceNonInterrupt_GetTimerCount();
jbradshaw 0:e4a10ed6eb92 101 nextTime = deviceLogging->getNextSampleTime();
jbradshaw 0:e4a10ed6eb92 102 if ((nextTime == 0) || (currentTime >= nextTime)) {
jbradshaw 0:e4a10ed6eb92 103 nextTime = currentTime + deviceLogging->getLoggingSampleRate();
jbradshaw 0:e4a10ed6eb92 104 deviceLogging->setNextSampleTime(nextTime);
jbradshaw 0:e4a10ed6eb92 105 Peripherals::bmp280()->ReadCompData(
jbradshaw 0:e4a10ed6eb92 106 &temp_C, &press_P); // Read the Temp (index 0) and Pressure (index 1)
jbradshaw 0:e4a10ed6eb92 107 bmp280_data[0] = (int32_t)(temp_C * 10);
jbradshaw 0:e4a10ed6eb92 108 bmp280_data[1] = (int32_t)(press_P * 10);
jbradshaw 0:e4a10ed6eb92 109 PacketFifo_InsertPacket(PACKET_BMP280_PRESSURE, &bmp280_data[0],
jbradshaw 0:e4a10ed6eb92 110 2); // Read it and insert it into the FIFO
jbradshaw 0:e4a10ed6eb92 111 }
jbradshaw 0:e4a10ed6eb92 112 }
jbradshaw 0:e4a10ed6eb92 113
jbradshaw 0:e4a10ed6eb92 114 /**
jbradshaw 0:e4a10ed6eb92 115 * @brief Log the BMP280 sensor value if it is time
jbradshaw 0:e4a10ed6eb92 116 * @param deviceLogging pointer to object that keeps track of logging for a
jbradshaw 0:e4a10ed6eb92 117 * device
jbradshaw 0:e4a10ed6eb92 118 * @param device pointer to the device instance (MAX30205 instance 0 or MAX30205
jbradshaw 0:e4a10ed6eb92 119 * instance 1)
jbradshaw 0:e4a10ed6eb92 120 * @param packetId packet id that is used when building a packet
jbradshaw 0:e4a10ed6eb92 121 */
jbradshaw 0:e4a10ed6eb92 122 void ServiceNonInterrupt_MAX30205(Device_Logging *deviceLogging,
jbradshaw 0:e4a10ed6eb92 123 MAX30205 *device, uint32_t packetId) {
jbradshaw 0:e4a10ed6eb92 124 int currentTime;
jbradshaw 0:e4a10ed6eb92 125 uint32_t data;
jbradshaw 0:e4a10ed6eb92 126 uint16_t tempData;
jbradshaw 0:e4a10ed6eb92 127 int nextTime;
jbradshaw 0:e4a10ed6eb92 128
jbradshaw 0:e4a10ed6eb92 129 if (deviceLogging->isLoggingEnabled() == 0)
jbradshaw 0:e4a10ed6eb92 130 return;
jbradshaw 0:e4a10ed6eb92 131 currentTime = ServiceNonInterrupt_GetTimerCount();
jbradshaw 0:e4a10ed6eb92 132 nextTime = deviceLogging->getNextSampleTime();
jbradshaw 0:e4a10ed6eb92 133 if ((nextTime == 0) || (currentTime >= nextTime)) {
jbradshaw 0:e4a10ed6eb92 134 nextTime = currentTime + deviceLogging->getLoggingSampleRate();
jbradshaw 0:e4a10ed6eb92 135 deviceLogging->setNextSampleTime(nextTime);
jbradshaw 0:e4a10ed6eb92 136 device->readTemperature(&tempData);
jbradshaw 0:e4a10ed6eb92 137 // assemble this in the correct order
jbradshaw 0:e4a10ed6eb92 138 data = (uint32_t)((tempData >> 8) + ((tempData & 0xFF) << 8));
jbradshaw 0:e4a10ed6eb92 139 PacketFifo_InsertPacket(packetId, &data,
jbradshaw 0:e4a10ed6eb92 140 1); // Read it and insert it into the FIFO
jbradshaw 0:e4a10ed6eb92 141 }
jbradshaw 0:e4a10ed6eb92 142 }