Skip to content

Commit b59fb16

Browse files
committed
First version with CAN/NvM stack
1 parent 8a7fab0 commit b59fb16

133 files changed

Lines changed: 10138 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.clang-format

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
---
2+
Language: Cpp
3+
# BasedOnStyle: LLVM
4+
AccessModifierOffset: -2
5+
AlignAfterOpenBracket: Align
6+
AlignConsecutiveMacros: false
7+
AlignConsecutiveAssignments: false
8+
AlignConsecutiveBitFields: false
9+
AlignConsecutiveDeclarations: false
10+
AlignEscapedNewlines: Right
11+
AlignOperands: Align
12+
AlignTrailingComments: true
13+
AllowAllArgumentsOnNextLine: true
14+
AllowAllConstructorInitializersOnNextLine: true
15+
AllowAllParametersOfDeclarationOnNextLine: true
16+
AllowShortEnumsOnASingleLine: false
17+
AllowShortBlocksOnASingleLine: false
18+
AllowShortCaseLabelsOnASingleLine: false
19+
AllowShortFunctionsOnASingleLine: false
20+
AllowShortLambdasOnASingleLine: false
21+
AllowShortIfStatementsOnASingleLine: false
22+
AllowShortLoopsOnASingleLine: false
23+
AlwaysBreakAfterDefinitionReturnType: None
24+
AlwaysBreakAfterReturnType: None
25+
AlwaysBreakBeforeMultilineStrings: false
26+
AlwaysBreakTemplateDeclarations: MultiLine
27+
BinPackArguments: true
28+
BinPackParameters: true
29+
BraceWrapping:
30+
AfterCaseLabel: false
31+
AfterClass: false
32+
AfterControlStatement: Never
33+
AfterEnum: false
34+
AfterFunction: false
35+
AfterNamespace: false
36+
AfterObjCDeclaration: false
37+
AfterStruct: false
38+
AfterUnion: false
39+
AfterExternBlock: false
40+
BeforeCatch: false
41+
BeforeElse: false
42+
BeforeLambdaBody: false
43+
BeforeWhile: false
44+
IndentBraces: false
45+
SplitEmptyFunction: true
46+
SplitEmptyRecord: true
47+
SplitEmptyNamespace: true
48+
BreakBeforeBinaryOperators: None
49+
BreakBeforeBraces: Attach
50+
BreakBeforeInheritanceComma: false
51+
BreakInheritanceList: BeforeColon
52+
BreakBeforeTernaryOperators: true
53+
BreakConstructorInitializersBeforeComma: false
54+
BreakConstructorInitializers: BeforeColon
55+
BreakAfterJavaFieldAnnotations: false
56+
BreakStringLiterals: true
57+
ColumnLimit: 100
58+
CommentPragmas: '^ IWYU pragma:'
59+
CompactNamespaces: false
60+
ConstructorInitializerAllOnOneLineOrOnePerLine: true
61+
ConstructorInitializerIndentWidth: 2
62+
ContinuationIndentWidth: 2
63+
Cpp11BracedListStyle: true
64+
DeriveLineEnding: true
65+
DerivePointerAlignment: false
66+
DisableFormat: false
67+
ExperimentalAutoDetectBinPacking: false
68+
FixNamespaceComments: true
69+
ForEachMacros:
70+
- foreach
71+
- Q_FOREACH
72+
- BOOST_FOREACH
73+
IncludeBlocks: Preserve
74+
IncludeCategories:
75+
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
76+
Priority: 2
77+
SortPriority: 0
78+
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
79+
Priority: 3
80+
SortPriority: 0
81+
- Regex: '.*'
82+
Priority: 1
83+
SortPriority: 0
84+
IncludeIsMainRegex: '(Test)?$'
85+
IncludeIsMainSourceRegex: ''
86+
IndentCaseLabels: false
87+
IndentCaseBlocks: false
88+
IndentGotoLabels: true
89+
IndentPPDirectives: None
90+
IndentExternBlock: AfterExternBlock
91+
IndentWidth: 2
92+
IndentWrappedFunctionNames: false
93+
InsertTrailingCommas: None
94+
JavaScriptQuotes: Leave
95+
JavaScriptWrapImports: true
96+
KeepEmptyLinesAtTheStartOfBlocks: true
97+
MacroBlockBegin: ''
98+
MacroBlockEnd: ''
99+
MaxEmptyLinesToKeep: 1
100+
NamespaceIndentation: None
101+
ObjCBinPackProtocolList: Auto
102+
ObjCBlockIndentWidth: 2
103+
ObjCBreakBeforeNestedBlockParam: true
104+
ObjCSpaceAfterProperty: false
105+
ObjCSpaceBeforeProtocolList: true
106+
PenaltyBreakAssignment: 2
107+
PenaltyBreakBeforeFirstCallParameter: 19
108+
PenaltyBreakComment: 300
109+
PenaltyBreakFirstLessLess: 120
110+
PenaltyBreakString: 1000
111+
PenaltyBreakTemplateDeclaration: 10
112+
PenaltyExcessCharacter: 1000000
113+
PenaltyReturnTypeOnItsOwnLine: 60
114+
PointerAlignment: Right
115+
ReflowComments: true
116+
SortIncludes: false
117+
SortUsingDeclarations: true
118+
SpaceAfterCStyleCast: false
119+
SpaceAfterLogicalNot: false
120+
SpaceAfterTemplateKeyword: true
121+
SpaceBeforeAssignmentOperators: true
122+
SpaceBeforeCpp11BracedList: false
123+
SpaceBeforeCtorInitializerColon: true
124+
SpaceBeforeInheritanceColon: true
125+
SpaceBeforeParens: ControlStatements
126+
SpaceBeforeRangeBasedForLoopColon: true
127+
SpaceInEmptyBlock: false
128+
SpaceInEmptyParentheses: false
129+
SpacesBeforeTrailingComments: 1
130+
SpacesInAngles: false
131+
SpacesInConditionalStatement: false
132+
SpacesInContainerLiterals: true
133+
SpacesInCStyleCastParentheses: false
134+
SpacesInParentheses: false
135+
SpacesInSquareBrackets: false
136+
SpaceBeforeSquareBrackets: false
137+
Standard: Latest
138+
StatementMacros:
139+
- Q_UNUSED
140+
- QT_REQUIRE_VERSION
141+
TabWidth: 2
142+
UseCRLF: false
143+
UseTab: Never
144+
WhitespaceSensitiveMacros:
145+
- STRINGIZE
146+
- PP_STRINGIZE
147+
- BOOST_PP_STRINGIZE

