mirror of
https://github.com/RfidResearchGroup/ChameleonMini.git
synced 2026-05-12 11:20:37 -07:00
Improved ISO15693 applications performance
Removed the if-elseif in EM4233 to use a switch case which yields minor speed improvements of ~1,5 microseconds Avoid reading the UID every AppProcess tick in both EM4233 and TiTagIT to save ~11 microseconds.
This commit is contained in:
@@ -23,6 +23,8 @@ static enum {
|
||||
} State;
|
||||
|
||||
bool loggedIn;
|
||||
uint8_t Uid[ISO15693_GENERIC_UID_SIZE];
|
||||
uint16_t ResponseByteCount;
|
||||
|
||||
void EM4233AppInit(void) {
|
||||
State = STATE_READY;
|
||||
@@ -35,7 +37,7 @@ void EM4233AppInit(void) {
|
||||
FrameInfo.Selected = false;
|
||||
loggedIn = false;
|
||||
MemoryReadBlock(&MyAFI, EM4233_MEM_AFI_ADDRESS, 1);
|
||||
|
||||
MemoryReadBlock(&Uid, EM4233_MEM_UID_ADDRESS, ActiveConfiguration.UidSize);
|
||||
}
|
||||
|
||||
void EM4233AppReset(void) {
|
||||
@@ -48,6 +50,8 @@ void EM4233AppReset(void) {
|
||||
FrameInfo.Addressed = false;
|
||||
FrameInfo.Selected = false;
|
||||
loggedIn = false;
|
||||
MemoryReadBlock(&MyAFI, EM4233_MEM_AFI_ADDRESS, 1);
|
||||
MemoryReadBlock(&Uid, EM4233_MEM_UID_ADDRESS, ActiveConfiguration.UidSize);
|
||||
}
|
||||
|
||||
void EM4233AppTask(void) {
|
||||
@@ -59,7 +63,7 @@ void EM4233AppTick(void) {
|
||||
}
|
||||
|
||||
uint16_t EM4233_Lock_Block(uint8_t *FrameBuf, uint16_t FrameBytes) {
|
||||
uint16_t ResponseByteCount = ISO15693_APP_NO_RESPONSE;
|
||||
ResponseByteCount = ISO15693_APP_NO_RESPONSE;
|
||||
uint8_t BlockAddress = *FrameInfo.Parameters;
|
||||
uint8_t LockStatus = 0;
|
||||
|
||||
@@ -89,7 +93,7 @@ uint16_t EM4233_Lock_Block(uint8_t *FrameBuf, uint16_t FrameBytes) {
|
||||
}
|
||||
|
||||
uint16_t EM4233_Write_Single(uint8_t *FrameBuf, uint16_t FrameBytes) {
|
||||
uint16_t ResponseByteCount = ISO15693_APP_NO_RESPONSE;
|
||||
ResponseByteCount = ISO15693_APP_NO_RESPONSE;
|
||||
uint8_t BlockAddress = *FrameInfo.Parameters;
|
||||
uint8_t *Dataptr = FrameInfo.Parameters + 0x01; /* Data to write begins on 2nd byte of the frame received by the reader */
|
||||
uint8_t LockStatus = 0;
|
||||
@@ -124,7 +128,7 @@ uint16_t EM4233_Write_Single(uint8_t *FrameBuf, uint16_t FrameBytes) {
|
||||
}
|
||||
|
||||
uint16_t EM4233_Read_Single(uint8_t *FrameBuf, uint16_t FrameBytes) {
|
||||
uint16_t ResponseByteCount = ISO15693_APP_NO_RESPONSE;
|
||||
ResponseByteCount = ISO15693_APP_NO_RESPONSE;
|
||||
uint8_t FramePtr; /* holds the address where block's data will be put */
|
||||
uint8_t BlockAddress = FrameInfo.Parameters[0];
|
||||
uint8_t LockStatus = 0;
|
||||
@@ -165,7 +169,7 @@ uint16_t EM4233_Read_Single(uint8_t *FrameBuf, uint16_t FrameBytes) {
|
||||
}
|
||||
|
||||
uint16_t EM4233_Read_Multiple(uint8_t *FrameBuf, uint16_t FrameBytes) {
|
||||
uint16_t ResponseByteCount = ISO15693_APP_NO_RESPONSE;
|
||||
ResponseByteCount = ISO15693_APP_NO_RESPONSE;
|
||||
uint8_t FramePtr; /* holds the address where block's data will be put */
|
||||
uint8_t BlockAddress = FrameInfo.Parameters[0];
|
||||
uint8_t BlocksNumber = FrameInfo.Parameters[1] + 0x01; /* according to ISO standard, we have to read 0x08 blocks if we get 0x07 in request */
|
||||
@@ -221,7 +225,7 @@ uint16_t EM4233_Read_Multiple(uint8_t *FrameBuf, uint16_t FrameBytes) {
|
||||
}
|
||||
|
||||
uint16_t EM4233_Write_AFI(uint8_t *FrameBuf, uint16_t FrameBytes) {
|
||||
uint16_t ResponseByteCount = ISO15693_APP_NO_RESPONSE;
|
||||
ResponseByteCount = ISO15693_APP_NO_RESPONSE;
|
||||
uint8_t AFI = FrameInfo.Parameters[0];
|
||||
uint8_t LockStatus = 0;
|
||||
|
||||
@@ -248,7 +252,7 @@ uint16_t EM4233_Write_AFI(uint8_t *FrameBuf, uint16_t FrameBytes) {
|
||||
}
|
||||
|
||||
uint16_t EM4233_Lock_AFI(uint8_t *FrameBuf, uint16_t FrameBytes) {
|
||||
uint16_t ResponseByteCount = ISO15693_APP_NO_RESPONSE;
|
||||
ResponseByteCount = ISO15693_APP_NO_RESPONSE;
|
||||
uint8_t LockStatus = 0;
|
||||
|
||||
if (FrameInfo.ParamLen != 0)
|
||||
@@ -275,7 +279,7 @@ uint16_t EM4233_Lock_AFI(uint8_t *FrameBuf, uint16_t FrameBytes) {
|
||||
}
|
||||
|
||||
uint16_t EM4233_Write_DSFID(uint8_t *FrameBuf, uint16_t FrameBytes) {
|
||||
uint16_t ResponseByteCount = ISO15693_APP_NO_RESPONSE;
|
||||
ResponseByteCount = ISO15693_APP_NO_RESPONSE;
|
||||
uint8_t DSFID = FrameInfo.Parameters[0];
|
||||
uint8_t LockStatus = 0;
|
||||
|
||||
@@ -301,7 +305,7 @@ uint16_t EM4233_Write_DSFID(uint8_t *FrameBuf, uint16_t FrameBytes) {
|
||||
}
|
||||
|
||||
uint16_t EM4233_Lock_DSFID(uint8_t *FrameBuf, uint16_t FrameBytes) {
|
||||
uint16_t ResponseByteCount = ISO15693_APP_NO_RESPONSE;
|
||||
ResponseByteCount = ISO15693_APP_NO_RESPONSE;
|
||||
uint8_t LockStatus = 0;
|
||||
|
||||
if (FrameInfo.ParamLen != 0)
|
||||
@@ -328,7 +332,7 @@ uint16_t EM4233_Lock_DSFID(uint8_t *FrameBuf, uint16_t FrameBytes) {
|
||||
}
|
||||
|
||||
uint8_t EM4233_Get_SysInfo(uint8_t *FrameBuf, uint16_t FrameBytes) {
|
||||
uint16_t ResponseByteCount = ISO15693_APP_NO_RESPONSE;
|
||||
ResponseByteCount = ISO15693_APP_NO_RESPONSE;
|
||||
uint8_t FramePtr; /* holds the address where block's data will be put */
|
||||
|
||||
if (FrameInfo.ParamLen != 0)
|
||||
@@ -351,8 +355,6 @@ uint8_t EM4233_Get_SysInfo(uint8_t *FrameBuf, uint16_t FrameBytes) {
|
||||
ResponseByteCount += 1; /* Increment the response count */
|
||||
|
||||
/* Then append UID */
|
||||
uint8_t Uid[ActiveConfiguration.UidSize];
|
||||
EM4233GetUid(Uid);
|
||||
ISO15693CopyUid(&FrameBuf[FramePtr], Uid);
|
||||
FramePtr += ISO15693_GENERIC_UID_SIZE; /* Move forward the buffer data pointer */
|
||||
ResponseByteCount += ISO15693_GENERIC_UID_SIZE; /* Increment the response count */
|
||||
@@ -395,7 +397,7 @@ uint8_t EM4233_Get_SysInfo(uint8_t *FrameBuf, uint16_t FrameBytes) {
|
||||
}
|
||||
|
||||
uint16_t EM4233_Get_Multi_Block_Sec_Stat(uint8_t *FrameBuf, uint16_t FrameBytes) {
|
||||
uint16_t ResponseByteCount = ISO15693_APP_NO_RESPONSE;
|
||||
ResponseByteCount = ISO15693_APP_NO_RESPONSE;
|
||||
uint8_t FramePtr; /* holds the address where block's data will be put */
|
||||
uint8_t BlockAddress = FrameInfo.Parameters[0];
|
||||
uint8_t BlocksNumber = FrameInfo.Parameters[1] + 0x01;
|
||||
@@ -424,7 +426,7 @@ uint16_t EM4233_Get_Multi_Block_Sec_Stat(uint8_t *FrameBuf, uint16_t FrameBytes)
|
||||
}
|
||||
|
||||
uint16_t EM4233_Select(uint8_t *FrameBuf, uint16_t FrameBytes, uint8_t *Uid) {
|
||||
uint16_t ResponseByteCount = ISO15693_APP_NO_RESPONSE;
|
||||
ResponseByteCount = ISO15693_APP_NO_RESPONSE;
|
||||
/* I've no idea how this request could generate errors ._.
|
||||
if ( ) {
|
||||
FrameBuf[ISO15693_ADDR_FLAGS] = ISO15693_RES_FLAG_ERROR;
|
||||
@@ -460,7 +462,7 @@ uint16_t EM4233_Select(uint8_t *FrameBuf, uint16_t FrameBytes, uint8_t *Uid) {
|
||||
}
|
||||
|
||||
uint16_t EM4233_Reset_To_Ready(uint8_t *FrameBuf, uint16_t FrameBytes) {
|
||||
uint16_t ResponseByteCount = ISO15693_APP_NO_RESPONSE;
|
||||
ResponseByteCount = ISO15693_APP_NO_RESPONSE;
|
||||
/* I've no idea how this request could generate errors ._.
|
||||
if ( ) {
|
||||
FrameBuf[ISO15693_ADDR_FLAGS] = ISO15693_RES_FLAG_ERROR;
|
||||
@@ -484,7 +486,7 @@ uint16_t EM4233_Reset_To_Ready(uint8_t *FrameBuf, uint16_t FrameBytes) {
|
||||
}
|
||||
|
||||
uint16_t EM4233_Login(uint8_t *FrameBuf, uint16_t FrameBytes) {
|
||||
uint16_t ResponseByteCount = ISO15693_APP_NO_RESPONSE;
|
||||
ResponseByteCount = ISO15693_APP_NO_RESPONSE;
|
||||
uint8_t Password[4] = { 0 };
|
||||
|
||||
if (FrameInfo.ParamLen != 4 || !FrameInfo.Addressed || !(FrameInfo.Selected && State == STATE_SELECTED))
|
||||
@@ -520,7 +522,7 @@ uint16_t EM4233_Login(uint8_t *FrameBuf, uint16_t FrameBytes) {
|
||||
}
|
||||
|
||||
uint16_t EM4233_Auth1(uint8_t *FrameBuf, uint16_t FrameBytes) {
|
||||
uint16_t ResponseByteCount = ISO15693_APP_NO_RESPONSE;
|
||||
ResponseByteCount = ISO15693_APP_NO_RESPONSE;
|
||||
// uint8_t KeyNo = *FrameInfo.Parameters; /* Right now this parameter is unused, but it will be useful */
|
||||
|
||||
if (FrameInfo.ParamLen != 1) /* Malformed: not enough or too much data */
|
||||
@@ -545,7 +547,7 @@ uint16_t EM4233_Auth1(uint8_t *FrameBuf, uint16_t FrameBytes) {
|
||||
}
|
||||
|
||||
uint16_t EM4233_Auth2(uint8_t *FrameBuf, uint16_t FrameBytes) {
|
||||
uint16_t ResponseByteCount = ISO15693_APP_NO_RESPONSE;
|
||||
ResponseByteCount = ISO15693_APP_NO_RESPONSE;
|
||||
// uint8_t A2 = FrameInfo.Parameters;
|
||||
// uint8_t f = FrameInfo.Parameters + 0x08;
|
||||
// uint8_t g[3] = { 0 }; /* Names according to EM Marin definitions */
|
||||
@@ -563,9 +565,7 @@ uint16_t EM4233_Auth2(uint8_t *FrameBuf, uint16_t FrameBytes) {
|
||||
}
|
||||
|
||||
uint16_t EM4233AppProcess(uint8_t *FrameBuf, uint16_t FrameBytes) {
|
||||
uint16_t ResponseByteCount = ISO15693_APP_NO_RESPONSE;
|
||||
uint8_t Uid[ActiveConfiguration.UidSize];
|
||||
EM4233GetUid(Uid);
|
||||
ResponseByteCount = ISO15693_APP_NO_RESPONSE;
|
||||
|
||||
if ((FrameBytes < ISO15693_MIN_FRAME_SIZE) || !ISO15693CheckCRC(FrameBuf, FrameBytes - ISO15693_CRC16_SIZE))
|
||||
/* malformed frame */
|
||||
@@ -582,8 +582,8 @@ uint16_t EM4233AppProcess(uint8_t *FrameBuf, uint16_t FrameBytes) {
|
||||
return ISO15693_APP_NO_RESPONSE;
|
||||
|
||||
if (State == STATE_READY || State == STATE_SELECTED) {
|
||||
|
||||
if (*FrameInfo.Command == ISO15693_CMD_INVENTORY) {
|
||||
switch (*FrameInfo.Command) {
|
||||
case ISO15693_CMD_INVENTORY:
|
||||
if (FrameInfo.ParamLen == 0)
|
||||
return ISO15693_APP_NO_RESPONSE; /* malformed: not enough or too much data */
|
||||
|
||||
@@ -593,59 +593,77 @@ uint16_t EM4233AppProcess(uint8_t *FrameBuf, uint16_t FrameBytes) {
|
||||
ISO15693CopyUid(&FrameBuf[ISO15693_RES_ADDR_PARAM + 0x01], Uid);
|
||||
ResponseByteCount += 10;
|
||||
}
|
||||
break;
|
||||
|
||||
} else if ((*FrameInfo.Command == ISO15693_CMD_STAY_QUIET) && FrameInfo.Addressed) {
|
||||
State = STATE_QUIET;
|
||||
case ISO15693_CMD_STAY_QUIET:
|
||||
if (FrameInfo.Addressed)
|
||||
State = STATE_QUIET;
|
||||
break;
|
||||
|
||||
} else if (*FrameInfo.Command == ISO15693_CMD_READ_SINGLE) {
|
||||
case ISO15693_CMD_READ_SINGLE:
|
||||
ResponseByteCount = EM4233_Read_Single(FrameBuf, FrameBytes);
|
||||
break;
|
||||
|
||||
} else if (*FrameInfo.Command == ISO15693_CMD_WRITE_SINGLE) {
|
||||
case ISO15693_CMD_WRITE_SINGLE:
|
||||
ResponseByteCount = EM4233_Write_Single(FrameBuf, FrameBytes);
|
||||
break;
|
||||
|
||||
} else if (*FrameInfo.Command == ISO15693_CMD_LOCK_BLOCK) {
|
||||
case ISO15693_CMD_LOCK_BLOCK:
|
||||
ResponseByteCount = EM4233_Lock_Block(FrameBuf, FrameBytes);
|
||||
break;
|
||||
|
||||
} else if (*FrameInfo.Command == ISO15693_CMD_READ_MULTIPLE) {
|
||||
case ISO15693_CMD_READ_MULTIPLE:
|
||||
ResponseByteCount = EM4233_Read_Multiple(FrameBuf, FrameBytes);
|
||||
break;
|
||||
|
||||
} else if (*FrameInfo.Command == ISO15693_CMD_WRITE_AFI) {
|
||||
case ISO15693_CMD_WRITE_AFI:
|
||||
ResponseByteCount = EM4233_Write_AFI(FrameBuf, FrameBytes);
|
||||
break;
|
||||
|
||||
} else if (*FrameInfo.Command == ISO15693_CMD_LOCK_AFI) {
|
||||
case ISO15693_CMD_LOCK_AFI:
|
||||
ResponseByteCount = EM4233_Lock_AFI(FrameBuf, FrameBytes);
|
||||
break;
|
||||
|
||||
} else if (*FrameInfo.Command == ISO15693_CMD_WRITE_DSFID) {
|
||||
case ISO15693_CMD_WRITE_DSFID:
|
||||
ResponseByteCount = EM4233_Write_DSFID(FrameBuf, FrameBytes);
|
||||
break;
|
||||
|
||||
} else if (*FrameInfo.Command == ISO15693_CMD_LOCK_DSFID) {
|
||||
case ISO15693_CMD_LOCK_DSFID:
|
||||
ResponseByteCount = EM4233_Lock_DSFID(FrameBuf, FrameBytes);
|
||||
break;
|
||||
|
||||
} else if (*FrameInfo.Command == ISO15693_CMD_GET_SYS_INFO) {
|
||||
case ISO15693_CMD_GET_SYS_INFO:
|
||||
ResponseByteCount = EM4233_Get_SysInfo(FrameBuf, FrameBytes);
|
||||
break;
|
||||
|
||||
} else if (*FrameInfo.Command == ISO15693_CMD_GET_BLOCK_SEC) {
|
||||
case ISO15693_CMD_GET_BLOCK_SEC:
|
||||
ResponseByteCount = EM4233_Get_Multi_Block_Sec_Stat(FrameBuf, FrameBytes);
|
||||
break;
|
||||
|
||||
} else if (*FrameInfo.Command == ISO15693_CMD_RESET_TO_READY) {
|
||||
case ISO15693_CMD_RESET_TO_READY:
|
||||
ResponseByteCount = EM4233_Reset_To_Ready(FrameBuf, FrameBytes);
|
||||
break;
|
||||
|
||||
} else if (*FrameInfo.Command == EM4233_CMD_LOGIN) {
|
||||
case EM4233_CMD_LOGIN:
|
||||
ResponseByteCount = EM4233_Login(FrameBuf, FrameBytes);
|
||||
break;
|
||||
|
||||
} else if (*FrameInfo.Command == EM4233_CMD_AUTH1) {
|
||||
case EM4233_CMD_AUTH1:
|
||||
ResponseByteCount = EM4233_Auth1(FrameBuf, FrameBytes);
|
||||
break;
|
||||
|
||||
} else if (*FrameInfo.Command == EM4233_CMD_AUTH2) {
|
||||
case EM4233_CMD_AUTH2:
|
||||
ResponseByteCount = EM4233_Auth2(FrameBuf, FrameBytes);
|
||||
break;
|
||||
|
||||
} else {
|
||||
default:
|
||||
if (FrameInfo.Addressed) {
|
||||
FrameBuf[ISO15693_ADDR_FLAGS] = ISO15693_RES_FLAG_ERROR;
|
||||
FrameBuf[ISO15693_RES_ADDR_PARAM] = ISO15693_RES_ERR_NOT_SUPP;
|
||||
ResponseByteCount = 2;
|
||||
} /* EM4233 respond with error flag only to addressed commands */
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
} else if (State == STATE_QUIET) {
|
||||
if (*FrameInfo.Command == ISO15693_CMD_RESET_TO_READY) {
|
||||
@@ -666,6 +684,7 @@ void EM4233GetUid(ConfigurationUidType Uid) {
|
||||
MemoryReadBlock(&Uid[0], EM4233_MEM_UID_ADDRESS, ActiveConfiguration.UidSize);
|
||||
}
|
||||
|
||||
void EM4233SetUid(ConfigurationUidType Uid) {
|
||||
MemoryWriteBlock(Uid, EM4233_MEM_UID_ADDRESS, ActiveConfiguration.UidSize);
|
||||
void EM4233SetUid(ConfigurationUidType NewUid) {
|
||||
memcpy(Uid, NewUid, ActiveConfiguration.UidSize);
|
||||
MemoryWriteBlock(NewUid, EM4233_MEM_UID_ADDRESS, ActiveConfiguration.UidSize);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,8 @@ static enum {
|
||||
|
||||
uint16_t UserLockBits_Mask = 0; /* Holds lock state of blocks */
|
||||
uint16_t FactoryLockBits_Mask = 0; /* Holds lock state of blocks */
|
||||
uint8_t Uid[ISO15693_GENERIC_UID_SIZE];
|
||||
uint16_t ResponseByteCount;
|
||||
|
||||
void TITagitstandardAppInit(void) {
|
||||
State = STATE_READY;
|
||||
@@ -33,6 +35,7 @@ void TITagitstandardAppInit(void) {
|
||||
FrameInfo.Selected = false;
|
||||
|
||||
MemoryReadBlock(&MyAFI, TITAGIT_MEM_AFI_ADDRESS, 1);
|
||||
TITagitstandardGetUid(Uid);
|
||||
}
|
||||
|
||||
void TITagitstandardAppReset(void) {
|
||||
@@ -44,6 +47,9 @@ void TITagitstandardAppReset(void) {
|
||||
FrameInfo.ParamLen = 0;
|
||||
FrameInfo.Addressed = false;
|
||||
FrameInfo.Selected = false;
|
||||
|
||||
MemoryReadBlock(&MyAFI, TITAGIT_MEM_AFI_ADDRESS, 1);
|
||||
TITagitstandardGetUid(Uid);
|
||||
}
|
||||
|
||||
|
||||
@@ -56,9 +62,7 @@ void TITagitstandardAppTick(void) {
|
||||
}
|
||||
|
||||
uint16_t TITagitstandardAppProcess(uint8_t *FrameBuf, uint16_t FrameBytes) {
|
||||
uint16_t ResponseByteCount = ISO15693_APP_NO_RESPONSE;
|
||||
uint8_t Uid[ActiveConfiguration.UidSize];
|
||||
TITagitstandardGetUid(Uid);
|
||||
ResponseByteCount = ISO15693_APP_NO_RESPONSE;
|
||||
|
||||
if ((FrameBytes < ISO15693_MIN_FRAME_SIZE) || !ISO15693CheckCRC(FrameBuf, FrameBytes - ISO15693_CRC16_SIZE))
|
||||
/* malformed frame */
|
||||
@@ -213,6 +217,7 @@ void TITagitstandardGetUid(ConfigurationUidType Uid) {
|
||||
}
|
||||
|
||||
void TITagitstandardSetUid(ConfigurationUidType Uid) {
|
||||
memcpy(Uid, NewUid, ActiveConfiguration.UidSize); // Update the local variable
|
||||
// Reverse UID before writing it
|
||||
TITagitstandardFlipUid(Uid);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user