EFR32 Mighty Gecko 1 Software Documentation  efr32mg1-doc-5.1.2
tempdrv.c File Reference

Detailed Description

TEMPDRV API implementation.

Version
5.1.2

License

(C) Copyright 2014 Silicon Labs, http://www.silabs.com

Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:

  1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software.
  2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
  3. This notice may not be removed or altered from any source distribution.

DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Silicon Labs has no obligation to support this Software. Silicon Labs is providing the Software "AS IS", with no express or implied warranties of any kind, including, but not limited to, any implied warranties of merchantability or fitness for any particular purpose or warranties against infringement of any proprietary rights of a third party.

Silicon Labs will not be liable for any consequential, incidental, or special damages, or any other relief, or for any claim by any third party, arising from your use of this Software.

Definition in file tempdrv.c.

#include "em_device.h"
#include "em_system.h"
#include "em_emu.h"
#include "string.h"
#include "tempdrv.h"

Go to the source code of this file.

Data Structures

struct  TEMPDRV_CallbackSet_t
 

Macros

#define ERRATA_HIGH_LIMIT   80
 
#define ERRATA_HYSTERESIS   8
 
#define ERRATA_MID_LIMIT   65
 
#define TEMPDRV_
 
#define TEMPDRV_CALLBACK_DEPTH   (TEMPDRV_INT_CALLBACK_DEPTH + TEMPDRV_CUSTOM_CALLBACK_DEPTH)
 
#define TEMPDRV_CUSTOM_CALLBACK_INDEX   TEMPDRV_INT_CALLBACK_DEPTH
 
#define TEMPDRV_ERRATA_FIX
 
#define TEMPDRV_INT_CALLBACK_DEPTH   1
 

Typedefs

typedef enum ErrataState ErrataState_t
 

Enumerations

enum  ErrataState {
  ERRATA_LOW = 0,
  ERRATA_MID = 1,
  ERRATA_HIGH = 2
}
 

Functions

static Ecode_t addCallback (TEMPDRV_CallbackSet_t *set, int8_t temp, TEMPDRV_Callback_t callback)
 Attempt to add a callback to a set. More...
 
static bool checkForDuplicates (TEMPDRV_CallbackSet_t *set, int8_t temp)
 Check if another callback has registered the same temperature. More...
 
static uint8_t convertToEmu (int8_t temp)
 Convert a temperature in °C to an EMU sensor value. More...
 
static int8_t convertToTemp (uint8_t emu)
 Convert EMU value to degrees Celsius. More...
 
static void disableInterrupts (void)
 Turn off and clear EMU temperature related interrupts.
 
void EMU_IRQHandler (void)
 EMU Interrupt Handler. More...
 
static void errataCallback (int8_t temp, TEMPDRV_LimitType_t limit)
 Errata Callback. More...
 
static void errataInit (void)
 Errata Initialization. More...
 
static void errataStateUpdate (int8_t temp)
 Errata State Update. More...
 
static int8_t findCallbackSpace (TEMPDRV_CallbackSet_t *set)
 Find an empty spot for callback in set. More...
 
static bool removeCallback (TEMPDRV_CallbackSet_t *set, TEMPDRV_Callback_t callback)
 Remove a callback from the set. More...
 
Ecode_t TEMPDRV_DeInit (void)
 De-initialize the TEMP driver. More...
 
Ecode_t TEMPDRV_Enable (bool enable)
 Enable or disable the TEMP driver. More...
 
uint8_t TEMPDRV_GetActiveCallbacks (TEMPDRV_LimitType_t limit)
 Get the number of active callbacks for a limit. More...
 
int8_t TEMPDRV_GetTemp (void)
 Get the current temperature. More...
 
Ecode_t TEMPDRV_Init (void)
 Initialize the TEMP driver. More...
 
void TEMPDRV_IRQHandler (void)
 TEMPDRV Interrupt Handler. More...
 
Ecode_t TEMPDRV_RegisterCallback (int8_t temp, TEMPDRV_LimitType_t limit, TEMPDRV_Callback_t callback)
 Register a callback in the TEMP driver. More...
 
Ecode_t TEMPDRV_UnregisterCallback (TEMPDRV_Callback_t callback)
 Unregister a callback in the TEMP driver. More...
 
static void updateInterrupts (void)
 Update interrupts based on active callbacks. More...
 

Variables

static int32_t calibrationEMU
 
static int32_t calibrationTEMP
 
static TEMPDRV_CallbackSet_t errataHighTemp [3]
 
static TEMPDRV_CallbackSet_t errataLowTemp [3]
 
static uint8_t fallbackEMU = 0x90
 
static uint8_t fallbackTEMP = 25
 
static TEMPDRV_CallbackSet_thighCallback
 
