NFC ZigBee 3.0 Modules and Libraries: app_ntag_icode.h File Reference

NFC ZigBee 3.0

NFC ZigBee 3.0 Modules and Libraries
NFC Commissioning using ZigBee Installation Codes
app_ntag_icode.h File Reference

ZigBee 3.0 NTAG network commissioning. More...

#include <jendefs.h> #include <ntag.h>

Go to the source code of this file.

Macros

#define APP_NTAG_ADDRESS   0xFFU
 
#define APP_NTAG_I2C_LOCATION   FALSE
 
#define APP_NTAG_I2C_FREQUENCY_HZ   100000
 
#define APP_NTAG_TICK_MS   5
 

Functions

PUBLIC bool_t APP_bNtagPdmLoad (void)
 Reads NTAG PDM records during initialisation and initiates out of band commissioning if an appropriate record is found. More...
 
PUBLIC void APP_vNtagStart (uint8 u8ApplicationEndpoint)
 Starts processing data in the NTAG. More...
 
PUBLIC void APP_vNtagStop (void)
 Stops processing data in the NTAG. More...
 
PUBLIC void APP_cbNtagTimer (void *pvParams)
 ZTIMER callback function. More...
 
PUBLIC void APP_cbNtagEvent (teNtagEvent eNtagEvent, uint32 u32Address, uint32 u32Length, uint8 *pu8Data)
 NTAG event callback function. More...
 

Detailed Description

ZigBee 3.0 NTAG network commissioning.

app_ntag_icode.h contains application APIs that can be used to commission ZigBee 3.0 devices into a network using NFC to write network information into an NTAG. The code in app_ntag_icode.h makes use of libNTAG to interact with the NTAG.

The changes required to add these features to ZigBee 3.0 applications are described in the sections on the individual functions and have already been made to the ZigBee 3.0 Application Notes. The changes in the source code are all wrapped by #ifdef APP_NTAG_ICODE and the NTAG functionality can be disabled in the makefiles or on the command line by setting APP_NTAG_ICODE = 0.

Macro Definition Documentation

◆ APP_NTAG_ADDRESS

#define APP_NTAG_ADDRESS   0xFFU

I2C Address (0xFF for automatic detection)

◆ APP_NTAG_I2C_LOCATION

#define APP_NTAG_I2C_LOCATION   FALSE

TRUE uses alternate I2C lines (DIO16, 17) instead of (DIO14, 15)

◆ APP_NTAG_I2C_FREQUENCY_HZ

#define APP_NTAG_I2C_FREQUENCY_HZ   100000

I2C frequency value in Hz

◆ APP_NTAG_TICK_MS

#define APP_NTAG_TICK_MS   5

Interval of tick timer in ms

Function Documentation

◆ APP_bNtagPdmLoad()

PUBLIC bool_t APP_bNtagPdmLoad ( void  )

Reads NTAG PDM records during initialisation and initiates out of band commissioning if an appropriate record is found.

This function should be called during initialisation of the application before starting the stack.

Two PDM records are used by app_ntag.h, with the IDs defined in PDM_IDs.h which are used in the following ways:

  • PDM_ID_APP_NFC_ICODE stores the installation code and its CRC in a tsNfcNwkInstallCode structure. If the record cannot be read from the PDM a random installation code is generated and its CRC calculated which is then stored in the PDM.
  • PDM_ID_APP_NFC_NWK_NCI stores network commissioning data written to the NTAG during NFC commissioning in a tsNfcNwkNci structure. If a valid NFC_NWK_NCI_CMD_JOIN_WITH_CODE command is present in the record read from the PDM the BDB_u8OutOfBandCommissionStartDevice() is called to commission the device into the network. An APP_vOobcSetRunning() function, which must be present in the application, is called to allow the application to take appropriate actions to move to a running state.
Return values
TRUEBDB_u8OutOfBandCommissionStartDevice() has been called and the stack should not be started by the application calling BDB_vStart().
FALSEBDB_u8OutOfBandCommissionStartDevice() has not been called and the stack may be started by the application calling BDB_vStart() if appropriate.

◆ APP_vNtagStart()

PUBLIC void APP_vNtagStart ( uint8  u8ApplicationEndpoint)

Starts processing data in the NTAG.

This function should be called in the following circumstances:

  • At initialisation: this allows device information to be written into an NTAG at startup and also to read and react to data that may have been written into the NTAG whilst the device was powered down.
  • On field detect (FD) input change: The FD input from the NTAG is raised and lowered when the NTAG is placed into or removed from an NFC reader's RF field. When placed into a field this status is simply tracked, when removed from a field the process of reading and writing data to the NTAG will be initiated. It is assumed that the standard button handling code (in app_buttons.h) is used to generate interupts and app_ntag_icode.c uses the APP_BUTTONS_NFC_FD define to determine the FD input DIO line.
  • On successfully joining a network: to write the current network data into the NTAG.

APP_vNtagStart() starts the u8TimerNtag ZTIMER which must be present in the application (usually in app_main.c). This timer is configured to prevent the device sleeping whilst the ZTIMER is running. At the end of NTAG processing the ZTIMER is allowed to expire and thus allow sleeping again.

Parameters
u8ApplicationEndpointMain application endpoint, used to determine the Device ID to be written into the NTAG

◆ APP_vNtagStop()

PUBLIC void APP_vNtagStop ( void  )

Stops processing data in the NTAG.

This function may be called to abort NTAG processing. The current ZigBee 3.0 application notes do not make use of this function.

◆ APP_cbNtagTimer()

PUBLIC void APP_cbNtagTimer ( void *  pvParams)

ZTIMER callback function.

This is the callback function used by the NTAG ZTIMER and drives the processing of NTAG data.

Warning
This function should not be called directly by the application code.

If a valid command has been read from the NTAG during processing it will initiate the following actions when NTAG processing is complete:

  • NFC_NWK_NCI_CMD_FACTORY_RESET: The function ZPS_eAplZdoLeaveNetwork() is called so the device cleanly leaves the network. If the ZPS_eAplZdoLeaveNetwork() function fails then APP_vFactoryResetRecords() is called, and must be present in the application, to reset the device to its factory state then the device is restarted.
  • NFC_NWK_NCI_CMD_JOIN_WITH_CODE: The commissioning data read from the NTAG is written into the PDM PDM_ID_APP_NFC_NWK_NCI record and the device is restarted. The data then gets picked up and applied by the call to APP_bNtagPdmLoad() during initialisation.

◆ APP_cbNtagEvent()

PUBLIC void APP_cbNtagEvent ( teNtagEvent  eNtagEvent,
uint32  u32Address,
uint32  u32Length,
uint8 *  pu8Data 
)

NTAG event callback function.

This is the callback function used by the NTAG library to pass events and data from the NTAG to the application.

This function initiates the reading of the NTAG data when the NTAG is removed from an NCI field indicated by the E_NTAG_EVENT_ABSENT event.

Warning
This function should not be called directly by the application code.
Parameters
eNtagEventEvent raised
u32AddressByte address in NTAG of data relating to the event
u32LengthLength of data relating to the event
pu8DataPointer to data relating to the event
Generated by   doxygen 1.8.13