1 // ********************************************************************* 2 // Custom DPA Handler code example - Custom indication * 3 // ********************************************************************* 4 // Copyright (c) MICRORISC s.r.o. 5 // 6 // File: $RCSfile: CustomDpaHandler-CustomIndicate.c,v $ 7 // Version: $Revision: 1.17 $ 8 // Date: $Date: 2022/02/25 09:41:25 $ 9 // 10 // Revision history: 11 // 2022/02/24 Release for DPA 4.17 12 // 2020/04/03 Release for DPA 4.14 13 // 2020/02/27 Release for DPA 4.13 14 // 15 // ********************************************************************* 16 17 // Online DPA documentation https://doc.iqrf.org/DpaTechGuide/ 18 19 // Default IQRF include (modify the path according to your setup) 20 #include "IQRF.h" 21 22 // Default DPA header (modify the path according to your setup) 23 #include "DPA.h" 24 // Default Custom DPA Handler header (modify the path according to your setup) 25 #include "DPAcustomHandler.h" 26 27 // Must be the 1st defined function in the source code in order to be placed at the correct FLASH location! 28 //############################################################################################ 29 bit CustomDpaHandler() 30 //############################################################################################ 31 { 32 // Handler presence mark 33 clrwdt(); 34 35 // Detect DPA event to handle (unused event handlers can be commented out or even deleted) 36 switch ( GetDpaEvent() ) 37 { 38 // ------------------------------------------------- 39 case DpaEvent_Interrupt: 40 // Do an extra quick background interrupt work 41 return Carry; 42 43 // ------------------------------------------------- 44 case DpaEvent_Init: 45 // Do a one time initialization before main loop starts 46 47 // Set custom indication GPIO to output 48 TRISA.0 = 0; 49 break; 50 51 // ------------------------------------------------- 52 case DpaEvent_Indicate: 53 // Called to allow a customization of the device indication 54 55 // userReg1 = Control byte with only valid bit.0-1, bit.2-7 = 0 56 57 // Control == 0 (indication off) ? 58 if ( userReg1 == 0 ) 59 { 60 _IndicateOff: 61 stopLEDR(); 62 LATA.0 = 0; 63 } 64 else 65 { 66 // Indication on 67 setLEDR(); 68 LATA.0 = 1; 69 70 // Timed indication? 71 if ( userReg1.1 ) 72 { 73 // 1 s 74 W = 1 * 2; 75 // Control != 2 76 if ( userReg1.0 ) 77 // 10 s 78 W = 10 * 2; 79 userReg1 = W; 80 do 81 { 82 // 0.5 s step 83 waitDelay( 50 ); 84 clrwdt(); 85 } while ( --userReg1 != 0 ); 86 87 // Switch off the indication 88 goto _IndicateOff; 89 } 90 } 91 92 // return TRUE to skip default indication by LEDR and LEDG (userReg1 might be thus modified) 93 return TRUE; 94 95 // ------------------------------------------------- 96 case DpaEvent_BeforeSleep: 97 // Called before going to sleep 98 99 // Switch off custom indication via GPIO 100 goto _IndicateOff; 101 102 // ------------------------------------------------- 103 case DpaEvent_DpaRequest: 104 // Called to interpret DPA request for peripherals 105 // ------------------------------------------------- 106 // Peripheral enumeration 107 if ( IsDpaEnumPeripheralsRequest() ) 108 { 109 // We implement no user peripheral 110 _DpaMessage.EnumPeripheralsAnswer.HWPID |= 0x15DF; 111 _DpaMessage.EnumPeripheralsAnswer.HWPIDver |= 0x0000; 112 return TRUE; 113 } 114 break; 115 } 116 117 return FALSE; 118 } 119 120 //############################################################################################ 121 // Default Custom DPA Handler header; 2nd include implementing a Code bumper to detect too long code of the Custom DPA Handler (modify the path according to your setup) 122 #include "DPAcustomHandler.h" 123 //############################################################################################