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.15 $ 8 // Date: $Date: 2022/11/28 12:55:45 $ 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 // Implement Custom DPA Handler for Coordinator 30 #define COORDINATOR_CUSTOM_HANDLER 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 61 // 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. 62 W = DpaEvent_LAST - GetDpaEvent(); 63 if ( !Carry ) 64 goto DpaHandleReturnFALSE; 65 66 skip( W ); 67 #pragma computedGoto 1 68 // Reverse order of events because of subtraction 69 #if DpaEvent_LAST == DpaEvent_InStandby 70 goto DpaHandleReturnFALSE; // _DpaEvent_InStandby : not implemented at Coordinator 71 goto DpaHandleReturnFALSE; // _DpaEvent_MenuItemFinalize : not implemented at Coordinator 72 goto DpaHandleReturnFALSE; // _DpaEvent_MenuItemSelected : not implemented at Coordinator 73 goto DpaHandleReturnFALSE; // _DpaEvent_MenuActivated : not implemented at Coordinator 74 #endif 75 goto DpaHandleReturnFALSE; // DpaEvent_VerifyLocalFrc : not implemented at Coordinator 76 goto DpaHandleReturnFALSE; // DpaEvent_Indicate : not implemented at Coordinator 77 goto DpaHandleReturnFALSE; // DpaEvent_BondingButton : not implemented at Coordinator 78 goto DpaHandleReturnFALSE; // DpaEvent_FrcResponseTime : not implemented at Coordinator 79 goto _DpaEvent_UserDpaValue; 80 goto DpaHandleReturnFALSE; // Formerly DpaEvent_AuthorizePreBonding 81 goto _DpaEvent_PeerToPeer; 82 goto _DpaEvent_BeforeSendingDpaResponse; 83 goto _DpaEvent_ReceiveDpaRequest; 84 goto _DpaEvent_IFaceReceive; 85 goto _DpaEvent_ReceiveDpaResponse; 86 goto DpaHandleReturnFALSE; // DpaEvent_FrcValue : not implemented at Coordinator 87 goto _DpaEvent_DisableInterrupts; 88 goto _DpaEvent_Reset; 89 goto DpaHandleReturnFALSE; // DpaEvent_AfterSleep : not implemented at Coordinator 90 goto DpaHandleReturnFALSE; // DpaEvent_BeforeSleep : not implemented at Coordinator 91 goto _DpaEvent_AfterRouting; 92 goto _DpaEvent_Notification; 93 goto _DpaEvent_Init; 94 goto _DpaEvent_Idle; 95 goto DpaHandleReturnFALSE; // DpaEvent_Interrupt : not implemented at Coordinator 96 goto _DpaEvent_DpaRequest; 97 #pragma computedGoto 0 98 ; 99 // ------------------------------------------------- 100 _DpaEvent_DpaRequest: 101 // Called to interpret DPA request for peripherals 102 // https://doc.iqrf.org/DpaTechGuide/pages/EventDpaRequest.html 103 // ------------------------------------------------- 104 // Peripheral enumeration 105 // https://doc.iqrf.org/DpaTechGuide/pages/enumerate-peripherals.html 106 IfDpaEnumPeripherals_Else_PeripheralInfo_Else_PeripheralRequest() 107 { 108 _DpaMessage.EnumPeripheralsAnswer.UserPerNr |= 0; // ? 109 // FlagUserPer( _DpaMessage.EnumPeripheralsAnswer.UserPer, PNUM_USER + 0 ); // ? 110 _DpaMessage.EnumPeripheralsAnswer.HWPID |= 0x000F; // ???? 111 _DpaMessage.EnumPeripheralsAnswer.HWPIDver |= 0; // ???? 112 113 DpaHandleReturnTRUE: 114 return TRUE; 115 } 116 // ------------------------------------------------- 117 // Get information about peripheral 118 // https://doc.iqrf.org/DpaTechGuide/pages/get-peripheral-info.html 119 else 120 { 121 if ( _PNUM == PNUM_USER + 0 ) // ? 122 { 123 _DpaMessage.PeripheralInfoAnswer.PerT = 0; // PERIPHERAL_TYPE_? 124 _DpaMessage.PeripheralInfoAnswer.PerTE = 0; // PERIPHERAL_TYPE_EXTENDED_? 125 _DpaMessage.PeripheralInfoAnswer.Par1 = 0; // ? 126 _DpaMessage.PeripheralInfoAnswer.Par2 = 0; // ? 127 goto DpaHandleReturnTRUE; 128 } 129 130 goto DpaHandleReturnFALSE; 131 } 132 // ------------------------------------------------- 133 // Handle peripheral command 134 // https://doc.iqrf.org/DpaTechGuide/pages/handle-peripheral-request.html 135 if ( _PNUM == PNUM_USER + 0 ) // ? 136 { 137 if ( _PCMD == 0 ) // ???? 138 { 139 goto DpaHandleReturnTRUE; 140 } 141 } 142 143 goto DpaHandleReturnFALSE; 144 145 // ------------------------------------------------- 146 _DpaEvent_Idle: 147 // Do a quick background work when RF packet is not received 148 // https://doc.iqrf.org/DpaTechGuide/pages/idle.html 149 goto DpaHandleReturnFALSE; 150 151 // ------------------------------------------------- 152 _DpaEvent_Reset: 153 // Called after module is reset 154 // https://doc.iqrf.org/DpaTechGuide/pages/ResetEvent.html 155 156 //goto DpaHandleReturnTRUE; // return TRUE only if you handle node bonding/unbonding 157 goto DpaHandleReturnFALSE; 158 159 // ------------------------------------------------- 160 _DpaEvent_Init: 161 // Do a one time initialization before main loop starts 162 // https://doc.iqrf.org/DpaTechGuide/pages/init.html 163 goto DpaHandleReturnFALSE; 164 165 // ------------------------------------------------- 166 _DpaEvent_ReceiveDpaRequest: 167 // Called after DPA request was received 168 // https://doc.iqrf.org/DpaTechGuide/pages/receivedparequest.html 169 170 //goto DpaHandleReturnTRUE; // return TRUE to skip default processing 171 goto DpaHandleReturnFALSE; 172 173 // ------------------------------------------------- 174 _DpaEvent_BeforeSendingDpaResponse: 175 // Called before sending DPA response back to originator of DPA response 176 // https://doc.iqrf.org/DpaTechGuide/pages/beforesendingdparesponse.html 177 178 goto DpaHandleReturnFALSE; 179 180 // ------------------------------------------------- 181 _DpaEvent_Notification: 182 // Called after DPA request was processed and after DPA response was sent 183 // https://doc.iqrf.org/DpaTechGuide/pages/notification.html 184 goto DpaHandleReturnFALSE; 185 186 // ------------------------------------------------- 187 _DpaEvent_AfterRouting: 188 // Called after Notification and after routing of the DPA response was finished 189 // https://doc.iqrf.org/DpaTechGuide/pages/afterrouting.html 190 goto DpaHandleReturnFALSE; 191 192 // ------------------------------------------------- 193 _DpaEvent_DisableInterrupts: 194 // Called when device needs all hardware interrupts to be disabled (before Reset, Restart, LoadCode, Remove bond and run RFPGM) 195 // https://doc.iqrf.org/DpaTechGuide/pages/eventDisableInterrupts.html 196 goto DpaHandleReturnFALSE; 197 198 // ------------------------------------------------- 199 _DpaEvent_ReceiveDpaResponse: 200 // Called after DPA response was received at coordinator 201 // https://doc.iqrf.org/DpaTechGuide/pages/receivedparesponse.html 202 203 //goto DpaHandleReturnTRUE; // return TRUE to skip default processing 204 goto DpaHandleReturnFALSE; 205 206 // ------------------------------------------------- 207 _DpaEvent_IFaceReceive: 208 // Called after DPA request from interface master was received at coordinator 209 // https://doc.iqrf.org/DpaTechGuide/pages/ifacereceive.html 210 211 //goto DpaHandleReturnTRUE; // return TRUE to skip default processing 212 goto DpaHandleReturnFALSE; 213 214 // ------------------------------------------------- 215 _DpaEvent_PeerToPeer: 216 // Called when peer-to-peer (non-networking) packet is received 217 // https://doc.iqrf.org/DpaTechGuide/pages/peertopeer.html 218 goto DpaHandleReturnFALSE; 219 220 // ------------------------------------------------- 221 _DpaEvent_UserDpaValue: 222 // Called when DPA is required to return User defined DPA value in the response 223 // https://doc.iqrf.org/DpaTechGuide/pages/userdpavalue.html 224 goto DpaHandleReturnFALSE; 225 226 // ------------------------------------------------- 227 228 DpaHandleReturnFALSE: 229 return FALSE; 230 } 231 232 //############################################################################################ 233 234 // Uncomment the following includes if the respective component is needed 235 //#include "NFC.c" 236 237 // 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) 238 #include "DPAcustomHandler.h" 239 //############################################################################################