# Qwantum ASIC Command Layer Functions

This section describes the Qwantum ASIC command layer functions.

The reference code defines the data length equates and four separate buffers to store individual tracks or the entire card data as shown below.

```
/* Length of Various Card Data Fields */
#define QTM_CD_STATUS_LEN    4 // bytes - from QTM_STAT1_REG & QTM_REV_REG
#define QTM_CD_QT_LEN        24 // words – Qwantum Token Format & CRC excluded
#define QTM_CD_QTEXT_LEN     96 // words - Qwantum Token Format & CRC excluded

/* The following definitions are in word count */
#define QTM_CD_TRACK_A_LEN    44 // leading/trailing zeros excluded 
#define QTM_CD_TRACK_B_LEN    QTM_CD_TRACK_A_LEN
#define QTM_CD_TRACK_C_LEN    QTM_CD_TRACK_A_LEN
#define QTM_CD_TRACK_BQT_LEN (QTM_CD_TRACK_B_LEN+QTM_CD_QT_LEN) 
#define QTM_CD_TRACK_BQTEXT_LEN (QTM_CD_TRACK_B_LEN+QTM_CD_QTEXT_LEN)
#define QTM_CD_TRACK_ABC_LEN	(QTM_CD_TRACK_A_LEN*3) 
#define QTM_CD_TRACK_ABCQT_LEN 
((QTM_CD_TRACK_A_LEN*3)+QTM_CD_QT_LEN)
#define QTM_CD_TRACK_ABCQTEXT_LEN 
((QTM_CD_TRACK_A_LEN*3)+QTM_CD_QTEXT_LEN)

/* Track data buffers */
static unsigned short tka_data[QTM_CD_TRACK_A_LEN]; 
static unsigned short tkc_data[QTM_CD_TRACK_C_LEN];
static unsigned short tkbmp_data[QTM_CD_TRACK_BQTEXT_LEN]; 
static unsigned short tkabcmp_data[QTM_CD_TRACK_ABCQTEXT_LEN];

```

## qasic\_pair

This function pairs the ASIC with the microcontroller. Since the reference code assumes the security certification code registers are not locked, it reads the security certification code registers and saves them in the structure variable, sec\_cert\_code. The function writes the saved register values back to the same registers for the pairing operation.&#x20;

This code is readable with the SPI interface unless the Read Security Lock is set. Once this lock is set the code is no longer readable. The paired microcontroller should store the security certification code in NVM or in a database it can access if the Security Lock feature is to be used.

The reference code doesn’t use the Security Lock feature.

## qasic\_config <a href="#bookmark48" id="bookmark48"></a>

This function should be called during reset or power-on after the SPI master is configured properly. It checks if the ASIC is in the OFF state. If it is not, it forces the ASIC to enter the OFF state.

Once the ASIC enters the OFF state, it configures the ASIC and then changes the ASIC state to the ATR state. It verifies the ASIC state transition to the ATR state is finished before exiting the routine.

For any reason, if the ASIC fails to move to the ATR state, it will not read the card data when swiped.

## qasic\_read\_asic\_status <a href="#bookmark49" id="bookmark49"></a>

This function constructs the 32-bit ASIC Status for the most recent card swipe from the following sources.

* Configuration register (address 0x00)
* Status 1 register (address 0x02)
* Test/ASIC Revision register (address 0x10)

The ASIC Status Bits are generated by the ASIC in the data strobe mode, but it needs to be constructed by firmware in the SPI mode. Therefore, if Qwantum ASIC operating in the SPI mode is expected to be backward compatible with MagTek Delta ASIC or MagnePrint ASIC application, this function should be included in firmware.

## qasic\_read\_track\_a <a href="#bookmark50" id="bookmark50"></a>

This function is invoked by QASIC\_get\_card\_data\_alt to read Track A data from the ASIC using the RTKA command.

## qasic\_read\_track\_b <a href="#bookmark51" id="bookmark51"></a>

This function is invoked by QASIC\_get\_card\_data\_alt to read Track B data and Qwantum Token from the ASIC using the RTKBQT command. It stores the track B data only in the buffer from the caller.

## qasic\_read\_track\_c <a href="#bookmark52" id="bookmark52"></a>

This function is invoked by QASIC\_get\_card\_data\_alt to read Track C data from the ASIC using the RTKC command.

## qasic\_read\_qt <a href="#bookmark53" id="bookmark53"></a>

This function returns Qwantum Token in the buffer from the caller, QASIC\_get\_card\_data\_alt. The call to this function should come after calling qasic\_read\_track\_b because the track B data and Qwantum Token are read using the RTKBQT command from the ASIC in qasic\_read\_track\_b.

## qasic\_get\_qt\_data\_rev <a href="#bookmark54" id="bookmark54"></a>

This function constructs Qwantum Token revision based on the configuration information and stores it in a variable, qtDataRev. This variable is used in Qwantum Token Status Byte #0.

## qasic\_reset <a href="#bookmark55" id="bookmark55"></a>

This function sends the Reset command to the ASIC. All components within the ASIC are reset except the SPI interface. The SPI interface is under reset when SSELn=0. After the ASIC exits reset, it will enter the OFFSET CORRECTION state, calibrating to correct input offsets of Track A, Track B, and Track C. After the offset calibration is complete, the ASIC will enter the ERASEMEM state to clear all the content stored in the internal buffers. After ERASEMEM is complete, the ASIC will enter the OFF state.

## qasic\_read\_reg <a href="#bookmark56" id="bookmark56"></a>

This function reads the Qwantum ASIC user register and returns the value to the caller.

## qasic\_write\_reg <a href="#bookmark57" id="bookmark57"></a>

This function write the value from the caller to the specified ASIC user register.

## qasic\_select\_device <a href="#bookmark58" id="bookmark58"></a>

This function configures the multiplexed MISO/GPIO pin as MISO so the pin can be used for the SPI protocol and selects the Qwantum ASIC. The actual implementation in the product application can be different from the refence code.

## qasic\_release\_device <a href="#bookmark59" id="bookmark59"></a>

This function configures the multiplexed MISO/GPIO pin as GPIO so the pin can be used for interrupt if needed and releases the Qwantum ASIC. The actual implementation in the product application can be different from the refence code.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developer.magtek.com/qwantum-services/qwantum-asic/documentation/msr-chip-spi-firmware-implementation-guide/qwantum-asic-spi-communication-interface/qwantum-asic-command-layer-functions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
