as3993 ST25RU3993 Firmware
Macros | Functions
gen2.h File Reference
#include "as3993_public.h"
#include "ams_types.h"
#include "errno_as3993.h"

Go to the source code of this file.

Macros

#define GEN2_LF_40   0
 
#define GEN2_LF_160   6
 
#define GEN2_LF_213   8
 
#define GEN2_LF_256   9
 
#define GEN2_LF_320   12
 
#define GEN2_LF_640   15
 
#define GEN2_COD_FM0   0
 
#define GEN2_COD_MILLER2   1
 
#define GEN2_COD_MILLER4   2
 
#define GEN2_COD_MILLER8   3
 
#define TREXT_OFF   0
 
#define TREXT_ON   1
 
#define TARI_625   0
 
#define TARI_125   1
 
#define TARI_25   2
 
#define MEM_RES   0x00
 
#define MEM_EPC   0x01
 
#define MEM_TID   0x02
 
#define MEM_USER   0x03
 
#define MEMADR_CRC   0x00
 
#define MEMADR_PC   0x01
 
#define MEMADR_EPC   0x02
 
#define MEMADR_KILLPWD   0x00
 
#define MEMADR_ACCESSPWD   0x02
 
#define MEMADR_TID   0x00
 
#define GEN2_IINV_S0   0x00 /*Inventoried (S0) */
 
#define GEN2_IINV_S1   0x01 /*001: Inventoried (S1) */
 
#define GEN2_IINV_S2   0x02 /*010: Inventoried (S2) */
 
#define GEN2_IINV_S3   0x03 /*011: Inventoried (S3) */
 
#define GEN2_IINV_SL   0x04 /*100: SL */
 
#define GEN2_OK   ERR_NONE
 
#define GEN2_ERR_REQRN   ERR_GEN2_REQRN
 
#define GEN2_ERR_ACCESS   ERR_GEN2_ACCESS
 
#define GEN2_ERR_SELECT   ERR_GEN2_SELECT
 
#define GEN2_ERR_CHANNEL_TIMEOUT   ERR_GEN2_CHANNEL_TIMEOUT
 

Functions

unsigned gen2SearchForTags (Tag *tags, u8 maxtags, u8 q, u8 addRounds, u8 queryAdjustUpTh, u8 queryAdjustDownTh, BOOL(*cbContinueScanning)(void), BOOL singulate, BOOL toggleSession, s8(*followTagCommand)(Tag *tag))
 
unsigned gen2SearchForTagsAutoAck (Tag *tags_, u8 maxtags, u8 q, BOOL(*cbContinueScanning)(void), BOOL singulate, BOOL toggleSession, s8(*followTagCommand)(Tag *tag))
 
s8 gen2AccessTag (Tag const *tag, u8 const *password)
 
s8 gen2LockTag (Tag *tag, const u8 *mask_action, u8 *tag_reply)
 
s8 gen2KillTag (Tag const *tag, u8 const *password, u8 rfu, u8 recom, u8 *tag_error)
 
s8 gen2WriteWordToTag (Tag const *tag, u8 memBank, u32 wordPtr, u8 const *databuf, u8 *tag_error)
 
s8 gen2ReadFromTag (Tag *tag, u8 memBank, u32 wordPtr, u8 wordCount, u8 *destbuf)
 
void gen2Select (struct gen2SelectParams *p)
 
void gen2PrintTagInfo (Tag *tag, u8 epclen, u8 tagNr)
 
void gen2Configure (const struct gen2Config *config)
 
void gen2Open (const struct gen2Config *config)
 
void gen2Close (void)
 
s8 gen2QueryMeasureRSSI (u8 *agc, u8 *log_rssis, s8 *irssi, s8 *qrssi)
 
struct gen2Config * getGen2IntConfig ()
 

Detailed Description

This file provides declarations for functions for the GEN2 aka ISO6c protocol.

Author
Ulrich Herrmann
Bernhard Breinbauer

