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