RA Flexible Software Package Documentation  Release v5.9.0

 
NFC Reader Driver on PTX (rm_nfc_reader_ptx)

Functions

fsp_err_t RM_NFC_READER_PTX_Open (nfc_reader_ptx_instance_ctrl_t *const p_ctrl, nfc_reader_ptx_cfg_t const *const p_cfg)
 
fsp_err_t RM_NFC_READER_PTX_DiscoveryStart (nfc_reader_ptx_instance_ctrl_t *const p_ctrl)
 
fsp_err_t RM_NFC_READER_PTX_StatusGet (nfc_reader_ptx_instance_ctrl_t *const p_ctrl, ptxIoTRd_StatusType_t status_type, uint8_t *const p_status)
 
fsp_err_t RM_NFC_READER_PTX_CardRegistryGet (nfc_reader_ptx_instance_ctrl_t *const p_ctrl, ptxIoTRd_CardRegistry_t **pp_card_registry)
 
fsp_err_t RM_NFC_READER_PTX_CardActivate (nfc_reader_ptx_instance_ctrl_t *const p_ctrl, ptxIoTRd_CardParams_t *const p_card_params, ptxIoTRd_CardProtocol_t protocol)
 
fsp_err_t RM_NFC_READER_PTX_DataExchange (nfc_reader_ptx_instance_ctrl_t *const p_ctrl, nfc_reader_ptx_data_info_t *const p_data_info)
 
fsp_err_t RM_NFC_READER_PTX_ReaderDeactivation (nfc_reader_ptx_instance_ctrl_t *const p_ctrl, nfc_reader_ptx_return_state_t return_state)
 
fsp_err_t RM_NFC_READER_PTX_Close (nfc_reader_ptx_instance_ctrl_t *const p_ctrl)
 

Detailed Description

NFC Reader driver implementation using the PTX NFC module on RA MCUs.

Overview

This middleware module supplies an implementation for the NFC IoT Reader on the PTX module. The NFC functionalities are provided via a modular NFC Soft Controller (NCS) architecture, and this FSP module will include the NSC (aka NFC SDK). Functionality is provided in a split-stack architecture, where time-critical operations are running on the on-chip MCU, and the rest of the NFC logic is in the host controller to carry out applications such as IoT reader. The driver may also be adapted to further support next-generation PTX devices in future (which have not yet been released).

The NFC Reader module supports the following modules:

Features

The NFC Reader PTX driver supplies these features:

Future support is considered for the following features:

Configuration

Build Time Configurations for rm_nfc_reader_ptx

The following build time configurations are defined in fsp_cfg/rm_nfc_reader_ptx_cfg.h:

ConfigurationOptionsDefaultDescription
Parameter Checking
  • Default (BSP)
  • Enabled
  • Disabled
Default (BSP) If selected code for parameter checking is included in the build.

Configurations for Networking > NFC IoT Reader on PTX (rm_nfc_reader_ptx)

This module can be added to the Stacks tab via New Stack > Networking > NFC IoT Reader on PTX (rm_nfc_reader_ptx).

ConfigurationOptionsDefaultDescription
NFC Poll Type
Type-A
  • Disabled
  • Enabled
Enabled Select to discover NFC Type-A tags
Type-B
  • Disabled
  • Enabled
Enabled Select to discover NFC Type-B tags
Type-V
  • Disabled
  • Enabled
Enabled Select to discover NFC Type-V tags
Type-F
  • Disabled
  • Enabled
Enabled Select to discover NFC Type-F tags
Temperature Sensor
Calibrate Sensor
  • Disabled
  • Enabled
