diff --git a/.gitignore b/.gitignore
index e1ff5d500..6aee0ed8e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -32,6 +32,7 @@ a.out
*.class
*.pyxbldc
*.vcd
+*.qm
config.json
clcache
compile_commands.json
@@ -54,7 +55,6 @@ selfdrive/modeld/_dmonitoringmodeld
/src/
one
-/body/
openpilot
notebooks
xx
diff --git a/Jenkinsfile b/Jenkinsfile
index 4e1371785..6b05e81d7 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -70,7 +70,6 @@ pipeline {
not {
anyOf {
branch 'master-ci'; branch 'devel'; branch 'devel-staging';
- branch 'release2'; branch 'release2-staging'; branch 'dashcam'; branch 'dashcam-staging';
branch 'release3'; branch 'release3-staging'; branch 'dashcam3'; branch 'dashcam3-staging';
branch 'testing-closet*'; branch 'hotfix-*'
}
@@ -128,7 +127,7 @@ pipeline {
steps {
phone_steps("tici2", [
["build", "cd selfdrive/manager && ./build.py"],
- ["test power draw", "python system/hardware/tici/test_power_draw.py"],
+ //["test power draw", "python system/hardware/tici/test_power_draw.py"],
["test boardd loopback", "python selfdrive/boardd/tests/test_boardd_loopback.py"],
["test loggerd", "python selfdrive/loggerd/tests/test_loggerd.py"],
["test encoder", "LD_LIBRARY_PATH=/usr/local/lib python selfdrive/loggerd/tests/test_encoder.py"],
diff --git a/README.md b/README.md
index 3dce9d447..0b6fc2010 100755
--- a/README.md
+++ b/README.md
@@ -4,7 +4,7 @@ Table of Contents
=======================
* [What is openpilot?](#what-is-openpilot)
-* [Running in a car](#running-in-a-car)
+* [Running in a car](#running-on-a-dedicated-device-in-a-car)
* [Running on PC](#running-on-pc)
* [Community and Contributing](#community-and-contributing)
* [User Data and comma Account](#user-data-and-comma-account)
@@ -17,7 +17,7 @@ Table of Contents
What is openpilot?
------
-[openpilot](http://github.com/commaai/openpilot) is an open source driver assistance system. Currently, openpilot performs the functions of Adaptive Cruise Control (ACC), Automated Lane Centering (ALC), Forward Collision Warning (FCW) and Lane Departure Warning (LDW) for a growing variety of [supported car makes, models and model years](docs/CARS.md). In addition, while openpilot is engaged, a camera based Driver Monitoring (DM) feature alerts distracted and asleep drivers. See more about [the vehicle integration](docs/INTEGRATION.md) and [limitations](docs/LIMITATIONS.md).
+[openpilot](http://github.com/commaai/openpilot) is an open source driver assistance system. Currently, openpilot performs the functions of Adaptive Cruise Control (ACC), Automated Lane Centering (ALC), Forward Collision Warning (FCW), and Lane Departure Warning (LDW) for a growing variety of [supported car makes, models, and model years](docs/CARS.md). In addition, while openpilot is engaged, a camera-based Driver Monitoring (DM) feature alerts distracted and asleep drivers. See more about [the vehicle integration](docs/INTEGRATION.md) and [limitations](docs/LIMITATIONS.md).
@@ -40,9 +40,9 @@ Running on a dedicated device in a car
To use openpilot in a car, you need four things
* A supported device to run this software: a [comma three](https://comma.ai/shop/products/three).
-* This software. The setup procedure of the comma three allows the user to enter a url for custom software.
-The url, openpilot.comma.ai will install the release version of openpilot. To install openpilot master, you can use installer.comma.ai/commaai/master, and replacing commaai with another github username can install a fork.
-* One of [the 150+ supported cars](docs/CARS.md). We support Honda, Toyota, Hyundai, Nissan, Kia, Chrysler, Lexus, Acura, Audi, VW, and more. If your car is not supported, but has adaptive cruise control and lane keeping assist, it's likely able to run openpilot.
+* This software. The setup procedure of the comma three allows the user to enter a URL for custom software.
+The URL, openpilot.comma.ai will install the release version of openpilot. To install openpilot master, you can use installer.comma.ai/commaai/master, and replacing commaai with another GitHub username can install a fork.
+* One of [the 150+ supported cars](docs/CARS.md). We support Honda, Toyota, Hyundai, Nissan, Kia, Chrysler, Lexus, Acura, Audi, VW, and more. If your car is not supported but has adaptive cruise control and lane-keeping assist, it's likely able to run openpilot.
* A [car harness](https://comma.ai/shop/products/car-harness) to connect to your car.
We have detailed instructions for [how to mount the device in a car](https://comma.ai/setup).
@@ -52,11 +52,11 @@ Running on PC
All of openpilot's services can run as normal on a PC, even without special hardware or a car. To develop or experiment with openpilot you can run openpilot on recorded or simulated data.
-With openpilot's tools you can plot logs, replay drives and watch the full-res camera streams. See [the tools README](tools/README.md) for more information.
+With openpilot's tools, you can plot logs, replay drives, and watch the full-res camera streams. See [the tools README](tools/README.md) for more information.
-You can also run openpilot in simulation [with the CARLA simulator](tools/sim/README.md). This allows openpilot to drive around a virtual car on your Ubuntu machine. The whole setup should only take a few minutes, but does require a decent GPU.
+You can also run openpilot in simulation [with the CARLA simulator](tools/sim/README.md). This allows openpilot to drive around a virtual car on your Ubuntu machine. The whole setup should only take a few minutes but does require a decent GPU.
-A PC running openpilot can also control your vehicle if it is connected to a [a webcam](https://github.com/commaai/openpilot/tree/master/tools/webcam), a [black panda](https://comma.ai/shop/products/panda), and [a harness](https://comma.ai/shop/products/car-harness).
+A PC running openpilot can also control your vehicle if it is connected to a [webcam](https://github.com/commaai/openpilot/tree/master/tools/webcam), a [black panda](https://comma.ai/shop/products/panda), and a [harness](https://comma.ai/shop/products/car-harness).
Community and Contributing
------
@@ -78,8 +78,8 @@ By default, openpilot uploads the driving data to our servers. You can also acce
openpilot is open source software: the user is free to disable data collection if they wish to do so.
-openpilot logs the road facing cameras, CAN, GPS, IMU, magnetometer, thermal sensors, crashes, and operating system logs.
-The driver facing camera is only logged if you explicitly opt-in in settings. The microphone is not recorded.
+openpilot logs the road-facing cameras, CAN, GPS, IMU, magnetometer, thermal sensors, crashes, and operating system logs.
+The driver-facing camera is only logged if you explicitly opt-in in settings. The microphone is not recorded.
By using openpilot, you agree to [our Privacy Policy](https://comma.ai/privacy). You understand that use of this software or its related services will generate certain types of user data, which may be logged and stored at the sole discretion of comma. By accepting this agreement, you grant an irrevocable, perpetual, worldwide right to comma for the use of this data.
@@ -87,11 +87,11 @@ Safety and Testing
----
* openpilot observes ISO26262 guidelines, see [SAFETY.md](docs/SAFETY.md) for more details.
-* openpilot has software in the loop [tests](.github/workflows/selfdrive_tests.yaml) that run on every commit.
+* openpilot has software-in-the-loop [tests](.github/workflows/selfdrive_tests.yaml) that run on every commit.
* The code enforcing the safety model lives in panda and is written in C, see [code rigor](https://github.com/commaai/panda#code-rigor) for more details.
-* panda has software in the loop [safety tests](https://github.com/commaai/panda/tree/master/tests/safety).
-* Internally, we have a hardware in the loop Jenkins test suite that builds and unit tests the various processes.
-* panda has additional hardware in the loop [tests](https://github.com/commaai/panda/blob/master/Jenkinsfile).
+* panda has software-in-the-loop [safety tests](https://github.com/commaai/panda/tree/master/tests/safety).
+* Internally, we have a hardware-in-the-loop Jenkins test suite that builds and unit tests the various processes.
+* panda has additional hardware-in-the-loop [tests](https://github.com/commaai/panda/blob/master/Jenkinsfile).
* We run the latest openpilot in a testing closet containing 10 comma devices continuously replaying routes.
Directory Structure
diff --git a/RELEASES.md b/RELEASES.md
index b87bd2ee7..a6ba4558e 100644
--- a/RELEASES.md
+++ b/RELEASES.md
@@ -1,3 +1,21 @@
+Version 0.8.16 (2022-08-26)
+========================
+* New driving model
+ * Reduced turn cutting
+* Auto-detect right hand drive setting with driver monitoring model
+* Improved fan controller for comma three
+* New translations
+ * Japanese thanks to cydia2020!
+ * Brazilian Portuguese thanks to AlexandreSato!
+* Chevrolet Bolt EUV 2022-23 support thanks to JasonJShuler!
+* Chevrolet Silverado 1500 2020-21 support thanks to JasonJShuler!
+* GMC Sierra 1500 2020-21 support thanks to JasonJShuler!
+* Hyundai Ioniq 5 2022 support thanks to sunnyhaibin!
+* Hyundai Kona Electric 2022 support thanks to sunnyhaibin!
+* Hyundai Tucson Hybrid 2022 support thanks to sunnyhaibin!
+* Subaru Legacy 2020-22 support thanks to martinl!
+* Subaru Outback 2020-22 support
+
Version 0.8.15 (2022-07-20)
========================
* New driving model
diff --git a/SConstruct b/SConstruct
index 1209894ba..49685b19b 100644
--- a/SConstruct
+++ b/SConstruct
@@ -393,9 +393,13 @@ if arch != "Darwin":
# Build openpilot
-SConscript(['cereal/SConscript'])
-SConscript(['panda/board/SConscript'])
-SConscript(['opendbc/can/SConscript'])
+# build submodules
+SConscript([
+ 'cereal/SConscript',
+ 'body/board/SConscript',
+ 'panda/board/SConscript',
+ 'opendbc/can/SConscript',
+])
SConscript(['third_party/SConscript'])
@@ -415,6 +419,7 @@ SConscript(['selfdrive/loggerd/SConscript'])
SConscript(['selfdrive/locationd/SConscript'])
SConscript(['selfdrive/sensord/SConscript'])
SConscript(['selfdrive/ui/SConscript'])
+SConscript(['selfdrive/navd/SConscript'])
SConscript(['tools/replay/SConscript'])
diff --git a/body/.gitignore b/body/.gitignore
new file mode 100644
index 000000000..cd74bc601
--- /dev/null
+++ b/body/.gitignore
@@ -0,0 +1,15 @@
+*.pyc
+.*.swp
+.*.swo
+*.o
+*.so
+*.os
+*.d
+*.dump
+a.out
+*~
+.#*
+.vscode*
+.DS_Store
+board/obj/
+.sconsign.dblite
diff --git a/body/board/SConscript b/body/board/SConscript
new file mode 100644
index 000000000..d1d6ea04b
--- /dev/null
+++ b/body/board/SConscript
@@ -0,0 +1,198 @@
+import os
+import subprocess
+
+PREFIX = "arm-none-eabi-"
+BUILDER = "DEV"
+
+common_flags = []
+build_projects = {}
+
+build_projects["body"] = {
+ "MAIN": "main.c",
+ "STARTUP_FILE": "startup_stm32f413xx.s",
+ "LINKER_SCRIPT": "stm32fx_flash.ld",
+ "APP_START_ADDRESS": "0x08004000",
+ "PROJECT_FLAGS": [
+ "-mcpu=cortex-m4",
+ "-mhard-float",
+ "-DSTM32F4",
+ "-DSTM32F413xx",
+ "-mfpu=fpv4-sp-d16",
+ "-fsingle-precision-constant",
+ "-Os",
+ "-g",
+ ],
+}
+
+if os.getenv("RELEASE"):
+ BUILD_TYPE = "RELEASE"
+ cert_fn = os.getenv("CERT")
+ assert cert_fn is not None, 'No certificate file specified. Please set CERT env variable'
+ assert os.path.exists(cert_fn), 'Certificate file not found. Please specify absolute path'
+else:
+ BUILD_TYPE = "DEBUG"
+ cert_fn = File("../certs/debug").srcnode().abspath
+ common_flags += ["-DALLOW_DEBUG"]
+
+if os.getenv("DEBUG"):
+ common_flags += ["-DDEBUG"]
+
+includes = [
+ "inc/STM32F4xx_HAL_Driver/Inc",
+ "inc",
+ "..",
+ ".",
+]
+
+c_sources = [
+ ["hal_flash", "inc/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c"],
+ ["hal_pwr", "inc/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c"],
+ ["hal_rcc", "inc/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c"],
+ ["hal_i2c", "inc/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c.c"],
+ ["hal_i2c_ex", "inc/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c_ex.c"],
+ ["hal_tim", "inc/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim.c"],
+ ["hal_tim_ex", "inc/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.c"],
+ ["hal_adc_ex", "inc/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_adc_ex.c"],
+ ["hal_cortex", "inc/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c"],
+ ["hal_flash_ex", "inc/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c"],
+ ["hal_gpio", "inc/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c"],
+ ["hal_rcc_ex", "inc/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc_ex.c"],
+ ["hal", "inc/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c"],
+ ["hal_adc", "inc/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_adc.c"],
+ ["hal_dma", "inc/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c"],
+ ["system", "inc/system_stm32f4xx.c"],
+ ["it", "inc/stm32f4xx_it.c"],
+ ["bldc", "bldc/bldc.c"],
+ ["bldc_data", "bldc/BLDC_controller_data.c"],
+ ["bldc_con", "bldc/BLDC_controller.c"],
+ ["util", "util.c"],
+]
+
+c_bstub_sources = [
+ ["hal_pwr", "inc/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c"],
+ ["hal_rcc", "inc/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c"],
+ ["hal_cortex", "inc/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c"],
+ ["hal_gpio", "inc/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c"],
+ ["hal_rcc_ex", "inc/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc_ex.c"],
+ ["hal", "inc/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c"],
+ ["system", "inc/system_stm32f4xx.c"],
+ ["it", "inc/stm32f4xx_it.c"],
+ ["util", "util.c"],
+]
+
+def get_version(builder, build_type):
+ try:
+ git = subprocess.check_output(["git", "rev-parse", "--short=8", "HEAD"], encoding='utf8').strip()
+ except subprocess.CalledProcessError:
+ git = "00000000"
+ return f"{git}"
+
+
+def to_c_uint32(x):
+ nums = []
+ for _ in range(0x20):
+ nums.append(x % (2**32))
+ x //= (2**32)
+ return "{" + 'U,'.join(map(str, nums)) + "U}"
+
+
+def get_key_header(name):
+ from Crypto.PublicKey import RSA
+
+ public_fn = File(f'../certs/{name}.pub').srcnode().abspath
+ rsa = RSA.importKey(open(public_fn).read())
+ assert(rsa.size_in_bits() == 1024)
+
+ rr = pow(2**1024, 2, rsa.n)
+ n0inv = 2**32 - pow(rsa.n, -1, 2**32)
+
+ r = [
+ f"RSAPublicKey {name}_rsa_key = {{",
+ f" .len = 0x20,",
+ f" .n0inv = {n0inv}U,",
+ f" .n = {to_c_uint32(rsa.n)},",
+ f" .rr = {to_c_uint32(rr)},",
+ f" .exponent = {rsa.e},",
+ f"}};",
+ ]
+ return r
+
+def objcopy(source, target, env, for_signature):
+ return '$OBJCOPY -O binary %s %s' % (source[0], target[0])
+
+# Common autogenerated includes
+git_ver = get_version(BUILDER, BUILD_TYPE)
+with open("obj/gitversion.h", "w") as f:
+ f.write(f'const uint8_t gitversion[8] = "{git_ver}";\n')
+print(f"Git commit hash for gitversion.h: {git_ver}")
+
+certs = [get_key_header(n) for n in ["debug", "release"]]
+with open("obj/cert.h", "w") as f:
+ for cert in certs:
+ f.write("\n".join(cert) + "\n")
+
+for project_name in build_projects:
+ project = build_projects[project_name]
+ linkerscript_fn = File(project["LINKER_SCRIPT"]).srcnode().abspath
+
+ flags = [
+ "-Wall",
+ "-Wextra",
+ "-Wstrict-prototypes",
+ "-Werror",
+ "-mlittle-endian",
+ "-mthumb",
+ "-nostdlib",
+ "-fno-builtin",
+ f"-T{linkerscript_fn}",
+ "-std=gnu11",
+ "-fdata-sections",
+ "-ffunction-sections",
+ "-Wl,--gc-sections",
+ ] + project["PROJECT_FLAGS"] + common_flags
+
+ project_env = Environment(
+ ENV=os.environ,
+ CC=PREFIX + 'gcc',
+ AS=PREFIX + 'gcc',
+ OBJCOPY=PREFIX + 'objcopy',
+ OBJDUMP=PREFIX + 'objdump',
+ ASCOM="$AS $ASFLAGS -o $TARGET -c $SOURCES",
+ CFLAGS=flags,
+ ASFLAGS=flags,
+ LINKFLAGS=flags,
+ LIBS = ['gcc',],
+ CPPPATH=includes,
+ BUILDERS={
+ 'Objcopy': Builder(generator=objcopy, suffix='.bin', src_suffix='.elf')
+ }
+ )
+ startup = project_env.Object(project["STARTUP_FILE"])
+
+ c_bstub_obj_list = []
+ for c in c_bstub_sources:
+ c_bstub_obj_list.append(project_env.Object(f"{c[0]}-{project_name}", c[1]))
+
+ # Bootstub
+ crypto_obj = [
+ project_env.Object(f"rsa-{project_name}", "../crypto/rsa.c"),
+ project_env.Object(f"sha-{project_name}", "../crypto/sha.c")
+ ]
+ bootstub_obj = project_env.Object(f"bootstub-{project_name}", "bootstub.c")
+ bootstub_elf = project_env.Program(f"obj/bootstub.{project_name}.elf", [startup] + crypto_obj + c_bstub_obj_list + [bootstub_obj])
+ bootstub_bin = project_env.Objcopy(f"obj/bootstub.{project_name}.bin", bootstub_elf)
+
+ c_obj_list = []
+ for c in c_sources:
+ c_obj_list.append(project_env.Object(f"{c[0]}-{project_name}", c[1]))
+
+ # Build main
+ main_obj = project_env.Object(f"main-{project_name}", project["MAIN"])
+ obj_list = [startup, main_obj] + c_obj_list
+ main_elf = project_env.Program(f"obj/{project_name}.elf", obj_list,
+ LINKFLAGS=[f"-Wl,--section-start,.isr_vector={project['APP_START_ADDRESS']}"] + flags)
+ main_bin = project_env.Objcopy(f"obj/{project_name}.bin", main_elf)
+
+ # Sign main
+ sign_py = File("../crypto/sign.py").srcnode().abspath
+ panda_bin_signed = project_env.Command(f"obj/{project_name}.bin.signed", main_bin, f"SETLEN=1 {sign_py} $SOURCE $TARGET {cert_fn}")
diff --git a/body/board/bldc/BLDC_controller.c b/body/board/bldc/BLDC_controller.c
new file mode 100644
index 000000000..ae63bd405
--- /dev/null
+++ b/body/board/bldc/BLDC_controller.c
@@ -0,0 +1,3376 @@
+/*
+ * File: BLDC_controller.c
+ *
+ * Code generated for Simulink model 'BLDC_controller'.
+ *
+ * Model version : 1.1297
+ * Simulink Coder version : 8.13 (R2017b) 24-Jul-2017
+ * C/C++ source code generated on : Sun Mar 6 11:02:11 2022
+ *
+ * Target selection: ert.tlc
+ * Embedded hardware selection: ARM Compatible->ARM Cortex
+ * Emulation hardware selection:
+ * Differs from embedded hardware (MATLAB Host)
+ * Code generation objectives:
+ * 1. Execution efficiency
+ * 2. RAM efficiency
+ * Validation result: Not run
+ */
+
+#include "BLDC_controller.h"
+
+/* Named constants for Chart: '/F03_02_Control_Mode_Manager' */
+#define IN_ACTIVE ((uint8_T)1U)
+#define IN_NO_ACTIVE_CHILD ((uint8_T)0U)
+#define IN_OPEN ((uint8_T)2U)
+#define IN_SPEED_MODE ((uint8_T)1U)
+#define IN_TORQUE_MODE ((uint8_T)2U)
+#define IN_VOLTAGE_MODE ((uint8_T)3U)
+#define OPEN_MODE ((uint8_T)0U)
+#define SPD_MODE ((uint8_T)2U)
+#define TRQ_MODE ((uint8_T)3U)
+#define VLT_MODE ((uint8_T)1U)
+#ifndef UCHAR_MAX
+#include
+#endif
+
+#if ( UCHAR_MAX != (0xFFU) ) || ( SCHAR_MAX != (0x7F) )
+#error Code was generated for compiler with different sized uchar/char. \
+Consider adjusting Test hardware word size settings on the \
+Hardware Implementation pane to match your compiler word sizes as \
+defined in limits.h of the compiler. Alternatively, you can \
+select the Test hardware is the same as production hardware option and \
+select the Enable portable word sizes option on the Code Generation > \
+Verification pane for ERT based targets, which will disable the \
+preprocessor word size checks.
+#endif
+
+#if ( USHRT_MAX != (0xFFFFU) ) || ( SHRT_MAX != (0x7FFF) )
+#error Code was generated for compiler with different sized ushort/short. \
+Consider adjusting Test hardware word size settings on the \
+Hardware Implementation pane to match your compiler word sizes as \
+defined in limits.h of the compiler. Alternatively, you can \
+select the Test hardware is the same as production hardware option and \
+select the Enable portable word sizes option on the Code Generation > \
+Verification pane for ERT based targets, which will disable the \
+preprocessor word size checks.
+#endif
+
+#if ( UINT_MAX != (0xFFFFFFFFU) ) || ( INT_MAX != (0x7FFFFFFF) )
+#error Code was generated for compiler with different sized uint/int. \
+Consider adjusting Test hardware word size settings on the \
+Hardware Implementation pane to match your compiler word sizes as \
+defined in limits.h of the compiler. Alternatively, you can \
+select the Test hardware is the same as production hardware option and \
+select the Enable portable word sizes option on the Code Generation > \
+Verification pane for ERT based targets, which will disable the \
+preprocessor word size checks.
+#endif
+
+#if ( ULONG_MAX != (0xFFFFFFFFU) ) || ( LONG_MAX != (0x7FFFFFFF) )
+#error Code was generated for compiler with different sized ulong/long. \
+Consider adjusting Test hardware word size settings on the \
+Hardware Implementation pane to match your compiler word sizes as \
+defined in limits.h of the compiler. Alternatively, you can \
+select the Test hardware is the same as production hardware option and \
+select the Enable portable word sizes option on the Code Generation > \
+Verification pane for ERT based targets, which will disable the \
+preprocessor word size checks.
+#endif
+
+#if 0
+
+/* Skip this size verification because of preprocessor limitation */
+#if ( ULLONG_MAX != (0xFFFFFFFFFFFFFFFFULL) ) || ( LLONG_MAX != (0x7FFFFFFFFFFFFFFFLL) )
+#error Code was generated for compiler with different sized ulong_long/long_long. \
+Consider adjusting Test hardware word size settings on the \
+Hardware Implementation pane to match your compiler word sizes as \
+defined in limits.h of the compiler. Alternatively, you can \
+select the Test hardware is the same as production hardware option and \
+select the Enable portable word sizes option on the Code Generation > \
+Verification pane for ERT based targets, which will disable the \
+preprocessor word size checks.
+#endif
+#endif
+
+uint8_T plook_u8s16_evencka(int16_T u, int16_T bp0, uint16_T bpSpace, uint32_T
+ maxIndex);
+uint8_T plook_u8u16_evencka(uint16_T u, uint16_T bp0, uint16_T bpSpace, uint32_T
+ maxIndex);
+int32_T div_nde_s32_floor(int32_T numerator, int32_T denominator);
+extern void Counter_Init(DW_Counter *localDW, int16_T rtp_z_cntInit);
+extern int16_T Counter(int16_T rtu_inc, int16_T rtu_max, boolean_T rtu_rst,
+ DW_Counter *localDW);
+extern void Low_Pass_Filter_Reset(DW_Low_Pass_Filter *localDW);
+extern void Low_Pass_Filter(const int16_T rtu_u[2], uint16_T rtu_coef, int16_T
+ rty_y[2], DW_Low_Pass_Filter *localDW);
+extern void Counter_b_Init(DW_Counter_b *localDW, uint16_T rtp_z_cntInit);
+extern void Counter_n(uint16_T rtu_inc, uint16_T rtu_max, boolean_T rtu_rst,
+ uint16_T *rty_cnt, DW_Counter_b *localDW);
+extern void either_edge(boolean_T rtu_u, boolean_T *rty_y, DW_either_edge
+ *localDW);
+extern void Debounce_Filter_Init(DW_Debounce_Filter *localDW);
+extern void Debounce_Filter(boolean_T rtu_u, uint16_T rtu_tAcv, uint16_T
+ rtu_tDeacv, boolean_T *rty_y, DW_Debounce_Filter *localDW);
+extern void I_backCalc_fixdt_Init(DW_I_backCalc_fixdt *localDW, int32_T
+ rtp_yInit);
+extern void I_backCalc_fixdt_Reset(DW_I_backCalc_fixdt *localDW, int32_T
+ rtp_yInit);
+extern void I_backCalc_fixdt(int16_T rtu_err, uint16_T rtu_I, uint16_T rtu_Kb,
+ int16_T rtu_satMax, int16_T rtu_satMin, int16_T *rty_out, DW_I_backCalc_fixdt *
+ localDW);
+extern void PI_clamp_fixdt_Init(DW_PI_clamp_fixdt *localDW);
+extern void PI_clamp_fixdt_Reset(DW_PI_clamp_fixdt *localDW);
+extern void PI_clamp_fixdt(int16_T rtu_err, uint16_T rtu_P, uint16_T rtu_I,
+ int32_T rtu_init, int16_T rtu_satMax, int16_T rtu_satMin, int32_T
+ rtu_ext_limProt, int16_T *rty_out, DW_PI_clamp_fixdt *localDW);
+extern void PI_clamp_fixdt_d_Init(DW_PI_clamp_fixdt_m *localDW);
+extern void PI_clamp_fixdt_b_Reset(DW_PI_clamp_fixdt_m *localDW);
+extern void PI_clamp_fixdt_l(int16_T rtu_err, uint16_T rtu_P, uint16_T rtu_I,
+ int16_T rtu_init, int16_T rtu_satMax, int16_T rtu_satMin, int32_T
+ rtu_ext_limProt, int16_T *rty_out, DW_PI_clamp_fixdt_m *localDW);
+extern void PI_clamp_fixdt_f_Init(DW_PI_clamp_fixdt_g *localDW);
+extern void PI_clamp_fixdt_g_Reset(DW_PI_clamp_fixdt_g *localDW);
+extern void PI_clamp_fixdt_k(int16_T rtu_err, uint16_T rtu_P, uint16_T rtu_I,
+ int16_T rtu_init, int16_T rtu_satMax, int16_T rtu_satMin, int32_T
+ rtu_ext_limProt, int16_T *rty_out, DW_PI_clamp_fixdt_g *localDW);
+uint8_T plook_u8s16_evencka(int16_T u, int16_T bp0, uint16_T bpSpace, uint32_T
+ maxIndex)
+{
+ uint8_T bpIndex;
+ uint16_T fbpIndex;
+
+ /* Prelookup - Index only
+ Index Search method: 'even'
+ Extrapolation method: 'Clip'
+ Use previous index: 'off'
+ Use last breakpoint for index at or above upper limit: 'on'
+ Remove protection against out-of-range input in generated code: 'off'
+ */
+ if (u <= bp0) {
+ bpIndex = 0U;
+ } else {
+ fbpIndex = (uint16_T)((uint32_T)(uint16_T)(u - bp0) / bpSpace);
+ if (fbpIndex < maxIndex) {
+ bpIndex = (uint8_T)fbpIndex;
+ } else {
+ bpIndex = (uint8_T)maxIndex;
+ }
+ }
+
+ return bpIndex;
+}
+
+uint8_T plook_u8u16_evencka(uint16_T u, uint16_T bp0, uint16_T bpSpace, uint32_T
+ maxIndex)
+{
+ uint8_T bpIndex;
+ uint16_T fbpIndex;
+
+ /* Prelookup - Index only
+ Index Search method: 'even'
+ Extrapolation method: 'Clip'
+ Use previous index: 'off'
+ Use last breakpoint for index at or above upper limit: 'on'
+ Remove protection against out-of-range input in generated code: 'off'
+ */
+ if (u <= bp0) {
+ bpIndex = 0U;
+ } else {
+ fbpIndex = (uint16_T)((uint32_T)(uint16_T)((uint32_T)u - bp0) / bpSpace);
+ if (fbpIndex < maxIndex) {
+ bpIndex = (uint8_T)fbpIndex;
+ } else {
+ bpIndex = (uint8_T)maxIndex;
+ }
+ }
+
+ return bpIndex;
+}
+
+int32_T div_nde_s32_floor(int32_T numerator, int32_T denominator)
+{
+ return (((numerator < 0) != (denominator < 0)) && (numerator % denominator !=
+ 0) ? -1 : 0) + numerator / denominator;
+}
+
+/* System initialize for atomic system: '/Counter' */
+void Counter_Init(DW_Counter *localDW, int16_T rtp_z_cntInit)
+{
+ /* InitializeConditions for UnitDelay: '/UnitDelay' */
+ localDW->UnitDelay_DSTATE = rtp_z_cntInit;
+}
+
+/* Output and update for atomic system: '/Counter' */
+int16_T Counter(int16_T rtu_inc, int16_T rtu_max, boolean_T rtu_rst, DW_Counter *
+ localDW)
+{
+ int16_T rtu_rst_0;
+ int16_T rty_cnt_0;
+
+ /* Switch: '/Switch1' incorporates:
+ * Constant: '/Constant23'
+ * UnitDelay: '/UnitDelay'
+ */
+ if (rtu_rst) {
+ rtu_rst_0 = 0;
+ } else {
+ rtu_rst_0 = localDW->UnitDelay_DSTATE;
+ }
+
+ /* End of Switch: '/Switch1' */
+
+ /* Sum: '/Sum1' */
+ rty_cnt_0 = (int16_T)(rtu_inc + rtu_rst_0);
+
+ /* MinMax: '/MinMax' */
+ if (rty_cnt_0 < rtu_max) {
+ /* Update for UnitDelay: '/UnitDelay' */
+ localDW->UnitDelay_DSTATE = rty_cnt_0;
+ } else {
+ /* Update for UnitDelay: '/UnitDelay' */
+ localDW->UnitDelay_DSTATE = rtu_max;
+ }
+
+ /* End of MinMax: '/MinMax' */
+ return rty_cnt_0;
+}
+
+/* System reset for atomic system: '/Low_Pass_Filter' */
+void Low_Pass_Filter_Reset(DW_Low_Pass_Filter *localDW)
+{
+ /* InitializeConditions for UnitDelay: '/UnitDelay1' */
+ localDW->UnitDelay1_DSTATE[0] = 0;
+ localDW->UnitDelay1_DSTATE[1] = 0;
+}
+
+/* Output and update for atomic system: '/Low_Pass_Filter' */
+void Low_Pass_Filter(const int16_T rtu_u[2], uint16_T rtu_coef, int16_T rty_y[2],
+ DW_Low_Pass_Filter *localDW)
+{
+ int32_T rtb_Sum3_g;
+
+ /* Sum: '/Sum2' incorporates:
+ * UnitDelay: '/UnitDelay1'
+ */
+ rtb_Sum3_g = rtu_u[0] - (localDW->UnitDelay1_DSTATE[0] >> 16);
+ if (rtb_Sum3_g > 32767) {
+ rtb_Sum3_g = 32767;
+ } else {
+ if (rtb_Sum3_g < -32768) {
+ rtb_Sum3_g = -32768;
+ }
+ }
+
+ /* Sum: '/Sum3' incorporates:
+ * Product: '/Divide3'
+ * Sum: '/Sum2'
+ * UnitDelay: '/UnitDelay1'
+ */
+ rtb_Sum3_g = rtu_coef * rtb_Sum3_g + localDW->UnitDelay1_DSTATE[0];
+
+ /* DataTypeConversion: '/Data Type Conversion' */
+ rty_y[0] = (int16_T)(rtb_Sum3_g >> 16);
+
+ /* Update for UnitDelay: '/UnitDelay1' */
+ localDW->UnitDelay1_DSTATE[0] = rtb_Sum3_g;
+
+ /* Sum: '/Sum2' incorporates:
+ * UnitDelay: '/UnitDelay1'
+ */
+ rtb_Sum3_g = rtu_u[1] - (localDW->UnitDelay1_DSTATE[1] >> 16);
+ if (rtb_Sum3_g > 32767) {
+ rtb_Sum3_g = 32767;
+ } else {
+ if (rtb_Sum3_g < -32768) {
+ rtb_Sum3_g = -32768;
+ }
+ }
+
+ /* Sum: '/Sum3' incorporates:
+ * Product: '/Divide3'
+ * Sum: '/Sum2'
+ * UnitDelay: '/UnitDelay1'
+ */
+ rtb_Sum3_g = rtu_coef * rtb_Sum3_g + localDW->UnitDelay1_DSTATE[1];
+
+ /* DataTypeConversion: '/Data Type Conversion' */
+ rty_y[1] = (int16_T)(rtb_Sum3_g >> 16);
+
+ /* Update for UnitDelay: '/UnitDelay1' */
+ localDW->UnitDelay1_DSTATE[1] = rtb_Sum3_g;
+}
+
+/*
+ * System initialize for atomic system:
+ * '/Counter'
+ * '/Counter'
+ */
+void Counter_b_Init(DW_Counter_b *localDW, uint16_T rtp_z_cntInit)
+{
+ /* InitializeConditions for UnitDelay: '/UnitDelay' */
+ localDW->UnitDelay_DSTATE = rtp_z_cntInit;
+}
+
+/*
+ * Output and update for atomic system:
+ * '/Counter'
+ * '/Counter'
+ */
+void Counter_n(uint16_T rtu_inc, uint16_T rtu_max, boolean_T rtu_rst, uint16_T
+ *rty_cnt, DW_Counter_b *localDW)
+{
+ uint16_T rtu_rst_0;
+
+ /* Switch: '/Switch1' incorporates:
+ * Constant: '/Constant23'
+ * UnitDelay: '/UnitDelay'
+ */
+ if (rtu_rst) {
+ rtu_rst_0 = 0U;
+ } else {
+ rtu_rst_0 = localDW->UnitDelay_DSTATE;
+ }
+
+ /* End of Switch: '/Switch1' */
+
+ /* Sum: '/Sum1' */
+ *rty_cnt = (uint16_T)((uint32_T)rtu_inc + rtu_rst_0);
+
+ /* MinMax: '/MinMax' */
+ if (*rty_cnt < rtu_max) {
+ /* Update for UnitDelay: '/UnitDelay' */
+ localDW->UnitDelay_DSTATE = *rty_cnt;
+ } else {
+ /* Update for UnitDelay: '/UnitDelay' */
+ localDW->UnitDelay_DSTATE = rtu_max;
+ }
+
+ /* End of MinMax: '/MinMax' */
+}
+
+/*
+ * Output and update for atomic system:
+ * '/either_edge'
+ * '/either_edge'
+ */
+void either_edge(boolean_T rtu_u, boolean_T *rty_y, DW_either_edge *localDW)
+{
+ /* RelationalOperator: '/Relational Operator' incorporates:
+ * UnitDelay: '/UnitDelay'
+ */
+ *rty_y = (rtu_u != localDW->UnitDelay_DSTATE);
+
+ /* Update for UnitDelay: '/UnitDelay' */
+ localDW->UnitDelay_DSTATE = rtu_u;
+}
+
+/* System initialize for atomic system: '/Debounce_Filter' */
+void Debounce_Filter_Init(DW_Debounce_Filter *localDW)
+{
+ /* SystemInitialize for IfAction SubSystem: '/Qualification' */
+
+ /* SystemInitialize for Atomic SubSystem: '/Counter' */
+ Counter_b_Init(&localDW->Counter_n1, 0U);
+
+ /* End of SystemInitialize for SubSystem: '/Counter' */
+
+ /* End of SystemInitialize for SubSystem: '/Qualification' */
+
+ /* SystemInitialize for IfAction SubSystem: '/Dequalification' */
+
+ /* SystemInitialize for Atomic SubSystem: '/Counter' */
+ Counter_b_Init(&localDW->Counter_e, 0U);
+
+ /* End of SystemInitialize for SubSystem: '/Counter' */
+
+ /* End of SystemInitialize for SubSystem: '/Dequalification' */
+}
+
+/* Output and update for atomic system: '/Debounce_Filter' */
+void Debounce_Filter(boolean_T rtu_u, uint16_T rtu_tAcv, uint16_T rtu_tDeacv,
+ boolean_T *rty_y, DW_Debounce_Filter *localDW)
+{
+ uint16_T rtb_Sum1_n;
+ boolean_T rtb_RelationalOperator_g;
+
+ /* Outputs for Atomic SubSystem: '/either_edge' */
+ either_edge(rtu_u, &rtb_RelationalOperator_g, &localDW->either_edge_p);
+
+ /* End of Outputs for SubSystem: '/either_edge' */
+
+ /* If: '/If2' incorporates:
+ * Constant: '/Constant6'
+ * Constant: '/Constant6'
+ * Inport: '/yPrev'
+ * Logic: '/Logical Operator1'
+ * Logic: '/Logical Operator2'
+ * Logic: '/Logical Operator3'
+ * Logic: '/Logical Operator4'
+ * UnitDelay: '/UnitDelay'
+ */
+ if (rtu_u && (!localDW->UnitDelay_DSTATE)) {
+ /* Outputs for IfAction SubSystem: '/Qualification' incorporates:
+ * ActionPort: '/Action Port'
+ */
+
+ /* Outputs for Atomic SubSystem: '/Counter' */
+ Counter_n(1U, rtu_tAcv, rtb_RelationalOperator_g, &rtb_Sum1_n,
+ &localDW->Counter_n1);
+
+ /* End of Outputs for SubSystem: '/Counter' */
+
+ /* Switch: '/Switch2' incorporates:
+ * Constant: '/Constant6'
+ * RelationalOperator: '/Relational Operator2'
+ */
+ *rty_y = ((rtb_Sum1_n > rtu_tAcv) || localDW->UnitDelay_DSTATE);
+
+ /* End of Outputs for SubSystem: '/Qualification' */
+ } else if ((!rtu_u) && localDW->UnitDelay_DSTATE) {
+ /* Outputs for IfAction SubSystem: '/Dequalification' incorporates:
+ * ActionPort: '/Action Port'
+ */
+
+ /* Outputs for Atomic SubSystem: '/Counter' */
+ Counter_n(1U, rtu_tDeacv, rtb_RelationalOperator_g, &rtb_Sum1_n,
+ &localDW->Counter_e);
+
+ /* End of Outputs for SubSystem: '/Counter' */
+
+ /* Switch: '/Switch2' incorporates:
+ * Constant: '/Constant6'
+ * RelationalOperator: '/Relational Operator2'
+ */
+ *rty_y = ((!(rtb_Sum1_n > rtu_tDeacv)) && localDW->UnitDelay_DSTATE);
+
+ /* End of Outputs for SubSystem: '/Dequalification' */
+ } else {
+ /* Outputs for IfAction SubSystem: '/Default' incorporates:
+ * ActionPort: '/Action Port'
+ */
+ *rty_y = localDW->UnitDelay_DSTATE;
+
+ /* End of Outputs for SubSystem: '/Default' */
+ }
+
+ /* End of If: '/If2' */
+
+ /* Update for UnitDelay: '/UnitDelay' */
+ localDW->UnitDelay_DSTATE = *rty_y;
+}
+
+/*
+ * System initialize for atomic system:
+ * '/I_backCalc_fixdt'
+ * '/I_backCalc_fixdt1'
+ * '/I_backCalc_fixdt'
+ */
+void I_backCalc_fixdt_Init(DW_I_backCalc_fixdt *localDW, int32_T rtp_yInit)
+{
+ /* InitializeConditions for UnitDelay: '/UnitDelay' */
+ localDW->UnitDelay_DSTATE_m = rtp_yInit;
+}
+
+/*
+ * System reset for atomic system:
+ * '/I_backCalc_fixdt'
+ * '/I_backCalc_fixdt1'
+ * '/I_backCalc_fixdt'
+ */
+void I_backCalc_fixdt_Reset(DW_I_backCalc_fixdt *localDW, int32_T rtp_yInit)
+{
+ /* InitializeConditions for UnitDelay: '/UnitDelay' */
+ localDW->UnitDelay_DSTATE = 0;
+
+ /* InitializeConditions for UnitDelay: '/UnitDelay' */
+ localDW->UnitDelay_DSTATE_m = rtp_yInit;
+}
+
+/*
+ * Output and update for atomic system:
+ * '/I_backCalc_fixdt'
+ * '/I_backCalc_fixdt1'
+ * '/I_backCalc_fixdt'
+ */
+void I_backCalc_fixdt(int16_T rtu_err, uint16_T rtu_I, uint16_T rtu_Kb, int16_T
+ rtu_satMax, int16_T rtu_satMin, int16_T *rty_out,
+ DW_I_backCalc_fixdt *localDW)
+{
+ int32_T rtb_Sum1_o;
+ int16_T rtb_DataTypeConversion1_gf;
+
+ /* Sum: '/Sum2' incorporates:
+ * Product: '/Divide2'
+ * UnitDelay: '/UnitDelay'
+ */
+ rtb_Sum1_o = (rtu_err * rtu_I) >> 4;
+ if ((rtb_Sum1_o < 0) && (localDW->UnitDelay_DSTATE < MIN_int32_T - rtb_Sum1_o))
+ {
+ rtb_Sum1_o = MIN_int32_T;
+ } else if ((rtb_Sum1_o > 0) && (localDW->UnitDelay_DSTATE > MAX_int32_T
+ - rtb_Sum1_o)) {
+ rtb_Sum1_o = MAX_int32_T;
+ } else {
+ rtb_Sum1_o += localDW->UnitDelay_DSTATE;
+ }
+
+ /* End of Sum: '/Sum2' */
+
+ /* Sum: '/Sum1' incorporates:
+ * UnitDelay: '/UnitDelay'
+ */
+ rtb_Sum1_o += localDW->UnitDelay_DSTATE_m;
+
+ /* DataTypeConversion: '/Data Type Conversion1' */
+ rtb_DataTypeConversion1_gf = (int16_T)(rtb_Sum1_o >> 12);
+
+ /* Switch: '/Switch2' incorporates:
+ * RelationalOperator: '/LowerRelop1'
+ * RelationalOperator: '/UpperRelop'
+ * Switch: '/Switch'
+ */
+ if (rtb_DataTypeConversion1_gf > rtu_satMax) {
+ *rty_out = rtu_satMax;
+ } else if (rtb_DataTypeConversion1_gf < rtu_satMin) {
+ /* Switch: '/Switch' */
+ *rty_out = rtu_satMin;
+ } else {
+ *rty_out = rtb_DataTypeConversion1_gf;
+ }
+
+ /* End of Switch: '/Switch2' */
+
+ /* Update for UnitDelay: '/UnitDelay' incorporates:
+ * Product: '/Divide1'
+ * Sum: '/Sum3'
+ */
+ localDW->UnitDelay_DSTATE = (int16_T)(*rty_out - rtb_DataTypeConversion1_gf) *
+ rtu_Kb;
+
+ /* Update for UnitDelay: '/UnitDelay' */
+ localDW->UnitDelay_DSTATE_m = rtb_Sum1_o;
+}
+
+/* System initialize for atomic system: '/PI_clamp_fixdt' */
+void PI_clamp_fixdt_Init(DW_PI_clamp_fixdt *localDW)
+{
+ /* InitializeConditions for Delay: '/Resettable Delay' */
+ localDW->icLoad = 1U;
+}
+
+/* System reset for atomic system: '/PI_clamp_fixdt' */
+void PI_clamp_fixdt_Reset(DW_PI_clamp_fixdt *localDW)
+{
+ /* InitializeConditions for UnitDelay: '/UnitDelay1' */
+ localDW->UnitDelay1_DSTATE = false;
+
+ /* InitializeConditions for Delay: '/Resettable Delay' */
+ localDW->icLoad = 1U;
+}
+
+/* Output and update for atomic system: '/PI_clamp_fixdt' */
+void PI_clamp_fixdt(int16_T rtu_err, uint16_T rtu_P, uint16_T rtu_I, int32_T
+ rtu_init, int16_T rtu_satMax, int16_T rtu_satMin, int32_T
+ rtu_ext_limProt, int16_T *rty_out, DW_PI_clamp_fixdt
+ *localDW)
+{
+ boolean_T rtb_LowerRelop1_c0;
+ boolean_T rtb_UpperRelop_f;
+ int32_T rtb_Sum1_p0;
+ int32_T q0;
+ int32_T tmp;
+ int16_T tmp_0;
+
+ /* Sum: '/Sum2' incorporates:
+ * Product: '/Divide2'
+ */
+ q0 = rtu_err * rtu_I;
+ if ((q0 < 0) && (rtu_ext_limProt < MIN_int32_T - q0)) {
+ q0 = MIN_int32_T;
+ } else if ((q0 > 0) && (rtu_ext_limProt > MAX_int32_T - q0)) {
+ q0 = MAX_int32_T;
+ } else {
+ q0 += rtu_ext_limProt;
+ }
+
+ /* Delay: '/Resettable Delay' */
+ if (localDW->icLoad != 0) {
+ localDW->ResettableDelay_DSTATE = rtu_init;
+ }
+
+ /* Switch: '/Switch1' incorporates:
+ * Constant: '/Constant'
+ * Sum: '/Sum2'
+ * UnitDelay: '/UnitDelay1'
+ */
+ if (localDW->UnitDelay1_DSTATE) {
+ tmp = 0;
+ } else {
+ tmp = q0;
+ }
+
+ /* End of Switch: '/Switch1' */
+
+ /* Sum: '/Sum1' incorporates:
+ * Delay: '/Resettable Delay'
+ */
+ rtb_Sum1_p0 = tmp + localDW->ResettableDelay_DSTATE;
+
+ /* Product: '/Divide5' */
+ tmp = (rtu_err * rtu_P) >> 11;
+ if (tmp > 32767) {
+ tmp = 32767;
+ } else {
+ if (tmp < -32768) {
+ tmp = -32768;
+ }
+ }
+
+ /* Sum: '/Sum1' incorporates:
+ * DataTypeConversion: '/Data Type Conversion1'
+ * Product: '/Divide5'
+ */
+ tmp = (((rtb_Sum1_p0 >> 16) << 1) + tmp) >> 1;
+ if (tmp > 32767) {
+ tmp = 32767;
+ } else {
+ if (tmp < -32768) {
+ tmp = -32768;
+ }
+ }
+
+ /* RelationalOperator: '/LowerRelop1' incorporates:
+ * Sum: '/Sum1'
+ */
+ rtb_LowerRelop1_c0 = ((int16_T)tmp > rtu_satMax);
+
+ /* RelationalOperator: '/UpperRelop' incorporates:
+ * Sum: '/Sum1'
+ */
+ rtb_UpperRelop_f = ((int16_T)tmp < rtu_satMin);
+
+ /* Switch: '/Switch1' incorporates:
+ * Sum: '/Sum1'
+ * Switch: '/Switch3'
+ */
+ if (rtb_LowerRelop1_c0) {
+ *rty_out = rtu_satMax;
+ } else if (rtb_UpperRelop_f) {
+ /* Switch: '/Switch3' */
+ *rty_out = rtu_satMin;
+ } else {
+ *rty_out = (int16_T)tmp;
+ }
+
+ /* End of Switch: '/Switch1' */
+
+ /* Signum: '/SignDeltaU2' incorporates:
+ * Sum: '/Sum2'
+ */
+ if (q0 < 0) {
+ q0 = -1;
+ } else {
+ q0 = (q0 > 0);
+ }
+
+ /* End of Signum: '/SignDeltaU2' */
+
+ /* Signum: '/SignDeltaU3' incorporates:
+ * Sum: '/Sum1'
+ */
+ if ((int16_T)tmp < 0) {
+ tmp_0 = -1;
+ } else {
+ tmp_0 = (int16_T)((int16_T)tmp > 0);
+ }
+
+ /* End of Signum: '/SignDeltaU3' */
+
+ /* Update for UnitDelay: '/UnitDelay1' incorporates:
+ * DataTypeConversion: '/DataTypeConv4'
+ * Logic: '/AND1'
+ * Logic: '/AND1'
+ * RelationalOperator: '/Equal1'
+ */
+ localDW->UnitDelay1_DSTATE = ((q0 == tmp_0) && (rtb_LowerRelop1_c0 ||
+ rtb_UpperRelop_f));
+
+ /* Update for Delay: '/Resettable Delay' */
+ localDW->icLoad = 0U;
+ localDW->ResettableDelay_DSTATE = rtb_Sum1_p0;
+}
+
+/* System initialize for atomic system: '/PI_clamp_fixdt' */
+void PI_clamp_fixdt_d_Init(DW_PI_clamp_fixdt_m *localDW)
+{
+ /* InitializeConditions for Delay: '/Resettable Delay' */
+ localDW->icLoad = 1U;
+}
+
+/* System reset for atomic system: '/PI_clamp_fixdt' */
+void PI_clamp_fixdt_b_Reset(DW_PI_clamp_fixdt_m *localDW)
+{
+ /* InitializeConditions for UnitDelay: '/UnitDelay1' */
+ localDW->UnitDelay1_DSTATE = false;
+
+ /* InitializeConditions for Delay: '/Resettable Delay' */
+ localDW->icLoad = 1U;
+}
+
+/* Output and update for atomic system: '/PI_clamp_fixdt' */
+void PI_clamp_fixdt_l(int16_T rtu_err, uint16_T rtu_P, uint16_T rtu_I, int16_T
+ rtu_init, int16_T rtu_satMax, int16_T rtu_satMin, int32_T
+ rtu_ext_limProt, int16_T *rty_out, DW_PI_clamp_fixdt_m
+ *localDW)
+{
+ boolean_T rtb_LowerRelop1_l;
+ boolean_T rtb_UpperRelop_l;
+ int32_T rtb_Sum1_ni;
+ int32_T q0;
+ int32_T tmp;
+ int16_T tmp_0;
+
+ /* Sum: '/Sum2' incorporates:
+ * Product: '/Divide2'
+ */
+ q0 = rtu_err * rtu_I;
+ if ((q0 < 0) && (rtu_ext_limProt < MIN_int32_T - q0)) {
+ q0 = MIN_int32_T;
+ } else if ((q0 > 0) && (rtu_ext_limProt > MAX_int32_T - q0)) {
+ q0 = MAX_int32_T;
+ } else {
+ q0 += rtu_ext_limProt;
+ }
+
+ /* Delay: '/Resettable Delay' */
+ if (localDW->icLoad != 0) {
+ localDW->ResettableDelay_DSTATE = rtu_init << 16;
+ }
+
+ /* Switch: '/Switch1' incorporates:
+ * Constant: '/Constant'
+ * Sum: '/Sum2'
+ * UnitDelay: '/UnitDelay1'
+ */
+ if (localDW->UnitDelay1_DSTATE) {
+ tmp = 0;
+ } else {
+ tmp = q0;
+ }
+
+ /* End of Switch: '/Switch1' */
+
+ /* Sum: '/Sum1' incorporates:
+ * Delay: '/Resettable Delay'
+ */
+ rtb_Sum1_ni = tmp + localDW->ResettableDelay_DSTATE;
+
+ /* Product: '/Divide5' */
+ tmp = (rtu_err * rtu_P) >> 11;
+ if (tmp > 32767) {
+ tmp = 32767;
+ } else {
+ if (tmp < -32768) {
+ tmp = -32768;
+ }
+ }
+
+ /* Sum: '/Sum1' incorporates:
+ * DataTypeConversion: '/Data Type Conversion1'
+ * Product: '/Divide5'
+ */
+ tmp = (((rtb_Sum1_ni >> 16) << 1) + tmp) >> 1;
+ if (tmp > 32767) {
+ tmp = 32767;
+ } else {
+ if (tmp < -32768) {
+ tmp = -32768;
+ }
+ }
+
+ /* RelationalOperator: '/LowerRelop1' incorporates:
+ * Sum: '/Sum1'
+ */
+ rtb_LowerRelop1_l = ((int16_T)tmp > rtu_satMax);
+
+ /* RelationalOperator: '/UpperRelop' incorporates:
+ * Sum: '/Sum1'
+ */
+ rtb_UpperRelop_l = ((int16_T)tmp < rtu_satMin);
+
+ /* Switch: '/Switch1' incorporates:
+ * Sum: '/Sum1'
+ * Switch: '/Switch3'
+ */
+ if (rtb_LowerRelop1_l) {
+ *rty_out = rtu_satMax;
+ } else if (rtb_UpperRelop_l) {
+ /* Switch: '/Switch3' */
+ *rty_out = rtu_satMin;
+ } else {
+ *rty_out = (int16_T)tmp;
+ }
+
+ /* End of Switch: '/Switch1' */
+
+ /* Signum: '/SignDeltaU2' incorporates:
+ * Sum: '/Sum2'
+ */
+ if (q0 < 0) {
+ q0 = -1;
+ } else {
+ q0 = (q0 > 0);
+ }
+
+ /* End of Signum: '/SignDeltaU2' */
+
+ /* Signum: '/SignDeltaU3' incorporates:
+ * Sum: '/Sum1'
+ */
+ if ((int16_T)tmp < 0) {
+ tmp_0 = -1;
+ } else {
+ tmp_0 = (int16_T)((int16_T)tmp > 0);
+ }
+
+ /* End of Signum: '/SignDeltaU3' */
+
+ /* Update for UnitDelay: '/UnitDelay1' incorporates:
+ * DataTypeConversion: '/DataTypeConv4'
+ * Logic: '/AND1'
+ * Logic: '/AND1'
+ * RelationalOperator: '/Equal1'
+ */
+ localDW->UnitDelay1_DSTATE = ((q0 == tmp_0) && (rtb_LowerRelop1_l ||
+ rtb_UpperRelop_l));
+
+ /* Update for Delay: '/Resettable Delay' */
+ localDW->icLoad = 0U;
+ localDW->ResettableDelay_DSTATE = rtb_Sum1_ni;
+}
+
+/* System initialize for atomic system: '/PI_clamp_fixdt' */
+void PI_clamp_fixdt_f_Init(DW_PI_clamp_fixdt_g *localDW)
+{
+ /* InitializeConditions for Delay: '/Resettable Delay' */
+ localDW->icLoad = 1U;
+}
+
+/* System reset for atomic system: '/PI_clamp_fixdt' */
+void PI_clamp_fixdt_g_Reset(DW_PI_clamp_fixdt_g *localDW)
+{
+ /* InitializeConditions for UnitDelay: '/UnitDelay1' */
+ localDW->UnitDelay1_DSTATE = false;
+
+ /* InitializeConditions for Delay: '/Resettable Delay' */
+ localDW->icLoad = 1U;
+}
+
+/* Output and update for atomic system: '/PI_clamp_fixdt' */
+void PI_clamp_fixdt_k(int16_T rtu_err, uint16_T rtu_P, uint16_T rtu_I, int16_T
+ rtu_init, int16_T rtu_satMax, int16_T rtu_satMin, int32_T
+ rtu_ext_limProt, int16_T *rty_out, DW_PI_clamp_fixdt_g
+ *localDW)
+{
+ boolean_T rtb_LowerRelop1_i3;
+ boolean_T rtb_UpperRelop_i;
+ int16_T rtb_Sum1_bm;
+ int16_T tmp;
+ int32_T tmp_0;
+ int32_T q0;
+
+ /* Sum: '/Sum2' incorporates:
+ * Product: '/Divide2'
+ */
+ q0 = rtu_err * rtu_I;
+ if ((q0 < 0) && (rtu_ext_limProt < MIN_int32_T - q0)) {
+ q0 = MIN_int32_T;
+ } else if ((q0 > 0) && (rtu_ext_limProt > MAX_int32_T - q0)) {
+ q0 = MAX_int32_T;
+ } else {
+ q0 += rtu_ext_limProt;
+ }
+
+ /* Delay: '/Resettable Delay' */
+ if (localDW->icLoad != 0) {
+ localDW->ResettableDelay_DSTATE = rtu_init;
+ }
+
+ /* Switch: '/Switch1' incorporates:
+ * Constant: '/Constant'
+ * Sum: '/Sum2'
+ * UnitDelay: '/UnitDelay1'
+ */
+ if (localDW->UnitDelay1_DSTATE) {
+ tmp = 0;
+ } else {
+ tmp = (int16_T)(((q0 < 0 ? 65535 : 0) + q0) >> 16);
+ }
+
+ /* End of Switch: '/Switch1' */
+
+ /* Sum: '/Sum1' incorporates:
+ * Delay: '/Resettable Delay'
+ */
+ rtb_Sum1_bm = (int16_T)(tmp + localDW->ResettableDelay_DSTATE);
+
+ /* Product: '/Divide5' */
+ tmp_0 = (rtu_err * rtu_P) >> 11;
+ if (tmp_0 > 32767) {
+ tmp_0 = 32767;
+ } else {
+ if (tmp_0 < -32768) {
+ tmp_0 = -32768;
+ }
+ }
+
+ /* Sum: '/Sum1' incorporates:
+ * Product: '/Divide5'
+ */
+ tmp_0 = ((rtb_Sum1_bm << 1) + tmp_0) >> 1;
+ if (tmp_0 > 32767) {
+ tmp_0 = 32767;
+ } else {
+ if (tmp_0 < -32768) {
+ tmp_0 = -32768;
+ }
+ }
+
+ /* RelationalOperator: '/LowerRelop1' incorporates:
+ * Sum: '/Sum1'
+ */
+ rtb_LowerRelop1_i3 = ((int16_T)tmp_0 > rtu_satMax);
+
+ /* RelationalOperator: '/UpperRelop' incorporates:
+ * Sum: '/Sum1'
+ */
+ rtb_UpperRelop_i = ((int16_T)tmp_0 < rtu_satMin);
+
+ /* Switch: '/Switch1' incorporates:
+ * Sum: '/Sum1'
+ * Switch: '/Switch3'
+ */
+ if (rtb_LowerRelop1_i3) {
+ *rty_out = rtu_satMax;
+ } else if (rtb_UpperRelop_i) {
+ /* Switch: '/Switch3' */
+ *rty_out = rtu_satMin;
+ } else {
+ *rty_out = (int16_T)tmp_0;
+ }
+
+ /* End of Switch: '/Switch1' */
+
+ /* Signum: '/SignDeltaU2' incorporates:
+ * Sum: '/Sum2'
+ */
+ if (q0 < 0) {
+ q0 = -1;
+ } else {
+ q0 = (q0 > 0);
+ }
+
+ /* End of Signum: '/SignDeltaU2' */
+
+ /* Signum: '/SignDeltaU3' incorporates:
+ * Sum: '/Sum1'
+ */
+ if ((int16_T)tmp_0 < 0) {
+ tmp = -1;
+ } else {
+ tmp = (int16_T)((int16_T)tmp_0 > 0);
+ }
+
+ /* End of Signum: '/SignDeltaU3' */
+
+ /* Update for UnitDelay: '/UnitDelay1' incorporates:
+ * DataTypeConversion: '/DataTypeConv4'
+ * Logic: '/AND1'
+ * Logic: '/AND1'
+ * RelationalOperator: '/Equal1'
+ */
+ localDW->UnitDelay1_DSTATE = ((q0 == tmp) && (rtb_LowerRelop1_i3 ||
+ rtb_UpperRelop_i));
+
+ /* Update for Delay: '/Resettable Delay' */
+ localDW->icLoad = 0U;
+ localDW->ResettableDelay_DSTATE = rtb_Sum1_bm;
+}
+
+/* Model step function */
+void BLDC_controller_step(RT_MODEL *const rtM)
+{
+ P *rtP = ((P *) rtM->defaultParam);
+ DW *rtDW = ((DW *) rtM->dwork);
+ ExtU *rtU = (ExtU *) rtM->inputs;
+ ExtY *rtY = (ExtY *) rtM->outputs;
+ boolean_T rtb_LogicalOperator;
+ int8_T rtb_Sum2_h;
+ boolean_T rtb_RelationalOperator4_d;
+ boolean_T rtb_UnitDelay5_e;
+ uint8_T rtb_a_elecAngle_XA_g;
+ boolean_T rtb_LogicalOperator1_j;
+ boolean_T rtb_LogicalOperator2_p;
+ boolean_T rtb_RelationalOperator1_mv;
+ int16_T rtb_Switch1_l;
+ int16_T rtb_Saturation;
+ int16_T rtb_Saturation1;
+ int32_T rtb_Sum1_jt;
+ int16_T rtb_Merge_m;
+ int16_T rtb_Merge1;
+ uint16_T rtb_Divide14_e;
+ uint16_T rtb_Divide1_f;
+ int16_T rtb_TmpSignalConversionAtLow_Pa[2];
+ int32_T rtb_Switch1;
+ int32_T rtb_Sum1;
+ int32_T rtb_Gain3;
+ uint8_T Sum;
+ int16_T Switch2;
+ int16_T Abs5;
+ int16_T DataTypeConversion2;
+ int16_T tmp[4];
+ int8_T UnitDelay3;
+
+ /* Outputs for Atomic SubSystem: '/BLDC_controller' */
+ /* Sum: '/Sum' incorporates:
+ * Gain: '/g_Ha'
+ * Gain: '/g_Hb'
+ * Inport: '/b_hallA '
+ * Inport: '/b_hallB'
+ * Inport: '