Microcontroller functions#

See also hal/micro/cortexm3/micro.h for source code.

Microcontroller functions.

Many of the supplied example applications use these microcontroller functions. See hal/micro/micro.h for source code.

Note

  • The term SFD refers to the Start Frame Delimiter.

Vector Table Index Definitions#

These are numerical definitions for vector table.Only Cortex-M standard exception vectors (indices 0 through 15) are represented since device specific vectors can be (and often are) different across dies.

#define
STACK_VECTOR_INDEX 0U

A numerical definition for a vector.

#define
RESET_VECTOR_INDEX 1U

reset vector index

#define
NMI_VECTOR_INDEX 2U

nmi vector index

#define
HARD_FAULT_VECTOR_INDEX 3U

hard fault vector index

#define
MEMORY_FAULT_VECTOR_INDEX 4U

memory fault vector index

#define
BUS_FAULT_VECTOR_INDEX 5U

bus fault vector index

#define
USAGE_FAULT_VECTOR_INDEX 6U

usage fault vector index

#define
RESERVED07_VECTOR_INDEX 7U

reserved07 vector index

#define
RESERVED08_VECTOR_INDEX 8U

reserved08 vector index

#define
RESERVED09_VECTOR_INDEX 9U

reserved09 vector index

#define
RESERVED10_VECTOR_INDEX 10U

reserved10 vector index

#define
SVCALL_VECTOR_INDEX 11U

svcall vector index

#define
DEBUG_MONITOR_VECTOR_INDEX 12U

debug monitor vector index

#define
RESERVED13_VECTOR_INDEX 13U

reserved13 vector index

#define
PENDSV_VECTOR_INDEX 14U

pendsv vector index

#define
SYSTICK_VECTOR_INDEX 15U

systick vector index

#define
IRQ_TO_VECTOR_NUMBER (x)

Utility macro to convert from IRQ numbers to exception numbers/ vector indices.

#define
VECTOR_TABLE_LENGTH (IRQ_TO_VECTOR_NUMBER(EXT_IRQ_COUNT))

Number of vectors.

Functions#

void
halInternalSysReset(uint16_t extendedCause)

Records the specified reset cause then forces a reboot.

uint16_t

Returns the Extended Reset Cause information.

uint8_t

Calls halGetExtendedResetInfo() and translates the EM35x reset code to the corresponding value used by the EM2XX HAL.

const char *

Calls halGetExtendedResetInfo() and supplies a string describing the extended cause of the reset.

void
halInit(void)

Initializes microcontroller-specific peripherals.

void
halReboot(void)

Restarts the microcontroller and therefore everything else.

void

Enables the watchdog timer.

void
halInternalDisableWatchDog(uint8_t magicKey)

Disables the watchdog timer.

bool

Determines whether the watchdog has been enabled or disabled.

void

hal Reset Watchdog

void
halInternalSetCtune(uint16_t tune)

Change the CTUNE value.

uint16_t

Get the CTUNE value.

uint8_t

Gets information about what caused the microcontroller to reset.

const char *

Calls halGetResetInfo() and supplies a string describing it.

Macros#

#define
EM2XX_RESET_UNKNOWN 0

EM2xx-compatible reset code returned by halGetEm2xxResetInfo()

#define
EM2XX_RESET_EXTERNAL 1

EM2XX reports POWERON instead.

#define
EM2XX_RESET_POWERON 2

EM2XX reset poweron.

#define
EM2XX_RESET_WATCHDOG 3

EM2XX reset watchdog.

#define
EM2XX_RESET_ASSERT 6

EM2XX reset assert.

#define
EM2XX_RESET_BOOTLOADER 9

EM2XX reset bootloader.

#define
EM2XX_RESET_SOFTWARE 11

EM2XX reset software.

#define
MICRO_DISABLE_WATCH_DOG_KEY 0xA5U

The value that must be passed as the single parameter to halInternalDisableWatchDog() in order to successfully disable the watchdog timer.

Vector Table Index Definitions Documentation#

Function Documentation#

halInternalSysReset#

void halInternalSysReset (uint16_t extendedCause)

Records the specified reset cause then forces a reboot.

Parameters
TypeDirectionArgument NameDescription
uint16_tN/AextendedCause

halGetExtendedResetInfo#

uint16_t halGetExtendedResetInfo (void )

Returns the Extended Reset Cause information.

Parameters
TypeDirectionArgument NameDescription
voidN/A

Returns

  • A 16-bit code identifying the base and extended cause of the reset


halGetEm2xxResetInfo#

uint8_t halGetEm2xxResetInfo (void )

Calls halGetExtendedResetInfo() and translates the EM35x reset code to the corresponding value used by the EM2XX HAL.

Parameters
TypeDirectionArgument NameDescription
voidN/A

Any reset codes not present in the EM2XX are returned after being OR'ed with 0x80.

Used by the EZSP host as a platform-independent NCP reset code.

Returns

  • The EM2XX-compatible reset code. If not supported by the EM2XX, return the platform-specific code with B7 set.


halGetExtendedResetString#

const char * halGetExtendedResetString (void )

Calls halGetExtendedResetInfo() and supplies a string describing the extended cause of the reset.

Parameters
TypeDirectionArgument NameDescription
voidN/A

halGetResetString() should also be called to get the string for the base reset cause

Useful for diagnostic printing of text just after program initialization.

Returns

  • A pointer to a program space string.


halInit#

void halInit (void )

Initializes microcontroller-specific peripherals.

Parameters
TypeDirectionArgument NameDescription
voidN/A

halReboot#

void halReboot (void )

Restarts the microcontroller and therefore everything else.

Parameters
TypeDirectionArgument NameDescription
voidN/A

halInternalEnableWatchDog#

void halInternalEnableWatchDog (void )

Enables the watchdog timer.

Parameters
TypeDirectionArgument NameDescription
voidN/A

halInternalDisableWatchDog#

void halInternalDisableWatchDog (uint8_t magicKey)

Disables the watchdog timer.

Parameters
TypeDirectionArgument NameDescription
uint8_tN/AmagicKey

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.


halInternalWatchDogEnabled#

bool halInternalWatchDogEnabled (void )

Determines whether the watchdog has been enabled or disabled.

Parameters
TypeDirectionArgument NameDescription
voidN/A

Returns

  • A bool value indicating if the watchdog is current enabled.


halResetWatchdog#

void halResetWatchdog (void )

hal Reset Watchdog

Parameters
TypeDirectionArgument NameDescription
voidN/A

halInternalSetCtune#

void halInternalSetCtune (uint16_t tune)

Change the CTUNE value.

Parameters
TypeDirectionArgument NameDescription
uint16_tN/Atune

Value to set CTUNE to.

Involves switching to HFRCO and turning off the HFXO temporarily.


halInternalGetCtune#

uint16_t halInternalGetCtune (void )

Get the CTUNE value.

Parameters
TypeDirectionArgument NameDescription
voidN/A

Returns

  • Current CTUNE value.


halGetResetInfo#

uint8_t halGetResetInfo (void )

Gets information about what caused the microcontroller to reset.

Parameters
TypeDirectionArgument NameDescription
voidN/A

Returns

  • A code identifying the cause of the reset.


halGetResetString#

const char * halGetResetString (void )

Calls halGetResetInfo() and supplies a string describing it.

Parameters
TypeDirectionArgument NameDescription
voidN/A

Useful for diagnostic printing of text just after program initialization.

Returns

  • A pointer to a program space string.