Enabled Enable/Disable on-board temperature sensor calibration. Must be executed once per chip (lifetime), it is not needed after.
Shutdown Temperature (°C)Must be an integer greater than 0 and less than 223100 Set the expected thermal shutdown threshold value (Celsius).
Ambient Temperature (°C)Must be an integer greater than 0 and less than 8525 Set the ambient temperature value at which calibration takes place (Celsius).
NameName must be a valid C symbolg_nfc_reader_ptx0 Module name.
NFC Interrupt PortRefer to the RA Configuration tool for available options.Disabled Specify the interrupt port/pin used by the NFC chip to signal for SPI communications.
NFC Interrupt PinRefer to the RA Configuration tool for available options.module.driver.nfc_reader_ptx.pin_control_pin.PIN_DISABLE Specify the interrupt port/pin used by the NFC chip to signal for SPI communications.
Device LimitMust be an integer greater than 0 and less than 505 Select the max number of tags to discover.
Idle TimeMust be an integer greater than 0 and less than 65535100 Select idle time between polling cycles (ms).

Note: This module provides the basic configurations in the FSP Configurator required to discover, activate, and exchange data with an NFC tag. The user can then copy these configurations to a new structure if they want to connect to a new tag type/make changes to the configurations dynamically.

Interrupt Configuration

Refer to SPI (r_sci_spi). R_SCI_SPI_Open() is called by this module

Clock Configuration

Refer to SPI (r_sci_spi).

Pin Configuration

Refer to SPI (r_sci_spi). R_SCI_SPI_Open() is called by this module

Usage Notes

Limitations

Examples

Basic Example

This is a basic example of minimal use of the NFC IoT Reader module in an application.

void nfc_basic_example (void)
{
fsp_err_t err = FSP_SUCCESS;
ptxIotRdInt_Demo_State_t demo_state = IoTRd_DemoState_WaitForActivation;
err = RM_NFC_READER_PTX_Open(&g_rm_nfc_reader_ptx_instance, &g_nfc_reader_ptx_cfg);
assert(FSP_SUCCESS == err);
err = RM_NFC_READER_PTX_DiscoveryStart(&g_rm_nfc_reader_ptx_instance);
assert(FSP_SUCCESS == err);
ptxIoTRd_CardRegistry_t * card_registry = NULL;
err = RM_NFC_READER_PTX_CardRegistryGet(&g_rm_nfc_reader_ptx_instance, &card_registry);
assert(FSP_SUCCESS == err);
/* T2T Protocol Example => READ BLOCK 0 */
const uint8_t PROT_T2T_EXAMPLE[] = {0x30, 0x00};
nfc_send_buf.tx_length = sizeof(PROT_T2T_EXAMPLE);
memcpy(&nfc_tx_buf[0], &PROT_T2T_EXAMPLE[0], nfc_send_buf.tx_length);
while (1)
{
/* Check regularly for critical system errors */
uint8_t system_state = PTX_SYSTEM_STATUS_OK;
err = RM_NFC_READER_PTX_StatusGet(&g_rm_nfc_reader_ptx_instance, StatusType_System, &system_state);
assert(FSP_SUCCESS == err);
if ((PTX_SYSTEM_STATUS_ERR_OVERCURRENT == system_state) || (PTX_SYSTEM_STATUS_ERR_TEMPERATURE == system_state))
{
/* Critical error detected, reset the device and stop */
RM_NFC_READER_PTX_Close(&g_rm_nfc_reader_ptx_instance);
while (1)
{
/* Do nothing */
}
;
}
/* Check optionally if PA current-limiter got activated */
uint8_t last_rf_error = PTX_RF_ERROR_NTF_CODE_NO_ERROR;
err = RM_NFC_READER_PTX_StatusGet(&g_rm_nfc_reader_ptx_instance, StatusType_LastRFError, &last_rf_error);
assert(FSP_SUCCESS == err);
switch (demo_state)
{
case IoTRd_DemoState_WaitForActivation:
{
uint8_t discover_status = RF_DISCOVER_STATUS_NO_CARD;
err = RM_NFC_READER_PTX_StatusGet(&g_rm_nfc_reader_ptx_instance, StatusType_Discover, &discover_status);
assert(FSP_SUCCESS == err);
switch (discover_status)
{
case RF_DISCOVER_STATUS_NO_CARD:
{
/* Sleep */
R_BSP_SoftwareDelay(NFC_READER_NO_CARD_SLEEP_TIME, BSP_DELAY_UNITS_MILLISECONDS);
break;
}
case RF_DISCOVER_STATUS_CARD_ACTIVE:
{
/* Card activated */
/* Get card details to find the protocol/decide what data to send */
err = RM_NFC_READER_PTX_CardRegistryGet(&g_rm_nfc_reader_ptx_instance, &card_registry);
assert(FSP_SUCCESS == err);
demo_state = IoTRd_DemoState_DataExchange;
break;
}
case RF_DISCOVER_STATUS_DISCOVER_RUNNING:
{
/* Multiple Card(s) detected - resolving */
break;
}
case RF_DISCOVER_STATUS_DISCOVER_DONE:
{
/* Multiple Card(s) detected - resolved */
/* Get card details to find the protocol/decide what data to send */
err = RM_NFC_READER_PTX_CardRegistryGet(&g_rm_nfc_reader_ptx_instance, &card_registry);
assert(FSP_SUCCESS == err);
demo_state = IoTRd_DemoState_SelectCard;
break;
}
default:
{
/* Unknown Discover-Status */
break;
}
}
break;
}
case IoTRd_DemoState_SelectCard:
{
/* Case for detection of multiple cards */
err =
RM_NFC_READER_PTX_CardActivate(&g_rm_nfc_reader_ptx_instance, &card_registry->Cards[0], Prot_T2T);
assert(FSP_SUCCESS == err);
demo_state = IoTRd_DemoState_DataExchange;
break;
}
case IoTRd_DemoState_DataExchange:
{
/* Case for data exchange due to detected card */
err = RM_NFC_READER_PTX_DataExchange(&g_rm_nfc_reader_ptx_instance, &nfc_send_buf);
assert(FSP_SUCCESS == err);
demo_state = IoTRd_DemoState_DeactivateReader;
break;
}
case IoTRd_DemoState_DeactivateReader:
{
err =
assert(FSP_SUCCESS == err);
demo_state = IoTRd_DemoState_WaitForActivation;
break;
}
case IoTRd_DemoState_SystemError:
{
/* System error */
RM_NFC_READER_PTX_Close(&g_rm_nfc_reader_ptx_instance);
while (1)
{
/* Do nothing */
}
break;
}
default:
{
break;
}
}
}
}

