Skip to content

Commit

Permalink
Add Arduino amalgamation.
Browse files Browse the repository at this point in the history
  • Loading branch information
christoph2 committed Sep 2, 2022
1 parent 318c2a3 commit 8516d44
Show file tree
Hide file tree
Showing 4 changed files with 370 additions and 0 deletions.
114 changes: 114 additions & 0 deletions tools/amalgam8.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from collections import defaultdict
import enum
import graphlib # requires Python >= 3.9
import pathlib
from pprint import pprint
import re


START = re.compile(r"/\*!!!\s+START-INCLUDE-SECTION\s+!!!\*/")
END = re.compile(r"/\*!!!\s+END-INCLUDE-SECTION\s+!!!\*/")

INCLUDE = re.compile(r'#include\s+"([^"]*)"')

class StateType(enum.IntEnum):
IDLE = 0
COLLECTING = 1

def builder(files, stoplist = None):
source_includes = defaultdict(list)
source_files = defaultdict(list)
state = StateType.IDLE
stoplist = stoplist or []
for fn in files:
if str(fn) in stoplist:
continue
with open(fn) as source:
#source_includes[str(fn)] = []
source_includes[fn] = []
for idx, line in enumerate(source, 1):
if state == StateType.IDLE:
match = START.match(line)
if match:
state = StateType.COLLECTING
else:
source_files[fn].append(line)
if state == StateType.COLLECTING:
match = END.match(line)
if match:
state = StateType.IDLE
else:
line = line.strip()
if not line:
continue
match = INCLUDE.match(line)
if match:
incf = match.group(1)
source_includes[fn].append(incf)
for k,v in source_files.items():
source_files[k] = "".join(v)
return source_includes, source_files

def convert_to_paths(file_name_dict: dict):
result = {}
for k, v in file_name_dict.items():
items = []
for item in v:
item = pathlib.Path(r"../inc") / pathlib.Path(item)
items.append(item)
result[k] = items
return result

def print_file_name(out_file, item):
out_file.write("\n")
out_file.write("/" * 80)
out_file.write("\n")
fname = "//" + f"{item.name}".center(76) + "//"
out_file.write(fname)
out_file.write("\n")
out_file.write("/" * 80)
out_file.write("\n\n")


STOP_LIST = [ # don't include these files.
r'..\src\hw\options.c',
r'..\src\hw\terminal.c',
r'..\src\hw\threads.c',
r'..\src\hw\linux\hw.c',
r'..\src\hw\win\hw.c',
r'..\src\tl\bt\winbt.c',
r'..\src\tl\can\kvaser.c',
r'..\src\tl\can\linux_socket_can.c',
r'..\src\tl\eth\common.c',
r'..\src\tl\eth\linuxeth.c',
r'..\src\tl\eth\wineth.c',
r'..\src\tl\eth\wineth_iocp.c',
]

pth = pathlib.Path("../src")
SOURCES = list(pth.glob('**/*.c')) + list(pth.glob('**/*.cpp'))
INCS = list(pathlib.Path("../inc").glob("**/*.h"))

source_includes, source_files = builder(INCS, stoplist = [r"..\inc\xcp_ow.h", r'..\inc\xcp_terminal.h', r'..\inc\xcp_threads.h', r'..\inc\xcp_tui.h'])

ts = graphlib.TopologicalSorter(convert_to_paths(source_includes))
static_ordered_files = tuple(ts.static_order())

with open("xcp.h", "wt") as sf:
for item in static_ordered_files:
print_file_name(sf, item)
if item in source_files:
sf.write(source_files[item])
else:
raise RuntimeError("Something went wrong")
source_includes, source_files = builder(SOURCES, STOP_LIST)
for k, v in source_files.items():
#print("KK", k)
print_file_name(sf, k)
sf.write(v)

print("\n", "=" * 80, "\n")

