forked from cailemieuxmack/InsulinPump
-
Notifications
You must be signed in to change notification settings - Fork 0
/
msfun_realtime_elapsed.m
61 lines (46 loc) · 1.88 KB
/
msfun_realtime_elapsed.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
function msfun_realtime_elapsed(block)
% Help for Writing Level-2 M-File S-Functions:
% web([docroot '/toolbox/simulink/sfg/f7-67622.html']
% http://www.mathworks.com/access/helpdesk/help/toolbox/simulink/sfg/f7-67622.html
% Copyright 2009, The MathWorks, Inc.
% instance variables
myRealTimeBaseline = 0;
setup(block);
%% ---------------------------------------------------
function setup(block)
% Register the number of ports.
block.NumInputPorts = 0;
block.NumOutputPorts = 1;
block.SetPreCompOutPortInfoToDynamic;
block.OutputPort(1).Dimensions = 1;
block.OutputPort(1).SamplingMode = 'sample';
% Set up the states
block.NumContStates = 0;
block.NumDworks = 0;
% Register the parameters.
block.NumDialogPrms = 0; % scale factor
% Block is fixed in minor time step, i.e., it is only executed on major
% time steps. With a fixed-step solver, the block runs at the fastest
% discrete rate.
block.SampleTimes = [0 1];
block.SetAccelRunOnTLC(false); % run block in interpreted mode even w/ Acceleration
% methods called at run-time
block.RegBlockMethod('Start', @Start);
block.RegBlockMethod('Outputs', @Output);
block.RegBlockMethod('SimStatusChange', @SimStatusChange);
end
%%
function Start(block) %#ok<INUSD>
myRealTimeBaseline = tic;
end
%%
function Output(block)
block.OutputPort(1).Data = toc(myRealTimeBaseline);
end
%%
function SimStatusChange(block, status) %#ok<INUSL>
if status == 1, % resume
myRealTimeBaseline = tic;
end
end
end