Slave controller for AEB and QA item
Diff: Controller_Slave.c
- Revision:
- 0:88fb7562377b
- Child:
- 1:370626c9b451
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Controller_Slave.c Wed Jul 06 09:21:22 2016 +0000 @@ -0,0 +1,767 @@ +/* + * Academic License - for use in teaching, academic research, and meeting + * course requirements at degree granting institutions only. Not for + * government, commercial, or other organizational use. + * + * File: Controller_Slave.c + * + * Code generated for Simulink model 'Controller_Slave'. + * + * Model version : 1.6 + * Simulink Coder version : 8.10 (R2016a) 10-Feb-2016 + * C/C++ source code generated on : Wed Jul 06 11:19:35 2016 + * + * Target selection: ert.tlc + * Embedded hardware selection: NXP->Cortex-M4 + * Code generation objectives: Unspecified + * Validation result: Not run + */ + +#include "Controller_Slave.h" + +/* Named constants for Chart: '<S1>/AEB_QA' */ +#define Controller_S_IN_NO_ACTIVE_CHILD ((uint8_T)0U) +#define Controller_Slave_IN_ACCELERATE ((uint8_T)1U) +#define Controller_Slave_IN_AEB_ACTIVE ((uint8_T)1U) +#define Controller_Slave_IN_BRAKE ((uint8_T)2U) +#define Controller_Slave_IN_BRAKE_i ((uint8_T)1U) +#define Controller_Slave_IN_ERR ((uint8_T)1U) +#define Controller_Slave_IN_IDLE ((uint8_T)3U) +#define Controller_Slave_IN_IDLE_b ((uint8_T)2U) +#define Controller_Slave_IN_OK ((uint8_T)2U) +#define Controller_Slave_IN_QA_ACTIVE ((uint8_T)2U) +#define Controller_Slave_IN_READY ((uint8_T)3U) +#define Controller_Slave_IN_WARNING ((uint8_T)3U) +#define Controller__IN_SLAVE_ACTIVATION ((uint8_T)3U) + +/* Named constants for Chart: '<S1>/select_command' */ +#define Controller_Slave_IN_BLINK ((uint8_T)1U) +#define Controller_Slave_IN_BLINK_OFF ((uint8_T)1U) +#define Controller_Slave_IN_BLINK_ON ((uint8_T)2U) +#define Controller_Slave_IN_OFF1 ((uint8_T)2U) +#define Controller_Slave_IN_ON ((uint8_T)3U) + +/* Forward declaration for local functions */ +static void Controller_Slave_AEB_QA(const uint8_T *Memory, real_T + Controller_Slave_U_V, real_T Controller_Slave_U_D_S, boolean_T + Controller_Slave_U_QA_EN, uint8_T *Controller_Slave_Y_BRAKE, uint8_T + *Controller_Slave_Y_ACC, uint8_T *Controller_Slave_Y_LED_RED, uint8_T + *Controller_Slave_Y_LED_GREEN, uint8_T *Controller_Slave_Y_SLAVE, + B_Controller_Slave_T *Controller_Slave_B, DW_Controller_Slave_T + *Controller_Slave_DW); + +/*===========* + * Constants * + *===========*/ +#define RT_PI 3.14159265358979323846 +#define RT_PIF 3.1415927F +#define RT_LN_10 2.30258509299404568402 +#define RT_LN_10F 2.3025851F +#define RT_LOG10E 0.43429448190325182765 +#define RT_LOG10EF 0.43429449F +#define RT_E 2.7182818284590452354 +#define RT_EF 2.7182817F + +/* + * UNUSED_PARAMETER(x) + * Used to specify that a function parameter (argument) is required but not + * accessed by the function body. + */ +#ifndef UNUSED_PARAMETER +# if defined(__LCC__) +# define UNUSED_PARAMETER(x) /* do nothing */ +# else + +/* + * This is the semi-ANSI standard way of indicating that an + * unused function parameter is required. + */ +# define UNUSED_PARAMETER(x) (void) (x) +# endif +#endif + +/* Function for Chart: '<S1>/AEB_QA' */ +static void Controller_Slave_AEB_QA(const uint8_T *Memory, real_T + Controller_Slave_U_V, real_T Controller_Slave_U_D_S, boolean_T + Controller_Slave_U_QA_EN, uint8_T *Controller_Slave_Y_BRAKE, uint8_T + *Controller_Slave_Y_ACC, uint8_T *Controller_Slave_Y_LED_RED, uint8_T + *Controller_Slave_Y_LED_GREEN, uint8_T *Controller_Slave_Y_SLAVE, + B_Controller_Slave_T *Controller_Slave_B, DW_Controller_Slave_T + *Controller_Slave_DW) +{ + real_T K; + + /* During 'AEB_QA': '<S2>:35' */ + /* During 'APPLICATION_THREAD': '<S2>:32' */ + switch (Controller_Slave_DW->is_APPLICATION_THREAD) { + case Controller_Slave_IN_AEB_ACTIVE: + /* During 'AEB_ACTIVE': '<S2>:1' */ + /* '<S2>:26:1' sf_internal_predicateOutput = ... */ + /* '<S2>:26:1' En == false; */ + if (!Controller_Slave_DW->En) { + /* Transition: '<S2>:26' */ + /* Exit Internal 'AEB_ACTIVE': '<S2>:1' */ + Controller_Slave_DW->is_AEB_ACTIVE = Controller_S_IN_NO_ACTIVE_CHILD; + Controller_Slave_DW->is_APPLICATION_THREAD = Controller_Slave_IN_READY; + + /* Entry 'READY': '<S2>:21' */ + /* '<S2>:21:1' Brake = uint8(0); */ + *Controller_Slave_Y_BRAKE = 0U; + + /* '<S2>:21:1' Led_Blue = 0; */ + Controller_Slave_B->Led_Blue = 0.0; + + /* '<S2>:21:1' Led_Green = uint8(0); */ + *Controller_Slave_Y_LED_GREEN = 0U; + + /* '<S2>:21:4' Acc =uint8(0); */ + *Controller_Slave_Y_ACC = 0U; + } else { + /* Inport: '<Root>/QA_EN' incorporates: + * Inport: '<Root>/V' + */ + /* '<S2>:70:1' sf_internal_predicateOutput = ... */ + /* '<S2>:70:1' QA_En == true && V<30; */ + if (Controller_Slave_U_QA_EN && (Controller_Slave_U_V < 30.0)) { + /* Transition: '<S2>:70' */ + /* Exit Internal 'AEB_ACTIVE': '<S2>:1' */ + Controller_Slave_DW->is_AEB_ACTIVE = Controller_S_IN_NO_ACTIVE_CHILD; + Controller_Slave_DW->is_APPLICATION_THREAD = + Controller_Slave_IN_QA_ACTIVE; + + /* Entry 'QA_ACTIVE': '<S2>:69' */ + /* '<S2>:69:1' K = (V^2)/D; */ + /* Entry Internal 'QA_ACTIVE': '<S2>:69' */ + /* Transition: '<S2>:64' */ + Controller_Slave_DW->is_QA_ACTIVE = Controller_Slave_IN_IDLE; + + /* Entry 'IDLE': '<S2>:67' */ + /* '<S2>:67:1' Brake = uint8(0); */ + *Controller_Slave_Y_BRAKE = 0U; + + /* '<S2>:67:1' Led_Blue = 0; */ + Controller_Slave_B->Led_Blue = 0.0; + + /* '<S2>:67:1' Led_Green = uint8(0); */ + *Controller_Slave_Y_LED_GREEN = 0U; + + /* '<S2>:67:4' Acc = uint8(0); */ + *Controller_Slave_Y_ACC = 0U; + } else { + /* Inport: '<Root>/D_S' */ + /* '<S2>:1:1' K = (V^2)/D; */ + K = Controller_Slave_U_V * Controller_Slave_U_V / Controller_Slave_U_D_S; + switch (Controller_Slave_DW->is_AEB_ACTIVE) { + case Controller_Slave_IN_BRAKE_i: + /* During 'BRAKE': '<S2>:3' */ + /* '<S2>:10:1' sf_internal_predicateOutput = ... */ + /* '<S2>:10:1' K < 100; */ + if (K < 100.0) { + /* Transition: '<S2>:10' */ + Controller_Slave_DW->is_AEB_ACTIVE = Controller_Slave_IN_WARNING; + + /* Entry 'WARNING': '<S2>:5' */ + /* '<S2>:5:1' Brake = uint8(0); */ + *Controller_Slave_Y_BRAKE = 0U; + } + break; + + case Controller_Slave_IN_IDLE_b: + /* During 'IDLE': '<S2>:6' */ + /* '<S2>:12:1' sf_internal_predicateOutput = ... */ + /* '<S2>:12:1' K >= 70; */ + if (K >= 70.0) { + /* Transition: '<S2>:12' */ + Controller_Slave_DW->is_AEB_ACTIVE = Controller_Slave_IN_WARNING; + + /* Entry 'WARNING': '<S2>:5' */ + /* '<S2>:5:1' Brake = uint8(0); */ + *Controller_Slave_Y_BRAKE = 0U; + } + break; + + default: + /* During 'WARNING': '<S2>:5' */ + /* '<S2>:9:1' sf_internal_predicateOutput = ... */ + /* '<S2>:9:1' K >= 100; */ + if (K >= 100.0) { + /* Transition: '<S2>:9' */ + Controller_Slave_DW->is_AEB_ACTIVE = Controller_Slave_IN_BRAKE_i; + + /* Entry 'BRAKE': '<S2>:3' */ + /* '<S2>:3:1' Brake = uint8(1); */ + *Controller_Slave_Y_BRAKE = 1U; + + /* '<S2>:3:1' Led_Blue = 1; */ + Controller_Slave_B->Led_Blue = 1.0; + } else { + /* '<S2>:11:1' sf_internal_predicateOutput = ... */ + /* '<S2>:11:1' K < 70; */ + if (K < 70.0) { + /* Transition: '<S2>:11' */ + Controller_Slave_DW->is_AEB_ACTIVE = Controller_Slave_IN_IDLE_b; + + /* Entry 'IDLE': '<S2>:6' */ + /* '<S2>:6:1' Brake = uint8(0); */ + *Controller_Slave_Y_BRAKE = 0U; + + /* '<S2>:6:1' Led_Blue = 0; */ + Controller_Slave_B->Led_Blue = 0.0; + } else { + /* '<S2>:5:1' Led_Blue = (K-70)/30; */ + Controller_Slave_B->Led_Blue = (K - 70.0) / 30.0; + } + } + break; + } + } + } + break; + + case Controller_Slave_IN_QA_ACTIVE: + /* Inport: '<Root>/QA_EN' incorporates: + * Inport: '<Root>/V' + */ + /* During 'QA_ACTIVE': '<S2>:69' */ + /* '<S2>:71:1' sf_internal_predicateOutput = ... */ + /* '<S2>:71:1' QA_En ~= true || V>=30; */ + if ((!Controller_Slave_U_QA_EN) || (Controller_Slave_U_V >= 30.0)) { + /* Transition: '<S2>:71' */ + /* Exit Internal 'QA_ACTIVE': '<S2>:69' */ + Controller_Slave_DW->is_QA_ACTIVE = Controller_S_IN_NO_ACTIVE_CHILD; + Controller_Slave_DW->is_APPLICATION_THREAD = + Controller_Slave_IN_AEB_ACTIVE; + + /* Entry 'AEB_ACTIVE': '<S2>:1' */ + /* '<S2>:1:1' K = (V^2)/D; */ + /* Entry Internal 'AEB_ACTIVE': '<S2>:1' */ + /* Transition: '<S2>:51' */ + Controller_Slave_DW->is_AEB_ACTIVE = Controller_Slave_IN_IDLE_b; + + /* Entry 'IDLE': '<S2>:6' */ + /* '<S2>:6:1' Brake = uint8(0); */ + *Controller_Slave_Y_BRAKE = 0U; + + /* '<S2>:6:1' Led_Blue = 0; */ + Controller_Slave_B->Led_Blue = 0.0; + } else { + /* '<S2>:79:1' sf_internal_predicateOutput = ... */ + /* '<S2>:79:1' En == false; */ + if (!Controller_Slave_DW->En) { + /* Transition: '<S2>:79' */ + /* Exit Internal 'QA_ACTIVE': '<S2>:69' */ + Controller_Slave_DW->is_QA_ACTIVE = Controller_S_IN_NO_ACTIVE_CHILD; + Controller_Slave_DW->is_APPLICATION_THREAD = Controller_Slave_IN_READY; + + /* Entry 'READY': '<S2>:21' */ + /* '<S2>:21:1' Brake = uint8(0); */ + *Controller_Slave_Y_BRAKE = 0U; + + /* '<S2>:21:1' Led_Blue = 0; */ + Controller_Slave_B->Led_Blue = 0.0; + + /* '<S2>:21:1' Led_Green = uint8(0); */ + *Controller_Slave_Y_LED_GREEN = 0U; + + /* '<S2>:21:4' Acc =uint8(0); */ + *Controller_Slave_Y_ACC = 0U; + } else { + /* Inport: '<Root>/D_S' */ + /* '<S2>:69:1' K = (V^2)/D; */ + K = Controller_Slave_U_V * Controller_Slave_U_V / Controller_Slave_U_D_S; + switch (Controller_Slave_DW->is_QA_ACTIVE) { + case Controller_Slave_IN_ACCELERATE: + /* During 'ACCELERATE': '<S2>:68' */ + /* '<S2>:75:1' sf_internal_predicateOutput = ... */ + /* '<S2>:75:1' K >= 100; */ + if (K >= 100.0) { + /* Transition: '<S2>:75' */ + Controller_Slave_DW->is_QA_ACTIVE = Controller_Slave_IN_IDLE; + + /* Entry 'IDLE': '<S2>:67' */ + /* '<S2>:67:1' Brake = uint8(0); */ + *Controller_Slave_Y_BRAKE = 0U; + + /* '<S2>:67:1' Led_Blue = 0; */ + Controller_Slave_B->Led_Blue = 0.0; + + /* '<S2>:67:1' Led_Green = uint8(0); */ + *Controller_Slave_Y_LED_GREEN = 0U; + + /* '<S2>:67:4' Acc = uint8(0); */ + *Controller_Slave_Y_ACC = 0U; + } + break; + + case Controller_Slave_IN_BRAKE: + /* During 'BRAKE': '<S2>:65' */ + /* '<S2>:73:1' sf_internal_predicateOutput = ... */ + /* '<S2>:73:1' K <= 100; */ + if (K <= 100.0) { + /* Transition: '<S2>:73' */ + Controller_Slave_DW->is_QA_ACTIVE = Controller_Slave_IN_IDLE; + + /* Entry 'IDLE': '<S2>:67' */ + /* '<S2>:67:1' Brake = uint8(0); */ + *Controller_Slave_Y_BRAKE = 0U; + + /* '<S2>:67:1' Led_Blue = 0; */ + Controller_Slave_B->Led_Blue = 0.0; + + /* '<S2>:67:1' Led_Green = uint8(0); */ + *Controller_Slave_Y_LED_GREEN = 0U; + + /* '<S2>:67:4' Acc = uint8(0); */ + *Controller_Slave_Y_ACC = 0U; + } + break; + + default: + /* During 'IDLE': '<S2>:67' */ + /* '<S2>:72:1' sf_internal_predicateOutput = ... */ + /* '<S2>:72:1' K > 100; */ + if (K > 100.0) { + /* Transition: '<S2>:72' */ + Controller_Slave_DW->is_QA_ACTIVE = Controller_Slave_IN_BRAKE; + + /* Entry 'BRAKE': '<S2>:65' */ + /* '<S2>:65:1' Brake = uint8(1); */ + *Controller_Slave_Y_BRAKE = 1U; + + /* '<S2>:65:1' Led_Blue = 1; */ + Controller_Slave_B->Led_Blue = 1.0; + } else { + /* '<S2>:74:1' sf_internal_predicateOutput = ... */ + /* '<S2>:74:1' K < 100; */ + if (K < 100.0) { + /* Transition: '<S2>:74' */ + Controller_Slave_DW->is_QA_ACTIVE = Controller_Slave_IN_ACCELERATE; + + /* Entry 'ACCELERATE': '<S2>:68' */ + /* '<S2>:68:1' Led_Green = uint8(1); */ + *Controller_Slave_Y_LED_GREEN = 1U; + + /* '<S2>:68:1' Acc = uint8(1); */ + *Controller_Slave_Y_ACC = 1U; + } + } + break; + } + } + } + break; + + default: + /* During 'READY': '<S2>:21' */ + /* '<S2>:23:1' sf_internal_predicateOutput = ... */ + /* '<S2>:23:1' En == true; */ + if (Controller_Slave_DW->En) { + /* Transition: '<S2>:23' */ + Controller_Slave_DW->is_APPLICATION_THREAD = + Controller_Slave_IN_AEB_ACTIVE; + + /* Entry 'AEB_ACTIVE': '<S2>:1' */ + /* '<S2>:1:1' K = (V^2)/D; */ + /* Entry Internal 'AEB_ACTIVE': '<S2>:1' */ + /* Transition: '<S2>:51' */ + Controller_Slave_DW->is_AEB_ACTIVE = Controller_Slave_IN_IDLE_b; + + /* Entry 'IDLE': '<S2>:6' */ + /* '<S2>:6:1' Brake = uint8(0); */ + *Controller_Slave_Y_BRAKE = 0U; + + /* '<S2>:6:1' Led_Blue = 0; */ + Controller_Slave_B->Led_Blue = 0.0; + } + break; + } + + /* During 'ERRORS_CHECK_THREAD': '<S2>:80' */ + switch (Controller_Slave_DW->is_ERRORS_CHECK_THREAD) { + case Controller_Slave_IN_ERR: + /* During 'ERR': '<S2>:89' */ + break; + + case Controller_Slave_IN_OK: + /* Inport: '<Root>/V' incorporates: + * Inport: '<Root>/D_S' + */ + /* During 'OK': '<S2>:94' */ + /* '<S2>:83:1' sf_internal_predicateOutput = ... */ + /* '<S2>:83:1' V > 180 || D > 200; */ + if ((Controller_Slave_U_V > 180.0) || (Controller_Slave_U_D_S > 200.0)) { + /* Transition: '<S2>:83' */ + Controller_Slave_DW->is_ERRORS_CHECK_THREAD = Controller_Slave_IN_ERR; + + /* Entry 'ERR': '<S2>:89' */ + /* '<S2>:89:1' Led_Red = uint8(1); */ + *Controller_Slave_Y_LED_RED = 1U; + + /* '<S2>:89:1' Slave = uint8(0); */ + *Controller_Slave_Y_SLAVE = 0U; + + /* '<S2>:89:3' En = false; */ + Controller_Slave_DW->En = false; + + /* '<S2>:89:3' Brake = uint8(0); */ + *Controller_Slave_Y_BRAKE = 0U; + + /* '<S2>:89:4' Led_Blue = 0; */ + Controller_Slave_B->Led_Blue = 0.0; + } else { + /* '<S2>:82:1' sf_internal_predicateOutput = ... */ + /* '<S2>:82:1' D == 0; */ + if (Controller_Slave_U_D_S == 0.0) { + /* Transition: '<S2>:82' */ + Controller_Slave_DW->is_ERRORS_CHECK_THREAD = Controller_Slave_IN_ERR; + + /* Entry 'ERR': '<S2>:89' */ + /* '<S2>:89:1' Led_Red = uint8(1); */ + *Controller_Slave_Y_LED_RED = 1U; + + /* '<S2>:89:1' Slave = uint8(0); */ + *Controller_Slave_Y_SLAVE = 0U; + + /* '<S2>:89:3' En = false; */ + Controller_Slave_DW->En = false; + + /* '<S2>:89:3' Brake = uint8(0); */ + *Controller_Slave_Y_BRAKE = 0U; + + /* '<S2>:89:4' Led_Blue = 0; */ + Controller_Slave_B->Led_Blue = 0.0; + } else { + /* '<S2>:85:1' sf_internal_predicateOutput = ... */ + /* '<S2>:85:1' Master ~= 1 && En == false; */ + if ((*Memory != 1) && (!Controller_Slave_DW->En)) { + /* Transition: '<S2>:85' */ + Controller_Slave_DW->is_ERRORS_CHECK_THREAD = + Controller__IN_SLAVE_ACTIVATION; + + /* Entry 'SLAVE_ACTIVATION': '<S2>:95' */ + /* '<S2>:95:1' En = true; */ + Controller_Slave_DW->En = true; + } + } + } + break; + + default: + /* During 'SLAVE_ACTIVATION': '<S2>:95' */ + /* Transition: '<S2>:84' */ + Controller_Slave_DW->is_ERRORS_CHECK_THREAD = Controller_Slave_IN_OK; + + /* Entry 'OK': '<S2>:94' */ + /* '<S2>:94:1' Led_Red = uint8(0); */ + *Controller_Slave_Y_LED_RED = 0U; + + /* '<S2>:94:1' Slave = uint8(1); */ + *Controller_Slave_Y_SLAVE = 1U; + break; + } +} + +/* Model step function */ +void Controller_Slave_step(RT_MODEL_Controller_Slave_T *const Controller_Slave_M, + real_T Controller_Slave_U_V, real_T Controller_Slave_U_D_S, uint8_T + Controller_Slave_U_Master, boolean_T Controller_Slave_U_QA_EN, uint8_T + *Controller_Slave_Y_BRAKE, uint8_T *Controller_Slave_Y_ACC, uint8_T + *Controller_Slave_Y_LED_RED, uint8_T *Controller_Slave_Y_LED_GREEN, uint8_T + *Controller_Slave_Y_LED_BLUE, uint8_T *Controller_Slave_Y_SLAVE) +{ + B_Controller_Slave_T *Controller_Slave_B = ((B_Controller_Slave_T *) + Controller_Slave_M->ModelData.blockIO); + DW_Controller_Slave_T *Controller_Slave_DW = ((DW_Controller_Slave_T *) + Controller_Slave_M->ModelData.dwork); + uint8_T Memory; + + /* Outputs for Atomic SubSystem: '<Root>/Controller_Slave' */ + /* Memory: '<S1>/Memory' */ + Memory = Controller_Slave_DW->Memory_PreviousInput; + + /* Chart: '<S1>/AEB_QA' */ + /* Gateway: Controller_Slave/AEB_QA */ + /* During: Controller_Slave/AEB_QA */ + if (Controller_Slave_DW->is_active_c5_Controller_Slave == 0U) { + /* Entry: Controller_Slave/AEB_QA */ + Controller_Slave_DW->is_active_c5_Controller_Slave = 1U; + + /* Entry Internal: Controller_Slave/AEB_QA */ + /* Entry Internal 'AEB_QA': '<S2>:35' */ + /* Entry Internal 'APPLICATION_THREAD': '<S2>:32' */ + /* Transition: '<S2>:27' */ + Controller_Slave_DW->is_APPLICATION_THREAD = Controller_Slave_IN_READY; + + /* Outport: '<Root>/BRAKE' */ + /* Entry 'READY': '<S2>:21' */ + /* '<S2>:21:1' Brake = uint8(0); */ + *Controller_Slave_Y_BRAKE = 0U; + + /* '<S2>:21:1' Led_Blue = 0; */ + Controller_Slave_B->Led_Blue = 0.0; + + /* Outport: '<Root>/LED_GREEN' */ + /* '<S2>:21:1' Led_Green = uint8(0); */ + *Controller_Slave_Y_LED_GREEN = 0U; + + /* Outport: '<Root>/ACC' */ + /* '<S2>:21:4' Acc =uint8(0); */ + *Controller_Slave_Y_ACC = 0U; + + /* Entry Internal 'ERRORS_CHECK_THREAD': '<S2>:80' */ + /* Transition: '<S2>:81' */ + Controller_Slave_DW->is_ERRORS_CHECK_THREAD = Controller_Slave_IN_OK; + + /* Outport: '<Root>/LED_RED' */ + /* Entry 'OK': '<S2>:94' */ + /* '<S2>:94:1' Led_Red = uint8(0); */ + *Controller_Slave_Y_LED_RED = 0U; + + /* Outport: '<Root>/SLAVE' */ + /* '<S2>:94:1' Slave = uint8(1); */ + *Controller_Slave_Y_SLAVE = 1U; + } else { + Controller_Slave_AEB_QA(&Memory, Controller_Slave_U_V, + Controller_Slave_U_D_S, Controller_Slave_U_QA_EN, Controller_Slave_Y_BRAKE, + Controller_Slave_Y_ACC, Controller_Slave_Y_LED_RED, + Controller_Slave_Y_LED_GREEN, Controller_Slave_Y_SLAVE, Controller_Slave_B, + Controller_Slave_DW); + } + + /* End of Chart: '<S1>/AEB_QA' */ + + /* Chart: '<S1>/select_command' */ + if (Controller_Slave_DW->temporalCounter_i1 < MAX_uint32_T) { + Controller_Slave_DW->temporalCounter_i1++; + } + + /* Gateway: Controller_Slave/select_command */ + /* During: Controller_Slave/select_command */ + if (Controller_Slave_DW->is_active_c6_Controller_Slave == 0U) { + /* Entry: Controller_Slave/select_command */ + Controller_Slave_DW->is_active_c6_Controller_Slave = 1U; + + /* Entry Internal: Controller_Slave/select_command */ + /* Transition: '<S3>:2' */ + Controller_Slave_DW->is_c6_Controller_Slave = Controller_Slave_IN_OFF1; + + /* Outport: '<Root>/LED_BLUE' */ + /* Entry 'OFF1': '<S3>:3' */ + /* '<S3>:3:1' led = uint8(0); */ + *Controller_Slave_Y_LED_BLUE = 0U; + } else { + switch (Controller_Slave_DW->is_c6_Controller_Slave) { + case Controller_Slave_IN_BLINK: + /* During 'BLINK': '<S3>:20' */ + /* '<S3>:7:1' sf_internal_predicateOutput = ... */ + /* '<S3>:7:1' enable == 1; */ + if (Controller_Slave_B->Led_Blue == 1.0) { + /* Transition: '<S3>:7' */ + /* Exit Internal 'BLINK': '<S3>:20' */ + Controller_Slave_DW->is_BLINK = Controller_S_IN_NO_ACTIVE_CHILD; + Controller_Slave_DW->is_c6_Controller_Slave = Controller_Slave_IN_ON; + + /* Outport: '<Root>/LED_BLUE' */ + /* Entry 'ON': '<S3>:6' */ + /* '<S3>:6:1' led = uint8(1); */ + *Controller_Slave_Y_LED_BLUE = 1U; + } else { + /* '<S3>:21:1' sf_internal_predicateOutput = ... */ + /* '<S3>:21:1' enable == 0; */ + if (Controller_Slave_B->Led_Blue == 0.0) { + /* Transition: '<S3>:21' */ + /* Exit Internal 'BLINK': '<S3>:20' */ + Controller_Slave_DW->is_BLINK = Controller_S_IN_NO_ACTIVE_CHILD; + Controller_Slave_DW->is_c6_Controller_Slave = Controller_Slave_IN_OFF1; + + /* Outport: '<Root>/LED_BLUE' */ + /* Entry 'OFF1': '<S3>:3' */ + /* '<S3>:3:1' led = uint8(0); */ + *Controller_Slave_Y_LED_BLUE = 0U; + } else if (Controller_Slave_DW->is_BLINK == + Controller_Slave_IN_BLINK_OFF) { + /* During 'BLINK_OFF': '<S3>:11' */ + /* '<S3>:14:1' sf_internal_predicateOutput = ... */ + /* '<S3>:14:1' after(1-enable,sec); */ + if (Controller_Slave_DW->temporalCounter_i1 >= (uint32_T)ceil((1.0 - + Controller_Slave_B->Led_Blue) / 0.1 - 1.0E-9)) { + /* Transition: '<S3>:14' */ + Controller_Slave_DW->is_BLINK = Controller_Slave_IN_BLINK_ON; + Controller_Slave_DW->temporalCounter_i1 = 0U; + + /* Outport: '<Root>/LED_BLUE' */ + /* Entry 'BLINK_ON': '<S3>:13' */ + /* '<S3>:13:1' led = uint8(1); */ + *Controller_Slave_Y_LED_BLUE = 1U; + } + } else { + /* During 'BLINK_ON': '<S3>:13' */ + /* '<S3>:15:1' sf_internal_predicateOutput = ... */ + /* '<S3>:15:1' after(0.1,sec); */ + if (Controller_Slave_DW->temporalCounter_i1 >= 1U) { + /* Transition: '<S3>:15' */ + Controller_Slave_DW->is_BLINK = Controller_Slave_IN_BLINK_OFF; + Controller_Slave_DW->temporalCounter_i1 = 0U; + + /* Outport: '<Root>/LED_BLUE' */ + /* Entry 'BLINK_OFF': '<S3>:11' */ + /* '<S3>:11:1' led = uint8(0); */ + *Controller_Slave_Y_LED_BLUE = 0U; + } + } + } + break; + + case Controller_Slave_IN_OFF1: + /* During 'OFF1': '<S3>:3' */ + /* '<S3>:22:1' sf_internal_predicateOutput = ... */ + /* '<S3>:22:1' enable == 1; */ + if (Controller_Slave_B->Led_Blue == 1.0) { + /* Transition: '<S3>:22' */ + Controller_Slave_DW->is_c6_Controller_Slave = Controller_Slave_IN_ON; + + /* Outport: '<Root>/LED_BLUE' */ + /* Entry 'ON': '<S3>:6' */ + /* '<S3>:6:1' led = uint8(1); */ + *Controller_Slave_Y_LED_BLUE = 1U; + } else { + /* '<S3>:12:1' sf_internal_predicateOutput = ... */ + /* '<S3>:12:1' enable >0 && enable <1; */ + if ((Controller_Slave_B->Led_Blue > 0.0) && + (Controller_Slave_B->Led_Blue < 1.0)) { + /* Transition: '<S3>:12' */ + Controller_Slave_DW->is_c6_Controller_Slave = + Controller_Slave_IN_BLINK; + + /* Entry Internal 'BLINK': '<S3>:20' */ + /* Transition: '<S3>:24' */ + Controller_Slave_DW->is_BLINK = Controller_Slave_IN_BLINK_OFF; + Controller_Slave_DW->temporalCounter_i1 = 0U; + + /* Outport: '<Root>/LED_BLUE' */ + /* Entry 'BLINK_OFF': '<S3>:11' */ + /* '<S3>:11:1' led = uint8(0); */ + *Controller_Slave_Y_LED_BLUE = 0U; + } + } + break; + + default: + /* During 'ON': '<S3>:6' */ + /* '<S3>:4:1' sf_internal_predicateOutput = ... */ + /* '<S3>:4:1' enable == 0; */ + if (Controller_Slave_B->Led_Blue == 0.0) { + /* Transition: '<S3>:4' */ + Controller_Slave_DW->is_c6_Controller_Slave = Controller_Slave_IN_OFF1; + + /* Outport: '<Root>/LED_BLUE' */ + /* Entry 'OFF1': '<S3>:3' */ + /* '<S3>:3:1' led = uint8(0); */ + *Controller_Slave_Y_LED_BLUE = 0U; + } else { + /* '<S3>:23:1' sf_internal_predicateOutput = ... */ + /* '<S3>:23:1' enable >0 && enable <1; */ + if ((Controller_Slave_B->Led_Blue > 0.0) && + (Controller_Slave_B->Led_Blue < 1.0)) { + /* Transition: '<S3>:23' */ + Controller_Slave_DW->is_c6_Controller_Slave = + Controller_Slave_IN_BLINK; + + /* Entry Internal 'BLINK': '<S3>:20' */ + /* Transition: '<S3>:24' */ + Controller_Slave_DW->is_BLINK = Controller_Slave_IN_BLINK_OFF; + Controller_Slave_DW->temporalCounter_i1 = 0U; + + /* Outport: '<Root>/LED_BLUE' */ + /* Entry 'BLINK_OFF': '<S3>:11' */ + /* '<S3>:11:1' led = uint8(0); */ + *Controller_Slave_Y_LED_BLUE = 0U; + } + } + break; + } + } + + /* End of Chart: '<S1>/select_command' */ + + /* Update for Memory: '<S1>/Memory' incorporates: + * Update for Inport: '<Root>/MASTER' + */ + Controller_Slave_DW->Memory_PreviousInput = Controller_Slave_U_Master; + + /* End of Outputs for SubSystem: '<Root>/Controller_Slave' */ +} + +/* Model initialize function */ +void Controller_Slave_initialize(RT_MODEL_Controller_Slave_T *const + Controller_Slave_M, real_T *Controller_Slave_U_V, real_T + *Controller_Slave_U_D_S, uint8_T *Controller_Slave_U_Master, boolean_T + *Controller_Slave_U_QA_EN, uint8_T *Controller_Slave_Y_BRAKE, uint8_T + *Controller_Slave_Y_ACC, uint8_T *Controller_Slave_Y_LED_RED, uint8_T + *Controller_Slave_Y_LED_GREEN, uint8_T *Controller_Slave_Y_LED_BLUE, uint8_T + *Controller_Slave_Y_SLAVE) +{ + DW_Controller_Slave_T *Controller_Slave_DW = ((DW_Controller_Slave_T *) + Controller_Slave_M->ModelData.dwork); + B_Controller_Slave_T *Controller_Slave_B = ((B_Controller_Slave_T *) + Controller_Slave_M->ModelData.blockIO); + + /* Registration code */ + + /* block I/O */ + (void) memset(((void *) Controller_Slave_B), 0, + sizeof(B_Controller_Slave_T)); + + /* states (dwork) */ + (void) memset((void *)Controller_Slave_DW, 0, + sizeof(DW_Controller_Slave_T)); + + /* external inputs */ + (*Controller_Slave_U_V) = 0.0; + (*Controller_Slave_U_D_S) = 0.0; + (*Controller_Slave_U_Master) = 0U; + (*Controller_Slave_U_QA_EN) = false; + + /* external outputs */ + (*Controller_Slave_Y_BRAKE) = 0U; + (*Controller_Slave_Y_ACC) = 0U; + (*Controller_Slave_Y_LED_RED) = 0U; + (*Controller_Slave_Y_LED_GREEN) = 0U; + (*Controller_Slave_Y_LED_BLUE) = 0U; + (*Controller_Slave_Y_SLAVE) = 0U; + + /* SystemInitialize for Atomic SubSystem: '<Root>/Controller_Slave' */ + /* InitializeConditions for Memory: '<S1>/Memory' */ + Controller_Slave_DW->Memory_PreviousInput = 1U; + + /* SystemInitialize for Chart: '<S1>/AEB_QA' */ + Controller_Slave_DW->is_APPLICATION_THREAD = Controller_S_IN_NO_ACTIVE_CHILD; + Controller_Slave_DW->is_AEB_ACTIVE = Controller_S_IN_NO_ACTIVE_CHILD; + Controller_Slave_DW->is_QA_ACTIVE = Controller_S_IN_NO_ACTIVE_CHILD; + Controller_Slave_DW->is_ERRORS_CHECK_THREAD = Controller_S_IN_NO_ACTIVE_CHILD; + Controller_Slave_DW->is_active_c5_Controller_Slave = 0U; + Controller_Slave_DW->En = false; + + /* SystemInitialize for Chart: '<S1>/select_command' */ + Controller_Slave_DW->is_BLINK = Controller_S_IN_NO_ACTIVE_CHILD; + Controller_Slave_DW->temporalCounter_i1 = 0U; + Controller_Slave_DW->is_active_c6_Controller_Slave = 0U; + Controller_Slave_DW->is_c6_Controller_Slave = Controller_S_IN_NO_ACTIVE_CHILD; + + /* End of SystemInitialize for SubSystem: '<Root>/Controller_Slave' */ +} + +/* Model terminate function */ +void Controller_Slave_terminate(RT_MODEL_Controller_Slave_T *const + Controller_Slave_M) +{ + /* (no terminate code required) */ + UNUSED_PARAMETER(Controller_Slave_M); +} + +/* + * File trailer for generated code. + * + * [EOF] + */ +