#include "__cf_Mohamed_Alaswed_Buck.h"
#include <math.h>
#include "Mohamed_Alaswed_Buck_acc.h"
#include "Mohamed_Alaswed_Buck_acc_private.h"
#include <stdio.h>
#include "simstruc.h"
#include "fixedpoint.h"
#define CodeFormat S-Function
#define AccDefine1 Accelerator_S-Function
static void mdlOutputs ( SimStruct * S , int_T tid ) { real_T taskTimeV ;
real_T tNextAdjusted ; uint32_T numCycles ; B_Mohamed_Alaswed_Buck_T * _rtB ;
P_Mohamed_Alaswed_Buck_T * _rtP ; DW_Mohamed_Alaswed_Buck_T * _rtDW ; _rtDW =
( ( DW_Mohamed_Alaswed_Buck_T * ) ssGetRootDWork ( S ) ) ; _rtP = ( (
P_Mohamed_Alaswed_Buck_T * ) ssGetDefaultParam ( S ) ) ; _rtB = ( (
B_Mohamed_Alaswed_Buck_T * ) _ssGetBlockIO ( S ) ) ; if ( ssIsSampleHit ( S ,
1 , 0 ) ) { _rtB -> B_0_0_0 [ 0 ] = _rtP -> P_0 [ 0 ] ; _rtB -> B_0_0_0 [ 1 ]
= _rtP -> P_0 [ 1 ] ; _rtB -> B_0_0_0 [ 2 ] = _rtP -> P_0 [ 2 ] ; _rtB ->
B_0_1_0 = _rtP -> P_1 ; _rtB -> B_0_2_0 = _rtP -> P_2 ; } ssCallAccelRunBlock
( S , 0 , 3 , SS_CALL_MDL_OUTPUTS ) ; _rtB -> B_0_4_0 = _rtP -> P_3 * _rtB ->
B_0_3_0 [ 3 ] ; _rtB -> B_0_5_0 = _rtP -> P_4 * _rtB -> B_0_3_0 [ 8 ] ; _rtB
-> B_0_6_0 = _rtP -> P_5 * _rtB -> B_0_3_0 [ 7 ] ; _rtB -> B_0_7_0 = _rtP ->
P_6 * _rtB -> B_0_3_0 [ 6 ] ; _rtB -> B_0_8_0 = _rtP -> P_7 * _rtB -> B_0_3_0
[ 5 ] ; _rtB -> B_0_9_0 = _rtP -> P_8 * _rtB -> B_0_3_0 [ 4 ] ;
ssCallAccelRunBlock ( S , 0 , 10 , SS_CALL_MDL_OUTPUTS ) ; if ( ssIsSampleHit
( S , 1 , 0 ) ) { _rtB -> B_0_29_0 = _rtP -> P_9 ; } _rtB -> B_0_30_0 = _rtP
-> P_10 * _rtB -> B_0_3_0 [ 0 ] ; if ( ssIsMajorTimeStep ( S ) ) { _rtDW ->
Switch_Mode = ( _rtB -> B_0_3_1 [ 0 ] >= _rtP -> P_11 ) ; } if (
ssIsSampleHit ( S , 2 , 0 ) ) { taskTimeV = ssGetTaskTime ( S , 2 ) ;
tNextAdjusted = ( real_T ) ssGetTNextWasAdjusted ( S , 2 ) ; if (
tNextAdjusted != 0.0 ) { _rtDW -> nextTime = _ssGetVarNextHitTime ( S , 0 ) ;
} if ( _rtDW -> justEnabled != 0 ) { _rtDW -> justEnabled = 0 ; if (
taskTimeV >= _rtP -> P_15 ) { tNextAdjusted = ( taskTimeV - _rtP -> P_15 ) /
_rtP -> P_13 ; numCycles = ( uint32_T ) ( int32_T ) muDoubleScalarFloor (
tNextAdjusted ) ; if ( muDoubleScalarAbs ( ( real_T ) ( numCycles + 1U ) -
tNextAdjusted ) < DBL_EPSILON * tNextAdjusted ) { numCycles ++ ; } _rtDW ->
numCompleteCycles = ( int32_T ) numCycles ; tNextAdjusted = ( ( real_T )
numCycles * _rtP -> P_13 + _rtP -> P_15 ) + _rtP -> P_14 * _rtP -> P_13 /
100.0 ; if ( taskTimeV < tNextAdjusted ) { _rtDW -> currentValue = 1 ; _rtDW
-> nextTime = tNextAdjusted ; } else { _rtDW -> currentValue = 0 ; _rtDW ->
nextTime = ( real_T ) ( numCycles + 1U ) * _rtP -> P_13 + _rtP -> P_15 ; } }
else { _rtDW -> numCompleteCycles = _rtP -> P_15 != 0.0 ? - 1 : 0 ; _rtDW ->
currentValue = 0 ; _rtDW -> nextTime = _rtP -> P_15 ; } } else { if ( _rtDW
-> nextTime <= taskTimeV ) { if ( _rtDW -> currentValue == 1 ) { _rtDW ->
currentValue = 0 ; _rtDW -> nextTime = ( real_T ) ( _rtDW ->
numCompleteCycles + 1 ) * _rtP -> P_13 + _rtP -> P_15 ; } else { _rtDW ->
numCompleteCycles ++ ; _rtDW -> currentValue = 1 ; _rtDW -> nextTime = ( _rtP
-> P_14 * _rtP -> P_13 * 0.01 + ( real_T ) _rtDW -> numCompleteCycles * _rtP
-> P_13 ) + _rtP -> P_15 ; } } } _ssSetVarNextHitTime ( S , 0 , _rtDW ->
nextTime ) ; if ( _rtDW -> currentValue == 1 ) { _rtB -> B_0_32_0 = _rtP ->
P_12 ; } else { _rtB -> B_0_32_0 = 0.0 ; } } if ( ssIsSampleHit ( S , 1 , 0 )
) { _rtB -> B_0_33_0 = _rtB -> B_0_32_0 ; _rtB -> B_0_37_0 = _rtP -> P_16 ; }
_rtB -> B_0_38_0 = _rtP -> P_17 * _rtB -> B_0_3_0 [ 2 ] ; if (
ssIsMajorTimeStep ( S ) ) { _rtDW -> Switch_Mode_g = ( _rtB -> B_0_3_1 [ 2 ]
>= _rtP -> P_18 ) ; } if ( _rtDW -> Switch_Mode_g ) { _rtB -> B_0_39_0 = _rtB
-> B_0_38_0 ; } else { _rtB -> B_0_39_0 = _rtB -> B_0_37_0 ; } if (
ssIsMajorTimeStep ( S ) ) { _rtDW -> Saturation_MODE = _rtB -> B_0_39_0 >=
_rtP -> P_19 ? 1 : _rtB -> B_0_39_0 > _rtP -> P_20 ? 0 : - 1 ; } if (
ssIsSampleHit ( S , 1 , 0 ) ) { _rtB -> B_0_47_0 = _rtP -> P_21 ; } _rtB ->
B_0_48_0 = _rtP -> P_22 * _rtB -> B_0_3_0 [ 1 ] ; if ( ssIsMajorTimeStep ( S
) ) { _rtDW -> Switch_Mode_c = ( _rtB -> B_0_3_1 [ 1 ] >= _rtP -> P_23 ) ; }
if ( _rtDW -> Switch_Mode_c ) { _rtB -> B_0_49_0 = _rtB -> B_0_48_0 ; } else
{ _rtB -> B_0_49_0 = _rtB -> B_0_47_0 ; } if ( ssIsMajorTimeStep ( S ) ) {
_rtDW -> Saturation_MODE_p = _rtB -> B_0_49_0 >= _rtP -> P_24 ? 1 : _rtB ->
B_0_49_0 > _rtP -> P_25 ? 0 : - 1 ; } UNUSED_PARAMETER ( tid ) ; }
#define MDL_UPDATE
static void mdlUpdate ( SimStruct * S , int_T tid ) {
B_Mohamed_Alaswed_Buck_T * _rtB ; DW_Mohamed_Alaswed_Buck_T * _rtDW ; _rtDW =
( ( DW_Mohamed_Alaswed_Buck_T * ) ssGetRootDWork ( S ) ) ; _rtB = ( (
B_Mohamed_Alaswed_Buck_T * ) _ssGetBlockIO ( S ) ) ; ssCallAccelRunBlock ( S
, 0 , 3 , SS_CALL_MDL_UPDATE ) ; UNUSED_PARAMETER ( tid ) ; }
#define MDL_DERIVATIVES
static void mdlDerivatives ( SimStruct * S ) { B_Mohamed_Alaswed_Buck_T *
_rtB ; DW_Mohamed_Alaswed_Buck_T * _rtDW ; _rtDW = ( (
DW_Mohamed_Alaswed_Buck_T * ) ssGetRootDWork ( S ) ) ; _rtB = ( (
B_Mohamed_Alaswed_Buck_T * ) _ssGetBlockIO ( S ) ) ; ssCallAccelRunBlock ( S
, 0 , 3 , SS_CALL_MDL_DERIVATIVES ) ; }
#define MDL_ZERO_CROSSINGS
static void mdlZeroCrossings ( SimStruct * S ) { B_Mohamed_Alaswed_Buck_T *
_rtB ; P_Mohamed_Alaswed_Buck_T * _rtP ; ZCV_Mohamed_Alaswed_Buck_T * _rtZCSV
; DW_Mohamed_Alaswed_Buck_T * _rtDW ; _rtDW = ( ( DW_Mohamed_Alaswed_Buck_T *
) ssGetRootDWork ( S ) ) ; _rtZCSV = ( ( ZCV_Mohamed_Alaswed_Buck_T * )
ssGetSolverZcSignalVector ( S ) ) ; _rtP = ( ( P_Mohamed_Alaswed_Buck_T * )
ssGetDefaultParam ( S ) ) ; _rtB = ( ( B_Mohamed_Alaswed_Buck_T * )
_ssGetBlockIO ( S ) ) ; ssCallAccelRunBlock ( S , 0 , 3 ,
SS_CALL_MDL_ZERO_CROSSINGS ) ; _rtZCSV -> Switch_SwitchCond_ZC = _rtB ->
B_0_3_1 [ 0 ] - _rtP -> P_11 ; _rtZCSV -> Switch_SwitchCond_ZC_k = _rtB ->
B_0_3_1 [ 2 ] - _rtP -> P_18 ; _rtZCSV -> Saturation_UprLim_ZC = _rtB ->
B_0_39_0 - _rtP -> P_19 ; _rtZCSV -> Saturation_LwrLim_ZC = _rtB -> B_0_39_0
- _rtP -> P_20 ; _rtZCSV -> Switch_SwitchCond_ZC_j = _rtB -> B_0_3_1 [ 1 ] -
_rtP -> P_23 ; _rtZCSV -> Saturation_UprLim_ZC_e = _rtB -> B_0_49_0 - _rtP ->
P_24 ; _rtZCSV -> Saturation_LwrLim_ZC_b = _rtB -> B_0_49_0 - _rtP -> P_25 ;
} static void mdlInitializeSizes ( SimStruct * S ) { ssSetChecksumVal ( S , 0
, 1722976605U ) ; ssSetChecksumVal ( S , 1 , 3254537793U ) ; ssSetChecksumVal
( S , 2 , 10252029U ) ; ssSetChecksumVal ( S , 3 , 1975391633U ) ; { mxArray
* slVerStructMat = NULL ; mxArray * slStrMat = mxCreateString ( "simulink" )
; char slVerChar [ 10 ] ; int status = mexCallMATLAB ( 1 , & slVerStructMat ,
1 , & slStrMat , "ver" ) ; if ( status == 0 ) { mxArray * slVerMat =
mxGetField ( slVerStructMat , 0 , "Version" ) ; if ( slVerMat == NULL ) {
status = 1 ; } else { status = mxGetString ( slVerMat , slVerChar , 10 ) ; }
} mxDestroyArray ( slStrMat ) ; mxDestroyArray ( slVerStructMat ) ; if ( (
status == 1 ) || ( strcmp ( slVerChar , "8.1" ) != 0 ) ) { return ; } }
ssSetOptions ( S , SS_OPTION_EXCEPTION_FREE_CODE ) ; if ( ssGetSizeofDWork (
S ) != sizeof ( DW_Mohamed_Alaswed_Buck_T ) ) { ssSetErrorStatus ( S ,
"Unexpected error: Internal DWork sizes do "
"not match for accelerator mex file." ) ; } if ( ssGetSizeofGlobalBlockIO ( S
) != sizeof ( B_Mohamed_Alaswed_Buck_T ) ) { ssSetErrorStatus ( S ,
"Unexpected error: Internal BlockIO sizes do "
"not match for accelerator mex file." ) ; } { int ssSizeofParams ;
ssGetSizeofParams ( S , & ssSizeofParams ) ; if ( ssSizeofParams != sizeof (
P_Mohamed_Alaswed_Buck_T ) ) { static char msg [ 256 ] ; sprintf ( msg ,
"Unexpected error: Internal Parameters sizes do "
"not match for accelerator mex file." ) ; } } _ssSetDefaultParam ( S , (
real_T * ) & Mohamed_Alaswed_Buck_rtDefaultP ) ; rt_InitInfAndNaN ( sizeof (
real_T ) ) ; ( ( P_Mohamed_Alaswed_Buck_T * ) ssGetDefaultParam ( S ) ) ->
P_19 = rtInf ; ( ( P_Mohamed_Alaswed_Buck_T * ) ssGetDefaultParam ( S ) ) ->
P_24 = rtInf ; } static void mdlInitializeSampleTimes ( SimStruct * S ) { }
static void mdlTerminate ( SimStruct * S ) { }
#include "simulink.c"
