Skip to content

Commit d71ea71

Browse files
committed
Merge remote-tracking branch 'donghoonpark/cmake'
2 parents 730cdaa + cc28557 commit d71ea71

File tree

9 files changed

+696
-603
lines changed

9 files changed

+696
-603
lines changed

.clang-format

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
BasedOnStyle: LLVM
22
AccessModifierOffset: -4
33
AlignAfterOpenBracket: Align
4-
AlignConsecutiveAssignments: None
4+
AlignConsecutiveAssignments: false
55
AlignOperands: Align
66
AllowAllArgumentsOnNextLine: false
77
AllowAllConstructorInitializersOnNextLine: false

.github/workflows/ci.yml

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,67 @@ jobs:
1010
steps:
1111
- name: Clone repo
1212
uses: actions/checkout@v2
13+
- name: configure
14+
run: |
15+
cmake -S . -B build -DBUILD_TESTS=ON -DCMAKE_BUILD_TYPE=Debug
1316
- name: build
1417
run: |
15-
mkdir build
16-
cd build
17-
cmake ..
18-
make
19-
./nanomodbus_tests
20-
- name: Compile Arduino examples
18+
cmake --build build --config Debug
19+
- name: Compress Build Directory
20+
run: tar -czf build.tar.gz build/
21+
- name: Upload Build Artifact
22+
uses: actions/upload-artifact@v3
23+
with:
24+
name: build
25+
path: build.tar.gz
26+
Embedded:
27+
runs-on: ubuntu-latest
28+
steps:
29+
- name: Clone repo
30+
uses: actions/checkout@v2
31+
- name: Build Arduino examples
2132
run: |
33+
mkdir -p build
2234
pushd build
2335
curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sh
2436
popd
2537
export PATH="build/bin:$PATH"
2638
./examples/arduino/compile-examples.sh
39+
- name: Install ARM dependencies
40+
run: |
41+
sudo apt update
42+
sudo apt install -y cmake gcc-arm-none-eabi libnewlib-arm-none-eabi build-essential
43+
- name: Build rp2040 examples
44+
run: |
45+
pushd examples/rp2040
46+
git clone --depth=1 https://github.com/raspberrypi/pico-sdk.git
47+
export PICO_SDK_PATH=$PWD/pico-sdk
48+
cmake -S . -B build -DPICO_SDK_PATH=$PWD/pico-sdk
49+
cmake --build build --config Debug
50+
popd
51+
- name: Build stm32 examples
52+
run: |
53+
pushd examples/stm32
54+
cmake -S . -B build
55+
cmake --build build --config Debug
56+
popd
57+
Test:
58+
runs-on: ubuntu-latest
59+
needs: Build # run after Build job
60+
steps:
61+
- uses: actions/checkout@v3
62+
- name: Download Build Directory
63+
uses: actions/download-artifact@v3
64+
with:
65+
name: build
66+
- name: Extract Build Directory
67+
run: |
68+
mkdir -p build
69+
tar -xzf build.tar.gz -C .
70+
- name: List Build Files
71+
run: ls -R .
72+
- name: test
73+
run: |
74+
cd build
75+
ctest
76+

.vscode/settings.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
{
22
"cmake.configureOnOpen": true,
3+
"cmake.configureArgs": [
4+
"-DBUILD_TESTS=ON",
5+
"-DBUILD_EXAMPLES=ON"
6+
],
37
"cmake.copyCompileCommands": "${workspaceFolder}/compile_commands.json",
48
"C_Cpp.intelliSenseEngine": "disabled",
59
"clangd.path": "clangd",
610
"editor.formatOnSave": true,
7-
"editor.rulers": [120],
11+
"editor.rulers": [
12+
120
13+
],
814
"[c]": {
915
"editor.defaultFormatter": "llvm-vs-code-extensions.vscode-clangd"
1016
},
1117
"[cpp]": {
1218
"editor.defaultFormatter": "llvm-vs-code-extensions.vscode-clangd"
1319
},
14-
}
20+
}

CMakeLists.txt

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,32 @@ include_directories(tests examples/linux .)
1010

