magicrfid 2.0.0.0
magicrfid.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2020 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
28#ifndef MAGICRFID_H
29#define MAGICRFID_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_uart.h"
52
73#define MAGICRFID_OPCODE_VERSION 0x03
74#define MAGICRFID_OPCODE_SET_BAUD_RATE 0x06
75#define MAGICRFID_OPCODE_READ_TAG_ID_SINGLE 0x21
76#define MAGICRFID_OPCODE_READ_TAG_ID_MULTIPLE 0x22
77#define MAGICRFID_OPCODE_WRITE_TAG_ID 0x23
78#define MAGICRFID_OPCODE_WRITE_TAG_DATA 0x24
79#define MAGICRFID_OPCODE_KILL_TAG 0x26
80#define MAGICRFID_OPCODE_READ_TAG_DATA 0x28
81#define MAGICRFID_OPCODE_CLEAR_TAG_ID_BUFFER 0x2A
82#define MAGICRFID_OPCODE_MULTI_PROTOCOL_TAG_OP 0x2F
83#define MAGICRFID_OPCODE_GET_READ_TX_POWER 0x62
84#define MAGICRFID_OPCODE_GET_WRITE_TX_POWER 0x64
85#define MAGICRFID_OPCODE_GET_POWER_MODE 0x68
86#define MAGICRFID_OPCODE_GET_READER_OPTIONAL_PARAMS 0x6A
87#define MAGICRFID_OPCODE_GET_PROTOCOL_PARAM 0x6B
88#define MAGICRFID_OPCODE_SET_ANTENNA_PORT 0x91
89#define MAGICRFID_OPCODE_SET_TAG_PROTOCOL 0x93
90#define MAGICRFID_OPCODE_SET_READ_TX_POWER 0x92
91#define MAGICRFID_OPCODE_SET_WRITE_TX_POWER 0x94
92#define MAGICRFID_OPCODE_SET_REGION 0x97
93#define MAGICRFID_OPCODE_SET_READER_OPTIONAL_PARAMS 0x9A
94#define MAGICRFID_OPCODE_SET_PROTOCOL_PARAM 0x9B
95
100#define MAGICRFID_REGION_INDIA 0x04
101#define MAGICRFID_REGION_JAPAN 0x05
102#define MAGICRFID_REGION_CHINA 0x06
103#define MAGICRFID_REGION_EUROPE 0x08
104#define MAGICRFID_REGION_KOREA 0x09
105#define MAGICRFID_REGION_AUSTRALIA 0x0B
106#define MAGICRFID_REGION_NEWZEALAND 0x0C
107#define MAGICRFID_REGION_NORTHAMERICA 0x0D
108#define MAGICRFID_REGION_OPEN 0xFF
109
114#define MAGICRFID_TAG_PROTOCOL_NONE 0x00
115#define MAGICRFID_TAG_PROTOCOL_ISO180006B 0x03
116#define MAGICRFID_TAG_PROTOCOL_GEN2 0x05
117#define MAGICRFID_TAG_PROTOCOL_ISO180006B_UCODE 0x06
118#define MAGICRFID_TAG_PROTOCOL_IPX64 0x07
119#define MAGICRFID_TAG_PROTOCOL_IPX256 0x08
120#define MAGICRFID_TAG_PROTOCOL_ATA 0x1D
121
126#define MAGICRFID_NORMAL_DELAY_TIME 50
127#define MAGICRFID_LONG_DELAY_TIME 100
128#define MAGICRFID_TIMEOUT_MS 3000
129
134#define MAGICRFID_HEADER 0xFF
135#define MAGICRFID_COMMAND_MAX_DATA_LEN 250
136#define MAGICRFID_RESPONSE_MAX_DATA_LEN 248
137#define MAGICRFID_EPC_MAX_DATA_LEN 16
138
144#define MAGICRFID_TX_DRV_BUFFER_SIZE 255
145#define MAGICRFID_RX_DRV_BUFFER_SIZE 255
146
147 // magicrfid_cmd
148
163#define MAGICRFID_MAP_MIKROBUS( cfg, mikrobus ) \
164 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
165 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
166 cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS )
167
168 // magicrfid_map
169 // magicrfid
170
175typedef struct
176{
177 // Output pins
178 digital_out_t en;
180 // Modules
181 uart_t uart;
183 // Buffers
184 uint8_t uart_rx_buffer[ MAGICRFID_RX_DRV_BUFFER_SIZE ];
185 uint8_t uart_tx_buffer[ MAGICRFID_TX_DRV_BUFFER_SIZE ];
188
193typedef struct
194{
195 // Communication gpio pins
196 pin_name_t rx_pin;
197 pin_name_t tx_pin;
199 // Additional gpio pins
200 pin_name_t en;
202 // Static variable
203 uint32_t baud_rate;
205 uart_data_bits_t data_bit;
206 uart_parity_t parity_bit;
207 uart_stop_bits_t stop_bit;
210
215typedef struct
216{
217 uint8_t data_len;
218 uint8_t opcode;
220
222
227typedef struct
228{
229 uint8_t data_len;
230 uint8_t opcode;
231 uint16_t status;
233
235
240typedef struct
241{
242 uint8_t data_len;
243 uint16_t epc_pc;
244 uint8_t data_buf[ MAGICRFID_EPC_MAX_DATA_LEN ];
245 uint16_t epc_crc;
246
248
259
276
291
303
315err_t magicrfid_generic_write ( magicrfid_t *ctx, uint8_t *data_buf, uint16_t len );
316
328err_t magicrfid_generic_read ( magicrfid_t *ctx, uint8_t *data_buf, uint16_t max_len );
329
338
349
362
371
380
391
401void magicrfid_set_tag_protocol ( magicrfid_t *ctx, uint8_t protocol );
402
412void magicrfid_set_region ( magicrfid_t *ctx, uint8_t region );
413
423
433void magicrfid_set_baud_rate ( magicrfid_t *ctx, uint32_t baud_rate );
434
444void magicrfid_set_read_power ( magicrfid_t *ctx, uint16_t power_setting );
445
455void magicrfid_set_write_power ( magicrfid_t *ctx, uint16_t power_setting );
456
465void magicrfid_set_reader_config ( magicrfid_t *ctx, uint8_t option1, uint8_t option2 );
466
476
485
486#ifdef __cplusplus
487}
488#endif
489#endif // MAGICRFID_H
490
491 // magicrfid
492
493// ------------------------------------------------------------------------ END
#define MAGICRFID_RESPONSE_MAX_DATA_LEN
Definition magicrfid.h:136
#define MAGICRFID_EPC_MAX_DATA_LEN
Definition magicrfid.h:137
#define MAGICRFID_TX_DRV_BUFFER_SIZE
Magic RFID driver buffer size.
Definition magicrfid.h:144
#define MAGICRFID_RX_DRV_BUFFER_SIZE
Definition magicrfid.h:145
#define MAGICRFID_COMMAND_MAX_DATA_LEN
Definition magicrfid.h:135
void magicrfid_send_command(magicrfid_t *ctx, magicrfid_command_t cmd)
Magic RFID send command function.
void magicrfid_set_antenna_port(magicrfid_t *ctx)
Magic RFID turn on antenna port function.
uint32_t magicrfid_parse_tag_freq(magicrfid_response_t rsp)
Parse Tag Freq value.
void magicrfid_set_read_power(magicrfid_t *ctx, uint16_t power_setting)
Magic RFID set read function power.
void magicrfid_default_cfg(magicrfid_t *ctx)
Magic RFID default configuration function.
void magicrfid_parse_tag_epc(magicrfid_response_t rsp, magicrfid_epc_t *epc)
Parse Tag EPC bytes.
void magicrfid_set_baud_rate(magicrfid_t *ctx, uint32_t baud_rate)
Magic RFID set baud rate function.
void magicrfid_set_region(magicrfid_t *ctx, uint8_t region)
Magic RFID set region function.
err_t magicrfid_generic_write(magicrfid_t *ctx, uint8_t *data_buf, uint16_t len)
Magic RFID data writing function.
err_t magicrfid_get_response(magicrfid_t *ctx, magicrfid_response_t *rsp)
Magic RFID get response function.
void magicrfid_start_reading(magicrfid_t *ctx)
Magic RFID enable reading function.
err_t magicrfid_init(magicrfid_t *ctx, magicrfid_cfg_t *cfg)
Magic RFID initialization function.
void magicrfid_set_tag_protocol(magicrfid_t *ctx, uint8_t protocol)
Magic RFID set protocol function.
void magicrfid_clear_buffers(magicrfid_t *ctx)
Magic RFID clear buffers function.
int8_t magicrfid_parse_tag_rssi(magicrfid_response_t rsp)
Parse Tag RSSI value.
void magicrfid_set_reader_config(magicrfid_t *ctx, uint8_t option1, uint8_t option2)
Magic RFID set reader configuration function.
void magicrfid_set_write_power(magicrfid_t *ctx, uint16_t power_setting)
Magic RFID set write function power.
err_t magicrfid_generic_read(magicrfid_t *ctx, uint8_t *data_buf, uint16_t max_len)
Magic RFID data reading function.
void magicrfid_cfg_setup(magicrfid_cfg_t *cfg)
Magic RFID configuration object setup function.
void magicrfid_device_reset(magicrfid_t *ctx)
Magic RFID device reset function.
magicrfid_return_value_t
Magic RFID Click return value data.
Definition magicrfid.h:254
@ MAGICRFID_OK
Definition magicrfid.h:255
@ MAGICRFID_ERROR
Definition magicrfid.h:256
Magic RFID Click configuration object.
Definition magicrfid.h:194
uint32_t baud_rate
Definition magicrfid.h:203
bool uart_blocking
Definition magicrfid.h:204
uart_data_bits_t data_bit
Definition magicrfid.h:205
pin_name_t tx_pin
Definition magicrfid.h:197
pin_name_t rx_pin
Definition magicrfid.h:196
uart_stop_bits_t stop_bit
Definition magicrfid.h:207
pin_name_t en
Definition magicrfid.h:200
uart_parity_t parity_bit
Definition magicrfid.h:206
Magic RFID Click command object.
Definition magicrfid.h:216
uint8_t opcode
Definition magicrfid.h:218
uint8_t data_len
Definition magicrfid.h:217
Magic RFID Click EPC data object.
Definition magicrfid.h:241
uint16_t epc_pc
Definition magicrfid.h:243
uint8_t data_len
Definition magicrfid.h:242
uint16_t epc_crc
Definition magicrfid.h:245
Magic RFID Click response object.
Definition magicrfid.h:228
uint16_t status
Definition magicrfid.h:231
uint8_t opcode
Definition magicrfid.h:230
uint8_t data_len
Definition magicrfid.h:229
Magic RFID Click context object.
Definition magicrfid.h:176
uart_t uart
Definition magicrfid.h:181
digital_out_t en
Definition magicrfid.h:178