Processor-Compiler Port Files
µC/CPU contains configuration specific to each processor and compiler, such as standard data type definitions, processor address and data word sizes, endianness word order, critical section macros, and possibly other functions and macros. These are defined in each specific processor/compiler subdirectory’s cpu.h.
Standard Data Types
µC/CPU ports define standard data types such as CPU_CHAR
, CPU_BOOLEAN
, CPU_INT08U
, CPU_INT16S
, CPU_FP32
, etc. These data types are used in Micriµm applications, and may be used in your applications, to facilitate portability independent of and between processors/compilers. Most µC/CPU processor/compiler port files minimally support 32-bit data types, but may optionally support 64-bit (or greater) data types.
In addition, several regularly-used function pointer data types are defined.
CPU Words
CPU Word-Memory Order
µC/CPU ports configure CPU_CFG_ENDIAN_TYPE
to indicate the processor’s word-memory order endianness. CPU_ENDIAN_TYPE_LITTLE
indicates that a CPU stores/reads data words in memory with the most significant octets at lower memory addresses (and the least significant octets at higher memory addresses) while a CPU_ENDIAN_TYPE_BIG
CPU stores/reads data words in memory with the most significant octets at higher memory addresses (and the least significant octets at lower memory addresses).
CPU Word Sizes
µC/CPU ports include word size configuration such as CPU_CFG_ADDR_SIZE
, CPU_CFG_DATA_SIZE
, and CPU_CFG_DATA_SIZE_MAX
; configured via CPU_WORD_SIZE_08
, CPU_WORD_SIZE_16
, CPU_WORD_SIZE_32
, and CPU_WORD_SIZE_64
.
In addition, the following CPU word sizes are also defined based on the configured sizes of CPU_CFG_ADDR_SIZE
and CPU_CFG_DATA_SIZE
: CPU_ADDR
, CPU_DATA
, CPU_ALIGN
, and CPU_SIZE_T
.
CPU Stacks
µC/CPU ports configure CPU_CFG_STK_GROWTH
to indicate the direction in memory a CPU updates its stack pointers after pushing data onto its stacks. CPU_STK_GROWTH_HI_TO_LO
indicates that a CPU decrements its stack pointers to the next lower memory address after data is pushed onto a CPU stack while a CPU_STK_GROWTH_LO_TO_HI
CPU increments its stack pointers to the next higher memory address after data is pushed.
In addition, each µC/CPU processor port defines a CPU_STK
data type to the CPU’s stack word size.
CPU Critical Sections
µC/CPU ports include CPU critical section configuration CPU_CFG_CRITICAL_METHOD
that indicates how a CPU disables/re-enables interrupts when entering/exiting critical, protected sections:
CPU_CRITICAL_METHOD_INT_DIS_EN
merely disables/enables interrupts on critical section enter/exit. This is not a preferred method since it does not support multiple levels of interrupts. However, with some processors/compilers, this is the only available method.
CPU_CRITICAL_METHOD_STATUS_STK
pushes/pops interrupt status onto stack before disabling/re-enabling interrupts. This is one preferred method since it supports multiple levels of interrupts. However, this method assumes that the compiler provides C-level and/or assembly-level functionality for pushing/saving the interrupt status onto a local stack, disabling interrupts, and popping/restoring the interrupt status from the local stack.
CPU_CRITICAL_METHOD_STATUS_LOCAL
saves/restores interrupt status to a local variable before disabling/re-enabling interrupts. This also is a preferred method since it supports multiple levels of interrupts. However, this method assumes that the compiler provides C-level and/or assembly-level functionality for saving the interrupt status to a local variable, disabling interrupts, and restoring the interrupt status from the local variable.
Each µC/CPU processor port implements critical section macros with calls to interrupt disable/enable macros. Applications should only use the critical section macros (see “CPU_CRITICAL_ENTER” and CPU_CRITICAL_EXIT) since interrupt disable/enable macros (see “CPU_INT_DIS” and “CPU_INT_EN”) are intended for use only by core µC/CPU functions.
Each µC/CPU processor port may define its interrupt disable/enable macros with inline-assembly directly in cpu.h
, or calls to C functions defined in cpu.c
, or calls to assembly subroutines defined in cpu_a.asm
(or cpu_a.s
). The specific implementation should be based on the processor port’s configured CPU critical section method.
In addition, each µC/CPU processor port defines an appropriately-sized CPU_SR
data type large enough to completely store the processor’s/compiler’s status word. CPU_CRITICAL_METHOD_STATUS_LOCAL
method requires each function that calls critical section macros or interrupt disable/enable macros to declare local variable cpu_sr
of type CPU_SR
, which should be declared via the CPU_SR_ALLOC()
macro (see CPU_SR_ALLOC).