Data Structures

struct  nfc_reader_ptx_data_info_t
 
struct  nfc_reader_ptx_cfg_t
 
struct  nfc_reader_ptx_instance_ctrl_t
 

Enumerations

enum  nfc_reader_ptx_state_t
 
enum  nfc_reader_ptx_return_state_t
 

Data Structure Documentation

◆ nfc_reader_ptx_data_info_t

struct nfc_reader_ptx_data_info_t

NFC data exchange packet parameters

Data Fields
uint8_t * p_tx_buf Pointer to buffer holding data to send.
uint32_t tx_length Length of data to send.
uint8_t * p_rx_buf Pointer to buffer for data to receive.
uint32_t rx_length Length of data to receive.

◆ nfc_reader_ptx_cfg_t

struct nfc_reader_ptx_cfg_t

NFC Configuration

Data Fields
bool poll_type_a Flag to indicate enabling discovery for Type-A tags.
bool poll_type_b Flag to indicate enabling discovery for Type-B tags.
bool poll_type_f Flag to indicate enabling discovery for Type-F tags.
bool poll_type_v Flag to indicate enabling discovery for Type-V tags.
uint8_t device_limit Defines the maximum number of devices that can be connected at once.
uint32_t idle_time_ms RF-Discovery Loop. Idle time between polling cycles in milliseconds.
uint8_t temp_sensor_calibrate Flag to enable/disable temperature sensor calibration.
uint8_t temp_sensor_shutdown Expected thermal shutdown threshold value.
uint8_t temp_sensor_ambient Ambient temperature at which temperature sensor calibration takes place.
const bsp_io_port_pin_t interrupt_pin Interrupt pin for NFC chip to signal for communication.
ptxIoTRd_t * iot_reader_context Instance of the NFC SDK IoT Reader main structure.
rm_comms_instance_t * p_comms_instance_ctrl Pointer to the NFC module's Comms instance.
ioport_instance_t * p_gpio_context Pointer to the NFC module's GPIO instance.
external_irq_instance_t * p_irq_context Pointer to the NFC module's SPI external interrupt instance.
timer_instance_t * p_timer_context Pointer to the NFC module's sleep timer instance.
timer_instance_t * p_app_timer Pointer to the NFC module's Transparent Data Channel (TDC) timer instance.

