AN2618
Application note
eTPU host interface
Introduction
The eTPU is the new generation of Time Processing Unit (TPU). Besides the hardware
enhancement, significant improvements have been made to the accompanying software
development tools; these tools make the enhanced Time Processing Unit (eTPU) easy to
use. A high level language (C) compiler has been developed to allow the user to program
the eTPU by using C language instead of microcode.
To program the eTPU effectively, the programmer still needs to have a clear understanding
of how the eTPU hardware works. Coding in C, the programmer can focus more on the
application logic and leave the mechanics of the eTPU programming to the compiler (i.e.,
register usage and tracking, parameter packing, micro-instruction packing, etc.). With the
help of the eTPU simulator and debugger, eTPU software can be developed much like the
software for the host CPU. Productivity of software development can be significantly
improved.
The introduction of the eTPU C compiler also changes the way the host interfaces to the
eTPU functions. With the help of the compiler, the same symbol can be referenced by the
both eTPU and host software. The host software can interface with eTPU functions via API
functions, instead of accessing physical memory locations and registers. For each eTPU
function, a host interface API function can now be developed as a part of the eTPU C
program. The host application can call these API functions to interface with the eTPU. The
references to these API functions and symbols for parameters are resolved at compile time.
The implementation details of the eTPU functions are hidden from the host application. This
design improves the flexibility of the eTPU functions’ implementation and the portability of
the host application code. This application note discusses how to build the host interface for
eTPU functions.
This application note shows how to build the host interface to access eTPU functions. The
eTPU PWM driver is used as an example to illustrate what the host needs to do to configure
eTPU module, channel and initialize PWM function. The appRev 2lication note also
describes the details of how to export eTPU software information to the host compiler. The
working code example is presented in the Appendix. The user can compile both host and
eTPU code, then download to actual hardware for testing.
September 2013
Rev 2
1/23
www.st.com
Contents
AN2618
Contents
1
2
3
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
eTPU and host interface hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Host interface software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3.1
3.2
3.3
3.4
3.5
Initialization overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
eTPU module initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
eTPU channel initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
eTPU function initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
eTPU and host interactive control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
4
5
Software integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Appendix A Code example 1.main.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Appendix B Code example 2.etpu_PWMControl.h . . . . . . . . . . . . . . . . . . . . . . . 12
Appendix C Code example 3.etpuc_pwm.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Appendix D Code example 4.etpuc_image.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Appendix E
Appendix F
Code example 5.etpu_pwm_auto.h . . . . . . . . . . . . . . . . . . . . . . . . . 17
Code example 6.utility.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Appendix G Code example 7.etpu_pwm.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
6
Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
2/23
AN2618
Overview
1
Overview
Host interface software adds another layer of abstraction between the host CPU and eTPU.
The host interface API functions hide the complexity of the interaction between the host
CPU and eTPU, providing a simple interface for host applications. Ideally, every eTPU
function shall have one or more host interface API functions.
The interface software between host and eTPU facilitates three major tasks:
1.
2.
3.
eTPU hardware initialization – configure eTPU peripheral hardware
eTPU function initialization – pass initial parameters and initiate function execution
eTPU function run time interactive control – update function parameters and handle
handshaking
Once the eTPU peripheral and eTPU functions are initialized, each eTPU function can start
to execute with initial function parameters. The host interface API functions need to be
provided for interactive control (i.e. parameters updating and control mode changing etc.).
To update the parameter or change control mode, the host is responsible for passing
updated parameters to the eTPU functions, and then informing the eTPU that the function
parameters have changed. If a coherent change of function parameters is required, the logic
has to be built in the eTPU functions to ensure the coherency. For some eTPU functions, the
interaction between host and eTPU is an essential part of the operation. In both host and
eTPU software, the logic is needed to handle the handshaking between host and eTPU. The
interaction between the eTPU and host can be encapsulated in the host interface API
functions.
The host code and eTPU code are compiled by different compilers. The host compiler is
normally used to build a single code image for both host and eTPU. In order to build eTPU
code and host code together, the eTPU software building information (i.e. eTPU code
image) has to be exported to the host compiler. The symbol information has to be exported
from the eTPU compiler to the host compiler as well. For the Byte Craft eTPU compiler, the
mechanism is implemented as a set of host interface macros. In the eTPU code, these
macros are inserted to generate proper executable and symbol information for the host
compiler.
The host interface design process is illustrated in the eTPU PWM driver examples in the
Appendices.
3/23
eTPU and host interface hardware
AN2618
2
eTPU and host interface hardware
The host interface hardware for the eTPU is shown in
Figure 1.
The host and eTPU can
communicate to each other via event or by data.
The host has access to all eTPU host interface registers. When the host wants the eTPU’s
services, it can issue the host service request (HSR) by writing the eTPU channel control
registers. Once the host service request is acknowledged, a thread of eTPU code
associated with this HSR is activated for execution. The eTPU code in the thread
implements the functions requested by the host. When eTPU needs the host service, it can
issue the interrupt request or DMA data transfer request, or generate a global exception.
The events handling logic is needed in the host software to provide services to the eTPU
corresponding to these requests.
The eTPU code memory (RAM) and data memory (RAM) are accessible by both host and
eTPU. eTPU code memory stores the eTPU executable binary image. At the power up
initialization, following the defined sequences, the host transfers the eTPU code stored in
the flash memory to the eTPU code memory. During the execution, the eTPU micro-engine
fetches the micro-instructions from the code memory.
Figure 1.
eTPU host interface hardware
The eTPU data memory is implemented by using tri-port RAM. It provides for data sharing
between the host and eTPU engines. Both host and eTPU can read and write the eTPU
data memory in any data size (8, 16, 24, and 32 bit). Since the eTPU data bus is 24 bits
wide, it is best to pack together a data word with an 8 bit value and a 24 bit value in order to
reduce data memory utilization. To reduce the overhead of packing and unpacking the data,
a virtual mirror memory space of the normal eTPU data memory has been created. The
virtual memory space is called Parameter Sign Extension (PSE) memory space. When the
host reads the 32-bit data from the PSE memory space, it will return the sign extended 24-
bit data. The conversion is needed if the 24-bit data is unsigned. Similarly, when the host
writes the 32-bit data to the eTPU PSE memory, only the three least significant bytes will be
written to the eTPU data memory. The most significant byte is untouched.
4/23
AN2618
Host interface software
3
Host interface software
The function partition between the application software and low-level driver is defined during
the software architecture design. To make the software portable, the application software is
normally designed to interface with the low-level driver via abstracted interface APIs. The
host interface of the eTPU functions should be designed such that the implementation of the
low-level driver is hidden from the application software.
Once the application software interface to the low-level driver is defined, the functionality of
the low-level driver can be partitioned between host CPU and eTPU. The eTPU interface
software running on the host CPU is an integral part of the low-level driver. It handles the
details of the interaction between host and eTPU.
The eTPU code and host interface code are compiled by two different compilers. In order to
resolve the eTPU code symbol reference in the host code, it is necessary to export the
symbolic information from the eTPU compiler to the host compiler. Similarly, to build a single
executable image, it is necessary to export eTPU code image to the host compiler. Several
types of information are exported from eTPU_C through host interface files, generated from
#pragma write
statements during compilation. For detailed information on
#pragma
write,
see the eTPU_C documentation.
An example of application software and low-level driver partition is shown in
Appendix A on
page 11.
3.1
Initialization overview
The eTPU initialization is an important part of the host interface. At the power up, the host
has to configure the eTPU peripheral properly before the eTPU function can be executed.
The eTPU initialization process is accomplished by both host CPU and eTPU. During the
initialization, the functional partition between host CPU and eTPU is as follows:
Host responsibility:
●
●
●
●
eTPU module initialization
eTPU channel configuration
Providing initial eTPU function parameters
Initiating the eTPU function execution
Responding to the HSR
Transitioning into the initialization state
eTPU responsibility:
●
●
The eTPU initialization can be broken down into three steps: eTPU module initialization,
eTPU channel initialization and eTPU function initialization. The following sections discuss
the interface design and the data exchange between host CPU and eTPU for each step of
initialization.
3.2
eTPU module initialization
At the power up initialization, the eTPU peripheral hardware is configured by the host. The
eTPU module initialization includes the following steps:
5/23