1 // ********************************************************************* 2 // Custom DPA Handler code template * 3 // ********************************************************************* 4 // Copyright (c) MICRORISC s.r.o. 5 // 6 // File: $RCSfile: CustomDpaHandler-Template.c,v $ 7 // Version: $Revision: 1.80 $ 8 // Date: $Date: 2025/10/20 17:01:10 $ 9 // 10 // Revision history: 11 // 2025/05/30 Release for DPA 4.33 12 // 2023/03/07 Release for DPA 4.30 13 // 2022/10/05 Release for DPA 4.18 14 // 2022/02/24 Release for DPA 4.17 15 // 2021/08/20 Release for DPA 4.16 16 // 2020/09/03 Release for DPA 4.15 17 // 2020/02/27 Release for DPA 4.13 18 // 2019/01/10 Release for DPA 4.00 19 // 2017/08/14 Release for DPA 3.01 20 // 2017/03/13 Release for DPA 3.00 21 // 2015/08/05 Release for DPA 2.20 22 // 2014/10/31 Release for DPA 2.10 23 // 2014/04/30 Release for DPA 2.00 24 // 25 // ********************************************************************* 26 27 // Online DPA documentation https://doc.iqrf.org/DpaTechGuide/ 28 29 /*< 30 This is a Custom DPA Handler with all available events prepared. 31 Use the following define to use a Coordinator version instead of default Node version. 32 `#define COORDINATOR_CUSTOM_HANDLER` 33 >*/ 34 35 // Default IQRF include (modify the path according to your setup) 36 #include "IQRF.h" 37 38 // Default DPA header (modify the path according to your setup) 39 #include "DPA.h" 40 // Default Custom DPA Handler header (modify the path according to your setup) 41 #include "DPAcustomHandler.h" 42 43 // Uncomment the following includes if the respective component is needed 44 // IQRF standards header (modify the path according to your setup) 45 //#include "IQRFstandard.h" 46 //#include "IQRF_HWPID.h" 47 //#include "NFC.c" 48 49 //############################################################################################ 50 51 // Place for global variables shared among CustomDpaHandler() and other function, otherwise local [static] variables are recommended 52 // example: uns8 globalCounter; 53 54 // Must be the 1st defined function in the source code in order to be placed at the correct FLASH location! 55 //############################################################################################ 56 // https://doc.iqrf.org/DpaTechGuide/pages/custom-dpa-handler.html 57 bit CustomDpaHandler() 58 //############################################################################################ 59 { 60 // Handler presence mark 61 clrwdt(); 62 63 // Place for local static variables used only within CustomDpaHandler() among more events 64 // example: static bit interruptOccured; 65 66 // Detect DPA event to handle (unused event handlers can be commented out or even deleted) 67 switch ( GetDpaEvent() ) 68 { 69 #ifdef DpaEvent_Interrupt 70 // ------------------------------------------------- 71 case DpaEvent_Interrupt: 72 // Do an extra quick background interrupt work 73 // ! The time spent handling this event is critical.If there is no interrupt to handle return immediately otherwise keep the code as fast as possible. 74 // ! Make sure the event is the 1st case in the main switch statement at the handler routine.This ensures that the event is handled as the 1st one. 75 // ! It is desirable that this event is handled with immediate return even if it is not used by the custom handler because the Interrupt event is raised on every MCU interrupt and the “empty” return handler ensures the shortest possible interrupt routine response time. 76 // ! Only global variables or local ones marked by static keyword can be used to allow reentrancy. 77 // ! Make sure race condition does not occur when accessing those variables at other places. 78 // ! Make sure( inspect.lst file generated by C compiler ) compiler does not create any hidden temporary local variable( occurs when using division, multiplication or bit shifts ) at the event handler code.The name of such variable is usually Cnumbercnt. 79 // ! Do not call any OS functions except setINDFx(). 80 // ! Do not use any OS variables especially for writing access. 81 // ! All above rules apply also to any other function being called from the event handler code, although calling any function from Interrupt event is not recommended because of additional MCU stack usage. 82 // https://doc.iqrf.org/DpaTechGuide/pages/EventInterrupt.html 83 return Carry; 84 #endif 85 // ------------------------------------------------- 86 case DpaEvent_Idle: 87 // Do a quick background work when RF packet is not received 88 // https://doc.iqrf.org/DpaTechGuide/pages/idle.html 89 break; 90 91 // ------------------------------------------------- 92 case DpaEvent_Reset: 93 // Called after module is reset 94 // https://doc.iqrf.org/DpaTechGuide/pages/ResetEvent.html 95 96 //goto DpaHandleReturnTRUE; // return TRUE only if you handle node bonding/unbonding 97 break; 98 99 #if !defined( COORDINATOR_CUSTOM_HANDLER ) && defined( DpaEvent_BondingButton ) 100 // ------------------------------------------------- 101 case DpaEvent_BondingButton: 102 // Called to allow a bonding button customization 103 // https://doc.iqrf.org/DpaTechGuide/pages/bondingbutton.html 104 105 //goto DpaHandleReturnTRUE; // return TRUE to handle bonding button 106 break; 107 #endif 108 109 #ifndef COORDINATOR_CUSTOM_HANDLER 110 // ------------------------------------------------- 111 case DpaEvent_Indicate: 112 // Called to allow a customization of the device indication 113 // https://doc.iqrf.org/DpaTechGuide/pages/IndicateEvent.html 114 115 //goto DpaHandleReturnTRUE; // return TRUE to skip default indication 116 break; 117 #endif 118 119 // ------------------------------------------------- 120 case DpaEvent_Init: 121 // Do a one time initialization before main loop starts 122 // https://doc.iqrf.org/DpaTechGuide/pages/init.html 123 break; 124 125 // ------------------------------------------------- 126 case DpaEvent_ReceiveDpaRequest: 127 // Called after DPA request was received 128 // https://doc.iqrf.org/DpaTechGuide/pages/receivedparequest.html 129 130 //goto DpaHandleReturnTRUE; // return TRUE to skip default processing 131 break; 132 133 // ------------------------------------------------- 134 case DpaEvent_BeforeSendingDpaResponse: 135 // Called before sending DPA response back to originator of DPA response 136 // https://doc.iqrf.org/DpaTechGuide/pages/beforesendingdparesponse.html 137 break; 138 139 // ------------------------------------------------- 140 case DpaEvent_Notification: 141 // Called after DPA request was processed and after DPA response was sent 142 // https://doc.iqrf.org/DpaTechGuide/pages/notification.html 143 break; 144 145 // ------------------------------------------------- 146 case DpaEvent_AfterRouting: 147 // Called after Notification and after routing of the DPA response was finished 148 // https://doc.iqrf.org/DpaTechGuide/pages/afterrouting.html 149 break; 150 151 #ifndef COORDINATOR_CUSTOM_HANDLER 152 // ------------------------------------------------- 153 case DpaEvent_FrcValue: 154 // Called to get FRC value 155 // https://doc.iqrf.org/DpaTechGuide/pages/frcvalue.html 156 break; 157 #endif 158 159 #ifndef COORDINATOR_CUSTOM_HANDLER 160 // ------------------------------------------------- 161 case DpaEvent_FrcResponseTime: 162 // Called to get FRC response time 163 // https://doc.iqrf.org/DpaTechGuide/pages/frcresponsetime.html 164 break; 165 #endif 166 167 #ifndef COORDINATOR_CUSTOM_HANDLER 168 // ------------------------------------------------- 169 case DpaEvent_BeforeSleep: 170 // Called before going to sleep 171 // https://doc.iqrf.org/DpaTechGuide/pages/beforesleep.html 172 break; 173 #endif 174 175 #ifndef COORDINATOR_CUSTOM_HANDLER 176 // ------------------------------------------------- 177 case DpaEvent_AfterSleep: 178 // Called after woken up after sleep 179 // https://doc.iqrf.org/DpaTechGuide/pages/aftersleep.html 180 break; 181 #endif 182 183 // ------------------------------------------------- 184 case DpaEvent_DisableInterrupts: 185 // Called when device needs all hardware interrupts to be disabled (before Reset, Restart, LoadCode, Remove bond and run RFPGM) 186 // https://doc.iqrf.org/DpaTechGuide/pages/eventDisableInterrupts.html 187 break; 188 189 #ifdef COORDINATOR_CUSTOM_HANDLER 190 // ------------------------------------------------- 191 case DpaEvent_ReceiveDpaResponse: 192 // Called after DPA response was received at coordinator 193 // https://doc.iqrf.org/DpaTechGuide/pages/receivedparesponse.html 194 195 //goto DpaHandleReturnTRUE; // return TRUE to skip default processing 196 break; 197 #endif 198 199 #ifdef COORDINATOR_CUSTOM_HANDLER 200 // ------------------------------------------------- 201 case DpaEvent_IFaceReceive: 202 // Called after DPA request from interface master was received at coordinator 203 // https://doc.iqrf.org/DpaTechGuide/pages/ifacereceive.html 204 205 //goto DpaHandleReturnTRUE; // return TRUE to skip default processing 206 break; 207 #endif 208 209 // ------------------------------------------------- 210 case DpaEvent_PeerToPeer: 211 // Called when peer-to-peer (non-networking) packet is received 212 // https://doc.iqrf.org/DpaTechGuide/pages/peertopeer.html 213 break; 214 215 // ------------------------------------------------- 216 case DpaEvent_UserDpaValue: 217 // Called when DPA is required to return User defined DPA value in the response 218 // https://doc.iqrf.org/DpaTechGuide/pages/userdpavalue.html 219 break; 220 221 // ------------------------------------------------- 222 #if !defined( COORDINATOR_CUSTOM_HANDLER ) && defined( DpaEvent_InStandby ) 223 case DpaEvent_InStandby: 224 // Called to set WDT during Standby 225 // https://doc.iqrf.org/DpaTechGuide/pages/instandby.html 226 227 //goto DpaHandleReturnTRUE; // return TRUE to indicate that userReg1 contains WDT settings 228 goto DpaHandleReturnFALSE; 229 #endif 230 231 #ifndef COORDINATOR_CUSTOM_HANDLER 232 // ------------------------------------------------- 233 case DpaEvent_VerifyLocalFrc: 234 // Called to verify local FRC command 235 // https://doc.iqrf.org/DpaTechGuide/pages/verifylocalfrc.html 236 237 //goto DpaHandleReturnTRUE; // return TRUE allow FRC command 238 break; 239 #endif 240 241 // ------------------------------------------------- 242 #if !defined( COORDINATOR_CUSTOM_HANDLER ) && defined( DpaEvent_MenuActivated ) 243 case DpaEvent_MenuActivated: 244 // Called to customize DPA menu 245 // https://doc.iqrf.org/DpaTechGuide/pages/menuactivated.html 246 247 //goto DpaHandleReturnTRUE; // return TRUE to allow customizing menu specified by userReg1 248 break; 249 #endif 250 251 // ------------------------------------------------- 252 #if !defined( COORDINATOR_CUSTOM_HANDLER ) && defined( DpaEvent_MenuItemSelected ) 253 case DpaEvent_MenuItemSelected: 254 // Called to indicate "OK" or "Error" for selected menu item 255 // https://doc.iqrf.org/DpaTechGuide/pages/menuitemselected.html 256 257 //goto DpaHandleReturnTRUE; // return TRUE to indicate "OK" for menu item specified by userReg1, otherwise to indicate Error 258 break; 259 #endif 260 261 // ------------------------------------------------- 262 #if !defined( COORDINATOR_CUSTOM_HANDLER ) && defined( DpaEvent_MenuItemFinalize ) 263 case DpaEvent_MenuItemFinalize: 264 // Called to finalize menu item execution 265 // https://doc.iqrf.org/DpaTechGuide/pages/menuitemfinalize.html 266 267 break; 268 #endif 269 270 // ------------------------------------------------- 271 #if !defined( COORDINATOR_CUSTOM_HANDLER ) && defined( DpaEvent_AsyncRequest ) 272 case DpaEvent_AsyncRequest: 273 // Optionally passed DPA Request to execute to the DPA 274 // https://doc.iqrf.org/DpaTechGuide/pages/asyncrequest.html 275 276 //goto DpaHandleReturnTRUE; // return TRUE to pass the DPA Request 277 break; 278 #endif 279 280 // ------------------------------------------------- 281 #if !defined( COORDINATOR_CUSTOM_HANDLER ) && defined( DpaEvent_AsyncResponse ) 282 case DpaEvent_AsyncResponse: 283 // Called with DPA response for DPA request from DpaEvent_MenuItemFinalize 284 // https://doc.iqrf.org/DpaTechGuide/pages/asyncresponse.html 285 286 break; 287 #endif 288 289 // ------------------------------------------------- 290 case DpaEvent_DpaRequest: 291 // Called to interpret DPA request for peripherals 292 // https://doc.iqrf.org/DpaTechGuide/pages/EventDpaRequest.html 293 IfDpaEnumPeripherals_Else_PeripheralInfo_Else_PeripheralRequest() 294 { 295 // ------------------------------------------------- 296 // Peripheral enumeration 297 // https://doc.iqrf.org/DpaTechGuide/pages/enumerate-peripherals.html 298 299 _DpaMessage.EnumPeripheralsAnswer.UserPerNr |= 0; // ? 300 // FlagUserPer( _DpaMessage.EnumPeripheralsAnswer.UserPer, PNUM_USER + 0 ); // ? 301 _DpaMessage.EnumPeripheralsAnswer.HWPID |= 0x000F; // ???? 302 _DpaMessage.EnumPeripheralsAnswer.HWPIDver |= 0; // ???? 303 304 DpaHandleReturnTRUE: 305 return TRUE; 306 } 307 else 308 { 309 // ------------------------------------------------- 310 // Get information about peripheral 311 // https://doc.iqrf.org/DpaTechGuide/pages/get-peripheral-info.html 312 313 if ( _PNUM == PNUM_USER + 0 ) // ? 314 { 315 _DpaMessage.PeripheralInfoAnswer.PerT = 0; // PERIPHERAL_TYPE_? 316 _DpaMessage.PeripheralInfoAnswer.PerTE = 0; // PERIPHERAL_TYPE_EXTENDED_? 317 _DpaMessage.PeripheralInfoAnswer.Par1 = 0; // ? 318 _DpaMessage.PeripheralInfoAnswer.Par2 = 0; // ? 319 goto DpaHandleReturnTRUE; 320 } 321 322 break; 323 } 324 325 // ------------------------------------------------- 326 // Handle peripheral command 327 // https://doc.iqrf.org/DpaTechGuide/pages/handle-peripheral-request.html 328 329 if ( _PNUM == PNUM_USER + 0 ) // ? 330 { 331 if ( _PCMD == 0 ) // ???? 332 { 333 goto DpaHandleReturnTRUE; 334 } 335 } 336 337 break; 338 } 339 340 DpaHandleReturnFALSE: 341 return FALSE; 342 } 343 344 //############################################################################################ 345 // Uncomment the following includes if the respective component is needed 346 //#include "NFC.c" 347 348 // Default Custom DPA Handler header; 2nd include implementing a Code bumper to detect too long code of the Custom DPA Handler (modify the path according to your setup) 349 #include "DPAcustomHandler.h" 350 //############################################################################################