Identifiants » Historique » Version 7
Patrice Nadeau, 2024-01-27 15:21
| 1 | 6 | Patrice Nadeau | # Objets |
|---|---|---|---|
| 2 | 3 | Patrice Nadeau | |
| 3 | ## Règles |
||
| 4 | |||
| 5 | 2 | Patrice Nadeau | 1. Comportent au maximum **31** caractères : |
| 6 | 1. Lettres minuscules |
||
| 7 | 4 | Patrice Nadeau | > Les macros sont en lettres majuscules |
| 8 | 2 | Patrice Nadeau | 1. Nombres |
| 9 | 1. Trait de soulignement |
||
| 10 | 1. Si plusieurs mots sont utilisés, ils sont séparées par des traits de soulignement |
||
| 11 | 1. Les objets ne devant plus être utilisés, DOIVENT générer un message lors de la compilation (`-Wall`) si un appel est effectué. |
||
| 12 | 1. Les attributs`deprecated` ou `unavailable` DOIVENT être ajoutés à la déclaration. |
||
| 13 | 7 | Patrice Nadeau | 1. Les commentaires Doxygen suivants doivent être ajoutés : |
| 14 | 1. `@deprecated` : |
||
| 15 | 1. `@since` : |
||
| 16 | 1 | Patrice Nadeau | |
| 17 | 3 | Patrice Nadeau | ## Exemple |
| 18 | 1 | Patrice Nadeau | ``` c |
| 19 | /** |
||
| 20 | * @brief OldFunction |
||
| 21 | * @deprecated Utiliser NewFunction à la place |
||
| 22 | * @since Version x.x.xx |
||
| 23 | */ |
||
| 24 | int OldFunction(void) __attribute__((deprecated)); |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @brief OldFunction |
||
| 28 | * @deprecated Utiliser NewFunction à la place |
||
| 29 | * @since Version x.x.xx |
||
| 30 | */ |
||
| 31 | int OldFunction(void) __attribute__((unavailable)); |
||
| 32 | 4 | Patrice Nadeau | |
| 33 | /** |
||
| 34 | * @brief MACRO1 |
||
| 35 | * @deprecated Utiliser NEWMACRO à la place |
||
| 36 | 1 | Patrice Nadeau | * @since Version x.x.xx |
| 37 | */ |
||
| 38 | #define MACRO1 43 |
||
| 39 | #pragma GCC poison MACRO1 |
||
| 40 | ``` |
||
| 41 | 5 | Patrice Nadeau | |
| 42 | ## Justification |
||
| 43 | * Linux kernel coding style : <https://www.kernel.org/doc/html/v4.10/process/coding-style.html#naming> |
||
| 44 | * GNU Coding Standards <https://www.gnu.org/prep/standards/html_node/Writing-C.html#Writing-C> |
||
| 45 | * Embedded C Coding Standard : <https://barrgroup.com/embedded-systems/books/embedded-c-coding-standard> |
||
| 46 | 1 | Patrice Nadeau | |
| 47 | ### Déclarations locales |
||
| 48 | |||
| 49 | Une déclaration n’ayant qu’une visibilité locale DOIT : |
||
| 50 | * Être de classe `static` |
||
| 51 | |||
| 52 | Exemple: |
||
| 53 | ``` c |
||
| 54 | /** |
||
| 55 | * @brief Fonction locale |
||
| 56 | * @return Une valeur |
||
| 57 | */ |
||
| 58 | static int local_func(void) { |
||
| 59 | ... |
||
| 60 | return 0; |
||
| 61 | } |
||
| 62 | ``` |
||
| 63 | |||
| 64 | ### Constantes |
||
| 65 | |||
| 66 | Utilisé au lieu d’une macro quand le type ou la visibilité de la variable doit être définis. |
||
| 67 | |||
| 68 | Exemple : |
||
| 69 | |||
| 70 | ``` c |
||
| 71 | /** |
||
| 72 | * @name Liste des constantes |
||
| 73 | * @brief |
||
| 74 | */ |
||
| 75 | /** @{ */ |
||
| 76 | /** @brief La chaîne d'initialisation du projet */ |
||
| 77 | static const char INIT_STR[6] = "POWER"; |
||
| 78 | /** @brief Constante globale de la librairie `random` */ |
||
| 79 | extern int RANDOM_MAX = 25; |
||
| 80 | /** @} */ |
||
| 81 | |||
| 82 | /** @brief Constante */ |
||
| 83 | const int ANSWER 42; |
||
| 84 | ``` |
||
| 85 | |||
| 86 | ### Énumérations |
||
| 87 | |||
| 88 | DOIT être utilisée pour définir une série de valeurs. |
||
| 89 | |||
| 90 | Exemple : |
||
| 91 | ```c |
||
| 92 | /** |
||
| 93 | * @name Liste des valeurs STATUS |
||
| 94 | * @brief |
||
| 95 | * */ |
||
| 96 | enum STATUS { |
||
| 97 | /** @brief Le processus est OK */ |
||
| 98 | STATUS_OK = 0, |
||
| 99 | /** @brief Le processus est en cours d'initialisation */ |
||
| 100 | STATUS_INIT, |
||
| 101 | /** @brief Le processus est arrêté */ |
||
| 102 | STATUS_HALTED |
||
| 103 | }; |
||
| 104 | ``` |
||
| 105 | |||
| 106 | ### Typedef |
||
| 107 | |||
| 108 | Format : |
||
| 109 | * En minuscule, suivie de **_t** |
||
| 110 | |||
| 111 | Exemple : |
||
| 112 | ``` c |
||
| 113 | /** Type de la structure dans la librairie `ds1305` */ |
||
| 114 | typedef struct { |
||
| 115 | /** @brief Dernier deux chiffres : ≥ 00, ≤ 99 */ |
||
| 116 | uint8_t year; |
||
| 117 | /** @brief 01 - 12 */ |
||
| 118 | uint8_t month; |
||
| 119 | /** @brief 01 - 31 */ |
||
| 120 | uint8_t date; |
||
| 121 | /** @brief 1 - 7 */ |
||
| 122 | uint8_t day; |
||
| 123 | /** @brief 00 - 23 */ |
||
| 124 | uint8_t hours; |
||
| 125 | /** @brief 00 - 59 */ |
||
| 126 | uint8_t minutes; |
||
| 127 | /** @brief 00 - 59 */ |
||
| 128 | uint8_t seconds; |
||
| 129 | } ds1305_time_t; |
||
| 130 | ``` |
||
| 131 | |||
| 132 | ### Variables |
||
| 133 | |||
| 134 | Exemple : |
||
| 135 | ``` c |
||
| 136 | /** @brief Variable locale */ |
||
| 137 | static int ctr; |
||
| 138 | /** @brief Variable globale */ |
||
| 139 | int RANDOM_CTR; |
||
| 140 | ``` |
||
| 141 | |||
| 142 | ### Structures |
||
| 143 | |||
| 144 | Format |
||
| 145 | * En minuscule, séparé par des «underscores» si nécessaire. |
||
| 146 | |||
| 147 | Exemple : |
||
| 148 | ``` c |
||
| 149 | /** |
||
| 150 | * @brief Structure d'un menu local |
||
| 151 | * @see MenuSelect |
||
| 152 | */ |
||
| 153 | struct menu { |
||
| 154 | /** @brief Caractère utilisé pour l'item */ |
||
| 155 | char choice; |
||
| 156 | /** @brief Description de l'item */ |
||
| 157 | char *item; |
||
| 158 | }; |
||
| 159 | ``` |
||
| 160 | |||
| 161 | ### Fonctions |
||
| 162 | |||
| 163 | * Le nom DOIT être dans le format suivant : *Item***_***Action***_***Attribut* |
||
| 164 | * *Action* signifie : |
||
| 165 | * **set**, **get**, **clear** : Règle, obtient ou vide un registre |
||
| 166 | * **read**, **write** : Lis ou écris dans un fichier |
||
| 167 | * **init** : Fonction d’initialisation |
||
| 168 | * **is** : Vérifie un état |
||
| 169 | * **setup** : Fonction de configuration des ports (AVR) |
||
| 170 | * Exceptions |
||
| 171 | * Les fonctions définies dans une librairie de bas niveau pour du matériel (« driver ») devraient utiliser le nom définis dans la fiche technique. |
||
| 172 | |||
| 173 | * Contient les champs Doxygen |
||
| 174 | * `@brief` : Brève description de la fonction |
||
| 175 | * `@param[in,out]` *paramètre* *Description* : Si nécessaire, sinon ne pas inclure le champ |
||
| 176 | * `@arg` : Valeur prédéfinie d'un paramètre (`#`, `* *`), sinon ne pas inclure le champs |
||
| 177 | * `@return` : Description de la valeur retournée, sinon le terme **Sans objet** |
||
| 178 | * `@retval` : Si une valeur de retour est prédéfinie, une ligne pour chaque valeur, sinon ne pas inclure le champs |
||
| 179 | * `@pre` : Chaque précondition, sur une ligne séparée, sinon le terme **Sans objet** |
||
| 180 | * `@post` : Chaque postcondition, sur une ligne séparée, sinon le terme **Sans objet** |
||
| 181 | * `@sa` : Si une référence a un autre objet doit être faite (#), sinon le terme **Sans objet** |
||
| 182 | * Le bloc d'exemple, si nécessaire |
||
| 183 | * `@par Example` |
||
| 184 | * `@code` |
||
| 185 | * ... |
||
| 186 | * `@endcode` |
||
| 187 | |||
| 188 | Une fonction DEVRAIT retourner une valeur. |
||
| 189 | * Type entier (oui/non) : |
||
| 190 | * Succès : **0** |
||
| 191 | * Erreur : **1** |
||
| 192 | * Type booléen (Librairie `<stdbool.h>`) |
||
| 193 | * **true** |
||
| 194 | * **false** |
||
| 195 | * Pointeur : |
||
| 196 | * **NULL** : Erreur |
||
| 197 | * Autre valeur : adresse du pointeur |
||
| 198 | |||
| 199 | Justification : |
||
| 200 | * [AVR1000b](https://ww1.microchip.com/downloads/en/Appnotes/AVR1000b-Getting-Started-Writing-C-Code-for-AVR-DS90003262B.pdf) |
||
| 201 | |||
| 202 | Exemple : |
||
| 203 | |||
| 204 | ``` c |
||
| 205 | /** |
||
| 206 | * @brief Vérifie si une horloge est initialisée |
||
| 207 | * @param[in] nb Le numéro du timer parmi |
||
| 208 | * @arg #TIMER_1 |
||
| 209 | * @arg #TIMER_2 |
||
| 210 | * @return |
||
| 211 | * @retval true Horloge *nb* est initialisée |
||
| 212 | * @retval false Horloge *nb* n'est PAS initialisée |
||
| 213 | * @pre init_timer |
||
| 214 | * @post Sans objet |
||
| 215 | **/ |
||
| 216 | static bool is_timer_set(uint8_t nb); |
||
| 217 | ``` |