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 = 10 * 2; 75 // Control != 2 76 if ( userReg1.0 ) 77 // 10 s 78 userReg1 = W; 79 do 80 { 81 // 0.5 s step 82 waitDelay( 50 ); 83 clrwdt(); 84 } while ( --userReg1 != 0 ); 85 86 // Switch off the indication 87 goto _IndicateOff; 88 } 89 } 90 91 // return TRUE to skip default indication by LEDR and LEDG (userReg1 might be thus modified) 92 return TRUE; 93 94 // ------------------------------------------------- 95 case DpaEvent_BeforeSleep: 96 // Called before going to sleep 97 98 // Switch off custom indication via GPIO 99 goto _IndicateOff; 100 101 // ------------------------------------------------- 102 case DpaEvent_DpaRequest: 103 // Called to interpret DPA request for peripherals 104 // ------------------------------------------------- 105 // Peripheral enumeration 106 if ( IsDpaEnumPeripheralsRequest() ) 107 { 108 // We implement no user peripheral 109 _DpaMessage.EnumPeripheralsAnswer.HWPID |= 0x15DF; 110 _DpaMessage.EnumPeripheralsAnswer.HWPIDver |= 0x0000; 111 return TRUE; 112 } 113 break; 114 } 115 116 return FALSE; 117 } 118 119 //############################################################################################ 120 // 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) 121 #include "DPAcustomHandler.h" 122 //############################################################################################