1111
# Define BUILD_SHARED_LIBS=ON to build a dynamic library instead
1212
add_library(nanomodbus nanomodbus.c)
13-
14-
add_executable(nanomodbus_tests nanomodbus.c tests/nanomodbus_tests.c)
15-
target_link_libraries(nanomodbus_tests pthread)
16-
17-
add_executable(server_disabled nanomodbus.c tests/server_disabled.c)
18-
target_compile_definitions(server_disabled PUBLIC NMBS_SERVER_DISABLED)
19-
20-
add_executable(client_disabled nanomodbus.c tests/client_disabled.c)
21-
target_compile_definitions(client_disabled PUBLIC NMBS_CLIENT_DISABLED)
22-
23-
add_executable(multi_server_rtu nanomodbus.c tests/multi_server_rtu.c)
24-
target_compile_definitions(multi_server_rtu PUBLIC NMBS_DEBUG)
25-
target_link_libraries(multi_server_rtu pthread)
26-
27-
add_custom_target(tests DEPENDS nanomodbus_tests server_disabled client_disabled multi_server_rtu)
28-
29-
add_executable(client-tcp nanomodbus.c examples/linux/client-tcp.c)
30-
add_executable(server-tcp nanomodbus.c examples/linux/server-tcp.c)
13+
target_include_directories(nanomodbus PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
14+
15+
if(BUILD_EXAMPLES)
16+
add_executable(client-tcp examples/linux/client-tcp.c)
17+
target_link_libraries(client-tcp nanomodbus)
18+
add_executable(server-tcp examples/linux/server-tcp.c)
19+
target_link_libraries(server-tcp nanomodbus)
20+
endif()
21+
22+
if(BUILD_TESTS)
23+
add_executable(nanomodbus_tests nanomodbus.c tests/nanomodbus_tests.c)
24+
target_link_libraries(nanomodbus_tests pthread)
25+
26+
add_executable(server_disabled nanomodbus.c tests/server_disabled.c)
27+
target_compile_definitions(server_disabled PUBLIC NMBS_SERVER_DISABLED)
28+
29+
add_executable(client_disabled nanomodbus.c tests/client_disabled.c)
30+
target_compile_definitions(client_disabled PUBLIC NMBS_CLIENT_DISABLED)
31+
32+
add_executable(multi_server_rtu nanomodbus.c tests/multi_server_rtu.c)
33+
target_compile_definitions(multi_server_rtu PUBLIC NMBS_DEBUG)
34+
target_link_libraries(multi_server_rtu pthread)
35+
36+
enable_testing()
37+
add_test(NAME test_general COMMAND $<TARGET_FILE:nanomodbus_tests>)
38+
add_test(NAME test_server_disabled COMMAND $<TARGET_FILE:server_disabled>)
39+
add_test(NAME test_client_disabled COMMAND $<TARGET_FILE:client_disabled>)
40+
add_test(NAME test_multi_server_rtu COMMAND $<TARGET_FILE:multi_server_rtu>)
41+
endif()

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,30 @@ int main(int argc, char* argv[]) {
9696
9797
## Installation
9898
99+
### Integrate source code to your project
100+
99101
Just copy `nanomodbus.c` and `nanomodbus.h` inside your application codebase.
100102
103+
### CMake project
104+
105+
nanomodbus supports library linking by using cmake.
106+
107+
```cmake
108+
FetchContent_Declare(
109+
nanomodbus
110+
GIT_REPOSITORY https://github.com/debevv/nanoMODBUS
111+
GIT_TAG master # or the version you want
112+
GIT_SHALLOW TRUE
113+
)
114+
115+
FetchContent_MakeAvailable(nanomodbus)
116+
117+
...
118+
119+
add_executable(your_program source_codes)
120+
target_link_libraries(your_program nanomodbus)
121+
```
122+
101123
## API reference
102124

103125
API reference is available in the repository's [GitHub Pages](https://debevv.github.io/nanoMODBUS/nanomodbus_8h.html).

examples/stm32/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ FetchContent_MakeAvailable(wizchip)
5555
FetchContent_Declare(
5656
nanomodbus
5757
GIT_REPOSITORY https://github.com/debevv/nanoMODBUS
58-
GIT_TAG v1.18.1
58+
GIT_TAG master
5959
GIT_SHALLOW TRUE
6060
)
6161

@@ -67,6 +67,8 @@ endif ()
6767
add_library(nanomodbus ${nanomodbus_SOURCE_DIR}/nanomodbus.c)
6868
target_include_directories(nanomodbus PUBLIC ${nanomodbus_SOURCE_DIR})
6969

70+
# FetchContent_MakeAvailable(nanomodbus)
71+
7072
set(TARGET_NAMES modbus_rtu modbus_tcp)
7173

7274
foreach (TARGET_NAME ${TARGET_NAMES})

examples/stm32/FreeRTOSConfig.h

Lines changed: 69 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,30 @@
22
* FreeRTOS Kernel V10.4.1
33
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
44
*
5-
* Permission is hereby granted, free of charge, to any person obtaining a copy of
6-
* this software and associated documentation files (the "Software"), to deal in
7-
* the Software without restriction, including without limitation the rights to
8-
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9-
* the Software, and to permit persons to whom the Software is furnished to do so,
10-
* subject to the following conditions:
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy
6+
* of this software and associated documentation files (the "Software"), to deal
7+
* in the Software without restriction, including without limitation the rights
8+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
1111
*
12-
* The above copyright notice and this permission notice shall be included in all
13-
* copies or substantial portions of the Software.
12+
* The above copyright notice and this permission notice shall be included in
13+
* all copies or substantial portions of the Software.
1414
*
1515
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17-
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18-
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19-
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20-
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
* SOFTWARE.
2122
*
2223
* http://www.FreeRTOS.org
2324
* http://aws.amazon.com/freertos
2425
*
2526
* 1 tab == 4 spaces!
2627
*/
2728

28-
2929
#ifndef FREERTOS_CONFIG_H
3030
#define FREERTOS_CONFIG_H
3131

@@ -45,57 +45,57 @@
4545
extern uint32_t SystemCoreClock;
4646

4747
#if defined STM32L5
48-
#define configENABLE_TRUSTZONE 0
49-
#if configENABLE_TRUSTZONE
50-
#define configMINIMAL_SECURE_STACK_SIZE ((uint16_t)1024)
51-
#endif
52-
#define configRUN_FREERTOS_SECURE_ONLY 0
53-
#define configENABLE_FPU 1
54-
#define configENABLE_MPU 0
48+
#define configENABLE_TRUSTZONE 0
49+
#if configENABLE_TRUSTZONE
50+
#define configMINIMAL_SECURE_STACK_SIZE ((uint16_t) 1024)
51+
#endif
52+
#define configRUN_FREERTOS_SECURE_ONLY 0
53+
#define configENABLE_FPU 1
54+
#define configENABLE_MPU 0
5555
#endif
5656

57-
#define configUSE_PREEMPTION 1
58-
#define configUSE_IDLE_HOOK 0
59-
#define configUSE_TICK_HOOK 0
60-
#define configCPU_CLOCK_HZ ( SystemCoreClock )
61-
#define configTICK_RATE_HZ ( ( TickType_t ) 1000 )
57+
#define configUSE_PREEMPTION 1
58+
#define configUSE_IDLE_HOOK 0
59+
#define configUSE_TICK_HOOK 0
60+
#define configCPU_CLOCK_HZ (SystemCoreClock)
61+
#define configTICK_RATE_HZ ((TickType_t) 1000)
6262
#if !defined USE_CMSIS_RTOS_V2
63-
#define configMAX_PRIORITIES ( 5 )
63+
#define configMAX_PRIORITIES (5)
6464
#endif
65-
#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 50 )
66-
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 32 * 1024 ) )
67-
#define configMAX_TASK_NAME_LEN ( 10 )
68-
#define configUSE_TRACE_FACILITY 1
69-
#define configUSE_16_BIT_TICKS 0
70-
#define configIDLE_SHOULD_YIELD 1
71-
#define configUSE_MUTEXES 1
72-
#define configQUEUE_REGISTRY_SIZE 8
73-
#define configCHECK_FOR_STACK_OVERFLOW 0
74-
#define configUSE_RECURSIVE_MUTEXES 1
75-
#define configUSE_MALLOC_FAILED_HOOK 0
76-
#define configUSE_APPLICATION_TASK_TAG 0
77-
#define configUSE_COUNTING_SEMAPHORES 1
78-
#define configGENERATE_RUN_TIME_STATS 0
65+
#define configMINIMAL_STACK_SIZE ((unsigned short) 50)
66+
#define configTOTAL_HEAP_SIZE (size_t)(32 * 1024)
67+
#define configMAX_TASK_NAME_LEN (10)
68+
#define configUSE_TRACE_FACILITY 1
69+
#define configUSE_16_BIT_TICKS 0
70+
#define configIDLE_SHOULD_YIELD 1
71+
#define configUSE_MUTEXES 1
72+
#define configQUEUE_REGISTRY_SIZE 8
73+
#define configCHECK_FOR_STACK_OVERFLOW 0
74+
#define configUSE_RECURSIVE_MUTEXES 1
75+
#define configUSE_MALLOC_FAILED_HOOK 0
76+
#define configUSE_APPLICATION_TASK_TAG 0
77+
#define configUSE_COUNTING_SEMAPHORES 1
78+
#define configGENERATE_RUN_TIME_STATS 0
7979