Before calling any of the functions herein the AS3993 chip needs to be initialized using as3993Initialize(). Thereafter the function gen2Open() needs to be called for opening a session. gen2SearchForTags() should be called to identify the tags in reach. Usually the the user then wants to select one of the found tags. For doing this gen2Select() can be used. If gen2Config and gen2SelectParams provide a matching configuration the next call to gen2SearchForTags() will only return 1 tag. If singulate parameter of gen2SearchForTags() is set to true the found tag will be in the Open state and can then be accessed using the other functions , gen2WriteWordToTag(), gen2ReadFromTag()... When finished with gen2 operations this session should be closed using gen2Close().

The tag state diagram looks as follows using the provided functions. For exact details please refer to the standard document provided by EPCglobal under uhfc1g2_1_2_0-standard-20080511.pdf

If the tag in question does have a password set:

dot_inline_dotgraph_1.png

If the tag in question does not have a password set:

dot_inline_dotgraph_2.png

So a typical use case may look like this:

* Tag tags[16];
* u8 tag_error;
* struct gen2Config config = = {TARI_125, GEN2_LF_256, GEN2_COD_MILLER4, TREXT_OFF, 0, GEN2_SESSION_S0, 0};
* // setup gen2SelectParams
* unsigned n;
* u8 buf[4];
* ...
* as3993Initialize(912000);
*
* gen2Open(&config);
*
* performSelects();
* n = gen2SearchForTags(tags_+1, 1, 0, continueAlways, 1);
* if ( n == 0) return;
*
* //Pick one of the tags based on the contents of tags. Here we use the very first tag
*
* if (gen2ReadFromTag(tags+0, MEM_USER, 0, 2, buf))
* return;
*
* buf[0] ^= 0xff; buf[1]^= 0x55; // change the data
*
* if (gen2WriteWordToTag( tags+0, MEM_USER, 0, buf, &tag_error))
* { // wrote back one of the two read words
* gen2Close();
* return;
* }
*
* //...
*
* gen2Close();
*
*

Definition in file gen2.h.

Macro Definition Documentation

#define GEN2_COD_FM0   0

Rx coding values FM coding for rx

Definition at line 121 of file gen2.h.

#define GEN2_COD_MILLER2   1

MILLER2 coding for rx

Definition at line 122 of file gen2.h.

#define GEN2_COD_MILLER4   2

MILLER4 coding for rx

Definition at line 123 of file gen2.h.

#define GEN2_COD_MILLER8   3

MILLER8 coding for rx

Definition at line 124 of file gen2.h.

#define GEN2_ERR_ACCESS   ERR_GEN2_ACCESS

Error sending Access password

Definition at line 181 of file gen2.h.

#define GEN2_ERR_CHANNEL_TIMEOUT   ERR_GEN2_CHANNEL_TIMEOUT

Error RF channel timed out

Definition at line 183 of file gen2.h.

#define GEN2_ERR_REQRN   ERR_GEN2_REQRN

Error sending ReqRN

Definition at line 180 of file gen2.h.

#define GEN2_ERR_SELECT   ERR_GEN2_SELECT

Error when selecting tag

Definition at line 182 of file gen2.h.

#define GEN2_IINV_S0   0x00 /*Inventoried (S0) */

Definition for inventory: Inventoried (S0)

Definition at line 163 of file gen2.h.

#define GEN2_IINV_S1   0x01 /*001: Inventoried (S1) */

Definition for inventory: 001: Inventoried (S1)

Definition at line 165 of file gen2.h.

#define GEN2_IINV_S2   0x02 /*010: Inventoried (S2) */

Definition for inventory: 010: Inventoried (S2)

Definition at line 167 of file gen2.h.

#define GEN2_IINV_S3   0x03 /*011: Inventoried (S3) */

Definition for inventory: 011: Inventoried (S3)

Definition at line 169 of file gen2.h.

#define GEN2_IINV_SL   0x04 /*100: SL */

Definition for inventory: 100: SL

Definition at line 171 of file gen2.h.

#define GEN2_LF_160   6

link frequency 160 kHz

Definition at line 114 of file gen2.h.

#define GEN2_LF_213   8

link frequency 213 kHz

Definition at line 115 of file gen2.h.

#define GEN2_LF_256   9

link frequency 213 kHz

Definition at line 116 of file gen2.h.

#define GEN2_LF_320   12

link frequency 213 kHz

Definition at line 117 of file gen2.h.

#define GEN2_LF_40   0

link frequency 40 kHz

Definition at line 113 of file gen2.h.

#define GEN2_LF_640   15

