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