static TEMPDRV_CallbackSet_tlowCallback
 
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]
 

Enumeration Type Documentation

Enumerator
ERRATA_LOW 

Low temperature <65°C.

ERRATA_MID 

Medium temperature >65°C and <80°C.

ERRATA_HIGH 

High temperature >80°C.

Definition at line 140 of file tempdrv.c.

Function Documentation

static Ecode_t addCallback ( TEMPDRV_CallbackSet_t set,
int8_t  temp,
TEMPDRV_Callback_t  callback 
)
static

Attempt to add a callback to a set.

Parameters
[in]setCallback set to add callback to
[in]tempTemperature to register callback at
[in]callbackCallback function
Returns

Definition at line 315 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 bool checkForDuplicates ( TEMPDRV_CallbackSet_t set,
int8_t  temp 
)
static

Check if another callback has registered the same temperature.

Parameters
[in]setCallback set to search
[in]tempTemperature to match
Returns
true if a duplicate is found, false if no duplicates is found.

Definition at line 374 of file tempdrv.c.

References convertToEmu().

Referenced by TEMPDRV_RegisterCallback().

static uint8_t convertToEmu ( int8_t  temp)
static

Convert a temperature in °C to an EMU sensor value.

Parameters
[in]tempTemperature to convert in degrees Celsius
Returns
EMU temperature sensor value that represents the given temperature

Definition at line 430 of file tempdrv.c.

Referenced by addCallback(), checkForDuplicates(), and errataInit().

static int8_t convertToTemp ( uint8_t  emu)
static

Convert EMU value to degrees Celsius.

Parameters
[in]emuEMU value to convert
Returns
temperature in degrees Celsius

Definition at line 404 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 91 of file tempdrv.c.

References TEMPDRV_IRQHandler().

static void errataCallback ( int8_t  temp,
TEMPDRV_LimitType_t  limit 
)
static

Errata Callback.

This function is called by the TEMPDRV_IRQHandler and will change the state depending on the current temperature.

Definition at line 166 of file tempdrv.c.

References errataStateUpdate().

Referenced by errataInit().

static void errataInit ( void  )
static

Errata Initialization.

Initialize the temperature thresholds based on calibration values and initializes the errata fix based on the current temperature.

Definition at line 234 of file tempdrv.c.

References TEMPDRV_CallbackSet_t::callback, convertToEmu(), ERRATA_HIGH, ERRATA_LOW, ERRATA_MID, errataCallback(), errataStateUpdate(), SYSTEM_ChipRevision_TypeDef::major, SYSTEM_ChipRevisionGet(), TEMPDRV_CallbackSet_t::temp, and TEMPDRV_GetTemp().

Referenced by TEMPDRV_Init().

static void errataStateUpdate ( int8_t  temp)
static

Errata State Update.

Updates registers based on the current temperature

Definition at line 179 of file tempdrv.c.

References EMU, EMU_LOCK_LOCKKEY_LOCK, EMU_LOCK_LOCKKEY_LOCKED, EMU_LOCK_LOCKKEY_UNLOCK, EMU_SetBiasMode(), ERRATA_HIGH, ERRATA_LOW, and ERRATA_MID.

Referenced by errataCallback(), and errataInit().

static int8_t findCallbackSpace ( TEMPDRV_CallbackSet_t set)
static

Find an empty spot for callback in set.

Parameters
[in]setCallback set to search
Returns
index of empty space if found, -1 if none

Definition at line 283 of file tempdrv.c.

Referenced by addCallback().

static bool removeCallback ( TEMPDRV_CallbackSet_t set,
TEMPDRV_Callback_t  callback 
)
static

Remove a callback from the set.

Parameters
[in]setCallback set to remove callback from
[in]callbackCallback function
Returns
true on success and false if the callback was not found.

Definition at line 343 of file tempdrv.c.

References TEMPDRV_CallbackSet_t::callback, TEMPDRV_CallbackSet_t::temp, and updateInterrupts().

Referenced by TEMPDRV_UnregisterCallback().

static void updateInterrupts ( void  )
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 466 of file tempdrv.c.

References _EMU_TEMPLIMITS_TEMPHIGH_MASK, _EMU_TEMPLIMITS_TEMPHIGH_SHIFT, _EMU_TEMPLIMITS_TEMPLOW_MASK, _EMU_TEMPLIMITS_TEMPLOW_SHIFT, TEMPDRV_CallbackSet_t::callback, EMU, EMU_IEN_TEMPHIGH, EMU_IEN_TEMPLOW, EMU_IntDisable(), EMU_IntEnable(), and TEMPDRV_CallbackSet_t::temp.

Referenced by addCallback(), removeCallback(), TEMPDRV_Enable(), TEMPDRV_Init(), and TEMPDRV_IRQHandler().