diff --git a/Makefile b/Makefile index cc9b70e..0b8e867 100644 --- a/Makefile +++ b/Makefile @@ -47,7 +47,7 @@ TARGET_B = $(BIN_DIR)/partition_b -all: clean mk_build_dir alib amain part_a part_b +all: mk_build_dir alib amain part_a part_b @echo done! @@ -64,12 +64,33 @@ part_b: $(OBJS_B) cd $(MY_BUILD_DIR); $(CC) $(CFLAGS) $(LDFLAGS) -o $(TARGET_B) $(OBJS_B) ./liba653.a $(LDLIBS) -alib: - make -e -C $(SRC_DIR)/a653_lib +alib: $(TMP_DIR)/download/a653Blackboard.h $(TMP_DIR)/download/a653Buffer.h $(TMP_DIR)/download/a653Event.h $(TMP_DIR)/download/a653Mutex.h cp -r $(SRC_DIR)/a653_inc $(MY_BUILD_DIR) + cp $^ $(MY_BUILD_DIR)/a653_inc # cp -r $(SRC_DIR)/a653_ada $(MY_BUILD_DIR) + # relies on the above headers + make -e -C $(SRC_DIR)/a653_lib + + +# rule to download the ARINC headerfiles +$(TMP_DIR)/download/arinc653.h.zip: + @mkdir -p -- $(@D) + test -f $@ || curl --user-agent 'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:41.0) Gecko/20100101 Firefox/41.0' \ + --location --output-dir $(TMP_DIR)/download --remote-name-all \ + https://brx-content.fullsight.org/site/binaries/content/assets/itc/content/support-files/arinc653.h.zip + +# rule to extract the ARINC headerfiles +$(TMP_DIR)/download/ARINC653.h: $(TMP_DIR)/download/arinc653.h.zip + @mkdir -p -- $(@D) + test -f $@ || echo $^ | xargs --max-args=1 bsdtar -x --cd $(TMP_DIR)/download --modification-time --file +# rule to generate our Wasm header file, by making every open type a 32 Bit integer +$(TMP_DIR)/download/ARINC653_patched.h: $(TMP_DIR)/download/ARINC653.h + @mkdir -p -- $(@D) + awk -f $(SRC_DIR)/scripts/process-arinc-header.awk $< > $@ +$(TMP_DIR)/download/a653Blackboard.h $(TMP_DIR)/download/a653Buffer.h $(TMP_DIR)/download/a653Event.h $(TMP_DIR)/download/a653Mutex.h &: $(TMP_DIR)/download/ARINC653_patched.h + cd $(TMP_DIR)/download; awk -f $(SRC_DIR)/scripts/split-arinc-header.awk $< gcc_version: diff --git a/README.md b/README.md index f8cdafd..153f8b2 100644 --- a/README.md +++ b/README.md @@ -88,3 +88,7 @@ pid: 578773 <1702486050.349254883>: > taskset --cpu-list 1 ./partition_b & : ## Tests debugging ## Build with Make + +## Links + +[Required Services](https://www.aviation-ia.com/support-files/arinc653h) diff --git a/a653_lib/Makefile b/a653_lib/Makefile index 44534eb..0bc0b44 100644 --- a/a653_lib/Makefile +++ b/a653_lib/Makefile @@ -6,10 +6,10 @@ CC = gcc AR = ar -CFLAGS = -Wall -Wno-unused-function -g2 -O0 -fPIC -c -I../a653_inc $(COMMON_SWITCH) +CFLAGS = -Wall -Wno-unused-function -g2 -O0 -fPIC -c -I$(BUILD_DIR)/a653_inc $(COMMON_SWITCH) LDFLAGS = -g2 #-L /tools/gcc-810-ppc/lib -OBJS = a653_i_semaphore.o a653_i_partition.o a653_i_process.o a653_i_sampling.o a653_i_queuing.o a653_i_time.o a653Init.o a653_i_shm_if.o a653_i_sync.o a653_i_time_lib.o a653_i_error.o +OBJS = a653_i_semaphore.o a653_i_partition.o a653_i_process.o a653_i_sampling.o a653_i_queuing.o a653_i_time.o a653Init.o a653_i_shm_if.o a653_i_sync.o a653_i_time_lib.o a653_i_error.o a653_i_buffer.o a653_i_blackboard.o a653_i_mutex.o a653_i_event.o MY_BUILD_DIR = $(BUILD_DIR)/a653_lib TARGET = $(BUILD_DIR)/liba653.a diff --git a/a653_lib/a653_i_blackboard.c b/a653_lib/a653_i_blackboard.c new file mode 100644 index 0000000..2f419bc --- /dev/null +++ b/a653_lib/a653_i_blackboard.c @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2022-2023 Airbus Defence and Space + * + * This file is part of liba653. + * + * liba653 is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * liba653 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with liba653; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file a653_i_blackboard.c + * @copyright Airbus Defence and Space + * @author patrick.siegl@airbus.com + * @date Mon Nov 3 21:28:21 CET 2025 + * @brief a653 blackboard + * @details + */ + +/* includes */ + +#include "a653Lib.h" +#include "a653Blackboard.h" + +void CREATE_BLACKBOARD ( + /*in */ BLACKBOARD_NAME_TYPE BLACKBOARD_NAME, + /*in */ MESSAGE_SIZE_TYPE MAX_MESSAGE_SIZE, + /*out*/ BLACKBOARD_ID_TYPE *BLACKBOARD_ID, + /*out*/ RETURN_CODE_TYPE *RETURN_CODE ) { + *RETURN_CODE = NO_ACTION; +} + +void DISPLAY_BLACKBOARD ( + /*in */ BLACKBOARD_ID_TYPE BLACKBOARD_ID, + /*in */ MESSAGE_ADDR_TYPE MESSAGE_ADDR, /* by reference */ + /*in */ MESSAGE_SIZE_TYPE LENGTH, + /*out*/ RETURN_CODE_TYPE *RETURN_CODE ) { + *RETURN_CODE = NO_ACTION; +} + +void READ_BLACKBOARD ( + /*in */ BLACKBOARD_ID_TYPE BLACKBOARD_ID, + /*in */ SYSTEM_TIME_TYPE TIME_OUT, + /*in */ MESSAGE_ADDR_TYPE MESSAGE_ADDR, + /* The message address is passed IN, although */ + /* the respective message is passed OUT */ + /*out*/ MESSAGE_SIZE_TYPE *LENGTH, + /*out*/ RETURN_CODE_TYPE *RETURN_CODE ) { + *RETURN_CODE = NO_ACTION; +} + +void CLEAR_BLACKBOARD ( + /*in */ BLACKBOARD_ID_TYPE BLACKBOARD_ID, + /*out*/ RETURN_CODE_TYPE *RETURN_CODE ) { + *RETURN_CODE = NO_ACTION; +} + +void GET_BLACKBOARD_ID ( + /*in */ BLACKBOARD_NAME_TYPE BLACKBOARD_NAME, + /*out*/ BLACKBOARD_ID_TYPE *BLACKBOARD_ID, + /*out*/ RETURN_CODE_TYPE *RETURN_CODE ) { + *RETURN_CODE = NO_ACTION; +} + +void GET_BLACKBOARD_STATUS ( + /*in */ BLACKBOARD_ID_TYPE BLACKBOARD_ID, + /*out*/ BLACKBOARD_STATUS_TYPE *BLACKBOARD_STATUS, + /*out*/ RETURN_CODE_TYPE *RETURN_CODE ) { + *RETURN_CODE = NO_ACTION; +} diff --git a/a653_lib/a653_i_buffer.c b/a653_lib/a653_i_buffer.c new file mode 100644 index 0000000..f8fe33e --- /dev/null +++ b/a653_lib/a653_i_buffer.c @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2022-2023 Airbus Defence and Space + * + * This file is part of liba653. + * + * liba653 is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * liba653 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with liba653; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file a653_i_buffer.c + * @copyright Airbus Defence and Space + * @author patrick.siegl@airbus.com + * @date Mon Nov 3 21:28:21 CET 2025 + * @brief a653 buffer + * @details + */ + +/* includes */ + +#include "a653Lib.h" +#include "a653Buffer.h" + +void CREATE_BUFFER ( + /*in */ BUFFER_NAME_TYPE BUFFER_NAME, + /*in */ MESSAGE_SIZE_TYPE MAX_MESSAGE_SIZE, + /*in */ MESSAGE_RANGE_TYPE MAX_NB_MESSAGE, + /*in */ QUEUING_DISCIPLINE_TYPE QUEUING_DISCIPLINE, + /*out*/ BUFFER_ID_TYPE *BUFFER_ID, + /*out*/ RETURN_CODE_TYPE *RETURN_CODE ) { + *RETURN_CODE = NO_ACTION; +} + +void SEND_BUFFER ( + /*in */ BUFFER_ID_TYPE BUFFER_ID, + /*in */ MESSAGE_ADDR_TYPE MESSAGE_ADDR, /* by reference */ + /*in */ MESSAGE_SIZE_TYPE LENGTH, + /*in */ SYSTEM_TIME_TYPE TIME_OUT, + /*out*/ RETURN_CODE_TYPE *RETURN_CODE ) { + *RETURN_CODE = NO_ACTION; +} + +void RECEIVE_BUFFER ( + /*in */ BUFFER_ID_TYPE BUFFER_ID, + /*in */ SYSTEM_TIME_TYPE TIME_OUT, + /*in */ MESSAGE_ADDR_TYPE MESSAGE_ADDR, + /* The message address is passed IN, although */ + /* the respective message is passed OUT */ + /*out*/ MESSAGE_SIZE_TYPE *LENGTH, + /*out*/ RETURN_CODE_TYPE *RETURN_CODE ) { + *RETURN_CODE = NO_ACTION; +} + +void GET_BUFFER_ID ( + /*in */ BUFFER_NAME_TYPE BUFFER_NAME, + /*out*/ BUFFER_ID_TYPE *BUFFER_ID, + /*out*/ RETURN_CODE_TYPE *RETURN_CODE ) { + *RETURN_CODE = NO_ACTION; +} + +void GET_BUFFER_STATUS ( + /*in */ BUFFER_ID_TYPE BUFFER_ID, + /*out*/ BUFFER_STATUS_TYPE *BUFFER_STATUS, + /*out*/ RETURN_CODE_TYPE *RETURN_CODE ) { + *RETURN_CODE = NO_ACTION; +} diff --git a/a653_lib/a653_i_event.c b/a653_lib/a653_i_event.c new file mode 100644 index 0000000..e8960f2 --- /dev/null +++ b/a653_lib/a653_i_event.c @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2022-2023 Airbus Defence and Space + * + * This file is part of liba653. + * + * liba653 is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * liba653 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with liba653; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file a653_i_event.c + * @copyright Airbus Defence and Space + * @author patrick.siegl@airbus.com + * @date Mon Nov 3 21:28:21 CET 2025 + * @brief a653 event + * @details + */ + +/* includes */ + +#include "a653Lib.h" +#include "a653Event.h" + +void CREATE_EVENT ( + /*in */ EVENT_NAME_TYPE EVENT_NAME, + /*out*/ EVENT_ID_TYPE *EVENT_ID, + /*out*/ RETURN_CODE_TYPE *RETURN_CODE ) { + *RETURN_CODE = NO_ACTION; +} + +void SET_EVENT ( + /*in */ EVENT_ID_TYPE EVENT_ID, + /*out*/ RETURN_CODE_TYPE *RETURN_CODE ) { + *RETURN_CODE = NO_ACTION; +} + +void RESET_EVENT ( + /*in */ EVENT_ID_TYPE EVENT_ID, + /*out*/ RETURN_CODE_TYPE *RETURN_CODE ) { + *RETURN_CODE = NO_ACTION; +} + +void WAIT_EVENT ( + /*in */ EVENT_ID_TYPE EVENT_ID, + /*in */ SYSTEM_TIME_TYPE TIME_OUT, + /*out*/ RETURN_CODE_TYPE *RETURN_CODE ) { + *RETURN_CODE = NO_ACTION; +} + +void GET_EVENT_ID ( + /*in */ EVENT_NAME_TYPE EVENT_NAME, + /*out*/ EVENT_ID_TYPE *EVENT_ID, + /*out*/ RETURN_CODE_TYPE *RETURN_CODE ) { + *RETURN_CODE = NO_ACTION; +} + +void GET_EVENT_STATUS ( + /*in */ EVENT_ID_TYPE EVENT_ID, + /*out*/ EVENT_STATUS_TYPE *EVENT_STATUS, + /*out*/ RETURN_CODE_TYPE *RETURN_CODE ) { + *RETURN_CODE = NO_ACTION; +} diff --git a/a653_lib/a653_i_mutex.c b/a653_lib/a653_i_mutex.c new file mode 100644 index 0000000..dc5ec54 --- /dev/null +++ b/a653_lib/a653_i_mutex.c @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2022-2023 Airbus Defence and Space + * + * This file is part of liba653. + * + * liba653 is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * liba653 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with liba653; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file a653_i_mutex.c + * @copyright Airbus Defence and Space + * @author patrick.siegl@airbus.com + * @date Mon Nov 3 21:28:21 CET 2025 + * @brief a653 mutex + * @details + */ + +/* includes */ + +#include "a653Lib.h" +#include "a653Mutex.h" + +void CREATE_MUTEX ( + /*in */ MUTEX_NAME_TYPE MUTEX_NAME, + /*in */ PRIORITY_TYPE MUTEX_PRIORITY, + /*in */ QUEUING_DISCIPLINE_TYPE QUEUING_DISCIPLINE, + /*out*/ MUTEX_ID_TYPE *MUTEX_ID, + /*out*/ RETURN_CODE_TYPE *RETURN_CODE ) { + *RETURN_CODE = NO_ACTION; +} + +void ACQUIRE_MUTEX ( + /*in */ MUTEX_ID_TYPE MUTEX_ID, + /*in */ SYSTEM_TIME_TYPE TIME_OUT, + /*out*/ RETURN_CODE_TYPE *RETURN_CODE ) { + *RETURN_CODE = NO_ACTION; +} + +void RELEASE_MUTEX ( + /*in */ MUTEX_ID_TYPE MUTEX_ID, + /*out*/ RETURN_CODE_TYPE *RETURN_CODE ) { + *RETURN_CODE = NO_ACTION; +} + +void RESET_MUTEX ( + /*in */ MUTEX_ID_TYPE MUTEX_ID, + /*in */ PROCESS_ID_TYPE PROCESS_ID, + /*out*/ RETURN_CODE_TYPE *RETURN_CODE ) { + *RETURN_CODE = NO_ACTION; +} + +void GET_MUTEX_ID ( + /*in */ MUTEX_NAME_TYPE MUTEX_NAME, + /*out*/ MUTEX_ID_TYPE *MUTEX_ID, + /*out*/ RETURN_CODE_TYPE *RETURN_CODE ) { + *RETURN_CODE = NO_ACTION; +} + +void GET_MUTEX_STATUS ( + /*in */ MUTEX_ID_TYPE MUTEX_ID, + /*out*/ MUTEX_STATUS_TYPE *MUTEX_STATUS, + /*out*/ RETURN_CODE_TYPE *RETURN_CODE ) { + *RETURN_CODE = NO_ACTION; +} + +void GET_PROCESS_MUTEX_STATE ( + /*in */ PROCESS_ID_TYPE PROCESS_ID, + /*out*/ MUTEX_ID_TYPE *MUTEX_ID, + /*out*/ RETURN_CODE_TYPE *RETURN_CODE ) { + *RETURN_CODE = NO_ACTION; +} diff --git a/pkgs/a653lib.nix b/pkgs/a653lib.nix index d728d07..9056716 100644 --- a/pkgs/a653lib.nix +++ b/pkgs/a653lib.nix @@ -1,4 +1,12 @@ -{ lib, stdenv, fetchFromGitHub, bintools }: +{ lib, stdenv, fetchzip, bintools, gawk }: + +let + arinc653Zip = fetchzip { + url = "https://brx-content.fullsight.org/site/binaries/content/assets/itc/content/support-files/arinc653.h.zip"; + sha256 = "sha256-BGR3haRc+5I9VuyI+P8E/qTNnqVhnJKjP7j7RRCMFwg="; + curlOptsList = [ "--user-agent" "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:41.0) Gecko/20100101 Firefox/41.0" ]; + }; +in stdenv.mkDerivation { pname = "a653lib"; @@ -10,9 +18,14 @@ stdenv.mkDerivation { preConfigure = '' mkdir home export HOME="$PWD/home" + + # make the Makefile happy + mkdir --parent -- $HOME/tmp/download + touch $HOME/tmp/download/arinc653.h.zip + cp ${arinc653Zip}/ARINC653.h $HOME/tmp/download/. ''; - buildInputs = [ bintools ]; + buildInputs = [ bintools gawk ]; makeFlags = [ "CC=${stdenv.cc.targetPrefix}gcc" diff --git a/scripts/process-arinc-header.awk b/scripts/process-arinc-header.awk new file mode 100755 index 0000000..f796313 --- /dev/null +++ b/scripts/process-arinc-header.awk @@ -0,0 +1,63 @@ +#!/usr/bin/env -S awk -f + +BEGIN { + # retain information whether the current section of the header is portable or not + is_impl_dependent = -1; + + # use linux style linendings (just \n, not \r\n) + # ORS = "\n"; + + BINMODE = 0; +} + +# detect that we are in an implementation dependent section of the header +"/*" == $1 && "Implementation" == $2 && "Dependent" == $3 { + is_impl_dependent = 1; +} + +# detect that we are in an implementation portable section of the header +"/*" == $1 && "Implementation" == $2 && "Portable" == $3 { + is_impl_dependent = 0; +} + +# mark all functions to be importend from the arinc module +#"extern" == $1 && "void" == $2 && $4 ~/^\(/ { +# print "WASM_IMPORT_MODULE(\"arinc653\")" +#} + + +# make all implementation dependent defines ifndef based +"#define" == $1 && $2 ~ /^SYSTEM_LIMIT_/ && 1 == is_impl_dependent { + define_ident = $2; + define_value = $3; + + # print the comment + for (i = 4; i <= NF; i++) { + if (i != NF) { + printf("%s ", $i); + } else { + print $i; + } + } + + printf("%-8s %s\n", "#ifndef", define_ident); + printf("%-8s %-38s %s\n", $1, $2, $3); + print "#endif"; + next; +} + + +# always pick `APEX_LONG_INTEGER` (which ist `int64_t`) where there is a choice +{ + gsub("", "A653_INTEGER "); + + # to fit to Airbus a653lib + gsub("APEX_BYTE", "A653_BYTE"); + gsub("APEX_WORD", "A653_WORD"); + gsub("APEX_INTEGER", "A653_INTEGER"); + gsub("APEX_UNSIGNED", "A653_UNSIGNED"); + gsub("APEX_LONG_INTEGER", "A653_LONG_INTEGER"); + print; +} + + diff --git a/scripts/split-arinc-header.awk b/scripts/split-arinc-header.awk new file mode 100755 index 0000000..2ce2560 --- /dev/null +++ b/scripts/split-arinc-header.awk @@ -0,0 +1,34 @@ +#!/usr/bin/env -S awk -f + +# not the nicest, should be rather on the comment .. + +/^#ifndef APEX_/ { + # Close the previous output file if open + if (out) close(out) + + # Extract the name part after APEX_ + match($0, /^#ifndef APEX_([A-Z0-9_]+)/, arr) + name = tolower(arr[1]) + # Capitalize first letter + name = toupper(substr(name, 1, 1)) substr(name, 2) + + # Compose output filename + out = "a653" name ".h" + + # Print the current line to the new output file + print $0 > out + next +} + +# mark all functions to be importend from the arinc module +/^#define APEX_([A-Z0-9_]+)/ { + print $0 > out + print "" > out + print "#include \"a653Type.h\"" > out + next +} + +{ + # Print all other lines to the current output file + if (out) print $0 > out +}