.gitignore

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
*.o
2+
*.exe
3+
*.so
4+
*.dll
5+
*.pyc
6+
*.d
7+
*.dblite
8+
.vscode
9+
*.log
10+
download
11+
*.img
12+
Makefile*
13+
TAGS
14+
platform
15+
release
16+
*.pkl
17+
*.pyd
18+
SeedToKey.py
19+
*.ini
20+
21+
libPCANBasic.a

SConscript

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from building import *
2+
for sc in Glob('*/SConscript'):
3+
SConscript(sc)
4+
5+
Building()

SConstruct

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import os
2+
import sys
3+
CWD = os.path.abspath('.')
4+
sys.path.append('%s/tools'%(CWD))
5+
6+
from building import *
7+
8+
SConscript('SConscript',variant_dir=BUILD_DIR, duplicate=0)

app/SConscript

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
for sc in Glob('*/SConscript'):
2+
SConscript(sc)

app/app/SConscript

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
from building import *
2+
3+
for sc in Glob('*/SConscript'):
4+
SConscript(sc)
5+
6+
CWD = GetCurrentDir()
7+
8+
generate(Glob('config/*.json'))
9+
generate(Glob('config/Com/*.json'))
10+
11+
objsApp = Glob('*.c') + Glob('src/*.c')
12+
13+
14+
class ApplicationApp(Application):
15+
def config(self):
16+
self.CPPDEFINES = []
17+
self.CPPPATH = ['$INFRAS', '%s/include' % (CWD)]
18+
self.LIBS = ['StdTimer']
19+
for libName, source in self.libsForApp.items():
20+
self.LIBS.append(libName)
21+
self.RegisterConfig(libName, source)
22+
self.Append(CPPDEFINES=['USE_%s' % (libName.split(':')[0].upper())])
23+
self.source = objsApp
24+
25+
26+
libsCommon = {'Dcm': Glob('config/Dcm/Dcm_Cfg.c'),
27+
'Dem': Glob('config/GEN/Dem_Cfg.c'),
28+
'Fls': Glob('config/Fls_Cfg.c'),
29+
'Fee': Glob('config/GEN/Fee_Cfg.c'),
30+
'NvM': Glob('config/GEN/NvM_Cfg.c'),
31+
}
32+
33+
libsForCanApp = {'CanTp': Glob('../bootloader/config/CanTp_Cfg.c'),
34+
'OsekNm': Glob('config/OsekNm_Cfg.c'),
35+
'CanNm': Glob('config/CanNm_Cfg.c'),
36+
'Com': Glob('config/Com/GEN/Com_Cfg.c'),
37+
}
38+
libsForCanApp.update(libsCommon)
39+
40+
41+
@register_application
42+
class ApplicationCanApp(ApplicationApp):
43+
def platform_config(self):
44+
self.Append(CPPDEFINES=['USE_STD_DEBUG'])
45+
self.LIBS.append('Simulator')
46+
47+
def config(self):
48+
self.libsForApp = libsForCanApp
49+
super().config()
50+
self.Append(CPPDEFINES=['USE_CAN'])
51+
self.platform_config()
52+
53+
@register_application
54+
class ApplicationCanNm(ApplicationApp):
55+
def platform_config(self):
56+
self.Append(CPPDEFINES=['USE_STD_DEBUG'])
57+
self.LIBS.append('Simulator')
58+
59+
def config(self):
60+
self.libsForApp = {k: libsForCanApp[k] for k in ['CanNm']}
61+
super().config()
62+
self.Append(CPPDEFINES=['USE_CAN'])
63+
self.platform_config()
64+
65+
@register_application
66+
class ApplicationOsekNm(ApplicationApp):
67+
def platform_config(self):
68+
self.Append(CPPDEFINES=['USE_STD_DEBUG'])
69+
self.LIBS.append('Simulator')
70+
71+
def config(self):
72+
self.libsForApp = {k: libsForCanApp[k] for k in ['OsekNm']}
73+
super().config()
74+
self.Append(CPPDEFINES=['USE_CAN'])
75+
self.platform_config()

