Is it possible to create a Matlab System block with no inputs nor outputs?
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I am working with the Simulink Coder Support package for STM Nucleo boards. I want to incorporate interrupt handling in my Simulink model. The External Interrupt block provided in this package triggers a Function-Call subsystem.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1389134/image.jpeg)
I wanted to place a simple Matlab System block in this subsystem.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1389139/image.jpeg)
The stepImpl method of the MatlabSystem block would call the interrup service routine to handle the interrupt.
function stepImpl(~)
if isempty(coder.target)
% Place simulation output code here
else
% Call C-function implementing device output
coder.ceval('isr_encoder');
end
end
However, when creating a Matlab System with no inputs nor outputs, build error saying
Reported by IRQ_encoder: System object that implements getSampleTimeImpl and has zero inputs and zero outputs is not supported.
pops up. How can I 'not-implement' the getSampleTimeImpl method? Or is there another approach?
The whole Matlab System is coded like this:
classdef IRQ_encoder < realtime.internal.SourceSampleTime ...
& coder.ExternalDependency ...
& matlab.system.mixin.Propagates ...
& matlab.system.mixin.CustomIcon
properties
% Public, tunable properties.
end
properties (Nontunable)
% Public, non-tunable properties.
end
properties (Access = private)
% Pre-computed constants.
end
methods
% Constructor
function obj = IRQ_encoder(varargin)
% ADC driver object
setProperties(obj,nargin,varargin{:});
end
end
methods (Access=protected)
function setupImpl(~)
if isempty(coder.target)
fprintf("Encoder ISR initialized\n");
else
% Call C-function implementing device initialization
coder.cinclude('IRQ_encoder.h');
coder.ceval('init_irq_encoder');
end
end
function stepImpl(~)
if isempty(coder.target)
% Place simulation output code here
else
% Call C-function implementing device output
coder.ceval('isr_encoder');
end
end
function releaseImpl(~)
if isempty(coder.target)
% Place simulation termination code here
else
% Call C-function implementing device termination
%coder.ceval('source_terminate');
end
end
end
methods (Access=protected)
%% Define output properties
function num = getNumInputsImpl(~)
num = 0;
end
function num = getNumOutputsImpl(~)
num = 0;
end
function flag = isOutputSizeLockedImpl(~,~)
flag = true;
end
function varargout = isOutputFixedSizeImpl(~,~)
varargout{1} = true;
end
function flag = isOutputComplexityLockedImpl(~,~)
flag = true;
end
function varargout = isOutputComplexImpl(~)
varargout{1} = false;
end
function varargout = getOutputSizeImpl(~)
varargout{1} = 0;
end
function varargout = getOutputDataTypeImpl(~)
varargout{1} = [];
end
% function icon = getIconImpl(~)
% Define a string as the icon for the System block in Simulink.
% icon = 'Source';
% end
end
methods (Static, Access=protected)
function simMode = getSimulateUsingImpl(~)
simMode = 'Interpreted execution';
end
function isVisible = showSimulateUsingImpl
isVisible = false;
end
end
methods (Static)
function name = getDescriptiveName()
name = 'A block used to handle encoder button ISR';
end
function b = isSupportedContext(context)
b = context.isCodeGenTarget('rtw');
end
function updateBuildInfo(buildInfo, context)
if context.isCodeGenTarget('rtw')
% Update buildInfo
srcDir = fullfile(fileparts(mfilename('fullpath')),'src');
includeDir = fullfile(fileparts(mfilename('fullpath')),'include');
addIncludePaths(buildInfo,includeDir);
addSourceFiles(buildInfo,'IRQ_encoder.c',srcDir);
% Use the following API's to add include files, sources and
% linker flags
%addIncludeFiles(buildInfo,'source.h',includeDir);
%addSourceFiles(buildInfo,'source.c',srcDir);
%addLinkFlags(buildInfo,{'-lSource'});
%addLinkObjects(buildInfo,'sourcelib.a',srcDir);
%addCompileFlags(buildInfo,{'-D_DEBUG=1'});
%addDefines(buildInfo,'MY_DEFINE_1')
end
end
end
end
2 Kommentare
Sathvik
am 30 Mai 2023
It is unclear why you don't need an input to the MATLAB System Block, since the IRQ generated by the External Interrupt Block should drive the ISR call. You can use a function-call block that will give a boolean output when it is triggered by an IRQ from the External Interrupt block. You can use this boolean output as input to the MATLAB System block which will trigger the stepImpl function when the bool input is true.
Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!