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