tempdrv.c File Reference
TEMPDRV API implementation.
License
Copyright 2018 Silicon Laboratories Inc. www.silabs.com
The licensor of this software is Silicon Laboratories Inc. Your use of this software is governed by the terms of Silicon Labs Master Software License Agreement (MSLA) available at www.silabs.com/about-us/legal/master-software-license-agreement. This software is distributed to you in Source Code format and is governed by the sections of the MSLA applicable to Source Code.
Definition in file
tempdrv.c
.
#include "
em_device.h
"
#include "
em_system.h
"
#include "
em_emu.h
"
#include "string.h"
#include "
tempdrv.h
"
Data Structures |
|
struct | TEMPDRV_CallbackSet_t |
Functions |
|
static Ecode_t | addCallback ( TEMPDRV_CallbackSet_t *set, int8_t temp, TEMPDRV_Callback_t callback) |
Attempt to add a callback to a set.
|
|
static void | calibration (void) |
Prepare calibration values for temperature conversion.
|
|
static bool | checkForDuplicates ( TEMPDRV_CallbackSet_t *set, int8_t temp) |
Check if another callback has registered the same temperature.
|
|
static uint32_t | convertToEmu (int temp) |
Convert a temperature in °C to an EMU sensor value.
|
|
static int | convertToTemp (uint32_t emu) |
Convert EMU value to degrees Celsius.
|
|
static void | disableInterrupts (void) |
Turn off and clear EMU temperature related interrupts.
|
|
void | EMU_IRQHandler (void) |
EMU Interrupt Handler.
|
|
static int8_t | findCallbackSpace ( TEMPDRV_CallbackSet_t *set) |
Find an empty spot for callback in set.
|
|
static bool | removeCallback ( TEMPDRV_CallbackSet_t *set, TEMPDRV_Callback_t callback) |
Remove a callback from the set.
|
|
Ecode_t | TEMPDRV_DeInit (void) |
De-initialize the TEMP driver.
|
|
Ecode_t | TEMPDRV_Enable (bool enable) |
Enable or disable the TEMP driver.
|
|
uint8_t | TEMPDRV_GetActiveCallbacks ( TEMPDRV_LimitType_t limit) |
Get the number of active callbacks for a limit.
|
|
int8_t | TEMPDRV_GetTemp (void) |
Get the current temperature.
|
|
Ecode_t | TEMPDRV_Init (void) |
Initialize the TEMP driver.
|
|
void | TEMPDRV_IRQHandler (void) |
TEMPDRV Interrupt Handler.
|
|
Ecode_t | TEMPDRV_RegisterCallback (int8_t temp, TEMPDRV_LimitType_t limit, TEMPDRV_Callback_t callback) |
Register a callback in the TEMP driver.
|
|
Ecode_t | TEMPDRV_UnregisterCallback ( TEMPDRV_Callback_t callback) |
Unregister a callback in the TEMP driver.
|
|
static void | updateInterrupts (void) |
Update interrupts based on active callbacks.
|
|
Variables |
|
static int | calibrationEMU |
static int | calibrationTEMP |
static uint8_t | fallbackEMU = 0x90 |
static uint8_t | fallbackTEMP = 25 |
static TEMPDRV_CallbackSet_t * | highCallback |
static TEMPDRV_CallbackSet_t * | lowCallback |
static TEMPDRV_CallbackSet_t | nullCallback = { NULL, 0 } |
static bool | TEMPDRV_EnableState = false |
static bool | TEMPDRV_InitState = false |
static TEMPDRV_CallbackSet_t | tempdrvHighCallbacks [TEMPDRV_CALLBACK_DEPTH] |
static TEMPDRV_CallbackSet_t | tempdrvLowCallbacks [TEMPDRV_CALLBACK_DEPTH] |
Function Documentation
|
static |
Attempt to add a callback to a set.
- Parameters
-
[in] set
Callback set to add callback to [in] temp
Temperature to register callback at [in] callback
Callback function
- Returns
-
- ECODE_EMDRV_TEMPDRV_OK on success.
- ECODE_EMDRV_TEMPDRV_NO_SPACE if there is no space left for callbacks.
Definition at line
293
of file
tempdrv.c
.
References TEMPDRV_CallbackSet_t::callback , convertToEmu() , ECODE_EMDRV_TEMPDRV_NO_SPACE , ECODE_EMDRV_TEMPDRV_OK , findCallbackSpace() , TEMPDRV_CallbackSet_t::temp , and updateInterrupts() .
Referenced by TEMPDRV_RegisterCallback() .
|
static |
Check if another callback has registered the same temperature.
- Parameters
-
[in] set
Callback set to search [in] temp
Temperature to match
- Returns
-
true
if a duplicate is found,false
if no duplicates is found.
Definition at line
349
of file
tempdrv.c
.
References convertToEmu() .
Referenced by TEMPDRV_RegisterCallback() .
|
static |
Convert a temperature in °C to an EMU sensor value.
- Parameters
-
[in] temp
Temperature to convert in degrees Celsius
- Returns
- EMU temperature sensor value that represents the given temperature
Definition at line
403
of file
tempdrv.c
.
Referenced by addCallback() , and checkForDuplicates() .
|
static |
Convert EMU value to degrees Celsius.
- Parameters
-
[in] emu
EMU value to convert
- Returns
- temperature in degrees Celsius
Definition at line
376
of file
tempdrv.c
.
Referenced by TEMPDRV_GetTemp() .
void EMU_IRQHandler | ( | void |
|
) |
EMU Interrupt Handler.
The EMU_IRQHandler provided by TEMPDRV will call TEMPDRV_IRQ_Handler. Configure EMU_CUSTOM_IRQ_HANDLER = true if the application wants to implement its own EMU_IRQHandler. This is typically needed if one of the non-temperature related EMU interrupt flags are in use.
Definition at line
87
of file
tempdrv.c
.
References TEMPDRV_IRQHandler() .
|
static |
Find an empty spot for callback in set.
- Parameters
-
[in] set
Callback set to search
- Returns
- index of empty space if found, -1 if none
Definition at line
263
of file
tempdrv.c
.
Referenced by addCallback() .
|
static |
Remove a callback from the set.
- Parameters
-
[in] set
Callback set to remove callback from [in] callback
Callback function
- Returns
-
true
on success andfalse
if the callback was not found.
Definition at line
320
of file
tempdrv.c
.
References TEMPDRV_CallbackSet_t::callback , TEMPDRV_CallbackSet_t::temp , and updateInterrupts() .
Referenced by TEMPDRV_UnregisterCallback() .
|
static |
Update interrupts based on active callbacks.
There can only be two temperature thresholds active in the EMU sensor at a single point in time. One threshold for increasing temperature and one threshold for decreasing temperature. The responsibility of this function is to always select which temperature thresholds that should be activated in the EMU sensor at any given time.
Definition at line
440
of file
tempdrv.c
.
References TEMPDRV_CallbackSet_t::callback , EMU , and TEMPDRV_CallbackSet_t::temp .
Referenced by addCallback() , removeCallback() , TEMPDRV_Enable() , TEMPDRV_Init() , and TEMPDRV_IRQHandler() .