Skip to content

Commit

Permalink
Merge pull request #171 from shinhub/workmem_funcbtn_brute_log_clean
Browse files Browse the repository at this point in the history
Workmem, CARD_FUNCTION, BRUTE, LOG and cleanup
  • Loading branch information
iceman1001 authored Nov 21, 2019
2 parents d044bb4 + efc5e19 commit 40af5ba
Show file tree
Hide file tree
Showing 19 changed files with 907 additions and 382 deletions.
34 changes: 24 additions & 10 deletions Firmware/ChameleonMini/AntennaLevel.c
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
#include "AntennaLevel.h"
#include "Application/Application.h"

#define FIELD_MIN_RSSI 500
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_PIN7_gc;
}

uint16_t AntennaLevelGet(void) {
ADCA.CH0.CTRL |= ADC_CH_START_bm;
while( !(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;

return (uint16_t) (((uint32_t) Result * ANTENNA_LEVEL_NUMERATOR) / ANTENNA_LEVEL_DENOMINATOR);
}

void AntennaLevelTick(void)
{
void AntennaLevelTick(void) {
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);
// UidSize != 0 implies that we are emulating right now
if( (rssi < ANTENNA_FIELD_MIN_RSSI) && (ActiveConfiguration.UidSize != 0) ) {
ApplicationReset(); // reset the application just like a real card gets reset when there is no field
}
}
46 changes: 14 additions & 32 deletions Firmware/ChameleonMini/AntennaLevel.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,40 +58,22 @@

#include "Common.h"

#define ANTENNA_LEVEL_R1 10E3
#define ANTENNA_LEVEL_R2 220E0
#define ANTENNA_LEVEL_VREF 1.0
#define ANTENNA_LEVEL_RES 4096
#define ANTENNA_LEVEL_OFFSET 190 /* LSB */
#define ANTENNA_LEVEL_R1 10E3
#define ANTENNA_LEVEL_R2 220E0
#define ANTENNA_LEVEL_VREF 1.0
#define ANTENNA_LEVEL_RES 4096
#define ANTENNA_LEVEL_OFFSET 190 /* LSB */

#define ANTENNA_LEVEL_MILLIVOLT 1E3
#define ANTENNA_LEVEL_FACTOR (ANTENNA_LEVEL_VREF * (ANTENNA_LEVEL_R1 + ANTENNA_LEVEL_R2) / (ANTENNA_LEVEL_RES * ANTENNA_LEVEL_R2) )
#define ANTENNA_LEVEL_SCALE ((uint32_t) 1<<16)
#define ANTENNA_LEVEL_NUMERATOR ((uint32_t) (ANTENNA_LEVEL_MILLIVOLT * ANTENNA_LEVEL_FACTOR * ANTENNA_LEVEL_SCALE + .5))
#define ANTENNA_LEVEL_DENOMINATOR (ANTENNA_LEVEL_SCALE)
#define ANTENNA_LEVEL_MILLIVOLT 1E3
#define ANTENNA_LEVEL_FACTOR (ANTENNA_LEVEL_VREF * (ANTENNA_LEVEL_R1 + ANTENNA_LEVEL_R2) / (ANTENNA_LEVEL_RES * ANTENNA_LEVEL_R2) )
#define ANTENNA_LEVEL_SCALE ((uint32_t) 1<<16)
#define ANTENNA_LEVEL_NUMERATOR ((uint32_t) (ANTENNA_LEVEL_MILLIVOLT * ANTENNA_LEVEL_FACTOR * ANTENNA_LEVEL_SCALE + .5))
#define ANTENNA_LEVEL_DENOMINATOR (ANTENNA_LEVEL_SCALE)

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_PIN7_gc;
#define ANTENNA_FIELD_MIN_RSSI 500

}

static inline uint16_t AntennaLevelGet(void)
{
ADCA.CH0.CTRL |= ADC_CH_START_bm;
while( !(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;

return (uint16_t) (((uint32_t) Result * ANTENNA_LEVEL_NUMERATOR) / ANTENNA_LEVEL_DENOMINATOR);
}
void AntennaLevelInit(void);
uint16_t AntennaLevelGet(void);
void AntennaLevelTick(void);

#endif /* ANTENNALEVEL_H_ */
4 changes: 4 additions & 0 deletions Firmware/ChameleonMini/Application/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ INLINE void ApplicationTick(void) {
ActiveConfiguration.ApplicationTickFunc();
}

INLINE void ApplicationButton(void) {
ActiveConfiguration.ApplicationButtonFunc();
}

INLINE uint16_t ApplicationProcess(uint8_t* ByteBuffer, uint16_t ByteCount) {
return ActiveConfiguration.ApplicationProcessFunc(ByteBuffer, ByteCount);
}
Expand Down
Loading

0 comments on commit 40af5ba

Please sign in to comment.