1 change: 1 addition & 0 deletions tools/build.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python amalgam8.py
10 changes: 10 additions & 0 deletions tools/library.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name=blink
version=1.0
author=Christoph Schueler <cpu12.gems@googlemail.com>
maintainer=Christoph Schueler <cpu12.gems@googlemail.com>
sentence=Measure and calibrate with XCP.
paragraph=Blink a pin without using digitalWrite.
category=Communication
url=https://github.com/christoph2/arduino-xcp
architectures=*
includes=xcp.h
245 changes: 245 additions & 0 deletions tools/xcp_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,245 @@
/*
* BlueParrot XCP
*
* (C) 2007-2021 by Christoph Schueler <github.com/Christoph2,
* cpu12.gems@googlemail.com>
*
* All Rights Reserved
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* s. FLOSS-EXCEPTION.txt
*/

/*
* For details on options refer to `documentation
* <https://github.com/christoph2/cxcp/docs/options.rst>`_
*/

#if !defined(__XCP_CONFIG_H)
#define __XCP_CONFIG_H

/*
** General Options.
*/
#define TP_CAN

#define XCP_GET_ID_0 "BlueParrot XCP running on Windows"
#define XCP_GET_ID_1 "Example_Project"

//#define XCP_BUILD_TYPE XCP_RELEASE_BUILD
#define XCP_BUILD_TYPE XCP_DEBUG_BUILD

#define XCP_ENABLE_EXTERN_C_GUARDS XCP_OFF

#define XCP_ENABLE_SLAVE_BLOCKMODE XCP_ON
#define XCP_ENABLE_MASTER_BLOCKMODE XCP_ON

#define XCP_ENABLE_STIM XCP_OFF

#define XCP_CHECKSUM_METHOD XCP_CHECKSUM_METHOD_XCP_CRC_16_CITT
#define XCP_CHECKSUM_CHUNKED_CALCULATION XCP_ON
#define XCP_CHECKSUM_CHUNK_SIZE (64)
#define XCP_CHECKSUM_MAXIMUM_BLOCK_SIZE (0) /* 0 ==> unlimited */

#define XCP_BYTE_ORDER XCP_BYTE_ORDER_INTEL
#define XCP_ADDRESS_GRANULARITY XCP_ADDRESS_GRANULARITY_BYTE

#define XCP_ENABLE_STATISTICS XCP_ON

#define XCP_MAX_BS (8)
#define XCP_MIN_ST (0)
#define XCP_QUEUE_SIZE (0)

#define XCP_MAIN_FUNCTION_PERIOD (2000) /* Period in microseconds. */

/*
** Resource Protection.
*/
#define XCP_PROTECT_CAL XCP_OFF
#define XCP_PROTECT_PAG XCP_ON
#define XCP_PROTECT_DAQ XCP_OFF
#define XCP_PROTECT_STIM XCP_ON
#define XCP_PROTECT_PGM XCP_OFF

/*
** DAQ Settings.
*/
#define XCP_DAQ_CONFIG_TYPE XCP_DAQ_CONFIG_TYPE_DYNAMIC
#define XCP_DAQ_DTO_BUFFER_SIZE (40)
#define XCP_DAQ_ENABLE_PREDEFINED_LISTS XCP_OFF
#define XCP_DAQ_TIMESTAMP_UNIT (XCP_DAQ_TIMESTAMP_UNIT_1US)
#define XCP_DAQ_TIMESTAMP_SIZE (XCP_DAQ_TIMESTAMP_SIZE_4)
#define XCP_DAQ_ENABLE_PRESCALER XCP_OFF
#define XCP_DAQ_ENABLE_ADDR_EXT XCP_OFF
#define XCP_DAQ_ENABLE_BIT_OFFSET XCP_OFF
#define XCP_DAQ_ENABLE_PRIORITIZATION XCP_OFF
#define XCP_DAQ_ENABLE_ALTERNATING XCP_OFF
#define XCP_DAQ_ENABLE_CLOCK_ACCESS_ALWAYS XCP_ON
#define XCP_DAQ_ENABLE_WRITE_THROUGH XCP_OFF
#define XCP_DAQ_MAX_DYNAMIC_ENTITIES (100)
#define XCP_DAQ_MAX_EVENT_CHANNEL (3)
#define XCP_DAQ_ENABLE_MULTIPLE_DAQ_LISTS_PER_EVENT XCP_OFF

