2.6. Getting a target interface

After obtaining a CADISimulation pointer, an individual target can be connected to. The steps are the same for connecting to an existing simulation or for instantiating a new one.

Figure 2.8. Getting a target interface

To view this graphic, your browser must support the SVG format. Either install a browser with native support, or install an appropriate plugin such as Adobe SVG Viewer.


The CADISimulation class holds information on the contained target components that can be retrieved using the GetTargetInfos() method. This information includes the ID and properties of the target that might be important for a debugger such as, for example, whether the target executes software.

The caller can decide which target to connect to based on the retrieved information. The required component is specified by its ID. The ID is forwarded as a parameter to the GetTarget() method in a later call.

The result of the GetTarget() call is a CAInterface pointer to the implementation of the CADI interface in the target component. This pointer is then used to obtain the required interface in combination with a compatibility check by calling ObtainInterface(). Typically, the requested interface is of type CADI as shown in Figure 2.9, but other interfaces such as CADIDisassembler, CADIProfiling, or a custom extension, can also be requested.

After acquiring another non-NULL CAInterface pointer, the caller must perform a static_cast to the appropriate type to access its full functionality.

Figure 2.9. Getting a CADI interface

To view this graphic, your browser must support the SVG format. Either install a browser with native support, or install an appropriate plugin such as Adobe SVG Viewer.


Example 2.5 shows a typical implementation:

Example 2.5. Getting a CADI interface

//having already obtained a CADISimulation pointer called
//cadi_simulation
uint32_t desiredNumberOfTargetInfos = 20; //arbitrarily chosen, must be
                                       //large enough to get all targets
uint32_t startTargetInfoIndex = 0;
uint32_t actualNumberOfTargetInfos = 0;
eslapi::CADITargetInfo_t *targetInfoList =
             new eslapi::CADITargetInfo_t[desiredNumberOfTargetInfos]();
status = cadi_simulation->GetTargetInfos(startTargetInfoIndex,
                                         desiredNumberOfTargetInfos,
                                         targetInfoList,
                                         &actualNumberOfTargetInfos);
if (status != eslapi::CADI_STATUS_OK)
{
     //GetTargetInfos() failed
// ...
// decide which target to connect to, we take the fourth (index '3'!!)
// ...

eslapi::CAInterface* ca_interface =
                       cadi_simulation->GetTarget(targetInfoList[3].id);
if (ca_interface == NULL)
{
      //GetTarget() failed
}

//requesting CADI 2.0 interface
eslapi::if_name_t ifNameTarget = "eslapi.CADI2";
eslapi::if_rev_t  minRevTarget = 0;
eslapi::if_rev_t  actualRevTarget = 0;
ca_interface = ca_interface->ObtainInterface(ifNameTarget,
                                             minRevTarget,
                                             &actualRevTarget);
if (ca_interface == NULL)
{
     //unsupported or incompatible interface
}
//converting CAInterface* to CADI*
CADI* cadi = static_cast<CADI*>(ca_interface);
//it might be necessary to connect to other targets later on, hence
//keeping the target infos for now
// continue using CADI ...

Copyright © 2008-2014 ARM. All rights reserved.ARM DUI 0444M
Non-ConfidentialID051314