as3993 ST25RU3993 Firmware
Macros | Functions | Variables
as3993.c File Reference
#include "as3993_config.h"
#include "platform.h"
#include "as3993.h"
#include "as3993_public.h"
#include "global.h"
#include "logger.h"
#include "timer.h"
#include "gen2.h"
#include "stdlib.h"
#include "string.h"
#include "Compiler.h"

Go to the source code of this file.

Macros

#define READ   0x40
 
#define AS3980WAITTIME   510
 
#define WaitForAS3980()   {}
 

Functions

u16 as3993Initialize (u32 baseFreq)
 
void INTERRUPT as3993Isr (void)
 
u8 as3993ReadChipVersion (void)
 
void as3993SingleCommand (u8 command)
 
void as3993ContinuousRead (u8 address, s8 len, u8 *readbuf)
 
void as3993FifoRead (s8 len, u8 *readbuf)
 
u8 as3993SingleRead (u8 address)
 
void as3993ContinuousWrite (u8 address, u8 *buf, s8 len)
 
void as3993SingleWrite (u8 address, u8 value)
 
void as3993CommandContinuousAddress (u8 *command, u8 com_len, u8 address, u8 *buf, u8 buf_len)
 
void as3993WaitForResponseTimed (u16 waitMask, u16 counter)
 
void as3993WaitForResponse (u16 waitMask)
 
void as3993WaitForResponseFAST (u16 waitMask)
 
void as3993EnterDirectMode ()
 
void as3993ExitDirectMode ()
 
void as3993SetBaseFrequency (u8 regs, u32 frequency)
 
void as3993EnterPowerDownMode ()
 
void as3993ExitPowerDownMode ()
 
void as3993Reset (void)
 
void as3993ResetDoNotPreserveRegisters (void)
 
void as3993EnterPowerNormalMode ()
 
void as3993ExitPowerNormalMode ()
 
void as3993EnterPowerNormalRfMode ()
 
void as3993ExitPowerNormalRfMode ()
 
void as3993EnterPowerStandbyMode ()
 
void as3993ExitPowerStandbyMode ()
 
void as3993WaitForStartup (void)
 
void as3993AntennaPower (u8 on)
 
s8 as3993GetSensitivity ()
 
s8 as3993GetADC (void)
 
u16 as3993GetReflectedPower (void)
 
u16 as3993GetReflectedPowerNoiseLevel (void)
 
s8 as3993TxRxGen2Bytes (u8 cmd, u8 *txbuf, u16 txbits, u8 *rxbuf, u16 *rxbits, u8 norestime, u8 followCmd, u8 waitTxIrq)
 

Variables

volatile u16 as3993Response = 0
 
static u8 as3993PowerDownRegs [AS3993_REG_ICD+6]
 
static u8 gChipRevisionZero = 1
 

Detailed Description

Functions provided by the as3993 series chips.

Author
U.Herrmann (based on work by E.Grubmueller)
T. Luecker (Substitute)
Bernhard Breinbauer
Rene Eggerstorfer

Functions provided by the as3993 series chips. All higher level and protocol work is contained in gen2.c and iso6b.c

Definition in file as3993.c.

Macro Definition Documentation

#define AS3980WAITTIME   510

time in ms to wait for AS3980 to be ready

Definition at line 53 of file as3993.c.

#define READ   0x40

Definition protocol read bit

Definition at line 50 of file as3993.c.

#define WaitForAS3980 ( )    {}

Wait for AS3980 to be ready.

Definition at line 61 of file as3993.c.

Function Documentation

void as3993AntennaPower ( u8  on)

This function turns the antenna power on or off.

Parameters
onboolean to value to turn it on (1) or off (0).

Definition at line 875 of file as3993.c.

void as3993CommandContinuousAddress ( u8 *  command,
u8  com_len,
u8  address,
u8 *  buf,
u8  buf_len 
)

Sends first some commands to the AS3993. The number of commands is specified with the parameter com_len. Then it sets the address where the first byte has to be written and after that every byte from the buffer is written to the AS3993.

Parameters
*commandPointer to the first byte of the command buffer
com_lenLength of the command buffer.
addressaddressbyte
*bufPointer to the first byte of the data array.
buf_lenLength of the buffer.

Definition at line 516 of file as3993.c.

