1 // ********************************************************************* 2 // Custom DPA Handler code template * 3 // ********************************************************************* 4 // Copyright (c) MICRORISC s.r.o. 5 // 6 // File: $RCSfile: CustomDpaHandler-Template-OptimizedSwitch-Coordinator.c,v $ 7 // Version: $Revision: 1.18 $ 8 // Date: $Date: 2025/09/22 15:45:41 $ 9 // 10 // Revision history: 11 // 2025/05/30 Release for DPA 4.33 12 // 2022/02/24 Release for DPA 4.17 13 // 2021/08/20 Release for DPA 4.16 14 // 2020/09/03 Release for DPA 4.15 15 // 2020/02/27 Release for DPA 4.13 16 // 2019/01/10 Release for DPA 4.00 17 // 2017/08/14 Release for DPA 3.01 18 // 2017/03/13 Release for DPA 3.00 19 // 2015/08/05 Release for DPA 2.20 20 // 2014/10/31 Release for DPA 2.10 21 // 2014/04/30 Release for DPA 2.00 22 // 23 // ********************************************************************* 24 25 // Online DPA documentation https://doc.iqrf.org/DpaTechGuide/ 26 27 // Default IQRF include (modify the path according to your setup) 28 #include "IQRF.h" 29 30 // Implement Custom DPA Handler for Coordinator 31 #define COORDINATOR_CUSTOM_HANDLER 32 33 // Default DPA header (modify the path according to your setup) 34 #include "DPA.h" 35 // Default Custom DPA Handler header (modify the path according to your setup) 36 #include "DPAcustomHandler.h" 37 38 // Uncomment the following includes if the respective component is needed 39 // IQRF standards header (modify the path according to your setup) 40 //#include "IQRFstandard.h" 41 //#include "IQRF_HWPID.h" 42 //#include "NFC.c" 43 44 //############################################################################################ 45 46 // Place for global variables shared among CustomDpaHandler() and other function, otherwise local [static] variables are recommended 47 // example: uns8 globalCounter; 48 49 // Must be the 1st defined function in the source code in order to be placed at the correct FLASH location! 50 //############################################################################################ 51 // https://doc.iqrf.org/DpaTechGuide/pages/custom-dpa-handler.html 52 bit CustomDpaHandler() 53 //############################################################################################ 54 { 55 // Handler presence mark 56 clrwdt(); 57 58 // Place for local static variables used only within CustomDpaHandler() among more events 59 // example: static bit interruptOccured; 60 61 // Detect DPA event to handle 62 // 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. 63 W = DpaEvent_LAST - GetDpaEvent(); 64 if ( !Carry ) 65 goto DpaHandleReturnFALSE; 66 67 skip( W ); 68 #pragma computedGoto 1 69 // Reverse order of events because of subtraction 70 #if DpaEvent_LAST == DpaEvent_AsyncResponse 71 goto DpaHandleReturnFALSE; // DpaEvent_AsyncResponse : not implemented at Coordinator 72 goto DpaHandleReturnFALSE; // DpaEvent_AsyncRequest : not implemented at Coordinator 73 goto DpaHandleReturnFALSE; // DpaEvent_InStandby : not implemented at Coordinator 74 goto DpaHandleReturnFALSE; // DpaEvent_MenuItemFinalize : not implemented at Coordinator 75 goto DpaHandleReturnFALSE; // DpaEvent_MenuItemSelected : not implemented at Coordinator 76 goto DpaHandleReturnFALSE; // DpaEvent_MenuActivated : not implemented at Coordinator 77 #endif 78 goto DpaHandleReturnFALSE; // DpaEvent_VerifyLocalFrc : not implemented at Coordinator 79 goto DpaHandleReturnFALSE; // DpaEvent_Indicate : not implemented at Coordinator 80 goto DpaHandleReturnFALSE; // DpaEvent_BondingButton : not implemented at Coordinator 81 goto DpaHandleReturnFALSE; // DpaEvent_FrcResponseTime : not implemented at Coordinator 82 goto _DpaEvent_UserDpaValue; 83 goto DpaHandleReturnFALSE; // Formerly DpaEvent_AuthorizePreBonding 84 goto _DpaEvent_PeerToPeer; 85 goto _DpaEvent_BeforeSendingDpaResponse; 86 goto _DpaEvent_ReceiveDpaRequest; 87 goto _DpaEvent_IFaceReceive; 88 goto _DpaEvent_ReceiveDpaResponse; 89 goto DpaHandleReturnFALSE; // DpaEvent_FrcValue : not implemented at Coordinator 90 goto _DpaEvent_DisableInterrupts; 91 goto _DpaEvent_Reset; 92 goto DpaHandleReturnFALSE; // DpaEvent_AfterSleep : not implemented at Coordinator 93 goto DpaHandleReturnFALSE; // DpaEvent_BeforeSleep : not implemented at Coordinator 94 goto _DpaEvent_AfterRouting; 95 goto _DpaEvent_Notification; 96 goto _DpaEvent_Init; 97 goto _DpaEvent_Idle; 98 goto DpaHandleReturnFALSE; // DpaEvent_Interrupt : not implemented at Coordinator 99 goto _DpaEvent_DpaRequest; 100 #pragma computedGoto 0 101 ; 102 // ------------------------------------------------- 103 _DpaEvent_DpaRequest: 104 // Called to interpret DPA request for peripherals 105 // https://doc.iqrf.org/DpaTechGuide/pages/EventDpaRequest.html 106 // ------------------------------------------------- 107 // Peripheral enumeration 108 // https://doc.iqrf.org/DpaTechGuide/pages/enumerate-peripherals.html 109 IfDpaEnumPeripherals_Else_PeripheralInfo_Else_PeripheralRequest() 110 { 111 _DpaMessage.EnumPeripheralsAnswer.UserPerNr |= 0; // ? 112 // FlagUserPer( _DpaMessage.EnumPeripheralsAnswer.UserPer, PNUM_USER + 0 ); // ? 113 _DpaMessage.EnumPeripheralsAnswer.HWPID |= 0x000F; // ???? 114 _DpaMessage.EnumPeripheralsAnswer.HWPIDver |= 0; // ???? 115 116 DpaHandleReturnTRUE: 117 return TRUE; 118 } 119 // ------------------------------------------------- 120 // Get information about peripheral 121 // https://doc.iqrf.org/DpaTechGuide/pages/get-peripheral-info.html 122 else 123 { 124 if ( _PNUM == PNUM_USER + 0 ) // ? 125 { 126 _DpaMessage.PeripheralInfoAnswer.PerT = 0; // PERIPHERAL_TYPE_? 127 _DpaMessage.PeripheralInfoAnswer.PerTE = 0; // PERIPHERAL_TYPE_EXTENDED_? 128 _DpaMessage.PeripheralInfoAnswer.Par1 = 0; // ? 129 _DpaMessage.PeripheralInfoAnswer.Par2 = 0; // ? 130 goto DpaHandleReturnTRUE; 131 } 132 133 goto DpaHandleReturnFALSE; 134 } 135 // ------------------------------------------------- 136 // Handle peripheral command 137 // https://doc.iqrf.org/DpaTechGuide/pages/handle-peripheral-request.html 138 if ( _PNUM == PNUM_USER + 0 ) // ? 139 { 140 if ( _PCMD == 0 ) // ???? 141 { 142 goto DpaHandleReturnTRUE; 143 } 144 } 145 146 goto DpaHandleReturnFALSE; 147 148 // ------------------------------------------------- 149 _DpaEvent_Idle: 150 // Do a quick background work when RF packet is not received 151 // https://doc.iqrf.org/DpaTechGuide/pages/idle.html 152 goto DpaHandleReturnFALSE; 153 154 // ------------------------------------------------- 155 _DpaEvent_Reset: 156 // Called after module is reset 157 // https://doc.iqrf.org/DpaTechGuide/pages/ResetEvent.html 158 159 //goto DpaHandleReturnTRUE; // return TRUE only if you handle node bonding/unbonding 160 goto DpaHandleReturnFALSE; 161 162 // ------------------------------------------------- 163 _DpaEvent_Init: 164 // Do a one time initialization before main loop starts 165 // https://doc.iqrf.org/DpaTechGuide/pages/init.html 166 goto DpaHandleReturnFALSE; 167 168 // ------------------------------------------------- 169 _DpaEvent_ReceiveDpaRequest: 170 // Called after DPA request was received 171 // https://doc.iqrf.org/DpaTechGuide/pages/receivedparequest.html 172 173 //goto DpaHandleReturnTRUE; // return TRUE to skip default processing 174 goto DpaHandleReturnFALSE; 175 176 // ------------------------------------------------- 177 _DpaEvent_BeforeSendingDpaResponse: 178 // Called before sending DPA response back to originator of DPA response 179 // https://doc.iqrf.org/DpaTechGuide/pages/beforesendingdparesponse.html 180 181 goto DpaHandleReturnFALSE; 182 183 // ------------------------------------------------- 184 _DpaEvent_Notification: 185 // Called after DPA request was processed and after DPA response was sent 186 // https://doc.iqrf.org/DpaTechGuide/pages/notification.html 187 goto DpaHandleReturnFALSE; 188 189 // ------------------------------------------------- 190 _DpaEvent_AfterRouting: 191 // Called after Notification and after routing of the DPA response was finished 192 // https://doc.iqrf.org/DpaTechGuide/pages/afterrouting.html 193 goto DpaHandleReturnFALSE; 194 195 // ------------------------------------------------- 196 _DpaEvent_DisableInterrupts: 197 // Called when device needs all hardware interrupts to be disabled (before Reset, Restart, LoadCode, Remove bond and run RFPGM) 198 // https://doc.iqrf.org/DpaTechGuide/pages/eventDisableInterrupts.html 199 goto DpaHandleReturnFALSE; 200 201 // ------------------------------------------------- 202 _DpaEvent_ReceiveDpaResponse: 203 // Called after DPA response was received at coordinator 204 // https://doc.iqrf.org/DpaTechGuide/pages/receivedparesponse.html 205 206 //goto DpaHandleReturnTRUE; // return TRUE to skip default processing 207 goto DpaHandleReturnFALSE; 208 209 // ------------------------------------------------- 210 _DpaEvent_IFaceReceive: 211 // Called after DPA request from interface master was received at coordinator 212 // https://doc.iqrf.org/DpaTechGuide/pages/ifacereceive.html 213 214 //goto DpaHandleReturnTRUE; // return TRUE to skip default processing 215 goto DpaHandleReturnFALSE; 216 217 // ------------------------------------------------- 218 _DpaEvent_PeerToPeer: 219 // Called when peer-to-peer (non-networking) packet is received 220 // https://doc.iqrf.org/DpaTechGuide/pages/peertopeer.html 221 goto DpaHandleReturnFALSE; 222 223 // ------------------------------------------------- 224 _DpaEvent_UserDpaValue: 225 // Called when DPA is required to return User defined DPA value in the response 226 // https://doc.iqrf.org/DpaTechGuide/pages/userdpavalue.html 227 goto DpaHandleReturnFALSE; 228 229 // ------------------------------------------------- 230 231 DpaHandleReturnFALSE: 232 return FALSE; 233 } 234 235 //############################################################################################ 236 237 // Uncomment the following includes if the respective component is needed 238 //#include "NFC.c" 239 240 // 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) 241 #include "DPAcustomHandler.h" 242 //############################################################################################