PASTA Python APIs Programming Guide
PASTA Python APIs Programming Guide
Programming Guide
Doc No:
Version: V1.3
Release date: 2020-02-24
Classification: Confidential B
Internet
[Link]
Classification:Confidential B
2 V1.3 (2020-02-24)
V1.3 (2020-02-24) 3
Table of Contents
MediaTek Confidential
1 Introduction .......................................................................................................................................... 7
Classification:Confidential B
5.1.4 set_property(name, property) ...................................................................................... 16
4 V1.3 (2020-02-24)
V1.3 (2020-02-24) 5
V1.3 (2020-02-24)
6
1 Introduction
1 Introduction
PASTA (Production-Line Automation Suite & Testing Architectures) is an application framework and a library
suite for developing MTK modem RF testing, calibration, tuning functions in Python language. The design
MediaTek Confidential
concepts of PASTA are focus on scalabilities, customizations and automation capabilities that achieved by
flexible software container architectures and facilitated APIs.
PASTA users can execute the META tool released RF python applications or develop customization features by
themselves.
1.1 Purpose
Unauthorized reproduction or disclosure of this information in whole or in part is strictly prohibited.
This document is intended to provide detailed information for the users would like to develop RF related scripting
applications using PASTA. It's a programming guide to make developers can quickly understand the capabilities
This document contains information that is proprietary to MediaTek Inc.
of PASTA.
© 2019 - 2020 MediaTek Inc.
1.2 Scope
This document describes detailed specifications of PASTA modules and APIs illusrated with sample code snippets.
The readers of this document are assumed to have relevant knowledge of MTK META tool and modem RF basic
concepts.
1.3 Conventions
The notation of API parameter with square brackets, e.g., [param] indicates optional parameter and can be
skipped. The parameter starts with asterisk, e.g., *values indicates an argument set (value1, value2, ...), each
Classification:Confidential B
value is separated by commas. Some functions need to specify name of parameter to assign correct parameter
value, such as function1(core=-1), which means set value -1 to the parameter core.
Python 3.7-32bit (Nice to have): PASTA package contains an embedded python interpreter: [Link]
can launch python scripts, but we recommend PASTA script developers install Python3.7 for debugging
efficiencies. The [Link] can be found in the META_TOOL_FOLDER\Utilities\Pasta\bin folder.
V1.3 (2020-02-24) 7
2 Abbreviations
The abbreviations and their explanations used in this document are listed in the Table 2-1.
MediaTek Confidential
Abbreviations Explanation
PASTA Production-Line Automation Suite & Testing Architectures
META Mobile Engineering Testing Architecture
ILM Inter Layer Message
DUT Device Under Test
8 V1.3 (2020-02-24)
3 System Overview
This chapter gives a brief introduction of PASTA software architectures shows as figure3.1. PASTA context is a
kernel component container that contains core features can be used by an application. The major functional
modules in a PASTA context include DUT communication module uses to connect to the device and doing data
MediaTek Confidential
transmission, the message codec module works for transaction commands encoding/decoding, the instrument
library module supports wrapped RF instruments controlling (very limited functions, we recommend users to
write the GPIB commands executed by python VISA module), the application interfaces enclose common usage
APIs, and the calibration & RF feature units are some META tool released functionality components.
Application
Unauthorized reproduction or disclosure of this information in whole or in part is strictly prohibited.
PASTA Context
Application Interfaces
This document contains information that is proprietary to MediaTek Inc.
Utilities
Instrument Library
Simulator
V1.3 (2020-02-24) 9
4 Start PASTA
The PASTA libraries and applications are delivered with META tool. All PASTA materials are kept in the
utilities/Pasta folder of the META tool package.
MediaTek Confidential
PASTA is implemented by Python3.7, we recommend users installing Python3.7 runtimes to setup
comprehensively development environments. But, if you don’t feel like to install new software, an embedded
python interpreter [Link] can be used as Python3.7 replacement.
Disclaimer:
Disclaimer:
PASTA requires VISA library to control RF instruments, for the users that already had Python3.7 installation and
not intend to using [Link] as script interpreter should install PyVisa library by yourselves. The PyVisa
installation command as:
Classification:Confidential B
Disclaimer:
If you copy META tool (PASTA) package to preferred folder, you have to re-run [Link] under the new folder.
10 V1.3 (2020-02-24)
V1.3 (2020-02-24) 11
MediaTek Confidential
-----------------------------------------------------------------------------------------------------------------------------------------------
# boot up smartphone device using default path [Link] file and auto comport search
Pasta.boot_device()
-----------------------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------------------
Pasta.boot_device(meta_console="YourMetaToolFolder\[Link]")
Pasta.boot_device(device="md", port=14)
-----------------------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------------------
Parameters
12 V1.3 (2020-02-24)
Disclaimer:
If you want to shut down the device after your script execution done, you can use adb command to do it. The
adb shutdown command is: [Link] shell reboot -p
MediaTek Confidential
import Pasta
# create a pasta runtime context
Unauthorized reproduction or disclosure of this information in whole or in part is strictly prohibited.
context = Pasta.create_context()
# connect to target device
This document contains information that is proprietary to MediaTek Inc.
dut = context.get_component("DUT_COMM_ENGINE")
[Link]("mode=usb;comport=auto")
© 2019 - 2020 MediaTek Inc.
connection_status = [Link]()
# get pasta module instances
pasta_api = context.get_api_instance ()
transaction = pasta_api.get_transaction_api()
codec = context. get_codec_instance()
# send version info query command to dut, and decode receiving data
FT_VER_INFO_REQ_ID, FT_VER_INFO_CNF_ID = 51, 52
# prepare command
token, command = transaction.create_ft_command(FT_VER_INFO_REQ_ID, "FT_VER_INFO_REQ")
# send command
transaction.send_modem_command(command.get_buffer())
# get confirmation
Classification:Confidential B
Detailed descriptions:
import Pasta
This is the first step of using PASTA, if you do not setup PASTA successfully, you might encounter something
wrong here.
context = Pasta.create_context()
V1.3 (2020-02-24) 13
Create a PASTA context, the context contains application based components and properties that can be
accessed in the whole execution cycle.
MediaTek Confidential
codec = context. get_codec_instance ()
[Link]("mode=usb;comport=auto")
connection_status = [Link]()
Configure connection settings and connect to the device, now only USB connection is available.
print (target_ver_info.SW_VER)
Get target confirmation that match request-command token and response id. Decode the received data then
show results.
Classification:Confidential B
14 V1.3 (2020-02-24)
5 PastaContext Module
The design concept of PASTA context is similar to application container that creates an independent workspace
and establishes the connections between working components. The application can access registered
components and exchange data under the same context. An individual context represent a unique execution
MediaTek Confidential
import Pasta
context = Pasta.create_context()
Unauthorized reproduction or disclosure of this information in whole or in part is strictly prohibited.
5.1.1 get_component(name)
Returns the component of a specified name.
Parameters
Return
Classification:Confidential B
Returns a component instance or python None value if the specified component doesn’t exist.
Remarks
Parameters
V1.3 (2020-02-24) 15
Remarks
MediaTek Confidential
You can add any python type of objects into context. If the specified name is existed in the context, the prior
component will be replaced by the new component.
Example
import configparser
context = Pasta.create_context()
context.set_component(“ConfigFileParser”, my_parser)
registered_parser = context.get_component(“ConfigFileParser”)
Parameters
Classification:Confidential B
Return
Remarks
Parameters
16 V1.3 (2020-02-24)
Remarks
MediaTek Confidential
You can add any python type of objects as property. If the specified name is existed in the context, the prior
property will be replaced by new one.
The perspectives of PASTA context components and properties are different. Properties are assigned for the
application configurations and components are setup to achieve application’s functionalities.
5.1.5 get_device_instance ()
Unauthorized reproduction or disclosure of this information in whole or in part is strictly prohibited.
Return
© 2019 - 2020 MediaTek Inc.
Returns the device module instance, same as calling get_component("DUT_COMM_ENGINE"). The detailed
descriptions of device module are addressed in the chapter 6.
5.1.6 get_api_instance ()
Gets the PastaApi instance
Return
Returns the PastaApi module instance same as calling get_component("PASTA_API "). The detailed descriptions
Classification:Confidential B
5.1.7 get_codec_instance ()
Gets the message codec builder instance
Return
V1.3 (2020-02-24) 17
5.1.8 get_logger_instance ()
Gets default context logging instance
Return
MediaTek Confidential
Returns the python logging object, same as calling get_component("PASTA_LOGGER").
Return
Remarks
Shared unit is a strictly regulated functional class implemented and maintained by a PASTA development team
to provide some domain specific features, e.g., get RF capabilities, PA bias tuning, and the rest. Please consult
PASTA owners if you don’t have certain ideas of how to use it.
Parameters
Return
Returns a created shared instance or python None value if the specified unit is not exist
18 V1.3 (2020-02-24)
Remarks
Shared unit is a strictly regulated functional class implemented and maintained by a PASTA development team
to provide some domain specific features, e.g., get RF capabilities, PA bias tuning, and the rest. Please consult
PASTA owners if you don’t have certain ideas of how to use it.
MediaTek Confidential
Unauthorized reproduction or disclosure of this information in whole or in part is strictly prohibited.
This document contains information that is proprietary to MediaTek Inc.
V1.3 (2020-02-24) 19
6 Device Module
The device module implements functions to connect to the target device and message transactions. You can get
device object as:
MediaTek Confidential
import Pasta
context = Pasta.create_context()
Parameters
Return
Classification:Confidential B
Remarks
e.g., [Link]("mode=usb;comport=auto").
20 V1.3 (2020-02-24)
6.1.2 connect()
Connects to the target device
Return
MediaTek Confidential
6.1.3 disconnect()
Disconnect the target connection
Unauthorized reproduction or disclosure of this information in whole or in part is strictly prohibited.
Return
Parameters
Return
Classification:Confidential B
Remarks
This is a low level API, users have to fully understand all details about command transaction protocols to compose
the precise binary data. We suggest not directly using this API to send command, using the transactional APIs is
much easier. Please refer to the chapter 7.2 for more details.
V1.3 (2020-02-24) 21
Parameters
MediaTek Confidential
Return
Remarks
This is a low level API of getting response from the DUT. We suggest not directly using this API to retrieve target
confirmations, using the transactional APIs is much easier. Please refer to the chapter 7.2 for more details.
Classification:Confidential B
22 V1.3 (2020-02-24)
7 PastaApi Module
PastaApi is the key module of PASTA framework provides high level APIs to process message codec, transaction
management, and feature level composition functions. You can get PastaApi object as:
MediaTek Confidential
import Pasta
context = Pasta.create_context()
According to the functionalities, PASTA provides multiple sub API interfaces, call the accessing function to get the
interested interface.
This document contains information that is proprietary to MediaTek Inc.
7.1.1 get_transaction_api ()
Get transaction api instance. Transaction api class performs working functions to complete ‘business’ between
application and target device.
Return
7.1.2 get_rftuning_api ()
Classification:Confidential B
Get rftuning api instance. Rftuning api class performs high level RF performance tuning oriented functions.
Return
Remarks
V1.3 (2020-02-24) 23
MediaTek Confidential
[data_buffer])
Creates a transactional command object to communicate with FT task running on the target device. FT command
is the based type of other radio access technology(RAT) specified commands.
Parameters
Return
Returns an integer value to represent serial number (token) of this transaction and a command codec object can
be used to assign values of command structure members.
Remarks
The FT command IDs and corresponded structure definitions are designed by L1 protocol team as communication
specifications. PASTA users may need to consult L1 experts to get precise command settings.
Classification:Confidential B
Example
import Pasta
context = Pasta.create_context() # create a runtime context
… # skip some connection flows
pasta_api = context.get_api_instance () # get pasta api
transaction = pasta_api.get_transaction_api() # get transaction api object
# create a FT command for locking down NVRAM
FT_NVRAM_LOCK_REQ_ID = 21
24 V1.3 (2020-02-24)
FT_NVRAM_LOCK_CNF_ID = 20
confirm = transaction.get_ft_confirmation(token, FT_NVRAM_LOCK_CNF_ID) # get target response matches command token and
confirmation id
Parameters
Return
This document contains information that is proprietary to MediaTek Inc.
Remarks
Based on modem message communication protocol: Inter Layer Message (ILM), there are two parts of
transaction data: local parameter and peer buffer. The local parameter contains mandatory communication data,
and the optional peer buffer uses to exchange massive private data.
Parameters
Return
V1.3 (2020-02-24) 25
MediaTek Confidential
Example
Return
Returns an integer value to represent serial number(token) of this transaction and a 'RF_TEST_REQ' command
codec object can be used to assign values of command structure members.
Remarks
Classification:Confidential B
The command_type argument is an identification number to determine the practical execution command in the
'RF_TEST_REQ' category. Each command_type has its data placeholder union member, without giving an explicit
union structure name, system will extend all available unions and take more time.
The command type number and corresponded structure definitions are designed by L1 protocol team as
communication specifications. PASTA users may need to consult L1 experts to get precise command settings.
Example
import Pasta
context = Pasta.create_context()
26 V1.3 (2020-02-24)
[Link]("mode=usb;comport=auto")
connect_result = [Link]()
transaction = api.get_transaction_api()
MediaTek Confidential
RF_TEST_CMD_GET_RFID = 20
transaction.send_modem_command(rf_command.get_buffer())
Unauthorized reproduction or disclosure of this information in whole or in part is strictly prohibited.
if dut_confirm.status == 0:
This document contains information that is proprietary to MediaTek Inc.
print(dut_confirm.rf_response.[Link]) # print RF id
© 2019 - 2020 MediaTek Inc.
Parameters
Return
Example
V1.3 (2020-02-24) 27
MediaTek Confidential
Parameters
The command_type argument is an identification number to determine the practical execution command in the
'MMRF_TEST_REQ ' category. Each command_type has its data settlement union member, without giving an
explicit union structure name, system will extend all available unions and take more time.
The command type number and corresponded structure definitions are designed by L1 protocol team as
communication specifications. PASTA users may need to consult L1 experts to get precise command settings.
Classification:Confidential B
7.2.7 get_mmrf_confirmation(token, [timeout])
Gets target response message aligned with specific message id (MMRF_TEST_CNF) and transaction serial
number(token).
Parameters
Return
28 V1.3 (2020-02-24)
Parameters
data_buffer byte array [Optional] Sets data buffer to initialize this ERF_TEST_REQ command. The command
structure members will be filled corresponded value gets from data buffer.
Return
Returns an integer value to represent serial number(token) of this transaction and a 'ERF_TEST_REQ' command
codec object can be used to assign values of command structure members.
Remarks
The command_type argument is an identification number to determine the practical execution command in the
'ERF_TEST_REQ ' category. Each command_type has its data settlement union member, without giving an explicit
Classification:Confidential B
union structure name, system will extend all available unions and take more time.
The command type number and corresponded structure definitions are designed by L1 protocol team as
communication specifications. PASTA users may need to consult L1 experts to get precise command settings.
Parameters
V1.3 (2020-02-24) 29
Return
MediaTek Confidential
Returns a DutConfirmation object, its attributes include:
Return
Returns an integer value to represent serial number(token) of this transaction and a 'NRF_TEST_REQ' command
Classification:Confidential B
codec object can be used to assign values of command structure members.
Remarks
The command_type argument is an identification number to determine the practical execution command in the
'NRF_TEST_REQ ' category. Each command_type has its data settlement union member, without giving an explicit
union structure name, system will extend all available unions and take more time.
The command type number and corresponded structure definitions are designed by L1 protocol team as
communication specifications. PASTA users may need to consult L1 experts to get precise command settings.
30 V1.3 (2020-02-24)
7.2.11 get_nrf_confirmation
Gets target response message aligned with specific message id(NRF_TEST_CNF) and transaction serial
number(token).
MediaTek Confidential
Parameters
Return
V1.3 (2020-02-24) 31
8 MessageCodecBuilder Module
This module provides functions to create message codec objects with specified structure name. The codec object
can be used to compose binary data sent to target, and decompose binary data into structure members came
from target. You can get codec builder object as:
MediaTek Confidential
import Pasta
context = Pasta.create_context()
Parameters
Return
Returns a MessageCodec object or python None if the structure name cannot be found in the database.
Classification:Confidential B
Remarks
Example
import Pasta
32 V1.3 (2020-02-24)
Parameters
Return
Returns a MessageCodec object or python None if the structure name cannot be found in the database.
This document contains information that is proprietary to MediaTek Inc.
Remarks
This API is designed to improve the creation performace of some fixed format structures that have a union
member, such as FT_RF_TEST_REQ , FT_RF_TEST_CNF, FT_ERF_TEST_REQ, FT_ERF_TEST_CNF, and so on.
8.1.3 add_structure(structure_definition)
Adds proprietary C structure definitions into the Pasta database, and can be used to create the representative
codec object
Classification:Confidential B
Parameters
Remarks
This API is designed for processing proprietary DUT commands and responses that are not defined in the PASTA
database. Not all C structures syntaxes are supported, such as union and pointer, etc. Please refer to the section
9.1 for the detailed usage example.
V1.3 (2020-02-24) 33
8.2 MessageCodec
MessageCodec is an abstraction class that can ship any types of structure defined in the database file. Developers
can access structure’s data members as normally read/write its attributes using the intuitive operator ".".
import Pasta
MediaTek Confidential
context = Pasta.create_context() # create a pasta context
Return
Remarks
It’s difficult to figure out precise member’s name of a coding structure. This API can enumerate all child members
of MessageCodec object to alleviate development efforts.
Classification:Confidential B
Example
import Pasta
print (member_info)
34 V1.3 (2020-02-24)
8.2.2 get_buffer()
Gets binary data of this MessageCodec object
MediaTek Confidential
Return
Returns a Python byte array object that contains its structure member values
Remarks
© 2019 - 2020 MediaTek Inc.
To access structure’s data members you can use Python class-attribute reference operator "." to get things done.
System will investigate data type of accessing member to guarantee the integrities of message data, an exception
will be raised if it finds invalid data type of value assignment.
No differences for accessing nested structure(structure contains child structure member), each structure type
member can be seen as an individual MessageCodec object has the same capabilities.
Example
import Pasta
nrf_command.type = 10
V1.3 (2020-02-24) 35
9 Developing Samples
This section provides some practical samples to help users dealing some common problems.
MediaTek Confidential
9.1 Process Undefined DUT Commands and Responses
Protocol users might want to verify some under developing commands and messages via Pasta. They will struggle
with how to add these new data structures into Pasta.
Pasta supports adding proprietary c-structure definitions in the user’s Python scripts, and can create
corresponded representative objects for processing DUT transactions.
Classification:Confidential B
struct MY_RESPONSE
{
kal_uint32 result;
kal_uint8 band;
kal_uint16 frequency;
};
"""
context = Pasta.create_context()
codec = context.get_codec_instance()
codec.add_structure(MY_COMMAND_STRUCT_DEFINITION)
36 V1.3 (2020-02-24)
[Link][0].mipi_data = 23
[Link][1].mipi_addr = 100
# .... assign other data ...
# print out the composed data for debugging
print(' '.join('{:02x}'.format(x) for x in request.get_buffer()))
Unauthorized reproduction or disclosure of this information in whole or in part is strictly prohibited.
V1.3 (2020-02-24) 37
The 'boot_device' function in PASTA allows users to boot up testing target devices, such as smartphones or dongle devices, into META mode for testing purposes. This function can be customized for various scenarios: it can automatically search for the appropriate comport or allow specific comport assignments, use default or specified paths for the MetaConsoleTool.exe, and selectively boot smartphone or dongle devices by adjusting the 'device' parameter between 'sp' and 'md.' Such flexibility is critical for integration into automated testing environments .
PASTA manages transaction commands through its APIs that allow the creation, sending, and receiving of commands between devices. The process involves obtaining the relevant transaction API and codec instances from the PASTA context. These instances are used to encode command requests and decode incoming responses, respectively. Codec instances are vital as they translate binary data into structured format, ensuring accurate data interpretation and manipulation for command transactions .
Command types and their associated structure definitions in PASTA are crafted according to communication specifications provided by the L1 protocol team. These definitions guide the execution of practical commands in categories like 'RF_TEST_REQ,' 'MMRF_TEST_REQ,' and 'NRF_TEST_REQ.' PASTA users should consult L1 protocol experts to obtain accurate command settings, ensuring the correct configuration and application of these transaction commands for their testing requirements .
PASTA facilitates querying version information from a DUT by establishing a connection using its DUT communication module and transaction APIs. The user sends a version information query command to the DUT, waits for a response, and subsequently decodes it using message codec instances to extract the software version information. This process enhances the testing framework by automatically gathering essential device metrics, thus reducing manual intervention and improving verification accuracy .
The VISA library is essential for extending PASTA's capability to control RF instruments, a common requirement in automated testing environments. Users must manually install the PyVisa library, which serves as a Python interface to the VISA standard, by executing the command 'pip install -U pyvisa.' Without this library, PASTA’s ability to manage RF instruments would be limited, thus compromising its effectiveness in comprehensive radio frequency testing scenarios .
The install.bat file is pivotal in the initial setup process of the PASTA environment. Executing this batch file is necessary for successfully installing the required components, as indicated by the 'Install completely' message upon completion. Failure to run this setup step may lead to missing module errors when developing or executing PASTA scripts. Additionally, if the META tool package is copied to a different directory, the install.bat must be run again to ensure proper configuration at the new location .
Ensuring the correct Python interpreter version is crucial because PASTA relies on Python 3.7 for its operations, and using an incompatible version may result in runtime errors or script execution failures. Mismatches can lead to erroneous behavior due to potential changes or deprecations between different Python versions, ultimately disrupting the development environment and workflow .
The PASTA context acts as a kernel component container, essential for application operations. The main components include the DUT communication module for device connection and data transmission, the message codec module for encoding/decoding transaction commands, the instrument library module (with limited RF instrument control functions), application interfaces with common usage APIs, and calibration & RF feature units. Each module is crucial for specific functionalities within the PASTA software, facilitating thorough testing and automation .
It is recommended to install Python 3.7 for developing with PASTA to ensure debugging efficiency and comprehensive development environments. For users who prefer not to install new software, alternatives such as using the embedded Python interpreter available as PastaRuntime.exe can substitute for Python 3.7. Utilizing this executable allows PASTA script execution without needing a separate Python installation .
To shut down a device post script execution using PASTA, one can employ the Android Debug Bridge (adb) command: 'adb.exe shell reboot -p.' This practice is important to ensure that the device returns to a safe and defined state, preventing any unintended operation or connectivity issues, particularly in an automated or shared testing environment .