13 \todo Discuss and agree on the enum naming convention
14
15 In case an enum represents a register bitfield value, then the following rules apply:
16 - The enum type shall have an explicit name. The name shall not include register or bitfield short names. This is to abstract the setting when passed as a parameter to a function in the same way the function APIs names does.
17 - Each enum member shall define explicitly an enum value with '='.
18 - The enum documentation shall state for which register bitfield the enum has been defined with "Definition for <ModuleType>.<REGISTER NAME>.B.<BITFIELDNAME>", this to avoid misuse of the enum.
19 - Each of the member shall have a documentation, that explain to users what is the enum for without reading the user manual.
20 - Only enum defined in the current Std or base drivers shall be used.
21
22 Correct:
23 \code
24 // File Std/IfxQspi.h
25
26 // QSPI controller mode
27 // Definition for Ifx_QSPI.GLOBALCON.B.MS
28 typedef enum
29 {
30 IfxQspi_Mode_master = 0, // QSPI in "master" mode
31 IfxQspi_Mode_pwmOverSpi = 1, // QSPI in "PWM over SPI" mode
32 IfxQspi_Mode_slave = 2 // QSPI in "slave" mode
33 } IfxQspi_Mode;
34
35 void IfxQspi_foo(IfxQSPI* module)
36 {
37 if (module->GLOBALCON.B.MS != IfxQspi_Mode_slave)
38 { //...
39 }
40 else
41 { // ...
42 }
43 }
44
45 \endcode
46
47 Wrong:
48 \code
49 // File 1_SrvSw/If/SscIf.h
50
51 // SSC operation modes
52 typedef enum
53 {
54 SscIf_Mode_master, // Master mode
55 SscIf_Mode_slave, // Slave mode
56 SscIf_Mode_undefined // Undefined mode
57 } SscIf_Mode;
58
59 // File Std/IfxQspi.h
60
61 // QSPI controller mode
62 typedef enum
63 {
64 IfxQspi_GLOBALCON_MS_master = 0, // Corresponds with GLOBALCON.B.MS == 0
65 IfxQspi_GLOBALCON_MS_pwmOverSpi, // Corresponds with GLOBALCON.B.MS == 1
66 IfxQspi_GLOBALCON_MS_slave // Corresponds with GLOBALCON.B.MS == 2
67 } IfxQspi_GLOBALCON_MS;
68
69 void IfxQspi_foo(IfxQSPI* module)
70 {
71 if (module->GLOBALCON.B.MS != SscIf_Mode_slave)
72 { //...
73 }
74 else
75 { // ...
76 }
77 }
78
79 \endcode
80
81
82 \section enum_in_std Usage of enums in microcontroller interface drivers
86 The code dependencies shall be limited to the microcontroller HAL and service software interface /1_SrvSw/If, therefore only enums from this files can be used.
87
88 \code
89 // File 1_SrvSw/If/SscIf.h
90
91 // SSC operation modes
92 typedef enum
93 {
94 SscIf_Mode_master, // Master mode
95 SscIf_Mode_slave, // Slave mode
96 SscIf_Mode_undefined // Undefined mode
97 } SscIf_Mode;
98
99 // File Ssc/IfxQspi_Ssc.h
100
101 // QSPI controller mode
102 // Definition for Ifx_QSPI.GLOBALCON.B.MS
103 typedef enum
104 {
105 IfxQspi_Mode_master = 0, // QSPI in "master" mode
106 IfxQspi_Mode_pwmOverSpi = 1, // QSPI in "PWM over SPI" mode
107 IfxQspi_Mode_slave = 2 // QSPI in "slave" mode