link frequency 640 kHz

Definition at line 118 of file gen2.h.

#define GEN2_OK   ERR_NONE

Defines for various return codes No error

Definition at line 179 of file gen2.h.

#define MEM_EPC   0x01

Definition for EPC tag memory bank: EPC memory

Definition at line 139 of file gen2.h.

#define MEM_RES   0x00

Definition for EPC tag memory bank: reserved

Definition at line 137 of file gen2.h.

#define MEM_TID   0x02

Definition for EPC tag memory bank: TID

Definition at line 141 of file gen2.h.

#define MEM_USER   0x03

Definition for EPC tag memory bank: user

Definition at line 143 of file gen2.h.

#define MEMADR_ACCESSPWD   0x02

Definition for EPC wordpointer: Address for access password value

Definition at line 156 of file gen2.h.

#define MEMADR_CRC   0x00

Definition for EPC wordpointer: Address for CRC value

Definition at line 147 of file gen2.h.

#define MEMADR_EPC   0x02

Definition for EPC wordpointer: Address for EPC value

Definition at line 151 of file gen2.h.

#define MEMADR_KILLPWD   0x00

Definition for EPC wordpointer: Address for kill password value

Definition at line 154 of file gen2.h.

#define MEMADR_PC   0x01

Definition for EPC wordpointer: Address for PC value Word position

Definition at line 149 of file gen2.h.

#define MEMADR_TID   0x00

Definition for EPC wordpointer: Address for TID value

Definition at line 159 of file gen2.h.

#define TARI_125   1

set tari to 12.5us

Definition at line 132 of file gen2.h.

#define TARI_25   2

set tari to 25us

Definition at line 133 of file gen2.h.

#define TARI_625   0

set tari to 6.25us

Definition at line 131 of file gen2.h.

#define TREXT_OFF   0

use short preamble

Definition at line 127 of file gen2.h.

#define TREXT_ON   1

use long preamble

Definition at line 128 of file gen2.h.

Function Documentation

s8 gen2AccessTag ( Tag const *  tag,
u8 const *  password 
)

EPC ACCESS command send to the Tag. This function is used to bring a tag with set access password from the Open state to the Secured state.

Attention
This command works on the one tag which is currently in the open state, i.e. on the last tag found by gen2SearchForTags().
Parameters
*tagPointer to the Tag structure.
*passwordPointer to first byte of the access password
Returns
The function returns an errorcode. 0x00 means no Error occoured. Any other value is the backscattered error code from the tag.

Definition at line 438 of file gen2.c.

void gen2Close ( void  )

Close a session.

Close the session for gen2 protocol

Definition at line 1174 of file gen2.c.

void gen2Configure ( const struct gen2Config *  config)

Set the link frequency.

Set the link frequency and gen2 specific parameters. After calling this function the AS3993 is in normal.

Definition at line 994 of file gen2.c.

s8 gen2KillTag ( Tag const *  tag,
u8 const *  password,
u8  rfu,
u8  recom,
u8 *  tag_error 
)

EPC KILL command send to the Tag. This function is used to permanently kill a tag. After that the tag will never ever respond again.

Attention
This command works on the one tag which is currently in the open state, i.e. on the last tag found by gen2SearchForTags().
Parameters
*tagPointer to the Tag structure.
*passwordPointer to first byte of the kill password
rfu3 bits used as rfu content for first half of kill, should be zero
recom3 bits used as recom content for second half of kill, zero for real kill, !=0 for recommisioning
*tag_error,:in case header bit is set this will be the return code from the tag
Returns
The function returns an errorcode. 0x00 means no Error occoured. Any other value is the backscattered error code from the tag.

Definition at line 519 of file gen2.c.

s8 gen2LockTag ( Tag tag,
const u8 *  mask_action,
u8 *  tag_reply 
)

EPC LOCK command send to the Tag. This function is used to lock some data region in the tag.

Attention
This command works on the one tag which is currently in the open state, i.e. on the last tag found by gen2SearchForTags().
Parameters
*tagPointer to the Tag structure.
*mask_actionPointer to the first byte of the mask and action array.
*tag_replyIn case ERR_HEADER is returned this variable will contain the 8-bit error code from the tag.
Returns
The function returns an errorcode. 0x00 means no Error occoured. Any other value is the backscattered error code from the tag.