◆ nfc_reader_ptx_instance_ctrl_t

struct nfc_reader_ptx_instance_ctrl_t

NFC_READER_PTX private control block. DO NOT MODIFY.

Data Fields
uint32_t open Flag to indicate if NFC has been opened.
nfc_reader_ptx_state_t state_flag Flag to track Idle/discovered/activated.
nfc_reader_ptx_cfg_t const * p_cfg Pointer to p_cfg for NFC.

Enumeration Type Documentation

◆ nfc_reader_ptx_state_t

NFC state machine status

Enumerator
NFC_READER_PTX_IDLE 

Idle state before starting discovery.

NFC_READER_PTX_POLLING 

Polling state for discovering tags.

NFC_READER_PTX_DISCOVERED 

Discovered state for tags that were found.

NFC_READER_PTX_ACTIVATED 

Activated state for activating a discovered tag.

◆ nfc_reader_ptx_return_state_t

NFC de-activation return state

Enumerator
NFC_READER_PTX_RETURN_IDLE 

Rf-Deactivation Type 0 - Turn off RF-field.

NFC_READER_PTX_RETURN_DISCOVER 

Rf-Deactivation Type 1 - Restart RF-Discovery.

NFC_READER_PTX_RETURN_SLEEP 

Rf-Deactivation Type 2 - Put remote device to sleep.

NFC_READER_PTX_RETURN_SLEEP_NON_BLOCKING 

Rf-Deactivation Type 3 - Put remote device to sleep (non-blocking)

NFC_READER_PTX_RETURN_NO_RF_RESET 

Rf-Deactivation Type 4 - Common RF Deactivate but no Field Reset.

NFC_READER_PTX_RETURN_IDLE_PROTOCOL 

Rf-Deactivation Type 5 - Use protocol-specific Deactivation, IDLE afterwards.

NFC_READER_PTX_RETURN_DISCOVER_PROTOCOL 

Rf-Deactivation Type 6 - Use protocol-specific Deactivation, RF-Discovery started afterwards.

Function Documentation

◆ RM_NFC_READER_PTX_Open()

fsp_err_t RM_NFC_READER_PTX_Open ( nfc_reader_ptx_instance_ctrl_t *const  p_ctrl,
nfc_reader_ptx_cfg_t const *const  p_cfg 
)

Initializes the NFC IoT Reader.

Parameters
[in]p_ctrlPointer to NFC IoT Reader control structure.
[in]p_cfgPointer to NFC IoT Reader configuration structure.
Return values
FSP_SUCCESSFunction completed successfully.
FSP_ERR_ASSERTIONAssertion error occurred.
FSP_ERR_INVALID_DATANFC SDK initialization data was incomplete.

◆ RM_NFC_READER_PTX_DiscoveryStart()

fsp_err_t RM_NFC_READER_PTX_DiscoveryStart ( nfc_reader_ptx_instance_ctrl_t *const  p_ctrl)

Initiates discovery of NFC tags.

Parameters
[in]p_ctrlPointer to NFC IoT Reader control structure.
Return values
FSP_SUCCESSFunction completed successfully.
FSP_ERR_ASSERTIONAssertion error occurred.
FSP_ERR_NOT_OPENModule is not opened yet.
FSP_ERR_INVALID_STATENFC module is not in the idle state.
FSP_ERR_INVALID_DATANFC Discovery parameters were invalid or discovery was not started.

◆ RM_NFC_READER_PTX_StatusGet()

