Skip to content

Commit aa2fecd

Browse files
committed
support cortex-m4 hard floating point abi.
1 parent 67a85e7 commit aa2fecd

3 files changed

Lines changed: 285 additions & 1 deletion

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ GTAGS
2626
build-docs
2727
/.cache/
2828
/.history/
29+
/venv/

doc/INSTALL.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ For AVR32
4141
```
4242
For STM32 and toolchain (gcc-arm-none-eabi-10.3-2021.10)
4343
```shell
44-
./waf configure --toolchain=arm-none-eabi- --with-os=freertos --prefix=build/lib --includes=../FreeRTOS/Source/include/,../../../Core/Inc/,../FreeRTOS/Source/portable/GCC/ARM_CM4F/,/usr/share/gcc-arm-none-eabi-10.3-2021.10/arm-none-eabi/include/ --enable-reproducible-builds
44+
./waf configure --toolchain=arm-none-eabi- --with-os=freertos --prefix=build/lib --includes=../FreeRTOS/Source/include/,../../../Core/Inc/,../FreeRTOS/Source/portable/GCC/ARM_CM4F/,/usr/share/gcc-arm-none-eabi-10.3-2021.10/arm-none-eabi/include/ --enable-reproducible-builds --abi=hard
4545
```
4646

4747
When compiling for FreeRTOS, the path to the FreeRTOS header files must

wscript

Lines changed: 283 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ APPNAME = 'libcsp'
77
VERSION = '2.1'
88

99
valid_os = ['posix', 'freertos']
10+
valid_float_abi = ['hard', 'soft', 'softfp']
1011

1112
def options(ctx):
1213
# Load compiler
@@ -17,7 +18,282 @@ def options(ctx):
1718
# Set libcsp options
1819
gr = ctx.add_option_group('libcsp options')
1920
gr.add_option('--includes', default='', help='Add additional include paths, separate with comma')
21+
gr.add_option('--abi', default='hard', help='Add additional CFLAG for floating point abi. Must be one of: ' + str(valid_float_abi))
22+
gr.add_option('--enable-reproducible-builds', action='store_true', help='Enable reproducible builds')
23+
24+
gr.add_option('--disable-output', action='store_true', help='Disable CSP output')
25+
gr.add_option('--disable-print-stdio', action='store_true', help='Disable vprintf for csp_print_func')
26+
gr.add_option('--disable-stlib', action='store_true', help='Build objects only')
27+
gr.add_option('--enable-shlib', action='store_true', help='Build shared library')
28+
gr.add_option('--enable-rdp', action='store_true', help='Enable RDP support')
29+
gr.add_option('--enable-promisc', action='store_true', help='Enable promiscuous support')
30+
gr.add_option('--enable-crc32', action='store_true', help='Enable CRC32 support')
31+
gr.add_option('--enable-hmac', action='store_true', help='Enable HMAC-SHA1 support')
32+
gr.add_option('--enable-rtable', action='store_true', help='Allows to setup a list of static routes')
33+
gr.add_option('--enable-python3-bindings', action='store_true', help='Enable Python3 bindings')
34+
gr.add_option('--enable-examples', action='store_true', help='Enable examples')
35+
gr.add_option('--enable-dedup', action='store_true', help='Enable packet deduplicator')
36+
gr.add_option('--enable-yaml', action='store_true', help='Enable YAML configurator')
37+
gr.add_option('--with-rdp-max-window', type=int, default=5, help='Set maximum window size for RDP')
38+
gr.add_option('--with-max-bind-port', type=int, default=16, help='Set maximum bindable port')
39+
gr.add_option('--with-max-connections', type=int, default=8, help='Set maximum number of connections')
40+
gr.add_option('--with-conn-queue-length', type=int, default=15, help='Set max connection queue length')
41+
gr.add_option('--with-router-queue-length', type=int, default=15, help='Set max router queue length')
42+
gr.add_option('--with-buffer-size', type=int, default=256, help='Set size of csp buffers')
43+
gr.add_option('--with-buffer-count', type=int, default=15, help='Set number of csp buffers')
44+
gr.add_option('--with-rtable-size', type=int, default=10, help='Set max number of entries in route table')
45+
46+
# Drivers and interfaces (requires external dependencies)
47+
gr.add_option('--enable-if-zmqhub', action='store_true', help='Enable ZMQ interface')
48+
gr.add_option('--enable-can-socketcan', action='store_true', help='Enable Linux socketcan driver')
49+
gr.add_option('--with-driver-usart', default=None, metavar='DRIVER', help='Build USART driver. [linux, None]')
50+
51+
# OS
52+
gr.add_option('--with-os', metavar='OS', default='posix', help='Set operating system. Must be one of: ' + str(valid_os))
53+
54+
55+
def configure(ctx):
56+
# Validate options
57+
if ctx.options.with_os not in valid_os:
58+
ctx.fatal('--with-os must be either: ' + str(valid_os))
59+
60+
# Setup and validate toolchain
61+
if (len(ctx.stack_path) <= 1) and ctx.options.toolchain:
62+
ctx.env.CC = ctx.options.toolchain + 'gcc'
63+
ctx.env.AR = ctx.options.toolchain + 'ar'
64+
65+
ctx.load('compiler_c python')
66+
67+
# Set git revision define
68+
git_rev = os.popen('git describe --long --always 2> /dev/null || echo unknown').read().strip()
69+
ctx.define('GIT_REV', git_rev)
70+
71+
# Set build output format
72+
ctx.env.FEATURES = ['c']
73+
if not ctx.options.disable_stlib:
74+
ctx.env.FEATURES += ['cstlib']
75+
76+
ctx.env.LIBCSP_SHLIB = ctx.options.enable_shlib
77+
78+
# Setup CFLAGS
79+
if (len(ctx.stack_path) <= 1) and (len(ctx.env.CFLAGS) == 0):
80+
ctx.env.prepend_value('CFLAGS', ["-std=gnu11", "-g", "-Os", "-Wall", "-Wextra", "-Wshadow", "-Wcast-align",
81+
"-Wpointer-arith",
82+
"-Wwrite-strings", "-Wno-unused-parameter", "-Werror"])
83+
84+
# Setup default include path and any extra defined
85+
ctx.env.append_unique('INCLUDES_CSP', ['include', 'src'] + ctx.options.includes.split(','))
86+
87+
# Store OS as env variable
88+
ctx.env.OS = ctx.options.with_os
2089

90+
# Platform/OS specifics
91+
if ctx.options.with_os == 'posix':
92+
ctx.env.append_unique('LIBS', ['rt', 'pthread', 'util'])
93+
94+
ctx.define_cond('CSP_FREERTOS', ctx.options.with_os == 'freertos')
95+
ctx.define_cond('CSP_POSIX', ctx.options.with_os == 'posix')
96+
97+
# Floating point
98+
if ctx.options.abi == 'hard':
99+
ctx.env.prepend_value('CFLAGS', ["-mfloat-abi=hard",
100+
"-mcpu=cortex-m4", "-mthumb",
101+
"-mfpu=fpv4-sp-d16" ,"-mcpu=cortex-m4",
102+
"-ffunction-sections", "-fdata-sections",
103+
"-fPIC", "-fstack-usage"])
104+
105+
# Add files
106+
ctx.env.append_unique('FILES_CSP', ['src/crypto/csp_hmac.c',
107+
'src/crypto/csp_sha1.c',
108+
'src/csp_buffer.c',
109+
'src/csp_bridge.c',
110+
'src/csp_conn.c',
111+
'src/csp_crc32.c',
112+
'src/csp_debug.c',
113+
'src/csp_dedup.c',
114+
'src/csp_iflist.c',
115+
'src/csp_init.c',
116+
'src/csp_io.c',
117+
'src/csp_port.c',
118+
'src/csp_qfifo.c',
119+
'src/csp_route.c',
120+
'src/csp_service_handler.c',
121+
'src/csp_services.c',
122+
'src/csp_id.c',
123+
'src/csp_sfp.c',
124+
'src/interfaces/csp_if_lo.c',
125+
'src/interfaces/csp_if_can.c',
126+
'src/interfaces/csp_if_can_pbuf.c',
127+
'src/interfaces/csp_if_kiss.c',
128+
'src/interfaces/csp_if_i2c.c',
129+
'src/arch/{0}/**/*.c'.format(ctx.options.with_os),
130+
])
131+
132+
# Add if rtable
133+
if ctx.options.enable_rtable:
134+
ctx.env.append_unique('FILES_CSP', ['src/csp_rtable_cidr.c'])
135+
# Add if stdio
136+
if ctx.check(header_name="stdio.h", mandatory=False):
137+
ctx.define('CSP_HAVE_STDIO', True)
138+
ctx.env.append_unique('FILES_CSP', ['src/csp_rtable_stdio.c'])
139+
140+
# Add if UDP
141+
if ctx.check(header_name="sys/socket.h", mandatory=False) and ctx.check(header_name="arpa/inet.h", mandatory=False):
142+
ctx.env.append_unique('FILES_CSP', ['src/interfaces/csp_if_udp.c'])
143+
144+
if not ctx.options.disable_output:
145+
ctx.env.append_unique('FILES_CSP', ['src/csp_hex_dump.c'])
146+
147+
if ctx.options.enable_promisc:
148+
ctx.env.append_unique('FILES_CSP', ['src/csp_promisc.c'])
149+
150+
if ctx.options.enable_rdp:
151+
ctx.env.append_unique('FILES_CSP', ['src/csp_rdp.c',
152+
'src/csp_rdp_queue.c'])
153+
154+
# Add YAML
155+
if ctx.options.enable_yaml:
156+
ctx.check_cfg(package='yaml-0.1', args='--cflags --libs', define_name='CSP_HAVE_LIBYAML')
157+
ctx.env.append_unique('LIBS', ctx.env.LIB_LIBYAML)
158+
ctx.env.append_unique('FILES_CSP', 'src/csp_yaml.c')
159+
160+
# Add socketcan
161+
if ctx.options.enable_can_socketcan:
162+
ctx.env.append_unique('FILES_CSP', 'src/drivers/can/can_socketcan.c')
163+
ctx.check_cfg(package='libsocketcan', args='--cflags --libs', define_name='CSP_HAVE_LIBSOCKETCAN')
164+
ctx.env.append_unique('LIBS', ctx.env.LIB_LIBSOCKETCAN)
165+
166+
# Add USART driver
167+
if ctx.options.with_driver_usart:
168+
ctx.env.append_unique('FILES_CSP', ['src/drivers/usart/usart_kiss.c',
169+
'src/drivers/usart/usart_{0}.c'.format(ctx.options.with_driver_usart)])
170+
171+
# Add ZMQ
172+
if ctx.options.enable_if_zmqhub:
173+
ctx.check_cfg(package='libzmq', args='--cflags --libs', define_name='CSP_HAVE_LIBZMQ')
174+
ctx.env.append_unique('LIBS', ctx.env.LIB_LIBZMQ)
175+
ctx.env.append_unique('FILES_CSP', 'src/interfaces/csp_if_zmqhub.c')
176+
177+
# Store configuration options
178+
ctx.env.ENABLE_EXAMPLES = ctx.options.enable_examples
179+
180+
# Add Python bindings
181+
if ctx.options.enable_python3_bindings:
182+
ctx.check_python_version((3,5))
183+
ctx.check_python_headers(features='pyext')
184+
185+
# Set defines for customizable parameters
186+
ctx.define('CSP_QFIFO_LEN', ctx.options.with_router_queue_length)
187+
ctx.define('CSP_PORT_MAX_BIND', ctx.options.with_max_bind_port)
188+
ctx.define('CSP_CONN_RXQUEUE_LEN', ctx.options.with_conn_queue_length)
189+
ctx.define('CSP_CONN_MAX', ctx.options.with_max_connections)
190+
ctx.define('CSP_BUFFER_SIZE', ctx.options.with_buffer_size)
191+
ctx.define('CSP_BUFFER_COUNT', ctx.options.with_buffer_count)
192+
ctx.define('CSP_RDP_MAX_WINDOW', ctx.options.with_rdp_max_window)
193+
ctx.define('CSP_RTABLE_SIZE', ctx.options.with_rtable_size)
194+
195+
# Set defines for enabling features
196+
ctx.define('CSP_REPRODUCIBLE_BUILDS', ctx.options.enable_reproducible_builds)
197+
ctx.define('CSP_ENABLE_CSP_PRINT', not ctx.options.disable_output)
198+
ctx.define('CSP_PRINT_STDIO', not ctx.options.disable_print_stdio)
199+
ctx.define('CSP_USE_RDP', ctx.options.enable_rdp)
200+
ctx.define('CSP_USE_HMAC', ctx.options.enable_hmac)
201+
ctx.define('CSP_USE_PROMISC', ctx.options.enable_promisc)
202+
ctx.define('CSP_USE_RTABLE', ctx.options.enable_rtable)
203+
204+
205+
ctx.write_config_header('include/csp/autoconfig.h')
206+
207+
def build(ctx):
208+
209+
# Set install path for header files
210+
install_path = None
211+
if ctx.is_install:
212+
install_path = '${PREFIX}/lib'
213+
ctx.install_files('${PREFIX}/include/csp',
214+
ctx.path.ant_glob('include/csp/**/*.h'),
215+
cwd=ctx.path.find_dir('include/csp'),
216+
relative_trick=True)
217+
ctx.install_files('${PREFIX}/include/csp', 'include/csp/autoconfig.h', cwd=ctx.bldnode)
218+
219+
ctx(export_includes=ctx.env.INCLUDES_CSP, name='csp_h')
220+
221+
ctx(features=ctx.env.FEATURES,
222+
source=ctx.path.ant_glob(ctx.env.FILES_CSP),
223+
target='csp',
224+
use=['csp_h', 'freertos_h', 'util'],
225+
install_path=install_path)
226+
227+
# Build shared library
228+
if ctx.env.LIBCSP_SHLIB or ctx.env.HAVE_PYEXT:
229+
ctx.shlib(source=ctx.path.ant_glob(ctx.env.FILES_CSP),
230+
name='csp_shlib',
231+
target='csp',
232+
use=['csp_h', 'util_shlib'],
233+
lib=ctx.env.LIBS)
234+
235+
# Build Python bindings
236+
if ctx.env.HAVE_PYEXT:
237+
ctx.shlib(source=ctx.path.ant_glob('src/bindings/python/**/*.c'),
238+
target='libcsp_py3',
239+
features='pyext',
240+
use=['csp_shlib'],
241+
pytest_path=[ctx.path.get_bld()])
242+
243+
if ctx.env.ENABLE_EXAMPLES:
244+
ctx.program(source=['examples/csp_server_client.c',
245+
'examples/csp_server_client_{0}.c'.format(ctx.env.OS)],
246+
target='examples/csp_server_client',
247+
lib=ctx.env.LIBS,
248+
use='csp')
249+
250+
ctx.program(source=['examples/csp_server.c',
251+
'examples/csp_server_{0}.c'.format(ctx.env.OS)],
252+
target='examples/csp_server',
253+
lib=ctx.env.LIBS,
254+
use='csp')
255+
256+
ctx.program(source=['examples/csp_client.c',
257+
'examples/csp_client_{0}.c'.format(ctx.env.OS)],
258+
target='examples/csp_client',
259+
lib=ctx.env.LIBS,
260+
use='csp')
261+
262+
ctx.program(source='examples/csp_arch.c',
263+
target='examples/csp_arch',
264+
lib=ctx.env.LIBS,
265+
use='csp')
266+
267+
if ctx.env.CSP_HAVE_LIBZMQ:
268+
ctx.program(source='examples/zmqproxy.c',
269+
target='examples/zmqproxy',
270+
lib=ctx.env.LIBS,
271+
use='csp')
272+
273+
274+
def dist(ctx):
275+
ctx.excl = 'build/* **/.* **/*.pyc **/*.o **/*~ *.tar.gz'
276+
#!/usr/bin/env python
277+
# encoding: utf-8
278+
279+
import os
280+
281+
APPNAME = 'libcsp'
282+
VERSION = '2.1'
283+
284+
valid_os = ['posix', 'freertos']
285+
valid_float_abi = ['hard', 'soft', 'softfp']
286+
287+
def options(ctx):
288+
# Load compiler
289+
ctx.load('compiler_c')
290+
291+
ctx.add_option('--toolchain', default=None, help='Set toolchain prefix')
292+
293+
# Set libcsp options
294+
gr = ctx.add_option_group('libcsp options')
295+
gr.add_option('--includes', default='', help='Add additional include paths, separate with comma')
296+
gr.add_option('--abi', default='hard', help='Add additional CFLAG for floating point abi. Must be one of: ' + str(valid_float_abi))
21297
gr.add_option('--enable-reproducible-builds', action='store_true', help='Enable reproducible builds')
22298

23299
gr.add_option('--disable-output', action='store_true', help='Disable CSP output')
@@ -93,6 +369,13 @@ def configure(ctx):
93369
ctx.define_cond('CSP_FREERTOS', ctx.options.with_os == 'freertos')
94370
ctx.define_cond('CSP_POSIX', ctx.options.with_os == 'posix')
95371

372+
# Floating point
373+
if ctx.options.abi == 'hard':
374+
ctx.env.prepend_value('CFLAGS', ["-mfloat-abi=hard",
375+
"-mcpu=cortex-m4", "-mthumb",
376+
"-mfpu=fpv4-sp-d16" ,"-mcpu=cortex-m4",
377+
"-ffunction-sections", "-fdata-sections",
378+
"-fPIC", "-fstack-usage"])
96379

97380
# Add files
98381
ctx.env.append_unique('FILES_CSP', ['src/crypto/csp_hmac.c',

0 commit comments

Comments
 (0)