ARM Technical Support Knowledge Articles

How can I control MTI behaviour from a LISA+ component

Applies to: Fast Models

Answer

Introduction

Fast Models supports the generation of traces that consistently track the execution and related activities in the model, particularly those that affect the state of the modeled IP. Generated virtual platforms provide trace support by using plug-ins in the form of DLLs and shared objects on Windows and Linux, respectively. The purpose of this article is to implement the Model Trace Interface (MTI) and control the trace through a LISA component. This article does not cover what can be achieved through using MTI. This example contains a dummy component which includes a trace enable register (REnable) that enables/disables the trace depending on the value written to it.

The System

The example system contains:

Trace Component

The dummy trace component is responsible for enabling or disabling the system trace depending on the value written to its internal resource register, REnable. This component includes and instantiates an external example trace plug-in (SimpleTraceExample.cpp) that traces the program counter (PC). 

    includes
    {

        #include "SimpleTraceExample.h"
    }
    
    resources
    {           
        SimpleTraceExample *plugin;
        eslapi::CADIParameterValue_t *params;  
        
        uint32_t PVBusAddress, PVBusData;
        
        REGISTER { description("Enable Register for the trace component"), type(uint), bitwidth(32) } REnable;
    }

Once the plug-in has been instantiated, the component invokes the RegisterSimulation() function which is a member function of the SimpleTracePlugin class and passes a pointer to the global simulation interface to it. This function is responsible for obtaining the System Trace Interface and trace sources. The source code for the plug-in implementation can be found in the attached example in the SimpleTraceExample.cpp file.

    behavior reset(int level)
    {      
        plugin = new SimpleTraceExample("SimpleTraceExample", 0, params);
        plugin->RegisterSimulation(getGlobalInterface());
    }

The component will only initiate the trace when a non-zero value is written into the REnable register. When a value is written to this register, the component invokes the StartTrace() or StopTrace() functions (members of SimpleTraceExample). These functions register or unregister the events that trigger callbacks respectively.

    internal slave port<PVDevice> device
    {
        behavior write(pv::WriteTransaction tx):pv::Tx_Result
        {        
            PVBusAddress = tx.getAddress(); 
            PVBusData = tx.getData32();
            
            switch(PVBusAddress)
            {
                 case 0x00: REnable = PVBusData;
                            
                            if ( PVBusData != 0x0)
                            {
                                plugin->StartTrace();
                                
                            }
                            else
                            {
                                plugin->StopTrace();
                            }
                            
                            break;
            }
            return tx.writeComplete();   
        }

    }  

The code snippet below is included from the SimpleTraceExample.cpp file and shows the contents of the StartTrace() and StopTrace() functions:

eslapi::CADIReturn_t SimpleTraceExample::StartTrace()
{
   // Now register the callback:
    Status status = save_event_class->RegisterCallback(TracePC_Thunk, this);
    if (status != MTI_OK)
        return Error("EventClass::RegisterCallback() returned error.");
    
    return eslapi::CADI_STATUS_OK;
}

eslapi::CADIReturn_t SimpleTraceExample::StopTrace()
{
    // Now register the callback:
    Status status = save_event_class->UnregisterCallback(TracePC_Thunk, this);
    if (status != MTI_OK)
        return Error("EventClass::UnregisterCallback() returned error.");
    
    return eslapi::CADI_STATUS_OK;
}

Example application

An example application is provided as assembler within the 'app' folder. A build script is also provided to aid rebuilding of the image. The application performs a store to the trace component's register to start tracing and another store to stop tracing. It then enters performs a semihosted sys_exit to stop the simulation.

Running the example

To run this example you need to perform the following steps:

1) build the example

2) build the application in the apps folder using the provided batch file (build.bat).

3) Launch the resulting model dll in Model Debugger via command line:

    $MAXCORE_HOME/bin/modeldebugger -m <path/to/model> -a  app/image.axf 

Attachments: MTIfromLISA.png , MTI_from_LISA_-_Controlled_by_component.zip

Article last edited on: 2013-08-27 13:31:05

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential