3636* INCLUDES
3737******************************************************************************
3838*/
39-
39+ # include " rfal_config.h "
4040#include " SPI.h"
41+ #include " Wire.h"
4142#include " rfal_rf.h"
4243#include " st_errno.h"
4344#include " nfc_utils.h"
4647#include " st25r3911_interrupt.h"
4748#include " rfal_rfst25r3911_analogConfig.h"
4849#include " rfal_rfst25r3911_iso15693_2.h"
50+ #include < functional>
4951
5052/*
51- ******************************************************************************
52- * ENABLE SWITCHES
53- ******************************************************************************
54- */
53+ ******************************************************************************
54+ * ENABLE SWITCH
55+ ******************************************************************************
56+ */
57+
58+ #ifndef RFAL_FEATURE_LISTEN_MODE
59+ #error " RFAL: Module configuration missing. Please enable/disable support for Listen Mode: RFAL_FEATURE_LISTEN_MODE "
60+ #endif
61+
62+ #ifndef RFAL_FEATURE_WAKEUP_MODE
63+ #error " RFAL: Module configuration missing. Please enable/disable support for Wake-Up Mode: RFAL_FEATURE_WAKEUP_MODE "
64+ #endif
5565
5666/*
5767******************************************************************************
@@ -70,22 +80,46 @@ typedef struct {
7080} rfalTxRx;
7181
7282
83+ /* ! Struct that holds certain WU mode information to be retrieved by rfalWakeUpModeGetInfo */
84+ typedef struct {
85+ bool irqWut; /* !< Wake-Up Timer IRQ received (cleared upon read) */
86+
87+ struct {
88+ uint8_t lastMeas; /* !< Value of the latest measurement */
89+ bool irqWu; /* !< Amplitude WU IRQ received (cleared upon read) */
90+ } indAmp; /* !< Inductive Amplitude */
91+ struct {
92+ uint8_t lastMeas; /* !< Value of the latest measurement */
93+ bool irqWu; /* !< Phase WU IRQ received (cleared upon read) */
94+ } indPha; /* !< Inductive Phase */
95+ struct {
96+ uint8_t lastMeas; /* !< Value of the latest measurement */
97+ bool irqWu; /* !< Capacitive WU IRQ received (cleared upon read) */
98+ } cap; /* !< Capacitance */
99+ } rfalWakeUpData;
100+
101+
73102/* ! Struct that holds all context for the Listen Mode */
74103typedef struct {
75104 rfalLmState state; /* !< Current Listen Mode state */
105+ uint32_t mdMask; /* !< Listen Mode mask used */
106+ uint32_t mdReg; /* !< Listen Mode register value used */
107+ uint32_t mdIrqs; /* !< Listen Mode IRQs used */
76108 rfalBitRate brDetected; /* !< Last bit rate detected */
77109
78110 uint8_t *rxBuf; /* !< Location to store incoming data in Listen Mode */
79111 uint16_t rxBufLen; /* !< Length of rxBuf */
80112 uint16_t *rxLen; /* !< Pointer to write the data length placed into rxBuf */
81113 bool dataFlag; /* !< Listen Mode current Data Flag */
114+ bool iniFlag; /* !< Listen Mode initialized Flag (FeliCa slots) */
82115} rfalLm;
83116
84117
85118/* ! Struct that holds all context for the Wake-Up Mode */
86119typedef struct {
87120 rfalWumState state; /* !< Current Wake-Up Mode state */
88121 rfalWakeUpConfig cfg; /* !< Current Wake-Up Mode context */
122+ rfalWakeUpData info; /* !< Current Wake-Up Mode info */
89123} rfalWum;
90124
91125
@@ -94,6 +128,7 @@ typedef struct {
94128 uint32_t GT; /* !< GT in 1/fc */
95129 uint32_t FDTListen; /* !< FDTListen in 1/fc */
96130 uint32_t FDTPoll; /* !< FDTPoll in 1/fc */
131+ uint8_t nTRFW; /* !< n*TRFW (last two bits) used during RF CA */
97132} rfalTimings;
98133
99134
@@ -102,13 +137,16 @@ typedef struct {
102137 uint32_t GT; /* !< RFAL's GT timer */
103138 uint32_t FWT; /* !< FWT/RWT timer for Active P2P*/
104139 uint32_t RXE; /* !< Timer between RXS and RXE */
140+ uint32_t PPON2; /* !< Timer between TXE - PPON2 */
141+ uint32_t txRx; /* !< Transceive sanity timer */
105142} rfalTimers;
106143
107144
108145/* ! Struct that holds the RFAL's callbacks */
109146typedef struct {
110147 rfalPreTxRxCallback preTxRx; /* !< RFAL's Pre TxRx callback */
111148 rfalPostTxRxCallback postTxRx; /* !< RFAL's Post TxRx callback */
149+ rfalSyncTxRxCallback syncTxRx; /* !< RFAL's Sync TxRx callback */
112150} rfalCallbacks;
113151
114152
@@ -128,10 +166,28 @@ typedef struct {
128166 rfalEHandling eHandling; /* !< RFAL's error handling config/mode */
129167} rfalConfigs;
130168
169+ /* ! Struct that holds NFC-A data - Used only inside rfalISO14443ATransceiveAnticollisionFrame() */
170+ typedef struct {
171+ uint8_t collByte; /* !< NFC-A Anticollision collision byte */
172+ uint8_t *buf; /* !< NFC-A Anticollision frame buffer */
173+ uint8_t *bytesToSend;/* !< NFC-A Anticollision NFCID|UID byte context */
174+ uint8_t *bitsToSend; /* !< NFC-A Anticollision NFCID|UID bit context */
175+ uint16_t *rxLength; /* !< NFC-A Anticollision received length */
176+ } rfalNfcaWorkingData;
177+
131178
132- /* ! Struct that holds NFC-F data - Used only inside rfalFelicaPoll() (static to avoid adding it into stack) */
179+ /* ! Struct that holds NFC-F data - Used only inside rfalFelicaPoll() */
133180typedef struct {
134- rfalFeliCaPollRes pollResponses[RFAL_FELICA_POLL_MAX_SLOTS]; /* FeliCa Poll response container for 16 slots */
181+ uint16_t actLen; /* Received length */
182+ rfalFeliCaPollRes *pollResList; /* Location of NFC-F device list */
183+ uint8_t pollResListSize; /* Size of NFC-F device list */
184+ uint8_t devDetected; /* Number of devices detected */
185+ uint8_t colDetected; /* Number of collisions detected */
186+ uint8_t *devicesDetected; /* Location to place number of devices */
187+ uint8_t *collisionsDetected; /* Location to place number of collisions */
188+ rfalEHandling curHandling; /* RFAL's error handling */
189+ rfalFeliCaPollRes pollResponses[RFAL_FELICA_POLL_MAX_SLOTS]; /* FeliCa Poll response buffer (16 slots) */
190+ rfalFeliCaPollSlots slots;
135191} rfalNfcfWorkingData;
136192
137193
@@ -171,11 +227,25 @@ typedef struct {
171227 rfalTimers tmr; /* !< RFAL's Software timers */
172228 rfalCallbacks callbacks; /* !< RFAL's callbacks */
173229
230+ #if RFAL_FEATURE_LISTEN_MODE
231+ rfalLm Lm; /* !< RFAL's listen mode management */
232+ #endif /* RFAL_FEATURE_LISTEN_MODE */
233+
234+ #if RFAL_FEATURE_WAKEUP_MODE
174235 rfalWum wum; /* !< RFAL's Wake-up mode management */
236+ #endif /* RFAL_FEATURE_WAKEUP_MODE */
237+
238+ #if RFAL_FEATURE_NFCA
239+ rfalNfcaWorkingData nfcaData; /* !< RFAL's working data when supporting NFC-A */
240+ #endif /* RFAL_FEATURE_NFCA */
175241
242+ #if RFAL_FEATURE_NFCF
176243 rfalNfcfWorkingData nfcfData; /* !< RFAL's working data when supporting NFC-F */
244+ #endif /* RFAL_FEATURE_NFCF */
177245
246+ #if RFAL_FEATURE_NFCV
178247 rfalNfcvWorkingData nfcvData; /* !< RFAL's working data when supporting NFC-V */
248+ #endif /* RFAL_FEATURE_NFCV */
179249
180250} rfal;
181251
@@ -362,6 +432,7 @@ typedef void (*ST25R3911BIrqHandler)(void);
362432#define rfalAdjACBR ( b ) (((uint16_t )(b) >= (uint16_t )RFAL_BR_52p97) ? (uint16_t )(b) : ((uint16_t )(b)+1U )) /* !< Adjusts ST25R391x Bit rate to Analog Configuration */
363433#define rfalConvBR2ACBR ( b ) (((rfalAdjACBR((b)))<<RFAL_ANALOG_CONFIG_BITRATE_SHIFT) & RFAL_ANALOG_CONFIG_BITRATE_MASK) /* !< Converts ST25R391x Bit rate to Analog Configuration bit rate id */
364434
435+ #define rfalRunBlocking ( e, fn ) do { (e)=(fn); rfalWorker (); }while ( (e) == ERR_BUSY )
365436
366437
367438class RfalRfST25R3911BClass : public RfalRfClass {
@@ -380,14 +451,15 @@ class RfalRfST25R3911BClass : public RfalRfClass {
380451 void rfalSetUpperLayerCallback (rfalUpperLayerCallback pFunc);
381452 void rfalSetPreTxRxCallback (rfalPreTxRxCallback pFunc);
382453 void rfalSetPostTxRxCallback (rfalPostTxRxCallback pFunc);
454+ void rfalSetLmEonCallback (rfalLmEonCallback pFunc);
383455 ReturnCode rfalDeinitialize (void );
384456 ReturnCode rfalSetMode (rfalMode mode, rfalBitRate txBR, rfalBitRate rxBR);
385457 rfalMode rfalGetMode (void );
386458 ReturnCode rfalSetBitRate (rfalBitRate txBR, rfalBitRate rxBR);
387459 ReturnCode rfalGetBitRate (rfalBitRate *txBR, rfalBitRate *rxBR);
388460 void rfalSetErrorHandling (rfalEHandling eHandling);
389461 rfalEHandling rfalGetErrorHandling (void );
390- void rfalSetObsvMode (uint8_t txMode, uint8_t rxMode);
462+ void rfalSetObsvMode (uint32_t txMode, uint32_t rxMode);
391463 void rfalGetObsvMode (uint8_t *txMode, uint8_t *rxMode);
392464 void rfalDisableObsvMode (void );
393465 void rfalSetFDTPoll (uint32_t FDTPoll);
@@ -406,12 +478,23 @@ class RfalRfST25R3911BClass : public RfalRfClass {
406478 bool rfalIsTransceiveInRx (void );
407479 ReturnCode rfalGetTransceiveRSSI (uint16_t *rssi);
408480 void rfalWorker (void );
481+ void rfalSetSyncTxRxCallback (rfalSyncTxRxCallback pFunc);
482+ bool rfalIsTransceiveSubcDetected (void );
483+ ReturnCode rfalISO14443AStartTransceiveAnticollisionFrame (uint8_t *buf, uint8_t *bytesToSend, uint8_t *bitsToSend, uint16_t *rxLength, uint32_t fwt);
484+ ReturnCode rfalISO14443AGetTransceiveAnticollisionFrameStatus (void );
485+
486+ #if RFAL_FEATURE_LISTEN_MODE
487+ ReturnCode rfalRunListenModeWorker (void );
488+ #endif /* RFAL_FEATURE_LISTEN_MODE */
489+
409490 ReturnCode rfalISO14443ATransceiveShortFrame (rfal14443AShortFrameCmd txCmd, uint8_t *rxBuf, uint8_t rxBufLen, uint16_t *rxRcvdLen, uint32_t fwt);
410491 ReturnCode rfalISO14443ATransceiveAnticollisionFrame (uint8_t *buf, uint8_t *bytesToSend, uint8_t *bitsToSend, uint16_t *rxLength, uint32_t fwt);
411492 ReturnCode rfalFeliCaPoll (rfalFeliCaPollSlots slots, uint16_t sysCode, uint8_t reqCode, rfalFeliCaPollRes *pollResList, uint8_t pollResListSize, uint8_t *devicesDetected, uint8_t *collisionsDetected);
493+ ReturnCode rfalStartFeliCaPoll (rfalFeliCaPollSlots slots, uint16_t sysCode, uint8_t reqCode, rfalFeliCaPollRes *pollResList, uint8_t pollResListSize, uint8_t *devicesDetected, uint8_t *collisionsDetected);
494+ ReturnCode rfalGetFeliCaPollStatus (void );
412495 ReturnCode rfalISO15693TransceiveAnticollisionFrame (uint8_t *txBuf, uint8_t txBufLen, uint8_t *rxBuf, uint8_t rxBufLen, uint16_t *actLen);
413496 ReturnCode rfalISO15693TransceiveEOFAnticollision (uint8_t *rxBuf, uint8_t rxBufLen, uint16_t *actLen);
414- ReturnCode rfalISO15693TransceiveEOF (uint8_t *rxBuf, uint8_t rxBufLen, uint16_t *actLen);
497+ ReturnCode rfalISO15693TransceiveEOF (uint8_t *rxBuf, uint16_t rxBufLen, uint16_t *actLen);
415498 ReturnCode rfalTransceiveBlockingTx (uint8_t *txBuf, uint16_t txBufLen, uint8_t *rxBuf, uint16_t rxBufLen, uint16_t *actLen, uint32_t flags, uint32_t fwt);
416499 ReturnCode rfalTransceiveBlockingRx (void );
417500 ReturnCode rfalTransceiveBlockingTxRx (uint8_t *txBuf, uint16_t txBufLen, uint8_t *rxBuf, uint16_t rxBufLen, uint16_t *actLen, uint32_t flags, uint32_t fwt);
@@ -421,7 +504,9 @@ class RfalRfST25R3911BClass : public RfalRfClass {
421504 ReturnCode rfalListenStop (void );
422505 rfalLmState rfalListenGetState (bool *dataFlag, rfalBitRate *lastBR);
423506 ReturnCode rfalListenSetState (rfalLmState newSt);
507+ bool rfalWakeUpModeIsEnabled (void );
424508 ReturnCode rfalWakeUpModeStart (const rfalWakeUpConfig *config);
509+ ReturnCode rfalWakeUpModeGetInfo (bool force, rfalWakeUpInfo *info);
425510 bool rfalWakeUpModeHasWoke (void );
426511 ReturnCode rfalWakeUpModeStop (void );
427512
@@ -1802,7 +1887,9 @@ class RfalRfST25R3911BClass : public RfalRfClass {
18021887 void rfalCleanupTransceive (void );
18031888 void rfalErrorHandling (void );
18041889 ReturnCode rfalRunTransceiveWorker (void );
1890+ #if RFAL_FEATURE_WAKEUP_MODE
18051891 void rfalRunWakeUpModeWorker (void );
1892+ #endif /* RFAL_FEATURE_WAKEUP_MODE */
18061893
18071894 void rfalFIFOStatusUpdate (void );
18081895 void rfalFIFOStatusClear (void );
@@ -1836,7 +1923,6 @@ class RfalRfST25R3911BClass : public RfalRfClass {
18361923 volatile t_st25r3911Interrupt st25r3911interrupt; /* !< Instance of ST25R3911 interrupt */
18371924 uint32_t timerStopwatchTick;
18381925 volatile bool isr_pending;
1839- volatile bool bus_busy;
18401926 ST25R3911BIrqHandler irq_handler;
18411927};
18421928
0 commit comments