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