as3993 ST25RU3993 Firmware
Data Structures | Macros | Functions | Variables
appl_commands.c File Reference: ST25RU3993 Communication protocol and instruction
#include "as3993_config.h"
#include "platform.h"
#include "global.h"
#include "gen2.h"
#include "as3993_public.h"
#include "appl_commands.h"
#include "logger.h"
#include "errno.h"
#include "iso6b.h"
#include "timer.h"
#include "string.h"
#include <limits.h>
#include "as3993.h"
#include "tuner.h"

Go to the source code of this file.

Data Structures

struct  CmdBuffer
 

Macros

#define APPLDEBUG   0
 
#define SESSION_GEN2   1
 
#define SESSION_ISO6B   2
 
#define MAX_SELECTS   2
 
#define POWER_DOWN   0
 
#define POWER_NORMAL   1
 
#define POWER_NORMAL_RF   2
 
#define POWER_STANDBY   3
 
#define APPLOG(...)
 
#define APPLOGDUMP(...)
 

Functions

static TuningTable tuningTable __attribute__ ((far)) = {15, 15, 15}
 
s8 gen2ReadTID (Tag *tag)
 
static void powerDownReader (void)
 
static void powerUpReader (void)
 
static void adaptSlotCounter (int num_of_tags)
 
static BOOL continueCheckTimeout ()
 
static void checkAndSetSession (u8 newSession)
 
void callWrongCommand (void)
 
void callAntennaPower (void)
 
void callAntennaTuner (void)
 
void callAutoTuner (void)
 
static u8 addToTuningTable (void)
 
void callTunerTable (void)
 
void callReaderConfig (void)
 
u8 writeRegister (u8 addr, u8 value, u16 *txSize, u8 *txData)
 
u8 readRegister (u8 addr, u16 *txSize, u8 *txData)
 
void callConfigTxRx (void)
 
void callConfigGen2 (void)
 
u8 readRegisters (u16 *txSize, u8 *txData)
 
void callInventory6B (void)
 
void callReadFromTag6B (void)
 
void callWriteToTag6B (void)
 
void callInventoryGen2Internal ()
 
void callInventoryGen2 (void)
 
void callSelectTag (void)
 
void callWriteToTag (void)
 
void callChangeFreq (void)
 
void callReadFromTag (void)
 
void callLockUnlockTag (void)
 
void callKillTag (void)
 
void callStartStop (void)
 
void callGenericCommand (void)
 
int doCyclicInventory (void)
 
u8 commands (u8 protocol, u16 rxSize, const u8 *rxData, u16 *txSize, u8 *txData)
 
u8 sendTagData (u8 *protocol, u16 *txSize, u8 *txData, u16 remainingSize)
 
void callConfigPA (void)
 
void callInventoryParams (void)
 

Variables

static struct gen2Config gen2Configuration = {TARI_25, GEN2_LF_256, GEN2_COD_MILLER4, TREXT_OFF, 0, GEN2_SESSION_S0, 0}
 
u8 gen2qbegin = 4
 
static u16 inventoryDelay = 0
 
static u16 scanTuningInterval = 500
 
static u16 tuningCounter = 0
 
static u8 scanRetuningLevel = 30
 
static int num_selects
 
static struct gen2SelectParams selParams [MAX_SELECTS]
 
static u8 num_of_tags
 
static u8 tagDataAvailable
 
u16 readerInitStatus
 
Tag tags_ [MAXTAG]
 
TagselectedTag
 
Freq Frequencies
 
static u8 guiActiveProfile = 1
 
static u8 guiNumFreqs =4
 
static u32 guiMinFreq = 865700
 
static u32 guiMaxFreq = 867500
 
static s8 rssiThreshold
 
static u16 idleTime = 0
 
static u16 maxSendingTime = 10000
 
static u16 listeningTime = 1
 
static u16 maxSendingLimit
 
static u8 maxSendingLimitTimedOut
 
static u8 cyclicInventory
 
static u8 autoAckMode
 
static u8 fastInventory
 
static BOOL adaptiveQ = 0
 
static u8 adjustmentRounds = 2
 
static u8 adjustmentUpThreshold = 25
 
static u8 adjustmentDownThreshold = 13
 
static u8 readTIDinInventoryRound
 
static u8 rssiMode
 
static u8 readerPowerDownMode
 
static s8 inventoryResult
 
static u8 usedAntenna = 2
 
static struct CmdBuffer cmdBuffer
 
static u16 currentFreqIdx
 
static u8 currentSession = 0
 

Detailed Description

Functions which handle commands received via USB or UART.

This file contains all functions for processing commands received via either USB or UART. It implements the parsing of reports data, executing the requested command and sending data back.

A description of the protocol between host and FW is included in the documentation for commands(). The documentation of the various appl command functions (call*) will only discuss the payload of the command data and will not include the header information for every transmitted packet, as this is already described for commands().


The frequency hopping is also done in this file before calling protocol/device specific functions.

Author
Ulrich Herrmann
Bernhard Breinbauer
Rene Eggerstorfer

Definition in file appl_commands.c.

Macro Definition Documentation

#define APPLDEBUG   0

Define this to 1 if you want to have logging for appl commands.

Definition at line 71 of file appl_commands.c.

#define APPLOG (   ...)

macro used for printing debug messages if USE_LOGGER is set

Definition at line 94 of file appl_commands.c.

#define APPLOGDUMP (   ...)

macro used for dumping buffers if USE_LOGGER is set

Definition at line 95 of file appl_commands.c.

#define MAX_SELECTS   2

Maximum of consecutive select commands currently supported.

Definition at line 79 of file appl_commands.c.

#define POWER_DOWN   0

value for readerPowerDownMode. Activates power down mode. (EN low)

Definition at line 82 of file appl_commands.c.

#define POWER_NORMAL   1

value for readerPowerDownMode. Activates normal mode. (EN high, RF off, stdby 0)

Definition at line 84 of file appl_commands.c.

#define POWER_NORMAL_RF   2

value for readerPowerDownMode. Activates normal mode with rf field on. (EN high, RF off, stdby 0)

Definition at line 86 of file appl_commands.c.

