Coding style guideline in TIMotorLIB ------------------------------------ This file describes the guidelines for writing code to be included in TIMotorLIB. 1 - Files: ---------- 1.1) Any file in the library MUST include the LGPL license at the begining of the file: /****************************************************************************** ** Copyright (C) 2010 ** Author1 <mail@author2> ** Author2 <mail@author1> ** ** This library is free software; you can redistribute it and/or ** modify it under the terms of the GNU Lesser General Public ** License as published by the Free Software Foundation; either ** version 2.1 of the License, or (at your option) any later version. ** This library is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ** Lesser General Public License for more details. ** You should have received a copy of the GNU Lesser General Public ** License along with this library; if not, write to the Free Software ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ******************************************************************************/ 1.2) Code lenguage is ENGLISH. Do not include any comments or variable name in other language 1.2) Any file in the library MUST end with the following comment block and a empty new line after it //----------------------------------------------------------------------------- // End Of File //----------------------------------------------------------------------------- 1.3) Header files MUST follow the following structure: - LGPL LICENSE - File description as shown in the following example: /**\file********************************************************************** File Name: adc.h Project: TIMotorLIB TI Doc: <a href="http://focus.ti.com/lit/ds/sprs439h/sprs439h.pdf"> SPRS439</a> \author Pablo Garcia (pgarcia@isa.uniovi.es) \brief AD Routines \date 2007 ******************************************************************************/ //----------------------------------------------------------------------------- // Define //----------------------------------------------------------------------------- #ifndef MYUNIT_H #define MYUNIT_H - needed #define macro //----------------------------------------------------------------------------- // Includes //----------------------------------------------------------------------------- - needed #include macros //----------------------------------------------------------------------------- // typedefs // ---------------------------------------------------------------------------- - needed typedefs //----------------------------------------------------------------------------- // Implemented Functions //----------------------------------------------------------------------------- - prototypes of ALL implemented functions - implementation of static inline functions - for code readability, functions are separated using a: //----------------------------------------------------------------------------- - before the DECLARATION of a function, a brief description MUST be included. For automatic documentation generation, the description MUST be done as the following example: //----------------------------------------------------------------------------- /// Read two AD simulatenous inputs in units and write raw (bits) value to internal memory. /// /// \param aInput: a input to be read. /// \param bInput: b input to be read. /// \param aVal: readed value for a input /// \param bVal: readed value for b input /// \return nothing //----------------------------------------------------------------------------- static inline void ReadADSimultaneousInputWriteRaw(Uint16 aInput, Uint16 bInput, volatile _iq* aVal, volatile _iq* bVal); 2 - Function names: ------------------- Function names are capitalized as shown in the following example: void MyFoo(void); 3 - Variable names: ------------------- 3.1) Variable names are declared with the first character in lower-case: int foo; 3.2) If the variable name contains more than one word, first character of each word is in upper-case: int myFoo; 3.3) avoid too short (2 or less characters) or too long (15 or more) variable names 3.4) each variable declaration on a new line 3 - Macros: ----------- Macro names have all the name characters in upper-case: #define MYFOO 1 4 - Blocks of code and braces: ------------------------------ 4.1) Braces, wheen needed for delimiting blocks of code, MUST be opened at the same line the block begins and closed at a new line after the block ends: for(int i=0;i<2;i++) { // .... This is OK } for(int i=0;i<2;i++) { // .... This is NOT OK } 4.2) Braces related to functions bodies MUST be opened and closed at their own line: void MyFunction(void) { } 5 -Indentation: ------------- 5.1) Indentation is done by 4 spaces for each level. Spaces are preferred to tab.