Activate the Scheduling Feature
The generated code includes scheduling code that executes application code based on sample times specified in the model. An ARM® Cortex®-R processor typically uses a operating system (OS) for scheduling application code. While the example presented here shows how to implement an operating system scheduler, the same conceptual steps also apply to a bare-metal scheduler.
Use the reference
OperatingSystem
object,os
, to yourTarget
object,tgt
, by callinggetOperatingSystem
with the'reference'
.os = getOperatingSystem(tgt,'reference');
Do not delete the
OperatingSystem
object,os
, from the MATLAB® workspace before you save the target.View the operating system name. The target being created will use the operating system provided with the reference target ARM Cortex-R.
os{1}.Name
ans = 'FreeRTOS'
Note
The
OperatingSystem
object must be accessed as a cell-array.Map the
OperatingSystem
object,os
, to theHardware
object,hw
.map(tgt,hw,os);
Confirm that the operating system
'FreeRTOS'
is used for the hardware'TIRM46Lx2 Launchpad'
show(tgt);
TIRM46Lx2 Launchpad Display Name TIRM46Lx2 Launchpad RM46 TI Deployer 1 FreeRTOS 1
The output shows that the operating system
'FreeRTOS'
is used for the hardware'TIRM46Lx2 Launchpad'
, and this fact is denoted by showing1
in the corresponding position for the hardware.Add the token to the
Deployer
to point to theFreeRTOS
components.token.Name = 'FREE_RTOS_SHRD_COMP_DIR'; token.Value = 'matlabshared.freertos.internal.getShrdCompRootDir'; deployerObj.Tokens{end+1} = token;
Add the compiler include paths to the
BuildConfiguration
by setting theIncludePaths
property to'$(TARGET_ROOT)/include'
.buildConfigurationObj.IncludePaths{end+1} = '$(TARGET_ROOT)/include';
If the source, header, and library files are not located within the
$(TARGET_ROOT)/include
folder, assign a cell array of all required paths toIncludePaths
.Note
$(TARGET_ROOT)
is a token that stands for the root folder of the target for ARM Cortex-R hardware board and will be resolved by the code generation software. This token was automatically assigned in the Create the Framework task.Define a MATLAB function to invoke after the code for the Simulink® model is generated.
deployerObj.AfterCodeGenFcn = 'matlabshared.target.tirm46.onAfterCodeGenHook_FreeRTOS';
The
'matlabshared.target.tirm46.onAfterCodeGenHook_freeRTOS'
function now specifiesFreeRTOS
as the operating system of your target and uses the predefined HALCoGen project files and generates specific source files for theTIRM46L852
device configuration. The previousfreeRunning
configuration defined in the Activate the Application Deployment Feature is overwritten.Save the information that describes a target to its framework.
saveTarget(tgt);
Copy the FreeRTOS specific header files, HALCoGen project files, FreeRTOS specific
onAfterCodeGenHook_FreeRTOS.m
files and other files to theTARGET_ROOT/src
folder.copyfile(fullfile(codertarget.arm_cortex_r.internal.getSpPkgRootDir(),... 'arm_cortex_r_examples', 'scheduler'),... fullfile(tgt.Folder),'f');
Test that the scheduler works correctly.
testTarget(tgt,'scheduler')
Upon completion of the test, a summary result is displayed. If the test
PASSED
, then you can proceed with adding the next feature. Otherwise, if the testFAILED
, a link to the test diagnostic logs is shown below the test summary.Note
Until an External Mode feature is added to the target, the scheduler cannot be fully tested and will return
Incomplete
in the test.
Confirm the Model Builds Successfully
In MATLAB, on the Home tab, select New > Simulink Model. The default name of the model is
untitled
. Click File > Save As and save your model astest
.In the model, select Simulation > Model Configuration Parameters.
In the Configuration Parameters dialog box, select the Hardware Implementation tab.
Set Hardware board to the hardware you registered, for example,
TIRM46Lx2 Launchpad
.On the
Solver
tab, set Tasking mode for periodic sample times to Auto.In the All Parameters tab, find and disable Block reduction.
Find and enable MAT-file logging.
In MATLAB, on the Home tab, select Simulink Library.
In the Simulink library, open Sources and add a Constant block to your model. Double-click the Constant block and set Sample time to
1
.Add another Constant block to the model. Double-click the
Constant1
block and set Sample time to2
and Constant value to2
.In the Simulink library, open Sinks and add a To Workspace block to your model. Click the block and set Save format to
Array
.Copy and paste this To Workspace block to the model.
Connect the Constant block to the To Workspace, and Constant1 and To Workspace1 .
Build your model. After the build completes, the code will run on your hardware. You need to verify whether the code actually runs. The technique you use for verification will be specific to your hardware.