#define POWER_STANDBY   3

value for readerPowerDownMode. Activates standby mode. (EN high, RF off, stdby 1)

Definition at line 88 of file appl_commands.c.

#define SESSION_GEN2   1

Identifier for gen2 protocol session

Definition at line 74 of file appl_commands.c.

#define SESSION_ISO6B   2

Identifier for ISO6B protocol session

Definition at line 76 of file appl_commands.c.

Function Documentation

static TunerParameters tunerParams __attribute__ ( (far)  ) = {15, 15, 15}
static

The tuningTable contains a list of frequencies and values for the tuner for every frequency. When frequency hopping is performed (hopFrequencies()) the closest frequency in the list is looked up and the corresponding tuner values are applied to the DTCs of the tuner. The tuningTable can be modified via callTunerTable().

Default and current tuner settings.

void adaptSlotCounter ( int  num_of_tags)
static

This function adapts the Slot Counter Q based on the number of found tags.
The slot counter gen2qbegin will be incremented if (slots <= (2.0*num_of_tags). The slot counter gen2qbegin will be decremented if (slots/2) > (2.0* num_of_tags).

Parameters
num_of_tagsNumber of Found Tags
Returns
none

Definition at line 3671 of file appl_commands.c.

static u8 addToTuningTable ( void  )
static

adds data in current USB buffer to tuning table, should be only called from callAntennaTuner().

Definition at line 689 of file appl_commands.c.

void callAntennaPower ( void  )

This function enables/disables the RF field and is executed when a stream packet with protocol = CMD_ANTENNA_POWER is received.
The payload of the stream packet looks like this:

Byte0 1
Content0x00 for off
0xFF for on
eval_mode

eval_mode: reserved, should be zero
The device sends back:

Byte0
Content0

Status of the reply packet indicates success or error.

Definition at line 402 of file appl_commands.c.

void callAntennaTuner ( void  )

This function sets and reads antenna tuner network related values and is executed when a stream packet with protocol = CMD_ANTENNA_TUNER is received. There are different kind of tuning networks available. The full network which is currently supported by the Firmware looks like this:

.--- L ---.
| |
in ----.----.----- L --.--C_len--.--.-----.-----.----- out
| | | | |
C_in L C_out L R
| | | | |
___ ___ ___ ___ ___
- - - - -
' ' ' ' '

On the Femto Reader there is a reduced tuning network: Clen is missing.
The DTCs capacity values range from:

  • C_* = 32 steps from 1.3pF to 5.5pF, step size 0.131pF, +-10%

The format of the payload from the host is: Get/Set current tuner parameters:

Byte 0 1 2 3 4 5
Content set_cin cin set_clen clen set_cout cout

The values are only being set if the proper set_X value is set to 1.
The device sends back:

Byte 0 1 2 3 4 5
Content reserved (0) cin reserved(0) clen reserved(0) cout

Reply status will be set to ERR_NONE if operation was successful. If reader does not support tuning status will be set to ERR_REQUEST.

Definition at line 501 of file appl_commands.c.

void callAutoTuner ( void  )

This function allows to trigger a auto tuning cycle. For in detail information to antenna tuning see callAntennaTuner() and tuner.h.
The function is executed when a stream packet with protocol = CMD_AUTO_TUNER is received. The format of the payload from the host is:

Byte 0
Content auto_tune

If the auto_tune value is not equal zero a auto tuner cycle will be started:


The device does not send a reply back, but the result of the auto tuning procedure can be read by callAntennaTuner().

Note
Depending on the used auto tune algorithm there will be some delay until the tune algorithm finshed and the new tuned DTC values are avaiable. The tuner algorithm 2 takes roughly 3 seconds, algorithm 1 is faster.

Definition at line 612 of file appl_commands.c.

void callChangeFreq ( void  )

This function sets/adds/measures frequency related stuff and is executed when a stream packet with protocol = CMD_CHANGE_FREQ is received.

Note
The freq parameter contains the frequency in kHz and is always 3 bytes long. The first byte in the payload is the LSB. The frequency is extracted from the payload like this:
u32 freq;
freq = 0;
freq += (u32)cmdBuffer.rxData[2];
freq += ((u32)cmdBuffer.rxData[3]) << 8;
freq += ((u32)cmdBuffer.rxData[4]) << 16;

The format of the payload received from the host is one of the following:

  • Get RSSI level

    Byte01 .. 3
    Content1 (SubCmd)freq

    The reader replies with:

    Byte0 1 2
    ContentI-channel Q-channel -

    The reader replies with ERR_REQUEST for HW with no external PA.

  • Get Reflected Power level

    Byte01 .. 34
    Content2 (SubCmd)freq Apply Tuner Setting

    to which the reader replies with:

    Byte01
    ContentI-channelQ-channel

  • Add frequency to frequency list used for hopping. If clear_list is set the list will be deleted before adding the new frequency. rssi_threshhold and profile_id are global values and not set for every frequency. Therefore the last value which they have been set to is valid.

    Byte01 .. 34 5 6
    Content4 (SubCmd)freq clear_listrssi_threshhold(dBm)profile_id

    Where rssi_threshold is used by the "listen before talk" feature: Before hopping to a new channel the reader listens on the frequency if the rssi value is smaller than this threshold.
    profile_id is used by the Reader Suite to enumerate the various frequency profiles.
    The reader replies with this:

    Byte0
    Content0x00

    Status will be set to ERR_MEM if no more frequency can be added (see MAXFREQ). If command was successful status will be ERR_NONE.

  • Get frequency list related parameters

    Byte0
    Content5 (SubCmd)

    The reader replies with:

    Byte0 1 .. 3 4 .. 6 7 8
    Contentprofile_idmin_freqmax_freqcurr_num_freqshost_num_freqs

    Where profile_id and rssi_threshold refer to the values used in SubCmd 4. Values for the other parameters are:

    Namevalues
    min_freqMinimum frequency of current frequency list.
    max_freqMaximum frequency of current frequency list.
    curr_num_freqNumber of frequencies in current frequency list.
    host_num_freqNumber of frequencies the host sent to add with SubCmd 4. Might be bigger than curr_num_freq.

  • Set frequency hopping related parameters

    Byte01 .. 2 3 .. 4 5 .. 6 7
    Content8 (SubCmd)listeningTimemaxSendingTimeidleTimerssi threshold

    The reader replies with:

    Byte0
    Content0x00

    Status of reply will be ERR_NONE.

  • Get frequency hopping related parameters

    Byte0
    Content9 (SubCmd)

    The reader replies with:

    Byte0 .. 1 2.. 3 4 .. 5
    Contentlistening_timemax_sending_timeidle_time

    Status of reply will be ERR_NONE.

  • Continuous modulation test
    Byte01 .. 34 .. 5 6 7 .. 16
    Content16 (SubCmd)freq duration in msrandomrandom_data
    causes continuous modulation of the RF field for given duration. If random is set to 0 Gen2 NAK commands are sent (On AS3980 NAK direct command is not available therefore Transmit with CRC with dummy payload is used). If random is set to 1 pseudo random data is sent. For this the random_data and timer values are used as random data to send.
    Note
    The reader does not reply any data to this command as it enters continuous modulation mode directly.

    Note
    Communication with host is not possible while continous modulation is performed. Wait at least for duration time before starting communication attempt with reader.

Definition at line 2177 of file appl_commands.c.

void callConfigGen2 ( void  )

This function sets and reads various gen2 related settings and is executed when a stream packet with protocol = CMD_CONFIG_TX_RX is received. Most of the parameters are related to the QUERY commmand of the Gen2 protocol specification.
The format of the payload from the host is:

Byte 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Content set_lf lf set_coding coding set_session session set_trext trext set_tari tari set_qbegin qbegin set_sel sel set_target target

The values are only being set if the proper set_X value is set to 1.
The device sends back:

Byte 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Content reserved(0) lf reserved(0) coding reserved(0) session reserved(0) trext reserved(0) tari reserved(0) qbegin reserved(0) sel reserved(0) target

Values for the different parameters are:

Namevalues
lf0 = 40 kHz,
3 = 80 kHz not AS3993,
6 = 160 kHz,
8 = 213 kHz,
9 = 256 kHz,
12 = 320 kHz,
15 = 640 kHz
coding0 = FM0,
1 = Miller2,
2 = Miller4,
3 = Miller8
session0 = S0,
1 = S1,
2 = S2,
3 = S3
trext0 = short preamble, no pilot tone,
1 = long preamble, pilot tone
tari0 = 6.25 us,
1 = 12.5 us,
2 = 25 us
qbegin0 .. 15. Initial gen2 round is 2^qbegin long. Please be careful with higher values.
sel0 .. 1 = All,
2 = ~SL,
3 = SL
target0 = A,
1 = B

Definition at line 1383 of file appl_commands.c.

void callConfigPA ( void  )

This function changes the PA HW configuration and is executed when a stream packet with protocol = CMD_CALL_PA_ID is received.
This function is currently only available for Newton readers. The payload of the stream packet looks like this:

Byte0 1
ContentReadWriteModeConfig Word


ReadWriteMode:
0=> Read, 1=>Write and Read
ConfigWord:
Bit 0 (LSB) : Value for G8
Bit 1 (2LSB): Value for G16
1 => High
0 => Low
The reply of this command looks like this:

Byte1
ContentConfig Word


Status of the reply packet indicates success or error.

Definition at line 3489 of file appl_commands.c.

void callConfigTxRx ( void  )

This function sets and reads various RF Tx/Rx related settings and is executed when a stream packet with protocol = CMD_CONFIG_TX_RX is received.

Note
Not every parameters is available on every board, eg: switching antenna boards is only available on boards with 2 antenna ports. The FW will silently ignore not applicable parameters.

The format of the payload from the host is:

Byte 0 1 2 3
Content set_sensitivity sensitivity set_antenna antenna id

The values are only being set if the proper set_X value is set to 1.
The device sends back:

Byte 0 1 2 3
Content reserved(0) sensitivity reserved (0) antenna id

Values for the different parameters are:

Namevalues
sensitivity-128 .. 127 (dBm)
antenna id1: antenna port 1
2: antenna port 2

Definition at line 1187 of file appl_commands.c.

void callGenericCommand ( void  )

This function executes an generic command from a previously selected gen2 tag when a stream packet with protocol = CMD_GENERIC_CMD_ID is received.
The format of the payload from the host is:

Byte0..34..5[UpperNibble]5[LowerNibble]..6789..9+TransmitByteSize
Contentpasswordlength_transmit_datalength_receive_datadirect commandno_response_timetransmit data

Parameters are:

  • password: access password; if the password is nonzero the tag will accessed first
  • length_transmit_data: bit size of the data to transmit without RN16 and CRC-16
  • length_receive_data: bit size of the data to receive without RN16 and CRC-16
  • direct command:
    • 0x90 AS3993_CMD_TRANSMCRC
    • 0x91 AS3993_CMD_TRANSMCRCEHEAD
    • 0x92 AS3993_CMD_TRANSMNOCRC
  • no_response_time: no respone interrupt wait time
  • transmit data: data to transmit to the tag

The device sends back the following report:

Byte012..2+ReceivedByteSize
Contentstatuslength_received_datareceived data

Definition at line 2683 of file appl_commands.c.

void callInventory6B ( void  )

This function performs one inventory round using ISO18000-6b protocol. The format of the payload from the host is:

Byte01..89
Contentaddressword_data mask

where

  • address: address where data will be compared
  • word_data: data which will be compared
  • mask: the mask value for GROUP_SELECT_EQ command, 0 will select all tags

The device sends back:

Byte0 1..8 9..16...
Contentnumber of tagsID of first tagID of second tag...

Definition at line 1455 of file appl_commands.c.

void callInventoryGen2 ( void  )
This function performs a single gen2 protocol inventory round according to

parameters configured by callConfigGen2() and callSelectTag().
The function is executed when a stream packet with protocol = CMD_INVENTORY_GEN2 is received.
The format of the payload from the host is:

Byte0 1 2
ContentautoAck tid(2LSB)+fast(LSB) rssi

Where autoAck defines if the autoACK mode of the reader is used. If autoAck = 0 autoACK will not be used, otherwise autoACK will be used. The parameter tid defines if a read of the TID Memory will be performed in inventory rounds. If tid = 1 the TID memory will be read, otherwise no read will be done. Parameter fast defines how the inventory rounds are performed. If fast = 0 the inventory round is executed until the tag is in the Open state. If fast = 1 the inventory round is stopped when the tag reaches Acknowledged state (no Req_RN command is sent). See Gen2 protocol specification page 47: Tag state diagram for details.
The rssi parameter defines which rssi value should be measured when getting a tag. The value of rssi parameter will be written to register 0x29.
The device sends back all the tags using the following report:

Byte 0 1 2 3 4 5 .. 7 8 9 10 11 .. 11+epclen 12+epclen 13+epclen .. 15+epclen ...
Content cyclic tags_left tags_in_reply AGC and status (reg 0x2A) RSSI_value (reg 0x2B) base_freq epclen+pclen pc[0] pc[1] epc next tag: RSSI next tag: base_freq ...
  • cyclic: is set to 1 if cyclic(continuous) inventory rounds are performed, otherwise 0.
  • tags_left: number of tags still to be sent after this reply. The next tag data will be sent in next iteration of sendTagData().
  • tags_in_reply: number of tags in reply.
  • agc and status: subc_phase, agc status, i/q channel (content of register 0x2A)
  • RSSI_value: upper 4 bits I channel, lower 4 bits Q channel (content of register 0x2B)
  • base_freq: base frequency at which the tag was found.
  • epclen+pclen: added length of pc and epc.

Sending the reply is implemented in function sendTagData(), which has to be called repeatedly until all tag data has been sent.

Definition at line 1667 of file appl_commands.c.

void callInventoryGen2Internal ( )

This function is called by callInventoryGen2() and doCyclicInventory() and performs the actual Gen2 inventory round.

Definition at line 1589 of file appl_commands.c.

void callInventoryParams ( void  )

This function changes some Inventory Parameters and is executed when a stream packet with protocol = CMD_CALL_INV_PARAMS_ID is received.
The payload of the stream packet looks like this:

Byte0 1..2 3 4 5 6 7 8 9..10 11
ContentWrite Round DelayRound DelayWrite Query Adjust ParametersAdaptive QAddtional RoundsQueryAdjust Up ThresholdQueryAdjust Down ThresholdWrite Tuning ParametersTuning IntervalTuning Deviation


Write Round Delay: 0 => Read, 1 => Write and Read
Round Delay: Inventory Round Delay
Write Query Adjust Parameters: 0 => Read, 1 => Write and Read
Adaptive Q: 0 => Off, 1 => On, see function inventoryGen2
Addtional Rounds: see function gen2SearchForTags
QueryAdjust Up Threshold: see function gen2SearchForTags
QueryAdjust Down Threshold: see function gen2SearchForTags
Write Tuning Parameters: 0 => Read, 1 => Write and Read
Tuning Interval: see function hopFrequencies
Tuning Deviation: see function hopFrequencies
The reply of this command looks like this:

Byte0..1 2 3 4 5 6 7 8
ContentRound DelayAdaptive QAddtional RoundsQueryAdjust Up ThresholdQueryAdjust Down ThresholdWrite Tuning ParametersTuning IntervalTuning Deviation


Status of the reply packet indicates success or error.

Definition at line 3541 of file appl_commands.c.

void callKillTag ( void  )

This function kills a gen2 tag and is executed when a stream packet with protocol = CMD_KILL_TAG is received.
The format of the payload from the host is:

Byte0 .. 3 4
Contentkill passwordrecom

where:

  • recom: see GEN2 standard: table on "XPC_W1 LSBs and a Tag's recomissioned status"

The device sends back the following report:

Byte0
Contentstatus

Definition at line 2594 of file appl_commands.c.

void callLockUnlockTag ( void  )

This function locks\unlocks a gen2 tag and is executed when a stream packet with protocol = CMD_LOCK_UNLOCK_TAG is received.
The format of the payload from the host is:

Byte0..2 3 .. 5
Contentmask_and_actionaccess password

The device sends back the following report:

Byte0
Contenttag_code

Definition at line 2534 of file appl_commands.c.

void callReaderConfig ( void  )

This function gets/sets the current reader config and is executed when a stream packet with protocol = CMD_READER_CONFIG is received. The reader config contains the power down mode which can be changed and various non-changeable parameters like: error codes, FW compile time switches, ...
The format of the payload from the host is:

Byte 0 1
Content set_powermode powermode

The values are only being set if the proper set_X value is set to 1.
The powermode value will be applied to readerPowerDownMode variable and used in powerDownReader() and powerUpReader().
The device reply payload is:

Byte0 1 2 3 4 5 6 7 8
ContentWrongChipIdInitErrCodeVCOPAINPUTAntSwitchTunerpowerDownModeHardware ID

The values for the parameters are:

ParameterValues
WrongChipId0-99: No Error. FW and reader chip match. The value is the last to digits of the reader chip eg: for AS3993 the value is 93.
0xFF: FW is not compatible with the reader chip on this board.
Init Error0: No Error. Init of reader chip was successful.
1: Writing and reading SPI failed.
2: Reset via EN low + high failed.
3: IRQ line failed.
4: Crystal not stable (Bit0 in AGC and Internal Status register 0x2A).
5: PLL not locked (Bit1 in AGC and Internal Status register 0x2A)
VCO0: FW was compiled for internal VCO (INTVCO).
1: FW was compiled for external VCO (EXTVCO).
PA0: FW was compiled for internal PA (INTPA).
1: FW was compiled for external PA (EXTPA).
Input0: FW was compiled for balanced input (BALANCEDINP).
1: FW was compiled for single input (SINGLEINP).
AntSwitch0: FW was not compiled for 2 antenna ports.
1: FW was compiled to use 2 antenna ports (ANTENNA_SWITCH).
TunerOr'ed tuner configuration, every bit repesents a tunable cap (DTC).
0: FW does not support tuning.
0x01: Cin tuner is used (TUNER_CIN).
0x02: Clen tuner is used (TUNER_CLEN).
0x04: Cout tuner is used (TUNER_COUT).
other bits: not yet supported.
powerDownModeCurrently configured power down mode of reader.
Available modes are: POWER_DOWN, POWER_NORMAL, POWER_NORMAL_RF and POWER_STANDBY.
Hardware IDIdentification number for the board (HARDWARE_ID_NUM)
Available IDs are defined in as3993_config.h

If any of the parameters is set to 0xFF an unidentified error/configuration occured.

Definition at line 995 of file appl_commands.c.

void callReadFromTag ( void  )

This function reads from a previously selected gen2 tag and is executed when a stream packet with protocol = CMD_READ_FROM_TAG is received.
The format of the payload from the host is:

Byte01..45..8
Contentmem_bankaddresspassword

rxSize divided by two defines the number of words to be read. If rxSize is odd then word by word reading is used. If even the desired memory is read as one bulk. Parameters are:

  • mem_bank:
    • 0:reserved membank
    • 1:EPC membank
    • 2:TID membank
    • 3:USER membank
  • address: the wordPtr where to read from

The device sends back the following report:

Byte0..txSize(max)
Contentdata

If the returned error is ERR_HEADER, the txSize will be odd and the last byte will be the error code returned by the tag.

Definition at line 2433 of file appl_commands.c.

void callReadFromTag6B ( void  )

This function reads from a tag using ISO18000-6b protocol command READ. The format of the payload from the host is:

Byte0..78
ContentID address

The device sends back:

Byte0..7
Contentword_data

Definition at line 1508 of file appl_commands.c.

void callSelectTag ( void  )

This function stores or clears gen2 select command parameters. The gen2 select based on these parameters can be executed with the function performSelects.
A Gen2 tag can be singulated using the given mask for subsequent operations like inventory/read/write. Several (MAX_SELECTS) Select commands can be configured, which are executed sequentially, allowing union and intersection based tag partitioning. See Gen2 protocol specification for further details.
This function is executed when a stream packet with protocol = CMD_SELECT_TAG is received.

Note
This command will reply with ERR_REQUEST on AS3980 as Select command is not supported by AS3980.

The format of the payload received from the host is one of the following:

  • Clear list of Select commands (no Select commands is executed):

    Byte 0 ...
    Content 0x00 (SubCmd ID) ignored

    The device sends back status ERR_NONE and no payload.

  • Add to list of Select commands, execute the Select commands and try to singulate a tag:

    Byte 0 1 2 3 4 .. 5 6 7 8 .. 8 + mask_len
    Content 0x01 (SubCmd ID) target action mem_bank address mask_len truncate mask

    The device sends back a status (no payload). ERR_MEM if no more select command can be selected or a specific Gen2 error if singulating tag failed.

  • Clear list of Select commands, add to list of Select commands, execute the Select commands and try to singulate a tag:
    Byte 0 1 2 3 4 .. 5 6 7 8 .. 8 + mask_len
    Content 0x02 (SubCmd ID) target action mem_bank address mask_len truncate mask
    The device sends back a status (no payload). ERR_MEM if no more select command can be selected or a specific Gen2 error if singulating tag failed.

Values for the different parameters are:

Namevalues
target0 = Inventoried (S0),
1 = Inventoried (S1),
2 = Inventoried (S2),
3 = Inventoried (S3),
4 = SL,
>4 = RFU
actionAction tag should perform is Select matches. See Table 6.20 in Gen2 protocol specification.
mem_bank0 = RFU,
1 = EPC,
2 = TID,
3 = User
address16bit pointer in memory bank, where mask should be applied. Will be converted into EBV format before Select command is sent.
mask_lenLength of mask in bits.
truncate0 = Disable truncation.
1 = Enable truncation.
maskActual mask data.

Definition at line 1849 of file appl_commands.c.

void callStartStop ( void  )

This function starts/stops cyclic inventory rounds and is executed when a stream packet with protocol = CMD_START_STOP is received.
The cyclic inventory rounds are performed by calling callInventoryGen2Internal() from the main loop. Therefore after starting a cyclic inventory, the host has to expect data just like after issueing the callInventoryGen2() because sendTagData() will be called repeatedly.
The format of the payload from the host is:

Byte01234
ContentupdatestartautoAcktid(2LSB)+fast(LSB)rssi

If update is zero the command is ignored. Parameter start defines if the cyclic inventories are started (1) or stopped (0).
For description of autoAck,tid, fast and rssi parameters see callInventoryGen2().
The device sends back:

Byte0
Contentcurrent start value

Subsequently callInventoryGen2() result packets are returned in a dense continuous loop.

Definition at line 2639 of file appl_commands.c.

void callTunerTable ( void  )

This function allows to update the tuner table. For in detail information to antenna tuning see callAntennaTuner() and tuner.h.
The function is executed when a stream packet with protocol = CMD_TUNER_TABLE is received. The format of the payload received from the host is one of the following:

  • Get current tuning table size:

    Byte 0
    Content 0x00 (SubCmd ID)

    The device sends back:

    Byte 0 1 2
    Content 0x00 (SubCmd ID) maximum tuning table size this device supports current tuning table size

  • Delete current tuning table:

    Byte 0
    Content 0x01 (SubCmd ID)

    The device sends back:

    Byte 0 1 2
    Content 0x01 (SubCmd ID) maximum tuning table size this device supports n/a

  • Add new entry in tuning table:

    Byte 0 1..3 4 5 6 7 8..9 10 11 12 13 14..15
    Content 0x02 (SubCmd ID) frequency Ant1: tune enable Ant1: cin Ant1: clen Ant1: cout Ant1: I*I+Q*Q Ant2: tune enable Ant2: cin Ant2: clen Ant2: cout Ant2: I*I+Q*Q

    Adds the data to the internal tuning table. The first set of data is for antenna 1 the second set for antenna 2.
    The device responds:

    Byte 0 1 2
    Content 0x02 (SubCmd ID) remaining size in tuningTable n/a

    If no more space is left in tuningTable the status will be set to ERR_NOMEM. If adding to tuningTable was successful status will be set to ERR_NONE.

  • If the device does not support antenna tuning or if a unsupported SubCmd ID was received the device sends back:
    Byte 0 1 2
    Content 0xFF 0x00 n/a
    The reply status will be set to ERR_REQUEST.

Definition at line 880 of file appl_commands.c.

void callWriteToTag ( void  )
This function writes to a previously selected (callSelectTag()) gen2 tag

and is executed when a stream packet with protocol = CMD_WRITE_TO_TAG is received.
The format of the payload from the host is:

Byte012 .. 56 .. (rxsize-1)
Contentmem_bankaddressacces_pwdata

where

  • mem_bank:
    • 0:reserved membank
    • 1:EPC membank
    • 2:TID membank
    • 3:USER membank
  • access_pw: if access password is nonzero the tag will be accessed first. (tag enters Secured state.)

The device sends back:

Byte0 1
Contentnum_words_writtentag error code if status==ERR_HEADER

Definition at line 1940 of file appl_commands.c.

void callWriteToTag6B ( void  )

This function writes to a tag using ISO18000-6b protocol command WRITE. The format of the payload from the host is:

Byte0..7 8 9
ContentID of the tagaddressbyte_data

The device sends back:

Byte0
Contentacknowledge

Definition at line 1552 of file appl_commands.c.

void callWrongCommand ( void  )

Dummy appl command which is called if an invalid command ID was received. Logs error message and returns error ERR_REQUEST to host.

Definition at line 343 of file appl_commands.c.

static void checkAndSetSession ( u8  newSession)
static

This function can be used instead of continueCheckTimeout() to circumvent allocation timeouts as this function always returns 1. This funcition checks the current session, if necessary closes it and opens a new session. Valid session values are: SESSION_GEN2 and SESSION_ISO6B.

Definition at line 311 of file appl_commands.c.

u8 commands ( u8  protocol,
u16  rxSize,
const u8 *  rxData,
u16 *  txSize,
u8 *  txData 
)

Process various generic commands.

Parameters
protocol: forward from applProcessCmd()
rxData: forward from applProcessCmd()
rxSize: forward from applProcessCmd()
txData: forward from applProcessCmd()
txSize: forward from applProcessCmd()
Returns
error code for processed command

Protocol description

The following description gives an overview of the ams stream protocol and how the data of stream packets is forwarded to the commands() function. The protocol can be executed over USB or UART. Only the header bytes between USB and UART are different.

For a detailed description of the ams stream protocol have a look in ams_stream.h

Protocol for USB:

A simple USB stream packet (not splitted, only 1 protocol in packet) is shown in the following table, which maps the transmitted data to the function parameters of commands().

Byte01234..56..78..8+txprot-1
ContentTIDpayloadreservedprotocoltxprotrxprotdata
ParameterprotocolrxSizetxSizerxData[0..rxSize-1]

where

  • TID : transaction ID.
  • payload: amount of data in report.
  • protocol: defines which action should be triggered. If commands() is is called it refers to a firmware application command (no generic stream command).
  • txprot: amount of data which has been received and should be forwarded to command function.
  • rxprot: This variable contains the expected size of data this command will return and will be set to the size of the actual data to be tx-ed back to host.
  • data: input data for command

The response will look like this:

Byte0123456..78..8+txprot-1
ContentTIDpayloadstream statusprotocolreservedprot statustxprotdata
ParameterprotocolstatustxSizetxData[0..txSize-1]

where

  • TID : transaction ID.
  • payload: amount of data in report.
  • stream status : a non-zero value indicates that a previous command could not be processed
  • protocol : defines to which action the transmitted data belongs
  • prot status : a non-zero value indicates error condition of command (return value of function commands())
  • txprot: size of data in response
  • data: response data for command

Example for the antenna power command, handled by callAntennaPower():

Request from host (Reader Suite):

Byte01234..56..78
ContentTIDpayloadreservedprotocoltxprotrxprotdata
Value0x0F0x070x000x010x00020x00010xFF

where:

The reader answer with this report:

Byte0123456..78
ContentTIDpayloadstream statusprotocolreservedprot statustxprotdata
Value0xF00x060x000x010x000x000x00010x00
  • 0x00 (txData[0]): the data this command produced.
  • 0x00 (status): ERR_NONE

Protocol for UART:

A simple UART stream packet is shown in the following table, which maps the transmitted data to the function parameters of commands().

Byte012..345..67..89..9+txprot-1
ContentTIDStatuspayloadprotocoltxprotrxprotdata
ParameterprotocolrxSizetxSizerxData[0..rxSize-1]

where

  • TID : transaction ID.
  • Status : Uart Status
  • payload: amount of data in report.
  • protocol: defines which action should be triggered. If commands() is is called it refers to a firmware application command (no generic stream command).
  • txprot: amount of data which has been received and should be forwarded to command function.
  • rxprot: This variable contains the expected size of data this command will return and will be set to the size of the actual data to be tx-ed back to host.
  • data: input data for command

The response will look like this:

Byte012..34567..89..9+txprot-1
ContentTIDStatuspayloadprotocolreservedprot statustxprotdata
ParameterprotocolstatustxSizetxData[0..txSize-1]

where

  • TID : transaction ID.
  • Status : Uart Status
  • payload: amount of data in report.
  • protocol : defines to which action the transmitted data belongs
  • prot status : a non-zero value indicates error condition of command (return value of function commands())
  • txprot: size of data in response
  • data: response data for command

UART Settings:

  • BAUD RATE: 115200
  • DATA BITS: 8
  • PARITY: NONE
  • STOP BITS: 1
  • FLOW CONTROL: NONE

Example for the config TX RX command, handled by callConfigTxRx():

Request from host (Reader Suite):

Byte0 12..345..67..89..12
ContentTID Statuspayloadprotocoltxprot rxprot data
Parameter0x200x00 0x00 090x04 0x00 040x00 040x00 00 01 01

where:

  • 0x04: command ID for callConfigTxRx(), is also used as index in call_fkt_() table.
  • 0x00 00 01 01 : parameter for callConfigTxRx() (set_sensitivity = false and sensitivity = 0; set_antenna = true and antenna id = 1)

The reader answer with this report:

Byte012..34567..8 9..12
ContentTID Statuspayloadprotocolreservedprot statustxprot data
Parameter0x010x00 0x00 090x04 0x00 0x00 0x00 040x00 0B 00 01
  • 0x00 0B 00 01: reserved bytes are 0x00, sensitivity is 0x0B and antenna id is 0x01

Example for the Inventory Gen2 command, handled by callInventoryGen2():

Request from host (Reader Suite):

Byte0 12..345..67..89..12
ContentTID Statuspayloadprotocoltxprot rxprot data
Parameter0x070x00 0x00 080x85 0x00 030x00 000x00 01 06

where:

The reader answer with this report:

Byte012..34567..8 9..12
ContentTID Statuspayloadprotocolreservedprot statustxprot data
Parameter0x760x00 0x00 140x05 0x00 0x00 0x00 0F00 00 01 8f ff ac 3c 0d 06 10 00 ba ba 77 77
  • 0xba ba 77 77: epc of tag

Example for the Read from Tag command, handled by callReadFromTag():

Request from host (Reader Suite):

Byte0 12..345..67..89..17
ContentTID Statuspayloadprotocoltxprot rxprot data
Parameter0x3E0x00 0x00 0e0x08 0x00 090x00 090x00 00 00 00 00 00 00 00 00

where:

The reader answer with this report:

Byte012..34567..8 9..16
ContentTID Statuspayloadprotocolreservedprot statustxprot data
Parameter0xE70x00 0x00 0D0x08 0x00 0x00 0x00 0800 00 00 00 55 55 55 55
  • 00 00 00 00 55 55 55 55: reserved memory of the tag

Implemented commands

Functions which handle the commands from the host are located in appl_commands.c

The documentation of the various appl command functions will only discuss the data received/sent back to host and will not include the header information for every transmitted packet.

For more details on the ams stream protocol have a look into ams_stream.h

Definition at line 3324 of file appl_commands.c.

static BOOL continueCheckTimeout ( )
static

This function can be used as callback parameter for gen2SearchForTags(). It will return 1 as long as allocation timeout has not been exceeded yet. If allocation timeout has occured it will return 0.

Returns
1 if allocation timeout has not been exceeded yet.

Definition at line 289 of file appl_commands.c.

int doCyclicInventory ( void  )

This function is called periodically from main() loop. If a cyclic inventory has been started callInventoryGen2Internal() is called.

Definition at line 3036 of file appl_commands.c.

s8 gen2ReadTID ( Tag tag)

This function reads the TID Memory of a specific Tag.
The maximum length is limited by TIDLENGTH.

Attention
This command works on the one tag which is currently in the open state
Parameters
*tagPointer to the Tag structure.
Returns
The function returns an errorcode. 0x00 means no error occoured. 0xFF unknown error occoured. Any other value is the backscattered error code from the tag.

Definition at line 3606 of file appl_commands.c.

static void powerDownReader ( void  )
static

Handles the configured power down mode of the reader. The power down mode is define in readerPowerDownMode variable and can be changed via callReaderConfig(). Available modes are: POWER_DOWN, POWER_NORMAL, POWER_NORMAL_RF and POWER_STANDBY

Definition at line 3050 of file appl_commands.c.

static void powerUpReader ( void  )
static

Handles power up of reader. Basically reverts changes done by powerDownReader().

Definition at line 3075 of file appl_commands.c.

u8 readRegister ( u8  addr,
u16 *  txSize,
u8 *  txData 
)

reads one AS3993 register at address and puts the value into the reply to the host.
see cmdReadReg() for reply structure.

Parameters
addrregister address
txSizeexpected tx size
txDatabuffer for reply
Returns
error code

Definition at line 1125 of file appl_commands.c.

u8 readRegisters ( u16 *  txSize,
u8 *  txData 
)

reads all AS3993 registers and puts the values into the reply to the host.
see cmdReadReg() for reply structure.

Parameters
txSizeexpected tx size
txDatabuffer for reply
Returns
error code

Definition at line 1395 of file appl_commands.c.

u8 sendTagData ( u8 *  protocol,
u16 *  txSize,
u8 *  txData,
u16  remainingSize 
)

This function sends the tag data received in the last inventory round to the host. The payload description is here: callInventoryGen2()

Parameters
protocolProtocol byte for the stream packet
txDataBuffer to use for tx data
txSizeNumber of bytes which have been copied into the buffer.
remainingSizeNumber of available bytes in the tx buffer.
Returns
Status of the command.

The fixed size part of a tag data reply payload (as described in callInventoryGen2()) consists of:
number of bytes content
1 cyclic
1 tags_left
1 tags_in_reply
1 AGC and status (reg 0x2A)
1 RSSI_value (reg 0x2B)
3 base_freq
1 epclen+pclen
2 pc
sum : 10
followed by an epc with variable length.
If the parameter readTIDinInventoryRound is set to 1, one byte with the tidlen and the tid with variable length will follow.

Definition at line 3390 of file appl_commands.c.

u8 writeRegister ( u8  addr,
u8  value,
u16 *  txSize,
u8 *  txData 
)

writes to AS3993 register at address addr the value and prepares tx answer to host.
see cmdWriteReg() for reply structure.

Parameters
addrregister address
valuethe value to write
txSizeexpected tx size
txDatabuffer for reply
Returns
error code

Definition at line 1097 of file appl_commands.c.

Variable Documentation

BOOL adaptiveQ = 0
static

If set to 1 the adaptSlotCounter function should be executed after an inventory round.

Definition at line 206 of file appl_commands.c.

u8 adjustmentDownThreshold = 13
static

Defines the Threshold for the QueryAdjust Parameter to decrement the Slot Counter Q. For details see gen2SearchForTags().

Definition at line 212 of file appl_commands.c.

u8 adjustmentRounds = 2
static

Defines the Number of additional rounds that can be executed after a Query Command Round

Definition at line 208 of file appl_commands.c.

u8 adjustmentUpThreshold = 25
static

Defines the Threshold for the QueryAdjust Parameter to increment the Slot Counter Q. For details see gen2SearchForTags().

Definition at line 210 of file appl_commands.c.

u8 autoAckMode
static

If set to 0 inventory round commandos will be triggered by the FW, otherwise the autoACK feature of the reader will be used which sends the required Gen2 commands automatically.

Definition at line 200 of file appl_commands.c.

struct CmdBuffer cmdBuffer
static

Structure which contains the command data which has been received and shall be sent. Provides access to parameters of commands() to all appl command funtions (call*()).

Definition at line 250 of file appl_commands.c.

u16 currentFreqIdx
static

Index of currently used frequency in frequency table Frequencies. Used in hopFrequencies().

Definition at line 252 of file appl_commands.c.

u8 currentSession = 0
static

Currently used protocol, valid values are: SESSION_GEN2 and SESSION_ISO6B.

Definition at line 254 of file appl_commands.c.

u8 cyclicInventory
static

Will be set to 1 if a cyclic inventory is performed, see callStartStop().

Definition at line 196 of file appl_commands.c.

u8 fastInventory
static

If set to 0 normal inventory round will be performed, if set to 1 fast inventory rounds will be performed. The value is set in callStartStop() and callInventoryGen2(). For details on normal/fast inventory rounds see parameter singulate of gen2SearchForTags().

Definition at line 204 of file appl_commands.c.

Freq Frequencies

Contains the list of used frequencies.

Definition at line 170 of file appl_commands.c.

struct gen2Config gen2Configuration = {TARI_25, GEN2_LF_256, GEN2_COD_MILLER4, TREXT_OFF, 0, GEN2_SESSION_S0, 0}
static

Default Gen2 configuration, can be changed callConfigGen2().

Definition at line 127 of file appl_commands.c.

u8 gen2qbegin = 4

Start value for Q for Gen2 inventory rounds, can be changed callConfigGen2().

Definition at line 129 of file appl_commands.c.

u8 guiActiveProfile = 1
static

Profile settings which can be set via GUI commands. We default to Europe settings.

Definition at line 172 of file appl_commands.c.

u32 guiMaxFreq = 867500
static

Profile settings which can be set via GUI commands. We default to Europe settings.

Definition at line 178 of file appl_commands.c.

u32 guiMinFreq = 865700
static

Profile settings which can be set via GUI commands. We default to Europe settings.

Definition at line 176 of file appl_commands.c.

u8 guiNumFreqs =4
static

Profile settings which can be set via GUI commands. We default to Europe settings.

Definition at line 174 of file appl_commands.c.

u16 idleTime = 0
static

Profile settings which can be set via GUI commands. We default to Europe settings.
Before starting the frequency hop this time (in ms) will be waited for.

Definition at line 184 of file appl_commands.c.

u16 inventoryDelay = 0
static

Delay between Inventory Rounds

Definition at line 140 of file appl_commands.c.

s8 inventoryResult
static

To be communicated to GUI, basically result of hopFrequencies(), having information on skipped rounds

Definition at line 225 of file appl_commands.c.

u16 listeningTime = 1
static

Profile settings which can be set via GUI commands. We default to Europe settings.
Measure rssi for this time (in ms) before deciding if the channel should be used.

Definition at line 190 of file appl_commands.c.

u16 maxSendingLimit
static

Maximal channel arbitration time in ms (internal value of maxSendingTime)

Definition at line 192 of file appl_commands.c.

u8 maxSendingLimitTimedOut
static

Will be set to 1 when maxSendingLimit in continueCheckTimeout() timed out.

Definition at line 194 of file appl_commands.c.

u16 maxSendingTime = 10000
static

Profile settings which can be set via GUI commands. We default to Europe settings.
Maximum allocation time (in ms) of a channel.

Definition at line 187 of file appl_commands.c.

u8 num_of_tags
static

Internal variable which contains the number of received tags in the last inventory round.

Definition at line 155 of file appl_commands.c.

int num_selects
static

Internal number of currently configured select commands.

Definition at line 150 of file appl_commands.c.

u16 readerInitStatus

AS3993 init status. This is the return value of as3993Initialize()

Definition at line 160 of file appl_commands.c.

u8 readerPowerDownMode
static

Currently configured power down mode of reader. Available modes are: POWER_DOWN, POWER_NORMAL, POWER_NORMAL_RF and POWER_STANDBY

Definition at line 223 of file appl_commands.c.

u8 readTIDinInventoryRound
static

If set to 1 an read of the TID will be performed in inventory rounds. The value is set in callStartStop() and callInventoryGen2(). For details see parameter followTagCommand of gen2SearchForTags() and gen2ReadTID(Tag *tag).

Definition at line 217 of file appl_commands.c.

u8 rssiMode
static

Value for register AS3993_REG_STATUSPAGE. This defines what RSSI value is sent to the host along with the tag data. The value is set in callStartStop() and callInventoryGen2().

Definition at line 220 of file appl_commands.c.

s8 rssiThreshold
static

If rssi measurement is above this threshold the channel is regarded as used and the system will hop to the next frequency. Otherwise this frequency is used

Definition at line 181 of file appl_commands.c.

u8 scanRetuningLevel = 30
static

Deviation Level for Retuning in percentage

Definition at line 148 of file appl_commands.c.

u16 scanTuningInterval = 500
static

Scan Tuning Interval

Definition at line 142 of file appl_commands.c.

Tag* selectedTag

Pointer to data of currently selected Tag.

Definition at line 167 of file appl_commands.c.

struct gen2SelectParams selParams[MAX_SELECTS]
static

Parameters for select commands, can be changed via callSelectTag()

Definition at line 152 of file appl_commands.c.

u8 tagDataAvailable
static

New tag data has been received in last inventory round and can be sent in sendTagData() now.

Definition at line 157 of file appl_commands.c.

Tag tags_[MAXTAG]

Array of Structures which stores all necessary Information about the Tags.

Definition at line 164 of file appl_commands.c.

u16 tuningCounter = 0
static

Tuning counter

Definition at line 145 of file appl_commands.c.

u8 usedAntenna = 2
static

Stores which antenna port is used atm. valid values are 1 and 2.

Definition at line 230 of file appl_commands.c.