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