app/app/config/CanNm_Cfg.c

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/**
2+
* SSAS - Simple Smart Automotive Software
3+
* Copyright (C) 2021 Parai Wang <parai@foxmail.com>
4+
*/
5+
/* ================================ [ INCLUDES ] ============================================== */
6+
#include "CanNm.h"
7+
#include "CanNm_Cfg.h"
8+
#include "CanNm_Priv.h"
9+
#include <Std_Debug.h>
10+
#ifdef _WIN32
11+
#include <stdlib.h>
12+
#endif
13+
/* ================================ [ MACROS ] ============================================== */
14+
#define CANNM_ImmediateNmCycleTime CANNM_CONVERT_MS_TO_MAIN_CYCLES(100)
15+
#define CANNM_MsgCycleOffset CANNM_CONVERT_MS_TO_MAIN_CYCLES(100)
16+
#define CANNM_MsgCycleTime CANNM_CONVERT_MS_TO_MAIN_CYCLES(1000)
17+
#define CANNM_MsgReducedTime CANNM_CONVERT_MS_TO_MAIN_CYCLES(500)
18+
#define CANNM_MsgTimeoutTime CANNM_CONVERT_MS_TO_MAIN_CYCLES(10)
19+
#define CANNM_RepeatMessageTime CANNM_CONVERT_MS_TO_MAIN_CYCLES(2000)
20+
#define CANNM_NmTimeoutTime CANNM_CONVERT_MS_TO_MAIN_CYCLES(2000)
21+
#define CANNM_WaitBusSleepTime CANNM_CONVERT_MS_TO_MAIN_CYCLES(5000)
22+
#define CANNM_RemoteSleepIndTime CANNM_CONVERT_MS_TO_MAIN_CYCLES(1500)
23+
#define CANNM_NODE_ID 0
24+
#define CANNM_ImmediateNmTransmissions 10
25+
26+
#ifdef _WIN32
27+
#define L_CONST
28+
#else
29+
#define L_CONST const
30+
#endif
31+
/* ================================ [ TYPES ] ============================================== */
32+
/* ================================ [ DECLARES ] ============================================== */
33+
/* ================================ [ DATAS ] ============================================== */
34+
#ifdef CANNM_GLOBAL_PN_SUPPORT
35+
static const uint8_t nm0PnFilterMaskByte[2] = {0x55, 0xAA};
36+
#endif
37+
static L_CONST CanNm_ChannelConfigType CanNm_ChannelConfigs[] = {
38+
{
39+
CANNM_ImmediateNmCycleTime,
40+
CANNM_MsgCycleOffset,
41+
CANNM_MsgCycleTime,
42+
CANNM_MsgReducedTime,
43+
CANNM_MsgTimeoutTime,
44+
CANNM_RepeatMessageTime,
45+
CANNM_NmTimeoutTime,
46+
CANNM_WaitBusSleepTime,
47+
#ifdef CANNM_REMOTE_SLEEP_IND_ENABLED
48+
CANNM_RemoteSleepIndTime,
49+
#endif
50+
3, /* TxPdu */
51+
CANNM_NODE_ID,
52+
0, /* nmNetworkHandle */
53+
CANNM_ImmediateNmTransmissions,
54+
CANNM_PDU_BYTE_1, /* PduCbvPosition */
55+
CANNM_PDU_BYTE_0, /* PduNidPosition */
56+
TRUE, /* ActiveWakeupBitEnabled */
57+
FALSE, /* PassiveModeEnabled */
58+
TRUE, /* RepeatMsgIndEnabled */
59+
TRUE, /* NodeDetectionEnabled */
60+
#ifdef CANNM_GLOBAL_PN_SUPPORT
61+
TRUE, /* PnEnabled */
62+
TRUE, /* AllNmMessagesKeepAwake */
63+
4, /* PnInfoOffset */
64+
sizeof(nm0PnFilterMaskByte), /* PnInfoLength */
65+
nm0PnFilterMaskByte,
66+
#endif
67+
},
68+
};
69+
70+
static CanNm_ChannelContextType CanNm_ChannelContexts[ARRAY_SIZE(CanNm_ChannelConfigs)];
71+
72+
const CanNm_ConfigType CanNm_Config = {
73+
CanNm_ChannelConfigs,
74+
CanNm_ChannelContexts,
75+
ARRAY_SIZE(CanNm_ChannelConfigs),
76+
};
77+
/* ================================ [ LOCALS ] ============================================== */
78+
#ifdef _WIN32
79+
static void __attribute__((constructor)) _cannm_start(void) {
80+
char *nodeStr = getenv("CANNM_NODE_ID");
81+
if (nodeStr != NULL) {
82+
CanNm_ChannelConfigs[0].NodeId = atoi(nodeStr);
83+
CanNm_ChannelConfigs[0].MsgReducedTime =
84+
CANNM_CONVERT_MS_TO_MAIN_CYCLES(500 + (CanNm_ChannelConfigs[0].NodeId * 100));
85+
ASLOG(INFO, ("CanNm NodeId=%d, ReduceTime=%d\n", CanNm_ChannelConfigs[0].NodeId,
86+
CanNm_ChannelConfigs[0].MsgReducedTime));
87+
}
88+
}
89+
#endif
90+
/* ================================ [ FUNCTIONS ] ============================================== */

