DigiBee CodeGuidelines v0.6
DigiBee CodeGuidelines v0.6
Version: 0.6
Name:
Date:
AUTHOR INFORMATION
DOCUMENT APPROVAL
REVISION HISTORY
TABLE OF CONTENTS
1 OVERVIEW.............................................................................................................................................................. 5
1.1 Scope & Objectives.......................................................................................................................................
Objectives....................................................................................................................................... 5
1.2 Document Conventions.................................................................................................................................
Conventions................................................................................................................................. 5
2 CODING GUIDELINES............................................................................................................................................ 5
2.1 Code Base Maintenance...............................................................................................................................
Maintenance............................................................................................................................... 5
2.2 File extension Conventions............................................................................................................................
Conventions............................................................................................................................ 6
2.3 Headers.........................................................................................................................................................
Headers ......................................................................................................................................................... 6
2.4 Assembly files Headers.................................................................................................................................
Headers................................................................................................................................. 7
2.5 Commenting style..........................................................................................................................................
style.......................................................................................................................................... 7
2.6 Text Formatting.............................................................................................................................................
Formatting............................................................................................................................................. 7
2.7 Header File organization................................................................................................................................
organization................................................................................................................................ 7
2.8 Variables........................................................................................................................................................
Variables........................................................................................................................................................ 7
2.9 Naming Convention.......................................................................................................................................
Convention....................................................................................................................................... 7
3 ANNEX A : DOCUMENTATION FOR DOXYGEN.................................................................................................... 7
3.1 Special documentation blocks.......................................................................................................................
blocks....................................................................................................................... 7
3.2 Documentation after members.......................................................................................................................
members....................................................................................................................... 7
3.2.1 Documentation at other places................................................................................................................. 7
3.2.2 List:........................................................................................................................................................... 7
1 Overview
This document describes C/C++/assembly language based coding standards and guidelines for
software development work within DGB Software Engineering group. The purpose of these coding
standards is to enhance consistency, readability, maintainability, and reusability of code. The
contents of this document are a bulleted summary of each of the concepts and a brief description of
each following them. This should be used as a reference guide. An effort shall be made at code
reviews and inspections to check to make sure that the coding standards are followed.
These standards are to be followed for all new code development in DGB. For code that we inherit
from other groups, we shall adhere to the coding standards followed by the originating group. In
terms of style, it should be difficult to determine what was written by DGB and the original code. An
exception to this is that additions and modifications must be well commented, regardless of how
much commenting the original code contains.
2 Coding Guidelines
2.1 Code Base Maintenance
[CG01] The modules, module names, files in each module, and file names
shall be identified at design cycle. Any change in this shall be discussed with the
team lead.
To avoid any uncontrolled development of code, at the design itself the module names and file
names are decided.
[CG02] The file names shall be in mixed case format, maximum of 32 ASCII
characters and has no white spaces. File and function names follow the convention of
XyzXxxxAbcd#, where the beginning Xyz is the module prefix and XxxxAbcd is the name. An underscore or
number cannot be the first character of either the module prefix or the name.
Example: MemcpyCommonFunctions.c
Example: ChenDCT.c, MotionEstimation.c
[CG03] The code shall be organized should be followed as per the document
Configuration Management Plan Multimedia Cell Phone (MCP) – Software.
2.3 Headers
[CG04] All files shall have the copyright notice as given below at the
beginning of the file.
/*******************************************************************************
**
** Copyright (c) 2004 2005 by DigiBee Microsystems Pvt Ltd
**
** All rights are reserved. Reproduction in whole or in part is prohibited
** without the written consent of the copyright owner.
**
** DigiBee MicroSystems reserves the right to make changes without notice
** at any time. DigiBee Microsystems makes no warranty, expressed, implied
** or statutory, including but not limited to any implied warranty of
** merchantability of fitness for any particular purpose, or that the use
** will not infringe any third party patent, copyright or trademark.
** DigiBee Microsystems must not be liable for any loss or damage arising
** from its use.
**
** This Copyright notice may not be removed or modified without prior
** written consent of DigiBee Microsystems.
**
*******************************************************************************/
[CG05] All files shall have the header immediately after the copyright notice
as per the format given below
/*!
********************************************************************************
** \file Filename
** \brief
** This describes what functions this file does. For example,
** within a module or subsystem, what are the functionalities
** provided by this file.
** \date DATE (optional)
** \author
** AuthorName (optional)
** \par Histoty:
** - 23-Sep-2004
** - Authors
** - Reference
** .
** - Revision history shall be given in a free flowing text format
** in a short Paragraph.
** - 20-Sep-2004
** - Author
** - Initial Draft
** \note
** Any special comment (optional)
** \bug
** Any bug report. It will generate reference in bug list
** generated by doxygen (optional)
**
********************************************************************************
*/
[CG06] The revision history in the file header field shall be written in reverse
chronological order. The description shall be in brief.
/***************************************************************************
* RCS INFORMATION:
*
* $RCSfile: Filename,v $
* $Author: AuthorName $ $Locker: $ $State: Exp $
* $Revision: Revision Number $ $Date: YYYY/MM/DD HH:MM:SS $
*
***************************************************************************/
[CG07] All function definitions shall precede with a function header as per
the format given below.
/*!
* \brief Brief description of function
*
* \fn Function name (optional if block is place just before the fuction)
* Detail description goes here. Note: by default doxygen will make brief
* description, first sentence of detail description
* \param Parameter1 Detail of it (optional)
* \param Parameter2 Detail of it (optional)
* \param ParameterN Detail of it (optional)
* \return Detail of return value (optional)
* \bug Bug report (optional)
* \note Any comment (optional)
*/
[CG08] All definitions of structures, enums, and unions shall precede with a
header as per the format given below.
/*!
* \brief brief description
* of the .. ..
*
* more description
*
*/
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Copyright (c) 2004 2005 by DigiBee Microsystems
;;
;; All rights are reserved. Reproduction in whole or in part is prohibited
;; without the written consent of the copyright owner.
;;
;; Digibee MicroSystems Pvt Ltd reserves the right to make changes without notice
;; at any time. DigibBee Microsystems makes no warranty, expressed, implied
;; or statutory, including but not limited to any implied warranty of
;; merchantability of fitness for any particular purpose, or that the use
;; will not infringe any third party patent, copyright or trademark.
;; DigibBee Microsystems must not be liable for any loss or damage arising
;; from its use.
;;
;; This Copyright notice may not be removed or modified without prior
;; written consent of DigiBee Microsystems.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
[CG11] All Assembly source / include files shall have the header immediately after the copyright notice as
per the format given below
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; \file Filename
;; \brief
;; This describes what functions this file does. For example,
;; within a module or subsystem, what are the functionalities
;; provided by this file.
;; \date DATE (optional)
;; \author
;; AuthorName (optional)
;; \par Histoty:
;; - 23-Sep-2004
;; - Authors
;; - Reference
;; .
;; - Revision history shall be given in a free flowing text format
;; in a short Paragraph.
;; - 20-Sep-2004
;; - Author
;; - Initial Draft
;; \note
;; Any special comment (optional)
;; \bug
;; Any bug report. It will generate reference in bug list
;; generated by doxygen (optional)
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
[CG12] All Assembly source / include files revision history in the file header field shall be written in reverse
chronological order. The description shall be in brief.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; RCS INFORMATION:
;;
;; $RCSfile: Filename,v $
;; $Author: AuthorName $ $Locker: $ $State: Exp $
;; $Revision: Revision Number $ $Date: YYYY/MM/DD HH:MM:SS $
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
[CG13] Parameters are passed through registers. Register name should be written clearly.
[CG14] It is functions responsibility to save (push and pop) all the registers which function uses as scratch
registers.
[CG15] Every source file should have proper Section begin Align Details
[CG16] All Assembly source / include files function definitions shall precede with a function header as per
the format given below.
[CG17] Jump Lables should of the format XyzXxxxAbcd#, where the beginning Xyz is the module prefix and
XxxxAbcd is the name. # is the number. An underscore or number cannot be the first character of either the
module prefix or the name.
[CG18] All Assembly source / include files function definitions shall precede with a function header as per
the format given below.
;;
; \brief Brief description of function
;
; \fn Function name (optional if block is place just before the fuction)
; Detail description goes here. Note: by default doxygen will make brief
; description, first sentence of detail description
; \param Parameter1 Register name (Should)
; \param Parameter2 Register name (Should)
; \param ParameterN Register name (Should)
; \return Detail of return value Register name (Should)
; \bug Bug report (optional)
; \note Any comment (optional)
;;
*/
[CG21] No Code segment shall be placed in the lines where multiple line
comments are placed.
Eg:
int * RxedPacket ; /* address for Rxed Packet
Has the constraints …. */
is not allowed. Do the same in following way.
/*
* address for Rx’ed packet
* has the constraints …
*/
int *RxedPacket ;
[CG22] Comments shall be included to explain the execution logic of the
code.
Comments need not explain the obvious in the code, which is best understood by C code it self.
Eg: for (i = 0; i < 30; i++) // Loop 30 times
The comment above is not necessary.
At the same time comment shall be included when the code is not easy to understand.
Eg: if ((x_coordinate < 0) || (y_coor < 0) ) // Point out of the range.
The above comment explains the meaning.
References to documents are allowed if it is hard to explain in comment.
Eg: fast_dct() // Implements DCT as per design doc “MPEG-4 design.doc”
[CG23] Programs may have a VERBOSE mode optionally enabled by a
preprocessor constant. When enabled the function entry, steps in function
execution, and function exit would be logged.
[CG24] Programs may have DEBUG mode optionally enabled by a
preprocessor constant. When enabled the assumed operating conditions are
verified.
[CG25] Programs may have a DATA_DUMP mode optionally enabled by a
preprocessor constant. When enabled the data is dumped. The details of this
functionality are identified at design level.
[CG26] Programs may have a PERF_CALC mode optionally enabled by a
preprocessor constant. When enabled the performance cycles are measured and
logged. The details of this functionality are identified at design level.
Example:
1. Project level the main include file has the following definitions
#define VERBOSE
#define DEBUG
#define DATA_DUMP
#define PERF_CALC
#ifdef VERBOSE
#define MODULE1_VERBOSE // for the modules define the macros
#define MODULEn_VERBOSE // one of these can be commented if that module is not under VERBOSE
#endif
#ifdef DEBUG
#ifdef DATA_DUMP
#define MODULE1_ DATA_DUMP
#define MODULEn_ DATA_DUMP
#endif
#ifdef PERF_CALC
#define MODULE1_ PERF_CALC
#define MODULEn_ PERF_CALC
#endif
#ifdef VERBOSE
#define LOG_VERBOSE(c) log_verbose(c)
#else
#define LOG_VERBOSE(c)
#endif
#ifdef DEBUG
#define ASSERT_PRECONDITION(cond)
assert(cond); // change it as u like it
#else
#define ASSERT_PRECONDITION(cond)
#endif
#ifdef DEBUG
#define ASSERT_POSTCONDITION(cond)
assert(cond); // change it as u like it
#else
#define ASSERT_POSTCONDITION(cond)
#endif
#ifdef DATA_DUMP
#define DUMP_ALL_DATA(ptrX, sizeOfX)
data_dump(ptrX, sizeOfX);
#else
#define DUMP_ALL_DATA(ptrX, sizeOfX)
#endif
#ifdef PREF_CALC
#define LOG_TIME_STAMP(TIMESTAMP_ID)
log_time_stamp(TIMESTAMP_ID);
else
define LOG_TIME_STAMP(TIMESTAMP_ID)
endif
DUMP_ALL_DATA(&x,sizeof(x));
LOG_TIME_STAMP(Func1_ID);
ASSERT_POSTCONDITION((y>10));
return SUCCESS;
4. Have header files FileDebug.h, FileVerbose.h, FileDataDump.h, and FilePerfCalc.h each having
#ifdef LOG_VERBOSE(c)
#undefine LOG_VERBOSE(c)
#endif
#define LOG_VERBOSE(c) log_verbose(c)
These files can be included when only one file is under VERBOSE. Similar to the example above, the other
DEBUG, DATA_DUMP, and PERF_CALC.
In these,
► VERBOSE mode is useful to trace the working path of the program.
► DEBUG mode is useful to check the assumptions made. This can also be success of memory
allocation, success of file opening, etc. When it is switched off the performance would he
higher.
► DATA_DUMP mode is useful in debugging.
► PERF_CALC mode is useful in calculating the performance at module level.
[CG40] The code block in the constructs ‘for’, ‘if’, ‘else’, ‘do-while’ and ‘while’
shall be embedded in curly braces, even when the block contains only one line.
Example:
for (i = 0; i < 30; i++)
{ // Though only one statement, put a {
if (condition)
{ // though only one statement put a {
x=y;
}
while ( TRUE == Condition )
{
/* Do something here */
...
...
}
do
{
/* Do something here */
...
...
} while ( Condition );
}
[CG41] The code associated with ‘switch’ construct shall be embedded in
curly braces.
switch ( Value )
{
case 1:
...
break;
case 2:
...
break;
default:
break;
}
[CG42] The “goto” construct shall not be used in C.
[CG43] A zero & non-zero condition checking shall be explicit.
Examples:
if (x) //this is not allowed as it assumes checking for non-zero value
if (x != 0) // this is allowed
#endif
[CG44] The user-defined files shall be included in a file using the relative
path of the included file and file name.
Example:
#include <UserDefined.h> // this is not allowed
#include “../dir1/UserDefined1.h” // this is allowed.
[CG45] Each project shall have a header file that is named in
<project>_exports.h. Any other project that wants to include the functionality of
this project shall include only <project>_exports.h
[CG46] The standard C includes, includes from external libraries, and any
macros / typedefs, as applicable, shall be organized in a central file
project_common.h
[CG47] All files shall be organized in the following order, as applicable
#includes project common.h
#includes from external modules of this project
#includes from current module
Conditional Compiles // #define DEBUG_MODE
Preprocessor Macros // eg: #define mNEGTIVE(x) (-(x))
Preprocessor constants // eg: #define LEN 255
Typedefs of structures
Typedefs of Enums
Typedefs of Unions
Global constants
Global variables
Function declarations
Function definitions
[CG48] Each Module, identified as part of design cycle, shall have a header
file that is named in the module_exports.h. Any other program that wants to
include the functionality of this module shall include only module_exports.h
[CG49] Each module shall have a header file named module_internal.h. The
first include file in module_internal.h is module_exports.h. All .h files as part of the
module shall be included in the module_internal.h.
[CG50] The module_intenal.h shall be the only included header file in all the
files in the module.
[CG51] C file shall not be included in any programs. Only h files shall be
included.
[CG52] Preprocessor conditional compiles, constants and macros that are
identified at design level shall only be used. Developer shall discuss with tech
prime to define other preprocessor constants or macros. This includes anything to
do with #define.
[CG53] Preprocessor conditional compiles, constants shall be in all capital
letters.
[CG54] Preprocessor Macro shall start with letter M and contains all capital
letters followed by this letter. Multilane macros should use a block of their own.
Example:
#define M_MEMCPY_ENABLE_READ() ((*(volatile WORD *)MEMCPY_ENABLE) |= 0x1)
#define M_MACRO(x) \
do { \
some c statement; \
some other c statement; \
} while (0);
2.8 Variables
[CG55] Data types defined in C shall not be used in its original form. The
header file “common.h” defined as part of this document contains the following
data types for use in the program.
[CG56] User defined structures, enums, and unions shall be type defined.
[CG57] User defined Structures, enums and unions shall be identified at
design level and only those without any modifications shall be used. Developer
shall discuss with technical prime to define any new ones or any modifications.
[CG58] All global and static variables shall be explicitly initialized.
[CG59] UI32 shall be used for variables having bit-wise functionality. If it is
used for values it shall be discussed with technical prime.
This is to avoid any failure of logic when it is used for comparison. When a UI32 is compared with
SI32 variable the SI32 is upgraded to UI32. When SI32 holds a negative value the upgradation
results in a wrong huge value leading to failure of the comparison.
[CG60] Each variable shall be defined in a line separate of other variables.
Example:
tS32 x_coor, y_coor; // this is not allowed
Array a as32NumberList[10];
char acAlphabet[26];
Global variable g_ G_flRandomSeed;
Static Variable s_ S16 s_s16CurrentState;
Register variable r_ S32 r_s32Count;
Constant k_ S8 k_s8InitialState;
Notes:
Combining two or more prefixes is allowed. Example: pa is pointer to an array.
A string is given with prefix ac (array of characters), which is null terminated string.
Function pointers and file pointers are treated as handles.
User defined data types and handled may be assigned with non-clashing prefixes.
The name element in component context structure should be a string representation of the
component id tag.
The name element in fsm context structure should be a string representation of the FSM id tag.
There should be control over which test cases should be executed. It should not be assumed that
the selection is always a range of numbers. The selection of test cases to be run must be taken from
a testing-scope-selection file that is input to the master test script. If the testing-scope-selection file
is not provided then the test script should run all test cases in a predefined directory (or set of
directories).Use of hardcoded parameters in the individual script should be avoided. (For
example :the parameters are like test-vector name file name, duration/s of seek for audio files, LCD
configuration etc.) A configuration file should be used where these parameters are defined and the
values should be picked up from therein.
Guidelines for porting to ARM
If code depends upon size of enum (i.e. size in bytes); Assume it to be int (4 byte).
The enclosed function library may be used for the defined purpose
Sub_str2a_char
Sub_a_char2str