1 // ********************************************************************* 2 // Custom DPA Handler code template * 3 // ********************************************************************* 4 // Copyright (c) MICRORISC s.r.o. 5 // 6 // File: $RCSfile: CustomDpaHandler-Template-Node.c,v $ 7 // Version: $Revision: 1.26 $ 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 // Default IQRF include (modify the path according to your setup) 30 #include "IQRF.h" 31 32 // Default DPA header (modify the path according to your setup) 33 #include "DPA.h" 34 // Default Custom DPA Handler header (modify the path according to your setup) 35 #include "DPAcustomHandler.h" 36 37 // Uncomment the following includes if the respective component is needed 38 // IQRF standards header (modify the path according to your setup) 39 //#include "IQRFstandard.h" 40 //#include "IQRF_HWPID.h" 41 //#include "NFC.c" 42 43 //############################################################################################ 44 45 // Place for global variables shared among CustomDpaHandler() and other function, otherwise local [static] variables are recommended 46 // example: uns8 globalCounter; 47 48 // Must be the 1st defined function in the source code in order to be placed at the correct FLASH location! 49 //############################################################################################ 50 // https://doc.iqrf.org/DpaTechGuide/pages/custom-dpa-handler.html 51 bit CustomDpaHandler() 52 //############################################################################################ 53 { 54 // Handler presence mark 55 clrwdt(); 56 57 // Place for local static variables used only within CustomDpaHandler() among more events 58 // example: static bit interruptOccured; 59 60 // Detect DPA event to handle (unused event handlers can be commented out or even deleted) 61 switch ( GetDpaEvent() ) 62 { 63 // ------------------------------------------------- 64 case DpaEvent_Interrupt: 65 // Do an extra quick background interrupt work 66 // ! 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. 67 // ! 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. 68 // ! 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. 69 // ! Only global variables or local ones marked by static keyword can be used to allow reentrancy. 70 // ! Make sure race condition does not occur when accessing those variables at other places. 71 // ! 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. 72 // ! Do not call any OS functions except setINDFx(). 73 // ! Do not use any OS variables especially for writing access. 74 // ! 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. 75 // https://doc.iqrf.org/DpaTechGuide/pages/EventInterrupt.html 76 return Carry; 77 78 // ------------------------------------------------- 79 case DpaEvent_Idle: 80 // Do a quick background work when RF packet is not received 81 // https://doc.iqrf.org/DpaTechGuide/pages/idle.html 82 break; 83 84 // ------------------------------------------------- 85 case DpaEvent_Reset: 86 // Called after module is reset 87 // https://doc.iqrf.org/DpaTechGuide/pages/ResetEvent.html 88 89 //goto DpaHandleReturnTRUE; // return TRUE only if you handle node bonding/unbonding 90 break; 91 92 // ------------------------------------------------- 93 #if defined( DpaEvent_BondingButton ) 94 case DpaEvent_BondingButton: 95 // Called to allow a bonding button customization 96 // https://doc.iqrf.org/DpaTechGuide/pages/bondingbutton.html 97 98 //goto DpaHandleReturnTRUE; // return TRUE to handle bonding button 99 break; 100 #endif 101 102 // ------------------------------------------------- 103 case DpaEvent_Indicate: 104 // Called to allow a customization of the device indication 105 // https://doc.iqrf.org/DpaTechGuide/pages/IndicateEvent.html 106 107 //goto DpaHandleReturnTRUE; // return TRUE to skip default indication 108 break; 109 110 // ------------------------------------------------- 111 case DpaEvent_Init: 112 // Do a one time initialization before main loop starts 113 // https://doc.iqrf.org/DpaTechGuide/pages/init.html 114 break; 115 116 // ------------------------------------------------- 117 case DpaEvent_ReceiveDpaRequest: 118 // Called after DPA request was received 119 // https://doc.iqrf.org/DpaTechGuide/pages/receivedparequest.html 120 121 //goto DpaHandleReturnTRUE; // return TRUE to skip default processing 122 break; 123 124 // ------------------------------------------------- 125 case DpaEvent_BeforeSendingDpaResponse: 126 // Called before sending DPA response back to originator of DPA response 127 // https://doc.iqrf.org/DpaTechGuide/pages/beforesendingdparesponse.html 128 break; 129 130 // ------------------------------------------------- 131 case DpaEvent_Notification: 132 // Called after DPA request was processed and after DPA response was sent 133 // https://doc.iqrf.org/DpaTechGuide/pages/notification.html 134 break; 135 136 // ------------------------------------------------- 137 case DpaEvent_AfterRouting: 138 // Called after Notification and after routing of the DPA response was finished 139 // https://doc.iqrf.org/DpaTechGuide/pages/afterrouting.html 140 break; 141 142 // ------------------------------------------------- 143 case DpaEvent_FrcValue: 144 // Called to get FRC value 145 // https://doc.iqrf.org/DpaTechGuide/pages/frcvalue.html 146 break; 147 148 // ------------------------------------------------- 149 case DpaEvent_FrcResponseTime: 150 // Called to get FRC response time 151 // https://doc.iqrf.org/DpaTechGuide/pages/frcresponsetime.html 152 break; 153 154 // ------------------------------------------------- 155 case DpaEvent_BeforeSleep: 156 // Called before going to sleep 157 // https://doc.iqrf.org/DpaTechGuide/pages/beforesleep.html 158 break; 159 160 // ------------------------------------------------- 161 case DpaEvent_AfterSleep: 162 // Called after woken up after sleep 163 // https://doc.iqrf.org/DpaTechGuide/pages/aftersleep.html 164 break; 165 166 // ------------------------------------------------- 167 case DpaEvent_DisableInterrupts: 168 // Called when device needs all hardware interrupts to be disabled (before Reset, Restart, LoadCode, Remove bond and run RFPGM) 169 // https://doc.iqrf.org/DpaTechGuide/pages/eventDisableInterrupts.html 170 break; 171 172 // ------------------------------------------------- 173 case DpaEvent_PeerToPeer: 174 // Called when peer-to-peer (non-networking) packet is received 175 // https://doc.iqrf.org/DpaTechGuide/pages/peertopeer.html 176 break; 177 178 // ------------------------------------------------- 179 case DpaEvent_UserDpaValue: 180 // Called when DPA is required to return User defined DPA value in the response 181 // https://doc.iqrf.org/DpaTechGuide/pages/userdpavalue.html 182 break; 183 184 // ------------------------------------------------- 185 #ifdef DpaEvent_InStandby 186 case DpaEvent_InStandby: 187 // Called to set WDT during Standby 188 // https://doc.iqrf.org/DpaTechGuide/pages/instandby.html 189 190 //goto DpaHandleReturnTRUE; // return TRUE to indicate that userReg1 contains WDT settings 191 break; 192 #endif 193 194 // ------------------------------------------------- 195 case DpaEvent_VerifyLocalFrc: 196 // Called to verify local FRC command 197 // https://doc.iqrf.org/DpaTechGuide/pages/verifylocalfrc.html 198 199 //goto DpaHandleReturnTRUE; // return TRUE allow FRC command 200 break; 201 202 // ------------------------------------------------- 203 #ifdef DpaEvent_MenuActivated 204 case DpaEvent_MenuActivated: 205 // Called to customize DPA menu 206 // https://doc.iqrf.org/DpaTechGuide/pages/menuactivated.html 207 208 //goto DpaHandleReturnTRUE; // return TRUE to allow customizing menu specified by userReg1 209 break; 210 #endif 211 212 // ------------------------------------------------- 213 #ifdef DpaEvent_MenuItemSelected 214 case DpaEvent_MenuItemSelected: 215 // Called to indicate "OK" or "Error" for selected menu item 216 // https://doc.iqrf.org/DpaTechGuide/pages/menuitemselected.html 217 218 //goto DpaHandleReturnTRUE; // return TRUE to indicate "OK" for menu item specified by userReg1, otherwise to indicate Error 219 break; 220 #endif 221 222 // ------------------------------------------------- 223 #ifdef DpaEvent_MenuItemFinalize 224 case DpaEvent_MenuItemFinalize: 225 // Called to finalize menu item execution 226 // https://doc.iqrf.org/DpaTechGuide/pages/menuitemfinalize.html 227 228 break; 229 #endif 230 231 // ------------------------------------------------- 232 #ifdef DpaEvent_AsyncRequest 233 case DpaEvent_AsyncRequest: 234 // Optionally passed DPA Request to execute to the DPA 235 // https://doc.iqrf.org/DpaTechGuide/pages/asyncrequest.html 236 237 //goto DpaHandleReturnTRUE; // return TRUE to pass the DPA Request 238 break; 239 #endif 240 241 // ------------------------------------------------- 242 #ifdef DpaEvent_AsyncResponse 243 case DpaEvent_AsyncResponse: 244 // Called with DPA response for DPA request from DpaEvent_MenuItemFinalize 245 // https://doc.iqrf.org/DpaTechGuide/pages/asyncresponse.html 246 247 break; 248 #endif 249 250 // ------------------------------------------------- 251 case DpaEvent_DpaRequest: 252 // Called to interpret DPA request for peripherals 253 // https://doc.iqrf.org/DpaTechGuide/pages/EventDpaRequest.html 254 IfDpaEnumPeripherals_Else_PeripheralInfo_Else_PeripheralRequest() 255 { 256 // ------------------------------------------------- 257 // Peripheral enumeration 258 // https://doc.iqrf.org/DpaTechGuide/pages/enumerate-peripherals.html 259 260 _DpaMessage.EnumPeripheralsAnswer.UserPerNr |= 0; // ? 261 // FlagUserPer( _DpaMessage.EnumPeripheralsAnswer.UserPer, PNUM_USER + 0 ); // ? 262 _DpaMessage.EnumPeripheralsAnswer.HWPID |= 0x000F; // ???? 263 _DpaMessage.EnumPeripheralsAnswer.HWPIDver |= 0; // ???? 264 265 DpaHandleReturnTRUE: 266 return TRUE; 267 } 268 else 269 { 270 // ------------------------------------------------- 271 // Get information about peripheral 272 // https://doc.iqrf.org/DpaTechGuide/pages/get-peripheral-info.html 273 274 if ( _PNUM == PNUM_USER + 0 ) // ? 275 { 276 _DpaMessage.PeripheralInfoAnswer.PerT = 0; // PERIPHERAL_TYPE_? 277 _DpaMessage.PeripheralInfoAnswer.PerTE = 0; // PERIPHERAL_TYPE_EXTENDED_? 278 _DpaMessage.PeripheralInfoAnswer.Par1 = 0; // ? 279 _DpaMessage.PeripheralInfoAnswer.Par2 = 0; // ? 280 goto DpaHandleReturnTRUE; 281 } 282 283 break; 284 } 285 286 // ------------------------------------------------- 287 // Handle peripheral command 288 // https://doc.iqrf.org/DpaTechGuide/pages/handle-peripheral-request.html 289 290 if ( _PNUM == PNUM_USER + 0 ) // ? 291 { 292 if ( _PCMD == 0 ) // ???? 293 { 294 goto DpaHandleReturnTRUE; 295 } 296 } 297 298 break; 299 } 300 301 DpaHandleReturnFALSE: 302 return FALSE; 303 } 304 305 //############################################################################################ 306 // Uncomment the following includes if the respective component is needed 307 //#include "NFC.c" 308 309 // 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) 310 #include "DPAcustomHandler.h" 311 //############################################################################################