Foundation Header Examples
Informative
Generalized, vendor-neutral skeletons of the foundation headers described in
Reference. They show the structure and the relevant parts only; the concrete
integer mapping, section attributes, and compiler keywords are target/compiler specific. Mip /
MIP stands in for a module implementation prefix.
Std_Types.h
Small and portable — it just pulls in the platform and compiler headers and defines the standard return type and on/off constants.
#ifndef STD_TYPES_H
#define STD_TYPES_H
#include "Compiler.h" /* compiler abstraction */
#include "Platform_Types.h" /* platform types */
#define E_OK (0x00U) /* API completed without error */
#define E_NOT_OK (0x01U) /* API detected an error */
#define STD_ON (0x01U)
#define STD_OFF (0x00U)
/* One of E_OK / E_NOT_OK, or a module-specific extended value (0x02..0xFF). */
typedef uint8 Std_ReturnType;
#endif /* STD_TYPES_H */
Normative: CHI-GEN-MUST-09 — a driver uses the standard type system instead of native C types; see standard types.
Platform_Types.h
The constants are fixed; the integer typedefs and the three CPU_* selections are chosen to match
the target architecture (a 32-bit little-endian MCU is shown).
#ifndef PLATFORM_TYPES_H
#define PLATFORM_TYPES_H
#define TRUE (1U)
#define FALSE (0U)
#define CPU_TYPE_8 (8U)
#define CPU_TYPE_16 (16U)
#define CPU_TYPE_32 (32U)
#define CPU_TYPE_64 (64U)
#define MSB_FIRST (0U)
#define LSB_FIRST (1U)
#define HIGH_BYTE_FIRST (0U)
#define LOW_BYTE_FIRST (1U)
/* Select the values that match the target: */
#define CPU_TYPE (CPU_TYPE_32)
#define CPU_BIT_ORDER (LSB_FIRST)
#define CPU_BYTE_ORDER (LOW_BYTE_FIRST)
/* The concrete mapping is target/compiler specific — example for a 32-bit MCU: */
typedef unsigned char boolean;
typedef unsigned char uint8;
typedef signed char sint8;
typedef unsigned short uint16;
typedef signed short sint16;
typedef unsigned long uint32;
typedef signed long sint32;
typedef unsigned long long uint64;
typedef signed long long sint64;
typedef float float32;
typedef double float64;
/* "least" types: fastest integer at least as wide as the named width */
typedef unsigned long uint8_least;
typedef unsigned long uint16_least;
typedef unsigned long uint32_least;
typedef signed long sint8_least;
typedef signed long sint16_least;
typedef signed long sint32_least;
#endif /* PLATFORM_TYPES_H */
Normative: CHI-GEN-MUST-09 — the platform types and CPU_* descriptors are part of the
shared type system; see platform types.
Compiler.h
Abstracts the compiler’s inline keyword, memory classes, and the declaration macros. The expansions below are illustrative — the exact qualifier placement is compiler-dependent, and each symbol is guarded against double definition in a production header.
#ifndef COMPILER_H
#define COMPILER_H
#include "Compiler_Cfg.h" /* module-specific memory and pointer classes */
#define NULL_PTR ((void *)0)
#define INLINE inline /* or empty, if unsupported */
#define LOCAL_INLINE static inline
/* memory classes that map to no compiler keyword */
#define AUTOMATIC
#define TYPEDEF
/* variables and constants */
#define VAR(variable_type, memory_class) memory_class variable_type
#define CONST(variable_type, memory_class) memory_class const variable_type
/* pointers */
#define P2VAR(type, mem_class, ptr_class) ptr_class type * mem_class
#define P2CONST(type, mem_class, ptr_class) const type ptr_class * mem_class
/* functions */
#define FUNC(return_type, memory_class) memory_class return_type
/* CONSTP2VAR, CONSTP2CONST, P2FUNC, CONSTP2FUNC, FUNC_P2VAR, FUNC_P2CONST
follow the same pattern — see the reference. */
#endif /* COMPILER_H */
Normative: CHI-GEN-MUST-09 — the compiler-abstraction and declaration macros are part of the shared contract; see memory class macros and declaration macros.
Mip_MemMap.h
The memory-mapping header is included once per section, each time with exactly one
MIP_START_SEC_* or MIP_STOP_SEC_* selected. It therefore deliberately has no include
guard. The block below shows one section pair; the same pattern repeats for every section keyword
the module uses (CODE, CONST_*, VAR_INIT_*, VAR_CLEARED_*,
VAR_POWER_ON_CLEARED_*, …).
/* NOTE: no include guard on purpose — this file is included many times. */
#ifdef MIP_START_SEC_VAR_CLEARED_32
#undef MIP_START_SEC_VAR_CLEARED_32
/* place the target-specific section #pragma / attribute here, if any */
#endif
#ifdef MIP_STOP_SEC_VAR_CLEARED_32
#undef MIP_STOP_SEC_VAR_CLEARED_32
/* close the section opened above */
#endif
Normative: CHI-GEN-MUST-07 (memory-mapping mechanism), CHI-GEN-MUST-08 (allocation-keyword templates).
Note
Production headers usually add a small consistency check (e.g. a MEMMAP_STARTED marker) so a
start without a matching stop, or two starts in a row, raise a #error at compile time. It is
omitted here for clarity.