8080
/* Co-routine definitions. */
81-
#define configUSE_CO_ROUTINES 0
82-
#define configMAX_CO_ROUTINE_PRIORITIES ( 2 )
81+
#define configUSE_CO_ROUTINES 0
82+
#define configMAX_CO_ROUTINE_PRIORITIES (2)
8383

8484
/* Software timer definitions. */
85-
#define configUSE_TIMERS 1
86-
#define configTIMER_TASK_PRIORITY ( 2 )
87-
#define configTIMER_QUEUE_LENGTH 10
88-
#define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 )
85+
#define configUSE_TIMERS 1
86+
#define configTIMER_TASK_PRIORITY (2)
87+
#define configTIMER_QUEUE_LENGTH 10
88+
#define configTIMER_TASK_STACK_DEPTH (configMINIMAL_STACK_SIZE * 2)
8989

9090
/* Set the following definitions to 1 to include the API function, or zero
9191
to exclude the API function. */
92-
#define INCLUDE_vTaskPrioritySet 1
93-
#define INCLUDE_uxTaskPriorityGet 1
94-
#define INCLUDE_vTaskDelete 1
95-
#define INCLUDE_vTaskCleanUpResources 1
96-
#define INCLUDE_vTaskSuspend 1
97-
#define INCLUDE_vTaskDelayUntil 1
98-
#define INCLUDE_vTaskDelay 1
92+
#define INCLUDE_vTaskPrioritySet 1
93+
#define INCLUDE_uxTaskPriorityGet 1
94+
#define INCLUDE_vTaskDelete 1
95+
#define INCLUDE_vTaskCleanUpResources 1
96+
#define INCLUDE_vTaskSuspend 1
97+
#define INCLUDE_vTaskDelayUntil 1
98+
#define INCLUDE_vTaskDelay 1
9999

