Supernova2 Coding Style
Supernova2 Coding Style
SW Coding Style
(For C/C++)
1
SW Coding Style
Revision History
2
SW Coding Style
File Organization
A file consists of various sections that should be separated by several blank
lines. Although there is no maximum length limit for source files, files with more
than about 3000 lines are cumbersome to deal with. The editor may not have
enough temp space to edit the file; compilations will go more slowly, etc. Many
rows of asterisks, for example, present little information compared to the time it
takes to scroll past, and are discouraged. Lines longer than 79 columns are not
handled well by all terminals and should be avoided if possible. Excessively
long lines which result from deep indenting are often a symptom of
poorly-organized code.
- < 3000 lines per file
- < 80 character per line
MW part
Middleware’s application layer file name are all lower case, mw app file are
made up of a prefix, “mapp”, ”_”, module name. Middleware API layer file
name are ,ade up of a prefix, “msapi”, ”_”, module name!
- mapp_mheg5.c
- msAPI_MPEG_Subtitle.c msapi_mpeg_subtitle.c
Drv part
API File names are made up of a prefix, “api”, function abbreviations, “_”,
sub-function abbreviations, HAL File names are made up of a prefix, “hal”,
HWIP, module name, Drv File names are made up of a prefix, “drv”, HWIP,
module name.
3
SW Coding Style
- apiDMX.c
- halMVD.c
- drvGE.c
- fwMAD_ac3.bin
MUF:
:
File names are made up of Class name and suffix.
(File will be generated by UML tool automatically)
The Class name should be Pascal Casting (The first character of every word is in
upper case)
- Definition:
:XXXX.cpp
- Declaration:
:XXXX.h
- Forward Declaration:
:XXXX_fdef.h
MSrv:
:
File names are made up of Class name and suffix. The Class name should be
Pascal Casting (The first character of every word is in upper case). The name
of interface class is MSrv_Xxxxx. The name of internal class or implement
class is MS_Xxxxxx.
Interface:
: MSrv_Xxxxx.cpp
- Definition:
- Declaration::MSrv_Xxxxx.h
- Forward Declaration:
:MSrv_Xxxxx_fdef.h
Internal/implement:
- Definition:: MS_Xxxxx.cpp
- Declaration: :MS_Xxxxx.h
- Forward Declaration:
:MS_Xxxxx_fdef.h
4
SW Coding Style
MStarSDK:
The file name and class name in SDK layer are all lower case. File name are
makeup of class name and suffix. The name of interface class (which will
release header file to customer) is mapi_xxxxx. The name of internal class or
implement class is ma_xxxxx
Interface:
- Definition:
: mapi_xxxxx.cpp
- Declaration:
:mapi_xxxxx.h
- Forward Declaration:
:mapi_xxxxx_fdef.h
Internal/implement:
- Definition:
: ma_xxxxx.cpp
- Declaration:
:ma_xxxxx.h
- Forward Declaration:
:ma_xxxxx_fdef.h
File structure
The suffix of source file should be “.c” in ANSI C, “.ccp” in C++; header file
should be “.h”. In each source file (.c/.cpp) and header file (.h), the MStar legal
declaration and file purpose description should be added in the beginning. In
each source file and header file, one specific definition is used as itself
identification.
Example:
////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2006-2009 MStar Semiconductor, Inc.
// All rights reserved.
//
5
SW Coding Style
////////////////////////////////////////////////////////////////////////////////
/// @file map_mheg5.c
/// @author MStar Semiconductor, Inc.
/// @brief MHEG5 application
////////////////////////////////////////////////////////////////////////////////
#define _MAPP_MHEG5_C_
( or _MAPP_MHEG5_CPP_ )
Header files should not be nested. The prologue for a header file should,
therefore, describe what other headers need to be #included for the header to
be functional. In extreme cases, where a large number of header files are to be
included in several different source files, it is acceptable to put all common
#includes in one include file.
It is common to put the following into each .h file to prevent accidental
double-inclusion.
#ifndef _MAPP_MHEG5_H_
#define _MAPP_MHEG5_H_
#ifdef _MAPP_MHEG5_C_
// Version define Only for module entry function file
6
SW Coding Style
'2' /* OS */\
#define EXTCALL
#else
#define EXTCALL extern
#endif
….
//-----------------------------------------------------------------------------
// External Function, if this one is library, external function
// Must be define in interface include file
//-----------------------------------------------------------------------------
extern void MApi_XC_FreezeImg(MS_BOOL bEnable, SCALER_WIN eWindow);
…
//-----------------------------------------------------------------------------
// Function
//-----------------------------------------------------------------------------
EXTCALL void MApp_MHEG5_ChannelProcessMailbox(U8 *u8MailBox)
;
….
#undef EXTCALL
#endif //_MSAPI_MHEG5_H_
7
SW Coding Style
Coding Style
Comment
Comments, if used improperly, can make code very difficult to understand. Use
comments sparingly, to document important parts of the code, and let the code
speak for itself at other times. A comment at the beginning of each function is a
good idea, and within the code comments are best kept short and used to
document unusual things.
Comments that describe data structure, algorithm, disabling unuseful code etc.,
should be comment form with opening /* and closing */. Comments that
describe the function call, should be comment form with “///, command
provided from Doxygen. Comments that describe any reminding information in
one-line comment statement, should be comment form with “//”.
8
SW Coding Style
Function input parameters should be four or less for clarifies. If the input
parameter is a pointer which transmits the data messages, Read-only, the
const specific word should be used to protect the pointer value and that
pointed by a pointer. Call by address is rather than call by value.
- void functionA(para1, para2, para3, para4, para5, ….)
void functionSetWindow(const U8 *pWindowInfo)
9
SW Coding Style
C++ Naming:
:
Casting format description:
:
Pascal Casing:The first character of every word is in upper case.
Ex:PascalCastingFormatExample
Camel Casing:Except the first character of the first word is in lower case, the first character of
every other words is in upper case.
Ex:camelCastingFormatExample
Upper Casing:All Words are in upper case with “_” for separation.
Ex:UPPER_CASTING_FORMAT_EXAMPLE
Naming:
:
Class:Use Nouns for naming in Pascal Casting.
- Class for Application with a prefix “MApp_” MApp_MainMenu
- Class for Main Frame with a prefix “MFrm_” MFrm_MainMenu
- Class for service with a prefix “MSrv_” MSrv_VBI
10
SW Coding Style
};
Don’t use any program language specific key word as needed definition.
Example: INTERFACE (used in original design). “EXTCALL” is to substitute
“INTERFACE”.
- INTERFACE EXTCALL void msAPI_Key_Transmit(U8 u8Key, U8 Status);
Programmer should use the “cast” method to read / write data structure to
avoid Big-Endian / Little-Endian.
Statement
12
SW Coding Style
If – else statement: must have “else” condition, and { } for code area.
If (condition-A)
{
}
else
{
}
Switch statement:
Switch (control variable)
{
case “A”:
{
}
break;
default:
{
}
break;
}
13
SW Coding Style
Abbreviation
Common Abbreviation
14
SW Coding Style
HW module abbreviation
Abbreviation Full name Note
GE Graphics Engine
G3D
PE Pixel Engine
XC Scaler
UART UART
CA Conditional Access
DSCMB Descrambler
PM Power Manager
SYS System
RLD Subtitle
HDMI Tx/Rx
IIC
15
SW Coding Style
PWM
SAR
SDIO
UART
USB
PM Power Management
GDMA
TTX Teletext
CC ClosedCaption
SI Service Information
CM Channel Manage
DB Database
OAD On-Air-Download
OTA Over-The-Air
BL Bootloader
MM Multimedia
MP Multimedia Player
FS File System
16
SW Coding Style
MUF/MIDE abbreviation
Abbreviation Full name Note
SRV Service
FRM Frame
Routinue Functions
- Get Library Version String:
XXX_GetLibVer
- Show debug message
XXXShowVerString(U8 *string)
- Get Static Information:
XXX_GetInfo
- Get Runtime Status:
XXX_GetStatus
- Show debug message
XXXDBGprintf(U32 u32Module, U32 u32Level, char* fmt, ...)
- Set debug message Module
XXXDebugSetModuleValue (U32 u32Module)
- Set debug message Level
XXXDebugSetLevelValue (U32 u32Level)
17