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