Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:02

0001 /*
0002  * Copyright 2020-2022 NXP
0003  * All rights reserved.
0004  *
0005  *
0006  * SPDX-License-Identifier: BSD-3-Clause
0007  */
0008 #ifndef _FSL_TEMPMON_H_
0009 #define _FSL_TEMPMON_H_
0010 
0011 #include "fsl_common.h"
0012 
0013 /*!
0014  * @addtogroup tempsensor
0015  * @{
0016  */
0017 
0018 /*! @file */
0019 
0020 /*******************************************************************************
0021  * Definitions
0022  ******************************************************************************/
0023 
0024 /*! @name Driver version */
0025 /*@{*/
0026 #define FSL_TMPSNS_DRIVER_VERSION (MAKE_VERSION(2, 1, 0))
0027 /*@}*/
0028 
0029 /*! @brief TMPSNS interrupt status enable type, tmpsns_interrupt_status_enable_t. */
0030 enum
0031 {
0032     kTEMPSENSOR_HighTempInterruptStatusEnable =
0033         TMPSNS_CTRL1_HIGH_TEMP_IE_MASK, /*!< High temperature interrupt status enable.*/
0034     kTEMPSENSOR_LowTempInterruptStatusEnable =
0035         TMPSNS_CTRL1_LOW_TEMP_IE_MASK, /*!< Low temperature interrupt status enable.*/
0036     kTEMPSENSOR_PanicTempInterruptStatusEnable =
0037         TMPSNS_CTRL1_PANIC_TEMP_IE_MASK, /*!< Panic temperature interrupt status enable.*/
0038     kTEMPSENSOR_FinishInterruptStatusEnable = TMPSNS_CTRL1_FINISH_IE_MASK, /*!< Finish interrupt enable.*/
0039 };
0040 
0041 /*! @brief TMPSNS interrupt status type, tmpsns_interrupt_status_t. */
0042 enum
0043 {
0044     kTEMPSENSOR_HighTempInterruptStatus  = TMPSNS_STATUS0_HIGH_TEMP_MASK,  /*!< High temperature interrupt status.*/
0045     kTEMPSENSOR_LowTempInterruptStatus   = TMPSNS_STATUS0_LOW_TEMP_MASK,   /*!< Low temperature interrupt status.*/
0046     kTEMPSENSOR_PanicTempInterruptStatus = TMPSNS_STATUS0_PANIC_TEMP_MASK, /*!< Panic temperature interrupt status.*/
0047 };
0048 
0049 /*! @brief TMPSNS measure mode, tempsensor_measure_mode. */
0050 typedef enum
0051 {
0052     kTEMPSENSOR_SingleMode     = 0U, /*!< Single measurement mode.*/
0053     kTEMPSENSOR_ContinuousMode = 1U, /*!< Continuous measurement mode.*/
0054 } tmpsns_measure_mode_t;
0055 
0056 /*! @brief TMPSNS temperature structure. */
0057 typedef struct _tmpsns_config
0058 {
0059     tmpsns_measure_mode_t measureMode; /*!< The temperature measure mode.*/
0060     uint16_t frequency;                /*!< The temperature measure frequency.*/
0061     int32_t highAlarmTemp;             /*!< The high alarm temperature.*/
0062     int32_t panicAlarmTemp;            /*!< The panic alarm temperature.*/
0063     int32_t lowAlarmTemp;              /*!< The low alarm temperature.*/
0064 } tmpsns_config_t;
0065 
0066 /*! @brief TMPSNS alarm mode. */
0067 typedef enum _tmpsns_alarm_mode
0068 {
0069     kTEMPMON_HighAlarmMode  = 0U, /*!< The high alarm temperature interrupt mode.*/
0070     kTEMPMON_PanicAlarmMode = 1U, /*!< The panic alarm temperature interrupt mode.*/
0071     kTEMPMON_LowAlarmMode   = 2U, /*!< The low alarm temperature interrupt mode.*/
0072 } tmpsns_alarm_mode_t;
0073 
0074 /*******************************************************************************
0075  * API
0076  ******************************************************************************/
0077 
0078 #if defined(__cplusplus)
0079 extern "C" {
0080 #endif
0081 
0082 /*!
0083  * @brief Initializes the TMPSNS module.
0084  *
0085  * @param base TMPSNS base pointer
0086  * @param config Pointer to configuration structure.
0087  */
0088 void TMPSNS_Init(TMPSNS_Type *base, const tmpsns_config_t *config);
0089 
0090 /*!
0091  * @brief Deinitializes the TMPSNS module.
0092  *
0093  * @param base TMPSNS base pointer
0094  */
0095 void TMPSNS_Deinit(TMPSNS_Type *base);
0096 
0097 /*!
0098  * @brief Gets the default configuration structure.
0099  *
0100  * This function initializes the TMPSNS configuration structure to a default value. The default
0101  * values are:
0102  *   tempmonConfig->frequency = 0x02U;
0103  *   tempmonConfig->highAlarmTemp = 44U;
0104  *   tempmonConfig->panicAlarmTemp = 90U;
0105  *   tempmonConfig->lowAlarmTemp = 39U;
0106  *
0107  * @param config Pointer to a configuration structure.
0108  */
0109 void TMPSNS_GetDefaultConfig(tmpsns_config_t *config);
0110 
0111 /*!
0112  * @brief start the temperature measurement process.
0113  *
0114  * @param base TMPSNS base pointer.
0115  */
0116 void TMPSNS_StartMeasure(TMPSNS_Type *base);
0117 
0118 /*!
0119  * @brief stop the measurement process.
0120  *
0121  * @param base TMPSNS base pointer
0122  */
0123 void TMPSNS_StopMeasure(TMPSNS_Type *base);
0124 
0125 /*!
0126  * @brief Get current temperature with the fused temperature calibration data.
0127  *
0128  * @param base TMPSNS base pointer
0129  * @return current temperature with degrees Celsius.
0130  */
0131 float TMPSNS_GetCurrentTemperature(TMPSNS_Type *base);
0132 
0133 /*!
0134  * @brief Set the temperature count (raw sensor output) that will generate an alarm interrupt.
0135  *
0136  * @param base TMPSNS base pointer
0137  * @param tempVal The alarm temperature with degrees Celsius
0138  * @param alarmMode The alarm mode.
0139  */
0140 void TMPSNS_SetTempAlarm(TMPSNS_Type *base, int32_t tempVal, tmpsns_alarm_mode_t alarmMode);
0141 
0142 /*!
0143  * @brief Enable interrupt status.
0144  *
0145  * @param base TMPSNS base pointer
0146  * @param mask The interrupts to enable from tmpsns_interrupt_status_enable_t.
0147  */
0148 void TMPSNS_EnableInterrupt(TMPSNS_Type *base, uint32_t mask);
0149 
0150 /*!
0151  * @brief Disable interrupt status.
0152  *
0153  * @param base TMPSNS base pointer
0154  * @param mask The interrupts to disable from tmpsns_interrupt_status_enable_t.
0155  */
0156 void TMPSNS_DisableInterrupt(TMPSNS_Type *base, uint32_t mask);
0157 
0158 /*!
0159  * @brief Get interrupt status flag.
0160  *
0161  * @param base TMPSNS base pointer
0162  * @param mask The interrupts to disable from tmpsns_interrupt_status_t.
0163  */
0164 static inline uint32_t TMPSNS_GetInterruptFlags(TMPSNS_Type *base)
0165 {
0166     return base->STATUS0;
0167 }
0168 
0169 /*!
0170  * @brief Clear interrupt status flag.
0171  *
0172  * @param base TMPSNS base pointer
0173  * @param mask The interrupts to disable from tmpsns_interrupt_status_t.
0174  */
0175 static inline void TMPSNS_ClearInterruptFlags(TMPSNS_Type *base, uint32_t mask)
0176 {
0177     base->STATUS0 = mask;
0178 }
0179 
0180 #if defined(__cplusplus)
0181 }
0182 #endif
0183 
0184 /*! @}*/
0185 
0186 #endif /* _FSL_TEMPMON_H_ */