/*
** PGM Settings.
*/
#define XCP_MAX_BS_PGM (0)
#define XCP_MIN_ST_PGM (0)

#define XCP_MAX_SECTOR_PGM UINT8(32)
#define XCP_PGM_PROPERIES XCP_PGM_ABSOLUTE_MODE

/*
** Optional Services.
*/
#define XCP_ENABLE_GET_COMM_MODE_INFO XCP_ON
#define XCP_ENABLE_GET_ID XCP_ON
#define XCP_ENABLE_SET_REQUEST XCP_OFF
#define XCP_ENABLE_GET_SEED XCP_ON
#define XCP_ENABLE_UNLOCK XCP_ON
#define XCP_ENABLE_SET_MTA XCP_ON
#define XCP_ENABLE_UPLOAD XCP_ON
#define XCP_ENABLE_SHORT_UPLOAD XCP_ON
#define XCP_ENABLE_BUILD_CHECKSUM XCP_ON
#define XCP_ENABLE_TRANSPORT_LAYER_CMD \
XCP_OFF /* TODO: TL dependend include file! */
#define XCP_ENABLE_USER_CMD XCP_OFF

#define XCP_ENABLE_CAL_COMMANDS XCP_ON

#define XCP_ENABLE_DOWNLOAD_NEXT XCP_ON
#define XCP_ENABLE_DOWNLOAD_MAX XCP_ON
#define XCP_ENABLE_SHORT_DOWNLOAD XCP_ON
#define XCP_ENABLE_MODIFY_BITS XCP_ON

#define XCP_ENABLE_PAG_COMMANDS XCP_OFF

#define XCP_ENABLE_GET_PAG_PROCESSOR_INFO XCP_OFF
#define XCP_ENABLE_GET_SEGMENT_INFO XCP_OFF
#define XCP_ENABLE_GET_PAGE_INFO XCP_OFF
#define XCP_ENABLE_SET_SEGMENT_MODE XCP_OFF
#define XCP_ENABLE_GET_SEGMENT_MODE XCP_OFF
#define XCP_ENABLE_COPY_CAL_PAGE XCP_OFF

#define XCP_ENABLE_DAQ_COMMANDS XCP_ON

#define XCP_ENABLE_GET_DAQ_CLOCK XCP_ON
#define XCP_ENABLE_READ_DAQ XCP_OFF
#define XCP_ENABLE_GET_DAQ_PROCESSOR_INFO XCP_ON
#define XCP_ENABLE_GET_DAQ_RESOLUTION_INFO XCP_ON
#define XCP_ENABLE_GET_DAQ_LIST_INFO XCP_ON
#define XCP_ENABLE_GET_DAQ_EVENT_INFO XCP_ON
#define XCP_ENABLE_FREE_DAQ XCP_ON
#define XCP_ENABLE_ALLOC_DAQ XCP_ON
#define XCP_ENABLE_ALLOC_ODT XCP_ON
#define XCP_ENABLE_ALLOC_ODT_ENTRY XCP_ON
#define XCP_ENABLE_WRITE_DAQ_MULTIPLE XCP_OFF

#define XCP_ENABLE_PGM_COMMANDS XCP_ON

#define XCP_ENABLE_GET_PGM_PROCESSOR_INFO XCP_ON
#define XCP_ENABLE_GET_SECTOR_INFO XCP_ON
#define XCP_ENABLE_PROGRAM_PREPARE XCP_ON
#define XCP_ENABLE_PROGRAM_FORMAT XCP_OFF
#define XCP_ENABLE_PROGRAM_NEXT XCP_OFF
#define XCP_ENABLE_PROGRAM_MAX XCP_OFF
#define XCP_ENABLE_PROGRAM_VERIFY XCP_OFF

#define XCP_ENABLE_EVENT_PACKET_API XCP_ON
#define XCP_ENABLE_SERVICE_REQUEST_API XCP_OFF

/*
** Transport-Layer specific Options (may not apply to every Transport).
*/
#if defined(TP_CAN)
#define XCP_TRANSPORT_LAYER XCP_ON_CAN

