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