1 // ********************************************************************* 2 // Custom DPA Handler - XLP long term sleep and wake up * 3 // ********************************************************************* 4 // Copyright (c) MICRORISC s.r.o. 5 // 6 // File: $RCSfile: CustomDpaHandler-XLPstandBy.c,v $ 7 // Version: $Revision: 1.5 $ 8 // Date: $Date: 2021/04/26 15:13:51 $ 9 // 10 // Revision history: 11 // 2019/01/10 Release for DPA 4.00 12 // 13 // ********************************************************************* 14 15 // Online DPA documentation https://doc.iqrf.org/DpaTechGuide/ 16 17 // Default IQRF include (modify the path according to your setup) 18 #include "IQRF.h" 19 20 // Default DPA header (modify the path according to your setup) 21 #include "DPA.h" 22 // Default Custom DPA Handler header (modify the path according to your setup) 23 #include "DPAcustomHandler.h" 24 25 //############################################################################################ 26 27 //############################################################################################ 28 bit CustomDpaHandler() 29 //############################################################################################ 30 { 31 // Handler presence mark 32 clrwdt(); 33 34 static bit doXLPstandBy; 35 36 // Detect DPA event to handle (unused event handlers can be commented out or even deleted) 37 switch ( GetDpaEvent() ) 38 { 39 // ------------------------------------------------- 40 case DpaEvent_Interrupt: 41 // Do an extra quick background interrupt work 42 43 return Carry; 44 45 // ------------------------------------------------- 46 case DpaEvent_Notification: 47 // Called after DPA request was processed and after DPA response was sent 48 49 if ( doXLPstandBy ) 50 { 51 doXLPstandBy = FALSE; 52 53 setNonetMode(); 54 setRFmode( _WPE | _RX_XLP | _TX_XLP ); 55 56 setLEDG(); 57 setLEDR(); 58 waitDelay( 100 ); 59 60 uns8 cnt; 61 for ( ;; ) 62 { 63 cnt++; 64 if ( cnt.0 ) 65 setLEDG(); 66 else 67 setLEDR(); 68 waitMS( 1 ); 69 stopLEDR(); 70 stopLEDG(); 71 72 toutRF = 2 * 10; 73 if ( RFRXpacket() && DLEN == 1 && bufferRF[0] == 'W' ) 74 { 75 setLEDG(); 76 setLEDR(); 77 waitDelay( 100 ); 78 stopLEDR(); 79 stopLEDG(); 80 break; 81 } 82 } 83 84 DpaApiSetRfDefaults(); 85 setNodeMode(); 86 } 87 break; 88 89 // ------------------------------------------------- 90 case DpaEvent_DpaRequest: 91 // Called to interpret DPA request for peripherals 92 IfDpaEnumPeripherals_Else_PeripheralInfo_Else_PeripheralRequest() 93 { 94 // ------------------------------------------------- 95 // Peripheral enumeration 96 97 _DpaMessage.EnumPeripheralsAnswer.UserPerNr = 1; 98 FlagUserPer( _DpaMessage.EnumPeripheralsAnswer.UserPer, PNUM_USER + 0 ); 99 _DpaMessage.EnumPeripheralsAnswer.HWPID = 0x581F; 100 101 DpaHandleReturnTRUE: 102 return TRUE; 103 } 104 else 105 { 106 // ------------------------------------------------- 107 // Get information about peripheral 108 109 if ( _PNUM == PNUM_USER + 0 ) 110 { 111 _DpaMessage.PeripheralInfoAnswer.PerT = PERIPHERAL_TYPE_USER_AREA; 112 _DpaMessage.PeripheralInfoAnswer.PerTE = PERIPHERAL_TYPE_EXTENDED_WRITE; 113 goto DpaHandleReturnTRUE; 114 } 115 116 break; 117 } 118 119 // ------------------------------------------------- 120 // Handle peripheral command 121 122 if ( _PNUM == PNUM_USER + 0 && _PCMD == 0 && _DpaDataLength == 0 ) 123 { 124 if ( ( DpaApiReadConfigByte( CFGIND_DPA_PERIPHERALS + PNUM_COORDINATOR / 8 ) & ( 1 << ( PNUM_COORDINATOR % 8 ) ) ) != 0 ) 125 { 126 // Coordinator 127 setNonetMode(); 128 setRFpower( 7 ); 129 setRFmode( _TX_XLP ); 130 131 PIN = 0; 132 DLEN = 1; 133 bufferRF[0] = 'W'; 134 RFTXpacket(); 135 136 DpaApiSetRfDefaults(); 137 setCoordinatorMode(); 138 } 139 else 140 { 141 // Node 142 doXLPstandBy = TRUE; 143 } 144 145 goto DpaHandleReturnTRUE; 146 } 147 148 break; 149 } 150 151 DpaHandleReturnFALSE: 152 return FALSE; 153 } 154 //############################################################################################ 155 // 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) 156 #include "DPAcustomHandler.h" 157 //############################################################################################