F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
BasicTypes.h
Go to the documentation of this file.
1 // ======================================================================
2 // \title Fw/Types/BasicTypes.h
3 // \author mstarch
4 // \brief h file for FPrime basic numerical aliases (I8, U64, etc.)
5 //
6 // \copyright
7 // Copyright 2024, by the California Institute of Technology.
8 // ALL RIGHTS RESERVED. United States Government Sponsorship
9 // acknowledged.
10 //
11 // FPrime allows use of shorthand fixed-with types. This file provides
12 // these definitions. I# is a signed integer of width #, U# is an unsigned
13 // integer of width #, F# is a floating point number of width #.
14 //
15 // This file also contains macros for a number of useful operations:
16 //
17 // - FW_NUM_ARRAY_ELEMENTS(a): number of elements in an array
18 // - FW_MAX(a, b): maximum of a and b
19 // - FW_MIN(a, b): minimum of a and b
20 //
21 // - FW_NO_ASSERT: constant for assertions turned off
22 // - FW_FILEID_ASSERT: constant for assertions reported as a file CRC and line number
23 // - FW_FILENAME_ASSERT: constant for assertions reported as a file path and line number
24 // - FW_RELATIVE_PATH_ASSERT: constant for assertions reported as a relative path within
25 // FPrime and line number
26 //
27 //
28 // This header is intended to be C-compatible.
29 //
30 // ======================================================================
31 #ifndef FW_BASIC_TYPES_H
32 #define FW_BASIC_TYPES_H
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 #include <config/FPrimeNumericalConfig.h>
38 #include <inttypes.h> // Standard integer types and printf macros
39 
40 // Compiler checks
41 #if defined(__GNUC__) || defined(__llvm__) || defined(PLATFORM_OVERRIDE_GCC_CLANG_CHECK)
42 #else
43 #error \
44  "FPrime only supports GCC or Clang compilers. You may attempt to use other compilers by defining PLATFORM_OVERRIDE_GCC_CLANG_CHECK, but this is not recommended."
45 #endif
46 
47 /*----------------------------------------------------------------------------*/
48 /* Type definitions: I8, U8, I16, U16, ..., I64, U64, F32, and F64 */
49 /*----------------------------------------------------------------------------*/
50 typedef int8_t I8;
51 #define PRI_I8 PRIi8 // NO_CODESONAR LANG.PREPROC.MACROSTART/END
52 
53 typedef uint8_t U8;
54 #define PRI_U8 PRIu8 // NO_CODESONAR LANG.PREPROC.MACROSTART/END
55 
56 typedef U8 BYTE;
57 #define PRI_BYTE PRIu8 // NO_CODESONAR LANG.PREPROC.MACROSTART/END
58 
59 typedef char CHAR;
60 #define PRI_CHAR "c" // NO_CODESONAR LANG.PREPROC.MACROSTART/END
61 
62 #if FW_HAS_16_BIT
63 typedef int16_t I16;
64 #define PRI_I16 PRIi16 // NO_CODESONAR LANG.PREPROC.MACROSTART/END
65 typedef uint16_t U16;
66 #define PRI_U16 PRIu16 // NO_CODESONAR LANG.PREPROC.MACROSTART/END
67 #endif
68 
69 #if FW_HAS_32_BIT
70 typedef int32_t I32;
71 #define PRI_I32 PRIi32 // NO_CODESONAR LANG.PREPROC.MACROSTART/END
72 typedef uint32_t U32;
73 #define PRI_U32 PRIu32 // NO_CODESONAR LANG.PREPROC.MACROSTART/END
74 #endif
75 
76 #if FW_HAS_64_BIT
77 typedef int64_t I64;
78 #define PRI_I64 PRIi64 // NO_CODESONAR LANG.PREPROC.MACROSTART/END
79 typedef uint64_t U64;
80 #define PRI_U64 PRIu64 // NO_CODESONAR LANG.PREPROC.MACROSTART/END
81 #endif
82 
83 typedef float F32;
84 #define PRI_F64 "lf" // NO_CODESONAR LANG.PREPROC.MACROSTART/END
85 typedef double F64;
86 
87 /*----------------------------------------------------------------------------*/
88 /* Useful macro definitions */
89 /*----------------------------------------------------------------------------*/
90 #define FW_NUM_ARRAY_ELEMENTS(a) (sizeof(a) / sizeof((a)[0]))
91 // Deprecated: prefer std::max/std::min from <algorithm> in C++ code.
92 // Kept for C compatibility only.
93 #define FW_MAX(a, b) (((a) > (b)) ? (a) : (b))
94 #define FW_MIN(a, b) (((a) < (b)) ? (a) : (b))
95 
96 #define FW_NO_ASSERT (1)
97 #define FW_FILEID_ASSERT \
98  (2)
99 #define FW_FILENAME_ASSERT (3)
100 #define FW_RELATIVE_PATH_ASSERT \
101  (4)
102 
104 #ifdef __cplusplus
105 }
106 #endif
107 #endif // FW_BASIC_TYPES_H
int8_t I8
8-bit signed integer
Definition: BasicTypes.h:50
char CHAR
Definition: BasicTypes.h:59
float F32
32-bit floating point
Definition: BasicTypes.h:83
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:53
double F64
64-bit floating point (double). Required for compiler-supplied double promotion.
Definition: BasicTypes.h:85
U8 BYTE
byte type
Definition: BasicTypes.h:56
#define U64(C)
Definition: sha.h:181