1 // ********************************************************************* 2 // Main Custom DPA Handler header * 3 // ********************************************************************* 4 // Copyright (c) IQRF Tech s.r.o. 5 // 6 // File: $RCSfile: DPAcustomHandler.h,v $ 7 // Version: $Revision: 1.94 $ 8 // Date: $Date: 2019/06/12 11:37:17 $ 9 // 10 // Revision history: 11 // 2019/06/12 Release for DPA 4.03 12 // 2019/06/03 Release for DPA 4.02 13 // 2019/03/07 Release for DPA 4.01 14 // 2019/01/10 Release for DPA 4.00 15 // 2018/10/25 Release for DPA 3.03 16 // 2017/11/16 Release for DPA 3.02 17 // 2017/08/14 Release for DPA 3.01 18 // 2017/03/13 Release for DPA 3.00 19 // 2016/09/12 Release for DPA 2.28 20 // 2016/04/14 Release for DPA 2.27 21 // 2016/03/03 Release for DPA 2.26 22 // 2016/01/21 Release for DPA 2.25 23 // 2015/12/01 Release for DPA 2.24 24 // 2015/10/23 Release for DPA 2.23 25 // 2015/09/25 Release for DPA 2.22 26 // 2015/09/03 Release for DPA 2.21 27 // 2015/08/05 Release for DPA 2.20 28 // 2014/10/31 Release for DPA 2.10 29 // 2014/04/30 Release for DPA 2.00 30 // 2013/10/03 Release for DPA 1.00 31 // 32 // ********************************************************************* 33 34 // Online DPA documentation http://www.iqrf.org/DpaTechGuide/ 35 // IQRF Standards documentation https://www.iqrfalliance.org/techDocs/ 36 37 #ifndef _CUSTOM_DPA_HANDLER_ 38 #define _CUSTOM_DPA_HANDLER_ 39 40 //############################################################################################ 41 // 1st include 42 43 // Custom DPA Handler routine declaration 44 bit CustomDpaHandler(); 45 46 // Various DPA flags shared between DPA and Custom DPA Handler 47 uns8 DpaFlags @ usedBank4[0]; 48 #ifdef COORDINATOR_CUSTOM_HANDLER 49 // [C] TRUE if interface master is not connected (detected) 50 bit IFaceMasterNotConnected @ DpaFlags.2; 51 #endif 52 // [N] [CN] DPA by interface notification is sent also when there was a "reading" like DPA request 53 bit EnableIFaceNotificationOnRead @ DpaFlags.3; 54 // [N] [NC] TRUE when node was just bonded using default bonding procedure 55 bit NodeWasBonded @ DpaFlags.4; 56 57 // [C] Ticks (decrementing) counter usable for timing in the coordinator's Customer DPA Handler 58 uns16 DpaTicks @ usedBank4[1]; 59 // [N] [NC] toutRF for LP mode, read from configuration memory after reset 60 uns8 LPtoutRF @ usedBank4[3]; 61 // DPA Request/Response HWPID 62 uns16 _HWPID @ usedBank4[4]; 63 // Identifies type of reset (stored at UserReg0 upon module reset). See Reset chapter at IQRF User's Guide for more information 64 uns8 ResetType @ usedBank4[6]; 65 // User DPA Values to return 66 uns8 UserDpaValue @ usedBank4[7]; 67 // Network depth of the DPA request/response, increases on bridging, decreases on back-bridging 68 uns8 NetDepth @ usedBank4[8]; 69 // TRUE when node was at DPA Service Mode after last boot 70 bit DSMactivated @ usedBank4[9].0; 71 // If set to TRUE, then LP RX mode in the main loop can be terminated by pin, see _RLPMAT 72 bit LpRxPinTerminate @ usedBank4[9].1; 73 // RX filter used at the DPA main loop checkRF call 74 uns8 RxFilter @ usedBank4[11]; 75 // Countdown variable for button bonding before going to deep sleep 76 uns16 BondingSleepCountdown @ usedBank4[12]; 77 #define BONDING_SLEEP_COUNTDOWN_UNIT 290 78 79 // Macro to return an error from the peripheral handler. If the code size is not an issue this macro is the right choice. 80 #define DpaApiReturnPeripheralError(error) do { \ 81 DpaApiSetPeripheralError( error ); \ 82 return Carry; \ 83 } while( 0 ) 84 85 // DPA API functions, see documentation for details 86 #define DpaApiRfTxDpaPacket( dpaValue, netDepthAndFlags ) DpaApiEntry( dpaValue, netDepthAndFlags, DPA_API_RFTX_DPAPACKET ) 87 #define DpaApiReadConfigByte( index ) DpaApiEntry( index, param3.low8, DPA_API_READ_CONFIG_BYTE ) 88 #define DpaApiLocalRequest() DpaApiEntry( param2, param3.low8, DPA_API_LOCAL_REQUEST ) 89 #define DpaApiSetPeripheralError( error ) DpaApiEntry( error, param3.low8, DPA_API_SET_PERIPHERAL_ERROR ) 90 #define DpaApiSendToIFaceMaster( dpaValue, flags ) DpaApiEntry( dpaValue, flags, DPA_API_SEND_TO_IFACEMASTER ) 91 #define DpaApiSetRfDefaults() DpaApiEntry( param2, param3.low8, DPA_API_SET_RF_DEFAULTS ) 92 93 #ifdef COORDINATOR_CUSTOM_HANDLER 94 #define DpaApiRfTxDpaPacketCoordinator() DpaApiEntry( param2, param3.low8, DPA_API_COORDINATOR_RFTX_DPAPACKET ) 95 #endif 96 97 #ifdef COORDINATOR_CUSTOM_HANDLER 98 #undef DpaEvent_Interrupt 99 #undef DpaEvent_BeforeSleep 100 #undef DpaEvent_AfterSleep 101 #undef DpaEvent_FrcValue 102 #undef DpaEvent_FrcResponseTime 103 #else 104 #undef DpaEvent_ReceiveDpaResponse 105 #undef DpaEvent_IFaceReceive 106 #endif 107 108 // To detect overlapping code in case someone would put some code before this header by mistake 109 #pragma origin __APPLICATION_ADDRESS 110 #pragma updateBank 0 111 112 //############################################################################################ 113 // Main IQRF entry point jumps to the main DPA entry point 114 void APPLICATION() 115 //############################################################################################ 116 { 117 #asm 118 DW __MOVLP( MAIN_DPA_ADDRESS >> 8 ); 119 DW __GOTO( MAIN_DPA_ADDRESS ); 120 #endasm 121 122 #ifndef NO_CUSTOM_DPA_HANDLER 123 // Fake call to force CustomDpaHandler() compilation 124 CustomDpaHandler(); 125 #endif 126 127 // Fake call to force DpaApiEntry() compilation 128 DpaApiEntry( param2, param3.low8, W ); 129 } 130 131 //############################################################################################ 132 // Entry stub to the real DPA API entry 133 #pragma origin DPA_API_ADDRESS_ENTRY 134 uns8 DpaApiEntry( uns8 par1 @ param2, uns8 par2 @ param3.low8, uns8 apiIndex @ W ) 135 //############################################################################################ 136 { 137 #asm 138 DW __MOVLP( DPA_API_ADDRESS >> 8 ); 139 DW __CALL( DPA_API_ADDRESS ); 140 DW __MOVLP( DPA_API_ADDRESS_ENTRY >> 8 ); 141 #endasm 142 143 return W; 144 } 145 146 //############################################################################################ 147 #pragma origin DPA_API_ADDRESS_ENTRY + 0x08 148 149 //############################################################################################ 150 151 #ifndef NO_CUSTOM_DPA_HANDLER 152 // Next comes Custom DPA handler routine 153 #pragma origin CUSTOM_HANDLER_ADDRESS 154 #endif 155 156 #pragma updateBank 1 157 158 //############################################################################################ 159 #else // _CUSTOM_DPA_HANDLER_ 160 //############################################################################################ 161 // 2nd include 162 163 #ifndef NO_CUSTOM_DPA_HANDLER 164 // Code bumper to detect too long code of Custom DPA handler + other routines 165 #pragma origin CUSTOM_HANDLER_ADDRESS_END 166 // To avoid adding some code after handler by mistake 167 #pragma origin __MAX_FLASH_ADDRESS 168 #endif 169 170 #endif // _CUSTOM_DPA_HANDLER_ 171 //############################################################################################