unified indentation

This commit is contained in:
Georg
2017-11-07 15:53:23 +01:00
parent 44f2085401
commit 94d24d95c6
40 changed files with 2895 additions and 2895 deletions
+9 -9
View File
@@ -6,14 +6,14 @@
void AntennaLevelTick(void)
{
uint16_t rssi = AntennaLevelGet();
uint16_t rssi = AntennaLevelGet();
if (rssi < FIELD_MIN_RSSI)
{
LEDHook(LED_FIELD_DETECTED, LED_OFF);
if (ActiveConfiguration.UidSize != 0) // this implies that we are emulating right now
ApplicationReset(); // reset the application just like a real card gets reset when there is no field
} else {
LEDHook(LED_FIELD_DETECTED, LED_ON);
}
if (rssi < FIELD_MIN_RSSI)
{
LEDHook(LED_FIELD_DETECTED, LED_OFF);
if (ActiveConfiguration.UidSize != 0) // this implies that we are emulating right now
ApplicationReset(); // reset the application just like a real card gets reset when there is no field
} else {
LEDHook(LED_FIELD_DETECTED, LED_ON);
}
}
+12 -12
View File
@@ -25,27 +25,27 @@
static inline
void AntennaLevelInit(void)
{
ADCA.CTRLA = ADC_ENABLE_bm;
ADCA.CTRLB = ADC_RESOLUTION_12BIT_gc;
ADCA.REFCTRL = ADC_REFSEL_INT1V_gc | ADC_BANDGAP_bm;
ADCA.PRESCALER = ADC_PRESCALER_DIV32_gc;
ADCA.CH0.CTRL = ADC_CH_INPUTMODE_SINGLEENDED_gc;
ADCA.CH0.MUXCTRL = ADC_CH_MUXPOS_PIN1_gc;
ADCA.CTRLA = ADC_ENABLE_bm;
ADCA.CTRLB = ADC_RESOLUTION_12BIT_gc;
ADCA.REFCTRL = ADC_REFSEL_INT1V_gc | ADC_BANDGAP_bm;
ADCA.PRESCALER = ADC_PRESCALER_DIV32_gc;
ADCA.CH0.CTRL = ADC_CH_INPUTMODE_SINGLEENDED_gc;
ADCA.CH0.MUXCTRL = ADC_CH_MUXPOS_PIN1_gc;
}
static inline
uint16_t AntennaLevelGet(void)
{
ADCA.CH0.CTRL |= ADC_CH_START_bm;
while( !(ADCA.CH0.INTFLAGS & ADC_CH_CHIF_bm) );
ADCA.CH0.CTRL |= ADC_CH_START_bm;
while( !(ADCA.CH0.INTFLAGS & ADC_CH_CHIF_bm) );
ADCA.CH0.INTFLAGS = ADC_CH_CHIF_bm;
ADCA.CH0.INTFLAGS = ADC_CH_CHIF_bm;
int16_t Result = ADCA.CH0RES - ANTENNA_LEVEL_OFFSET;
if (Result < 0) Result = 0;
int16_t Result = ADCA.CH0RES - ANTENNA_LEVEL_OFFSET;
if (Result < 0) Result = 0;
return (uint16_t) (((uint32_t) Result * ANTENNA_LEVEL_NUMERATOR) / ANTENNA_LEVEL_DENOMINATOR);
return (uint16_t) (((uint32_t) Result * ANTENNA_LEVEL_NUMERATOR) / ANTENNA_LEVEL_DENOMINATOR);
}
void AntennaLevelTick(void);
@@ -23,11 +23,11 @@ INLINE void ApplicationInit(void) {
}
INLINE void ApplicationTask(void) {
ActiveConfiguration.ApplicationTaskFunc();
ActiveConfiguration.ApplicationTaskFunc();
}
INLINE void ApplicationTick(void) {
ActiveConfiguration.ApplicationTickFunc();
ActiveConfiguration.ApplicationTickFunc();
}
INLINE uint16_t ApplicationProcess(uint8_t* ByteBuffer, uint16_t ByteCount) {
+105 -105
View File
@@ -50,42 +50,42 @@
/* Used for LFSR setup. */
#define SPLIT_BYTE(__even, __odd, __byte) \
__asm__ __volatile__ ( \
"lsr %2" "\n\t" \
"ror %0" "\n\t" \
"lsr %2" "\n\t" \
"ror %1" "\n\t" \
"lsr %2" "\n\t" \
"ror %0" "\n\t" \
"lsr %2" "\n\t" \
"ror %1" "\n\t" \
"lsr %2" "\n\t" \
"ror %0" "\n\t" \
"lsr %2" "\n\t" \
"ror %1" "\n\t" \
"lsr %2" "\n\t" \
"ror %0" "\n\t" \
"lsr %2" "\n\t" \
"ror %1" \
: "+r" (__even), \
"lsr %2" "\n\t" \
"ror %0" "\n\t" \
"lsr %2" "\n\t" \
"ror %1" "\n\t" \
"lsr %2" "\n\t" \
"ror %0" "\n\t" \
"lsr %2" "\n\t" \
"ror %1" "\n\t" \
"lsr %2" "\n\t" \
"ror %0" "\n\t" \
"lsr %2" "\n\t" \
"ror %1" "\n\t" \
"lsr %2" "\n\t" \
"ror %0" "\n\t" \
"lsr %2" "\n\t" \
"ror %1" \
: "+r" (__even), \
"+r" (__odd), \
"+r" (__byte) \
"+r" (__byte) \
: \
: "r0" )
: "r0" )
/* Shift half LFSR state stored in three registers */
/* Input is bit 0 of __in */
#define SHIFT24(__b0, __b1, __b2, __in) \
__asm__ __volatile__ ( \
"lsr %3" "\n\t" \
"ror %2" "\n\t" \
"ror %1" "\n\t" \
"ror %0" \
: "+r" (__b0), \
"lsr %3" "\n\t" \
"ror %2" "\n\t" \
"ror %1" "\n\t" \
"ror %0" \
: "+r" (__b0), \
"+r" (__b1), \
"+r" (__b2), \
"+r" (__in) \
"+r" (__in) \
: \
: )
: )
/* Shift half LFSR state stored in three registers */
/* Input is bit 0 of __in */
@@ -93,29 +93,29 @@
#define SHIFT24_COND_DECRYPT(__b0, __b1, __b2, __in, __stream, __decrypt) \
__asm__ __volatile__ ( \
"sbrc %5, 0" "\n\t" \
"eor %3, %4" "\n\t" \
"eor %3, %4" "\n\t" \
"lsr %3" "\n\t" \
"ror %2" "\n\t" \
"ror %1" "\n\t" \
"ror %0" \
: "+r" (__b0), \
"ror %2" "\n\t" \
"ror %1" "\n\t" \
"ror %0" \
: "+r" (__b0), \
"+r" (__b1), \
"+r" (__b2), \
"+r" (__in) \
: "r" (__stream), \
"r" (__decrypt) \
: "r0" )
"+r" (__in) \
: "r" (__stream), \
"r" (__decrypt) \
: "r0" )
/* Shift a byte with input from an other byte */
/* Input is bit 0 of __in */
#define SHIFT8(__byte, __in) \
__asm__ __volatile__ ( \
"lsr %1" "\n\t" \
"ror %0" \
: "+r" (__byte), \
"+r" (__in) \
__asm__ __volatile__ ( \
"lsr %1" "\n\t" \
"ror %0" \
: "+r" (__byte), \
"+r" (__in) \
: \
: "r0" )
: "r0" )
/* End AVR specific */
#else
@@ -142,14 +142,14 @@
#define SHIFT8(__byte, __in) __byte = (__byte>>1) | ((__in)<<7)
#define SPLIT_BYTE(__even, __odd, __byte) \
__even = (__even >> 1) | (__byte<<7); __byte>>=1; \
__odd = (__odd >> 1) | (__byte<<7); __byte>>=1; \
__even = (__even >> 1) | (__byte<<7); __byte>>=1; \
__odd = (__odd >> 1) | (__byte<<7); __byte>>=1; \
__even = (__even >> 1) | (__byte<<7); __byte>>=1; \
__odd = (__odd >> 1) | (__byte<<7); __byte>>=1; \
__even = (__even >> 1) | (__byte<<7); __byte>>=1; \
__odd = (__odd >> 1) | (__byte<<7)
__even = (__even >> 1) | (__byte<<7); __byte>>=1; \
__odd = (__odd >> 1) | (__byte<<7); __byte>>=1; \
__even = (__even >> 1) | (__byte<<7); __byte>>=1; \
__odd = (__odd >> 1) | (__byte<<7); __byte>>=1; \
__even = (__even >> 1) | (__byte<<7); __byte>>=1; \
__odd = (__odd >> 1) | (__byte<<7); __byte>>=1; \
__even = (__even >> 1) | (__byte<<7); __byte>>=1; \
__odd = (__odd >> 1) | (__byte<<7)
/* Generate odd parity bit */
@@ -319,26 +319,26 @@ static const uint8_t TableC3[32] = {
/* Filter Output Macros */
/* Output at bit 7 for optimized byte processing */
#define CRYPTO1_FILTER_OUTPUT_B7_24(__O0, __O1, __O2) TableC7[ abFilterTable[0][__O0] | \
abFilterTable[1][__O1] | \
abFilterTable[2][__O2]]
abFilterTable[1][__O1] | \
abFilterTable[2][__O2]]
/* Output at bit 3 for optimized nibble processing */
#define CRYPTO1_FILTER_OUTPUT_B3_24(__O0, __O1, __O2) TableC3[ abFilterTable[0][__O0] | \
abFilterTable[1][__O1] | \
abFilterTable[2][__O2]]
abFilterTable[1][__O1] | \
abFilterTable[2][__O2]]
/* Output at bit 0 for general purpose */
#define CRYPTO1_FILTER_OUTPUT_B0_24(__O0, __O1, __O2) TableC0[ abFilterTable[0][__O0] | \
abFilterTable[1][__O1] | \
abFilterTable[2][__O2]]
abFilterTable[1][__O1] | \
abFilterTable[2][__O2]]
/* Split Crypto1 state into even and odd bits */
/* to speed up the output filter network */
/* Put both into one struct to enable relative adressing */
typedef struct
{
uint8_t Even[LFSR_SIZE/2];
uint8_t Odd[LFSR_SIZE/2];
uint8_t Even[LFSR_SIZE/2];
uint8_t Odd[LFSR_SIZE/2];
} Crypto1LfsrState_t;
static Crypto1LfsrState_t State = {{0},{0}};
@@ -346,35 +346,35 @@ static Crypto1LfsrState_t State = {{0},{0}};
/* Debug output of state */
void Crypto1GetState(uint8_t* pEven, uint8_t* pOdd)
{
if (pEven)
{
pEven[0] = State.Even[0];
pEven[1] = State.Even[1];
pEven[2] = State.Even[2];
}
if (pOdd)
{
pOdd[0] = State.Odd[0];
pOdd[1] = State.Odd[1];
pOdd[2] = State.Odd[2];
}
if (pEven)
{
pEven[0] = State.Even[0];
pEven[1] = State.Even[1];
pEven[2] = State.Even[2];
}
if (pOdd)
{
pOdd[0] = State.Odd[0];
pOdd[1] = State.Odd[1];
pOdd[2] = State.Odd[2];
}
}
/* Proceed LFSR by one clock cycle */
/* Prototype to force inlining */
static __inline__ uint8_t Crypto1LFSRbyteFeedback (uint8_t E0,
uint8_t E1,
uint8_t E2,
uint8_t O0,
uint8_t O1,
uint8_t O2) __attribute__((always_inline));
uint8_t E1,
uint8_t E2,
uint8_t O0,
uint8_t O1,
uint8_t O2) __attribute__((always_inline));
static uint8_t Crypto1LFSRbyteFeedback (uint8_t E0,
uint8_t E1,
uint8_t E2,
uint8_t O0,
uint8_t O1,
uint8_t O2)
uint8_t E1,
uint8_t E2,
uint8_t O0,
uint8_t O1,
uint8_t O2)
{
uint8_t Feedback;
@@ -448,8 +448,8 @@ uint8_t Crypto1FilterOutput(void) {
/* Setup LFSR split into odd and even states, feed in uid ^nonce */
/* Version for first (not nested) authentication. */
void Crypto1Setup(uint8_t Key[6],
uint8_t Uid[4],
uint8_t CardNonce[4])
uint8_t Uid[4],
uint8_t CardNonce[4])
{
/* state registers */
register uint8_t Even0, Even1, Even2;
@@ -1061,32 +1061,32 @@ void Crypto1PRNG(uint8_t State[4], uint8_t ClockCount)
void Crypto1EncryptWithParity(uint8_t * Buffer, uint8_t BitCount)
{
uint8_t i = 0;
while (i < BitCount)
{
Buffer[i/8] ^=
CRYPTO1_FILTER_OUTPUT_B0_24(State.Odd[0], State.Odd[1], State.Odd[2])
<< (i % 8);
if (++i % 9 != 0) // only shift, if this was no parity bit
Crypto1LFSR(0);
}
uint8_t i = 0;
while (i < BitCount)
{
Buffer[i/8] ^=
CRYPTO1_FILTER_OUTPUT_B0_24(State.Odd[0], State.Odd[1], State.Odd[2])
<< (i % 8);
if (++i % 9 != 0) // only shift, if this was no parity bit
Crypto1LFSR(0);
}
}
void Crypto1ReaderAuthWithParity(uint8_t PlainReaderAnswerWithParityBits[9])
{
uint8_t i = 0, feedback;
while (i < 72)
{
feedback = PlainReaderAnswerWithParityBits[i/8] >> (i % 8);
PlainReaderAnswerWithParityBits[i/8] ^=
CRYPTO1_FILTER_OUTPUT_B0_24(State.Odd[0], State.Odd[1], State.Odd[2])
<< (i % 8);
if (++i % 9 != 0) // only shift, if this was no parity bit
{
if (i <= 36)
Crypto1LFSR(feedback & 1);
else
Crypto1LFSR(0);
}
}
uint8_t i = 0, feedback;
while (i < 72)
{
feedback = PlainReaderAnswerWithParityBits[i/8] >> (i % 8);
PlainReaderAnswerWithParityBits[i/8] ^=
CRYPTO1_FILTER_OUTPUT_B0_24(State.Odd[0], State.Odd[1], State.Odd[2])
<< (i % 8);
if (++i % 9 != 0) // only shift, if this was no parity bit
{
if (i <= 36)
Crypto1LFSR(feedback & 1);
else
Crypto1LFSR(0);
}
}
}
@@ -93,16 +93,16 @@ bool ISO14443ASelect(void* Buffer, uint16_t* BitCount, uint8_t* UidCL, uint8_t S
}
default:
{
uint8_t CollisionByteCount = ((NVB >> 4) & 0x0f) - 2;
uint8_t CollisionBitCount = (NVB >> 0) & 0x0f;
uint8_t mask = 0xFF >> (8 - CollisionBitCount);
// Since the UidCL does not contain the BCC, we have to distinguish here
uint8_t CollisionByteCount = ((NVB >> 4) & 0x0f) - 2;
uint8_t CollisionBitCount = (NVB >> 0) & 0x0f;
uint8_t mask = 0xFF >> (8 - CollisionBitCount);
// Since the UidCL does not contain the BCC, we have to distinguish here
if (
((CollisionByteCount == 5 || (CollisionByteCount == 4 && CollisionBitCount > 0)) && memcmp(UidCL, &DataPtr[2], 4) == 0 && (ISO14443A_CALC_BCC(UidCL) & mask) == (DataPtr[6] & mask))
||
(CollisionByteCount == 4 && CollisionBitCount == 0 && memcmp(UidCL, &DataPtr[2], 4) == 0)
||
(CollisionByteCount < 4 && memcmp(UidCL, &DataPtr[2], CollisionByteCount) == 0 && (UidCL[CollisionByteCount] & mask) == (DataPtr[CollisionByteCount + 2] & mask))
((CollisionByteCount == 5 || (CollisionByteCount == 4 && CollisionBitCount > 0)) && memcmp(UidCL, &DataPtr[2], 4) == 0 && (ISO14443A_CALC_BCC(UidCL) & mask) == (DataPtr[6] & mask))
||
(CollisionByteCount == 4 && CollisionBitCount == 0 && memcmp(UidCL, &DataPtr[2], 4) == 0)
||
(CollisionByteCount < 4 && memcmp(UidCL, &DataPtr[2], CollisionByteCount) == 0 && (UidCL[CollisionByteCount] & mask) == (DataPtr[CollisionByteCount + 2] & mask))
)
{
DataPtr[0] = UidCL[0];
@@ -113,7 +113,7 @@ bool ISO14443ASelect(void* Buffer, uint16_t* BitCount, uint8_t* UidCL, uint8_t S
*BitCount = ISO14443A_CL_FRAME_SIZE;
} else {
*BitCount = 0;
*BitCount = 0;
}
return false;
}
@@ -137,7 +137,7 @@ bool ISO14443AWakeUp(void* Buffer, uint16_t* BitCount, uint16_t ATQAValue, bool
return true;
} else {
*BitCount = 0;
*BitCount = 0;
return false;
}
File diff suppressed because it is too large Load Diff
@@ -88,7 +88,7 @@ uint16_t MifareUltralightAppProcess(uint8_t* Buffer, uint16_t BitCount)
switch(State) {
case STATE_IDLE:
case STATE_HALT:
FromHalt = State == STATE_HALT;
FromHalt = State == STATE_HALT;
if (ISO14443AWakeUp(Buffer, &BitCount, ATQA_VALUE, FromHalt)) {
/* We received a REQA or WUPA command, so wake up. */
State = STATE_READY1;
File diff suppressed because it is too large Load Diff
@@ -24,13 +24,13 @@ bool checkParityBits(uint8_t * Buffer, uint16_t BitCount);
uint16_t ISO14443_CRCA(uint8_t * Buffer, uint8_t ByteCount);
typedef enum {
Reader14443_Do_Nothing,
Reader14443_Send,
Reader14443_Send_Raw,
Reader14443_Get_UID,
Reader14443_Autocalibrate,
Reader14443_Read_MF_Ultralight,
Reader14443_Identify
Reader14443_Do_Nothing,
Reader14443_Send,
Reader14443_Send_Raw,
Reader14443_Get_UID,
Reader14443_Autocalibrate,
Reader14443_Read_MF_Ultralight,
Reader14443_Identify
} Reader14443Command;
+7 -7
View File
@@ -16,16 +16,16 @@
#define BATTERY_PORT_MASK (BATTERY_STAT_PIN)
INLINE void BatteryInit(void) {
BATTERY_PORT.DIRCLR = BATTERY_PORT_MASK;
BATTERY_PORT.BATTERY_STAT_PINCTRL = PORT_OPC_PULLUP_gc;
BATTERY_PORT.DIRCLR = BATTERY_PORT_MASK;
BATTERY_PORT.BATTERY_STAT_PINCTRL = PORT_OPC_PULLUP_gc;
}
INLINE bool BatteryIsCharging(void) {
if (!(BATTERY_PORT.IN & BATTERY_STAT_PIN)) {
return true;
} else {
return false;
}
if (!(BATTERY_PORT.IN & BATTERY_STAT_PIN)) {
return true;
} else {
return false;
}
}
#endif /* BATTERY_H_ */
+80 -80
View File
@@ -16,17 +16,17 @@
#define LONG_PRESS_TICK_COUNT 10
static const MapEntryType PROGMEM ButtonActionMap[] = {
{ .Id = BUTTON_ACTION_NONE, .Text = "NONE" },
{ .Id = BUTTON_ACTION_UID_RANDOM, .Text = "UID_RANDOM" },
{ .Id = BUTTON_ACTION_UID_LEFT_INCREMENT, .Text = "UID_LEFT_INCREMENT" },
{ .Id = BUTTON_ACTION_UID_RIGHT_INCREMENT, .Text = "UID_RIGHT_INCREMENT" },
{ .Id = BUTTON_ACTION_UID_LEFT_DECREMENT, .Text = "UID_LEFT_DECREMENT" },
{ .Id = BUTTON_ACTION_UID_RIGHT_DECREMENT, .Text = "UID_RIGHT_DECREMENT" },
{ .Id = BUTTON_ACTION_CYCLE_SETTINGS, .Text = "CYCLE_SETTINGS" },
{ .Id = BUTTON_ACTION_STORE_MEM, .Text = "STORE_MEM" },
{ .Id = BUTTON_ACTION_RECALL_MEM, .Text = "RECALL_MEM" },
{ .Id = BUTTON_ACTION_TOGGLE_FIELD, .Text = "TOGGLE_FIELD" },
{ .Id = BUTTON_ACTION_STORE_LOG, .Text = "STORE_LOG" },
{ .Id = BUTTON_ACTION_NONE, .Text = "NONE" },
{ .Id = BUTTON_ACTION_UID_RANDOM, .Text = "UID_RANDOM" },
{ .Id = BUTTON_ACTION_UID_LEFT_INCREMENT, .Text = "UID_LEFT_INCREMENT" },
{ .Id = BUTTON_ACTION_UID_RIGHT_INCREMENT, .Text = "UID_RIGHT_INCREMENT" },
{ .Id = BUTTON_ACTION_UID_LEFT_DECREMENT, .Text = "UID_LEFT_DECREMENT" },
{ .Id = BUTTON_ACTION_UID_RIGHT_DECREMENT, .Text = "UID_RIGHT_DECREMENT" },
{ .Id = BUTTON_ACTION_CYCLE_SETTINGS, .Text = "CYCLE_SETTINGS" },
{ .Id = BUTTON_ACTION_STORE_MEM, .Text = "STORE_MEM" },
{ .Id = BUTTON_ACTION_RECALL_MEM, .Text = "RECALL_MEM" },
{ .Id = BUTTON_ACTION_TOGGLE_FIELD, .Text = "TOGGLE_FIELD" },
{ .Id = BUTTON_ACTION_STORE_LOG, .Text = "STORE_LOG" },
};
static void ExecuteButtonAction(ButtonActionEnum ButtonAction)
@@ -147,51 +147,51 @@ static void ExecuteButtonAction(ButtonActionEnum ButtonAction)
case BUTTON_ACTION_CYCLE_SETTINGS:
{
SettingsCycle();
SettingsCycle();
break;
}
case BUTTON_ACTION_STORE_MEM:
{
MemoryStore();
MemoryStore();
break;
}
case BUTTON_ACTION_RECALL_MEM:
{
MemoryRecall();
MemoryRecall();
break;
}
case BUTTON_ACTION_TOGGLE_FIELD:
{
if (!CodecGetReaderField())
{
CodecReaderFieldStart();
} else {
CodecReaderFieldStop();
}
break;
if (!CodecGetReaderField())
{
CodecReaderFieldStart();
} else {
CodecReaderFieldStop();
}
break;
}
case BUTTON_ACTION_STORE_LOG:
{
LogSRAMToFRAM();
break;
LogSRAMToFRAM();
break;
}
default:
break;
break;
}
}
void ButtonInit(void)
{
BUTTON_PORT.DIRCLR = BUTTON_MASK;
BUTTON_PORT.BUTTON_R_PINCTRL = PORT_OPC_PULLUP_gc;
BUTTON_PORT.BUTTON_L_PINCTRL = PORT_OPC_PULLUP_gc;
BUTTON_PORT.DIRCLR = BUTTON_MASK;
BUTTON_PORT.BUTTON_R_PINCTRL = PORT_OPC_PULLUP_gc;
BUTTON_PORT.BUTTON_L_PINCTRL = PORT_OPC_PULLUP_gc;
}
void ButtonTick(void)
@@ -201,85 +201,85 @@ void ButtonTick(void)
uint8_t ThisButtonState = ~BUTTON_PORT.IN;
if (ThisButtonState & BUTTON_R) {
/* Button is currently pressed */
if (ButtonRPressTick < LONG_PRESS_TICK_COUNT) {
/* Count ticks while button is being pressed */
ButtonRPressTick++;
} else if (ButtonRPressTick == LONG_PRESS_TICK_COUNT) {
/* Long button press detected execute button action and advance PressTickCounter
* to an invalid state. */
ExecuteButtonAction(GlobalSettings.ActiveSettingPtr->ButtonActions[BUTTON_R_PRESS_LONG]);
ButtonRPressTick++;
} else {
/* Button is still pressed, ignore */
}
/* Button is currently pressed */
if (ButtonRPressTick < LONG_PRESS_TICK_COUNT) {
/* Count ticks while button is being pressed */
ButtonRPressTick++;
} else if (ButtonRPressTick == LONG_PRESS_TICK_COUNT) {
/* Long button press detected execute button action and advance PressTickCounter
* to an invalid state. */
ExecuteButtonAction(GlobalSettings.ActiveSettingPtr->ButtonActions[BUTTON_R_PRESS_LONG]);
ButtonRPressTick++;
} else {
/* Button is still pressed, ignore */
}
} else if (!(ThisButtonState & BUTTON_MASK)) {
/* Button is currently not being pressed. Check if PressTickCounter contains
* a recent short button press. */
if ( (ButtonRPressTick > 0) && (ButtonRPressTick <= LONG_PRESS_TICK_COUNT) ) {
/* We have a short button press */
ExecuteButtonAction(GlobalSettings.ActiveSettingPtr->ButtonActions[BUTTON_R_PRESS_SHORT]);
}
/* Button is currently not being pressed. Check if PressTickCounter contains
* a recent short button press. */
if ( (ButtonRPressTick > 0) && (ButtonRPressTick <= LONG_PRESS_TICK_COUNT) ) {
/* We have a short button press */
ExecuteButtonAction(GlobalSettings.ActiveSettingPtr->ButtonActions[BUTTON_R_PRESS_SHORT]);
}
ButtonRPressTick = 0;
ButtonRPressTick = 0;
}
if (ThisButtonState & BUTTON_L) {
/* Button is currently pressed */
if (ButtonLPressTick < LONG_PRESS_TICK_COUNT) {
/* Count ticks while button is being pressed */
ButtonLPressTick++;
} else if (ButtonLPressTick == LONG_PRESS_TICK_COUNT) {
/* Long button press detected execute button action and advance PressTickCounter
* to an invalid state. */
ExecuteButtonAction(GlobalSettings.ActiveSettingPtr->ButtonActions[BUTTON_L_PRESS_LONG]);
ButtonLPressTick++;
} else {
/* Button is still pressed, ignore */
}
/* Button is currently pressed */
if (ButtonLPressTick < LONG_PRESS_TICK_COUNT) {
/* Count ticks while button is being pressed */
ButtonLPressTick++;
} else if (ButtonLPressTick == LONG_PRESS_TICK_COUNT) {
/* Long button press detected execute button action and advance PressTickCounter
* to an invalid state. */
ExecuteButtonAction(GlobalSettings.ActiveSettingPtr->ButtonActions[BUTTON_L_PRESS_LONG]);
ButtonLPressTick++;
} else {
/* Button is still pressed, ignore */
}
} else if (!(ThisButtonState & BUTTON_MASK)) {
/* Button is currently not being pressed. Check if PressTickCounter contains
* a recent short button press. */
if ( (ButtonLPressTick > 0) && (ButtonLPressTick <= LONG_PRESS_TICK_COUNT) ) {
/* We have a short button press */
ExecuteButtonAction(GlobalSettings.ActiveSettingPtr->ButtonActions[BUTTON_L_PRESS_SHORT]);
}
/* Button is currently not being pressed. Check if PressTickCounter contains
* a recent short button press. */
if ( (ButtonLPressTick > 0) && (ButtonLPressTick <= LONG_PRESS_TICK_COUNT) ) {
/* We have a short button press */
ExecuteButtonAction(GlobalSettings.ActiveSettingPtr->ButtonActions[BUTTON_L_PRESS_SHORT]);
}
ButtonLPressTick = 0;
ButtonLPressTick = 0;
}
}
void ButtonGetActionList(char* List, uint16_t BufferSize)
{
MapToString(ButtonActionMap, ARRAY_COUNT(ButtonActionMap), List, BufferSize);
MapToString(ButtonActionMap, ARRAY_COUNT(ButtonActionMap), List, BufferSize);
}
void ButtonSetActionById(ButtonTypeEnum Type, ButtonActionEnum Action)
{
#ifndef BUTTON_SETTING_GLOBAL
GlobalSettings.ActiveSettingPtr->ButtonActions[Type] = Action;
GlobalSettings.ActiveSettingPtr->ButtonActions[Type] = Action;
#else
/* Write button action to all settings when using global settings */
for (uint8_t i=0; i<SETTINGS_COUNT; i++) {
GlobalSettings.Settings[i].ButtonActions[Type] = Action;
}
/* Write button action to all settings when using global settings */
for (uint8_t i=0; i<SETTINGS_COUNT; i++) {
GlobalSettings.Settings[i].ButtonActions[Type] = Action;
}
#endif
}
void ButtonGetActionByName(ButtonTypeEnum Type, char* Action, uint16_t BufferSize)
{
MapIdToText(ButtonActionMap, ARRAY_COUNT(ButtonActionMap),
GlobalSettings.ActiveSettingPtr->ButtonActions[Type], Action, BufferSize);
MapIdToText(ButtonActionMap, ARRAY_COUNT(ButtonActionMap),
GlobalSettings.ActiveSettingPtr->ButtonActions[Type], Action, BufferSize);
}
bool ButtonSetActionByName(ButtonTypeEnum Type, const char* Action)
{
MapIdType Id;
MapIdType Id;
if (MapTextToId(ButtonActionMap, ARRAY_COUNT(ButtonActionMap), Action, &Id)) {
ButtonSetActionById(Type, Id);
return true;
} else {
return false;
}
if (MapTextToId(ButtonActionMap, ARRAY_COUNT(ButtonActionMap), Action, &Id)) {
ButtonSetActionById(Type, Id);
return true;
} else {
return false;
}
}
+8 -8
View File
@@ -11,13 +11,13 @@
#include "Common.h"
typedef enum {
BUTTON_R_PRESS_SHORT = 0,
BUTTON_R_PRESS_LONG,
BUTTON_L_PRESS_SHORT,
BUTTON_L_PRESS_LONG,
BUTTON_R_PRESS_SHORT = 0,
BUTTON_R_PRESS_LONG,
BUTTON_L_PRESS_SHORT,
BUTTON_L_PRESS_LONG,
/* Must be last element */
BUTTON_TYPE_COUNT
/* Must be last element */
BUTTON_TYPE_COUNT
} ButtonTypeEnum;
typedef enum {
@@ -30,8 +30,8 @@ typedef enum {
BUTTON_ACTION_CYCLE_SETTINGS,
BUTTON_ACTION_STORE_MEM,
BUTTON_ACTION_RECALL_MEM,
BUTTON_ACTION_TOGGLE_FIELD,
BUTTON_ACTION_STORE_LOG,
BUTTON_ACTION_TOGGLE_FIELD,
BUTTON_ACTION_STORE_LOG,
/* This has to be last element */
BUTTON_ACTION_COUNT
+14 -14
View File
@@ -16,24 +16,24 @@ int main(void)
SystemInterruptInit();
while(1) {
if (SystemTick100ms()) {
if (SystemTick100ms()) {
LEDTick(); // this has to be the first function called here, since it is time-critical - the functions below may have non-negligible runtimes!
RandomTick();
TerminalTick();
ButtonTick();
LogTick();
ApplicationTick();
CommandLineTick();
AntennaLevelTick();
RandomTick();
TerminalTick();
ButtonTick();
LogTick();
ApplicationTick();
CommandLineTick();
AntennaLevelTick();
LEDHook(LED_POWERED, LED_ON);
}
LEDHook(LED_POWERED, LED_ON);
}
TerminalTask();
LogTask();
ApplicationTask();
CodecTask();
TerminalTask();
LogTask();
ApplicationTask();
CodecTask();
}
}
+35 -35
View File
@@ -17,9 +17,9 @@ static uint16_t ReaderFieldStartTimestamp = 0;
static uint16_t ReaderFieldRestartTimestamp = 0;
static uint16_t ReaderFieldRestartDelay = 0;
static volatile struct {
bool Started;
bool Ready;
bool ToBeRestarted;
bool Started;
bool Ready;
bool ToBeRestarted;
} ReaderFieldFlags = { false };
uint8_t CodecBuffer[CODEC_BUFFER_SIZE];
@@ -28,28 +28,28 @@ uint16_t ReaderThreshold = 400; // standard value
// the following three functions prevent sending data directly after turning on the reader field
void CodecReaderFieldStart(void) // DO NOT CALL THIS FUNCTION INSIDE APPLICATION!
{
if (!CodecGetReaderField() && !ReaderFieldFlags.ToBeRestarted)
{
CodecSetReaderField(true);
ReaderFieldFlags.Started = true;
ReaderFieldFlags.Ready = false;
ReaderFieldStartTimestamp = SystemGetSysTick();
}
if (!CodecGetReaderField() && !ReaderFieldFlags.ToBeRestarted)
{
CodecSetReaderField(true);
ReaderFieldFlags.Started = true;
ReaderFieldFlags.Ready = false;
ReaderFieldStartTimestamp = SystemGetSysTick();
}
}
void CodecReaderFieldStop(void)
{
CodecSetReaderField(false);
ReaderFieldFlags.Started = false;
ReaderFieldFlags.Ready = false;
CodecSetReaderField(false);
ReaderFieldFlags.Started = false;
ReaderFieldFlags.Ready = false;
}
void CodecReaderFieldRestart(uint16_t delay)
{
ReaderFieldFlags.ToBeRestarted = true;
ReaderFieldRestartTimestamp = SystemGetSysTick();
ReaderFieldRestartDelay = delay;
CodecReaderFieldStop();
ReaderFieldFlags.ToBeRestarted = true;
ReaderFieldRestartTimestamp = SystemGetSysTick();
ReaderFieldRestartDelay = delay;
CodecReaderFieldStop();
}
/*
@@ -58,28 +58,28 @@ void CodecReaderFieldRestart(uint16_t delay)
*/
bool CodecIsReaderFieldReady(void)
{
if (!ReaderFieldFlags.Started)
return true;
if (ReaderFieldFlags.Ready || (ReaderFieldFlags.Started && SYSTICK_DIFF(ReaderFieldStartTimestamp) >= READER_FIELD_MINIMUM_WAITING_TIME))
{
ReaderFieldFlags.Ready = true;
return true;
}
return false;
if (!ReaderFieldFlags.Started)
return true;
if (ReaderFieldFlags.Ready || (ReaderFieldFlags.Started && SYSTICK_DIFF(ReaderFieldStartTimestamp) >= READER_FIELD_MINIMUM_WAITING_TIME))
{
ReaderFieldFlags.Ready = true;
return true;
}
return false;
}
bool CodecIsReaderToBeRestarted(void)
{
if (ReaderFieldFlags.ToBeRestarted)
{
if (SYSTICK_DIFF(ReaderFieldRestartTimestamp) >= ReaderFieldRestartDelay)
{
ReaderFieldFlags.ToBeRestarted = false;
CodecReaderFieldStart();
}
return true;
}
return false;
if (ReaderFieldFlags.ToBeRestarted)
{
if (SYSTICK_DIFF(ReaderFieldRestartTimestamp) >= ReaderFieldRestartDelay)
{
ReaderFieldFlags.ToBeRestarted = false;
CodecReaderFieldStart();
}
return true;
}
return false;
}
void CodecThresholdSet(uint16_t th)
+36 -36
View File
@@ -98,8 +98,8 @@ extern uint16_t Reader_FWT;
#define FWI2FWT(x) ((uint32_t)(256 * 16 * ((uint32_t)1 << (x))) / (CODEC_CARRIER_FREQ / 1000) + 1)
typedef enum {
CODEC_SUBCARRIERMOD_OFF,
CODEC_SUBCARRIERMOD_OOK
CODEC_SUBCARRIERMOD_OFF,
CODEC_SUBCARRIERMOD_OOK
} SubcarrierModType;
extern uint8_t CodecBuffer[CODEC_BUFFER_SIZE];
@@ -127,7 +127,7 @@ INLINE void CodecInitCommon(void)
#else
#error Option not supported
#endif
CODEC_CARRIER_IN_PORT.DIRCLR = CODEC_CARRIER_IN_MASK;
CODEC_CARRIER_IN_PORT.DIRCLR = CODEC_CARRIER_IN_MASK;
EVSYS.CH6MUX = CODEC_CARRIER_IN_EVMUX;
/* Configure two DEMOD pins for input.
@@ -143,8 +143,8 @@ INLINE void CodecInitCommon(void)
EVSYS.CH0MUX = CODEC_DEMOD_IN_EVMUX0;
EVSYS.CH1MUX = CODEC_DEMOD_IN_EVMUX1;
/* Configure loadmod pin configuration and use a virtual port configuration
* for single instruction cycle access */
/* Configure loadmod pin configuration and use a virtual port configuration
* for single instruction cycle access */
CODEC_LOADMOD_PORT.DIRSET = CODEC_LOADMOD_MASK;
CODEC_LOADMOD_PORT.OUTCLR = CODEC_LOADMOD_MASK;
PORTCFG.VPCTRLA &= ~PORTCFG_VP0MAP_gm;
@@ -188,21 +188,21 @@ INLINE void CodecInitCommon(void)
INLINE void CodecSetSubcarrier(SubcarrierModType ModType, uint16_t Divider)
{
if (ModType == CODEC_SUBCARRIERMOD_OFF) {
CODEC_SUBCARRIER_TIMER.CTRLA = TC_CLKSEL_OFF_gc;
CODEC_SUBCARRIER_TIMER.CTRLB = 0;
} else if (ModType == CODEC_SUBCARRIERMOD_OOK) {
/* Configure subcarrier generation with 50% DC output using OOK */
CODEC_SUBCARRIER_TIMER.CNT = 0;
CODEC_SUBCARRIER_TIMER.PER = Divider - 1;
CODEC_SUBCARRIER_TIMER.CODEC_SUBCARRIER_CC_OOK = Divider/2;
CODEC_SUBCARRIER_TIMER.CTRLB = CODEC_SUBCARRIER_CCEN_OOK | TC_WGMODE_SINGLESLOPE_gc;
}
if (ModType == CODEC_SUBCARRIERMOD_OFF) {
CODEC_SUBCARRIER_TIMER.CTRLA = TC_CLKSEL_OFF_gc;
CODEC_SUBCARRIER_TIMER.CTRLB = 0;
} else if (ModType == CODEC_SUBCARRIERMOD_OOK) {
/* Configure subcarrier generation with 50% DC output using OOK */
CODEC_SUBCARRIER_TIMER.CNT = 0;
CODEC_SUBCARRIER_TIMER.PER = Divider - 1;
CODEC_SUBCARRIER_TIMER.CODEC_SUBCARRIER_CC_OOK = Divider/2;
CODEC_SUBCARRIER_TIMER.CTRLB = CODEC_SUBCARRIER_CCEN_OOK | TC_WGMODE_SINGLESLOPE_gc;
}
}
INLINE void CodecStartSubcarrier(void)
{
CODEC_SUBCARRIER_TIMER.CTRLA = CODEC_TIMER_CARRIER_CLKSEL;
CODEC_SUBCARRIER_TIMER.CTRLA = CODEC_TIMER_CARRIER_CLKSEL;
}
INLINE void CodecSetDemodPower(bool bOnOff)
@@ -215,36 +215,36 @@ INLINE void CodecSetDemodPower(bool bOnOff)
}
INLINE bool CodecGetLoadmodState(void) {
if (ACA.STATUS & AC_AC0STATE_bm) {
return true;
} else {
return false;
}
if (ACA.STATUS & AC_AC0STATE_bm) {
return true;
} else {
return false;
}
}
INLINE void CodecSetLoadmodState(bool bOnOff) {
if (bOnOff) {
VPORT0.OUT |= CODEC_LOADMOD_MASK;
} else {
VPORT0.OUT &= ~CODEC_LOADMOD_MASK;
}
if (bOnOff) {
VPORT0.OUT |= CODEC_LOADMOD_MASK;
} else {
VPORT0.OUT &= ~CODEC_LOADMOD_MASK;
}
}
INLINE void CodecSetReaderField(bool bOnOff) { // this is the function for turning on/off the reader field dumbly; before using this function, please consider to use CodecReaderField{Start,Stop}
if (bOnOff) {
/* Start timer for field generation and unmask outputs */
CODEC_READER_TIMER.CTRLA = TC_CLKSEL_DIV1_gc;
AWEXC.OUTOVEN = CODEC_READER_MASK;
} else {
/* Disable outputs of AWEX and stop field generation */
AWEXC.OUTOVEN = 0x00;
CODEC_READER_TIMER.CTRLA = TC_CLKSEL_OFF_gc;
}
if (bOnOff) {
/* Start timer for field generation and unmask outputs */
CODEC_READER_TIMER.CTRLA = TC_CLKSEL_DIV1_gc;
AWEXC.OUTOVEN = CODEC_READER_MASK;
} else {
/* Disable outputs of AWEX and stop field generation */
AWEXC.OUTOVEN = 0x00;
CODEC_READER_TIMER.CTRLA = TC_CLKSEL_OFF_gc;
}
}
INLINE bool CodecGetReaderField(void) {
return (CODEC_READER_TIMER.CTRLA == TC_CLKSEL_DIV1_gc) && (AWEXC.OUTOVEN == CODEC_READER_MASK);
return (CODEC_READER_TIMER.CTRLA == TC_CLKSEL_DIV1_gc) && (AWEXC.OUTOVEN == CODEC_READER_MASK);
}
void CodecReaderFieldStart(void);
+72 -72
View File
@@ -24,11 +24,11 @@ static volatile struct {
} Flags = { 0 };
typedef enum {
/* Demod */
DEMOD_DATA_BIT,
DEMOD_PARITY_BIT,
/* Demod */
DEMOD_DATA_BIT,
DEMOD_PARITY_BIT,
/* Loadmod */
/* Loadmod */
LOADMOD_FDT,
LOADMOD_START,
LOADMOD_START_BIT0,
@@ -120,7 +120,7 @@ ISR(CODEC_TIMER_SAMPLING_CCA_VECT) {
SampleRegister = (SampleRegister << 1) | (!SamplePin ? 0x01 : 0x00);
if (SampleIdxRegister) {
SampleIdxRegister = 0;
SampleIdxRegister = 0;
/* Analyze the sampling register after 2 samples. */
if ((SampleRegister & 0x07) == 0x07) {
/* No carrier modulation for 3 sample points. EOC! */
@@ -201,7 +201,7 @@ ISR(CODEC_TIMER_SAMPLING_CCA_VECT) {
*ParityBufferPtr++ = Bit;
StateRegister = DEMOD_DATA_BIT;
} else {
/* Should never Happen (TM) */
/* Should never Happen (TM) */
}
} else {
/* 00 sequence. -> No valid data yet. This also occurs if we just started
@@ -210,7 +210,7 @@ ISR(CODEC_TIMER_SAMPLING_CCA_VECT) {
}
} else {
/* On odd sample position just sample. */
SampleIdxRegister = ~SampleIdxRegister;
SampleIdxRegister = ~SampleIdxRegister;
}
/* Make sure the sampling timer gets automatically aligned to the
@@ -224,23 +224,23 @@ ISR(CODEC_TIMER_LOADMOD_OVF_VECT) {
/* Bit rate timer. Output a half bit on the output. */
static void* JumpTable[] = {
[LOADMOD_FDT] = &&LOADMOD_FDT_LABEL,
[LOADMOD_START] = &&LOADMOD_START_LABEL,
[LOADMOD_START_BIT0] = &&LOADMOD_START_BIT0_LABEL,
[LOADMOD_START_BIT1] = &&LOADMOD_START_BIT1_LABEL,
[LOADMOD_DATA0] = &&LOADMOD_DATA0_LABEL,
[LOADMOD_DATA1] = &&LOADMOD_DATA1_LABEL,
[LOADMOD_PARITY0] = &&LOADMOD_PARITY0_LABEL,
[LOADMOD_PARITY1] = &&LOADMOD_PARITY1_LABEL,
[LOADMOD_STOP_BIT0] = &&LOADMOD_STOP_BIT0_LABEL,
[LOADMOD_STOP_BIT1] = &&LOADMOD_STOP_BIT1_LABEL,
[LOADMOD_FINISHED] = &&LOADMOD_FINISHED_LABEL
[LOADMOD_FDT] = &&LOADMOD_FDT_LABEL,
[LOADMOD_START] = &&LOADMOD_START_LABEL,
[LOADMOD_START_BIT0] = &&LOADMOD_START_BIT0_LABEL,
[LOADMOD_START_BIT1] = &&LOADMOD_START_BIT1_LABEL,
[LOADMOD_DATA0] = &&LOADMOD_DATA0_LABEL,
[LOADMOD_DATA1] = &&LOADMOD_DATA1_LABEL,
[LOADMOD_PARITY0] = &&LOADMOD_PARITY0_LABEL,
[LOADMOD_PARITY1] = &&LOADMOD_PARITY1_LABEL,
[LOADMOD_STOP_BIT0] = &&LOADMOD_STOP_BIT0_LABEL,
[LOADMOD_STOP_BIT1] = &&LOADMOD_STOP_BIT1_LABEL,
[LOADMOD_FINISHED] = &&LOADMOD_FINISHED_LABEL
};
if ( (StateRegister >= LOADMOD_FDT) && (StateRegister <= LOADMOD_FINISHED) ) {
goto *JumpTable[StateRegister];
goto *JumpTable[StateRegister];
} else {
return;
return;
}
LOADMOD_FDT_LABEL:
@@ -253,17 +253,17 @@ ISR(CODEC_TIMER_LOADMOD_OVF_VECT) {
/* Fallthrough to first bit */
LOADMOD_START_BIT0_LABEL:
/* Start subcarrier generation, output startbit and align to bitrate. */
CodecSetLoadmodState(true);
CodecStartSubcarrier();
/* Start subcarrier generation, output startbit and align to bitrate. */
CodecSetLoadmodState(true);
CodecStartSubcarrier();
CODEC_TIMER_LOADMOD.PER = ISO14443A_BIT_RATE_CYCLES / 2 - 1;
CODEC_TIMER_LOADMOD.PER = ISO14443A_BIT_RATE_CYCLES / 2 - 1;
StateRegister = LOADMOD_START_BIT1;
return;
LOADMOD_START_BIT1_LABEL:
CodecSetLoadmodState(false);
CodecSetLoadmodState(false);
StateRegister = LOADMOD_DATA0;
ParityRegister = ~0;
BitSent = 0;
@@ -272,12 +272,12 @@ ISR(CODEC_TIMER_LOADMOD_OVF_VECT) {
DataRegister = *CodecBufferPtr;
return;
LOADMOD_DATA0_LABEL:
LOADMOD_DATA0_LABEL:
if (DataRegister & 1) {
CodecSetLoadmodState(true);
ParityRegister = ~ParityRegister;
CodecSetLoadmodState(true);
ParityRegister = ~ParityRegister;
} else {
CodecSetLoadmodState(false);
CodecSetLoadmodState(false);
}
StateRegister = LOADMOD_DATA1;
@@ -285,9 +285,9 @@ ISR(CODEC_TIMER_LOADMOD_OVF_VECT) {
LOADMOD_DATA1_LABEL:
if (DataRegister & 1) {
CodecSetLoadmodState(false);
CodecSetLoadmodState(false);
} else {
CodecSetLoadmodState(true);
CodecSetLoadmodState(true);
}
DataRegister = DataRegister >> 1;
@@ -300,47 +300,47 @@ ISR(CODEC_TIMER_LOADMOD_OVF_VECT) {
/* End of transmission without byte boundary. Don't send parity. */
StateRegister = LOADMOD_STOP_BIT0;
} else {
/* Next bit is data */
StateRegister = LOADMOD_DATA0;
/* Next bit is data */
StateRegister = LOADMOD_DATA0;
}
return;
LOADMOD_PARITY0_LABEL:
if (ParityBufferPtr != NULL) {
if (*ParityBufferPtr) {
CodecSetLoadmodState(true);
} else {
CodecSetLoadmodState(false);
}
} else {
if (ParityRegister) {
CodecSetLoadmodState(true);
} else {
CodecSetLoadmodState(false);
}
}
if (ParityBufferPtr != NULL) {
if (*ParityBufferPtr) {
CodecSetLoadmodState(true);
} else {
CodecSetLoadmodState(false);
}
} else {
if (ParityRegister) {
CodecSetLoadmodState(true);
} else {
CodecSetLoadmodState(false);
}
}
StateRegister = LOADMOD_PARITY1;
return;
LOADMOD_PARITY1_LABEL:
if (ParityBufferPtr != NULL) {
if (*ParityBufferPtr) {
CodecSetLoadmodState(false);
} else {
CodecSetLoadmodState(true);
}
if (ParityBufferPtr != NULL) {
if (*ParityBufferPtr) {
CodecSetLoadmodState(false);
} else {
CodecSetLoadmodState(true);
}
ParityBufferPtr++;
} else {
if (ParityRegister) {
CodecSetLoadmodState(false);
} else {
CodecSetLoadmodState(true);
}
} else {
if (ParityRegister) {
CodecSetLoadmodState(false);
} else {
CodecSetLoadmodState(true);
}
ParityRegister = ~0;
}
ParityRegister = ~0;
}
if (BitSent == BitCount) {
/* No data left */
@@ -354,12 +354,12 @@ ISR(CODEC_TIMER_LOADMOD_OVF_VECT) {
return;
LOADMOD_STOP_BIT0_LABEL:
CodecSetLoadmodState(false);
CodecSetLoadmodState(false);
StateRegister = LOADMOD_STOP_BIT1;
return;
LOADMOD_STOP_BIT1_LABEL:
CodecSetLoadmodState(false);
CodecSetLoadmodState(false);
StateRegister = LOADMOD_FINISHED;
return;
@@ -378,25 +378,25 @@ ISR(CODEC_TIMER_LOADMOD_OVF_VECT) {
void ISO14443ACodecInit(void) {
/* Initialize some global vars and start looking out for reader commands */
Flags.DemodFinished = 0;
Flags.LoadmodFinished = 0;
Flags.DemodFinished = 0;
Flags.LoadmodFinished = 0;
CodecInitCommon();
CodecInitCommon();
StartDemod();
}
void ISO14443ACodecDeInit(void)
{
/* Gracefully shutdown codec */
CODEC_DEMOD_IN_PORT.INT0MASK = 0;
/* Gracefully shutdown codec */
CODEC_DEMOD_IN_PORT.INT0MASK = 0;
Flags.DemodFinished = 0;
Flags.LoadmodFinished = 0;
Flags.DemodFinished = 0;
Flags.LoadmodFinished = 0;
CODEC_TIMER_SAMPLING.CTRLA = TC_CLKSEL_OFF_gc;
CODEC_TIMER_SAMPLING.CTRLD = TC_EVACT_OFF_gc;
CODEC_TIMER_SAMPLING.CTRLD = TC_EVACT_OFF_gc;
CODEC_TIMER_SAMPLING.INTCTRLB = TC_CCAINTLVL_OFF_gc;
CODEC_TIMER_SAMPLING.INTFLAGS = TC0_CCAIF_bm;
CODEC_TIMER_SAMPLING.INTFLAGS = TC0_CCAIF_bm;
CODEC_TIMER_LOADMOD.CTRLA = TC_CLKSEL_OFF_gc;
@@ -431,7 +431,7 @@ void ISO14443ACodecTask(void) {
ParityBufferPtr = &CodecBuffer[ISO14443A_BUFFER_PARITY_OFFSET];
} else {
/* We have to generate the parity bits ourself */
ParityBufferPtr = 0;
ParityBufferPtr = 0;
}
}
File diff suppressed because it is too large Load Diff
+16 -16
View File
@@ -8,22 +8,22 @@ const uint8_t PROGMEM BitReverseByteTable[256] = {
};
const uint8_t PROGMEM OddParityByteTable[256] = {
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
};
uint16_t BufferToHexString(char* HexOut, uint16_t MaxChars, const void* Buffer, uint16_t ByteCount)
+12 -12
View File
@@ -38,31 +38,31 @@ uint16_t HexStringToBuffer(void* Buffer, uint16_t MaxBytes, const char* HexIn);
INLINE uint8_t BitReverseByte(uint8_t Byte)
{
extern const uint8_t PROGMEM BitReverseByteTable[];
extern const uint8_t PROGMEM BitReverseByteTable[];
return pgm_read_byte(&BitReverseByteTable[Byte]);
return pgm_read_byte(&BitReverseByteTable[Byte]);
}
INLINE uint8_t OddParityBit(uint8_t Byte)
{
extern const uint8_t PROGMEM OddParityByteTable[];
extern const uint8_t PROGMEM OddParityByteTable[];
return pgm_read_byte(&OddParityByteTable[Byte]);
return pgm_read_byte(&OddParityByteTable[Byte]);
}
INLINE uint8_t StringLength(const char* Str, uint8_t MaxLen)
{
uint8_t StrLen = 0;
uint8_t StrLen = 0;
while(MaxLen > 0) {
if (*Str++ == '\0')
break;
while(MaxLen > 0) {
if (*Str++ == '\0')
break;
MaxLen--;
StrLen++;
}
MaxLen--;
StrLen++;
}
return StrLen;
return StrLen;
}
#endif /* COMMON_H_ */
+56 -56
View File
@@ -13,27 +13,27 @@
/* Map IDs to text */
static const MapEntryType PROGMEM ConfigurationMap[] = {
{ .Id = CONFIG_NONE, .Text = "NONE" },
{ .Id = CONFIG_NONE, .Text = "NONE" },
#ifdef CONFIG_MF_ULTRALIGHT_SUPPORT
{ .Id = CONFIG_MF_ULTRALIGHT, .Text = "MF_ULTRALIGHT" },
{ .Id = CONFIG_MF_ULTRALIGHT, .Text = "MF_ULTRALIGHT" },
#endif
#ifdef CONFIG_MF_CLASSIC_1K_SUPPORT
{ .Id = CONFIG_MF_CLASSIC_1K, .Text = "MF_CLASSIC_1K" },
{ .Id = CONFIG_MF_CLASSIC_1K, .Text = "MF_CLASSIC_1K" },
#endif
#ifdef CONFIG_MF_CLASSIC_1K_7B_SUPPORT
{ .Id = CONFIG_MF_CLASSIC_1K_7B, .Text = "MF_CLASSIC_1K_7B" },
{ .Id = CONFIG_MF_CLASSIC_1K_7B, .Text = "MF_CLASSIC_1K_7B" },
#endif
#ifdef CONFIG_MF_CLASSIC_4K_SUPPORT
{ .Id = CONFIG_MF_CLASSIC_4K, .Text = "MF_CLASSIC_4K" },
{ .Id = CONFIG_MF_CLASSIC_4K, .Text = "MF_CLASSIC_4K" },
#endif
#ifdef CONFIG_MF_CLASSIC_4K_7B_SUPPORT
{ .Id = CONFIG_MF_CLASSIC_4K_7B, .Text = "MF_CLASSIC_4K_7B" },
{ .Id = CONFIG_MF_CLASSIC_4K_7B, .Text = "MF_CLASSIC_4K_7B" },
#endif
#ifdef CONFIG_ISO14443A_SNIFF_SUPPORT
{ .Id = CONFIG_ISO14443A_SNIFF, .Text = "ISO14443A_SNIFF" },
{ .Id = CONFIG_ISO14443A_SNIFF, .Text = "ISO14443A_SNIFF" },
#endif
#ifdef CONFIG_ISO14443A_READER_SUPPORT
{ .Id = CONFIG_ISO14443A_READER, .Text = "ISO14443A_READER" },
{ .Id = CONFIG_ISO14443A_READER, .Text = "ISO14443A_READER" },
#endif
};
@@ -105,19 +105,19 @@ static const PROGMEM ConfigurationType ConfigurationTable[] = {
#endif
#ifdef CONFIG_MF_CLASSIC_1K_7B_SUPPORT
[CONFIG_MF_CLASSIC_1K_7B] = {
.CodecInitFunc = ISO14443ACodecInit,
.CodecDeInitFunc = ISO14443ACodecDeInit,
.CodecTaskFunc = ISO14443ACodecTask,
.ApplicationInitFunc = MifareClassicAppInit1K7B,
.ApplicationResetFunc = MifareClassicAppReset,
.ApplicationTaskFunc = MifareClassicAppTask,
.ApplicationTickFunc = ApplicationTickDummy,
.ApplicationProcessFunc = MifareClassicAppProcess,
.ApplicationGetUidFunc = MifareClassicGetUid,
.ApplicationSetUidFunc = MifareClassicSetUid,
.UidSize = ISO14443A_UID_SIZE_DOUBLE,
.MemorySize = MIFARE_CLASSIC_1K_MEM_SIZE,
.ReadOnly = false
.CodecInitFunc = ISO14443ACodecInit,
.CodecDeInitFunc = ISO14443ACodecDeInit,
.CodecTaskFunc = ISO14443ACodecTask,
.ApplicationInitFunc = MifareClassicAppInit1K7B,
.ApplicationResetFunc = MifareClassicAppReset,
.ApplicationTaskFunc = MifareClassicAppTask,
.ApplicationTickFunc = ApplicationTickDummy,
.ApplicationProcessFunc = MifareClassicAppProcess,
.ApplicationGetUidFunc = MifareClassicGetUid,
.ApplicationSetUidFunc = MifareClassicSetUid,
.UidSize = ISO14443A_UID_SIZE_DOUBLE,
.MemorySize = MIFARE_CLASSIC_1K_MEM_SIZE,
.ReadOnly = false
},
#endif
#ifdef CONFIG_MF_CLASSIC_4K_SUPPORT
@@ -156,36 +156,36 @@ static const PROGMEM ConfigurationType ConfigurationTable[] = {
#endif
#ifdef CONFIG_ISO14443A_SNIFF_SUPPORT
[CONFIG_ISO14443A_SNIFF] = {
.CodecInitFunc = ISO14443ACodecInit,
.CodecDeInitFunc = ISO14443ACodecDeInit,
.CodecTaskFunc = ISO14443ACodecTask,
.ApplicationInitFunc = ApplicationInitDummy,
.ApplicationResetFunc = ApplicationResetDummy,
.ApplicationTaskFunc = ApplicationTaskDummy,
.ApplicationTickFunc = ApplicationTickDummy,
.ApplicationProcessFunc = ApplicationProcessDummy,
.ApplicationGetUidFunc = ApplicationGetUidDummy,
.ApplicationSetUidFunc = ApplicationSetUidDummy,
.UidSize = 0,
.MemorySize = 0,
.ReadOnly = true
.CodecInitFunc = ISO14443ACodecInit,
.CodecDeInitFunc = ISO14443ACodecDeInit,
.CodecTaskFunc = ISO14443ACodecTask,
.ApplicationInitFunc = ApplicationInitDummy,
.ApplicationResetFunc = ApplicationResetDummy,
.ApplicationTaskFunc = ApplicationTaskDummy,
.ApplicationTickFunc = ApplicationTickDummy,
.ApplicationProcessFunc = ApplicationProcessDummy,
.ApplicationGetUidFunc = ApplicationGetUidDummy,
.ApplicationSetUidFunc = ApplicationSetUidDummy,
.UidSize = 0,
.MemorySize = 0,
.ReadOnly = true
},
#endif
#ifdef CONFIG_ISO14443A_READER_SUPPORT
[CONFIG_ISO14443A_READER] = {
.CodecInitFunc = Reader14443ACodecInit,
.CodecDeInitFunc = Reader14443ACodecDeInit,
.CodecTaskFunc = Reader14443ACodecTask,
.ApplicationInitFunc = Reader14443AAppInit,
.ApplicationResetFunc = Reader14443AAppReset,
.ApplicationTaskFunc = Reader14443AAppTask,
.ApplicationTickFunc = Reader14443AAppTick,
.ApplicationProcessFunc = Reader14443AAppProcess,
.ApplicationGetUidFunc = ApplicationGetUidDummy,
.ApplicationSetUidFunc = ApplicationSetUidDummy,
.UidSize = 0,
.MemorySize = 0,
.ReadOnly = false
.CodecInitFunc = Reader14443ACodecInit,
.CodecDeInitFunc = Reader14443ACodecDeInit,
.CodecTaskFunc = Reader14443ACodecTask,
.ApplicationInitFunc = Reader14443AAppInit,
.ApplicationResetFunc = Reader14443AAppReset,
.ApplicationTaskFunc = Reader14443AAppTask,
.ApplicationTickFunc = Reader14443AAppTick,
.ApplicationProcessFunc = Reader14443AAppProcess,
.ApplicationGetUidFunc = ApplicationGetUidDummy,
.ApplicationSetUidFunc = ApplicationSetUidDummy,
.UidSize = 0,
.MemorySize = 0,
.ReadOnly = false
},
#endif
};
@@ -202,11 +202,11 @@ void ConfigurationInit(void)
void ConfigurationSetById( ConfigurationEnum Configuration )
{
CodecDeInit();
CodecDeInit();
CommandLinePendingTaskBreak(); // break possibly pending task
CommandLinePendingTaskBreak(); // break possibly pending task
GlobalSettings.ActiveSettingPtr->Configuration = Configuration;
GlobalSettings.ActiveSettingPtr->Configuration = Configuration;
/* Copy struct from PROGMEM to RAM */
memcpy_P(&ActiveConfiguration,
@@ -218,7 +218,7 @@ void ConfigurationSetById( ConfigurationEnum Configuration )
void ConfigurationGetByName(char* Configuration, uint16_t BufferSize)
{
MapIdToText(ConfigurationMap, ARRAY_COUNT(ConfigurationMap), GlobalSettings.ActiveSettingPtr->Configuration, Configuration, BufferSize);
MapIdToText(ConfigurationMap, ARRAY_COUNT(ConfigurationMap), GlobalSettings.ActiveSettingPtr->Configuration, Configuration, BufferSize);
}
bool ConfigurationSetByName(const char* Configuration)
@@ -226,16 +226,16 @@ bool ConfigurationSetByName(const char* Configuration)
MapIdType Id;
if (MapTextToId(ConfigurationMap, ARRAY_COUNT(ConfigurationMap), Configuration, &Id)) {
ConfigurationSetById(Id);
LogEntry(LOG_INFO_CONFIG_SET, Configuration, StringLength(Configuration, CONFIGURATION_NAME_LENGTH_MAX-1));
return true;
ConfigurationSetById(Id);
LogEntry(LOG_INFO_CONFIG_SET, Configuration, StringLength(Configuration, CONFIGURATION_NAME_LENGTH_MAX-1));
return true;
} else {
return false;
return false;
}
}
void ConfigurationGetList(char* List, uint16_t BufferSize)
{
MapToString(ConfigurationMap, ARRAY_COUNT(ConfigurationMap), List, BufferSize);
MapToString(ConfigurationMap, ARRAY_COUNT(ConfigurationMap), List, BufferSize);
}

Some files were not shown because too many files have changed in this diff Show More