Is it possible to create a Matlab System block with no inputs nor outputs?

3 次查看(过去 30 天)
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.
I wanted to place a simple Matlab System block in this subsystem.
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 个评论
Sathvik
Sathvik 2023-5-30
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.
Ondrej
Ondrej 2023-6-16
Thank you very much for your comment @Sathvik. This is an interesting idea. So to conclude: Matlab System block cannot be implemented without an input anyhow, right?
To make my initial intention more clear...I wanted the Matlab System's stepImpl function to be called when the IRQ is generated. Thus I thought if I place it in the function-call block, it will execute when the interrupt occurs. And since I wanted only to reset a counter value in the ISR I didn't need any input.

请先登录,再进行评论。

回答(0 个)

产品


版本

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by