1.4.1. Writing a macro

To write a macro:

  1. Decide how instructions must be grouped together to optimize the speed of transfer. Better performance results from macros containing a large number of operations.

  2. Convert the parameters of the normal TAPOp operations to the macro versions. The structure for the data required for the macro versions of the instructions is in the header file macstruct.h.

It is good practice to get the nonmacro version of a client working before attempting to turn it into a macro, because it is harder to debug when in macro format.

The prototype for the standard ARMTAP_AccessDR_W TAPOp function call is shown in Example 1.1.

Example 1.1. ARMTAP_AccessDR_W C function prototype declaration

extern TAPOp_ErrorARMTAP_AccessDR_W(unsigned8 connectId, ScanData40 *TDIbits, unsigned8 TDIrev, unsigned8 len, unsigned8 WRoffset, ScanData40 *WRmask, unsigned8 nclks, unsigned8 deselect);

When creating the ARMTAP_AccessDR_W instruction macro, a structure containing the parameters shown in Example 1.2 is used.

Example 1.2. ARMTAP_AccessDR_W macro structure declaration

typedef struct MAC_ARMTAP_AccessDR_WIn {    unsigned32      TDIbits1;
    unsigned8       TDIbits2;
    unsigned8       TDIrev;
    unsigned8       len;
    unsigned8       WRoffset;
    unsigned32      WRmask1;
    unsigned8       WRmask2;
    unsigned8       nclks;

There are a number of differences:

You must decide which parameters are fixed (define time) and which are variable (runtime). This depends on the specific programming task. There are two things to consider when choosing:

You are recommended to use this strategy:

  1. Perform the initial coding of the program without using macros. This enables you to find out what TAPOp sequences your application requires.

  2. Run and analyze this program to determine if there are specific speed or efficiency bottlenecks. Address these by writing macros for the parts of the system involved.

  3. Analyze the program again. If there are still problems with speed or efficiency, attempt to use macros more widely, and apply more general techniques for efficiency improvement (for example, avoiding calling functions, performing calculations outside loops, and caching results).

Proper error checking is essential with all TAPOp and ARMTAP functions. It is strongly recommended that the macro definition operation is performed within (a version of) the TAPCheck macro.

Copyright © 1998-2002 ARM Limited. All rights reserved.ARM DUI 0154B