cortexm_common/include/cpu.h

Basic definitions for the Cortex-M common module.

When ever you want to do something hardware related, that is accessing MCUs registers, just include this file. It will then make sure that the MCU specific headers are included.

remove include irq.h once core was adjusted

STACK_CANARY_WORD

Interrupt stack canary value.

1
(0xE7FEE7FEu)

Note

0xe7fe is the ARM Thumb machine code equivalent of asm(“bl #-2\n”) or ‘while (1);’, i.e. an infinite loop.

PROVIDES_PM_SET_LOWEST

All Cortex-m-based CPUs provide pm_set_lowest.

The pm_set_lowest is provided either by the pm_layered module if used, or alternatively as fallback by the cortexm’s own implementation.

CORTEXM_SCB_CPACR_FPU_ACCESS_FULL

Pattern to write into the co-processor Access Control Register to allow full FPU access.

1
(0x00f00000)

Used in the cortexm_common/include/cpu.h::cortexm_init_fpu() inline function below.

void cpu_init(void)

Initialization of the CPU.

void cortexm_init(void)

Initialize Cortex-M specific core parts of the CPU.

cortexm_common/include/cpu.h::cortexm_init() calls, in a default order, cortexm_common/include/cpu.h::cortexm_init_fpu(), cortexm_common/include/cpu.h::cortexm_init_isr_priorities(), and cortexm_common/include/cpu.h::cortexm_init_misc(). Also performs other default initialisations, including ones which you may or may not want.

Unless you have special requirements (like nRF52 with SD has), it is sufficient to call just cortexm_common/include/cpu.h::cortexm_init() and the cortexm_init_* functions do not need to (and should not) be called separately. If you have conflicting requirements, you may want to have a look cpu/nrft/cpu.c for an example of a non-default approach.

void cortexm_init_fpu(void)

Initialize Cortex-M FPU.

Called from cpu/nrf52/cpu.c, since it cannot use the whole cortexm_common/include/cpu.h::cortexm_init() due to conflicting requirements.

Defined here as a static inline function to allow all callers to optimise this away if the FPU is not used.

void cortexm_init_isr_priorities(void)

Initialize Cortex-M interrupt priorities.

Called from cpu/nrf52/cpu.c, since it cannot use the whole cortexm_common/include/cpu.h::cortexm_init() due to conflicting requirements.

Define CPU_CORTEXM_INIT_SUBFUNCTIONS to make this function publicly available.

void cortexm_init_misc(void)

Initialize Cortex-M misc functions.

Called from cpu/nrf52/cpu.c, since it cannot use the whole cortexm_common/include/cpu.h::cortexm_init() due to conflicting requirements.

Define CPU_CORTEXM_INIT_SUBFUNCTIONS to make this function publicly available.

void cpu_print_last_instruction(void)

Prints the current content of the link register (lr)

void cortexm_sleep_until_event(void)

Put the CPU into the ‘wait for event’ sleep mode.

This function is meant to be used for short periods of time, where it is not feasible to switch to the idle thread and back.

void cortexm_sleep(int deep)

Put the CPU into (deep) sleep mode, using the WFI instruction.

Parameters

deep:!=0 for deep sleep, 0 for light sleep

void cortexm_isr_end(void)

Trigger a conditional context scheduler run / context switch.

This function is supposed to be called in the end of each ISR.