100100
#if defined USE_CMSIS_RTOS_V2
101101

@@ -119,33 +119,38 @@ to exclude the API function. */
119119

120120
/* Cortex-M specific definitions. */
121121
#ifdef __NVIC_PRIO_BITS
122-
/* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */
123-
#define configPRIO_BITS __NVIC_PRIO_BITS
122+
/* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */
123+
#define configPRIO_BITS __NVIC_PRIO_BITS
124124
#else
125-
#define configPRIO_BITS 4 /* 15 priority levels */
125+
#define configPRIO_BITS 4 /* 15 priority levels */
126126
#endif
127127

128128
/* The lowest interrupt priority that can be used in a call to a "set priority"
129129
function. */
130-
#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 0xf
130+
#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 0xf
131131

132132
/* The highest interrupt priority that can be used by any interrupt service
133133
routine that makes calls to interrupt safe FreeRTOS API functions. DO NOT CALL
134134
INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER
135135
PRIORITY THAN THIS! (higher priorities are lower numeric values. */
136-
#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 5
136+
#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 5
137137

138138
/* Interrupt priorities used by the kernel port layer itself. These are generic
139139
to all Cortex-M ports, and do not rely on any particular library functions. */
140-
#define configKERNEL_INTERRUPT_PRIORITY ( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
140+
#define configKERNEL_INTERRUPT_PRIORITY (configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS))
141141
/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!!
142142
See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */
143-
#define configMAX_SYSCALL_INTERRUPT_PRIORITY ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
144-
143+
#define configMAX_SYSCALL_INTERRUPT_PRIORITY (configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS))
144+
145145
/* Normal assert() semantics without relying on the provision of an assert.h
146146
header file. */
147-
#define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); }
148-
147+
#define configASSERT(x) \
148+
if ((x) == 0) { \
149+
taskDISABLE_INTERRUPTS(); \
150+
for (;;) \
151+
; \
152+
}
153+
149154
/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS
150155
standard names. */
151156
#define vPortSVCHandler SVC_Handler

0 commit comments

Comments
 (0)