Skip to content

Commit

Permalink
Merge pull request #8 from harp-tech/fw-reset_tag_register
Browse files Browse the repository at this point in the history
Clear tag's register when tag leaves the detection zone
  • Loading branch information
filcarv authored Jan 26, 2024
2 parents 4edba0f + 038e2f4 commit d5b56f7
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Firmware/RfidReader/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void hwbp_app_initialize(void)
uint8_t hwH = 1;
uint8_t hwL = 2;
uint8_t fwH = 1;
uint8_t fwL = 2;
uint8_t fwL = 3;
uint8_t ass = 0;

/* Start core */
Expand Down Expand Up @@ -202,6 +202,7 @@ void uart0_rcv_byte_callback(uint8_t byte_received)
timer_type1_enable(&TCD1, TIMER_PRESCALER_DIV1024, 156, INT_LEVEL_LOW); // ~5 ms
// 1 byte = 833 us @ 9600bps
id_event_was_sent = false;
app_regs.REG_TAG_ID_ARRIVED = 0;
}

rxbuff_uart0[rxbuff_pointer++] = byte_received;
Expand Down
44 changes: 41 additions & 3 deletions Firmware/RfidReader/interrupts.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ ISR(PORTA_INT0_vect, ISR_NAKED)
/************************************************************************/
extern bool id_event_was_sent;

uint64_t id_leaved_temp = 0;

ISR(PORTC_INT0_vect, ISR_NAKED)
{
if (read_TAG_IN_RANGE)
Expand All @@ -51,8 +53,12 @@ ISR(PORTC_INT0_vect, ISR_NAKED)
{
id_event_was_sent = false;

app_regs.REG_TAG_ID_LEAVED = app_regs.REG_TAG_ID_ARRIVED;
core_func_send_event(ADD_REG_TAG_ID_LEAVED, true);
if (app_regs.REG_TAG_ID_ARRIVED != 0) // if != 0 it's a 125 KHz antenna
{
app_regs.REG_TAG_ID_LEAVED = app_regs.REG_TAG_ID_ARRIVED;
core_func_send_event(ADD_REG_TAG_ID_LEAVED, true);
app_regs.REG_TAG_ID_ARRIVED = 0;
}
}
}

Expand Down Expand Up @@ -154,6 +160,8 @@ ISR(TCD1_OVF_vect, ISR_NAKED)
*(((uint8_t*)(&app_regs.REG_TAG_ID_ARRIVED))+5) = 0;
*(((uint8_t*)(&app_regs.REG_TAG_ID_ARRIVED))+6) = 0;
*(((uint8_t*)(&app_regs.REG_TAG_ID_ARRIVED))+7) = 0;

id_leaved_temp = app_regs.REG_TAG_ID_ARRIVED;
}
else
{
Expand All @@ -178,6 +186,12 @@ ISR(TCD1_OVF_vect, ISR_NAKED)
if (app_regs.REG_TAG_ID_ARRIVED == app_regs.REG_TAG_MATCH0)
{
core_func_send_event(ADD_REG_TAG_ID_ARRIVED, (rxbuff_pointer == 16) ? false : true);
if (rxbuff_pointer == 30)
{
app_regs.REG_TAG_ID_ARRIVED = 0;
app_regs.REG_TAG_ID_LEAVED = 0;
}

id_event_was_sent = true;
notify(app_regs.REG_NOTIFICATIONS);
out0_timeout_ms = app_regs.REG_TAG_MATCH0_OUT0_PERIOD;
Expand All @@ -186,6 +200,12 @@ ISR(TCD1_OVF_vect, ISR_NAKED)
if (app_regs.REG_TAG_ID_ARRIVED == app_regs.REG_TAG_MATCH1)
{
core_func_send_event(ADD_REG_TAG_ID_ARRIVED, (rxbuff_pointer == 16) ? false : true);
if (rxbuff_pointer == 30)
{
app_regs.REG_TAG_ID_ARRIVED = 0;
app_regs.REG_TAG_ID_LEAVED = 0;
}

id_event_was_sent = true;
notify(app_regs.REG_NOTIFICATIONS);
out0_timeout_ms = app_regs.REG_TAG_MATCH1_OUT0_PERIOD;
Expand All @@ -194,6 +214,12 @@ ISR(TCD1_OVF_vect, ISR_NAKED)
if (app_regs.REG_TAG_ID_ARRIVED == app_regs.REG_TAG_MATCH2)
{
core_func_send_event(ADD_REG_TAG_ID_ARRIVED, (rxbuff_pointer == 16) ? false : true);
if (rxbuff_pointer == 30)
{
app_regs.REG_TAG_ID_ARRIVED = 0;
app_regs.REG_TAG_ID_LEAVED = 0;
}

id_event_was_sent = true;
notify(app_regs.REG_NOTIFICATIONS);
out0_timeout_ms = app_regs.REG_TAG_MATCH2_OUT0_PERIOD;
Expand All @@ -202,6 +228,12 @@ ISR(TCD1_OVF_vect, ISR_NAKED)
if (app_regs.REG_TAG_ID_ARRIVED == app_regs.REG_TAG_MATCH3)
{
core_func_send_event(ADD_REG_TAG_ID_ARRIVED, (rxbuff_pointer == 16) ? false : true);
if (rxbuff_pointer == 30)
{
app_regs.REG_TAG_ID_ARRIVED = 0;
app_regs.REG_TAG_ID_LEAVED = 0;
}

id_event_was_sent = true;
notify(app_regs.REG_NOTIFICATIONS);
out0_timeout_ms = app_regs.REG_TAG_MATCH3_OUT0_PERIOD;
Expand All @@ -211,10 +243,16 @@ ISR(TCD1_OVF_vect, ISR_NAKED)
else
{
core_func_send_event(ADD_REG_TAG_ID_ARRIVED, (rxbuff_pointer == 16) ? false : true);
if (rxbuff_pointer == 30)
{
app_regs.REG_TAG_ID_ARRIVED = 0;
app_regs.REG_TAG_ID_LEAVED = 0;
}

id_event_was_sent = true;
out0_timeout_ms = app_regs.REG_TAG_ID_ARRIVED_PERIOD;
notify(app_regs.REG_NOTIFICATIONS);
}
}
}

rxbuff_pointer = 0;
Expand Down
2 changes: 1 addition & 1 deletion device.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/harp-tech/reflex-generator/main/schema/device.json
device: RfidReader
whoAmI: 2094
firmwareVersion: "1.2"
firmwareVersion: "1.3"
hardwareTargets: "1.2"
registers:
InboundDetectionId: &detectionevent
Expand Down

0 comments on commit d5b56f7

Please sign in to comment.