1 /* 2 ** Licensed under the Apache License, Version 2.0 (the "License"); 3 ** you may not use this file except in compliance with the License. 4 ** You may obtain a copy of the License at 5 ** 6 ** http://www.apache.org/licenses/LICENSE-2.0 7 ** 8 ** Unless required by applicable law or agreed to in writing, software 9 ** distributed under the License is distributed on an "AS IS" BASIS, 10 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 ** See the License for the specific language governing permissions and 12 ** limitations under the License. 13 ** 14 ** Copyright 2023 NXP 15 ** 16 */ 17 #pragma once 18 19 #include <fstream> 20 #include <mutex> 21 22 using namespace std; 23 24 class phNxpTempMgr { 25 public: 26 // mark copy constructor deleted 27 phNxpTempMgr(const phNxpTempMgr&) = delete; 28 29 /** 30 * Get singleton instance of phNxpTempMgr. 31 */ 32 static phNxpTempMgr& GetInstance(); 33 34 /** 35 * Record current temperature status. 36 */ 37 void UpdateICTempStatus(uint8_t* p_ntf, uint16_t p_len); 38 39 /** 40 * Apply delay if temp of any of IC module is NOK. 41 */ 42 void Wait(); 43 44 /** 45 * Reset the state to default. 46 */ 47 void Reset(bool reset_timer = true); 48 49 /** 50 * Return current temp status. 51 */ IsICTempOk(void)52 inline bool IsICTempOk(void) { 53 std::lock_guard<std::mutex> lock(ic_temp_mutex_); 54 return is_ic_temp_ok_; 55 } 56 57 private: 58 // constructor 59 phNxpTempMgr(); 60 61 /** 62 * Update IC temperature status with mutex locked. 63 */ 64 void UpdateTempStatusLocked(bool temp_status); 65 66 std::mutex ic_temp_mutex_; // Mutex for protecting shared resources 67 68 // tracks IC temp status 69 bool is_ic_temp_ok_; 70 71 // delay(in ms) before sending the next nci cmd to NFCC 72 uint32_t total_delay_ms_; 73 uint32_t timeout_timer_id_; // ID of the tempNTF timeout callback timer 74 }; 75