#define XCP_ON_CAN_INBOUND_IDENTIFIER (0x102)
#define XCP_ON_CAN_OUTBOUND_IDENTIFIER (0x101)
#define XCP_ON_CAN_MAX_DLC_REQUIRED XCP_OFF
#define XCP_ON_CAN_BROADCAST_IDENTIFIER (0x103)
#define XCP_ON_CAN_FREQ (canBITRATE_250K)
#define XCP_ON_CAN_BTQ (16)
#define XCP_ON_CAN_TSEG1 (14)
#define XCP_ON_CAN_TSEG2 (2)
#define XCP_ON_CAN_SJW (2)
#define XCP_ON_CAN_NOSAMP (1)
#elif defined(TP_BLUETOOTH)
#define XCP_TRANSPORT_LAYER XCP_ON_BTH

#define XCP_MAX_CTO (64) // (16)
#define XCP_MAX_DTO (64)

#define XCP_TRANSPORT_LAYER_LENGTH_SIZE (2)
#define XCP_TRANSPORT_LAYER_COUNTER_SIZE (2)
#define XCP_TRANSPORT_LAYER_CHECKSUM_SIZE (0)
#elif defined(TP_ETHER)
#define XCP_TRANSPORT_LAYER XCP_ON_ETHERNET

#define XCP_MAX_CTO (64) // (16)
#define XCP_MAX_DTO (64)

#define XCP_TRANSPORT_LAYER_LENGTH_SIZE (2)
#define XCP_TRANSPORT_LAYER_COUNTER_SIZE (2)
#define XCP_TRANSPORT_LAYER_CHECKSUM_SIZE (0)
#else
#error \
"No transport-layer. please define either TP_ETHER, TP_CAN, or TP_BLUETOOTH."
#endif // KVASER_CAN

/*
** Customization Options.
*/
#define XCP_ENABLE_ADDRESS_MAPPER XCP_ON
#define XCP_ENABLE_CHECK_MEMORY_ACCESS XCP_ON
#define XCP_REPLACE_STD_COPY_MEMORY XCP_OFF
#define XCP_ENABLE_GET_ID_HOOK XCP_ON

/*
**
** Arduino Specific Options.
**
*/

/*
** Platform Specific Function-like Macros.
*/
#define XCP_ENTER_CRITICAL() XcpHw_AcquireLock(XCP_HW_LOCK_XCP)
#define XCP_LEAVE_CRITICAL() XcpHw_ReleaseLock(XCP_HW_LOCK_XCP)
#define XCP_HW_ENTER_CRITICAL() XcpHw_AcquireLock(XCP_HW_LOCK_HW)
#define XCP_HW_LEAVE_CRITICAL() XcpHw_ReleaseLock(XCP_HW_LOCK_HW)
#define XCP_TL_ENTER_CRITICAL() XcpHw_AcquireLock(XCP_HW_LOCK_TL)
#define XCP_TL_LEAVE_CRITICAL() XcpHw_ReleaseLock(XCP_HW_LOCK_TL)
#define XCP_DAQ_ENTER_CRITICAL() XcpHw_AcquireLock(XCP_HW_LOCK_DAQ)
#define XCP_DAQ_LEAVE_CRITICAL() XcpHw_ReleaseLock(XCP_HW_LOCK_DAQ)
#define XCP_STIM_ENTER_CRITICAL()
#define XCP_STIM_LEAVE_CRITICAL()
#define XCP_PGM_ENTER_CRITICAL()
#define XCP_PGM_LEAVE_CRITICAL()
#define XCP_CAL_ENTER_CRITICAL()
#define XCP_CAL_LEAVE_CRITICAL()
#define XCP_PAG_ENTER_CRITICAL()
#define XCP_PAG_LEAVE_CRITICAL()

/*
** Application Settings.
*/
#define XCP_APP_TIMEBASE \
(10) /* Applications gets called every 'n' milliseconds, \
** 0 ==> free running. \
*/

#endif /* __XCP_CONFIG_H */

0 comments on commit 8516d44

Please sign in to comment.