46 #if defined(_SILICON_LABS_GECKO_INTERNAL_SDID_80)
47 #define TEMPDRV_ERRATA_FIX
50 #ifdef TEMPDRV_ERRATA_FIX
51 #define TEMPDRV_INT_CALLBACK_DEPTH 1
54 #define TEMPDRV_INT_CALLBACK_DEPTH 0
57 #define TEMPDRV_CALLBACK_DEPTH (TEMPDRV_INT_CALLBACK_DEPTH + TEMPDRV_CUSTOM_CALLBACK_DEPTH)
58 #define TEMPDRV_CUSTOM_CALLBACK_INDEX TEMPDRV_INT_CALLBACK_DEPTH
66 static bool TEMPDRV_InitState =
false;
67 static bool TEMPDRV_EnableState =
false;
74 static int32_t calibrationEMU;
75 static int32_t calibrationTEMP;
77 static uint8_t fallbackEMU = 0x90;
78 static uint8_t fallbackTEMP = 25;
80 #if (EMU_CUSTOM_IRQ_HANDLER == false)
110 uint32_t flags = EMU_IntGetEnabled();
113 if (flags & EMU_IF_TEMPHIGH)
118 activeCallback = lowCallback->
callback;
122 EMU_IntClear(EMU_IFC_TEMPHIGH);
124 else if (flags & EMU_IF_TEMPLOW)
129 activeCallback = highCallback->
callback;
133 EMU_IntClear(EMU_IFC_TEMPLOW);
138 #if defined(TEMPDRV_ERRATA_FIX)
140 typedef enum ErrataState
148 #define ERRATA_MID_LIMIT 65
149 #define ERRATA_HIGH_LIMIT 80
150 #define ERRATA_HYSTERESIS 8
153 static void errataStateUpdate(int8_t temp);
169 errataStateUpdate(temp);
179 static void errataStateUpdate(int8_t temp)
181 ErrataState_t errataState;
185 if (temp < ERRATA_MID_LIMIT)
187 errataState = ERRATA_LOW;
189 else if (temp < ERRATA_HIGH_LIMIT)
191 errataState = ERRATA_MID;
195 errataState = ERRATA_HIGH;
199 tempdrvHighCallbacks[0] = errataHighTemp[errataState];
200 tempdrvLowCallbacks[0] = errataLowTemp[errataState];
210 EMU_SetBiasMode(emuBiasMode_1KHz);
213 EMU_SetBiasMode(emuBiasMode_4KHz);
216 EMU_SetBiasMode(emuBiasMode_Continuous);
234 static void errataInit(
void)
240 if (rev.
major == 0x01)
247 errataHighTemp[ERRATA_LOW].
temp = limitHigh;
248 errataHighTemp[ERRATA_LOW].
callback = errataCallback;
251 limitLow =
convertToEmu(ERRATA_MID_LIMIT - ERRATA_HYSTERESIS);
253 errataLowTemp[ERRATA_MID].
temp = limitLow;
254 errataLowTemp[ERRATA_MID].
callback = errataCallback;
255 errataHighTemp[ERRATA_MID].
temp = limitHigh;
256 errataHighTemp[ERRATA_MID].
callback = errataCallback;
259 limitLow =
convertToEmu(ERRATA_HIGH_LIMIT - ERRATA_HYSTERESIS);
260 errataLowTemp[ERRATA_HIGH].
temp = limitLow;
261 errataLowTemp[ERRATA_HIGH].
callback = errataCallback;
266 #else // TEMPDRV_ERRATA_FIX
270 #endif // TEMPDRV_ERRATA_FIX
286 for (index = TEMPDRV_CUSTOM_CALLBACK_INDEX; index < TEMPDRV_CALLBACK_DEPTH; index++)
288 if (set[index].callback==NULL)
348 for (index = TEMPDRV_CUSTOM_CALLBACK_INDEX; index < TEMPDRV_CALLBACK_DEPTH; index++)
350 if (set[index].callback == callback)
378 for (index = TEMPDRV_CUSTOM_CALLBACK_INDEX; index < TEMPDRV_CALLBACK_DEPTH; index++)
381 if (set[index].callback!=NULL)
384 if (set[index].temp == emu)
406 int32_t res = (int32_t) calibrationTEMP - ((emu * 8) / 5);
432 int32_t res = (int32_t) calibrationEMU - ((temp * 5) >> 3);
442 return (uint8_t) res;
451 EMU_IntClear(EMU_IFC_TEMPLOW | EMU_IFC_TEMPHIGH);
452 EMU_IntDisable(EMU_IFC_TEMPLOW | EMU_IFC_TEMPHIGH);
470 for (index = 0; index < TEMPDRV_CALLBACK_DEPTH; index++)
473 if (tempdrvHighCallbacks[index].callback!=NULL)
477 highCallback = &tempdrvHighCallbacks[index];
481 if (tempdrvHighCallbacks[index].temp>highCallback->
temp)
483 highCallback = &tempdrvHighCallbacks[index];
492 EMU->TEMPLIMITS &= ~_EMU_TEMPLIMITS_TEMPLOW_MASK;
493 EMU->TEMPLIMITS |= highCallback->
temp << _EMU_TEMPLIMITS_TEMPLOW_SHIFT;
494 EMU_IntEnable(EMU_IEN_TEMPLOW);
498 EMU_IntDisable(EMU_IEN_TEMPLOW);
502 for (index = 0; index < TEMPDRV_CALLBACK_DEPTH; index++)
505 if (tempdrvLowCallbacks[index].callback!=NULL)
509 lowCallback = &tempdrvLowCallbacks[index];
513 if (tempdrvLowCallbacks[index].temp<lowCallback->temp)
515 lowCallback = &tempdrvLowCallbacks[index];
524 EMU->TEMPLIMITS &= ~_EMU_TEMPLIMITS_TEMPHIGH_MASK;
525 EMU->TEMPLIMITS |= lowCallback->
temp << _EMU_TEMPLIMITS_TEMPHIGH_SHIFT;
526 EMU_IntEnable(EMU_IEN_TEMPHIGH);
530 EMU_IntDisable(EMU_IEN_TEMPHIGH);
549 uint32_t DItemp, DIemu;
552 TEMPDRV_InitState =
true;
557 highCallback = &nullCallback;
558 lowCallback = &nullCallback;
562 DIemu = ((
DEVINFO->EMUTEMP & _DEVINFO_EMUTEMP_EMUTEMPROOM_MASK) >> _DEVINFO_EMUTEMP_EMUTEMPROOM_SHIFT);
565 || (DIemu == (_DEVINFO_EMUTEMP_EMUTEMPROOM_MASK >> _DEVINFO_EMUTEMP_EMUTEMPROOM_SHIFT)))
568 DItemp = fallbackTEMP;
573 calibrationEMU = (DIemu) + ((5*(DItemp))/8);
574 calibrationTEMP = (DItemp) + (8*(DIemu)/5);
579 NVIC_ClearPendingIRQ(EMU_IRQn);
580 NVIC_EnableIRQ(EMU_IRQn);
599 TEMPDRV_InitState =
false;
600 NVIC_DisableIRQ(EMU_IRQn);
601 NVIC_ClearPendingIRQ(EMU_IRQn);
620 if (TEMPDRV_EnableState != enable)
622 TEMPDRV_EnableState = enable;
652 set = tempdrvHighCallbacks;
657 set = tempdrvLowCallbacks;
664 uint8_t index, count=0;
665 for (index = TEMPDRV_CUSTOM_CALLBACK_INDEX; index < TEMPDRV_CALLBACK_DEPTH; index++)
668 if (set[index].callback!=NULL)
755 if (TEMPDRV_InitState ==
false)
760 if (callback == NULL)
772 set = tempdrvHighCallbacks;
782 set = tempdrvLowCallbacks;
816 if (callback == NULL)
static int8_t convertToTemp(uint8_t emu)
Convert EMU value to degrees Celsius.
static void updateInterrupts(void)
Update interrupts based on active callbacks.
static bool removeCallback(TEMPDRV_CallbackSet_t *set, TEMPDRV_Callback_t callback)
Remove a callback from the set.
#define ECODE_EMDRV_TEMPDRV_DUP_TEMP
Requested temperature is a duplicate.
TEMPDRV_Callback_t callback
Callback function.
void SYSTEM_ChipRevisionGet(SYSTEM_ChipRevision_TypeDef *rev)
Get chip major/minor revision.
static bool checkForDuplicates(TEMPDRV_CallbackSet_t *set, int8_t temp)
Check if another callback has registered the same temperature.
static int8_t findCallbackSpace(TEMPDRV_CallbackSet_t *set)
Find an empty spot for callback in set.
void(* TEMPDRV_Callback_t)(int8_t temp, TEMPDRV_LimitType_t limit)
TEMPDRV temperature limit callback function.
#define _DEVINFO_CAL_TEMP_MASK
int8_t TEMPDRV_GetTemp(void)
Get the current temperature.
CMSIS Cortex-M Peripheral Access Layer for Silicon Laboratories microcontroller devices.
Ecode_t TEMPDRV_DeInit(void)
De-initialize the TEMP driver.
static uint8_t convertToEmu(int8_t temp)
Convert a temperature in °C to an EMU sensor value.
void TEMPDRV_IRQHandler(void)
TEMPDRV Interrupt Handler.
static Ecode_t addCallback(TEMPDRV_CallbackSet_t *set, int8_t temp, TEMPDRV_Callback_t callback)
Attempt to add a callback to a set.
#define ECODE_EMDRV_TEMPDRV_BAD_LIMIT
Temperature mismatch with limit.
void EMU_IRQHandler(void)
EMU Interrupt Handler.
#define ECODE_EMDRV_TEMPDRV_NO_INIT
Function requires prior initialization.
uint32_t Ecode_t
Typedef for API function error code return values.
#define EMU_LOCK_LOCKKEY_UNLOCK
uint8_t temp
Limit temperature (EMU value)
uint8_t TEMPDRV_GetActiveCallbacks(TEMPDRV_LimitType_t limit)
Get the number of active callbacks for a limit.
#define ECODE_EMDRV_TEMPDRV_PARAM_ERROR
Illegal input parameter.
#define EMU_LOCK_LOCKKEY_LOCK
Ecode_t TEMPDRV_UnregisterCallback(TEMPDRV_Callback_t callback)
Unregister a callback in the TEMP driver.
#define ECODE_EMDRV_TEMPDRV_NO_SPACE
No more space to register.
Ecode_t TEMPDRV_Enable(bool enable)
Enable or disable the TEMP driver.
Energy management unit (EMU) peripheral API.
#define EMU_LOCK_LOCKKEY_LOCKED
#define ECODE_EMDRV_TEMPDRV_NO_CALLBACK
Can't find callback.
static void disableInterrupts(void)
Turn off and clear EMU temperature related interrupts.
enum TEMPDRV_LimitType TEMPDRV_LimitType_t
#define ECODE_EMDRV_TEMPDRV_OK
Success return value.
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_Init(void)
Initialize the TEMP driver.
#define _DEVINFO_CAL_TEMP_SHIFT