void as3993ContinuousRead ( u8  address,
s8  len,
u8 *  readbuf 
)

Reads data from a address and some following addresses from the AS3993. The len parameter defines the number of address read.

Parameters
addressaddressbyte
lenLength of the buffer.
*readbufPointer to the first byte of the array where the data has to be stored in.

Definition at line 456 of file as3993.c.

void as3993ContinuousWrite ( u8  address,
u8 *  buf,
s8  len 
)

Continuous Write -> writes several bytes to subsequent addresses of the AS3993.

Parameters
addressaddressbyte
*bufPointer to the first byte of the array.
lenLength of the buffer.

Definition at line 492 of file as3993.c.

void as3993EnterDirectMode ( )

Enter the direct mode.

The direct mode is needed since the AS3993 doesn't support ISO18000-6B directly. Direct mode means that the MCU directly issues the commands. The AS3993 modulates the serial stream from the MCU and sends it out.

Definition at line 579 of file as3993.c.

void as3993ExitDirectMode ( )

Leave the direct mode.

After calling this function the AS3993 is in normal mode again.

Definition at line 589 of file as3993.c.

void as3993FifoRead ( s8  len,
u8 *  readbuf 
)

Reads data from the fifo and some following addresses from the AS3993. The len parameter defines the number of address read.

Parameters
lenLength of the buffer.
*readbufPointer to the first byte of the array where the data has to be stored in.

Definition at line 465 of file as3993.c.

s8 as3993GetADC ( void  )

This functions performs an ADC conversion and returns the signed result in machine coding

Definition at line 1116 of file as3993.c.

u16 as3993GetReflectedPower ( void  )

This function gets the values for the reflected power. For measuring the antenna will be switched on, a measurement performed and the antenna if necessary turned back off. The two measured 8-bit values are returned as one 16-bit value, the lower byte containing receiver-A (I) value, the higher byte containing receiver-B (Q) value. The two values are signed values and will be converted from sign magnitude representation to natural. Note: To get a more accurate result the I and Q values of as3993GetReflectedPowerNoiseLevel() should be subtracted from the result of as3993GetReflectedPower()

Definition at line 1126 of file as3993.c.

u16 as3993GetReflectedPowerNoiseLevel ( void  )

This function measures and returns the noise level of the reflected power measurement of the active antenna. The returned value is of type u16 and contains the 8 bit I and Q values of the reflected power. The I value is located in the lower 8 bits, the Q value in the upper 8 bits.
See as3993GetReflectedPower() fore more info.

Definition at line 1153 of file as3993.c.

s8 as3993GetSensitivity ( void  )

This function gets the current rx sensitivity level.

Definition at line 921 of file as3993.c.

u16 as3993Initialize ( u32  baseFreq)

This function initialises the AS3993. A return value greater 0 indicates an error.

Parameters
baseFreqthe base frequency to set at initialization time, may be changed later on.
Returns
error code
0 : if everything went o.k.
1 : writing + 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 (Bits1 in AGC and Internal Status register 0x2A)

Definition at line 127 of file as3993.c.

void INTERRUPT as3993Isr ( void  )

External Interrupt Function The AS3993 uses the external interrupt to signal the uC that something happened. The interrupt function reads the AS3993 IRQ status registers. The interrupt function sets the flags if an event occours.

Definition at line 416 of file as3993.c.

u8 as3993ReadChipVersion ( void  )

This function reads the version register of the AS3993 and returns the value.

Returns
Returns the value of the AS3993 version register.

Definition at line 438 of file as3993.c.

void as3993Reset ( void  )

This function reads in the current register settings (configuration only), performs a reset by driving the enable line first low, then high and then writes back the register values.

Definition at line 789 of file as3993.c.

void as3993ResetDoNotPreserveRegisters ( void  )

This function performs a reset by driving the enable line first low, then high.

Definition at line 796 of file as3993.c.

void as3993SetBaseFrequency ( u8  regs,
u32  frequency 
)

This function sets the frequency in the appropriate register WARNING, only implemented for PLL Main Registers!!!

Parameters
regsWhich register is being used either AS3993_REG_PLLMAIN or AS3993_REG_PLLAUX
frequencyfrequency in kHz

Definition at line 633 of file as3993.c.