Definition at line 485 of file gen2.c.

void gen2Open ( const struct gen2Config *  config)

Open a session.

Parameters
config,:configuration to use

Open a session for gen2 protocol

Definition at line 1169 of file gen2.c.

void gen2PrintTagInfo ( Tag tag,
u8  epclen,
u8  tagNr 
)

Prints the tag information out (UART).

Parameters
*tagPointer to the Tag structure.
epclenLength of the EPC.
tagNrNumber of the tag.

Definition at line 655 of file gen2.c.

s8 gen2ReadFromTag ( Tag tag,
u8  memBank,
u32  wordPtr,
u8  wordCount,
u8 *  destbuf 
)

EPC READ command send to the Tag.

Attention
This command works on the one tag which is currently in the open state, i.e. on the last tag found by gen2SearchForTags().
Parameters
*tagPointer to the Tag structure.
memBankMemory Bank to which the data should be written.
wordPtrWord Pointer Address to which the data should be written.
wordCountNumber of bytes to read from the tag.
*destbufPointer to the first byte of the data array.
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 611 of file gen2.c.

unsigned gen2SearchForTags ( Tag tags,
u8  maxtags,
u8  q,
u8  addRounds,
u8  queryAdjustUpTh,
u8  queryAdjustDownTh,
BOOL(*)(void)  cbContinueScanning,
BOOL  singulate,
BOOL  toggleSession,
s8(*)(Tag *tag)  followTagCommand 
)

Search for tags (aka do an inventory round). Before calling any other gen2 functions this routine has to be called. It first selects using the given mask a set of tags and then does an inventory round issuing query commands. All tags are stored in then tags array for examination by the user.

Parameters
*tagsan array for the found tags to be stored to
maxtagsthe size of the tags array
q2^q slots will be done first, additional 2 round with increased or decreased q may be performed
addRoundsadditional Rounds with Query Adjust
queryAdjustUpThThreshold for the additional round with Query Adjust to increase Q; slots * (queryAdjustUpTh/100)
queryAdjustDownThThreshold for the additional round with Query Adjust to decrease Q; slots * (queryAdjustDownTh/100)
cbContinueScanningcallback is called after each slot to inquire if we should continue scanning (e.g. for allowing a timeout)
singulateIf set to true Req_RN command will be sent to get tag into Open state otherwise it will end up in arbitrate
toggleSessionIf set to true, QueryRep commands will be sent immediately after receiving tag reply to toggle session flag on tag.
followTagCommandcallback function is called after a tag is inventoried. If function will be called, no fast mode is possible.
Returns
the number of tags found

Definition at line 679 of file gen2.c.

unsigned gen2SearchForTagsAutoAck ( Tag tags_,
u8  maxtags,
u8  q,
BOOL(*)(void)  cbContinueScanning,
BOOL  singulate,
BOOL  toggleSession,
s8(*)(Tag *tag)  followTagCommand 
)

For reference see gen2SearchForTags(). The main difference is that it uses the autoACK mode of the reader.

Definition at line 861 of file gen2.c.

void gen2Select ( struct gen2SelectParams *  p)

EPC SELECT command. send to the tag. This function does not take or return a parameter

Definition at line 142 of file gen2.c.

s8 gen2WriteWordToTag ( Tag const *  tag,
u8  memBank,
u32  wordPtr,
u8 const *  databuf,
u8 *  tag_error 
)

EPC WRITE command send to the Tag. This function writes one word (16 bit) to the tag. It first requests a new handle. The handle is then exored with the data.

Attention
This command works on the one tag which is currently in the open state, i.e. on the last tag found by gen2SearchForTags().
Parameters
*tagPointer to the Tag structure.
memBankMemory Bank to which the data should be written.
wordPtrWord Pointer Address to which the data should be written.
*databufPointer to the first byte of the data array. The data buffer has to be 2 bytes long.
*tag_errorIn case tag returns an error (header bit set), this functions returns ERR_HEADER and inside tag_error the actual code
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 566 of file gen2.c.

struct gen2Config* getGen2IntConfig ( )

Returns the Gen2 Configuration.

Returns
Gen2 Configuration

Definition at line 1178 of file gen2.c.