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