void as3993SingleCommand ( u8  command)

Sends only one command to the AS3993.

Parameters
commandThe command which is send to the AS3993.

Definition at line 448 of file as3993.c.

u8 as3993SingleRead ( u8  address)

Single Read -> reads one byte from one address of the AS3993.

Parameters
addressThe addressbyte
Returns
The databyte read from the AS3993

Definition at line 475 of file as3993.c.

void as3993SingleWrite ( u8  address,
u8  value 
)

Single Write -> writes one byte to one address of the AS3993.

Parameters
addressThe addressbyte
valueThe databyte

Definition at line 500 of file as3993.c.

s8 as3993TxRxGen2Bytes ( u8  cmd,
u8 *  txbuf,
u16  txbits,
u8 *  rxbuf,
u16 *  rxbits,
u8  norestime,
u8  followCmd,
u8  waitTxIrq 
)

This function is for generic sending and receiving gen2 commands through the FIFO. The parameters are:

Parameters
cmd,:One of the AS3993_CMD_* commands wich transmits something.
txbuf,:buffer to be tranmitted.
txbits,:the size of txbuf in bits
rxbuf,:a buffer getting the response of the tag
rxbits,:the maximum number of expected rx bits (size of rxbuf in bits) The value will be written to rxlength register. If 0 rxlength is automatically calculated by the reader and no boundary check for rxbuf is done.
norestime,:value for register AS3993_REG_RXNORESPONSEWAITTIME 0xff means 26 ms. Other values are much shorter.
followCmd,:Command to be sent after rxdone interrupt but before emptying FIFO. This is needed for not violating T2 timing requirement.
waitTxIrq,:If 0 tx irq will not be handled after transmitting command, otherwise FW will wait for Tx irq after transmitting command.

Certain values may be set to 0/NULL thus changing the behavior. Examples:

  • as3993TxRxGen2Bytes(AS3993_CMD_TRANSMCRCEHEAD, buf_, 50, buf_, &rxbits, 0xff, 0) with rxbits=33 can be used to send WRITE command and retrieve after max 20ms a reply expecting a header.
  • as3993TxRxGen2Bytes(AS3993_CMD_TRANSMCRC, buf_, len, NULL, &rxbits, 0, 0) with rxbits=0 is a transmit-only used for sending SELECT. With *rxbits==0 and rxbuf==NULL RX will be turned off immediately after TX-done interrupt
  • as3993TxRxGen2Bytes(AS3993_CMD_QUERY,buf_,16,tag->rn16,&rxlen,gen2IntConfig.no_resp_time,AS3993_CMD_ACK) with rxlen==16 sends QUERY command, waits for tx-done, then waits for rx-done, then sends ACK command and only as the last step reads RN16 from FIFO
  • as3993TxRxGen2Bytes(0,buf_,0,buf_,&rxlen,gen2IntConfig.no_resp_time,fast?0:AS3993_CMD_REQRN) with rxlen==sizeof(buf_)*8 does not send anything (ACK was executed via followCmd as previous example), waits for tx-done, waits for rx-done, sends REQRN, reads EPC from FIFO

Definition at line 1180 of file as3993.c.

void as3993WaitForResponse ( u16  waitMask)

This function waits for the specified response(IRQ).

Definition at line 543 of file as3993.c.

void as3993WaitForResponseFAST ( u16  waitMask)

This function waits for the specified response(IRQ).

Definition at line 563 of file as3993.c.

void as3993WaitForResponseTimed ( u16  waitMask,
u16  ms 
)

This function waits for the specified response(IRQ).

Definition at line 526 of file as3993.c.

Variable Documentation

u8 as3993PowerDownRegs[AS3993_REG_ICD+6]
static

Restore registers 0x00 to 0x1D + 5 registers (0x22, 0x29, 0x35, 0x36 and 0x3A) after power up

Definition at line 71 of file as3993.c.

volatile u16 as3993Response = 0

This variable is used as flag to signal an data reception. It is a bit mask of the RESP_TXIRQ, RESP_RXIRQ, RESP_* values

Definition at line 67 of file as3993.c.

u8 gChipRevisionZero = 1
static

Will be set to 0 if version register is > 0x60. Silicon revision 0x60 needs specific handling in some functions.

Definition at line 75 of file as3993.c.