Modules#
Minimal Hal functions common across all microcontroller-specific files. See Common Microcontroller Functions for documentation.
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.
/***************************************************************************/
#ifndef __MICRO_COMMON_H__
#define __MICRO_COMMON_H__
void halInit(void);
void halReboot(void);
void halPowerUp(void);
void halPowerDown(void);
void halResume(void);
void halSuspend(void);
#define MICRO_DISABLE_WATCH_DOG_KEY 0xA5U
void halInternalEnableWatchDog(void);
void halInternalDisableWatchDog(uint8_t magicKey);
bool halInternalWatchDogEnabled(void);
#ifdef DOXYGEN_SHOULD_SKIP_THIS
enum SleepModes
#else
typedef uint8_t SleepModes;
enum
#endif
{
SLEEPMODE_RUNNING = 0U,
SLEEPMODE_IDLE = 1U,
SLEEPMODE_WAKETIMER = 2U,
SLEEPMODE_MAINTAINTIMER = 3U,
SLEEPMODE_NOTIMER = 4U,
SLEEPMODE_HIBERNATE = 5U,
//The following SleepModes are deprecated on EM2xx and EM3xx chips. Each
//micro's halSleep() function will remap these modes to the appropriate
//replacement, as necessary.
SLEEPMODE_RESERVED = 6U,
SLEEPMODE_POWERDOWN = 7U,
SLEEPMODE_POWERSAVE = 8U,
};
#ifdef CORTEXM3_EMBER_MICRO
#ifdef EMBER_MICRO_PORT_F_GPIO
#define WAKEPORTD uint8_t portD;
#define WAKEPORTE uint8_t portE;
#define WAKEPORTF uint8_t portF;
#define GPIO_MASK_SIZE 48
#define GPIO_MASK 0xFFFFFFFFFFFF
typedef uint64_t GpioMaskType;
typedef uint64_t WakeMask;
#elif defined (EMBER_MICRO_PORT_E_GPIO)
#define WAKEPORTD uint8_t portD;
#define WAKEPORTE uint8_t portE;
#define WAKEPORTF
#define GPIO_MASK_SIZE 40
#define GPIO_MASK 0xFFFFFFFFFF
typedef uint64_t GpioMaskType;
typedef uint64_t WakeMask;
#elif defined (EMBER_MICRO_PORT_D_GPIO)
#define WAKEPORTD uint8_t portD;
#define WAKEPORTE
#define WAKEPORTF
#define GPIO_MASK_SIZE 32
#define GPIO_MASK 0xFFFFFFFF
typedef uint32_t GpioMaskType;
typedef uint64_t WakeMask;
#else
#define WAKEPORTD
#define WAKEPORTE
#define WAKEPORTF
#define GPIO_MASK_SIZE 24
#define GPIO_MASK 0xFFFFFF
typedef uint32_t GpioMaskType;
typedef uint32_t WakeMask;
#endif
#define WAKE_GPIO_MASK GPIO_MASK
#define WAKE_GPIO_SIZE GPIO_MASK_SIZE
//We don't have a real register to hold this composite information.
//Pretend we do so halGetWakeInfo can operate like halGetResetInfo.
//This "register" is only ever set by halSleep.
// [31] = WakeInfoValid
// [30] = SleepSkipped
// [29] = CSYSPWRUPREQ
// [28] = CDBGPWRUPREQ
// [27] = WAKE_CORE
// [26] = TIMER_WAKE_WRAP
// [25] = TIMER_WAKE_COMPB
// [24] = TIMER_WAKE_COMPA
// [23:0] = corresponding GPIO activity
#define WAKEINFOVALID_INTERNAL_WAKE_EVENT_BIT (GPIO_MASK_SIZE + 7)
#define SLEEPSKIPPED_INTERNAL_WAKE_EVENT_BIT (GPIO_MASK_SIZE + 6)
#define CSYSPWRUPREQ_INTERNAL_WAKE_EVENT_BIT (GPIO_MASK_SIZE + 5)
#define CDBGPWRUPREQ_INTERNAL_WAKE_EVENT_BIT (GPIO_MASK_SIZE + 4)
#define WAKE_CORE_INTERNAL_WAKE_EVENT_BIT (GPIO_MASK_SIZE + 3)
#define WRAP_INTERNAL_WAKE_EVENT_BIT (GPIO_MASK_SIZE + 2)
#define CMPB_INTERNAL_WAKE_EVENT_BIT (GPIO_MASK_SIZE + 1)
#define CMPA_INTERNAL_WAKE_EVENT_BIT (GPIO_MASK_SIZE + 0)
//This define shifts events from the PWRUP_EVENT register into the proper
//place in the halInternalWakeEvent variable
#define INTERNAL_WAKE_EVENT_BIT_SHIFT (GPIO_MASK_SIZE - 4)
typedef union {
struct {
uint8_t portA;
uint8_t portB;
uint8_t portC;
WAKEPORTD
WAKEPORTE
WAKEPORTF
union {
struct {
uint8_t TIMER_WAKE_COMPA : 1;
uint8_t TIMER_WAKE_COMPB : 1;
uint8_t TIMER_WAKE_WRAP : 1;
uint8_t WAKE_CORE_B : 1;
uint8_t CDBGPWRUPREQ : 1;
uint8_t CSYSPWRUPREQ : 1;
uint8_t SleepSkipped : 1;
uint8_t WakeInfoValid : 1;
}bits;
uint8_t byte;
} internal;
} events;
WakeMask eventflags;
} WakeEvents;
#undef WAKEPORTD
#undef WAKEPORTE
#undef WAKEPORTF
#elif defined (CORTEXM3_EFM32_MICRO)
#define WAKE_GPIO_SIZE 16
#define WAKE_GPIO_MASK 0x0000FFFF
#define WAKE_IRQ_GPIO (1 << 16)
#define WAKE_IRQ_SYSTIMER (1 << 17)
#define WAKE_IRQ_RFSENSE (1 << 18)
typedef uint32_t WakeEvents;
typedef uint32_t WakeMask;
#else // to cover simulation targets
#define GPIO_MASK_SIZE 24
#define GPIO_MASK 0xFFFFFF
#define WAKE_GPIO_MASK GPIO_MASK
#define WAKE_GPIO_SIZE GPIO_MASK_SIZE
typedef uint32_t WakeEvents;
typedef uint32_t WakeMask;
#endif // CORTEXM3_EMBER_MICRO
#define WAKE_MASK_INVALID (-1)
#define WAKE_EVENT_SIZE WakeMask
void halSleep(SleepModes sleepMode);
void halSleepPreserveInts(SleepModes sleepMode);
void halCommonDelayMicroseconds(uint16_t us);
#define DEBUG_TOGGLE(n)
extern volatile int8_t halCommonVreg1v8EnableCount;
void halCommonDisableVreg1v8(void);
void halCommonEnableVreg1v8(void);
/*
* This function should set CRYOTimer for EFR32 wakeup from em4 sleep, and also write the counters to RTCC RAM
*/
typedef struct {//Saved in RTCCRAM starting from index 0
uint32_t outgoingNwkFrameCounter; //saved in index 0 of RTCCRAM
uint32_t incomingParentNwkFrameCounter;
uint32_t outgoingLinkKeyFrameCounter; //NextApsFrameCounter
uint32_t incomingLinkKeyFrameCounter; //incomingTCLinkKeyFrameCounter saved in index 3 of RTCCRAM
} RTCCRamData;
void halBeforeEM4(uint32_t duration, RTCCRamData input);
RTCCRamData halAfterEM4(void);
#endif //__MICRO_COMMON_H__
Macros#
The value that must be passed as the single parameter to halInternalDisableWatchDog() in order to successfully disable the watchdog timer.
Enumerations#
Enumerations for the possible microcontroller sleep modes.
Variables#
Helper variable to track the state of 1.8V regulator.
Functions#
Initializes microcontroller-specific peripherals.
Restarts the microcontroller and therefore everything else.
Powers up microcontroller peripherals and board peripherals.
Powers down microcontroller peripherals and board peripherals.
Resumes microcontroller peripherals and board peripherals.
Suspends microcontroller peripherals and board peripherals.
Enables the watchdog timer.
Disables the watchdog timer.
Determines whether the watchdog has been enabled or disabled.
Puts the microcontroller to sleep in a specified mode.
Same as halSleep() except it preserves the current interrupt state rather than always enabling interrupts prior to returning.
Blocks the current thread of execution for the specified amount of time, in microseconds.
Disable the 1.8V regulator. This function is to be used when the 1.8V supply is provided externally. Disabling the regulator saves current consumption. Disabling the regulator will cause ADC readings of external signals to be wrong. These exteranl signals include analog sources ADC0 thru ADC5 and VDD_PADS/4.
Enable the 1.8V regulator. Normally the 1.8V regulator is enabled out of reset. This function is only needed if the 1.8V regulator has been disabled and ADC conversions on external signals are needed. These exteranl signals include analog sources ADC0 thru ADC5 and VDD_PADS/4. The state of 1v8 survives deep sleep.
Macro Definition Documentation#
MICRO_DISABLE_WATCH_DOG_KEY#
#define MICRO_DISABLE_WATCH_DOG_KEYValue:
0xA5U
The value that must be passed as the single parameter to halInternalDisableWatchDog() in order to successfully disable the watchdog timer.
56
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/micro-common.h
GPIO_MASK_SIZE#
#define GPIO_MASK_SIZEValue:
24
227
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/micro-common.h
GPIO_MASK#
#define GPIO_MASKValue:
0xFFFFFF
228
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/micro-common.h
WAKE_GPIO_MASK#
#define WAKE_GPIO_MASKValue:
GPIO_MASK
229
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/micro-common.h
WAKE_GPIO_SIZE#
#define WAKE_GPIO_SIZEValue:
GPIO_MASK_SIZE
230
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/micro-common.h
WAKE_MASK_INVALID#
#define WAKE_MASK_INVALIDValue:
(-1)
235
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/micro-common.h
WAKE_EVENT_SIZE#
#define WAKE_EVENT_SIZEValue:
WakeMask
Note
The preprocessor symbol WAKE_EVENT_SIZE has been deprecated. Please use WakeMask instead.
240
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/micro-common.h
DEBUG_TOGGLE#
#define DEBUG_TOGGLE
278
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/micro-common.h
Enumeration Documentation#
SleepModes#
SleepModes
Enumerations for the possible microcontroller sleep modes.
SLEEPMODE_RUNNING Everything is active and running. In practice this mode is not used, but it is defined for completeness of information.
SLEEPMODE_IDLE Only the CPU is idled. The rest of the chip continues running normally. The chip will wake from any interrupt.
SLEEPMODE_WAKETIMER The sleep timer clock sources remain running. The RC is always running and the 32kHz XTAL depends on the board header. Wakeup is possible from both GPIO and the sleep timer. System time is maintained. The sleep timer is assumed to be configured properly for wake events.
SLEEPMODE_MAINTAINTIMER The sleep timer clock sources remain running. The RC is always running and the 32kHz XTAL depends on the board header. Wakeup is possible from only GPIO. System time is maintained. NOTE: This mode is not available on EM2XX chips.
SLEEPMODE_NOTIMER The sleep timer clock sources (both RC and XTAL) are turned off. Wakeup is possible from only GPIO. System time is lost.
SLEEPMODE_HIBERNATE This maps to EM4 Hibernate on the EFM32/EFR32 devices. RAM is not retained in SLEEPMODE_HIBERNATE so waking up from this sleepmode will behave like a reset. NOTE: This mode is only available on EFM32/EFR32
Enumerator | |
---|---|
SLEEPMODE_RUNNING | |
SLEEPMODE_IDLE | |
SLEEPMODE_WAKETIMER | |
SLEEPMODE_MAINTAINTIMER | |
SLEEPMODE_NOTIMER | |
SLEEPMODE_HIBERNATE | |
SLEEPMODE_RESERVED | |
SLEEPMODE_POWERDOWN | |
SLEEPMODE_POWERSAVE |
106
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/micro-common.h
Typedef Documentation#
WakeEvents#
typedef uint32_t WakeEvents
231
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/micro-common.h
WakeMask#
typedef uint32_t WakeMask
232
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/micro-common.h
Variable Documentation#
halCommonVreg1v8EnableCount#
volatile int8_t halCommonVreg1v8EnableCount
Helper variable to track the state of 1.8V regulator.
Note
: Only used when DISABLE_INTERNAL_1V8_REGULATOR is defined.
285
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/micro-common.h
Function Documentation#
halInit#
void halInit (void )
Initializes microcontroller-specific peripherals.
N/A |
30
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/micro-common.h
halReboot#
void halReboot (void )
Restarts the microcontroller and therefore everything else.
N/A |
34
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/micro-common.h
halPowerUp#
void halPowerUp (void )
Powers up microcontroller peripherals and board peripherals.
N/A |
38
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/micro-common.h
halPowerDown#
void halPowerDown (void )
Powers down microcontroller peripherals and board peripherals.
N/A |
42
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/micro-common.h
halResume#
void halResume (void )
Resumes microcontroller peripherals and board peripherals.
N/A |
46
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/micro-common.h
halSuspend#
void halSuspend (void )
Suspends microcontroller peripherals and board peripherals.
N/A |
50
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/micro-common.h
halInternalEnableWatchDog#
void halInternalEnableWatchDog (void )
Enables the watchdog timer.
N/A |
60
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/micro-common.h
halInternalDisableWatchDog#
void halInternalDisableWatchDog (uint8_t magicKey)
Disables the watchdog timer.
N/A | magicKey | A value (MICRO_DISABLE_WATCH_DOG_KEY) that enables the function. |
Note
To prevent the watchdog from being disabled accidentally, a magic key must be provided.
69
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/micro-common.h
halInternalWatchDogEnabled#
bool halInternalWatchDogEnabled (void )
Determines whether the watchdog has been enabled or disabled.
N/A |
Returns
A bool value indicating if the watchdog is current enabled.
75
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/micro-common.h
halSleep#
void halSleep (SleepModes sleepMode)
Puts the microcontroller to sleep in a specified mode.
N/A | sleepMode | A microcontroller sleep mode |
Note
This routine always enables interrupts.
See Also
250
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/micro-common.h
halSleepPreserveInts#
void halSleepPreserveInts (SleepModes sleepMode)
Same as halSleep() except it preserves the current interrupt state rather than always enabling interrupts prior to returning.
N/A | sleepMode | A microcontroller sleep mode |
See Also
259
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/micro-common.h
halCommonDelayMicroseconds#
void halCommonDelayMicroseconds (uint16_t us)
Blocks the current thread of execution for the specified amount of time, in microseconds.
N/A | us | The specified time, in microseconds. Values should be between 1 and 65535 microseconds. |
The function is implemented with cycle-counted busy loops and is intended to create the short delays required when interfacing with hardware peripherals.
The accuracy of the timing provided by this function is not specified, but a general rule is that when running off of a crystal oscillator it will be within 10us. If the micro is running off of another type of oscillator (e.g. RC) the timing accuracy will potentially be much worse.
276
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/micro-common.h
halCommonDisableVreg1v8#
void halCommonDisableVreg1v8 (void )
Disable the 1.8V regulator. This function is to be used when the 1.8V supply is provided externally. Disabling the regulator saves current consumption. Disabling the regulator will cause ADC readings of external signals to be wrong. These exteranl signals include analog sources ADC0 thru ADC5 and VDD_PADS/4.
N/A |
Note
: Only used when DISABLE_INTERNAL_1V8_REGULATOR is defined.
296
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/micro-common.h
halCommonEnableVreg1v8#
void halCommonEnableVreg1v8 (void )
Enable the 1.8V regulator. Normally the 1.8V regulator is enabled out of reset. This function is only needed if the 1.8V regulator has been disabled and ADC conversions on external signals are needed. These exteranl signals include analog sources ADC0 thru ADC5 and VDD_PADS/4. The state of 1v8 survives deep sleep.
N/A |
Note
: Only used when DISABLE_INTERNAL_1V8_REGULATOR is defined.
307
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/micro-common.h
halBeforeEM4#
void halBeforeEM4 (uint32_t duration, RTCCRamData input)
N/A | duration | |
N/A | input |
318
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/micro-common.h
halAfterEM4#
RTCCRamData halAfterEM4 (void )
N/A |
319
of file /Users/vihuszar/Git/EmbeddedSoftware/super/platform/base/hal/micro/micro-common.h