fsp_err_t RM_NFC_READER_PTX_StatusGet ( nfc_reader_ptx_instance_ctrl_t *const  p_ctrl,
ptxIoTRd_StatusType_t  status_type,
uint8_t *const  p_status 
)

Gets the status information on the provided status identifier (system, discovery, etc.). Used during polling to confirm a card was discovered.

Parameters
[in]p_ctrlPointer to NFC IoT Reader control structure.
[in]status_typeStatus identifier for target info.
[in]p_statusPointer to location to store NFC chip status flag.
Return values
FSP_SUCCESSFunction completed successfully.
FSP_ERR_ASSERTIONAssertion error occurred.
FSP_ERR_NOT_OPENModule is not opened yet.
FSP_ERR_INVALID_STATENFC module is not in the polling state.
FSP_ERR_INVALID_ARGUMENTInvalid input parameters to NFC Status function.

◆ RM_NFC_READER_PTX_CardRegistryGet()

fsp_err_t RM_NFC_READER_PTX_CardRegistryGet ( nfc_reader_ptx_instance_ctrl_t *const  p_ctrl,
ptxIoTRd_CardRegistry_t **  pp_card_registry 
)

Gets the internal card registry.

Parameters
[in]p_ctrlPointer to NFC IoT Reader control structure.
[in]pp_card_registryPointer to card registry for discovered cards.
Return values
FSP_SUCCESSFunction completed successfully.
FSP_ERR_ASSERTIONAssertion error occurred.
FSP_ERR_INVALID_ARGUMENTInvalid input parameters to NFC registry function.

◆ RM_NFC_READER_PTX_CardActivate()

fsp_err_t RM_NFC_READER_PTX_CardActivate ( nfc_reader_ptx_instance_ctrl_t *const  p_ctrl,
ptxIoTRd_CardParams_t *const  p_card_params,
ptxIoTRd_CardProtocol_t  protocol 
)

Gets the details of the discovered card and connects to it.

Parameters
[in]p_ctrlPointer to NFC IoT Reader control structure.
[in]p_card_paramsParameters of the card to be activated.
[in]protocolThe NFC protocol of the card to be activated.
Return values
FSP_SUCCESSFunction completed successfully.
FSP_ERR_ASSERTIONAssertion error occurred.

◆ RM_NFC_READER_PTX_DataExchange()

fsp_err_t RM_NFC_READER_PTX_DataExchange ( nfc_reader_ptx_instance_ctrl_t *const  p_ctrl,
nfc_reader_ptx_data_info_t *const  p_data_info 
)

Sends and receives data to/from the activated card.

Parameters
[in]p_ctrlPointer to NFC IoT Reader control structure.
[in]p_data_infoPointer to the NFC TX/RX data.
Return values
FSP_SUCCESSFunction completed successfully.
FSP_ERR_ASSERTIONAssertion error occurred.

◆ RM_NFC_READER_PTX_ReaderDeactivation()

fsp_err_t RM_NFC_READER_PTX_ReaderDeactivation ( nfc_reader_ptx_instance_ctrl_t *const  p_ctrl,
nfc_reader_ptx_return_state_t  return_state 
)

Deactivates the activated card to return to the desired state (idle, discovery, etc.).

Parameters
[in]p_ctrlPointer to NFC IoT Reader control structure.
[in]return_stateExpectation for end state of NFC state machine.
Return values
FSP_SUCCESSFunction completed successfully.
FSP_ERR_ASSERTIONAssertion error occurred.

◆ RM_NFC_READER_PTX_Close()

fsp_err_t RM_NFC_READER_PTX_Close ( nfc_reader_ptx_instance_ctrl_t *const  p_ctrl)

Closes the FSP NFC module and resets all variables.

Parameters
[in]p_ctrlPointer to NFC IoT Reader control structure.
Return values
FSP_SUCCESSFunction completed successfully.
FSP_ERR_ASSERTIONAssertion error occurred.
FSP_ERR_NOT_OPENClose being called before the module is Open.