app/app/config/CanNm_Cfg.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* SSAS - Simple Smart Automotive Software
3+
* Copyright (C) 2021 Parai Wang <parai@foxmail.com>
4+
*/
5+
#ifndef _CAN_NM_CFG_H
6+
#define _CAN_NM_CFG_H
7+
/* ================================ [ INCLUDES ] ============================================== */
8+
/* ================================ [ MACROS ] ============================================== */
9+
#ifndef CANNM_MAIN_FUNCTION_PERIOD
10+
#define CANNM_MAIN_FUNCTION_PERIOD 10
11+
#endif
12+
#define CANNM_CONVERT_MS_TO_MAIN_CYCLES(x) \
13+
((x + CANNM_MAIN_FUNCTION_PERIOD - 1) / CANNM_MAIN_FUNCTION_PERIOD)
14+
15+
/* @ECUC_CanNm_00055 */
16+
#define CANNM_REMOTE_SLEEP_IND_ENABLED
17+
18+
/* @ECUC_CanNm_00010 */
19+
//#define CANNM_PASSIVE_MODE_ENABLED
20+
21+
/* @ECUC_CanNm_00080 */
22+
#define CANNM_COORDINATOR_SYNC_SUPPORT
23+
24+
/* @ECUC_CanNm_00086 */
25+
#define CANNM_GLOBAL_PN_SUPPORT
26+
/* ================================ [ TYPES ] ============================================== */
27+
/* ================================ [ DECLARES ] ============================================== */
28+
/* ================================ [ DATAS ] ============================================== */
29+
/* ================================ [ LOCALS ] ============================================== */
30+
/* ================================ [ FUNCTIONS ] ============================================== */
31+
#endif /* _CAN_NM_CFG_H */

0 commit comments

Comments
 (0)